From timr at probo.com Wed Sep 1 00:30:33 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 31 Aug 2010 21:30:33 -0700 Subject: Source code for itertools References: <9aa266f0-be9b-4c9a-bfbd-6cdfc86ad2c8@t20g2000yqa.googlegroups.com> <7xmxs3sdt2.fsf@ruckus.brouhaha.com> Message-ID: vsoler wrote: >On 31 ago, 04:42, Paul Rubin wrote: >> vsoler writes: >> > I was expecting an itertools.py file, but I don't see it in your list. >> >> ./python3.1-3.1.2+20100829/Modules/itertoolsmodule.c >> >> looks promising. ?Lots of stdlib modules are written in C for speed or >> access to system facilities. > >Lawrence, Paul, > >You seem to be running a utility I am not familiar with. Perhaps this >is because I am using Windows, and most likely you are not. > >How could I have found the answer in a windows environment? Did you take the time to understand what he did? It's not that hard to figure out. He fetched the Python source code, unpacked it, then search for filenames that contained the string "itertools." The equivalent in Windows, after unpacking the source archive, would have been: dir /s *itertools* -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From contact at xavierho.com Wed Sep 1 01:14:31 2010 From: contact at xavierho.com (Xavier Ho) Date: Wed, 1 Sep 2010 15:14:31 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: On 1 September 2010 12:00, Alban Nona wrote: > @Xavier: ShaDoW, WorldPositionPoint (which is the same thing as > WordPointCloud passe) :) > Aha! That's what I was missing. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From enleverLesX_XXmcX at XmclavXeauX.com.invalid Wed Sep 1 02:23:00 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Wed, 01 Sep 2010 08:23:00 +0200 Subject: Installing Python as Scripting Language in IIS References: <125c518f-d418-4f3f-ae8f-4f0fdcae00df@y12g2000prb.googlegroups.com> Message-ID: <4c7df147$0$10226$ba4acef3@reader.news.orange.fr> Hi! You must register Python as ActiveScripting's language. See : C:\Python26\Lib\site-packages\win32comext\axscript @-salutations -- Michel Claveau From enleverLesX_XXmcX at XmclavXeauX.com.invalid Wed Sep 1 02:24:46 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Wed, 01 Sep 2010 08:24:46 +0200 Subject: Installing Python as Scripting Language in IIS References: <125c518f-d418-4f3f-ae8f-4f0fdcae00df@y12g2000prb.googlegroups.com> Message-ID: <4c7df1b2$0$10212$ba4acef3@reader.news.orange.fr> Re ! More details: C:\Python26\Lib\site-packages\win32comext\axscript\Demos\client\ie\demo.htm @+ -- Michel Claveau From no.email at nospam.invalid Wed Sep 1 02:42:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 31 Aug 2010 23:42:15 -0700 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <878w3ogpvq.fsf@benfinney.id.au> Message-ID: <7xvd6qufqw.fsf@ruckus.brouhaha.com> Terry Reedy writes: > Does anyone seriously think that an implementation should be rejected > as an implementation if it intellegently did seq[n] lookups in > log2(n)/31 time units for all n (as humans would do), instead of > stupidly taking 1 time unit for all n < 2**31 and rejecting all larger > values (as 32-bit CPython does)? Er, how can one handle n > 2**31 at all, in 32-bit CPython? >> Dicts that were not O(1) for access with non-pathological hashing? > > You would actually be unhappy if small dicts ran even faster than they > do now (while large dicts ran the same)? Not me! Not sure what you are referring to by that. I'd actually be ok with using O(log(n)) dicts to eliminate the O(n) behavior of the hash-based implementation on adverse input sets. > Similarly, books say that O(n*logn) sorting is 'better' that O(n**2) > sorting. However, Tim Peters verified that the opposite is true for > real times for small n, and hence the current list.sort smartly uses a > fast O(n**2) algorithm for small lists (len < 64) and small runs in > larger lists. Rejecting list.sort for this reason would be stupid. That algorithm is still O(n log n) since the n**2 behavior up to some constant n is effectively an additive constant that asymptotically is within the specified big-O. 64 actually sounds suspiciously large for the cutover, but I'm sure Tim tuned it carefully. From no.email at nospam.invalid Wed Sep 1 02:48:00 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 31 Aug 2010 23:48:00 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> Message-ID: <7xr5heufhb.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > And yet Java code, for example, doesn?t have a reputation for greater > reliability compared to, say code written in Ada or C++, or even C. What is > the Java runtime written in? C. Why not use Java, if there is no speed > penalty in doing so? The Java runtime (such as the garbage collector) needs untyped pointers and can't be written in Java. It might be possible to write a type-safe GC in something like ATS, which has extremely precise types, but that is almost alien technology by comparison to writing in C. Java has considerably greater reputation for reliability than C or C++. Ada is a different story, but Ada programs (because of the application area Ada is used in) tend not to use a lot of dynamic memory allocation in the first place. A little googling shows there are GC extensions available for Ada, though I don't know if they are used much. From no.email at nospam.invalid Wed Sep 1 02:58:58 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 31 Aug 2010 23:58:58 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> Message-ID: <7xmxs2uez1.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > Whereas garbage collection will happen at some indeterminate time long after > the last access to the object, when it very likely will no longer be in the > cache, and have to be brought back in just to be freed, GC's for large systems generally don't free (or even examine) individual garbage objects. They copy the live objects to a new contiguous heap without ever touching the garbage, and then they release the old heap. That has the effect of improving locality, since the new heap is compacted and has no dead objects. The algorithms are generational (they do frequent gc's on recently-created objects and less frequent ones on older objects), so "minor" gc operations are on regions that fit in cache, while "major" ones might have cache misses but are infrequent. Non-compacting reference counting (or simple mark/sweep gc) has much worse fragmentation and consequently worse cache locality than copying-style gc. From stefan_ml at behnel.de Wed Sep 1 03:06:00 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Sep 2010 09:06:00 +0200 Subject: Optimising literals away In-Reply-To: <4C7D79EE.8010402@mrabarnett.plus.com> References: <69a8fbbc-5f45-491a-adf3-2fb5a4d79660@s9g2000yqd.googlegroups.com> <4C7D79EE.8010402@mrabarnett.plus.com> Message-ID: MRAB, 31.08.2010 23:53: > On 31/08/2010 21:18, Terry Reedy wrote: >> On 8/31/2010 12:33 PM, Aleksey wrote: >>> On Aug 30, 10:38 pm, Tobias Weber wrote: >>>> Hi, >>>> whenever I type an "object literal" I'm unsure what optimisation >>>> will do >>>> to it. >> >> Optimizations are generally implentation dependent. CPython currently >> creates numbers, strings, and tuple literals just once. Mutable literals >> must be created each time as they may be bound and saved. >> >>>> def m(arg): >>>> if arg& set([1,2,3]): >> >> set() is a function call, not a literal. When m is called, who knows >> what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, >> which is much faster as it avoids creating and deleting a list. On my >> machine, .35 versus .88 usec. Even then, it must be calculated each time >> because sets are mutable and could be returned to the calling code. >> > There's still the possibility of some optimisation. If the resulting > set is never stored anywhere (bound to a name, for example) then it > could be created once. When the expression is evaluated there could be > a check so see whether 'set' is bound to the built-in class, and, if it > is, then just use the pre-created set. Cython applies this kind of optimistic optimisation in a couple of other cases and I can affirm that it often makes sense to do that. However, drawback here: the set takes up space while not being used (not a huge problem if literals are expected to be small), and the global lookup of "set" still has to be done to determine if it *is* the builtin set type. After that, however, the savings should be considerable. Another possibility: always cache the set and create a copy on access. Copying a set avoids the entire eval loop overhead and runs in a C loop instead, using cached item instances with (most likely) cached hash values. So even that will most likely be much faster than the spelled-out code above. Stefan From no.email at nospam.invalid Wed Sep 1 03:14:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 01 Sep 2010 00:14:32 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <4c78e7a5$0$28655$c3e8da3@news.astraweb.com> <4c7a2c3b$0$22941$e4fe514c@news.xs4all.nl> <7xhbidndc6.fsf@ruckus.brouhaha.com> <8e15pqFn89U1@mid.individual.net> <7xmxs4uzjl.fsf@ruckus.brouhaha.com> Message-ID: <7xiq2que93.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: >> Refcounting is susceptable to the same pauses for reasons already >> discussed. > > Doesn?t seem to happen in the real world, though. def f(n): from time import time a = [1] * n t0 = time() del a t1 = time() return t1 - t0 for i in range(9): print i, f(10**i) on my system prints: 0 2.86102294922e-06 1 2.14576721191e-06 2 3.09944152832e-06 3 1.00135803223e-05 4 0.000104904174805 5 0.00098991394043 6 0.00413608551025 7 0.037693977356 8 0.362598896027 Looks pretty linear as n gets large. 0.36 seconds (the last line) is a noticable pause. From nkaunda at yahoo.com Wed Sep 1 03:29:05 2010 From: nkaunda at yahoo.com (Nally Kaunda-Bukenya) Date: Wed, 1 Sep 2010 00:29:05 -0700 (PDT) Subject: Newby Needs Help with Python code Message-ID: <861505.20099.qm@web33506.mail.mud.yahoo.com> ? Dear Python experts, I hope someone can help me. I am new to Python and trying to achive the following: 1)????? I would like to populate the Tot_Ouf_Area field with total area of each unique outfall_id (code attempted below,but Tot_Ouf_Area not populating) 2)????? I would also like to get the user input of Rv ( each landuse type will have a specific Rv value). For example the program should ask the user for Rv value of Low Density Residential (user enters 0.4 in example below and that value must be stored in the Rv field), and so on as shown in the 2nd table below? Below is my original table (comma-delimited) "OBJECTID","OUTFALL_ID","LANDUSE","AREA_ACRES","Rv","Tot_Outf_Area" 16,"ALD06001","High Density Residential",6.860922,0.000000,0.000000 15,"ALD06001","General Commercial",7.520816,0.000000,0.000000 14,"ALD05002","Low Density Residential",7.255491,0.000000,0.000000 13,"ALD05002","Forest",37.090473,0.000000,0.000000 12,"ALD05001","Low Density Residential",16.904560,0.000000,0.000000 11,"ALD05001","Forest",84.971686,0.000000,0.000000 10,"ALD04002","Urban Open",1.478677,0.000000,0.000000 9,"ALD04002","Transportation",0.491887,0.000000,0.000000 8,"ALD04002","Low Density Residential",25.259720,0.000000,0.000000 7,"ALD04002","Forest",0.355659,0.000000,0.000000 6,"ALD04001","Recreational",0.013240,0.000000,0.000000 5,"ALD04001","Low Density Residential",34.440130,0.000000,0.000000 4,"ALD04001","Forest",10.229973,0.000000,0.000000 3,"ALD03002","Low Density Residential",23.191538,0.000000,0.000000 2,"ALD03002","Forest",1.853920,0.000000,0.000000 1,"ALD03001","Low Density Residential",6.828130,0.000000,0.000000 21,"ALD06001","Water.dgn",0.013951,0.000000,0.000000 20,"ALD06001","Urban Open",10.382900,0.000000,0.000000 19,"ALD06001","Transportation",2.064454,0.000000,0.000000 18,"ALD06001","Recreational",0.011007,0.000000,0.000000 17,"ALD06001","Low Density Residential",0.752509,0.000000,0.000000 ? Below is my desired output table (comma delimited): "OBJECTID","OUTFALL_ID","LANDUSE","AREA_ACRES","Rv","Tot_Outf_Area" 16,"ALD06001","High Density Residential",6.860922,0.000000,27.606562 15,"ALD06001","General Commercial",7.520816,0.000000,27.606562 14,"ALD05002","Low Density Residential",7.255491,0.400000,44.345966 13,"ALD05002","Forest",37.090473,0.300000,44.345966 11,"ALD05001","Forest",84.971686,0.300000,101.876247 12,"ALD05001","Low Density Residential",16.904560,0.400000,101.876247 10,"ALD04002","Urban Open",1.478677,0.000000,27.585945 9,"ALD04002","Transportation",0.491887,0.000000,27.585945 8,"ALD04002","Low Density Residential",25.259720,0.400000,27.585945 7,"ALD04002","Forest",0.355659,0.300000,27.585945 6,"ALD04001","Recreational",0.013240,0.000000,44.683345 5,"ALD04001","Low Density Residential",34.440130,0.400000,44.683345 4,"ALD04001","Forest",10.229973,0.300000,44.683345 3,"ALD03002","Low Density Residential",23.191538,0.400000,25.045460 2,"ALD03002","Forest",1.853920,0.300000,25.045460 1,"ALD03001","Low Density Residential",6.828130,0.400000,6.828130 21,"ALD06001","Water.dgn",0.013951,0.000000,27.606562 20,"ALD06001","Urban Open",10.382900,0.000000,27.606562 19,"ALD06001","Transportation",2.064454,0.000000,27.606562 18,"ALD06001","Recreational",0.011007,0.000000,27.606562 17,"ALD06001","Low Density Residential",0.752509,0.400000,27.606562 Below is my code so far for updating rows with total area (Tot_Ouf_Area): ? #THE PROGRAM: import arcgisscripting gp=arcgisscripting.create() gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb" fc = "Outfalls_ND" try: ??? # Set the field to create a list of unique values??? ??????? fieldname = "OUTFALL_ID" ??????? ??? # Open a Search Cursor to identify all unique values ??????? cur = gp.UpdateCursor(fc) ??????? row = cur.Next() ??????? # Set a list variable to hold all unique values ??????? L = [] ??????? # Using a while loop, cursor through all records and append unique ??????? #values to the list variable ??????? while row <> None: ??????????? value = row.GetValue(fieldname) ??????????? if value not in L: ??????????????? L.append(value) ??????????? row = cur.Next() ??????????? row.SetValue(Tot_Outf_Area, sum(row.AREA_ACRES)) #total area of each outfall=sum of all area 4 each unique outfallid ??????????? cur.UpdateRow(row) #to commit changes ??????????? row=cur.Next() ??????????? print row.Tot_Outf_Area ??????? # Sort the list variable ??????? L.sort() ??????? # If a value in the list variable is blank, remove it from the list variable ??????? #to filter out diffuse outfalls ??????? if ' ' in L: ??????????? L.remove(' ') except: ??? # If an error occurred while running a tool, print the messages ??? print gp.GetMessages() ? #Please Help!!! #Esther -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at merton.oxon.org Wed Sep 1 07:28:37 2010 From: rami.chowdhury at merton.oxon.org (Rami Chowdhury) Date: Wed, 1 Sep 2010 17:28:37 +0600 Subject: Newby Needs Help with Python code In-Reply-To: <861505.20099.qm@web33506.mail.mud.yahoo.com> References: <861505.20099.qm@web33506.mail.mud.yahoo.com> Message-ID: Hi Esther, On Wed, Sep 1, 2010 at 13:29, Nally Kaunda-Bukenya wrote: > #THE PROGRAM: > import arcgisscripting > gp=arcgisscripting.create() > gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb" > fc = "Outfalls_ND" > > try: > ??? # Set the field to create a list of unique values > ??????? fieldname = "OUTFALL_ID" > > ??? # Open a Search Cursor to identify all unique values > ??????? cur = gp.UpdateCursor(fc) > ??????? row = cur.Next() > > ??????? # Set a list variable to hold all unique values > ??????? L = [] > > ??????? # Using a while loop, cursor through all records and append unique > ??????? #values to the list variable > ??????? while row <> None: > ??????????? value = row.GetValue(fieldname) > ??????????? if value not in L: > ??????????????? L.append(value) > ??????????? row = cur.Next() > ??????????? row.SetValue(Tot_Outf_Area, sum(row.AREA_ACRES)) #total area of > each outfall=sum of all area 4 each unique outfallid > ??????????? cur.UpdateRow(row) #to commit changes > ??????????? row=cur.Next() > ??????????? print row.Tot_Outf_Area > ??????? # Sort the list variable > ??????? L.sort() > > ??????? # If a value in the list variable is blank, remove it from the list > variable > ??????? #to filter out diffuse outfalls > ??????? if ' ' in L: > ??????????? L.remove(' ') > > except: > ??? # If an error occurred while running a tool, print the messages > ??? print gp.GetMessages() Have you tried running this code? I suspect it won't work at all -- and because you are catching all possible exceptions in your try...except, you won't even know why. Here are the things that I'd suggest, just from glancing over the code: - Remove the try...except for now. Getting an exception, and understanding why it occurred and how best to deal with it, is IMHO very helpful when prototyping and debugging. - Take another look at your while loop. I don't know ArcGIS, so I don't know if the UpdateCursor object supports the iterator protocol, but the normal Python way of looping through all rows would be a for loop: for row in cur: # code For example, you are calling cur.Next() twice inside the loop -- is that what you want? Hope that helps, Rami > > > > #Please Help!!! > > #Esther > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From luke.leighton at gmail.com Wed Sep 1 08:36:26 2010 From: luke.leighton at gmail.com (lkcl) Date: Wed, 1 Sep 2010 05:36:26 -0700 (PDT) Subject: fairly urgent request: paid python (or other) work required Message-ID: i apologise for having to contact so many people but this is fairly urgent, and i'm running out of time and options. i'm a free software programmer, and i need some paid work - preferably python - fairly urgently, so that i can pay for food and keep paying rent, and so that my family doesn't get deported or have to leave the country. i really would not be doing this unless it was absolutely, absolutely essential that i get money. so that both i and the list are not unnecessarily spammed, please don't reply with recommendations of "where to get jobs", unless they are guaranteed to result in immediate work and money. if you have need of a highly skilled and experienced python-preferring free-software-preferring software engineer, please simply contact me, and tell me what you need doing: there's no need for you to read the rest of this message. so that people are not offended by me asking on such a high-volume list for work, here are some questions and answers: Q: who are you? A: luke leighton. free sofware developer, free software project leader, and "unusual cross-project mash-up-er" (meaning: i spot the value of joining one or more bits of disparate "stuff" to make something that's more powerful than its components). Q: where's your CV? A: executive version of CV is at http://lkcl.net/exec_cv.txt - please don't ask for a proprietary microsoft word version, as a refusal and referral to the "sylvester response" often offends. Q: what can you do? A: python programming, c programming, web development, networking, cryptography, reverse-engineering, IT security, etc. etc. preferably involving free software. Q: what do you need? A: money to pay rent and food. at the ABSOLUTE MINIMUM, i need as little as ?1500 per month to pay everything, and have been earning approx ?800 per month for the past year. a ?5000 inheritance last year which i was not expecting has delayed eviction and bankruptcy for me and my family, and deportation for my partner and 17 month old daughter (marie is here in the UK on a FLR/M visa) Q: why are you asking here? A: because it's urgent that i get money really really soon; my family members are refusing to assist, and the few friends that i have do not have any spare money to lend. Q: why here and not "monster jobs" or "python-jobs list" or the various "recruitment agencies"? A: those are full-time employment positions, which i have been frequently applying for and get rejected for various reasons, and i'm running out of time and money. further interviews cost money, and do not result in guaranteed work. i need work - and money - _now_. Q: why here and not "peopleperhour.com"? A: if you've ever bid on peopleperhour.com you will know that you are bidding against "offshore" contrators and even being undercut by 1st world country bidders who, insanely, appear to be happy to do work for as little as ?2 / hour. Q: why are you getting rejected from interviews? A: that's complex. a) i simply don't interview well. people with the classic symptoms of asperger's just don't. b) my daughter is 17 months old. when i go away for as little as 3 days, which i've done three times now, she is extremely upset both when i am away and when i return. i think what would happen if i was doing some sort of full- time job, away from home, and... i can't do it. subconsciously that affects how i react when speaking to interviewers. Q: why do you not go "get a job at tesco's" or "drive a truck"? A: tescos and HGV driving etc. pay around ?12 per hour. ?12 per hour after tax comes down to about ?8 to ?9 per hour. ?9 per hour requires 35 hours per week to earn as little as ?1500. 35 hours per week is effectively full-time, and means that a) my programming and software engineering skills are utterly, utterly wasted b) my daughter gets extremely upset because i won't be at home. so you get the gist, and thank you for putting up with me needing to take this action. l. From see.my.homepage at gmail.com Wed Sep 1 08:37:10 2010 From: see.my.homepage at gmail.com (Maciej Sobczak) Date: Wed, 1 Sep 2010 05:37:10 -0700 (PDT) Subject: YAMI4 v. 1.1.0 - messaging solution for distributed systems Message-ID: I am pleased to announce that the new version of YAMI4, 1.1.0, has been just released and is available for download. http://www.inspirel.com/yami4/ This new version extends the coverage of supported programming languages with a completely new Python3 module, which allows full integration of built-in dictionary objects as message payloads. Thanks to this level of language integration, the API is very easy to learn and natural in use. Please check code examples in the src/python/examples directory to see complete client-server systems. The users of other programming languages will also benefit from the ability to transmit raw binary messages, which in addition to support high-performance scenarios can be used as a hook for custom serialization routines. The API of the whole library was also extended a bit to allow better control of automatic reconnection and to ensure low jitter in communication involving many receivers even in case of partial system failure. Last but not least, a number of fixes and improvements have been introduced - please see the changelog.txt file, which is part of the whole package, for a detailed description of all improvements. -- Maciej Sobczak * http://www.inspirel.com From victorsubervi at gmail.com Wed Sep 1 09:00:03 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 1 Sep 2010 09:00:03 -0400 Subject: Reversing a List Message-ID: Hi; I have this code: cursor.execute('describe products;') cols = [item[0] for item in cursor] cols = cols.reverse() cols.append('Delete') cols = cols.reverse() Unfortunately, the list doesn't reverse. If I print cols after the first reverse(), it prints None. Please advise. Also, is there a way to append to the front of the list directly? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From bussiere at gmail.com Wed Sep 1 09:02:51 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Wed, 1 Sep 2010 15:02:51 +0200 Subject: [Pickle]dirty problem 3 lines In-Reply-To: <4C7DC74D.6060702@mrabarnett.plus.com> References: <4C7DC74D.6060702@mrabarnett.plus.com> Message-ID: it's just as it seems : i want to know how does ti works to get back an object from a string in python : pickle.loads("""b'\x80\x03]q\x00(K\x00K\x01e.'""") #doesn't work Google Fan boy On Wed, Sep 1, 2010 at 5:23 AM, MRAB wrote: > On 01/09/2010 03:33, bussiere bussiere wrote: >> >> i know it's dirty, i know i should use json but i want to know, it's >> quiet late here : >> import pickle >> dump = """b'\x80\x03]q\x00(K\x00K\x01e.'""" >> print(pickle.loads(dump)) >> >> how can i get back my object from this string ? >> the string is : ?b'\x80\x03]q\x00(K\x00K\x01e.' >> and i'am using python3 >> help will be appreciated i'am chewing on this for a long time now. > > Well, pickle.loads(b'\x80\x03]q\x00(K\x00K\x01e.') works. > > That, of course, is not the same as """b'\x80\x03]q\x00(K\x00K\x01e.'""". > > Do you mean r"""b'\x80\x03]q\x00(K\x00K\x01e.'"""? > > (It's also late here, well, actually, so late it's early... Time to > sleep. :-)) > -- > http://mail.python.org/mailman/listinfo/python-list > From matt at scotweb.co.uk Wed Sep 1 09:15:54 2010 From: matt at scotweb.co.uk (Matt Saxton) Date: Wed, 1 Sep 2010 14:15:54 +0100 Subject: Reversing a List In-Reply-To: References: Message-ID: <20100901141554.a8d606f0.matt@scotweb.co.uk> On Wed, 1 Sep 2010 09:00:03 -0400 Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('describe products;') > cols = [item[0] for item in cursor] > cols = cols.reverse() > cols.append('Delete') > cols = cols.reverse() > > Unfortunately, the list doesn't reverse. If I print cols after the first > reverse(), it prints None. Please advise. The reverse() method modifies the list in place, but returns None, so just use >>> cols.reverse() rather than >>> cols = cols.reverse() > Also, is there a way to append to > the front of the list directly? > TIA, > beno The insert() method can do this, i.e. >>> cols.insert(0, 'Delete') -- Matt Saxton From shashank.sunny.singh at gmail.com Wed Sep 1 09:17:34 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Wed, 1 Sep 2010 18:47:34 +0530 Subject: Reversing a List In-Reply-To: References: Message-ID: reverse reverses in-place >>> l = [1, 2, 3] >>> r = l.reverse() >>> r is None True >>> l [3, 2, 1] >>> On Wed, Sep 1, 2010 at 6:30 PM, Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('describe products;') > cols = [item[0] for item in cursor] > cols = cols.reverse() > cols.append('Delete') > cols = cols.reverse() > > Unfortunately, the list doesn't reverse. If I print cols after the first > reverse(), it prints None. Please advise. Also, is there a way to append to > the front of the list directly? > TIA, > beno > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Sep 1 09:21:17 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 1 Sep 2010 09:21:17 -0400 Subject: Reversing a List In-Reply-To: References: Message-ID: On Wed, Sep 1, 2010 at 9:17 AM, Shashank Singh < shashank.sunny.singh at gmail.com> wrote: > reverse reverses in-place > > >>> l = [1, 2, 3] > >>> r = l.reverse() > >>> r is None > True > >>> l > [3, 2, 1] > >>> > Ah. Thanks! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert at spenarnc.xs4all.nl Wed Sep 1 09:22:52 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 Sep 2010 13:22:52 GMT Subject: Fibonacci: How to think recursively References: <890665ce-4df5-4a6d-b18b-9170d743bd55@a36g2000yqc.googlegroups.com> Message-ID: In article , Mel wrote: >Baba wrote: > >> Level: beginner >> >> I would like to know how to approach the following Fibonacci problem: >> How may rabbits do i have after n months? >> >> I'm not looking for the code as i could Google that very easily. I'm >> looking for a hint to put me on the right track to solve this myself >> without looking it up. >> >> my brainstorming so far brought me to a stand still as i can't seem to >> imagine a recursive way to code this: >> >> my attempted rough code: >> >> def fibonacci(n): >> # base case: >> result = fibonacci (n-1) + fibonacci (n-2) >>>> this will end up in a mess as it will create overlapping recursions > >I don't think this is the base case. The base case would be one or more >values of `n` that you already know the fibonacci number for. Your >recursive function can just test for those and return the right answer right >away. The the expression you've coded contains a good way to handle the >non-base cases. There's no such problem as "overlapping recursions". [Didn't you mean: I don't understand what you mean by overlapping recursions? You're right about the base case, so clearly the OP uses some confusing terminology.] I see a problem with overlapping recursions. Unless automatic memoizing is one, they are unduely inefficient, as each call splits into two calls. If one insists on recursion (untested code, just for the idea.). def fib2( n ): ' return #rabbits last year, #rabbits before last ' if n ==1 : return (1,1) else penult, ult = fib2( n-1 ) return ( ult, ult+penult) def fub( n ): return fib2(n)[1] Try fib and fub for largish numbers (>1000) and you'll feel the problem. > > Mel. > Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From lie.1296 at gmail.com Wed Sep 1 09:25:13 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 01 Sep 2010 23:25:13 +1000 Subject: Optimising literals away In-Reply-To: References: <69a8fbbc-5f45-491a-adf3-2fb5a4d79660@s9g2000yqd.googlegroups.com> <4C7D79EE.8010402@mrabarnett.plus.com> Message-ID: <4c7e3ef6$1@dnews.tpgi.com.au> On 09/01/10 17:06, Stefan Behnel wrote: > MRAB, 31.08.2010 23:53: >> On 31/08/2010 21:18, Terry Reedy wrote: >>> On 8/31/2010 12:33 PM, Aleksey wrote: >>>> On Aug 30, 10:38 pm, Tobias Weber wrote: >>>>> Hi, >>>>> whenever I type an "object literal" I'm unsure what optimisation >>>>> will do >>>>> to it. >>> >>> Optimizations are generally implentation dependent. CPython currently >>> creates numbers, strings, and tuple literals just once. Mutable literals >>> must be created each time as they may be bound and saved. >>> >>>>> def m(arg): >>>>> if arg& set([1,2,3]): >>> >>> set() is a function call, not a literal. When m is called, who knows >>> what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, >>> which is much faster as it avoids creating and deleting a list. On my >>> machine, .35 versus .88 usec. Even then, it must be calculated each time >>> because sets are mutable and could be returned to the calling code. >>> >> There's still the possibility of some optimisation. If the resulting >> set is never stored anywhere (bound to a name, for example) then it >> could be created once. When the expression is evaluated there could be >> a check so see whether 'set' is bound to the built-in class, and, if it >> is, then just use the pre-created set. What if the set is mutated by the function? That will modify the global cache of the set; one way to prevent mutation is to use frozenset, but from the back of my mind, I think there was a discussion that rejects set literals producing a frozen set instead of regular set. > Cython applies this kind of optimistic optimisation in a couple of other > cases and I can affirm that it often makes sense to do that. However, > drawback here: the set takes up space while not being used (not a huge > problem if literals are expected to be small), and the global lookup of > "set" still has to be done to determine if it *is* the builtin set type. > After that, however, the savings should be considerable. > > Another possibility: always cache the set and create a copy on access. > Copying a set avoids the entire eval loop overhead and runs in a C loop > instead, using cached item instances with (most likely) cached hash > values. So even that will most likely be much faster than the > spelled-out code above. I think that these kind of optimizations would probably be out-of-character for CPython, which values implementation simplicity above small increase in speed. Sets are not that much used and optimizing this particular case seems to be prone to create many subtle issues (especially with multithreading). In other word, these optimizations makes sense for Python implementations that are heavily geared for speed (e.g. Unladen Swallow, Stackless Python, PyPy[1], Cython); but probably may only have a minuscule chance of being implemented in CPython. [1] yes, their goal was to be faster than CPython (and faster than the speed of photon in vacuum), though AFAICT they have yet to succeed. From anand.shashwat at gmail.com Wed Sep 1 09:26:36 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 1 Sep 2010 18:56:36 +0530 Subject: Reversing a List In-Reply-To: <20100901141554.a8d606f0.matt@scotweb.co.uk> References: <20100901141554.a8d606f0.matt@scotweb.co.uk> Message-ID: On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton wrote: > On Wed, 1 Sep 2010 09:00:03 -0400 > Victor Subervi wrote: > > > Hi; > > I have this code: > > > > cursor.execute('describe products;') > > cols = [item[0] for item in cursor] > > cols = cols.reverse() > > cols.append('Delete') > > cols = cols.reverse() > > > > Unfortunately, the list doesn't reverse. If I print cols after the first > > reverse(), it prints None. Please advise. > > The reverse() method modifies the list in place, but returns None, so just > use > >>> cols.reverse() > > rather than > >>> cols = cols.reverse() > Alternatively you can do \, >>>cols = reversed(cols) > > > Also, is there a way to append to > > the front of the list directly? > > TIA, > > beno > > The insert() method can do this, i.e. > >>> cols.insert(0, 'Delete') > > -- > Matt Saxton > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Sep 1 09:30:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Sep 2010 15:30:21 +0200 Subject: Performance: sets vs dicts. In-Reply-To: <4c7e43ef$1@dnews.tpgi.com.au> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <878w3ogpvq.fsf@benfinney.id.au> <4c7e43ef$1@dnews.tpgi.com.au> Message-ID: Lie Ryan, 01.09.2010 15:46: > On 09/01/10 00:09, Aahz wrote: >> However, I think there are some rock-bottom basic guarantees we can make >> regardless of implementation. Does anyone seriously think that an >> implementation would be accepted that had anything other than O(1) for >> index access into tuples and lists? Dicts that were not O(1) for access >> with non-pathological hashing? That we would accept sets having O() >> performance worse than dicts? >> >> I suggest that we should agree on these guarantees and document them in >> the core. > > While I think documenting them would be great for all programmers that > care about practical and theoretical execution speed; I think including > these implementation details in core documentation as a "guarantee" > would be a bad idea for the reasons Terry outlined. > > One way of resolving that is by having two documentations (or two > separate sections in the documentation) for: > - Python -- the language -- documenting Python as an abstract language, > this is the documentation which can be shared across all Python > implementations. This will also be the specification for Python Language > which other implementations will be measured to. > - CPython -- the Python interpreter -- documents implementation details > and performance metrics. It should be properly noted that these are not > part of the language per se. This will be the playground for CPython > experts that need to fine tune their applications to the last drop of > blood and don't mind their application going nuts with the next release > of CPython. I disagree. I think putting the "obvious" guarantees right into the normal documentation will actually make programmers aware that there *are* different implementations (and differences between implementations), simply because it wouldn't just say "O(1)" but "the CPython implementation of this method has an algorithmic complexity of O(1), other Python implementations are known to perform alike at the time of this writing". Maybe without the last half of the sentence if we really don't know how other implementations work here, or if we expect that there may well be a reason they may choose to behave different, but in most cases, it shouldn't be hard to make that complete statement. After all, we basically know what other implementations there are, and we also know that they tend to match the algorithmic complexities at least for the major builtin types. It seems quite clear to me as a developer that the set of builtin types and "collections" types was chosen in order to cover a certain set of algorithmic complexities and not just arbitrary interfaces. Stefan From davea at ieee.org Wed Sep 1 09:35:53 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 01 Sep 2010 09:35:53 -0400 Subject: Reversing a List In-Reply-To: References: Message-ID: <4C7E56B9.6070408@ieee.org> Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('describe products;') > cols = [item[0] for item in cursor] > cols = cols.reverse() > cols.append('Delete') > cols = cols.reverse() > > Unfortunately, the list doesn't reverse. If I print cols after the first > reverse(), it prints None. Please advise. Also, is there a way to append to > the front of the list directly? > TIA, > beno > > The reverse() method reverses that cols object just fine, in place. Unfortunately, you immediately assign it a new value of None. Just remove the cols= and it'll work fine. If you want to understand the problem better, read up on reverse() and reversed(). They're very different. In answer to your second question, you could combine the last three lines as: cols.insert('Delete', 0) DaveA From cutebhavanaa at gmail.com Wed Sep 1 09:41:09 2010 From: cutebhavanaa at gmail.com (sexy girl) Date: Wed, 1 Sep 2010 06:41:09 -0700 (PDT) Subject: ***SEX IN COLLEGE HOT AND SEXY VIDEOS*** Message-ID: <5d5f018b-1da1-40c8-9d9b-e0848c53b85d@y32g2000prc.googlegroups.com> http://cute-actress-images.blogspot.com/ http://cute-sexy-images.blogspot.com/ http://actress.0jet.com http://factson-globalwarming.blogspot.com/ http://mysteries-that-threats.blogspot.com/ http://healthtips.06fr.com http://actress.0jet.com http://dailyscience.youblog.net http://jobs4all.menblogs.net http://healthtips.06fr.com http://dailyscience.youblog.net http://jobs4all.menblogs.net http://schoolsuniversities.web-day.net http://cute-actress-images.blogspot.com/ http://science-vs-technology.blogspot.com/ http://my-jobs-4-u.blogspot.com/ http://cute-sexy-images.blogspot.com/ From lie.1296 at gmail.com Wed Sep 1 09:46:26 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 01 Sep 2010 23:46:26 +1000 Subject: Performance: sets vs dicts. In-Reply-To: References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <878w3ogpvq.fsf@benfinney.id.au> Message-ID: <4c7e43ef$1@dnews.tpgi.com.au> On 09/01/10 00:09, Aahz wrote: > In article , > Jerry Hill wrote: >> On Mon, Aug 30, 2010 at 7:42 PM, Aahz wrote: >>> >>> Possibly; IMO, people should not need to run timeit to determine basic >>> algorithmic speed for standard Python datatypes. >> >> http://wiki.python.org/moin/TimeComplexity takes a stab at it. IIRC, >> last time this came up, there was some resistance to making promises >> about time complexity in the official docs, since that would make >> those numbers part of the language, and thus binding on other >> implementations. > > I'm thoroughly aware of that page and updated it yesterday to make it > easier to find. ;-) > > However, I think there are some rock-bottom basic guarantees we can make > regardless of implementation. Does anyone seriously think that an > implementation would be accepted that had anything other than O(1) for > index access into tuples and lists? Dicts that were not O(1) for access > with non-pathological hashing? That we would accept sets having O() > performance worse than dicts? > > I suggest that we should agree on these guarantees and document them in > the core. While I think documenting them would be great for all programmers that care about practical and theoretical execution speed; I think including these implementation details in core documentation as a "guarantee" would be a bad idea for the reasons Terry outlined. One way of resolving that is by having two documentations (or two separate sections in the documentation) for: - Python -- the language -- documenting Python as an abstract language, this is the documentation which can be shared across all Python implementations. This will also be the specification for Python Language which other implementations will be measured to. - CPython -- the Python interpreter -- documents implementation details and performance metrics. It should be properly noted that these are not part of the language per se. This will be the playground for CPython experts that need to fine tune their applications to the last drop of blood and don't mind their application going nuts with the next release of CPython. From albert at spenarnc.xs4all.nl Wed Sep 1 09:46:32 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 Sep 2010 13:46:32 GMT Subject: Saving (unusual) linux filenames References: Message-ID: In article , Grant Edwards wrote: >On 2010-08-31, MRAB wrote: >> On 31/08/2010 17:58, Grant Edwards wrote: >>> On 2010-08-31, MRAB wrote: >>>> On 31/08/2010 15:49, AmFreak at web.de wrote: >>>>> Hi, >>>>> >>>>> i have a script that reads and writes linux paths in a file. I save the >>>>> path (as unicode) with 2 other variables. I save them seperated by "," >>>>> and the "packets" by newlines. So my file looks like this: >>>>> path1, var1A, var1B >>>>> path2, var2A, var2B >>>>> path3, var3A, var3B >>>>> .... >>>>> >>>>> this works for "normal" paths but as soon as i have a path that does >>>>> include a "," it breaks. The problem now is that (afaik) linux allows >>>>> every char (aside from "/" and null) to be used in filenames. The only >>>>> solution i can think of is using null as a seperator, but there have to >>>>> a cleaner version ? >>>> >>>> You could use a tab character '\t' instead. >>> >>> That just breaks with a different set of filenames. >>> >> How many filenames contain control characters? > >How many filenames contain ","? Not many, but the OP wants his >program to be bulletproof. Can't fault him for that. As appending ",v" is the convention for rcs / cvs archives, I would say: a lot. Enough to guarantee that all my backup tar's contain at least a few. > >If I had a nickle for every Unix program or shell-script that failed >when a filename had a space it it.... I'd rather have it fail for spaces than for comma's. > >> Surely that's a bad idea. > >Of course it's a bad idea. That doesn't stop people from doing it. > >-- >Grant Edwards grant.b.edwards Yow! ! Now I understand > at advanced MICROBIOLOGY and > gmail.com th' new TAX REFORM laws!! -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From ben+python at benfinney.id.au Wed Sep 1 10:10:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 02 Sep 2010 00:10:27 +1000 Subject: fairly urgent request: paid python (or other) work required References: Message-ID: <87r5hdftbg.fsf@benfinney.id.au> lkcl writes: > i apologise for having to contact so many people but this is fairly > urgent, and i'm running out of time and options. [?] I sympathise with your situation; work for skilled practicioners is scarce in many places right now. For that reason, many people are likely to be in your position. For the sake of keeping this forum habitable, I have to point out to anyone reading: It's not cool to post requests for work here. There are, as you noted, other appropriate forums for that, of which this is not one. I wish you success in finding gainful work, but all readers should please note that this is *not* the place to look for it. -- \ ?Sittin' on the fence, that's a dangerous course / You can even | `\ catch a bullet from the peace-keeping force? ?Dire Straits, | _o__) _Once Upon A Time In The West_ | Ben Finney From neilc at norwich.edu Wed Sep 1 10:19:07 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 1 Sep 2010 14:19:07 GMT Subject: Fibonacci: How to think recursively References: <890665ce-4df5-4a6d-b18b-9170d743bd55@a36g2000yqc.googlegroups.com> Message-ID: <8e75mqFbtuU1@mid.individual.net> On 2010-09-01, Albert van der Horst wrote: > [Didn't you mean: I don't understand what you mean by > overlapping recursions? You're right about the base case, so > clearly the OP uses some confusing terminology.] > > I see a problem with overlapping recursions. Unless automatic > memoizing is one, they are unduely inefficient, as each call > splits into two calls. > > If one insists on recursion (untested code, just for the idea.). > > def fib2( n ): > ' return #rabbits last year, #rabbits before last ' > if n ==1 : > return (1,1) > else > penult, ult = fib2( n-1 ) > return ( ult, ult+penult) > > def fub( n ): > return fib2(n)[1] > > Try fib and fub for largish numbers (>1000) and you'll feel the > problem. There are standard tricks for converting a recursive iteration into a tail-recursive one. It's usually done by adding the necessary parameters, e.g.: def fibr(n): def fib_helper(fibminus2, fibminus1, i, n): if i == n: return fibminus2 + fibminus1 else: return fib_helper(fibminus1, fibminus1 + fibminus2, i+1, n) if n < 2: return 1 else: return fib_helper(1, 1, 2, n) Once you've got a tail-recursive solution, you can usually convert it to loop iteration for languages like Python that favor them. The need for a temporary messed me up. def fibi(n): if n < 2: return 1 else: fibminus2 = 1 fibminus1 = 1 i = 2 while i < n: fibminus2, fibminus1 = fibminus1, fibminus2 + fibminus1 i += 1 return fibminus2 + fibminus1 It's interesting that the loop iterative solution is, for me, harder to think up without doing the tail-recursive one first. -- Neil Cerutti From python.koda at gmail.com Wed Sep 1 10:47:49 2010 From: python.koda at gmail.com (Alban Nona) Date: Wed, 1 Sep 2010 10:47:49 -0400 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: Hello, So I figure out this night how to create automatically varibales via vars(), the script seems to work, exept that where it should give me a list like : [ELM004_DIF,ELM004_SPC,ELM004_RFL,ELM004_SSS, ELM004_REFR, ELM004_ALB, etc...] it gave me just one entry in my list, and the last one [ELM004_WPP] Any Ideas why that please ? http://pastebin.com/7CDbVgdD 2010/9/1 Xavier Ho > On 1 September 2010 12:00, Alban Nona wrote: > >> @Xavier: ShaDoW, WorldPositionPoint (which is the same thing as >> WordPointCloud passe) :) >> > > Aha! That's what I was missing. > > Cheers, > Xav > -------------- next part -------------- An HTML attachment was scrubbed... URL: From contact at xavierho.com Wed Sep 1 11:05:12 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 2 Sep 2010 01:05:12 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: On 2 September 2010 00:47, Alban Nona wrote: > Hello, > > So I figure out this night how to create automatically varibales via > vars(), the script seems to work, exept that where it should give me a list > like : > [ELM004_DIF,ELM004_SPC,ELM004_RFL,ELM004_SSS, ELM004_REFR, ELM004_ALB, > etc...] it gave me just one entry in my list, and the last one [ELM004_WPP] > Any Ideas why that please ? > > http://pastebin.com/7CDbVgdD Some comments: 1) Avoid overwriting global functions like list as a variable name. If you do that, you won't be able to use list() later in your code, and nor can anyone else who imports your code. 2) I'm a bit iffy about automatic variable generations. Why not just use a dictionary? What do others on comp.lang.python think? 3) I'm getting an error from your code, and it doesn't match with what you seem to get: # output ELM004_DIF ELM004_SPC ELM004_RFL ELM004_SSS ELM004_REFR ELM004_ALB ELM004_AMB ELM004_NRM ELM004_MVE ELM004_DPF ELM004_SDW ELM004_MAT ELM004_WPP Traceback (most recent call last): File "Test.py", line 33, in print ELM001 NameError: name 'ELM001' is not defined Did you get any compiler errors? I'm using Python 2.7 Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.koda at gmail.com Wed Sep 1 11:11:31 2010 From: python.koda at gmail.com (Alban Nona) Date: Wed, 1 Sep 2010 11:11:31 -0400 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: Hello, seems to have the same error with python. In fact I was coding within nuke, a 2d compositing software (not the best) unfortunately, I dont see how I can use dictionnary to do what I would like to do. 2010/9/1 Xavier Ho > On 2 September 2010 00:47, Alban Nona wrote: > >> Hello, >> >> So I figure out this night how to create automatically varibales via >> vars(), the script seems to work, exept that where it should give me a list >> like : >> [ELM004_DIF,ELM004_SPC,ELM004_RFL,ELM004_SSS, ELM004_REFR, ELM004_ALB, >> etc...] it gave me just one entry in my list, and the last one [ELM004_WPP] >> Any Ideas why that please ? >> >> http://pastebin.com/7CDbVgdD > > > Some comments: > > 1) Avoid overwriting global functions like list as a variable name. If you > do that, you won't be able to use list() later in your code, and nor can > anyone else who imports your code. > 2) I'm a bit iffy about automatic variable generations. Why not just use a > dictionary? What do others on comp.lang.python think? > 3) I'm getting an error from your code, and it doesn't match with what you > seem to get: > > # output > > ELM004_DIF > ELM004_SPC > ELM004_RFL > ELM004_SSS > ELM004_REFR > ELM004_ALB > ELM004_AMB > ELM004_NRM > ELM004_MVE > ELM004_DPF > ELM004_SDW > ELM004_MAT > ELM004_WPP > Traceback (most recent call last): > File "Test.py", line 33, in > print ELM001 > NameError: name 'ELM001' is not defined > > Did you get any compiler errors? I'm using Python 2.7 > > Cheers, > Xav > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lkcl at lkcl.net Wed Sep 1 11:14:41 2010 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 1 Sep 2010 16:14:41 +0100 Subject: [ANN] git peer-to-peer bittorrent experiment: first milestone reached Message-ID: http://gitorious.org/python-libbittorrent/pybtlib this is to let people know that a first milestone has been reached in an experiment to combine git with a file-sharing protocol, thus making it possible to use git for truly distributed software development and other file-revision-management operations (such as transparently turning git-configured ikiwiki and moinmoin wikis into peer-to-peer ones). the milestone reached is to transfer git commit "pack objects", as if they were ordinary files, over a bittorrent network, and have them "unpacked" at the far end. the significance of being able to transfer git commit pack objects is that this is the core of the "git fetch" command. the core of this experiment comprises a python-based VFS layer, providing alternatives to os.listdir, os.path.exists, open and so on - sufficient to make an interesting experiment itself by combining that VFS layer with e.g. python-fuse. the bittornado library, also available at the above URL, has been modified to take a VFS module as an argument to all operations, such that it would be conceivable to share maildir mailboxes, mailing list archives, .tar.gz archives, .deb and .rpm archives and so on, as if they were files and directories within a file-sharing network. as the core code has only existed for under three days, and is only 400 lines long, there are rough edges: * all existing commit objects are unpacked at startup time and are stored in-memory (!). this is done so as to avoid significant modification of the bittorrent library, which will be required. * all transferred commit objects are again stored in-memory before being unpacked. so, killing the client will lose all transfers received up to that point. on the roadmap: * make things efficient! requires modification of the bittornado library. * create some documentation! * explore how to make git use this code as a new URI type so that it will be possible to just do "git pull" * explore how to use PGP/GPG to sign commits(?) or perhaps just tags(?) in order to allow commits to be pulled only from trusted parties. * share all branches and tags as well as just refs/heads/* * make "git push" re-create the .torrent (make_torrent.py) and work out how to notify seeders of a new HEAD (name the torrent after the HEAD ref, and just create a new one rather than delete the old?) so there is quite a bit to do, with the priority being on making a new URI type and a new "git-remote-{URI}" command, so that this becomes actually useable rather than just an experiment, and the project can be self-hosting as a truly distributed peer-to-peer development effort. if anyone would like to assist, you only have to ask and (ironically) i will happily grant access to the gitorious-hosted repository. if anyone would like to sponsor this project, that would be very timely, as if i don't get some money soon i will be unable to pay for food and rent. l. From aahz at pythoncraft.com Wed Sep 1 11:40:37 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Sep 2010 08:40:37 -0700 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: In article , Jerry Hill wrote: >On Tue, Aug 31, 2010 at 10:09 AM, Aahz wrote: >> >> I suggest that we should agree on these guarantees and document them in >> the core. > >I can't get to the online python-dev archives from work (stupid >filter!) so I can't give you a link to the archives, but the original >thread that resulted in the creation of that wiki page was started on >March 9th, 2008 and was titled "Complexity documentation request". http://mail.python.org/pipermail/python-dev/2008-March/077499.html >At the time, opposition to formally documenting this seemed pretty >widespread, including from yourself and Guido. You've obviously >changed your mind on the subject, so maybe it's something that would >be worth revisiting, assuming someone wants to write the doc change. Looking back at that thread, it's less that I've changed my mind as that I've gotten a bit more nuanced. I still think that making a full set of algorithmic guarantees is a Bad Idea, but I think that any implementation that doesn't have O(1) for list element access is fundamentally broken, and we should probably document that somewhere. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From stefan_ml at behnel.de Wed Sep 1 11:55:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Sep 2010 17:55:48 +0200 Subject: [ANN] git peer-to-peer bittorrent experiment: first milestone reached In-Reply-To: References: Message-ID: Luke Kenneth Casson Leighton, 01.09.2010 17:14: > this is to let people know that a first milestone has been reached in > an experiment to combine git with a file-sharing protocol, thus making > it possible to use git for truly distributed software development Basically, BitTorrent only works well when there are enough people who share a common interest at the same time. Why would you think that is the case for software development, and what minimum project size would you consider reasonable to make this tool a valid choice? If you're more like targeting in-house development, it could become a little boring to be the first who arrives in the morning ... Stefan From stefan_ml at behnel.de Wed Sep 1 11:57:43 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Sep 2010 17:57:43 +0200 Subject: Performance: sets vs dicts. In-Reply-To: References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: Aahz, 01.09.2010 17:40: > I still think that making a full set of > algorithmic guarantees is a Bad Idea, but I think that any implementation > that doesn't have O(1) for list element access is fundamentally broken, > and we should probably document that somewhere. +1 Stefan From ron.eggler at gmail.com Wed Sep 1 11:58:43 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 1 Sep 2010 08:58:43 -0700 (PDT) Subject: DeprecationWarning Message-ID: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Hi There, I would like to create an scp handle and download a file from a client. I have following code: import sys, os, paramiko,time from attachment import SCPClient transport = paramiko.Transport((prgIP, 22)) try: transport.connect(username='root', password=prgPass) except IOError: print "Transport connect timed out" writelog(" Transport connect timed out. \n") sys.exit() scp = SCPClient(transport) writelog("Succesfully created scp transport handle to get P-file \n") # Create '/tmp/autokernel' if it does not exist. if not os.access('./PRGfiles', os.F_OK): os.mkdir('./PRGfiles') try: scp.get("/usr/share/NovaxTSP/P0086_2003.xml","./PRGfiles/ P0086_2003.xml") writelog("succesfully downloaded P-file \n") except IOError: writelog("Downloading P-file failed. \n") but what i'm getting is this and no file is downloaded...: /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 chan.send('\x01'+e.message) 09/01/2010 08:53:56 : Downloading P-file failed. What does that mean and how do i resolve this? Thank you! Ron From ipatrol6010 at yahoo.com Wed Sep 1 12:01:39 2010 From: ipatrol6010 at yahoo.com (ipatrol6010 at yahoo.com) Date: Wed, 1 Sep 2010 12:01:39 -0400 Subject: Better multiprocessing and data persistance with C level serialisation Message-ID: I was thinking about this for a while. Owing to a lack of forking or START/STOP signals, all process interchange in CPython requires serialisation, usually pickling. But what if that could be done within the interpreter core instead of by the script, creating a complete internal representation that can then be read by the child interpreter. Any comments/ideas/suggestions? From contact at xavierho.com Wed Sep 1 12:37:03 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 2 Sep 2010 02:37:03 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: On 2 September 2010 01:11, Alban Nona wrote: > Hello, > > seems to have the same error with python. > In fact I was coding within nuke, a 2d compositing software (not the best) > unfortunately, I dont see how I can use dictionnary to do what I would like > to do. > Hello Alban, The reason it's printing only the ELM004 elements is because the variable, first, is 'ELM004' when your code goes to line 29. I noticed you're using variables created from the for loop out of its block as well. Personally I wouldn't recommend it as good practice. There are ways around it. Could you explain briefly what you want to achieve with this program? What's the desired sample output? Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.koda at gmail.com Wed Sep 1 12:49:57 2010 From: python.koda at gmail.com (Alban Nona) Date: Wed, 1 Sep 2010 12:49:57 -0400 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: Hello Xavier, Thank you :) Well what Iam trying to generate is that kind of result: listn1=['ELM001_DIF', 'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT', 'ELM001_WPP'] listn2 = ['ELM002_DIF', 'ELM002_SPC', 'ELM002_RFL', 'ELM002_SSS', 'ELM002_REFR', 'ELM002_ALB', 'ELM002_AMB', 'ELM002_NRM', 'ELM002_MVE', 'ELM002_DPF', 'ELM002_SDW', 'ELM002_MAT', 'ELM002_WPP'] etc... The thing is, the first list will be generated automatically. (so there will be unknow versions of ELM00x....) that why Im trying to figure out how to genere variable and list in an automatic way. Can you tell me if its not clear please ? :P my english still need improvement when Im trying to explain scripting things. 2010/9/1 Xavier Ho > On 2 September 2010 01:11, Alban Nona wrote: > >> Hello, >> >> seems to have the same error with python. >> In fact I was coding within nuke, a 2d compositing software (not the best) >> unfortunately, I dont see how I can use dictionnary to do what I would >> like to do. >> > > Hello Alban, > > The reason it's printing only the ELM004 elements is because the variable, > first, is 'ELM004' when your code goes to line 29. > > I noticed you're using variables created from the for loop out of its block > as well. Personally I wouldn't recommend it as good practice. There are ways > around it. > > Could you explain briefly what you want to achieve with this program? > What's the desired sample output? > > Cheers, > Xav > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.koda at gmail.com Wed Sep 1 12:49:57 2010 From: python.koda at gmail.com (Alban Nona) Date: Wed, 1 Sep 2010 12:49:57 -0400 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: Hello Xavier, Thank you :) Well what Iam trying to generate is that kind of result: listn1=['ELM001_DIF', 'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT', 'ELM001_WPP'] listn2 = ['ELM002_DIF', 'ELM002_SPC', 'ELM002_RFL', 'ELM002_SSS', 'ELM002_REFR', 'ELM002_ALB', 'ELM002_AMB', 'ELM002_NRM', 'ELM002_MVE', 'ELM002_DPF', 'ELM002_SDW', 'ELM002_MAT', 'ELM002_WPP'] etc... The thing is, the first list will be generated automatically. (so there will be unknow versions of ELM00x....) that why Im trying to figure out how to genere variable and list in an automatic way. Can you tell me if its not clear please ? :P my english still need improvement when Im trying to explain scripting things. 2010/9/1 Xavier Ho > On 2 September 2010 01:11, Alban Nona wrote: > >> Hello, >> >> seems to have the same error with python. >> In fact I was coding within nuke, a 2d compositing software (not the best) >> unfortunately, I dont see how I can use dictionnary to do what I would >> like to do. >> > > Hello Alban, > > The reason it's printing only the ELM004 elements is because the variable, > first, is 'ELM004' when your code goes to line 29. > > I noticed you're using variables created from the for loop out of its block > as well. Personally I wouldn't recommend it as good practice. There are ways > around it. > > Could you explain briefly what you want to achieve with this program? > What's the desired sample output? > > Cheers, > Xav > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Sep 1 12:52:09 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Sep 2010 18:52:09 +0200 Subject: Newby Needs Help with Python code References: <861505.20099.qm@web33506.mail.mud.yahoo.com> Message-ID: Nally Kaunda-Bukenya wrote: > I hope someone can help me. I am new to Python and trying to achive the > following: > 1) I would like to populate the Tot_Ouf_Area field with total area of > each unique outfall_id (code attempted below,but Tot_Ouf_Area not > populating) > 2) I would also like to get the user input of Rv ( each > landuse type will have a specific Rv value). For example the program > should ask the user for Rv value of Low Density Residential (user enters > 0.4 in example below and that value must be stored in the Rv field), and > so on as shown in the 2nd table below? I don't know arcgis, so the following is just guesswork. I iterate over the Outfalls_ND table twice, the first time to calculate the sums per OUTFALL_ID and put them into a dict. With the second pass the Tot_Outf_Area column is updated import arcgisscripting def rows(cur): while True: row = cur.Next() if row is None: break yield row gp = arcgisscripting.create() gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb" TABLE = "Outfalls_ND" GROUP = "OUTFALL_ID" SUM = "AREA_ACRES" TOTAL = "Tot_Outf_Area" aggregate = {} cur = gp.UpdateCursor(TABLE) for row in rows(cur): group = row.GetValue(GROUP) amount = row.GetValue(SUM) aggregate[group] = aggregate.get(group, 0.0) + amount cur = gp.UpdateCursor(TABLE) for row in rows(cur): group = row.GetValue(GROUP) row.SetValue(TOTAL, aggregate[group]) cur.UpdateRow(row) As this is written into the blue it is unlikely that it runs successfully without changes. Just try and report back the results. Peter From ron.eggler at gmail.com Wed Sep 1 12:56:18 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 1 Sep 2010 09:56:18 -0700 (PDT) Subject: scp with paramiko Message-ID: <8bfa00e7-2ae5-42a3-bb45-fcdb491d70e4@x18g2000pro.googlegroups.com> Hi There, I want to download a file from a client using paramiko. I found plenty of ressources using google on how to send a file but none that would describe how to download files from a client. Help would be appreciated! Thanks a lot! Ron From python at mrabarnett.plus.com Wed Sep 1 12:59:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Sep 2010 17:59:49 +0100 Subject: Optimising literals away In-Reply-To: <4c7e3ef6$1@dnews.tpgi.com.au> References: <69a8fbbc-5f45-491a-adf3-2fb5a4d79660@s9g2000yqd.googlegroups.com> <4C7D79EE.8010402@mrabarnett.plus.com> <4c7e3ef6$1@dnews.tpgi.com.au> Message-ID: <4C7E8685.4090408@mrabarnett.plus.com> On 01/09/2010 14:25, Lie Ryan wrote: > On 09/01/10 17:06, Stefan Behnel wrote: >> MRAB, 31.08.2010 23:53: >>> On 31/08/2010 21:18, Terry Reedy wrote: >>>> On 8/31/2010 12:33 PM, Aleksey wrote: >>>>> On Aug 30, 10:38 pm, Tobias Weber wrote: >>>>>> Hi, >>>>>> whenever I type an "object literal" I'm unsure what optimisation >>>>>> will do >>>>>> to it. >>>> >>>> Optimizations are generally implentation dependent. CPython currently >>>> creates numbers, strings, and tuple literals just once. Mutable literals >>>> must be created each time as they may be bound and saved. >>>> >>>>>> def m(arg): >>>>>> if arg& set([1,2,3]): >>>> >>>> set() is a function call, not a literal. When m is called, who knows >>>> what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, >>>> which is much faster as it avoids creating and deleting a list. On my >>>> machine, .35 versus .88 usec. Even then, it must be calculated each time >>>> because sets are mutable and could be returned to the calling code. >>>> >>> There's still the possibility of some optimisation. If the resulting >>> set is never stored anywhere (bound to a name, for example) then it >>> could be created once. When the expression is evaluated there could be >>> a check so see whether 'set' is bound to the built-in class, and, if it >>> is, then just use the pre-created set. > > What if the set is mutated by the function? That will modify the global > cache of the set; one way to prevent mutation is to use frozenset, but > from the back of my mind, I think there was a discussion that rejects > set literals producing a frozen set instead of regular set. > [snip] I was talking about a use case like the example code, where the set is created, checked, and then discarded. From hennebry at web.cs.ndsu.nodak.edu Wed Sep 1 13:03:43 2010 From: hennebry at web.cs.ndsu.nodak.edu (Mike) Date: Wed, 1 Sep 2010 10:03:43 -0700 (PDT) Subject: Windows vs. file.read Message-ID: I have a ppm file that python 2.5 on Windows XP cannot read completely. Python on linux can read the file with no problem Python on Windows can read similar files. I've placed test code and data here: http://www.cs.ndsu.nodak.edu/~hennebry/ppm_test.zip Within the directory ppm_test, type python ppm_test.py The chunk size commentary occurs only if file.read cannot read enough bytes. The commentary only occurs for the last file. Any ideas? Any ideas that don't require getting rid of Windows? It's not my option. From contact at xavierho.com Wed Sep 1 13:18:13 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 2 Sep 2010 03:18:13 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: On 2 September 2010 02:49, Alban Nona wrote: > Well what Iam trying to generate is that kind of result: > > listn1=['ELM001_DIF', 'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', > 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', > 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT', 'ELM001_WPP'] > > listn2 = ['ELM002_DIF', 'ELM002_SPC', 'ELM002_RFL', 'ELM002_SSS', > 'ELM002_REFR', 'ELM002_ALB', 'ELM002_AMB', 'ELM002_NRM', 'ELM002_MVE', > 'ELM002_DPF', 'ELM002_SDW', 'ELM002_MAT', 'ELM002_WPP'] > > etc... > Have a look at http://www.ideone.com/zlBeB . I took some liberty and renamed some of your variables. I wanted to show you what I (personally) think as good practices in python, from naming conventions to how to use the list and dictionary, and so on. Also, 4-spaces indent. I noticed you have 5 for some reason, but that's none of my business now. I hope my comments explain what they do, and why they are that way. > The thing is, the first list will be generated automatically. (so there > will be unknow versions of ELM00x....) > that why Im trying to figure out how to genere variable and list in an > automatic way. > Yes, that's totally possible. See range() (and xrange(), possibly) in the Python API. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Sep 1 13:22:29 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Sep 2010 18:22:29 +0100 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: <4C7E8BD5.3010300@mrabarnett.plus.com> On 01/09/2010 17:49, Alban Nona wrote: > Hello Xavier, > > Thank you :) > > Well what Iam trying to generate is that kind of result: > > listn1=['ELM001_DIF', 'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', > 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', > 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT', 'ELM001_WPP'] > > listn2 = ['ELM002_DIF', 'ELM002_SPC', 'ELM002_RFL', 'ELM002_SSS', > 'ELM002_REFR', 'ELM002_ALB', 'ELM002_AMB', 'ELM002_NRM', 'ELM002_MVE', > 'ELM002_DPF', 'ELM002_SDW', 'ELM002_MAT', 'ELM002_WPP'] > > etc... > > The thing is, the first list will be generated automatically. (so there > will be unknow versions of ELM00x....) > that why Im trying to figure out how to genere variable and list in an > automatic way. > > Can you tell me if its not clear please ? :P > my english still need improvement when Im trying to explain scripting > things. > [snip] Create a dict in which the key is the "ELEM" part and the value is a list of those entries which begin with that "ELEM" part. For example, if the entry is 'ELEM001_DIF' then the key is 'ELEM001', which is the first 7 characters of entry, or entry[ : 7]. Something like this: elem_dict = {} for entry in list_of_entries: key = entry[ : 7] if key in elem_dict: elem_dict[key].append(entry) else: elem_dict[key] = [entry] From hennebry at web.cs.ndsu.nodak.edu Wed Sep 1 13:31:27 2010 From: hennebry at web.cs.ndsu.nodak.edu (Mike) Date: Wed, 1 Sep 2010 10:31:27 -0700 (PDT) Subject: Fibonacci: How to think recursively References: <890665ce-4df5-4a6d-b18b-9170d743bd55@a36g2000yqc.googlegroups.com> <8e75mqFbtuU1@mid.individual.net> Message-ID: The most straightforward method would be to apply the formula directly. Loop on j computing Fj along the way if n<=1 : return n Fold=0 Fnew=1 for j in range(2,n) : Fold, Fnew = Fnew, Fold+Fnew return Fnew Even simpler: return round(((1+sqrt(5.))/2)**n/sqrt(5.)) From python at mrabarnett.plus.com Wed Sep 1 13:31:50 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Sep 2010 18:31:50 +0100 Subject: Windows vs. file.read In-Reply-To: References: Message-ID: <4C7E8E06.5000202@mrabarnett.plus.com> On 01/09/2010 18:03, Mike wrote: > I have a ppm file that python 2.5 on Windows XP cannot read > completely. > Python on linux can read the file with no problem > Python on Windows can read similar files. > I've placed test code and data here: > http://www.cs.ndsu.nodak.edu/~hennebry/ppm_test.zip > Within the directory ppm_test, type > python ppm_test.py > The chunk size commentary occurs only if file.read cannot read enough > bytes. > The commentary only occurs for the last file. > Any ideas? > Any ideas that don't require getting rid of Windows? > It's not my option. You should open the files in binary mode, not text mode, ie file(path, "rb"). Text mode is the default. Not a problem on *nix because the line ending is newline. From drobinow at gmail.com Wed Sep 1 13:34:06 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 1 Sep 2010 13:34:06 -0400 Subject: Windows vs. file.read In-Reply-To: References: Message-ID: On Wed, Sep 1, 2010 at 1:03 PM, Mike wrote: > I have a ppm file that python 2.5 on Windows XP cannot read > completely. > Python on linux can read the file with no problem > Python on Windows can read similar files. > I've placed test code and data here: > http://www.cs.ndsu.nodak.edu/~hennebry/ppm_test.zip > Within the directory ppm_test, type > python ppm_test.py > The chunk size commentary occurs only if file.read cannot read enough > bytes. > The commentary only occurs for the last file. > Any ideas? > Any ideas that don't require getting rid of Windows? > It's not my option. Open the files in binary mode. i.e., x=Ppm(file("ff48x32.ppm",'rb')) x=Ppm(file("bw48x32.ppm",'rb')) x=Ppm(file("bisonfootball.ppm",'rb')) You were just lucky on the first two files. From a_jtim at bellsouth.net Wed Sep 1 13:46:50 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Wed, 1 Sep 2010 10:46:50 -0700 (PDT) Subject: parsing string into dict Message-ID: Hi, I have a set of strings that are *basically* comma separated, but with the exception that if a comma occur insides curly braces it is not a delimiter. Here's an example: [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] I'd like to parse that into a dictionary (note that 'continued' gets the value 'true'): {'code':'one', 'caption':'{My Analysis for \textbf{t}, Version 1}','continued':'true'} I know and love pyparsing, but for this particular code I need to rely only on the standard library (I'm running 2.7). Here's what I've got, and it works. I wonder if there's a simpler way? thanks, --Tim Arnold The 'line' is like my example above but it comes in without the ending bracket, so I append one on the 6th line. def parse_options(line): options = dict() if not line: return options active = ['[','=',',','{','}',']'] line += ']' key = '' word = '' inner = 0 for c in list(line): if c in active: if c == '{': inner +=1 elif c == '}': inner -=1 if inner: word += c else: if c == '=': (key,word) = (word,'') options[key.strip()] = True elif c in [',', ']']: if not key: options[word.strip()] = True else: options[key.strip()] = word.strip() (key,word) = (False, '') else: word += c return options From sarvilive at gmail.com Wed Sep 1 13:49:39 2010 From: sarvilive at gmail.com (sarvi) Date: Wed, 1 Sep 2010 10:49:39 -0700 (PDT) Subject: PyPy and RPython Message-ID: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Is there a plan to adopt PyPy and RPython under the python foundation in attempt to standardize both. I have been watching PyPy and RPython evolve over the years. PyPy seems to have momentum and is rapidly gaining followers and performance. PyPy JIT and performance would be a good thing for the Python Community And it seems to be well ahead of Unladen Swallow in performance and in a position to improve quite a bit. Secondly I have always fantasized of never having to write C code yet get its compiled performance. With RPython(a strict subset of Python), I can actually compile it to C/Machine code These 2 seem like spectacular advantages for Python to pickup on. And all this by just showing the PyPy and the Python foundation's support and direction to adopt them. Yet I see this forum relatively quite on PyPy or Rpython ? Any reasons??? Sarvi From hennebry at web.cs.ndsu.nodak.edu Wed Sep 1 13:58:05 2010 From: hennebry at web.cs.ndsu.nodak.edu (Mike) Date: Wed, 1 Sep 2010 10:58:05 -0700 (PDT) Subject: Windows vs. file.read References: Message-ID: On Sep 1, 12:31?pm, MRAB wrote: > You should open the files in binary mode, not text mode, ie file(path, > "rb"). Text mode is the default. Not a problem on *nix because the line > ending is newline. Thanks. That was it. From contact at xavierho.com Wed Sep 1 14:12:02 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 2 Sep 2010 04:12:02 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: 2010/9/2 Alban Nona > Hello Xavier, working great ! thank you very much ! :p > Do you know by any chance if dictionnary can be sorted asthis: > Look at the sorted() global function in the Python API. ;] Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From cappy2112 at gmail.com Wed Sep 1 15:18:18 2010 From: cappy2112 at gmail.com (Cappy2112) Date: Wed, 1 Sep 2010 12:18:18 -0700 (PDT) Subject: Installation problem: Python 2.6.6 (32-Bit) on Windows 7 (32-Bit) Message-ID: <0781783a-b182-455f-8522-ed5a37db6e14@o7g2000prg.googlegroups.com> Has anyone else had problems running the msi for Python 2.6.6 on Windows 7 Professional? If I don't check "Compile .py to byte code", the installer completes without error. Checking "Compile .py to byte code" causes the following to be displayed "There is a problem with the windows installer package. A program run as part of setup did not complete as expected" 1. I have GB of disk space available. 2. I have admin privileges 3. The MD5 checksum of the downloaded installer matches the MD5 checksum on python.org 4. Run As Adminsitrator is not available when I Shift-Right Click (probably because my login already has admin privileges) I'm also having a similar issue with the PythonWin32 extensions installer on the same machine. From vicente.soler at gmail.com Wed Sep 1 15:29:52 2010 From: vicente.soler at gmail.com (vsoler) Date: Wed, 1 Sep 2010 12:29:52 -0700 (PDT) Subject: Source code for itertools References: <9aa266f0-be9b-4c9a-bfbd-6cdfc86ad2c8@t20g2000yqa.googlegroups.com> <7xmxs3sdt2.fsf@ruckus.brouhaha.com> Message-ID: On 31 ago, 05:33, Rolando Espinoza La Fuente wrote: > On Mon, Aug 30, 2010 at 11:06 PM, vsoler wrote: > > On 31 ago, 04:42, Paul Rubin wrote: > >> vsoler writes: > >> > I was expecting an itertools.py file, but I don't see it in your list. > >> >> ./python3.1-3.1.2+20100829/Modules/itertoolsmodule.c > > >> looks promising. ?Lots of stdlib modules are written in C for speed or > >> access to system facilities. > > > Lawrence, Paul, > > > You seem to be running a utility I am not familiar with. Perhaps this > > is because I am using Windows, and most likely you are not. > > > How could I have found the answer in a windows environment? > > Hard question. They are using standard unix utilities. > > But you can find the source file of a python module within python: > > >>> import itertools > >>> print(itertools.__file__) > > /usr/lib/python2.6/lib-dynload/itertools.so > > Yours should point to a windows path. If the file ends with a ".py", > you can open the file > with any editor. If ends with ".so" or something else ?likely is a > compiled module in C > and you should search in the source distribution, not the binary distribution. > > Hope it helps. > > Regards, > > Rolando Espinoza La fuentewww.insophia.com Thank you Rolando for your contribution. Followinf your piece of advice I got: >>> import itertools >>> print(itertools.__file__) Traceback (most recent call last): File "", line 1, in print(itertools.__file__) AttributeError: 'module' object has no attribute '__file__' >>> So, I undestand that the module is written in C. Vicente Soler From vicente.soler at gmail.com Wed Sep 1 15:30:40 2010 From: vicente.soler at gmail.com (vsoler) Date: Wed, 1 Sep 2010 12:30:40 -0700 (PDT) Subject: Source code for itertools References: <9aa266f0-be9b-4c9a-bfbd-6cdfc86ad2c8@t20g2000yqa.googlegroups.com> <7xmxs3sdt2.fsf@ruckus.brouhaha.com> Message-ID: <331028b7-29a3-4a6b-893e-c0f1f77a6f03@k10g2000yqa.googlegroups.com> On 1 sep, 06:30, Tim Roberts wrote: > vsoler wrote: > >On 31 ago, 04:42, Paul Rubin wrote: > >> vsoler writes: > >> > I was expecting an itertools.py file, but I don't see it in your list. > >> >> ./python3.1-3.1.2+20100829/Modules/itertoolsmodule.c > > >> looks promising. ?Lots of stdlib modules are written in C for speed or > >> access to system facilities. > > >Lawrence, Paul, > > >You seem to be running a utility I am not familiar with. Perhaps this > >is because I am using Windows, and most likely you are not. > > >How could I have found the answer in a windows environment? > > Did you take the time to understand what he did? ?It's not that hard to > figure out. ?He fetched the Python source code, unpacked it, then search > for filenames that contained the string "itertools." > > The equivalent in Windows, after unpacking the source archive, would have > been: > ? ? dir /s *itertools* > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Thank you Tim, understood!!! From kr4uzi at googlemail.com Wed Sep 1 16:14:51 2010 From: kr4uzi at googlemail.com (Markus Kraus) Date: Wed, 1 Sep 2010 13:14:51 -0700 (PDT) Subject: C++ - Python API Message-ID: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Hi guys i worked on this for severl days (or even weeks?!) now, but im nearly finished with it: A complete C++ to Python API which allows you to use python as a scripting language for your C++ projects. Simple example: --- python code --- def greet( player ): print( "Hello player " + player.getName() + " !" ) ------ --- c++ code --- class CPlayer { REGISTER_CLASS( CPlayer, CLASS_METHOD("getName", GetName) ) private: string m_Name; public: CPlayer( string nName ) { m_Name = nName; INITIALIZE("player"); } string GetName( ) { return m_Name; } }; ------ If you call the python function (look into the example in the project to see how to do this) this results in ( assume you have CPlayer("myPlayerName") ) "Hello player myPlayerName!". So the feature overview: For C++ classes: - "translating" it into a python object - complete reflexion (attributes and methods) of the c++ instance - call c++ methods nearly directly from python - method-overloading (native python doesnt support it (!)) Modules: - the API allowes to create hardcoded python modules without having any knowledge about the python C-API - Adding attributes to the module (long/char*/PyObject*) General: -runs on any platform and doenst need an installed python -runs in multithreaded environments (requires python > 2.3) -support for python 3.x -no need of any python C-API knowledge (maybe for coding modules but then only 2 or 3 functions) -the project is a VC2010 one and there is also an example module + class If there is any interest in testing this or using this for your own project, please post; in that case i'll release it now instead of finishing the inheritance support before releasing it (this may take a few days though). From arnodel at googlemail.com Wed Sep 1 16:20:07 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 01 Sep 2010 21:20:07 +0100 Subject: parsing string into dict References: Message-ID: Tim Arnold writes: > Hi, > I have a set of strings that are *basically* comma separated, but with > the exception that if a comma occur insides curly braces it is not a > delimiter. Here's an example: > > [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] > > I'd like to parse that into a dictionary (note that 'continued' gets > the value 'true'): > {'code':'one', 'caption':'{My Analysis for \textbf{t}, Version > 1}','continued':'true'} > > I know and love pyparsing, but for this particular code I need to rely > only on the standard library (I'm running 2.7). Here's what I've got, > and it works. I wonder if there's a simpler way? > thanks, > --Tim Arnold > FWIW, here's how I would do it: def parse_key(s, start): pos = start while s[pos] not in ",=]": pos += 1 return s[start:pos].strip(), pos def parse_value(s, start): pos, nesting = start, 0 while nesting or s[pos] not in ",]": nesting += {"{":1, "}":-1}.get(s[pos], 0) pos += 1 return s[start:pos].strip(), pos def parse_options(s): options, pos = {}, 0 while s[pos] != "]": key, pos = parse_key(s, pos + 1) if s[pos] == "=": value, pos = parse_value(s, pos + 1) else: value = 'true' options[key] = value return options test = "[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued]" >>> parse_options(test) {'caption': '{My Analysis for \textbf{t}, Version 1}', 'code': 'one', 'continued': True} -- Arnaud From tjreedy at udel.edu Wed Sep 1 16:22:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Sep 2010 16:22:56 -0400 Subject: Performance: sets vs dicts. In-Reply-To: References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: On 9/1/2010 11:40 AM, Aahz wrote: > I think that any implementation > that doesn't have O(1) for list element access is fundamentally broken, Whereas I think that that claim is fundamentally broken in multiple ways. > and we should probably document that somewhere. I agree that *current* algorithmic behavior of parts of CPython on typical *current* hardware should be documented not just 'somewhere' (which I understand it is, in the Wiki) but in a CPython doc included in the doc set distributed with each release. Perhaps someone or some group could write a HowTo on Programming with CPython's Builtin Classes that would describe both the implementation and performance and also the implications for coding style. In particular, it could compare CPython's array lists and tuples to singly linked lists (which are easily created in Python also). But such a document, after stating that array access may be thought of as constant time on current hardware to a useful first approximation, should also state that repeated seqeuntial accessess may be *much* faster than repeated random accessess. People in the high-performance computing community are quite aware of this difference between simplified lies and messy truth. Because of this, array algorithms are (should be) written differently in Fortran and C because Fortran stores arrays by columns and C by rows and because it is usually much faster to access the next item than one far away. -- Terry Jan Reedy From thomas at jollybox.de Wed Sep 1 16:29:42 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 1 Sep 2010 22:29:42 +0200 Subject: C++ - Python API In-Reply-To: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: <201009012229.43096.thomas@jollybox.de> On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: > So the feature overview: First, the obligatory things you don't want to hear: Have you had a look at similar efforts? A while ago, Aahz posted something very similar on this very list. You should be able to find it in any of the archives without too much trouble. The most prominent example of this is obviously Boost.Python. > For C++ classes: > - "translating" it into a python object How do you handle memory management ? > - complete reflexion (attributes and methods) of the c++ instance > - call c++ methods nearly directly from python > - method-overloading (native python doesnt support it (!)) > > Modules: > - the API allowes to create hardcoded python modules without having > any knowledge about the python C-API > - Adding attributes to the module (long/char*/PyObject*) char*... Unicode? Somewhere? wchar_t* maybe, or std::wstring? No? Also -- double? (I'm just being pedantic now, at least double should be trivial to add) > > General: > -runs on any platform and doenst need an installed python Which platforms did you test it on? Which compilers did you test? Are you sure your C++ is portable? > -runs in multithreaded environments (requires python > 2.3) How do you deal with the GIL? How do you handle calling to Python from multiple C++ threads? > -support for python 3.x > -no need of any python C-API knowledge (maybe for coding modules but > then only 2 or 3 functions) > -the project is a VC2010 one and there is also an example module + > class Again, have you tested other compilers? > If there is any interest in testing this or using this for your own > project, please post; in that case i'll release it now instead of > finishing the inheritance support before releasing it (this may take a > few days though). Just publish a bitbucket or github repository ;-) From arnodel at googlemail.com Wed Sep 1 16:46:12 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 01 Sep 2010 21:46:12 +0100 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: Terry Reedy writes: > On 9/1/2010 11:40 AM, Aahz wrote: >> I think that any implementation >> that doesn't have O(1) for list element access is fundamentally broken, > > Whereas I think that that claim is fundamentally broken in multiple ways. > >> and we should probably document that somewhere. > > I agree that *current* algorithmic behavior of parts of CPython on > typical *current* hardware should be documented not just 'somewhere' > (which I understand it is, in the Wiki) but in a CPython doc included > in the doc set distributed with each release. > > Perhaps someone or some group could write a HowTo on Programming with > CPython's Builtin Classes that would describe both the implementation > and performance and also the implications for coding style. In > particular, it could compare CPython's array lists and tuples to > singly linked lists (which are easily created in Python also). > > But such a document, after stating that array access may be thought of > as constant time on current hardware to a useful first approximation, > should also state that repeated seqeuntial accessess may be *much* > faster than repeated random accessess. People in the high-performance > computing community are quite aware of this difference between > simplified lies and messy truth. Because of this, array algorithms are > (should be) written differently in Fortran and C because Fortran > stores arrays by columns and C by rows and because it is usually much > faster to access the next item than one far away. I don't understand what you're trying to say. Aahz didn't claim that random list element access was constant time, he said it was O(1) (and that it should be part of the Python spec that it is). -- Arnaud From kr4uzi at googlemail.com Wed Sep 1 16:49:19 2010 From: kr4uzi at googlemail.com (Markus Kraus) Date: Wed, 1 Sep 2010 13:49:19 -0700 (PDT) Subject: C++ - Python API References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: <0ea3a6ee-b78d-4d82-88e8-4e7aaf3c9bd7@h19g2000yqb.googlegroups.com> Thanks for the answer On 1 Sep., 22:29, Thomas Jollans wrote: > On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: > > > So the feature overview: > > First, the obligatory things you don't want to hear: Have you had a look at > similar efforts? A while ago, Aahz posted something very similar on this very > list. You should be able to find it in any of the archives without too much > trouble. > The most prominent example of this is obviously Boost.Python. I searched in Aahz posts but i didn't find anything related. About Boost.Python: I worked with it but (for me) it seems more like if it's meant to create pyd modules. > > For C++ classes: > > - "translating" it into a python object > > How do you handle memory management ? As long as the c++ instanze itself exists, the python object is existing too. If you delete the c++ instanze the python one is also deleted (in a multithreaded environment you'll get a "This object has already been deleted" error). > > - complete reflexion (attributes and methods) of the c++ instance > > - call c++ methods nearly directly from python > > - method-overloading (native python doesnt support it (!)) > > > Modules: > > - the API allowes to create hardcoded python modules without having > > any knowledge about the python C-API > > - Adding attributes to the module (long/char*/PyObject*) > > char*... > Unicode? Somewhere? wchar_t* maybe, or std::wstring? No? Also -- double? (I'm > just being pedantic now, at least double should be trivial to add) I haven't worked too much on this yet but ill add support for all common c++ types. > > General: > > -runs on any platform and doenst need an installed python > > Which platforms did you test it on? Which compilers did you test? Are you sure > your C++ is portable? My C++ code is not platform dependent so it should (haven't tested it yet) be portable. > > -runs in multithreaded environments (requires python > 2.3) > > How do you deal with the GIL? > How do you handle calling to Python from multiple C++ threads? Since python 2.3 there are the function PyGILState_Ensure and PyGILState_Release functions which do the whole GIL stuff for you :). > > -support for python 3.x > > -no need of any python C-API knowledge (maybe for coding modules but > > then only 2 or 3 functions) > > -the project is a VC2010 one and there is also an example module + > > class > > Again, have you tested other compilers? Dont have the ability for it (could need a linux guy who knows how to create a makefile). > > If there is any interest in testing this or using this for your own > > project, please post; in that case i'll release it now instead of > > finishing the inheritance support before releasing it (this may take a > > few days though). > > Just publish a bitbucket or github repository ;-) Ill set up a googlecode site :P From tjreedy at udel.edu Wed Sep 1 16:54:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Sep 2010 16:54:09 -0400 Subject: Performance: sets vs dicts. In-Reply-To: <7xvd6qufqw.fsf@ruckus.brouhaha.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <878w3ogpvq.fsf@benfinney.id.au> <7xvd6qufqw.fsf@ruckus.brouhaha.com> Message-ID: On 9/1/2010 2:42 AM, Paul Rubin wrote: > Terry Reedy writes: >> Does anyone seriously think that an implementation should be rejected >> as an implementation if it intellegently did seq[n] lookups in >> log2(n)/31 time units for all n (as humans would do), instead of >> stupidly taking 1 time unit for all n< 2**31 and rejecting all larger >> values (as 32-bit CPython does)? > > Er, how can one handle n> 2**31 at all, in 32-bit CPython? I am not sure of what you mean by 'handle'. Ints (longs in 2.x) are not limited, but indexes are. 2**31 and bigger are summarily rejected as impossibly too large, even though they might not actually be so these days. >>> s=b'' >>> s[1] Traceback (most recent call last): File "", line 1, in s[1] IndexError: index out of range >>> s[2**32] Traceback (most recent call last): File "", line 1, in s[2**32] IndexError: cannot fit 'int' into an index-sized integer As far as I know, this is undocumented. In any case, this means that if it were possible to create a byte array longer than 2**31 on an otherwise loaded 32-bit linux machine with 2**32 memory, then indexing the end elements would not be possible, which is to say, O(1) would jump to O(INF). I do not have such a machine to test whether big = open('2.01.gigabytes', 'rb').read() executes or raises an exception. Array size limits are also not documented. -- Terry Jan Reedy From stef.mientki at gmail.com Wed Sep 1 17:32:57 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 01 Sep 2010 23:32:57 +0200 Subject: what is this kind of string: b'string' ? Message-ID: <4C7EC689.6040508@gmail.com> in winpdb I see strings like this: >>>a = b'string' >>>a 'string' >>> type(a) what's the "b" doing in front of the string ? thanks, Stef Mientki From robert.kern at gmail.com Wed Sep 1 17:39:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 01 Sep 2010 16:39:29 -0500 Subject: what is this kind of string: b'string' ? In-Reply-To: <4C7EC689.6040508@gmail.com> References: <4C7EC689.6040508@gmail.com> Message-ID: On 9/1/10 4:32 PM, Stef Mientki wrote: > in winpdb I see strings like this: > >>>> a = b'string' >>>> a > 'string' >>>> type(a) > > > what's the "b" doing in front of the string ? http://docs.python.org/py3k/library/stdtypes.html#bytes-and-byte-array-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 john at castleamber.com Wed Sep 1 17:40:59 2010 From: john at castleamber.com (John Bokma) Date: Wed, 01 Sep 2010 16:40:59 -0500 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: <87iq2pcfbo.fsf@castleamber.com> Arnaud Delobelle writes: > Terry Reedy writes: > >> On 9/1/2010 11:40 AM, Aahz wrote: >>> I think that any implementation >>> that doesn't have O(1) for list element access is fundamentally broken, >> >> Whereas I think that that claim is fundamentally broken in multiple ways. >> >>> and we should probably document that somewhere. >> >> I agree that *current* algorithmic behavior of parts of CPython on >> typical *current* hardware should be documented not just 'somewhere' >> (which I understand it is, in the Wiki) but in a CPython doc included >> in the doc set distributed with each release. >> >> Perhaps someone or some group could write a HowTo on Programming with >> CPython's Builtin Classes that would describe both the implementation >> and performance and also the implications for coding style. In >> particular, it could compare CPython's array lists and tuples to >> singly linked lists (which are easily created in Python also). >> >> But such a document, after stating that array access may be thought of >> as constant time on current hardware to a useful first approximation, >> should also state that repeated seqeuntial accessess may be *much* >> faster than repeated random accessess. People in the high-performance >> computing community are quite aware of this difference between >> simplified lies and messy truth. Because of this, array algorithms are >> (should be) written differently in Fortran and C because Fortran >> stores arrays by columns and C by rows and because it is usually much >> faster to access the next item than one far away. > > I don't understand what you're trying to say. Aahz didn't claim that > random list element access was constant time, he said it was O(1) (and > that it should be part of the Python spec that it is). Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, 2nd edition. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From pauljefferson at gmail.com Wed Sep 1 17:52:43 2010 From: pauljefferson at gmail.com (Paul Jefferson) Date: Wed, 1 Sep 2010 22:52:43 +0100 Subject: Email Previews Message-ID: Hello, I'm currently trying to write a quick script that takes email message objects and generates quick snippet previews (like the iPhone does when you are in the menu) but I'm struggling. I was just wondering before I started to put a lot of work in this if there were any existing scripts out there that did it, as it seems a bit pointless spending a lot of time reinventing the wheel if something already exists. Thanks for your help, Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Wed Sep 1 18:30:06 2010 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 01 Sep 2010 15:30:06 -0700 Subject: what is this kind of string: b'string' ? In-Reply-To: <4C7EC689.6040508@gmail.com> References: <4C7EC689.6040508@gmail.com> Message-ID: <4C7ED3EE.4050908@islandtraining.com> On 09/01/2010 02:32 PM, Stef Mientki wrote: > in winpdb I see strings like this: > > >>>> a = b'string' >>>> a >>>> > 'string' > >>>> type(a) >>>> > > > what's the "b" doing in front of the string ? > > thanks, > Stef Mientki > In Python2 the b is meaningless (but allowed for compatibility and future-proofing purposes), while in Python 3 it creates a byte array (or byte string or technically an object of type bytes) rather than a string (of unicode). Python2 >>> type(b'abc') >>> type('abc') Python3: >>> type(b'abc') >>> type('abc') From robert.kern at gmail.com Wed Sep 1 18:30:31 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 01 Sep 2010 17:30:31 -0500 Subject: Performance: sets vs dicts. In-Reply-To: <87iq2pcfbo.fsf@castleamber.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> Message-ID: On 9/1/10 4:40 PM, John Bokma wrote: > Arnaud Delobelle writes: > >> Terry Reedy writes: >>> But such a document, after stating that array access may be thought of >>> as constant time on current hardware to a useful first approximation, >>> should also state that repeated seqeuntial accessess may be *much* >>> faster than repeated random accessess. People in the high-performance >>> computing community are quite aware of this difference between >>> simplified lies and messy truth. Because of this, array algorithms are >>> (should be) written differently in Fortran and C because Fortran >>> stores arrays by columns and C by rows and because it is usually much >>> faster to access the next item than one far away. >> >> I don't understand what you're trying to say. Aahz didn't claim that >> random list element access was constant time, he said it was O(1) (and >> that it should be part of the Python spec that it is). > > Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, > 2nd edition. While we often use the term "constant time" to as a synonym for O(1) complexity of an algorithm, Arnaud and Terry are using the term here to mean "an implementation takes roughly the same amount of wall-clock time every time". -- 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 at rcn.com Wed Sep 1 18:51:33 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 1 Sep 2010 15:51:33 -0700 (PDT) Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: <7a38148b-79e9-40ce-9700-2c0d1c9b3ee4@a4g2000prm.googlegroups.com> On Aug 30, 6:03?am, a... at pythoncraft.com (Aahz) wrote: > That reminds me: one co-worker (who really should have known better ;-) > had the impression that sets were O(N) rather than O(1). ?Although > writing that off as a brain-fart seems appropriate, it's also the case > that the docs don't really make that clear, it's implied from requiring > elements to be hashable. ?Do you agree that there should be a comment? There probably ought to be a HOWTO or FAQ entry on algorithmic complexity that covers classes and functions where the algorithms are interesting. That will concentrate the knowledge in one place where performance is a main theme and where the various alternatives can be compared and contrasted. I think most users of sets rarely read the docs for sets. The few lines in the tutorial are enough so that most folks "just get it" and don't read more detail unless they attempting something exotic. Our docs have gotten somewhat voluminous, so it's unlikely that adding that particular needle to the haystack would have cured your colleague's "brain-fart" unless he had been focused on a single document talking about the performance characteristics of various data structures. Raymond Raymond From tjreedy at udel.edu Wed Sep 1 19:24:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Sep 2010 19:24:40 -0400 Subject: Performance: sets vs dicts. In-Reply-To: <87iq2pcfbo.fsf@castleamber.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> Message-ID: On 9/1/2010 5:40 PM, John Bokma wrote: > Arnaud Delobelle writes: > >> Terry Reedy writes: >> >>> On 9/1/2010 11:40 AM, Aahz wrote: >>>> I think that any implementation >>>> that doesn't have O(1) for list element access is fundamentally broken, >>> >>> Whereas I think that that claim is fundamentally broken in multiple ways. >>> >>>> and we should probably document that somewhere. >>> >>> I agree that *current* algorithmic behavior of parts of CPython on >>> typical *current* hardware should be documented not just 'somewhere' >>> (which I understand it is, in the Wiki) but in a CPython doc included >>> in the doc set distributed with each release. >>> >>> Perhaps someone or some group could write a HowTo on Programming with >>> CPython's Builtin Classes that would describe both the implementation >>> and performance and also the implications for coding style. In >>> particular, it could compare CPython's array lists and tuples to >>> singly linked lists (which are easily created in Python also). >>> >>> But such a document, after stating that array access may be thought of >>> as constant time on current hardware to a useful first approximation, >>> should also state that repeated seqeuntial accessess may be *much* >>> faster than repeated random accessess. People in the high-performance >>> computing community are quite aware of this difference between >>> simplified lies and messy truth. Because of this, array algorithms are >>> (should be) written differently in Fortran and C because Fortran >>> stores arrays by columns and C by rows and because it is usually much >>> faster to access the next item than one far away. >> >> I don't understand what you're trying to say. Most generally, that I view Python as an general algorithm language and not just as a VonNeuman machine programming language. More specifically, that O() claims can be inapplicable, confusing, misleading, incomplete, or false, especially when applied to real time and to real systems with finite limits. >> Aahz didn't claim that random list element access was constant time, >> he said it was O(1) (and >> that it should be part of the Python spec that it is). Yes, I switched, because 'constant time' is a comprehensible claim that can be refuted and because that is how some will interpret O(1) (see below for proof;-). If one takes O(1) to mean bounded, which I believe is the usual technical meaning, then all Python built-in sequence operations take bounded time because of the hard size limit. If sequences were not bounded in length, then access time would not be bounded either. My most specific point is that O(1), interpreted as more-or-less constant time across a range of problem sizes, can be either a virute or vice depending on whether the constancy is a result of speeding up large problems or slowing down small problems. I furthermore contend that Python sequences on current hardware exhibit both virtue and vice and that is would be absurd to reject a system that kept the virtue without the vice and that such absurdity should not be built into the language definition. My fourth point is that we can meet the reasonable goal of helping some people make better use of current Python/CPython on current hardware without big-O controversy and without screwing around with the language definition and locking out the future. > Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, > 2nd edition. -- Terry Jan Reedy From pmcnameeking at gmail.com Wed Sep 1 19:35:45 2010 From: pmcnameeking at gmail.com (patrick mcnameeking) Date: Wed, 1 Sep 2010 19:35:45 -0400 Subject: importing excel data into a python matrix? Message-ID: Hello list, I've been working with Python now for about a year using it primarily for scripting in the Puredata graphical programming environment. I'm working on a project where I have been given a 1000 by 1000 cell excel spreadsheet and I would like to be able to access the data using Python. Does anyone know of a way that I can do this? Thanks, Pat -- 'Given enough eyeballs, all bugs are shallow.' -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Wed Sep 1 19:43:02 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 1 Sep 2010 16:43:02 -0700 Subject: importing excel data into a python matrix? In-Reply-To: References: Message-ID: On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking wrote: > Hello list, > I've been working with Python now for about a year using it primarily for > scripting in the Puredata graphical programming environment. ?I'm working on > a project where I have been given a 1000 by 1000 cell excel spreadsheet and > I would like to be able to access the data using Python. ?Does anyone know > of a way that I can do this? > Thanks, > Pat http://tinyurl.com/2eqqjxv ;) Geremy Condra From clp2 at rebertia.com Wed Sep 1 19:45:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Sep 2010 16:45:39 -0700 Subject: importing excel data into a python matrix? In-Reply-To: References: Message-ID: On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking wrote: > Hello list, > I've been working with Python now for about a year using it primarily for > scripting in the Puredata graphical programming environment. ?I'm working on > a project where I have been given a 1000 by 1000 cell excel spreadsheet and > I would like to be able to access the data using Python. ?Does anyone know > of a way that I can do this? "xlrd 0.7.1 - Library for developers to extract data from Microsoft Excel (tm) spreadsheet files": http://pypi.python.org/pypi/xlrd If requiring the user to re-save the file as .CSV instead of .XLS is feasible, then you /can/ avoid the third-party dependency and use just the std lib instead: http://docs.python.org/library/csv.html Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Wed Sep 1 20:04:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Sep 2010 17:04:01 -0700 Subject: DeprecationWarning In-Reply-To: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> References: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Message-ID: On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: > Hi There, > > I would like to create an scp handle and download a file from a > client. I have following code: > but what i'm getting is this and no file is downloaded...: > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: > BaseException.message has been deprecated as of Python 2.6 > ?chan.send('\x01'+e.message) > 09/01/2010 08:53:56 : Downloading P-file failed. > > What does that mean and how do i resolve this? http://stackoverflow.com/questions/1272138/baseexception-message-deprecated-in-python-2-6 As the warning message says, line 243 of /opt/lampp/cgi-bin/attachment.py is the cause of the warning. However, that's only a warning (albeit probably about a small part of some error-raising code), not an error itself, so it's not the cause of the download failure. Printing out the IOError encountered would be the first step in debugging the download failure. Cheers, Chris -- http://blog.rebertia.com From john at castleamber.com Wed Sep 1 20:11:03 2010 From: john at castleamber.com (John Bokma) Date: Wed, 01 Sep 2010 19:11:03 -0500 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> Message-ID: <87aao1c8dk.fsf@castleamber.com> Terry Reedy writes: > On 9/1/2010 5:40 PM, John Bokma wrote: [..] > Yes, I switched, because 'constant time' is a comprehensible claim > that can be refuted and because that is how some will interpret O(1) > (see below for proof;-). You make it now sound alsof this interpretation is not correct or out of place. People who have bothered to read ItA will use O(1) and constant time interchangeably while talking of the order of growth of the running time algorithms and most of those are aware that 'big oh' hides a constant, and that in the real world a O(log n) algorithm can outperform an O(1) algorithm for small values of n. >> Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, >> 2nd edition. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Wed Sep 1 20:13:43 2010 From: john at castleamber.com (John Bokma) Date: Wed, 01 Sep 2010 19:13:43 -0500 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> Message-ID: <8762ypc894.fsf@castleamber.com> Robert Kern writes: > On 9/1/10 4:40 PM, John Bokma wrote: >> Arnaud Delobelle writes: >> >>> Terry Reedy writes: [...] >>> I don't understand what you're trying to say. Aahz didn't claim that >>> random list element access was constant time, he said it was O(1) (and >>> that it should be part of the Python spec that it is). >> >> Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, >> 2nd edition. > > While we often use the term "constant time" to as a synonym for O(1) > complexity of an algorithm, Arnaud and Terry are using the term here > to mean "an implementation takes roughly the same amount of wall-clock > time every time". Now that's confusing in a discussion that earlier on provided a link to a page using big O notation. At least for people following this partially, like I do. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From nkaunda at yahoo.com Wed Sep 1 20:50:40 2010 From: nkaunda at yahoo.com (Nally Kaunda-Bukenya) Date: Wed, 1 Sep 2010 17:50:40 -0700 (PDT) Subject: Python-list Digest, Vol 84, Issue 8 In-Reply-To: References: Message-ID: <363316.54542.qm@web33502.mail.mud.yahoo.com> Dear Peter, that did wonders!!?thanks so much for the code fix; I will check back with you later for the meaning of some functions you used. Many thanks?to all those good people who gave me pointers: Rami, Mathew, Bob,?? Best wishes for now:) ________________________________ From: "python-list-request at python.org" To: python-list at python.org Sent: Wed, September 1, 2010 11:52:02 AM Subject: Python-list Digest, Vol 84, Issue 8 Note: Forwarded message is attached. 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. DeprecationWarning (cerr) ? 2. Re: Performance: sets vs dicts. (Stefan Behnel) ? 3. Better multiprocessing and data persistance with C level ? ? ? serialisation (ipatrol6010 at yahoo.com) ? 4. Re: Dumb Stupid Question About List and String (Xavier Ho) ? 5. Re: Dumb Stupid Question About List and String (Alban Nona) ? 6. Re: Dumb Stupid Question About List and String (Alban Nona) ? 7. Re: Newby Needs Help with Python code (Peter Otten) -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ipatrol6010 at yahoo.com Wed Sep 1 20:59:50 2010 From: ipatrol6010 at yahoo.com (ipatrol6010 at yahoo.com) Date: Wed, 1 Sep 2010 20:59:50 -0400 Subject: Python libs on Windows ME Message-ID: <3A147D09-4B7E-41F3-A669-D20EA00D6489@yahoo.com> Damn Small Linux could work. If even that won't work, perhaps it's time to scrap your old fossil for parts and buy a modern computer. Even a netbook would probably be an improvement based on your situation. From dchichkov at gmail.com Wed Sep 1 21:08:25 2010 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Wed, 1 Sep 2010 18:08:25 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) Message-ID: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Given: a large list (10,000,000) of floating point numbers; Task: fastest python code that finds k (small, e.g. 10) smallest items, preferably with item indexes; Limitations: in python, using only standard libraries (numpy & scipy is Ok); I've tried several methods. With N = 10,000,000, K = 10 The fastest so far (without item indexes) was pure python implementation nsmallest_slott_bisect (using bisect/insert). And with indexes nargsmallest_numpy_argmin (argmin() in the numpy array k times). Anyone up to the challenge beating my code with some clever selection algorithm? Current Table: 1.66864395142 mins_heapq(items, n): 0.946580886841 nsmallest_slott_bisect(items, n): 1.38014793396 nargsmallest(items, n): 10.0732769966 sorted(items)[:n]: 3.17916202545 nargsmallest_numpy_argsort(items, n): 1.31794500351 nargsmallest_numpy_argmin(items, n): 2.37499308586 nargsmallest_numpy_array_argsort(items, n): 0.524670124054 nargsmallest_numpy_array_argmin(items, n): 0.0525538921356 numpy argmin(items): 1892997 0.364673852921 min(items): 10.0000026786 Code: ---------------- import heapq from random import randint, random import time from bisect import insort from itertools import islice from operator import itemgetter def mins_heapq(items, n): nlesser_items = heapq.nsmallest(n, items) return nlesser_items def nsmallest_slott_bisect(iterable, n, insort=insort): it = iter(iterable) mins = sorted(islice(it, n)) for el in it: if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates insort(mins, el) mins.pop() return mins def nargsmallest(iterable, n, insort=insort): it = enumerate(iterable) mins = sorted(islice(it, n), key = itemgetter(1)) loser = mins[-1][1] # largest of smallest for el in it: if el[1] <= loser: # NOTE: equal sign is to preserve dupl mins.append(el) mins.sort(key = itemgetter(1)) mins.pop() loser = mins[-1][1] return mins def nargsmallest_numpy_argsort(iter, k): distances = N.asarray(iter) return [(i, distances[i]) for i in distances.argsort()[0:k]] def nargsmallest_numpy_array_argsort(array, k): return [(i, array[i]) for i in array.argsort()[0:k]] def nargsmallest_numpy_argmin(iter, k): distances = N.asarray(iter) mins = [] def nargsmallest_numpy_array_argmin(distances, k): mins = [] for i in xrange(k): j = distances.argmin() mins.append((j, distances[j])) distances[j] = float('inf') return mins test_data = [randint(10, 50) + random() for i in range(10000000)] K = 10 init = time.time() mins = mins_heapq(test_data, K) print time.time() - init, 'mins_heapq(items, n):', mins[:2] init = time.time() mins = nsmallest_slott_bisect(test_data, K) print time.time() - init, 'nsmallest_slott_bisect(items, n):', mins[: 2] init = time.time() mins = nargsmallest(test_data, K) print time.time() - init, 'nargsmallest(items, n):', mins[:2] init = time.time() mins = sorted(test_data)[:K] print time.time() - init, 'sorted(items)[:n]:', time.time() - init, mins[:2] import numpy as N init = time.time() mins = nargsmallest_numpy_argsort(test_data, K) print time.time() - init, 'nargsmallest_numpy_argsort(items, n):', mins[:2] init = time.time() mins = nargsmallest_numpy_argmin(test_data, K) print time.time() - init, 'nargsmallest_numpy_argmin(items, n):', mins[:2] print init = time.time() mins = array.argmin() print time.time() - init, 'numpy argmin(items):', mins init = time.time() mins = min(test_data) print time.time() - init, 'min(items):', mins From rasjidw at gmail.com Wed Sep 1 21:10:04 2010 From: rasjidw at gmail.com (Rasjid Wilcox) Date: Thu, 2 Sep 2010 11:10:04 +1000 Subject: Private variables Message-ID: Hi all, I am aware the private variables are generally done via convention (leading underscore), but I came across a technique in Douglas Crockford's book "Javascript: The Good Parts" for creating private variables in Javascript, and I'd thought I'd see how it translated to Python. Here is my attempt. def get_config(_cache=[]): private = {} private['a'] = 1 private['b'] = 2 if not _cache: class Config(object): @property def a(self): return private['a'] @property def b(self): return private['b'] config = Config() _cache.append(config) else: config = _cache[0] return config >>> c = get_config() >>> c.a 1 >>> c.b 2 >>> c.a = 10 Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute >>> dir(c) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b'] >>> d = get_config() >>> d is c True I'm not really asking 'is it a good idea' but just 'does this work'? It seems to work to me, and is certainly 'good enough' in the sense that it should be impossible to accidentally change the variables of c. But is it possible to change the value of c.a or c.b with standard python, without resorting to ctypes level manipulation? Cheers, Rasjid. From benjamin at python.org Wed Sep 1 21:49:40 2010 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 2 Sep 2010 01:49:40 +0000 (UTC) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Message-ID: sarvi gmail.com> writes: > > > Is there a plan to adopt PyPy and RPython under the python foundation > in attempt to standardize both. There is not. > > Secondly I have always fantasized of never having to write C code yet > get its compiled performance. > With RPython(a strict subset of Python), I can actually compile it to > C/Machine code RPython is not supposed to be a general purpose language. As a PyPy developer myself, I can testify that it is no fun. > > Yet I see this forum relatively quite on PyPy or Rpython ? Any > reasons??? You should post to the PyPy list instead. (See pypy.org) From ryan at rfk.id.au Wed Sep 1 22:06:52 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 02 Sep 2010 12:06:52 +1000 Subject: Private variables In-Reply-To: References: Message-ID: <1283393212.2136.4.camel@durian> On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: > Hi all, > > I am aware the private variables are generally done via convention > (leading underscore), but I came across a technique in Douglas > Crockford's book "Javascript: The Good Parts" for creating private > variables in Javascript, and I'd thought I'd see how it translated to > Python. Here is my attempt. > > def get_config(_cache=[]): > private = {} > private['a'] = 1 > private['b'] = 2 > if not _cache: > class Config(object): > @property > def a(self): > return private['a'] > @property > def b(self): > return private['b'] > config = Config() > _cache.append(config) > else: > config = _cache[0] > return config > > >>> c = get_config() > >>> c.a > 1 > >>> c.b > 2 > >>> c.a = 10 > Traceback (most recent call last): > File "", line 1, in > AttributeError: can't set attribute > >>> dir(c) > ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', > '__getattribute__', '__hash__', '__init__', '__module__', '__new__', > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', > '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b'] > >>> d = get_config() > >>> d is c > True > > I'm not really asking 'is it a good idea' but just 'does this work'? > It seems to work to me, and is certainly 'good enough' in the sense > that it should be impossible to accidentally change the variables of > c. > > But is it possible to change the value of c.a or c.b with standard > python, without resorting to ctypes level manipulation? It's not easy, but it can be done by introspecting the property object you created and munging the closed-over dictionary object: >>> c = get_config() >>> c.a 1 >>> c.__class__.__dict__['a'].fget.func_closure[0].cell_contents['a'] = 7 >>> c.a 7 >>> Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ryan at rfk.id.au Wed Sep 1 22:22:21 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 02 Sep 2010 12:22:21 +1000 Subject: Private variables In-Reply-To: <1283393212.2136.4.camel@durian> References: <1283393212.2136.4.camel@durian> Message-ID: <1283394141.2136.5.camel@durian> On Thu, 2010-09-02 at 12:06 +1000, Ryan Kelly wrote: > On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: > > Hi all, > > > > I am aware the private variables are generally done via convention > > (leading underscore), but I came across a technique in Douglas > > Crockford's book "Javascript: The Good Parts" for creating private > > variables in Javascript, and I'd thought I'd see how it translated to > > Python. Here is my attempt. > > > > def get_config(_cache=[]): > > private = {} > > private['a'] = 1 > > private['b'] = 2 > > if not _cache: > > class Config(object): > > @property > > def a(self): > > return private['a'] > > @property > > def b(self): > > return private['b'] > > config = Config() > > _cache.append(config) > > else: > > config = _cache[0] > > return config > > > > >>> c = get_config() > > >>> c.a > > 1 > > >>> c.b > > 2 > > >>> c.a = 10 > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: can't set attribute > > >>> dir(c) > > ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', > > '__getattribute__', '__hash__', '__init__', '__module__', '__new__', > > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', > > '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b'] > > >>> d = get_config() > > >>> d is c > > True > > > > I'm not really asking 'is it a good idea' but just 'does this work'? > > It seems to work to me, and is certainly 'good enough' in the sense > > that it should be impossible to accidentally change the variables of > > c. > > > > But is it possible to change the value of c.a or c.b with standard > > python, without resorting to ctypes level manipulation? > > It's not easy, but it can be done by introspecting the property object > you created and munging the closed-over dictionary object: > > >>> c = get_config() > >>> c.a > 1 > >>> c.__class__.__dict__['a'].fget.func_closure[0].cell_contents['a'] = 7 > >>> c.a > 7 > >>> Heh, and of course I miss the even more obvious trick of just clobbering the property with something else: >>> c.a 1 >>> setattr(c.__class__,"a",7) >>> c.a 7 >>> Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From nikos.the.gr33k at gmail.com Wed Sep 1 22:30:30 2010 From: nikos.the.gr33k at gmail.com (Nik the Greek) Date: Wed, 1 Sep 2010 19:30:30 -0700 (PDT) Subject: Problem checking an existing browser cookie References: <14868a50-f20d-49bb-8ed6-2c290619d2af@a36g2000yqc.googlegroups.com> <8fe0540e-1818-4891-b165-f6731e918e6d@v41g2000yqv.googlegroups.com> <3ff780f9-1b6e-45ef-a530-0726eacb6064@g17g2000yqe.googlegroups.com> <809138c7-4ec3-404e-8863-dddb214c4100@s15g2000yqm.googlegroups.com> Message-ID: <5e88e97d-8d9b-4215-bad8-49d202522442@z7g2000yqg.googlegroups.com> On 31 ???, 11:07, Nik the Greek wrote: > On 30 ???, 20:50, MRAB wrote: > > > > > > > > > > > On 30/08/2010 18:16, Nik the Greek wrote: > > > > On 30 ???, 19:41, MRAB ?wrote: > > >> On 30/08/2010 04:33, Nik the Greek wrote: > > > >>> On 30 ???, 06:12, MRAB ? ?wrote: > > > >>>> This part: > > > >>>> ? ? ? ?( not mycookie or mycookie.value != 'nikos' ) > > > >>>> is false but this part: > > > >>>> ? ? ? ?re.search( r'(msn|yandex|13448|spider|crawl)', host ) is None > > > >>>> is true because host doesn't contain any of those substrings. > > > >>> So, the if code does executed because one of the condition is true? > > > >>> How should i write it? > > > >>> I cannot think clearly on this at all. > > > >>> I just wan to tell it to get executed ?ONLY IF > > > >>> the cookie values is not 'nikos' > > > >>> or ( don't knwo if i have to use and or 'or' here) > > > >>> host does not contain any of the substrings. > > > >>> What am i doign wrong?! > > > >> It might be clearer if you reverse the condition and say: > > > >> ? ? ? me_visiting = ... > > >> ? ? ? if not me_visiting: > > >> ? ? ? ? ? ... > > > > I don't understand what are you trying to say > > > > Please provide a full example. > > > > You mean i should try it like this? > > > > unless ( visitor and visitor.value == 'nikos' ) or re.search( r'(msn| > > > yandex|13448|spider|crawl)', host ) not None: > > > > But isnt it the same thing like the if? > > > My point is that the logic might be clearer to you if you think first > > about how you know when you _are_ the visitor. > > Well my idea was to set a cookie on my browser with the name visitor > and a value of "nikos" and then check each time that cooki. if value > is "nikos" then dont count! > > I could also pass an extra url string likehttp://webville.gr?show=nikos > and check that but i dont like the idea very much of giving an extra > string each time i want to visit my webpage. > So form the 2 solution mentioned the 1st one is better but cant come > into action for some reason. > > Aprt form those too solution i cant think of anyhting else that would > identify me and filter me out of the actual guest of my website. > > I'm all ears if you can think of something else. Is there any other way for the webpage to identify me and filter me out except checking a cookie or attach an extra url string to the address bar? From wuwei23 at gmail.com Wed Sep 1 22:47:10 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 1 Sep 2010 19:47:10 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Message-ID: On Sep 2, 3:49?am, sarvi wrote: > Yet I see this forum relatively quite on PyPy or Rpython ? ?Any > reasons??? For me, it's two major ones: 1. PyPy only recently hit a stability/performance point that makes it worth checking out, 2. Using non-pure-python modules wasn't straightforward (at least when I last looked) However, I've always felt the PyPy project was far more promising than Unladen Swallow. From rurpy at yahoo.com Wed Sep 1 22:57:16 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 1 Sep 2010 19:57:16 -0700 (PDT) Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <7a38148b-79e9-40ce-9700-2c0d1c9b3ee4@a4g2000prm.googlegroups.com> Message-ID: <4a3665a0-fc7f-425a-878e-6f8dcc5ed319@y11g2000yqm.googlegroups.com> On 09/01/2010 04:51 PM, Raymond Hettinger wrote: > On Aug 30, 6:03 am, a... at pythoncraft.com (Aahz) wrote: >> That reminds me: one co-worker (who really should have known better ;-) >> had the impression that sets were O(N) rather than O(1). Although >> writing that off as a brain-fart seems appropriate, it's also the case >> that the docs don't really make that clear, it's implied from requiring >> elements to be hashable. Do you agree that there should be a comment? > > There probably ought to be a HOWTO or FAQ entry on algorithmic > complexity > that covers classes and functions where the algorithms are > interesting. > That will concentrate the knowledge in one place where performance is > a > main theme and where the various alternatives can be compared and > contrasted. > I think most users of sets rarely read the docs for sets. The few lines > in the tutorial are enough so that most folks "just get it" and don't read > more detail unless they attempting something exotic. I think that attitude is very dangerous. There is a long history in this world of one group of people presuming what another group of people does or does not do or think. This seems to be a characteristic of human beings and is often used to promote one's own ideology. And even if you have hard evidence for what you say, why should 60% of people who don't read docs justify providing poor quality docs to the 40% that do? So while you may "think" most people rarely read the docs for basic language features and objects (I presume you don't mean to restrict your statement to only sets), I and most people I know *do* read them. And when read them I expect them, as any good reference documentation does, to completely and accurately describe the behavior of the item I am reading about. If big-O performance is deemed an intrinsic behavior of an (operation of) an object, it should be described in the documentation for that object. Your use of the word "exotic" is also suspect. I learned long ago to always click the "advanced options" box on dialogs because most developers/- designers really don't have a clue about what users need access to. > Our docs have gotten > somewhat voluminous, No they haven't (relative to what they attempt to describe). The biggest problem with the docs is that they are too terse. They often appear to have been written by people playing a game of "who can describe X in the minimum number of words that can still be defended as correct." While that may be fun, good docs are produced by considering how to describe something to the reader, completely and accurately, as effectively as possible. The test is not how few words were used, but how quickly the reader can understand the object or find the information being sought about the object. > so it's unlikely that adding that particular > needle to the haystack would have cured your colleague's "brain-fart" > unless he had been focused on a single document talking about the > performance > characteristics of various data structures. I don't know the colleague any more that you so I feel comfortable saying that having it very likely *would* have cured that brain-fart. That is, he or she very likely would have needed to check some behavior of sets at some point and would have either noted the big-O characteristics in passing, or would have noted that such information was available, and would have returned to the documentation when the need for that information arose. The reference description of sets is the *one* canonical place to look for information about sets. There are people who don't read documentation, but one has to be very careful not use the existence of such people as an excuse to justify sub-standard documentation. So I think relegating algorithmic complexity information to some remote document far from the description of the object it pertains to, is exactly the wrong approach. This is not to say that a performance HOWTO or FAQ in addition to the reference manual would not be good. From astan.chee at al.com.au Wed Sep 1 23:12:07 2010 From: astan.chee at al.com.au (Astan Chee) Date: Thu, 2 Sep 2010 13:12:07 +1000 Subject: killing all subprocess childrens Message-ID: <4C7F1607.8040308@al.com.au> Hi, I have a piece of code that looks like this: import subprocess retcode = subprocess.call(["java","test","string"]) print "Exited with retcode " + str(retcode) What I'm trying to do (and wondering if its possible) is to make sure that any children (and any descendants) of this process is killed when the main java process is killed (or dies). How do I do this in windows, linux and OSX? Thanks Astan From clp2 at rebertia.com Wed Sep 1 23:24:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Sep 2010 20:24:02 -0700 Subject: killing all subprocess childrens In-Reply-To: <4C7F1607.8040308@al.com.au> References: <4C7F1607.8040308@al.com.au> Message-ID: On Wed, Sep 1, 2010 at 8:12 PM, Astan Chee wrote: > Hi, > I have a piece of code that looks like this: > > import subprocess > retcode = subprocess.call(["java","test","string"]) > print "Exited with retcode " + str(retcode) > > What I'm trying to do (and wondering if its possible) is to make sure that > any children (and any descendants) of this process is killed when the main > java process is killed (or dies). > How do I do this in windows, linux and OSX? Something /roughly/ like: import os import psutil # http://code.google.com/p/psutil/ # your piece of code goes here myself = os.getpid() for proc in psutil.process_iter(): if proc.ppid == myself: proc.kill() Cheers, Chris -- http://blog.rebertia.com From astan.chee at al.com.au Wed Sep 1 23:30:40 2010 From: astan.chee at al.com.au (Astan Chee) Date: Thu, 2 Sep 2010 13:30:40 +1000 Subject: killing all subprocess childrens In-Reply-To: References: <4C7F1607.8040308@al.com.au> Message-ID: <4C7F1A60.6080000@al.com.au> Chris Rebert wrote: > import os > import psutil # http://code.google.com/p/psutil/ > > # your piece of code goes here > > myself = os.getpid() > for proc in psutil.process_iter(): > Is there a way to do this without psutil or installing any external modules or doing it from python2.5? Just wondering. Thanks again > if proc.ppid == myself: > proc.kill() > > Cheers, > Chris > -- > http://blog.rebertia.com > From rasjidw at gmail.com Wed Sep 1 23:59:44 2010 From: rasjidw at gmail.com (Rasjid Wilcox) Date: Thu, 2 Sep 2010 13:59:44 +1000 Subject: Private variables In-Reply-To: <1283394141.2136.5.camel@durian> References: <1283393212.2136.4.camel@durian> <1283394141.2136.5.camel@durian> Message-ID: On 2 September 2010 12:22, Ryan Kelly wrote: > On Thu, 2010-09-02 at 12:06 +1000, Ryan Kelly wrote: >> On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: >> > Hi all, >> > >> > I am aware the private variables are generally done via convention >> > (leading underscore), but I came across a technique in Douglas >> > Crockford's book "Javascript: The Good Parts" for creating private >> > variables in Javascript, and I'd thought I'd see how it translated to >> > Python. Here is my attempt. >> > >> > def get_config(_cache=[]): >> > ? ? private = {} >> > ? ? private['a'] = 1 >> > ? ? private['b'] = 2 >> > ? ? if not _cache: >> > ? ? ? ? class Config(object): >> > ? ? ? ? ? ? @property >> > ? ? ? ? ? ? def a(self): >> > ? ? ? ? ? ? ? ? return private['a'] >> > ? ? ? ? ? ? @property >> > ? ? ? ? ? ? def b(self): >> > ? ? ? ? ? ? ? ? return private['b'] >> > ? ? ? ? config = Config() >> > ? ? ? ? _cache.append(config) >> > ? ? else: >> > ? ? ? ? config = _cache[0] >> > ? ? return config >> > >> > >>> c = get_config() >> > >>> c.a >> > 1 >> > >>> c.b >> > 2 >> > >>> c.a = 10 >> > Traceback (most recent call last): >> > ? File "", line 1, in >> > AttributeError: can't set attribute >> > >>> dir(c) >> > ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', >> > '__getattribute__', '__hash__', '__init__', '__module__', '__new__', >> > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', >> > '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b'] >> > >>> d = get_config() >> > >>> d is c >> > True >> > >> > I'm not really asking 'is it a good idea' but just 'does this work'? >> > It seems to work to me, and is certainly 'good enough' in the sense >> > that it should be impossible to accidentally change the variables of >> > c. >> > >> > But is it possible to change the value of c.a or c.b with standard >> > python, without resorting to ctypes level manipulation? >> >> It's not easy, but it can be done by introspecting the property object >> you created and munging the closed-over dictionary object: >> >> ? ?>>> c = get_config() >> ? ?>>> c.a >> ? ?1 >> ? ?>>> c.__class__.__dict__['a'].fget.func_closure[0].cell_contents['a'] = 7 >> ? ?>>> c.a >> ? ?7 Ah! That is what I was looking for. > Heh, and of course I miss the even more obvious trick of just clobbering > the property with something else: > > >>> c.a > 1 > >>> setattr(c.__class__,"a",7) > >>> c.a > 7 Well, that is just cheating! :-) Anyway, thanks for that. I still think it is 'good enough' for those cases where private variables are 'required'. In both cases one has to go out of ones way to modify the attribute. OTOH, I guess it depends on what the use case is. If it is for storing a secret password that no other part of the system should have access to, then perhaps not 'good enough' at all. Cheers, Rasjid. From sarvilive at gmail.com Thu Sep 2 01:06:38 2010 From: sarvilive at gmail.com (sarvi) Date: Wed, 1 Sep 2010 22:06:38 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Message-ID: <3a854a6c-648b-43c6-b7f4-e7b0d849274b@x18g2000pro.googlegroups.com> On Sep 1, 6:49?pm, Benjamin Peterson wrote: > sarvi gmail.com> writes: > > Secondly I have always fantasized of never having to write C code yet > > get its compiled performance. > > With RPython(a strict subset of Python), I can actually compile it to > > C/Machine code > > RPython is not supposed to be a general purpose language. As a PyPy developer > myself, I can testify that it is no fun. Can be worse than than writing C/C++ Compared to Java, having the interpreter during development is huge I actually think yall at PyPy are hugely underestimating RPython. http://olliwang.com/2009/12/20/aes-implementation-in-rpython/ http://alexgaynor.net/2010/may/15/pypy-future-python/ Look at all the alternatives we have. Cython? Shedskin? I'll take PyPy anyday instead of them We make performance tradeoffs all the the time. Look at Mercurial. 90% python and 5% C Wouldn't you rather this be 90% Python and 5% RPython ??? Add to the possibility of writing Python extension module in RPython. You could be winning a whole group of developer mindshare. > > > > > Yet I see this forum relatively quite on PyPy or Rpython ? ?Any > > reasons??? > > You should post to the PyPy list instead. (See pypy.org) I tried. got bounced. Just subscribed. Will try again. Sarvi From wuwei23 at gmail.com Thu Sep 2 01:32:05 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 1 Sep 2010 22:32:05 -0700 (PDT) Subject: dirty problem 3 lines References: <4C7DC74D.6060702@mrabarnett.plus.com> Message-ID: <928816d6-e72f-4faf-882b-756fd185ce4c@w15g2000pro.googlegroups.com> bussiere bussiere wrote: > it's just as it seems : > i want to know how does ti works to get back an object from a string in python : > pickle.loads("""b'\x80\x03]q\x00(K\x00K\x01e.'""") #doesn't work Repeating the question without providing any further information doesn't really help. This is a byte string: b'\x80\x03]q\x00(K\x00K\x01e.' As MRAB points out, you can unpickle a byte string directly. This is a doc string: """note the triplet of double quotes""" What you have is a doc string that appears to contain a byte string: """b'\x80\x03]q\x00(K\x00K\x01e.'""" So the question for you is: what is putting the byte string inside of a doc string? If you can stop that from happening, then you'll have a byte string you can directly unpickle. Now, if you _don't_ have control over whatever is handing you the dump string, then you can just use string manipulation to reproduce the byte string: >>> dump = """b'\x80\x03]q\x00(K\x00K\x01e.'""" >>> badump = dump[2:-1].encode()[1:] >>> pickle.loads(badump) [0, 1] So: - dump[2:-1] strips off string representation of the byte string (b'...') - .encode() turns it into an actual byte string - [1:] strips a unicode blank from the start of the byte string (not entirely sure how that gets there...) After that it should be fine to unpickle. From nagle at animats.com Thu Sep 2 02:08:05 2010 From: nagle at animats.com (John Nagle) Date: Wed, 01 Sep 2010 23:08:05 -0700 Subject: Queue cleanup In-Reply-To: <7xmxs436qe.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <4c78f210$0$28655$c3e8da3@news.astraweb.com> <7xd3t0orah.fsf@ruckus.brouhaha.com> <4c7b279d$0$28650$c3e8da3@news.astraweb.com> <7xmxs436qe.fsf@ruckus.brouhaha.com> Message-ID: <4c7f3f43$0$1624$742ec2ed@news.sonic.net> On 8/30/2010 12:22 AM, Paul Rubin wrote: > I guess that is how the so-called smart pointers in the Boost C++ > template library work. I haven't used them so I don't have personal > experience with how convenient or reliable they are, or what kinds of > constraints they imposed on programming style. I've always felt a bit > suspicious of them though, and I seem to remember Alex Martelli (I hope > he shows up here again someday) advising against using them. "Smart pointers" in C++ have never quite worked right. They almost work. But there always seems to be something that needs access to a raw C pointer, which breaks the abstraction. The mold keeps creeping through the wallpaper. Also, since they are a bolt-on at the macro level in C++, reference count updates aren't optimized and hoisted out of loops. (They aren't in CPython either, but there have been reference counted systems that optimize out most reference count updates.) John Nagle From gallium.arsenide at gmail.com Thu Sep 2 02:32:23 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Wed, 1 Sep 2010 23:32:23 -0700 (PDT) Subject: importing excel data into a python matrix? References: Message-ID: <04da2ca7-092c-4a81-81a4-07636429408d@z7g2000yqg.googlegroups.com> On Sep 1, 7:45?pm, Chris Rebert wrote: > On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking > > wrote: > >?I'm working on a project where I have been given > > a 1000 by 1000 cell excel spreadsheet and I would > > like to be able to access the data using Python. > >?Does anyone know of a way that I can do this? > > "xlrd 0.7.1 - Library for developers to extract data from Microsoft > Excel (tm) spreadsheet files":http://pypi.python.org/pypi/xlrd While I heartily recommend xlrd, it only works with "traditional" Excel files (extension .xls, not .xlsx). If the data really is 1000 columns wide, it must be in the new (Excel 2007 or later) format, because the old only supported up to 256 columns. The most promising-looking Python package to handle .xlsx files is openpyxl. There are also a couple of older .xlsx readers (openpyxl can write as well). I have not tried any of these. John From stefan_ml at behnel.de Thu Sep 2 02:36:32 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 02 Sep 2010 08:36:32 +0200 Subject: PyPy and RPython In-Reply-To: <3a854a6c-648b-43c6-b7f4-e7b0d849274b@x18g2000pro.googlegroups.com> References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <3a854a6c-648b-43c6-b7f4-e7b0d849274b@x18g2000pro.googlegroups.com> Message-ID: sarvi, 02.09.2010 07:06: > Look at all the alternatives we have. Cython? Shedskin? > I'll take PyPy anyday instead of them Fell free to do so, but don't forget that the choice of a language always depends on the specific requirements at hand. Cython has proven its applicability in a couple of large projects, for example. And it has a lot more third party libraries available than both PyPy and Shedskin together: all Python libraries, pure Python and CPython binary extensions, as well as tons of code written in Cython, C, C++, Fortran, and then some. And you don't have to give up one bit of CPython compatibility to use all of that. That alone counts as a pretty huge advantage to some people. Stefan From nagle at animats.com Thu Sep 2 02:39:57 2010 From: nagle at animats.com (John Nagle) Date: Wed, 01 Sep 2010 23:39:57 -0700 Subject: PyPy and RPython In-Reply-To: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Message-ID: <4c7f46bb$0$1663$742ec2ed@news.sonic.net> On 9/1/2010 10:49 AM, sarvi wrote: > > Is there a plan to adopt PyPy and RPython under the python foundation > in attempt to standardize both. > > I have been watching PyPy and RPython evolve over the years. > > PyPy seems to have momentum and is rapidly gaining followers and > performance. > > PyPy JIT and performance would be a good thing for the Python > Community > And it seems to be well ahead of Unladen Swallow in performance and in > a position to improve quite a bit. > > > Secondly I have always fantasized of never having to write C code yet > get its compiled performance. > With RPython(a strict subset of Python), I can actually compile it to > C/Machine code > > > These 2 seem like spectacular advantages for Python to pickup on. > And all this by just showing the PyPy and the Python foundation's > support and direction to adopt them. > > > Yet I see this forum relatively quiet on PyPy or Rpython ? Any > reasons??? > > Sarvi The winner on performance, by a huge margin, is Shed Skin, the optimizing type-inferring compiler for a restricted subset of Python. PyPy and Unladen Swallow have run into the problem that if you want to keep some of the less useful dynamic semantics of Python, the heavy-duty optimizations become extremely difficult. However, if we defined a High Performance Python language, with some restrictions, the problem becomes much easier. The necessary restrictions are roughly this: -- Functions, once defined, cannot be redefined. (Inlining and redefinition do not play well together.) -- Variables are implicitly typed for the base types: integer, float, bool, and everything else. The compiler figures this out automatically. (Shed Skin does this now.) -- Unless a class uses a "setattr" function or has a __setattr__ method, its entire list of attributes is known at compile time. (In other words, you can't patch in new attributes from outside the class unless the class indicates it supports that. You can subclass, of course.) -- Mutable objects (other than some form of synchronized object) cannot be shared between threads. This is the key step in getting rid of the Global Interpreter Lock. -- "eval" must be restricted to the form that has a list of the variables it can access. -- Import after startup probably won't work. Those are the essential restrictions. With those, Python could go 20x to 60x faster than CPython. The failures of PyPy and Unladen Swallow to get any significant performance gains over CPython demonstrate the futility of trying to make the current language go fast. Reference counts aren't a huge issue. With some static analysis, most reference count updates can be optimized out. (As for how this is done, the key issue is to determine whether each function "keeps" a reference to each parameter. For any function which does not, that parameter doesn't have to have reference count updates within the function. Most math library functions have this property. You do have to analyze the entire program globally, though.) John Nagle From arnodel at googlemail.com Thu Sep 2 02:43:27 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 02 Sep 2010 07:43:27 +0100 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: Dmitry Chichkov writes: > Given: a large list (10,000,000) of floating point numbers; > Task: fastest python code that finds k (small, e.g. 10) smallest > items, preferably with item indexes; > Limitations: in python, using only standard libraries (numpy & scipy > is Ok); > > I've tried several methods. With N = 10,000,000, K = 10 The fastest so > far (without item indexes) was pure python implementation > nsmallest_slott_bisect (using bisect/insert). And with indexes > nargsmallest_numpy_argmin (argmin() in the numpy array k times). > > Anyone up to the challenge beating my code with some clever selection > algorithm? > > Current Table: > 1.66864395142 mins_heapq(items, n): > 0.946580886841 nsmallest_slott_bisect(items, n): > 1.38014793396 nargsmallest(items, n): > 10.0732769966 sorted(items)[:n]: > 3.17916202545 nargsmallest_numpy_argsort(items, n): > 1.31794500351 nargsmallest_numpy_argmin(items, n): > 2.37499308586 nargsmallest_numpy_array_argsort(items, n): > 0.524670124054 nargsmallest_numpy_array_argmin(items, n): > > 0.0525538921356 numpy argmin(items): 1892997 > 0.364673852921 min(items): 10.0000026786 I think without numpy, nsmallest_slott_bisect is almost optimal. There is a slight improvement: 1.33862709999 nsmallest_slott_bisect(items, n): [10.000011643188717, 10.000017791492528] 0.883894920349 nsmallest_slott_bisect2(items, n): [10.000011643188717, 10.000017791492528] ==== code ==== from bisect import insort from itertools import islice def nsmallest_slott_bisect(iterable, n, insort=insort): it = iter(iterable) mins = sorted(islice(it, n)) for el in it: if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates insort(mins, el) mins.pop() return mins def nsmallest_slott_bisect2(iterable, n, insort=insort): it = iter(iterable) mins = sorted(islice(it, n)) maxmin = mins[-1] for el in it: if el <= maxmin: #NOTE: equal sign is to preserve duplicates insort(mins, el) mins.pop() maxmin = mins[-1] return mins import time from random import randint, random test_data = [randint(10, 50) + random() for i in range(10000000)] K = 10 init = time.time() mins = nsmallest_slott_bisect(test_data, K) print time.time() - init, 'nsmallest_slott_bisect(items, n):', mins[: 2] init = time.time() mins = nsmallest_slott_bisect2(test_data, K) print time.time() - init, 'nsmallest_slott_bisect2(items, n):', mins[: 2] -- Arnaud From swapnil.st at gmail.com Thu Sep 2 02:57:21 2010 From: swapnil.st at gmail.com (swapnil) Date: Wed, 1 Sep 2010 23:57:21 -0700 (PDT) Subject: python path separator Message-ID: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> I could not find any documentation for variables os.path.sep and os.path.altsep. Although the first is pretty straightforward can anyone explain the purpose of the second variable? Is it even useful? According to issue http://bugs.python.org/issue709428, os.path.altsep was 'None' till a long time and it didn't bother anyone? From __peter__ at web.de Thu Sep 2 02:59:59 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 08:59:59 +0200 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: Dmitry Chichkov wrote: > Given: a large list (10,000,000) of floating point numbers; > Task: fastest python code that finds k (small, e.g. 10) smallest > items, preferably with item indexes; > Limitations: in python, using only standard libraries (numpy & scipy > is Ok); > > I've tried several methods. With N = 10,000,000, K = 10 The fastest so > far (without item indexes) was pure python implementation > nsmallest_slott_bisect (using bisect/insert). And with indexes > nargsmallest_numpy_argmin (argmin() in the numpy array k times). > > Anyone up to the challenge beating my code with some clever selection > algorithm? If you don't care about stability, i. e. whether nlargest(2, [1, 2, 2.0]) returns [1, 2] or [1, 2.0], use _heapq.nlargest() directly $ python nsmallest_perf2.py nsmallest --> 0.142784833908 nsmallest_slott_bisect --> 0.19291305542 $ cat nsmallest_perf2.py from random import randint, random import time from bisect import insort from itertools import islice import _heapq _funcs = [] def timeit(f): _funcs.append(f) def time_all(*args): funcs = _funcs width = max(len(f.__name__) for f in funcs) prev = None for f in funcs: start = time.time() result = f(*args) end = time.time() print "%-*s --> %10s" % (width, f.__name__, end - start) if prev is None: prev = result else: assert prev == result timeit(_heapq.nsmallest) @timeit def nsmallest_slott_bisect(n, iterable, insort=insort): it = iter(iterable) mins = sorted(islice(it, n)) for el in it: if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates insort(mins, el) mins.pop() return mins test_data = [randint(10, 50) + random() for i in range(10**6)] K = 10 time_all(K, test_data) Peter From __peter__ at web.de Thu Sep 2 03:18:06 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 09:18:06 +0200 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: Dmitry Chichkov wrote: > Code: A lot of the following doesn't run or returns incorrect results. To give but one example: > def nargsmallest_numpy_argmin(iter, k): > distances = N.asarray(iter) > mins = [] Could you please provide an up-to-date version? Peter PS: for an easy way to ensure consistency see timeit/time_all in my previous post. From vlastimil.brom at gmail.com Thu Sep 2 03:25:23 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 2 Sep 2010 09:25:23 +0200 Subject: python path separator In-Reply-To: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> References: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> Message-ID: 2010/9/2 swapnil : > I could not find any documentation for variables os.path.sep and > os.path.altsep. Although the first is pretty straightforward can > anyone explain the purpose of the second variable? Is it even useful? > According to issue http://bugs.python.org/issue709428, os.path.altsep > was 'None' till a long time and it didn't bother anyone? > -- > http://mail.python.org/mailman/listinfo/python-list > see http://docs.python.org/library/os.html#os.sep http://docs.python.org/library/os.html#os.altsep On windows it returns a slash >>> os.altsep '/' which is often easier to use (i.e. if I understand correctly, in most usual cases the forward slash should probably just work on most of the recent OSes). vbr From anand.sadasivam at gmail.com Thu Sep 2 03:29:41 2010 From: anand.sadasivam at gmail.com (Anand Sadasivam) Date: Thu, 2 Sep 2010 12:59:41 +0530 Subject: Is python is the safest language ... Message-ID: Hi All, Is python is the safest language is my question. I feel its good language, but however java has good occupancy. About four years back I did few python programs and worked with some of add-on product over ZOPE and Plone. The suggestion to me is mostly welcome. Regards, -- Anand.S anand.sadasivam at gmail.com asadasiv at gmail.com +91 99025 38904 -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at googlemail.com Thu Sep 2 03:47:57 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 2 Sep 2010 00:47:57 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: <1c854f03-f2fd-4bc2-acda-d6791561e2cc@f25g2000yqc.googlegroups.com> On Sep 2, 7:59?am, Peter Otten <__pete... at web.de> wrote: > Dmitry Chichkov wrote: > > Given: a large list (10,000,000) of floating point numbers; > > Task: fastest python code that finds k (small, e.g. 10) smallest > > items, preferably with item indexes; > > Limitations: in python, using only standard libraries (numpy & scipy > > is Ok); > > > I've tried several methods. With N = 10,000,000, K = 10 The fastest so > > far (without item indexes) was pure python implementation > > nsmallest_slott_bisect (using bisect/insert). And with indexes > > nargsmallest_numpy_argmin (argmin() in the numpy array k times). > > > Anyone up to the challenge beating my code with some clever selection > > algorithm? > > If you don't care about stability, i. e. whether nlargest(2, [1, 2, 2.0]) > returns [1, 2] or [1, 2.0], use > > _heapq.nlargest() directly > > $ python nsmallest_perf2.py > nsmallest ? ? ? ? ? ? ?--> 0.142784833908 > nsmallest_slott_bisect --> 0.19291305542 > $ cat nsmallest_perf2.py > from random import randint, random > import time > from bisect ? ?import insort > from itertools import islice > import _heapq > > _funcs = [] > def timeit(f): > ? ? _funcs.append(f) > > def time_all(*args): > ? ? funcs = _funcs > ? ? width = max(len(f.__name__) for f in funcs) > ? ? prev = None > ? ? for f in funcs: > ? ? ? ? start = time.time() > ? ? ? ? result = f(*args) > ? ? ? ? end = time.time() > ? ? ? ? print "%-*s --> %10s" % (width, f.__name__, end - start) > ? ? ? ? if prev is None: > ? ? ? ? ? ? prev = result > ? ? ? ? else: > ? ? ? ? ? ? assert prev == result > > timeit(_heapq.nsmallest) > > @timeit > def nsmallest_slott_bisect(n, iterable, insort=insort): > ? ? it ? = iter(iterable) > ? ? mins = sorted(islice(it, n)) > ? ? for el in it: > ? ? ? ? if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates > ? ? ? ? ? ? insort(mins, el) > ? ? ? ? ? ? mins.pop() > ? ? return mins > > test_data = [randint(10, 50) + random() for i in range(10**6)] > K = 10 > > time_all(K, test_data) > > Peter I get: 1.46s for _heapq.nsmallest 0.85s for nsmallest_slott_bisect2 (version I posted) I am a bit surprised that mine is so slow compared with yours. I'll do more tests later! -- Arnaud From ldo at geek-central.gen.new_zealand Thu Sep 2 03:49:23 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 02 Sep 2010 19:49:23 +1200 Subject: Windows vs. file.read References: Message-ID: In message , MRAB wrote: > You should open the files in binary mode, not text mode, ie file(path, > "rb"). Text mode is the default. Not a problem on *nix because the line > ending is newline. We used to pride ourselves on not having to worry about text versus binary I/O modes on *nix, but I?m beginning to think the reality is we have to adopt it. To start with, it means we can automatically handle different newline conventions with text files originating on different systems. From clp2 at rebertia.com Thu Sep 2 04:00:00 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 2 Sep 2010 01:00:00 -0700 Subject: Is python is the safest language ... In-Reply-To: References: Message-ID: On Thu, Sep 2, 2010 at 12:29 AM, Anand Sadasivam wrote: > Hi All, > > Is python is the safest language is my question. I feel its good language, > but however java has good occupancy. About four years back I did few python > programs and worked with some of add-on product over ZOPE and Plone. The question is vague. "Safest" in what sense? Type safety? Long-term viability? Difficulty in the programmer shooting themself in the foot? Cheers, Chris -- http://blog.rebertia.com From sschwarzer at sschwarzer.net Thu Sep 2 04:06:50 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Thu, 02 Sep 2010 10:06:50 +0200 Subject: Is there a Python equivalent to Perl's File::Listing::parse_dir In-Reply-To: <4c62ead3$0$1587$742ec2ed@news.sonic.net> References: <4c62ead3$0$1587$742ec2ed@news.sonic.net> Message-ID: <4C7F5B1A.3000905@sschwarzer.net> Hi John, On 2010-08-11 20:24, John Nagle wrote: > Perl has a function which will take a remote directory page, in > the form that most web sites return for a file directory, and > parse it into a useful form: > > http://www.xav.com/perl/site/lib/File/Listing.html > > This is especially useful for FTP sites. > > Is there a Python equivalent of this? I'm converting some > old Perl code. > > Even the Python FTP module doesn't have a directory parser. I saw this posting only now. I hope it's not too late to point you to ftputil, http://ftputil.sschwarzer.net . :-) As the name implies, it's FTP-only for now, though. If you have any questions regarding the library, please ask. Stefan From fetchinson at googlemail.com Thu Sep 2 04:12:23 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 2 Sep 2010 10:12:23 +0200 Subject: fairly urgent request: paid python (or other) work required In-Reply-To: References: Message-ID: On 9/1/10, lkcl wrote: > i apologise for having to contact so many people but this is fairly > urgent, and i'm running out of time and options. i'm a free software > programmer, and i need some paid work - preferably python - fairly > urgently, so that i can pay for food and keep paying rent, and so that > my family doesn't get deported or have to leave the country. > > i really would not be doing this unless it was absolutely, absolutely > essential that i get money. > > so that both i and the list are not unnecessarily spammed, please > don't reply with recommendations of "where to get jobs", unless they > are guaranteed to result in immediate work and money. > > if you have need of a highly skilled and experienced python-preferring > free-software-preferring software engineer, please simply contact me, > and tell me what you need doing: there's no need for you to read the > rest of this message. > > so that people are not offended by me asking on such a high-volume > list for work, here are some questions and answers: > > Q: who are you? > A: luke leighton. free sofware developer, free software project > leader, and "unusual cross-project mash-up-er" (meaning: i spot the > value of joining one or more bits of disparate "stuff" to make > something that's more powerful than its components). > > Q: where's your CV? > A: executive version of CV is at http://lkcl.net/exec_cv.txt - please > don't ask for a proprietary microsoft word version, as a refusal and > referral to the "sylvester response" often offends. > > Q: what can you do? > A: python programming, c programming, web development, networking, > cryptography, reverse-engineering, IT security, etc. etc. preferably > involving free software. > > Q: what do you need? > A: money to pay rent and food. at the ABSOLUTE MINIMUM, i need as > little as ?1500 per month to pay everything, and have been earning > approx ?800 per month for the past year. a ?5000 inheritance last > year which i was not expecting has delayed eviction and bankruptcy for > me and my family, and deportation for my partner and 17 month old > daughter (marie is here in the UK on a FLR/M visa) > > Q: why are you asking here? > A: because it's urgent that i get money really really soon; my family > members are refusing to assist, and the few friends that i have do not > have any spare money to lend. > > Q: why here and not "monster jobs" or "python-jobs list" or the > various "recruitment agencies"? > A: those are full-time employment positions, which i have been > frequently applying for and get rejected for various reasons, and i'm > running out of time and money. further interviews cost money, and do > not result in guaranteed work. i need work - and money - _now_. > > Q: why here and not "peopleperhour.com"? > A: if you've ever bid on peopleperhour.com you will know that you are > bidding against "offshore" contrators and even being undercut by 1st > world country bidders who, insanely, appear to be happy to do work for > as little as ?2 / hour. > > Q: why are you getting rejected from interviews? > A: that's complex. a) i simply don't interview well. people with the > classic symptoms of asperger's just don't. b) my daughter is 17 months > old. when i go away for as little as 3 days, which i've done three > times now, she is extremely upset both when i am away and when i > return. i think what would happen if i was doing some sort of full- > time job, away from home, and... i can't do it. subconsciously that > affects how i react when speaking to interviewers. > > Q: why do you not go "get a job at tesco's" or "drive a truck"? > A: tescos and HGV driving etc. pay around ?12 per hour. ?12 per hour > after tax comes down to about ?8 to ?9 per hour. ?9 per hour requires > 35 hours per week to earn as little as ?1500. 35 hours per week is > effectively full-time, and means that a) my programming and software > engineering skills are utterly, utterly wasted b) my daughter gets > extremely upset because i won't be at home. > > so you get the gist, and thank you for putting up with me needing to > take this action. For the sake of your family, I'd recommend taking the following paragraphs off your cv: """ If you require someone whom you do NOT want to take the initiative to assess all aspects of the required work and beyond; if you require someone who will "stay in the box", do NOT contact me. """ """ The speed at which I acquire new knowledge and be able to integrate and recommend new ideas tends to make insecure people feel frightened and threatened. """ """ Pet Hates: - "peer to peer networking" [peer equals neanderthal...] - "microsoft marketing machine" [FUD at its best...] - "restrictive anti-competitive business practices" - "information-restricive laws" [DMCA etc.] - Unreliable systems that cannot be made to do the job you really needed done yesterday... """ I'd also recommend updating the links on your cv, these ones do not work at all: http://www.well.com/~lkcl http://dcerpc.net/person/index.xvl?acct=person:lkcl http://www.watfordcleaningsupplies.co.uk https://secure.digimask.com/ http://dcerpc.net And this one is outdated: http://sourceforge.net/projects/python/ HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From no.email at nospam.invalid Thu Sep 2 04:16:54 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Sep 2010 01:16:54 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> Message-ID: <7x8w3kimq1.fsf@ruckus.brouhaha.com> Dennis Lee Bieber writes: >> GC's for large systems ... copy the live objects to a new contiguous heap > That sounds suspiciously like the original Macintosh OS, with its > "handles"... IE, double-indirection. Nah, a double indirection on every access would be a terrible performance hit. The classic approach is when you move an object to the new heap, you leave a tagged forwarding pointer at its former location the old heap, giving the its location in the new heap. Then as you move other objects, you dereference the pointers in them to see whether they point to moved or unmoved objects, and relocate any unmoved ones. A more complete explanation is here: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-33.html#%_sec_5.3.2 From __peter__ at web.de Thu Sep 2 04:17:30 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 10:17:30 +0200 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> <1c854f03-f2fd-4bc2-acda-d6791561e2cc@f25g2000yqc.googlegroups.com> Message-ID: Arnaud Delobelle wrote: > I get: > > 1.46s for _heapq.nsmallest > 0.85s for nsmallest_slott_bisect2 (version I posted) > > I am a bit surprised that mine is so slow compared with yours. I'll > do more tests later! Strange. I see a significant difference only for python3 (on 64bit Linux) $ python3 nsmallest_perf3.py 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] pick the 10 smallest items out of 5000000 nsmallest --> 0.310983181 nsmallest_slott_bisect --> 1.02625894547 nsmallest_slott_bisect2 --> 0.612951040268 $ python nsmallest_perf3.py 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] pick the 10 smallest items out of 5000000 nsmallest --> 0.743387937546 nsmallest_slott_bisect --> 0.961116075516 nsmallest_slott_bisect2 --> 0.746085882187 Peter From sarvilive at gmail.com Thu Sep 2 04:29:54 2010 From: sarvilive at gmail.com (sarvi) Date: Thu, 2 Sep 2010 01:29:54 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> Message-ID: When I think about it these restrictions below seem a very reasonable tradeoff for performance. And I can use this for just the modules/sections that are performance critical. Essentially, the PyPy interpreter can have a restricted mode that enforces these restriction. This will help write such RPython code that can then be compiled into C/ASM using the PyPy Compiler which as I understand can do this today. If Shedskin generated C++ code is faster than PyPy generate C++ code. Isn't that just another reason why PyPy and Shedskin should be joining forces. Wouldn't we want PyPy generated C code to be just as fast as Shedskin's Afterall thats how the PyPy compiler is built, right? and we do want that to be fast too? Sarvi On Sep 1, 11:39?pm, John Nagle wrote: > On 9/1/2010 10:49 AM, sarvi wrote: > > > > > > > > > Is there a plan to adopt PyPy and RPython under the python foundation > > in attempt to standardize both. > > > I have been watching PyPy and RPython evolve over the years. > > > PyPy seems to have momentum and is rapidly gaining followers and > > performance. > > > PyPy JIT and performance would be a good thing for the Python > > Community > > And it seems to be well ahead of Unladen Swallow in performance and in > > a position to improve quite a bit. > > > Secondly I have always fantasized of never having to write C code yet > > get its compiled performance. > > With RPython(a strict subset of Python), I can actually compile it to > > C/Machine code > > > These 2 seem like spectacular advantages for Python to pickup on. > > And all this by just showing the PyPy and the Python foundation's > > support and direction to adopt them. > > > Yet I see this forum relatively quiet on PyPy or Rpython ? ?Any > > reasons??? > > > Sarvi > > ? ? ?The winner on performance, by a huge margin, is Shed Skin, > the optimizing type-inferring compiler for a restricted subset > of Python. ?PyPy and Unladen Swallow have run into the problem > that if you want to keep some of the less useful dynamic semantics > of Python, the heavy-duty optimizations become extremely difficult. > > ? ? ?However, if we defined a High Performance Python language, with > some restrictions, the problem becomes much easier. ?The necessary > restrictions are roughly this: > > -- Functions, once defined, cannot be redefined. > ? ? (Inlining and redefinition do not play well > ? ? together.) > > -- Variables are implicitly typed for the base types: > ? ? integer, float, bool, and everything else. ?The > ? ? compiler figures this out automatically. > ? ? (Shed Skin does this now.) > > -- Unless a class uses a "setattr" function or has > ? ? a __setattr__ method, its entire list of attributes is > ? ? known at compile time. > ? ? (In other words, you can't patch in new attributes > ? ? from outside the class unless the class indicates > ? ? it supports that. ?You can subclass, of course.) > > -- Mutable objects (other than some form of synchronized > ? ? object) cannot be shared between threads. ?This is the > ? ? key step in getting rid of the Global Interpreter Lock. > > -- "eval" must be restricted to the form that has a list of > ? ? the variables it can access. > > -- Import after startup probably won't work. > > Those are the essential restrictions. ?With those, Python > could go 20x to 60x faster than CPython. ?The failures > of PyPy and Unladen Swallow to get any significant > performance gains over CPython demonstrate the futility > of trying to make the current language go fast. > > Reference counts aren't a huge issue. ?With some static > analysis, most reference count updates can be optimized out. > (As for how this is done, the key issue is to determine whether > each function "keeps" a reference to each parameter. ?For > any function which does not, that parameter doesn't have > to have reference count updates within the function. > Most math library functions have this property. > You do have to analyze the entire program globally, though.) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle From dchichkov at gmail.com Thu Sep 2 04:47:58 2010 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Thu, 2 Sep 2010 01:47:58 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: Uh. I'm sorry about the confusion. Last three items are just O(N) baselines. Python min(), Numpy argmin(), Numpy asarray(). I'll update the code. Thanks! > A lot of the following doesn't run or returns incorrect results. > To give but one example: > > > def nargsmallest_numpy_argmin(iter, k): > > ? ? distances = N.asarray(iter) > > ? ? mins = [] > > Could you please provide an up-to-date version? > > Peter > > PS: for an easy way to ensure consistency see timeit/time_all in my previous > post. From dchichkov at gmail.com Thu Sep 2 05:20:14 2010 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Thu, 2 Sep 2010 02:20:14 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: <96c70ee2-2662-499e-afbf-a90f7f85cec4@k1g2000prl.googlegroups.com> By the way, improving n-ARG-smallest (that returns indexes as well as values) is actually more desirable than just regular n-smallest: == Result == 1.38639092445 nargsmallest 3.1569879055 nargsmallest_numpy_argsort 1.29344892502 nargsmallest_numpy_argmin Note that numpy array constructor eats around 0.789. == Code == from operator import itemgetter from random import randint, random from itertools import islice from time import time def nargsmallest(iterable, n): it = enumerate(iterable) mins = sorted(islice(it, n), key = itemgetter(1)) loser = mins[-1][1] # largest of smallest for el in it: if el[1] <= loser: # NOTE: preserve dups mins.append(el) mins.sort(key = itemgetter(1)) mins.pop() loser = mins[-1][1] return mins def nargsmallest_numpy_argsort(iter, k): distances = N.asarray(iter) return [(i, distances[i]) for i in distances.argsort()[0:k]] def nargsmallest_numpy_argmin(iter, k): mins = [] distances = N.asarray(iter) for i in xrange(k): j = distances.argmin() mins.append((j, distances[j])) distances[j] = float('inf') return mins test_data = [randint(10, 50) + random() for i in range(10000000)] K = 10 init = time() mins = nargsmallest(test_data, K) print time() - init, 'nargsmallest:', mins[:2] import numpy as N init = time() mins = nargsmallest_numpy_argsort(test_data, K) print time() - init, 'nargsmallest_numpy_argsort:', mins[:2] init = time() mins = nargsmallest_numpy_argmin(test_data, K) print time() - init, 'nargsmallest_numpy_argmin:', mins[:2] From mahaboobnisha at gmail.com Thu Sep 2 06:00:52 2010 From: mahaboobnisha at gmail.com (roshini begum) Date: Thu, 2 Sep 2010 03:00:52 -0700 (PDT) Subject: comp.lang.python Message-ID: www.127760.blogspot.com From michael at perfect-kreim.de Thu Sep 2 06:02:40 2010 From: michael at perfect-kreim.de (Michael Kreim) Date: Thu, 02 Sep 2010 12:02:40 +0200 Subject: Speed-up for loops Message-ID: <4C7F7640.1010102@perfect-kreim.de> Hi, I was comparing the speed of a simple loop program between Matlab and Python. My Codes: $ cat addition.py imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a $ cat addition.m imax = 1e9; a = 0; for i=0:imax-1 a = a + 10; end disp(a); exit; The results look like this: $ /usr/bin/time --verbose python addition.py 10000000000 Command being timed: "python addition.py" User time (seconds): 107.30 System time (seconds): 0.08 Percent of CPU this job got: 97% Elapsed (wall clock) time (h:mm:ss or m:ss): 1:50.09 [...] $ /usr/bin/time --verbose matlab -nodesktop -nosplash -r "addition" [...] 1.0000e+10 Command being timed: "matlab -nodesktop -nosplash -r addition" User time (seconds): 7.65 System time (seconds): 0.18 Percent of CPU this job got: 94% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.25 [...] Unfortunately my Python Code was much slower and I do not understand why. Are there any ways to speed up the for/xrange loop? Or do I have to live with the fact that Matlab beats Python in this example? Thanks a lot for your answers. With best regards, Michael From swapnil.st at gmail.com Thu Sep 2 06:22:27 2010 From: swapnil.st at gmail.com (swapnil) Date: Thu, 2 Sep 2010 03:22:27 -0700 (PDT) Subject: python path separator References: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> Message-ID: On Sep 2, 12:25?pm, Vlastimil Brom wrote: > 2010/9/2 swapnil :> I could not find any documentation for variables os.path.sep and > > os.path.altsep. Although the first is pretty straightforward can > > anyone explain the purpose of the second variable? Is it even useful? > > According to issuehttp://bugs.python.org/issue709428, os.path.altsep > > was 'None' till a long time and it didn't bother anyone? > > -- > >http://mail.python.org/mailman/listinfo/python-list > > seehttp://docs.python.org/library/os.html#os.sephttp://docs.python.org/library/os.html#os.altsep > > On windows it returns a slash>>> os.altsep > > '/' > which is often easier to use (i.e. if I understand correctly, in most > usual cases the forward slash should probably just work on most of the > recent OSes). > > ? ?vbr Thanks for help From magguru.chinnamnaidu at gmail.com Thu Sep 2 06:33:04 2010 From: magguru.chinnamnaidu at gmail.com (paypal cash) Date: Thu, 2 Sep 2010 03:33:04 -0700 (PDT) Subject: I GOT $5000 FROM PAYPAL BY SIMPLE HACK. Message-ID: I GOT $5000 FROM PAYPAL BY SIMPLE HACK At http://happyandeasy.co.cc Due to high security risks, i have hidden the PayPal Form link in an image. in that website On RIGHT SIDE Below search box , click on image and enter your PAYPAL id And Your name. From __peter__ at web.de Thu Sep 2 06:36:51 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 12:36:51 +0200 Subject: Speed-up for loops References: Message-ID: Michael Kreim wrote: > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Are there any ways to speed up the for/xrange loop? Move it into a function; this turns a and i into local variables. def f(): imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a f() > Or do I have to live with the fact that Matlab beats Python in this > example? I think so. From bussiere at gmail.com Thu Sep 2 06:49:30 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Thu, 2 Sep 2010 12:49:30 +0200 Subject: dirty problem 3 lines In-Reply-To: <928816d6-e72f-4faf-882b-756fd185ce4c@w15g2000pro.googlegroups.com> References: <4C7DC74D.6060702@mrabarnett.plus.com> <928816d6-e72f-4faf-882b-756fd185ce4c@w15g2000pro.googlegroups.com> Message-ID: It seems to work perfectly thanks a lot Bussiere Google Fan boy On Thu, Sep 2, 2010 at 7:32 AM, alex23 wrote: > bussiere bussiere wrote: >> it's just as it seems : >> i want to know how does ti works to get back an object from a string in python : >> pickle.loads("""b'\x80\x03]q\x00(K\x00K\x01e.'""") #doesn't work > > Repeating the question without providing any further information > doesn't really help. > > This is a byte string: b'\x80\x03]q\x00(K\x00K\x01e.' > As MRAB points out, you can unpickle a byte string directly. > > This is a doc string: """note the triplet of double quotes""" > What you have is a doc string that appears to contain a byte string: > """b'\x80\x03]q\x00(K\x00K\x01e.'""" > > So the question for you is: what is putting the byte string inside of > a doc string? If you can stop that from happening, then you'll have a > byte string you can directly unpickle. > > Now, if you _don't_ have control over whatever is handing you the dump > string, then you can just use string manipulation to reproduce the > byte string: > >>>> dump = """b'\x80\x03]q\x00(K\x00K\x01e.'""" >>>> badump = dump[2:-1].encode()[1:] >>>> pickle.loads(badump) > [0, 1] > > So: > ?- dump[2:-1] strips off string representation of the byte string > (b'...') > ?- .encode() turns it into an actual byte string > ?- [1:] strips a unicode blank from the start of the byte string (not > entirely sure how that gets there...) > > After that it should be fine to unpickle. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From michael at perfect-kreim.de Thu Sep 2 07:16:08 2010 From: michael at perfect-kreim.de (Michael Kreim) Date: Thu, 02 Sep 2010 13:16:08 +0200 Subject: Speed-up for loops In-Reply-To: References: Message-ID: <4C7F8778.5030509@perfect-kreim.de> Peter Otten wrote: > Move it into a function; this turns a and i into local variables. > > def f(): > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > f() Wow. It is still slower than Matlab, but your suggestion speeds up the code by ca 50%. But I do not understand why the change of a global to a local variable gives such a big difference. $ cat addition.py imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a $ cat additionOtten.py def f(): imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a f() $ /usr/bin/time --verbose python addition.py 10000000000 Command being timed: "python addition.py" User time (seconds): 110.52 System time (seconds): 0.01 Percent of CPU this job got: 98% Elapsed (wall clock) time (h:mm:ss or m:ss): 1:52.76 [...] $ /usr/bin/time --verbose python additionOtten.py 10000000000 Command being timed: "python additionOtten.py" User time (seconds): 56.38 System time (seconds): 0.00 Percent of CPU this job got: 99% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:56.64 [...] From __peter__ at web.de Thu Sep 2 07:43:11 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 13:43:11 +0200 Subject: Speed-up for loops References: Message-ID: Michael Kreim wrote: > Peter Otten wrote: >> Move it into a function; this turns a and i into local variables. >> >> def f(): >> imax = 1000000000 >> a = 0 >> for i in xrange(imax): >> a = a + 10 >> print a >> f() > > Wow. It is still slower than Matlab, but your suggestion speeds up the > code by ca 50%. > But I do not understand why the change of a global to a local variable > gives such a big difference. Basically the local namespace is a C array where accessing an item is just pointer arithmetic while the global namespace is a Python dictionary. There may be optimisations for the latter. If you can read C have a look at the LOAD/STORE_FAST and LOAD/STORE_GLOBAL implementations for the gory details: http://svn.python.org/view/python/trunk/Python/ceval.c?view=markup Peter From ndbecker2 at gmail.com Thu Sep 2 07:45:16 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 02 Sep 2010 07:45:16 -0400 Subject: argparse list Message-ID: I'm interested in using argparse to parse a string formatted as: my_prog --option1=1,10,37 That is, a list of comma delimited values. I guess nargs almost does it, but expects options to be space-delimited. What would be the easiest approach? From __peter__ at web.de Thu Sep 2 07:58:15 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 13:58:15 +0200 Subject: argparse list References: Message-ID: Neal Becker wrote: > I'm interested in using argparse to parse a string formatted as: > > my_prog --option1=1,10,37 > > That is, a list of comma delimited values. I guess nargs almost does it, > but expects options to be space-delimited. > > What would be the easiest approach? >>> import argparse >>> def csv(value): ... return map(int, value.split(",")) ... >>> p = argparse.ArgumentParser() >>> p.add_argument("--option1", type=csv) and None >>> p.parse_args(["--option1=1,10,37"]) Namespace(option1=[1, 10, 37]) >>> _.option1[0] 1 Peter From ndbecker2 at gmail.com Thu Sep 2 08:26:35 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 02 Sep 2010 08:26:35 -0400 Subject: argparse list References: Message-ID: Peter Otten wrote: >>>> import argparse >>>> def csv(value): > ... return map(int, value.split(",")) > ... >>>> p = argparse.ArgumentParser() >>>> p.add_argument("--option1", type=csv) and None >>>> p.parse_args(["--option1=1,10,37"]) Thanks! But, why the 'and None'? From tom.h.miller at gmail.com Thu Sep 2 08:31:28 2010 From: tom.h.miller at gmail.com (Tom Miller) Date: Thu, 2 Sep 2010 08:31:28 -0400 Subject: Safely decoding user input Message-ID: Hello everyone, Before I pose my question, I should mention that I'm still pretty unfamiliar with proper terminology for string encoding, so I might get some of it wrong. Please bear with me. I'm writing a program that accepts arguments from the command line. Some of my users are using Windows with a non-unicode locale setting and characters outside of the ascii set. So something like $ program --option ultimately results in "UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-3: invalid data" My questions: 1) Is it safe to immediately decode all strings in sys.argv[] with something like sys.argv = [string.decode(sys.stdin.encoding) for string in sys.argv]? 2) Can something similar be done to anything returned by raw_input()? Thanks, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Sep 2 08:34:21 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 14:34:21 +0200 Subject: argparse list References: Message-ID: Neal Becker wrote: > Peter Otten wrote: > >>>>> import argparse >>>>> def csv(value): >> ... return map(int, value.split(",")) >> ... >>>>> p = argparse.ArgumentParser() >>>>> p.add_argument("--option1", type=csv) and None >>>>> p.parse_args(["--option1=1,10,37"]) > > Thanks! But, why the 'and None'? To hide the result of p.add_argument(). >>> "irrelevant junk" 'irrelevant junk' >>> "irrelevant junk" and None >>> I'm not going to do it again ;) Peter From alekseymv at gmail.com Thu Sep 2 08:42:55 2010 From: alekseymv at gmail.com (Aleksey) Date: Thu, 2 Sep 2010 05:42:55 -0700 (PDT) Subject: parsing string into dict References: Message-ID: <7fee17a9-6417-457b-a8cc-5de65028440f@f6g2000yqa.googlegroups.com> On Sep 2, 12:46?am, Tim Arnold wrote: > Hi, > I have a set of strings that are *basically* comma separated, but with > the exception that if a comma occur insides curly braces it is not a > delimiter. ?Here's an example: > > [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] > > I'd like to parse that into a dictionary (note that 'continued' gets > the value 'true'): > {'code':'one', 'caption':'{My Analysis for \textbf{t}, Version > 1}','continued':'true'} > > I know and love pyparsing, but for this particular code I need to rely > only on the standard library (I'm running 2.7). Here's what I've got, > and it works. I wonder if there's a simpler way? > thanks, > --Tim Arnold > > The 'line' is like my example above but it comes in without the ending > bracket, so I append one on the 6th line. > You can use regular expression (also you not need adding ending bracket): import re patt = re.compile(ur'\[code=(?P\w+),\scaption=(?P\{.+\}) (?P,\scontinued)?\]?') def parse_options(s): g=patt.match(s).groupdict() return {'caption' : g['CAPTION'], 'code' : g['CODE'], 'continued' : g['CONTINUED'] and True or False} Test is next: >>> s=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued]' >>> s1=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}]' >>> s2=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued' >>> s3=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}' >>> parse_options(s) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': True} >>> parse_options(s1) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': False} >>> parse_options(s2) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': True} >>> parse_options(s3) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': False} >>> From alekseymv at gmail.com Thu Sep 2 08:43:16 2010 From: alekseymv at gmail.com (Aleksey) Date: Thu, 2 Sep 2010 05:43:16 -0700 (PDT) Subject: parsing string into dict References: Message-ID: <43144686-cbc3-4816-8d49-1ead2217223e@u6g2000yqh.googlegroups.com> On Sep 2, 12:46?am, Tim Arnold wrote: > Hi, > I have a set of strings that are *basically* comma separated, but with > the exception that if a comma occur insides curly braces it is not a > delimiter. ?Here's an example: > > [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] > > I'd like to parse that into a dictionary (note that 'continued' gets > the value 'true'): > {'code':'one', 'caption':'{My Analysis for \textbf{t}, Version > 1}','continued':'true'} > > I know and love pyparsing, but for this particular code I need to rely > only on the standard library (I'm running 2.7). Here's what I've got, > and it works. I wonder if there's a simpler way? > thanks, > --Tim Arnold > > The 'line' is like my example above but it comes in without the ending > bracket, so I append one on the 6th line. > You can use regular expression (also you not need adding ending bracket): import re patt = re.compile(ur'\[code=(?P\w+),\scaption=(?P\{.+\}) (?P,\scontinued)?\]?') def parse_options(s): g=patt.match(s).groupdict() return {'caption' : g['CAPTION'], 'code' : g['CODE'], 'continued' : g['CONTINUED'] and True or False} Test is next: >>> s=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued]' >>> s1=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}]' >>> s2=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued' >>> s3=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}' >>> parse_options(s) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': True} >>> parse_options(s1) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': False} >>> parse_options(s2) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': True} >>> parse_options(s3) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': False} >>> From tim.wintle at teamrubber.com Thu Sep 2 08:55:16 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 02 Sep 2010 13:55:16 +0100 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <1283432116.14252.37.camel@tim-laptop> On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: > Hi, > > I was comparing the speed of a simple loop program between Matlab and > Python. > Unfortunately my Python Code was much slower and I do not understand why. The main reason is that, under the hood, cpython does something like this (in psudo-code) itterator = xrange(imax) while 1: next_attribute = itterator.next try: i = next_attribute() except: break a = a + 10 where C (and I'm assuming matlab) does this: while 1: i = i + 1 if (i > imax): break a = a + 10 And the function call in the python is fairly expensive on it's own. Plus it has to do all the standard interpreter stuff for memory management and deciding when to give up the GIL etc. > Are there any ways to speed up the for/xrange loop? leaving it in python, no. (well, "range" is faster in 2.x, but once you get some cache misses due to increased memory usage it's much slower) avoiding iteration by using list comprehensions can help a lot though as it avoids most of the function calls. If you really need to optimise it then you can convert that module to cython by adding a cdef, and then compile it: cdef int i for i in xrange(imax): a = a + 10 print a or you can write it in C it'll run a lot faster. From bauketilma at gmail.com Thu Sep 2 09:08:18 2010 From: bauketilma at gmail.com (Duim) Date: Thu, 2 Sep 2010 06:08:18 -0700 (PDT) Subject: profiling qt programs Message-ID: I'm trying to get a qt program a little faster by looking at the most expensive functions. To find out which functions are most important I wanted to profile the application using cProfile module. Unfortunately this runs through the complete code in 1 go without waiting until all threads (or in whatever way QT is running), are finished. Is there a way to globally profile all running python functions? I saw in this mail http://old.nabble.com/cProfile-and-threads-td29458757.html mention of a profile.enable()/disable() function. Or is this "wishful thinking/mailing"? From stefan_ml at behnel.de Thu Sep 2 09:25:10 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 02 Sep 2010 15:25:10 +0200 Subject: Speed-up for loops In-Reply-To: <1283432116.14252.37.camel@tim-laptop> References: <4C7F7640.1010102@perfect-kreim.de> <1283432116.14252.37.camel@tim-laptop> Message-ID: Tim Wintle, 02.09.2010 14:55: > If you really need to optimise it then you can convert that module to > cython by adding a cdef, and then compile it: > > cdef int i > for i in xrange(imax): > a = a + 10 > print a > > or you can write it in C it'll run a lot faster. Just to get the context right here: a C implementation won't run even a tad faster than the obvious Cython version, but both will run "a lot faster" than the Python version. Plus, if Cython knows that the imax value is small enough, it'll infer "int" for the "i" variable automatically, so you won't need the "cdef" annotation. It won't automatically do that for "a", though, as that might break Python's unlimited integer semantics if "imax" and/or "a" are large enough. Stefan From wherespythonmonks at gmail.com Thu Sep 2 09:48:41 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 2 Sep 2010 09:48:41 -0400 Subject: first non-null element in a list, otherwise None Message-ID: This should be trivial: I am looking to extract the first non-None element in a list, and "None" otherwise. Here's one implementation: >>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) >>> print x 1 I thought maybe a generator expression would be better, to prevent iterating over the whole list: >>> x = ( x for x in [None,1,2] if x is not None ).next() >>> print x 1 However, the generator expression throws if the list is entirely None. With list comprehensions, a solution is: >>> x = ([ x for x in [None,1,2] if x is not None ] + [ None ] )[0] But this can be expensive memory wise. Is there a way to concatenate generator expressions? More importantly, Is there a better way? (In one line?) Thanks, W From __peter__ at web.de Thu Sep 2 09:57:59 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 15:57:59 +0200 Subject: first non-null element in a list, otherwise None References: Message-ID: wheres pythonmonks wrote: > I am looking to extract the first non-None element in a list, and > "None" otherwise. Here's one implementation: > >>>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) >>>> print x > 1 > > I thought maybe a generator expression would be better, to prevent > iterating over the whole list: > >>>> x = ( x for x in [None,1,2] if x is not None ).next() >>>> print x > 1 > > However, the generator expression throws if the list is entirely None. The next() builtin (new in Python 2.6) allows you to provide a default: >>> next((item for item in [None, None, "found"] if item is not None), "no match") 'found' >>> next((item for item in [None, None, None] if item is not None), "no match") 'no match' > With list comprehensions, a solution is: > >>>> x = ([ x for x in [None,1,2] if x is not None ] + [ None ] )[0] > > But this can be expensive memory wise. Is there a way to concatenate > generator expressions? itertools.chain() Peter From hniksic at xemacs.org Thu Sep 2 10:03:01 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 02 Sep 2010 16:03:01 +0200 Subject: Speed-up for loops References: Message-ID: <87wrr4gs4q.fsf@busola.homelinux.net> Michael Kreim writes: > Are there any ways to speed up the for/xrange loop? > Or do I have to live with the fact that Matlab beats Python in this > example? To a point, yes. However, there are things you can do to make your Python code go faster. One has been pointed out by Peter. Another is that Python treats numbers as regular heap objects, so creating a bunch of unneeded integers by xrange slows things down (despite allocation of integer objects being heavily optimized). For this reason, you may want to change xrange(1000000000) to itertools.repeat(None, 1000000000). $ python -m timeit -s 'from itertools import repeat' 'for _ in repeat(None, 100000): pass' 1000 loops, best of 3: 1.71 msec per loop $ python -m timeit -s 'from itertools import repeat' 'for _ in xrange(100000): pass' 100 loops, best of 3: 2.43 msec per loop From michele.simionato at gmail.com Thu Sep 2 10:11:27 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 2 Sep 2010 07:11:27 -0700 (PDT) Subject: argparse list References: Message-ID: On Sep 2, 1:45?pm, Neal Becker wrote: > I'm interested in using argparse to parse a string formatted as: > > my_prog --option1=1,10,37 > > That is, a list of comma delimited values. ?I guess nargs almost does it, > but expects options to be space-delimited. > > What would be the easiest approach? In plac (http://pypi.python.org/pypi/plac) you would write the following: import plac @plac.annotations( option1=('option with comma separated values', 'option', 'o', lambda x: x.split(','))) def main(option1): print option1 if __name__ == '__main__': plac.call(main) From wherespythonmonks at gmail.com Thu Sep 2 10:11:32 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 2 Sep 2010 10:11:32 -0400 Subject: first non-null element in a list, otherwise None In-Reply-To: References: Message-ID: Peter wrote: >> But this can be expensive memory wise. ?Is there a way to concatenate >> generator expressions? > > itertools.chain() > Aha! import itertools >>> x = itertools.chain( (x for x in [None,None] if x is not None), [ None ] ).next() >>> print x None >>> x = itertools.chain( (x for x in [None,7] if x is not None), [ None ] ).next() >>> print x 7 >>> W From r.koebler at yahoo.de Thu Sep 2 10:13:39 2010 From: r.koebler at yahoo.de (Roland Koebler) Date: Thu, 2 Sep 2010 16:13:39 +0200 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <20100902141339.GA31040@localhost> Hi, > Are there any ways to speed up the for/xrange loop? You can use psyco. The following example should be about 4-times as fast as your example: import psyco psyco.full() def f(): imax = 1000000000 a = 0 for i in xrange(imax): a += 10 print a f() regards, Roland From arnodel at googlemail.com Thu Sep 2 11:01:34 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 2 Sep 2010 08:01:34 -0700 (PDT) Subject: first non-null element in a list, otherwise None References: Message-ID: <2971a79a-82ae-49b7-b3ab-71396e39231d@t2g2000yqe.googlegroups.com> On Sep 2, 2:48?pm, wheres pythonmonks wrote: > This should be trivial: > > I am looking to extract the first non-None element in a list, and > "None" otherwise. ?Here's one implementation: > > >>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) > >>> print x > > 1 > > I thought maybe a generator expression would be better, to prevent > iterating over the whole list: > > >>> x = ( x for x in [None,1,2] if x is not None ).next() > >>> print x > > 1 > > However, the generator expression throws if the list is entirely None. > > With list comprehensions, a solution is: > > >>> x = ([ x for x in [None,1,2] if x is not None ] + [ None ] )[0] > > But this can be expensive memory wise. ?Is there a way to concatenate > generator expressions? > > More importantly, > > Is there a better way? ?(In one line?) > > Thanks, > > W Just for fun: >>> print min([None, 2, None, None, 1], key=lambda x: x is None) 2 >>> print min([None, None, None], key=lambda x: x is None) None Looks clever but: min([], key=lambda x: x is None) throws an exception. -- Arnaud From ian at ianhobson.co.uk Thu Sep 2 11:22:04 2010 From: ian at ianhobson.co.uk (Ian Hobson) Date: Thu, 02 Sep 2010 16:22:04 +0100 Subject: Help needed with Windows Service in Python Message-ID: <4C7FC11C.7030904@ianhobson.co.uk> Hi All, I am attempting to create a Windows Service in Python. I have the framework (from Mark Hammond and Andy Robinason's book) running - see below. It starts fine - but it will not stop. :( net stop "Python Service" and using the services GUI both leave the services showing it as "stopping" I guess this means SvcStop is called but it is not enough to get it out of the machine. Does anyone know why not? Python 2.7 with win32 extensions, sunning on Windows 7. Many thanks Ian the (complete) source code is #!/usr/bin/env python # coding=utf8 # service.py = testing services and Named pipes # import win32serviceutil import win32service import win32event class PythonService(win32serviceutil.ServiceFramework): _svc_name_ = "Python Service" _svc_display_name_ = "Test Service in Python" def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self,args) self.hWaitStop = win32event.CreateEvent(None,0,0,None) def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) wind32event.SetEvent(self.hWaitStop) def SvcDoRun(self): win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) if __name__ == '__main__': win32serviceutil.HandleCommandLine(PythonService) From grflanagan at gmail.com Thu Sep 2 11:28:39 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 02 Sep 2010 16:28:39 +0100 Subject: first non-null element in a list, otherwise None In-Reply-To: References: Message-ID: wheres pythonmonks wrote: > This should be trivial: > > > I am looking to extract the first non-None element in a list, and > "None" otherwise. Here's one implementation: > >>>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) >>>> print x > 1 > > I thought maybe a generator expression would be better, to prevent > iterating over the whole list: > >>>> x = ( x for x in [None,1,2] if x is not None ).next() >>>> print x > 1 > > However, the generator expression throws if the list is entirely None. > > With list comprehensions, a solution is: > >>>> x = ([ x for x in [None,1,2] if x is not None ] + [ None ] )[0] > > But this can be expensive memory wise. Is there a way to concatenate > generator expressions? > > More importantly, > > Is there a better way? (In one line?) > > Thanks, > > W itertools.dropwhile(lambda x: x is None, inlist + [0]).next() or None From nobody at nowhere.com Thu Sep 2 11:52:00 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Sep 2010 16:52:00 +0100 Subject: killing all subprocess childrens References: Message-ID: On Thu, 02 Sep 2010 13:12:07 +1000, Astan Chee wrote: > I have a piece of code that looks like this: > > import subprocess > retcode = subprocess.call(["java","test","string"]) > print "Exited with retcode " + str(retcode) > > What I'm trying to do (and wondering if its possible) is to make sure > that any children (and any descendants) of this process is killed when > the main java process is killed (or dies). > How do I do this in windows, linux and OSX? I don't think that you can do it reliably on any of those platforms. Consider: A spawns B, B spawns C, C spawns D, B and C terminate. There is no information available to tie D to A. A knows that it spawned B, and D's PPID is C, but C no longer exists so you can't tell that B spawned C. Process groups won't help, as subprocess.Popen() doesn't put the child into a new process group, so all of its descendents will share the PGID of the Python process and any children spawned from it. Even it did use a new process group, the descendents might have different process groups (quite likely if the initial child is a shell script, as the shell executes each "command" in a new process group). If you avoid the subprocess module and use os.fork(), the child can create a new session by fork()ing again, and having the grandchild call os.setsid(). All descendents will share this session unless they explicitly create a new session (and you probably shouldn't be killing any descendents which explicitly create a new session). Another option is if to create the child with std{in,out,err} set to a descriptor created for that specific child. Descendents inherit their descriptors unless explicitly changed. The same applies to the CWD, and (by convention) the environment. On Linux, you can discover a process' descriptors, cwd and environment via the /proc filesystem. From nobody at nowhere.com Thu Sep 2 11:57:08 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Sep 2010 16:57:08 +0100 Subject: python path separator References: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> Message-ID: On Wed, 01 Sep 2010 23:57:21 -0700, swapnil wrote: > I could not find any documentation for variables os.path.sep and > os.path.altsep. Although the first is pretty straightforward can > anyone explain the purpose of the second variable? Is it even useful? The purpose is so that you can do e.g.: if c == os.path.sep or c == os.path.altsep: ... On Windows, both '\' and '/' are directory separators; you shouldn't rely upon a particular one being used, but should check for either. From nobody at nowhere.com Thu Sep 2 12:05:25 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Sep 2010 17:05:25 +0100 Subject: Speed-up for loops References: Message-ID: On Thu, 02 Sep 2010 12:02:40 +0200, Michael Kreim wrote: > I was comparing the speed of a simple loop program between Matlab and > Python. > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Are there any ways to speed up the for/xrange loop? Sure; the above can be reduced to just: print imax * 10 ;) More seriously, if you're comparing against Matlab, you should look at NumPy. If there's a reasonably direct approach using NumPy, it will be much quicker than a Python "for" loop (in a sense, NumPy is a library of useful "for" loops implemented in C). Even a fairly indirect NumPy approach is often quicker than pure Python. From darcy at druid.net Thu Sep 2 12:06:03 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 2 Sep 2010 12:06:03 -0400 Subject: Customizing cgitb Message-ID: <20100902120603.4f56b8d5.darcy@druid.net> I have a small problem with the cgitb module. I know that I can basically write my own version but it seems kind of silly to rewrite something that does 99% what I want. Here is an excerpt from the output of an exception. 1520 (current_job['job_id'], job['_SELECT_'])) 1521 1522 elif job['_ACTION_'].startswith('queue_'): 1523 action = job['_ACTION_'][6:] 1524 if action == 'mod': job = {'_PARENTDIR_': '', '__BAD_DATA__': [], '_REMOTE...orage('npq7', '5')]), '_REMOTE_HOST_': 'unknown'} ].startswith undefined My problem is that the "job =" line is abridging the value. I need to see all of the variables in the dictionary. Is there any way I can wrap cgitb and get the behaviour I want or do I have to write my own method for sys.excepthook? -- 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 mrabarnett.plus.com Thu Sep 2 12:15:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Sep 2010 17:15:24 +0100 Subject: Windows vs. file.read In-Reply-To: References: Message-ID: <4C7FCD9C.9020901@mrabarnett.plus.com> On 02/09/2010 08:49, Lawrence D'Oliveiro wrote: > In message, MRAB > wrote: > >> You should open the files in binary mode, not text mode, ie file(path, >> "rb"). Text mode is the default. Not a problem on *nix because the line >> ending is newline. > > We used to pride ourselves on not having to worry about text versus binary > I/O modes on *nix, but I?m beginning to think the reality is we have to > adopt it. > > To start with, it means we can automatically handle different newline > conventions with text files originating on different systems. In Python 3 the difference is important because binary mode works with bytes and text mode works with strings, plus the file encoding and line endings. From __peter__ at web.de Thu Sep 2 13:02:35 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 19:02:35 +0200 Subject: Customizing cgitb References: Message-ID: D'Arcy J.M. Cain wrote: > I have a small problem with the cgitb module. I know that I can > basically write my own version but it seems kind of silly to rewrite > something that does 99% what I want. Here is an excerpt from the > output of an exception. > > 1520 (current_job['job_id'], job['_SELECT_'])) > 1521 > 1522 elif job['_ACTION_'].startswith('queue_'): > 1523 action = job['_ACTION_'][6:] > 1524 if action == 'mod': > job = {'_PARENTDIR_': '', '__BAD_DATA__': [], '_REMOTE...orage('npq7', > '5')]), '_REMOTE_HOST_': 'unknown'} ].startswith undefined > > My problem is that the "job =" line is abridging the value. I need to > see all of the variables in the dictionary. Is there any way I can > wrap cgitb and get the behaviour I want or do I have to write my own > method for sys.excepthook? You could try to monkey-patch pydoc: import pydoc def cram(text, maxlen): return text pydoc.cram = cram Peter From 71david at libero.it Thu Sep 2 13:03:51 2010 From: 71david at libero.it (David) Date: Thu, 2 Sep 2010 19:03:51 +0200 Subject: Help needed with Windows Service in Python References: Message-ID: Il Thu, 02 Sep 2010 16:22:04 +0100, Ian Hobson ha scritto: > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) You may try to give a WaitHint parameter to ReportServiceStatus call, otherwise the Service Manager will expect the service is stopped istantly. self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 1000) David From tim.wintle at teamrubber.com Thu Sep 2 13:05:47 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 02 Sep 2010 18:05:47 +0100 Subject: Speed-up for loops In-Reply-To: <20100902141339.GA31040@localhost> References: <4C7F7640.1010102@perfect-kreim.de> <20100902141339.GA31040@localhost> Message-ID: <1283447147.17916.1.camel@tim-laptop> On Thu, 2010-09-02 at 16:13 +0200, Roland Koebler wrote: > Hi, > > > Are there any ways to speed up the for/xrange loop? > You can use psyco. Assuming you've got a 32-bit machine. From vs at it.uu.se Thu Sep 2 13:12:54 2010 From: vs at it.uu.se (Virgil Stokes) Date: Thu, 02 Sep 2010 19:12:54 +0200 Subject: Financial time series data Message-ID: <4C7FDB16.9020208@it.uu.se> Has anyone written code or worked with Python software for downloading financial time series data (e.g. from Yahoo financial)? If yes, would you please contact me. --Thanks, V. Stokes From darcy at druid.net Thu Sep 2 13:30:45 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 2 Sep 2010 13:30:45 -0400 Subject: Customizing cgitb In-Reply-To: References: Message-ID: <20100902133045.c8b944fb.darcy@druid.net> On Thu, 02 Sep 2010 19:02:35 +0200 Peter Otten <__peter__ at web.de> wrote: > You could try to monkey-patch pydoc: I suppose so. Not a comfortable solution of course. It's bad enough when you get too familiar with the internals of a module but even worse when you need to get familiar with the internals of modules imported by a module. I'll give it a shot though. > import pydoc > def cram(text, maxlen): > return text > pydoc.cram = cram Or... import pydoc pydoc.cram = lambda text,maxlen: text Thanks. -- 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 pbloom at crystald.com Thu Sep 2 14:12:50 2010 From: pbloom at crystald.com (Philip Bloom) Date: Thu, 2 Sep 2010 11:12:50 -0700 Subject: Speed-up for loops In-Reply-To: References: Message-ID: <2DEFEB25B65B1D4C962D79E3CCBAFC7F09C03467@mpkexc01.eidos.com> Uh. Try: Imax=1000000000 a=0 i=0 While(i I was comparing the speed of a simple loop program between Matlab and > Python. > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Are there any ways to speed up the for/xrange loop? Sure; the above can be reduced to just: print imax * 10 ;) More seriously, if you're comparing against Matlab, you should look at NumPy. If there's a reasonably direct approach using NumPy, it will be much quicker than a Python "for" loop (in a sense, NumPy is a library of useful "for" loops implemented in C). Even a fairly indirect NumPy approach is often quicker than pure Python. -- http://mail.python.org/mailman/listinfo/python-list ______________________________________________________________________ This email has been scanned by the MessageLabs ______________________________________________________________________ ______________________________________________________________________ This email has been scanned by the MessageLabs ______________________________________________________________________ From ipatrol6010 at yahoo.com Thu Sep 2 14:13:51 2010 From: ipatrol6010 at yahoo.com (ipatrol6010 at yahoo.com) Date: Thu, 2 Sep 2010 14:13:51 -0400 Subject: Help needed with Windows Service in Python Message-ID: Well for one, if you're writing with pywin32, you certainly don't need the shbang line. #! /usr/bin/env is purely a POSIX thing. From hidura at gmail.com Thu Sep 2 14:15:06 2010 From: hidura at gmail.com (Hidura) Date: Thu, 2 Sep 2010 15:15:06 -0300 Subject: Financial time series data In-Reply-To: <4C7FDB16.9020208@it.uu.se> References: <4C7FDB16.9020208@it.uu.se> Message-ID: But what kind of data you want to download?, because the financial time it's basicly html code and you can work very well with a parser 2010/9/2, Virgil Stokes : > Has anyone written code or worked with Python software for downloading > financial time series data (e.g. from Yahoo financial)? If yes, would you > please contact me. > > --Thanks, > V. Stokes > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From ipatrol6010 at yahoo.com Thu Sep 2 14:21:23 2010 From: ipatrol6010 at yahoo.com (ipatrol6010 at yahoo.com) Date: Thu, 2 Sep 2010 14:21:23 -0400 Subject: Windows vs. file.read Message-ID: Correct in that regard. In Python 3.x, strings are by default considered UTF-8. Wheras ASCII isn't a problem because it's fixed-width, UTF-8 will give you a different character depending on the last byte value. Therefore handling any kind of data that is not UTF-8 will need you to open it with 'b' and uses bytes instead of str (literals with b'some value'). Just an FYI. From victorsubervi at gmail.com Thu Sep 2 14:34:46 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 2 Sep 2010 14:34:46 -0400 Subject: MySQL Problem Message-ID: Hi; I have this code: print 'select * from spreadsheets s join products p on p.Item=s.Item join productsCategories pc on p.ID=pc.ProductsID join categories c on pc.CategoryID=c.ID where s.Client="%s" order by c.Category, c.Parent' % (client,) cursor.execute('select * from spreadsheets s join products p on p.Item=s.Item join productsCategories pc on p.ID=pc.ProductsID join categories c on pc.CategoryID=c.ID where s.Client=%s order by c.Category, c.Parent', (client,)) tmp = cursor.fetchall() print tmp Now, when I run the print of the mysql command in the mysql interpreter, it gives me the following data: mysql> select * from spreadsheets s join products p on p.Item=s.Item join productsCategories pc on p.ID=pc.ProductsID join categories c on pc.CategoryID=c.ID where s.Client='Lincoln_Properties' order by c.Category, c.Parent; +-----+--------------------+-------+------------+--------+------+-----+------------+------------------------------------------------------+---------+-------+-----+------------+------------+----+-------------------+----------------------+ | ID | Client | Multi | Item | Markup | Temp | ID | Item | Description | UOM | Cost | ID | ProductsID | CategoryID | ID | Category | Parent | +-----+--------------------+-------+------------+--------+------+-----+------------+------------------------------------------------------+---------+-------+-----+------------+------------+----+-------------------+----------------------+ | 163 | Lincoln_Properties | 0 | 5349513 | 53.22 | NULL | 39 | 5349513 | 24833RNH 24" x 33 " 8 Mic Natural Can Liners | 1000/CS | 25.63 | 39 | 39 | 23 | 23 | Can Liners | Bags | | 156 | Lincoln_Properties | 0 | 5349520 | 30.00 | NULL | 31 | 5349520 | Can Liners Coreless 45 gal Clear | 250/CS | 28.69 | 31 | 31 | 23 | 23 | Can Liners | Bags | | 161 | Lincoln_Properties | 0 | 40x48Green | 99.32 | NULL | 37 | 40x48Green | Green Can Liners | 1000/cs | 17.56 | 37 | 37 | 23 | 23 | Can Liners | Bags | | 160 | Lincoln_Properties | 0 | 24x33Green | 60.04 | NULL | 36 | 24x33Green | Green Can Liners | 1000/CS | 20.27 | 36 | 36 | 23 | 23 | Can Liners | Bags | | 162 | Lincoln_Properties | 0 | 5349518 | 26.02 | NULL | 38 | 5349518 | 28048VNR01 40" x 48" HI-D | 250/CS | 25.63 | 38 | 38 | 1 | 1 | Facility Supplies | BASE | | 152 | Lincoln_Properties | 0 | 4440120 | 72.44 | NULL | 35 | 4440120 | 91315 Pearlescent White Lotion Gallon Soap | 4/CS | 17.85 | 35 | 35 | 67 | 67 | Liquid Hand | Soap | | 609 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | 343 | 2030572 | Americo 20" Beige Floor Pad | 5/cs | 15.88 | 335 | 343 | 49 | 49 | Mats | Restaurant Paper/Pla | | 159 | Lincoln_Properties | 0 | 2028071 | 20.00 | NULL | 34 | 2028071 | 25025088 77 Sanisac Liner | 500/CS | 14.88 | 34 | 34 | 34 | 34 | Tampons | Bathroom Paper | | 158 | Lincoln_Properties | 0 | 2062866 | 33.31 | NULL | 33 | 2062866 | 7410 1/2 Fold Seat Cover | 3000/CS | 35.81 | 33 | 33 | 35 | 35 | Toilet Seat Cover | Bathroom Paper | | 155 | Lincoln_Properties | 0 | 5380447 | 30.00 | NULL | 30 | 5380447 | Scottfold Foldedd Towel 1-Ply White | 4375/CS | 35.00 | 30 | 30 | 33 | 33 | Toilet Tissue | Bathroom Paper | | 154 | Lincoln_Properties | 0 | 5207270 | 7.01 | NULL | 29 | 5207270 | Standard Roll Bath Tissue 2-Ply White | 80/CS | 43.50 | 29 | 29 | 33 | 33 | Toilet Tissue | Bathroom Paper | | 164 | Lincoln_Properties | 0 | 5207269 | 20.00 | NULL | 28 | 5207269 | 17713-00 Kleenex Cottonelle 2-Ply Toilet Tissue | 60/CS | 35.50 | 28 | 28 | 33 | 33 | Toilet Tissue | Bathroom Paper | | 157 | Lincoln_Properties | 0 | 5217344 | 17.49 | NULL | 32 | 5217344 | 1900-60 Kleenex Scottfold White Towel | 2400/CS | 26.81 | 32 | 32 | 32 | 32 | Towels | Bathroom Paper | +-----+--------------------+-------+------------+--------+------+-----+------------+------------------------------------------------------+---------+-------+-----+------------+------------+----+-------------------+----------------------+ 13 rows in set (0.00 sec) You will notice there is this data therein: | 609 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | 343 | 2030572 | Americo 20" Beige Floor Pad | 5/cs | 15.88 | 335 | 343 | 49 | 49 | Mats | Restaurant Paper/Pla | That particular item does *not* show up when I print tmp! That is, for some reason running the command through python *omits* this one data!! The only difference is that a flag in spreadsheets (Temp) is set to 1. Why on earth doesn't it work in python?? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From hobson42 at gmaiil.com Thu Sep 2 14:45:01 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 02 Sep 2010 19:45:01 +0100 Subject: Help needed with Windows Service in Python In-Reply-To: References: Message-ID: <4C7FF0AD.1030203@gmaiil.com> On 02/09/2010 18:03, David wrote: > Il Thu, 02 Sep 2010 16:22:04 +0100, Ian Hobson ha scritto: > >> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > You may try to give a WaitHint parameter to ReportServiceStatus call, > otherwise the Service Manager will expect the service is stopped istantly. > > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 1000) > > > David Thanks David. Sadly that makes no difference. From victorsubervi at gmail.com Thu Sep 2 14:51:04 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 2 Sep 2010 14:51:04 -0400 Subject: Reversing a List In-Reply-To: References: <20100901141554.a8d606f0.matt@scotweb.co.uk> Message-ID: On Wed, Sep 1, 2010 at 9:26 AM, Shashwat Anand wrote: > > > On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton wrote: > >> On Wed, 1 Sep 2010 09:00:03 -0400 >> Victor Subervi wrote: >> >> > Hi; >> > I have this code: >> > >> > cursor.execute('describe products;') >> > cols = [item[0] for item in cursor] >> > cols = cols.reverse() >> > cols.append('Delete') >> > cols = cols.reverse() >> > >> > Unfortunately, the list doesn't reverse. If I print cols after the first >> > reverse(), it prints None. Please advise. >> >> The reverse() method modifies the list in place, but returns None, so just >> use >> >>> cols.reverse() >> >> rather than >> >>> cols = cols.reverse() >> > > Alternatively you can do \, > > >>>cols = reversed(cols) > Thanks again, all beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From hobson42 at gmaiil.com Thu Sep 2 15:02:24 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 02 Sep 2010 20:02:24 +0100 Subject: MySQL Problem In-Reply-To: References: Message-ID: <4C7FF4C0.1010503@gmaiil.com> On 02/09/2010 19:34, Victor Subervi wrote: > for some reason running the command through python *omits* this one > data!! The only difference is that a flag in spreadsheets (Temp) is > set to 1. Why on earth doesn't it work in python?? Some ideas to follow up. (These are only guesses). 1) One of the enum type fields contains an invalid value (perhaps a value removed from the column definition). 2) The second id field (products.id?) appears to be very large. I wonder what would happen if it was larger than the auto-increment value? 3) A field in the one of the rows in the missing data contains bytes that are invalid in the character encoding you are using in python. 4) The python field type used for some column in the missing row, contains a value that cannot be held in the python variable assigned. Regards Ian From ekozlowski1 at gmail.com Thu Sep 2 15:06:48 2010 From: ekozlowski1 at gmail.com (Edward Kozlowski) Date: Thu, 2 Sep 2010 12:06:48 -0700 (PDT) Subject: Help needed with Windows Service in Python References: Message-ID: On Sep 2, 10:22?am, Ian Hobson wrote: > Hi All, > > I am attempting to create a Windows Service in Python. > > I have the framework (from Mark Hammond and Andy Robinason's book) > running - see below. It starts fine - but it will not stop. :( > > net stop "Python Service" > > and using the services GUI both leave the services showing it as "stopping" > > I guess this means SvcStop is called but it is not enough to get it out > of the machine. > > Does anyone know why not? > > Python 2.7 with win32 extensions, sunning on Windows 7. > > Many thanks > > Ian > > the (complete) source code is > #!/usr/bin/env python > # coding=utf8 > # ? service.py ?= testing services and Named pipes > # > import win32serviceutil > import win32service > import win32event > class PythonService(win32serviceutil.ServiceFramework): > ? ?_svc_name_ = "Python Service" > ? ?_svc_display_name_ = "Test Service in Python" > ? ?def __init__(self, args): > ? ? ?win32serviceutil.ServiceFramework.__init__(self,args) > ? ? ?self.hWaitStop = win32event.CreateEvent(None,0,0,None) > ? ?def SvcStop(self): > ? ? ?self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > ? ? ?wind32event.SetEvent(self.hWaitStop) > ? ?def SvcDoRun(self): > ? ? ?win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) > if __name__ == '__main__': > ? ?win32serviceutil.HandleCommandLine(PythonService) Looks to me like there may be a typo in your code. You probably meant win32event.SetEvent(self.hWaitStop), not wind32event. Regards, -Edward Kozlowski From __peter__ at web.de Thu Sep 2 15:13:24 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 21:13:24 +0200 Subject: Speed-up for loops References: Message-ID: Philip Bloom wrote: > Uh. > Try: > Imax=1000000000 > a=0 > i=0 > While(i a= a+10 > i=i+1 > print a > I suspect you will find it is way faster than using range or xrange for > large numbers and map far more closely in the final result to what you > are doing on matlab's side. At least last I checked, xrange and range > both involve iterating through an array, which is much slower in all > cases than just doing an int vs int compare (which is what your matlab > is doing). How did you check? $ python -m timeit "for i in xrange(1000000): pass" 10 loops, best of 3: 47.5 msec per loop $ python -m timeit "i = 0" "while i < 1000000: i += 1" 10 loops, best of 3: 152 msec per loop $ So an empty while loop takes about three times as long as the equivalent for loop. Also: """ class xrange(object) | xrange([start,] stop[, step]) -> xrange object | | Like range(), but instead of returning a list, returns an object that | generates the numbers in the range on demand. For looping, this is | slightly faster than range() and more memory efficient. """ Peter From thomas at jollybox.de Thu Sep 2 15:30:56 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 2 Sep 2010 21:30:56 +0200 Subject: Windows vs. file.read In-Reply-To: References: Message-ID: <201009022130.56813.thomas@jollybox.de> On Thursday 02 September 2010, it occurred to ipatrol6010 at yahoo.com to exclaim: > Correct in that regard. In Python 3.x, strings are by default considered > UTF-8. Wheras ASCII isn't a problem because it's fixed-width, UTF-8 will > give you a different character depending on the last byte value. Therefore > handling any kind of data that is not UTF-8 will need you to open it with > 'b' and uses bytes instead of str (literals with b'some value'). Except if it's text of a known encoding, in which case you just open it with that encoding. From hobson42 at gmaiil.com Thu Sep 2 15:38:35 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 02 Sep 2010 20:38:35 +0100 Subject: Help needed with Windows Service in Python In-Reply-To: References: Message-ID: <4C7FFD3B.9060904@gmaiil.com> On 02/09/2010 20:06, Edward Kozlowski wrote: > On Sep 2, 10:22 am, Ian Hobson wrote: >> Hi All, >> >> I am attempting to create a Windows Service in Python. >> >> I have the framework (from Mark Hammond and Andy Robinason's book) >> running - see below. It starts fine - but it will not stop. :( >> >> net stop "Python Service" >> >> and using the services GUI both leave the services showing it as "stopping" >> >> I guess this means SvcStop is called but it is not enough to get it out >> of the machine. >> >> Does anyone know why not? >> >> Python 2.7 with win32 extensions, sunning on Windows 7. >> >> Many thanks >> >> Ian >> >> the (complete) source code is >> #!/usr/bin/env python >> # coding=utf8 >> # service.py = testing services and Named pipes >> # >> import win32serviceutil >> import win32service >> import win32event >> class PythonService(win32serviceutil.ServiceFramework): >> _svc_name_ = "Python Service" >> _svc_display_name_ = "Test Service in Python" >> def __init__(self, args): >> win32serviceutil.ServiceFramework.__init__(self,args) >> self.hWaitStop = win32event.CreateEvent(None,0,0,None) >> def SvcStop(self): >> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) >> wind32event.SetEvent(self.hWaitStop) >> def SvcDoRun(self): >> win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) >> if __name__ == '__main__': >> win32serviceutil.HandleCommandLine(PythonService) > Looks to me like there may be a typo in your code. > > You probably meant win32event.SetEvent(self.hWaitStop), not > wind32event. > > Regards, > -Edward Kozlowski A huge big thank you Edward. That was the problem. Regards Ian From ekozlowski1 at gmail.com Thu Sep 2 15:55:19 2010 From: ekozlowski1 at gmail.com (Edward Kozlowski) Date: Thu, 2 Sep 2010 12:55:19 -0700 (PDT) Subject: Help needed with Windows Service in Python References: Message-ID: <288bf7ad-9251-40d7-9270-e938170a8ed0@x25g2000yqj.googlegroups.com> On Sep 2, 2:38?pm, Ian wrote: > ? On 02/09/2010 20:06, Edward Kozlowski wrote: > > > > > On Sep 2, 10:22 am, Ian Hobson ?wrote: > >> Hi All, > > >> I am attempting to create a Windows Service in Python. > > >> I have the framework (from Mark Hammond and Andy Robinason's book) > >> running - see below. It starts fine - but it will not stop. :( > > >> net stop "Python Service" > > >> and using the services GUI both leave the services showing it as "stopping" > > >> I guess this means SvcStop is called but it is not enough to get it out > >> of the machine. > > >> Does anyone know why not? > > >> Python 2.7 with win32 extensions, sunning on Windows 7. > > >> Many thanks > > >> Ian > > >> the (complete) source code is > >> #!/usr/bin/env python > >> # coding=utf8 > >> # ? service.py ?= testing services and Named pipes > >> # > >> import win32serviceutil > >> import win32service > >> import win32event > >> class PythonService(win32serviceutil.ServiceFramework): > >> ? ? _svc_name_ = "Python Service" > >> ? ? _svc_display_name_ = "Test Service in Python" > >> ? ? def __init__(self, args): > >> ? ? ? win32serviceutil.ServiceFramework.__init__(self,args) > >> ? ? ? self.hWaitStop = win32event.CreateEvent(None,0,0,None) > >> ? ? def SvcStop(self): > >> ? ? ? self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > >> ? ? ? wind32event.SetEvent(self.hWaitStop) > >> ? ? def SvcDoRun(self): > >> ? ? ? win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) > >> if __name__ == '__main__': > >> ? ? win32serviceutil.HandleCommandLine(PythonService) > > Looks to me like there may be a typo in your code. > > > You probably meant win32event.SetEvent(self.hWaitStop), not > > wind32event. > > > Regards, > > -Edward Kozlowski > > A huge big thank you Edward. ?That was the problem. > > Regards > > Ian You're most welcome. If you're looking at running services in Windows using Python, one other hangup I ran into was that my services would freeze for no reason. At Pycon '09, I learned that there were buffers for stdout and stderr that were filling. I wish I could remember who gave the talk that included the jewel of knowledge, because I'd love to give credit where it's due... After I redirected stdout and stderr to files, my problems with the services freezing went away. Regards, -Edward Kozlowski From aahz at pythoncraft.com Thu Sep 2 15:58:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Sep 2010 12:58:49 -0700 Subject: killing all subprocess childrens References: <4C7F1607.8040308@al.com.au> Message-ID: In article , Astan Chee wrote: >Chris Rebert wrote: >> >> import os >> import psutil # http://code.google.com/p/psutil/ >> >> # your piece of code goes here >> >> myself = os.getpid() >> for proc in psutil.process_iter(): > >Is there a way to do this without psutil or installing any external >modules or doing it from python2.5? Lightly edited code I wrote yesterday: cmd = ['ps', '-eo', 'pid,ppid'] output = Popen(cmd, stdout=PIPE).communicate()[0] output = output.split('\n')[1:] # skip the header for row in output: if not row: continue child_pid, parent_pid = row.split() if parent_pid == str(pid): child_pid = int(child_pid) os.kill(child_pid, signal.SIGUSR1) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From pavlovevidence at gmail.com Thu Sep 2 16:01:40 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 2 Sep 2010 13:01:40 -0700 (PDT) Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <60511c27-1995-4deb-beb0-4fb47773b40d@i13g2000yqd.googlegroups.com> On Sep 2, 5:55?am, Tim Wintle wrote: > On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: > > Hi, > > > I was comparing the speed of a simple loop program between Matlab and > > Python. > > Unfortunately my Python Code was much slower and I do not understand why. > > The main reason is that, under the hood, cpython does something like > this (in psudo-code) > > itterator = xrange(imax) > while 1: > ? next_attribute = itterator.next > ? try: > ? ? i = next_attribute() > ? except: > ? ? break > ? a = a + 10 > > where C (and I'm assuming matlab) does this: > > while 1: > ? i = i + 1 > ? if (i > imax): > ? ? break > ? a = a + 10 Not really. Someone already posted timings of the while-loop version in Python and it's much slower than the for loop. The iterator stuff is a minor overhead. The real reason is simple and boring: many languages optimize loops like this, Python doesn't. Matlab has a hundred paid engineers who's job is to optimize it, and its focus is mathematics, so of course they're going to pull out every stop to get simple loops like the above as fast as possible. > And the function call in the python is fairly expensive on it's own. > Plus it has to do all the standard interpreter stuff for memory > management and deciding when to give up the GIL etc. Matlab has all that stuff too (it's memory management is much, much worse than Python's, in fact, but memory management usually doesn't play into tight loop timings). > > Are there any ways to speed up the for/xrange loop? > > leaving it in python, no. (well, "range" is faster in 2.x, but once you > get some cache misses due to increased memory usage it's much slower) > > avoiding iteration by using list comprehensions can help a lot though as > it avoids most of the function calls. List comprehensions use iteration and don't avoid function calls relative to equivalent for-loops. I think the main reason they're a little faster is they can use tighter bytecode. > If you really need to optimise it then you can convert that module to > cython by adding a cdef, and then compile it: > > cdef int i > for i in xrange(imax): > ? ? ?a = a + 10 > print a > > or you can write it in C it'll run a lot faster. numpy is terrific when you can use it, and I've found that it can do a lot more than most people expect. The hard part is figuring out how. In particular, numpy will trounce Matlab's performance for large amounts of data, because of the aforementioned memory management problem. Carl Banks From raoulbia at gmail.com Thu Sep 2 16:37:01 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 2 Sep 2010 13:37:01 -0700 (PDT) Subject: bisection method: Simulating a retirement fund Message-ID: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> level: beginner exercise source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset4.pdf Problem 4 Can my code be optimised? I think my approach is correct but i am hesitant about the initial max value. def nestEgVariable(salary, save, preRetireGrowthRates): SavingsRecord = [] fund = 0 depositPerYear = salary * save * 0.01 for i in preRetireGrowthRates: fund = fund * (1 + 0.01 * i) + depositPerYear SavingsRecord += [fund,] startingPot = SavingsRecord[-1] return startingPot def expenseCalculator(postRetireGrowthRates,fundsize,epsilon,yearsOfretirement ): low = 0 high = fundsize guess = (low + high) /2 while abs(guess * yearsOfretirement - fundsize) > epsilon: if guess * yearsOfretirement > fundsize : high = guess else: low = guess guess = (low + high) /2 return guess def findMaxExpenses(salary,save,preRetireGrowthRates, postRetireGrowthRates,epsilon): yearsOfretirement = len(postRetireGrowthRates) fundsize = nestEgVariable(salary, save, preRetireGrowthRates) for growthRate in postRetireGrowthRates: expenses = expenseCalculator(postRetireGrowthRates, fundsize ,epsilon,yearsOfretirement ) fundsize = (fundsize * (1 + 0.01 * growthRate)) - expenses print 'fundsize', fundsize print 'expenses', expenses yearsOfretirement -=1 return fundsize findMaxExpenses(10000,10,[3, 4, 5, 0, 3],[10, 5, 0, 5, 1],0.01) thanks Baba From tjreedy at udel.edu Thu Sep 2 16:47:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Sep 2010 16:47:16 -0400 Subject: Performance: sets vs dicts. In-Reply-To: <4a3665a0-fc7f-425a-878e-6f8dcc5ed319@y11g2000yqm.googlegroups.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <7a38148b-79e9-40ce-9700-2c0d1c9b3ee4@a4g2000prm.googlegroups.com> <4a3665a0-fc7f-425a-878e-6f8dcc5ed319@y11g2000yqm.googlegroups.com> Message-ID: On 9/1/2010 10:57 PM, rurpy at yahoo.com wrote: > So while you may "think" most people rarely read > the docs for basic language features and objects > (I presume you don't mean to restrict your statement > to only sets), I and most people I know *do* read > them. And when read them I expect them, as any good > reference documentation does, to completely and > accurately describe the behavior of the item I am > reading about. If big-O performance is deemed an > intrinsic behavior of an (operation of) an object, > it should be described in the documentation for > that object. However, big-O performance is intentionally NOT so deemed. And I have and would continue to argue that it should not be, for multiple reasons. Performance is a feature of implementations, and I think they should be documented. > This is not to say that a performance HOWTO or FAQ > in addition to the reference manual would not be good. I have writing a draft of such for CPython on my personal todo list. -- Terry Jan Reedy From nagle at animats.com Thu Sep 2 17:07:38 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Sep 2010 14:07:38 -0700 Subject: Obscure MySQLdb question - duplicating a database handle Message-ID: <4c801218$0$1622$742ec2ed@news.sonic.net> I have a system which does error logging to its database: db = MySQLdb.connect(...) # get database connection ... errorlog(db, "Message") The problem is that I want errorlog to commit its message to the table used for error logging, but don't want to commit whatever the caller was doing - that may well revert. MySQL doesn't support nested transactions, so that won't help. At the many points errorlog is called, only the database handle is available, not the params used for "connect". Is there something like UNIX "dup" for database connections in MySQLdb, or can I get the connection parameters (username, password, database, etc.) from the "db" object? John Nagle From nagle at animats.com Thu Sep 2 17:19:01 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Sep 2010 14:19:01 -0700 Subject: PyPy and RPython In-Reply-To: References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> Message-ID: <4c8014c2$0$1602$742ec2ed@news.sonic.net> On 9/2/2010 1:29 AM, sarvi wrote: > When I think about it these restrictions below seem a very reasonable > tradeoff for performance. Yes. > And I can use this for just the modules/sections that are performance > critical. Not quite. Neither Shed Skin nor RPython let you call from restricted code to unrestricted code. That tends to happen implicitly as objects are passed around. It's the global analysis that makes this work; when you call something, you need to know more about it than how to call it. John Nagle From tjreedy at udel.edu Thu Sep 2 17:55:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Sep 2010 17:55:59 -0400 Subject: Performance: sets vs dicts. In-Reply-To: <87aao1c8dk.fsf@castleamber.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> <87aao1c8dk.fsf@castleamber.com> Message-ID: On 9/1/2010 8:11 PM, John Bokma wrote: > Terry Reedy writes: > >> On 9/1/2010 5:40 PM, John Bokma wrote: > > [..] > >> Yes, I switched, because 'constant time' is a comprehensible claim >> that can be refuted and because that is how some will interpret O(1) >> (see below for proof;-). > > You make it now sound as if this interpretation is not correct or out of > place. Saying that an interpretation is comprehensible and common is hardly a putdown ;-). It simply is not unique. I also said that the other interpretation is not coherent for size-limited problems. However, if you mean 'constant', whatever you mean by that, why not say so? Here is the technical definition given in https://secure.wikimedia.org/wikipedia/en/wiki/Big_O_notation I assure you that it is the standard one invented by a mathematiciam over a century ago and used by mathematicians ever since. It was popularized in computer science by Donald Knuth in 1976 and used in The Art of Computer Programming. It is related to the definition of limits. ''' Formal definition Let f(x) and g(x) be two functions defined on some subset of the real numbers. One writes f(x)=O(g(x))\mbox{ as }x\to\infty\, if and only if, for sufficiently large values of x, f(x) is at most a constant multiplied by g(x) in absolute value. That is, f(x) = O(g(x)) if and only if there exists a positive real number M and a real number x0 such that |f(x)| \le \; M |g(x)|\mbox{ for all }x>x_0. ''' For g(x) == 1, this reduces to |f(x)| < M for some M (and large x), which is to say, f(x) is bounded (at least for large x). Hmmm. By that definition, 1/x is O(1). Let x0 be anything but 0 and M = 1/x0. Some might find that disturbing. But it is the nature of the notation, as with limit notation, that is says *nothing* about the behavior of f for small x. > People who have bothered to read ItA will use O(1) and constant > time interchangeably while talking of the order of growth of the running > time algorithms People who have bothered to read the Bidle will use terms the way they are used in the Bible. So what? In other words, I do not regard ItA as scripture in the way you seem to. (I presume you mean the Cormen, etal book. I partially read a library copy over 20 years ago but never bothered to buy a copy. I see it is now into its third edition.) If they disagree with Knuth and most others (which I would not claim without seeing their actual text) then so much the worse for them. > and most of those are aware that 'big oh' hides a > constant, and that in the real world a O(log n) algorithm can outperform > an O(1) algorithm for small values of n. Right. And if 'small values of n' include all possible values, then rejecting a particular O(log n) algorithm as 'unacceptable' relative to all O(1) algorithms is pretty absurd. >>> Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, >>> 2nd edition. Given that the Wikipedia article references that section also, I wonder if it really disagrees with the definition above. -- Terry Jan Reedy From nkaunda at yahoo.com Thu Sep 2 18:01:10 2010 From: nkaunda at yahoo.com (Nally Kaunda-Bukenya) Date: Thu, 2 Sep 2010 15:01:10 -0700 (PDT) Subject: Sum of product-please help Message-ID: <500917.93744.qm@web33502.mail.mud.yahoo.com> Dear all, kindly help me with this code; This script? is supposed to calculate Rvi for each row by first summing the product of #fields (Ai*Rv) and dividing by another field (Tot) such that? Rvi=sum(Ai*Rv)/Tot. First it's acting like I need another parenthesis and it doesn't seem to work at all. i even imported the math module, but not sure if a need it. Please advice, your help is highly appreciated.? Please see the code below: import arcpy, math arcpy.Workspace = "C:\\data\\basins.mdb" fc = "wshed" sum = 0 ??????? # Create the update cursor and advance the cursor to the first row cur = arcpy.UpdateCursor(fc) row = cur.Next() # Perform the update and move to the next row as long as there are #? rows left for row: ??? row.GetValue(Rvi) = sum(row.Ai*row.Rv)/row.ATot ??? cur.UpdateRow(row) ??? row = cur.Next() # Delete the cursors to remove any data locks del row, cur? -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Sep 2 18:10:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Sep 2010 23:10:42 +0100 Subject: bisection method: Simulating a retirement fund In-Reply-To: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> References: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> Message-ID: <4C8020E2.9040803@mrabarnett.plus.com> On 02/09/2010 21:37, Baba wrote: > level: beginner > > exercise source: > http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset4.pdf > > Problem 4 > > Can my code be optimised? > I think my approach is correct but i am hesitant about the initial max > value. > > def nestEgVariable(salary, save, preRetireGrowthRates): > SavingsRecord = [] > fund = 0 > depositPerYear = salary * save * 0.01 > for i in preRetireGrowthRates: > fund = fund * (1 + 0.01 * i) + depositPerYear > SavingsRecord += [fund,] > startingPot = SavingsRecord[-1] > return startingPot > Why are you saving 'fund' in SavingsRecord if you're returning just the last and discarding others? Basically you're returning the final value of fund. > > def > expenseCalculator(postRetireGrowthRates,fundsize,epsilon,yearsOfretirement ): > low = 0 > high = fundsize > guess = (low + high) /2 > while abs(guess * yearsOfretirement - fundsize)> epsilon: > if guess * yearsOfretirement> fundsize : > high = guess > else: low = guess > guess = (low + high) /2 > return guess > When performing this type of 'search' make sure that the interval (high - low) reduces at every step. If, for example: low + 1 == high then: guess == (low + (low + 1)) / 2 == (low * 2 + 1) / 2 == low (integer division) and if the 'if' condition happens to be false then the value of 'low' won't change for the next iteration, leading to an infinite loop. > > def findMaxExpenses(salary,save,preRetireGrowthRates, > postRetireGrowthRates,epsilon): > yearsOfretirement = len(postRetireGrowthRates) > fundsize = nestEgVariable(salary, save, preRetireGrowthRates) > for growthRate in postRetireGrowthRates: > expenses = expenseCalculator(postRetireGrowthRates, > > fundsize ,epsilon,yearsOfretirement ) > fundsize = (fundsize * (1 + 0.01 * growthRate)) - expenses > print 'fundsize', fundsize > print 'expenses', expenses > yearsOfretirement -=1 > return fundsize > > > > findMaxExpenses(10000,10,[3, 4, 5, 0, 3],[10, 5, 0, 5, 1],0.01) > From tjreedy at udel.edu Thu Sep 2 18:14:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Sep 2010 18:14:42 -0400 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) In-Reply-To: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: On 9/1/2010 9:08 PM, Dmitry Chichkov wrote: > Given: a large list (10,000,000) of floating point numbers; > Task: fastest python code that finds k (small, e.g. 10) smallest > items, preferably with item indexes; > Limitations: in python, using only standard libraries (numpy& scipy > is Ok); > > I've tried several methods. With N = 10,000,000, K = 10 The fastest so > far (without item indexes) was pure python implementation > nsmallest_slott_bisect (using bisect/insert). And with indexes > nargsmallest_numpy_argmin (argmin() in the numpy array k times). > > Anyone up to the challenge beating my code with some clever selection > algorithm? > > Current Table: > 1.66864395142 mins_heapq(items, n): > 0.946580886841 nsmallest_slott_bisect(items, n): > 1.38014793396 nargsmallest(items, n): > 10.0732769966 sorted(items)[:n]: > 3.17916202545 nargsmallest_numpy_argsort(items, n): > 1.31794500351 nargsmallest_numpy_argmin(items, n): > 2.37499308586 nargsmallest_numpy_array_argsort(items, n): > 0.524670124054 nargsmallest_numpy_array_argmin(items, n): > > 0.0525538921356 numpy argmin(items): 1892997 > 0.364673852921 min(items): 10.0000026786 Your problem is underspecified;-). Detailed timing comparisons are only valid for a particular Python version running under a particular OS on particular hardware. So, to actually run a contest, you would have to specify a version and OS and offer to run entries on your machine, with as much else as possible turned off, or else enlist a neutral judge to do so. And the timing method should also be specified. -- Terry Jan Reedy From python at mrabarnett.plus.com Thu Sep 2 18:16:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Sep 2010 23:16:43 +0100 Subject: Sum of product-please help In-Reply-To: <500917.93744.qm@web33502.mail.mud.yahoo.com> References: <500917.93744.qm@web33502.mail.mud.yahoo.com> Message-ID: <4C80224B.4010300@mrabarnett.plus.com> On 02/09/2010 23:01, Nally Kaunda-Bukenya wrote: > Dear all, kindly help me with this code; > This script is supposed to calculate Rvi for each row by first summing > the product of #fields (Ai*Rv) and dividing by another field (Tot) such > that Rvi=sum(Ai*Rv)/Tot. First it's acting like I need another > parenthesis and it doesn't seem to work at all. i even imported the math > module, but not sure if a need it. Please advice, your help is highly > appreciated. Please see the code below: > import arcpy, math > arcpy.Workspace = "C:\\data\\basins.mdb" > fc = "wshed" > sum = 0 > It looks like you're using 'sum' as a variable. Bad idea. That hides the 'sum' function which you need later. > # Create the update cursor and advance the cursor to the first row > cur = arcpy.UpdateCursor(fc) > row = cur.Next() > # Perform the update and move to the next row as long as there are > # rows left > for row: Syntax error. It's: for variable in iterator: ... > row.GetValue(Rvi) = sum(row.Ai*row.Rv)/row.ATot Assign to the result of row.GetValue(Rvi)? Is that right? I don't know arcpy, but somehow that doesn't look right to me. > cur.UpdateRow(row) > row = cur.Next() > # Delete the cursors to remove any data locks > del row, cur > From tjreedy at udel.edu Thu Sep 2 18:20:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Sep 2010 18:20:27 -0400 Subject: Speed-up for loops In-Reply-To: <1283432116.14252.37.camel@tim-laptop> References: <4C7F7640.1010102@perfect-kreim.de> <1283432116.14252.37.camel@tim-laptop> Message-ID: On 9/2/2010 8:55 AM, Tim Wintle wrote: > On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: >> Hi, >> >> I was comparing the speed of a simple loop program between Matlab and >> Python. > >> Unfortunately my Python Code was much slower and I do not understand why. > > The main reason is that, under the hood, cpython does something like > this (in psudo-code) > > itterator = xrange(imax) > while 1: > next_attribute = itterator.next > try: > i = next_attribute() > except: > break > a = a + 10 > > where C (and I'm assuming matlab) does this: > > while 1: > i = i + 1 > if (i> imax): > break > a = a + 10 Which is to say, 'for' in python is not the same as 'for' in C/matlab and the latter is what Michael should use in a fair comparison. Otherwise, apples and oranges. -- Terry Jan Reedy From clp2 at rebertia.com Thu Sep 2 18:24:17 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 2 Sep 2010 15:24:17 -0700 Subject: killing all subprocess childrens In-Reply-To: References: <4C7F1607.8040308@al.com.au> Message-ID: On Thu, Sep 2, 2010 at 12:58 PM, Aahz wrote: > In article , > Astan Chee ? wrote: >>Chris Rebert wrote: >>> >>> import os >>> import psutil # http://code.google.com/p/psutil/ >>> >>> # your piece of code goes here >>> >>> myself = os.getpid() >>> for proc in psutil.process_iter(): >> >>Is there a way to do this without psutil or installing any external >>modules or doing it from python2.5? > > Lightly edited code I wrote yesterday: > > ? ? ? ?cmd = ['ps', '-eo', 'pid,ppid'] > ? ? ? ?output = Popen(cmd, stdout=PIPE).communicate()[0] > ? ? ? ?output = output.split('\n')[1:] ?# skip the header > ? ? ? ?for row in output: > ? ? ? ? ? ?if not row: > ? ? ? ? ? ? ? ?continue > ? ? ? ? ? ?child_pid, parent_pid = row.split() > ? ? ? ? ? ?if parent_pid == str(pid): > ? ? ? ? ? ? ? ?child_pid = int(child_pid) > ? ? ? ? ? ? ? ?os.kill(child_pid, signal.SIGUSR1) Although this doesn't meet the OP's Windows-compatibility requirement. Cheers, Chris From raoulbia at gmail.com Thu Sep 2 18:25:11 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 2 Sep 2010 15:25:11 -0700 (PDT) Subject: Fibonacci: returning a selection of the series References: <87d3t1qo34.fsf@dpt-info.u-strasbg.fr> Message-ID: <2479aafa-231f-4741-b88e-46fa340756b4@y11g2000yqm.googlegroups.com> On Aug 29, 7:18?pm, Alain Ketterlin wrote: > In general, if you have a program that produces something just to > remove/ignore it five lines later, you have a problem. In your case: > > 1) are you sure you need to append to list(*) at every iteration? When > do you *really* need to? And... > > 2) your loop runs up to n (the index of the fib number), but you want to > stop on some fib number value (not index). > > So, why not pass start and end to i_fib, and use them where appropriate? > Hi Alain Thank you for your (pragmatic) suggestions! Based on your input i was able to considerably optimise my approach: def fib_range(start, end): fib_1 = 0 fib_2 = 1 range = [] while fib_2 < end: fib_1, fib_2 = fib_2, fib_1 + fib_2 if fib_2 >= start and fib_2 <= end: range.append(fib_2) return range print fib_range(4,76) Thanks Baba From john at castleamber.com Thu Sep 2 18:35:07 2010 From: john at castleamber.com (John Bokma) Date: Thu, 02 Sep 2010 17:35:07 -0500 Subject: Obscure MySQLdb question - duplicating a database handle References: <4c801218$0$1622$742ec2ed@news.sonic.net> Message-ID: <87pqwv93l0.fsf@castleamber.com> John Nagle writes: > I have a system which does error logging to its database: > > db = MySQLdb.connect(...) # get database connection > ... > errorlog(db, "Message") > > The problem is that I want errorlog to commit its message to > the table used for error logging, but don't want to commit > whatever the caller was doing - that may well revert. > > MySQL doesn't support nested transactions, so that won't help. > At the many points errorlog is called, only the database > handle is available, not the params used for "connect". > > Is there something like UNIX "dup" for database connections > in MySQLdb, or can I get the connection parameters (username, > password, database, etc.) from the "db" object? Maybe I am not clear anymore (long day), but why not make 2 db connections? It might even be better since you can give each one its own user and hence, privileges. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From ron.eggler at gmail.com Thu Sep 2 19:19:45 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 2 Sep 2010 16:19:45 -0700 (PDT) Subject: DeprecationWarning References: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Message-ID: On Sep 1, 5:04?pm, Chris Rebert wrote: > On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: > > Hi There, > > > I would like to create an scp handle and download a file from a > > client. I have following code: > > > but what i'm getting is this and no file is downloaded...: > > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: > > BaseException.message has been deprecated as of Python 2.6 > > ?chan.send('\x01'+e.message) > > 09/01/2010 08:53:56 : Downloading P-file failed. > > > What does that mean and how do i resolve this? > > http://stackoverflow.com/questions/1272138/baseexception-message-depr... > As the warning message says, line 243 of > /opt/lampp/cgi-bin/attachment.py is the cause of the warning. > > However, that's only a warning (albeit probably about a small part of > some error-raising code), not an error itself, so it's not the cause > of the download failure. > Printing out the IOError encountered would be the first step in > debugging the download failure. > > Cheers, > Chris > --http://blog.rebertia.com Hi Chris, Thanks for getting back! I get an "I/O error(2): No such file or directory" error even tho the file i'm trying to copy at /usr/share/NovaxTSP/P0086_2003.xml is present, an "ls /usr/share/NovaxTSP/P0086_2003.xml" on the target is succesful... :( What am i doing wrong? Thanks, Ron From dchichkov at gmail.com Thu Sep 2 19:21:38 2010 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Thu, 2 Sep 2010 16:21:38 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: <59daca25-3154-4b12-9299-0976bd37c2a9@u6g2000yqh.googlegroups.com> Yes, you are right of course. But it is not really a contest. And if you could improve algorithm or implementation on "your Python version running under your OS on your hardware" it may as well improve performance for other people under other OS's. On Sep 2, 3:14?pm, Terry Reedy wrote: > On 9/1/2010 9:08 PM, Dmitry Chichkov wrote: > > > Your problem is underspecified;-). > Detailed timing comparisons are only valid for a particular Python > version running under a particular OS on particular hardware. So, to > actually run a contest, you would have to specify a version and OS and > offer to run entries on your machine, with as much else as possible > turned off, or else enlist a neutral judge to do so. And the timing > method should also be specified. > > -- > Terry Jan Reedy From clp2 at rebertia.com Thu Sep 2 19:25:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 2 Sep 2010 16:25:39 -0700 Subject: DeprecationWarning In-Reply-To: References: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Message-ID: On Thu, Sep 2, 2010 at 4:19 PM, cerr wrote: > On Sep 1, 5:04?pm, Chris Rebert wrote: >> On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: >> > Hi There, >> >> > I would like to create an scp handle and download a file from a >> > client. I have following code: >> >> > but what i'm getting is this and no file is downloaded...: >> > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: >> > BaseException.message has been deprecated as of Python 2.6 >> > ?chan.send('\x01'+e.message) >> > 09/01/2010 08:53:56 : Downloading P-file failed. >> >> > What does that mean and how do i resolve this? >> >> http://stackoverflow.com/questions/1272138/baseexception-message-depr... >> As the warning message says, line 243 of >> /opt/lampp/cgi-bin/attachment.py is the cause of the warning. >> >> However, that's only a warning (albeit probably about a small part of >> some error-raising code), not an error itself, so it's not the cause >> of the download failure. >> Printing out the IOError encountered would be the first step in >> debugging the download failure. >> >> Cheers, >> Chris > > Hi Chris, > > Thanks for getting back! > I get an "I/O error(2): No such file or directory" error even tho the > file i'm trying to copy at /usr/share/NovaxTSP/P0086_2003.xml is > present, an "ls /usr/share/NovaxTSP/P0086_2003.xml" on the target is > succesful... :( What am i doing wrong? Asking on the Paramiko mailinglist might be more fruitful: http://www.lag.net/mailman/listinfo/paramiko Cheers, Chris From vs at it.uu.se Thu Sep 2 19:56:47 2010 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 03 Sep 2010 01:56:47 +0200 Subject: Financial time series data In-Reply-To: References: <4C7FDB16.9020208@it.uu.se> Message-ID: <4C8039BF.5080407@it.uu.se> On 09/02/2010 08:15 PM, Hidura wrote: > But what kind of data you want to download?, because the financial > time it's basicly html code and you can work very well with a parser > > 2010/9/2, Virgil Stokes: > >> Has anyone written code or worked with Python software for downloading >> financial time series data (e.g. from Yahoo financial)? If yes, would you >> please contact me. >> >> --Thanks, >> V. Stokes >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > Here is a snippet of python code that I am trying to use for downloading financial data; but, I do not understand why it returns information from the second HTML page. import urllib2 ''' I am trying to read each row of the table at: http://finance.yahoo.com/q/cp?s=^GSPC ''' ticker = [] url = urllib2.urlopen("http://download.finance.yahoo.com/d/quotes.csv?s=@%5EGSPC&f=sl1d1t1c1ohgv&e=.csv&h=PAGE".replace('PAGE', str(0))) data = url.read() Note, it does get all 50 rows of the first page; but, why does it also get the first row of the "next" HTML page? --V From skippy.hammond at gmail.com Thu Sep 2 20:38:30 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 03 Sep 2010 10:38:30 +1000 Subject: Help needed with Windows Service in Python In-Reply-To: <4C7FC11C.7030904@ianhobson.co.uk> References: <4C7FC11C.7030904@ianhobson.co.uk> Message-ID: <4C804386.90304@gmail.com> On 3/09/2010 1:22 AM, Ian Hobson wrote: > Hi All, > > I am attempting to create a Windows Service in Python. > > I have the framework (from Mark Hammond and Andy Robinason's book) > running - see below. It starts fine - but it will not stop. :( > > net stop "Python Service" > > and using the services GUI both leave the services showing it as "stopping" > > I guess this means SvcStop is called but it is not enough to get it out > of the machine. > > Does anyone know why not? I expect that the Windows Event Log might have some clues, as would attempting to use it in "debug" mode. > def SvcStop(self): > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > wind32event.SetEvent(self.hWaitStop) Note the typo in the line above... Mark From python at mrabarnett.plus.com Thu Sep 2 20:50:26 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 03 Sep 2010 01:50:26 +0100 Subject: Financial time series data In-Reply-To: <4C8039BF.5080407@it.uu.se> References: <4C7FDB16.9020208@it.uu.se> <4C8039BF.5080407@it.uu.se> Message-ID: <4C804652.6020501@mrabarnett.plus.com> On 03/09/2010 00:56, Virgil Stokes wrote: > On 09/02/2010 08:15 PM, Hidura wrote: >> But what kind of data you want to download?, because the financial >> time it's basicly html code and you can work very well with a parser >> >> 2010/9/2, Virgil Stokes: >>> Has anyone written code or worked with Python software for downloading >>> financial time series data (e.g. from Yahoo financial)? If yes, would >>> you >>> please contact me. >>> >>> --Thanks, >>> V. Stokes >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> > Here is a snippet of python code that I am trying to use for downloading > financial data; but, I do not understand why it returns information from > the second HTML page. > > import urllib2 > ''' > I am trying to read each row of the table at: > http://finance.yahoo.com/q/cp?s=^GSPC > ''' > ticker = [] > url = > urllib2.urlopen("http://download.finance.yahoo.com/d/quotes.csv?s=@%5EGSPC&f=sl1d1t1c1ohgv&e=.csv&h=PAGE".replace('PAGE', > str(0))) > data = url.read() > > Note, it does get all 50 rows of the first page; but, why does it also > get the first row of the "next" HTML page? > Did you try downloading from a browser? That also returns an extra row. Looks like an idiosyncrasy of the site. From hidura at gmail.com Thu Sep 2 20:55:12 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Fri, 03 Sep 2010 00:55:12 +0000 Subject: Financial time series data In-Reply-To: <4C8039BF.5080407@it.uu.se> Message-ID: <0016e656b74e0e26ea048f5062e1@google.com> I've tried to see the page and the code GSPC it's wrong i has used ^DJI, and when you download the page code use a xml parser localize the table element and read it. I can't access from the browser to the next page it doesn't appear as a link. El , Virgil Stokes escribi?: > On 09/02/2010 08:15 PM, Hidura wrote: > But what kind of data you want to download?, because the financial > time it's basicly html code and you can work very well with a parser > 2010/9/2, Virgil Stokesvs at it.uu.se>: > Has anyone written code or worked with Python software for downloading > financial time series data (eg from Yahoo financial)? If yes, would you > please contact me. > --Thanks, > V. Stokes > -- > http://mail.python.org/mailman/listinfo/python-list > Here is a snippet of python code that I am trying to use for downloading > financial data; but, I do not understand why it returns information from > the second HTML page. > import urllib2 > ''' > I am trying to read each row of the table at: > http://finance.yahoo.com/q/cp?s=^GSPC > ''' > ticker = [] > url = > urllib2.urlopen("http://download.finance.yahoo.com/d/quotes.csv?s=@%5EGSPC&f=sl1d1t1c1ohgv&e=.csv&h=PAGE".replace('PAGE', > str(0))) > data = url.read() > Note, it does get all 50 rows of the first page; but, why does it also > get the first row of the "next" HTML page? > --V -------------- next part -------------- An HTML attachment was scrubbed... URL: From ron.eggler at gmail.com Thu Sep 2 21:39:07 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 2 Sep 2010 18:39:07 -0700 (PDT) Subject: DeprecationWarning References: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Message-ID: <916e2640-82ee-4ea6-a010-5a872da105c4@t20g2000yqa.googlegroups.com> On Sep 2, 4:25?pm, Chris Rebert wrote: > On Thu, Sep 2, 2010 at 4:19 PM, cerr wrote: > > On Sep 1, 5:04?pm, Chris Rebert wrote: > >> On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: > >> > Hi There, > > >> > I would like to create an scp handle and download a file from a > >> > client. I have following code: > >> > >> > but what i'm getting is this and no file is downloaded...: > >> > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: > >> > BaseException.message has been deprecated as of Python 2.6 > >> > ?chan.send('\x01'+e.message) > >> > 09/01/2010 08:53:56 : Downloading P-file failed. > > >> > What does that mean and how do i resolve this? > > >>http://stackoverflow.com/questions/1272138/baseexception-message-depr... > >> As the warning message says, line 243 of > >> /opt/lampp/cgi-bin/attachment.py is the cause of the warning. > > >> However, that's only a warning (albeit probably about a small part of > >> some error-raising code), not an error itself, so it's not the cause > >> of the download failure. > >> Printing out the IOError encountered would be the first step in > >> debugging the download failure. > > >> Cheers, > >> Chris > > > Hi Chris, > > > Thanks for getting back! > > I get an "I/O error(2): No such file or directory" error even tho the > > file i'm trying to copy at /usr/share/NovaxTSP/P0086_2003.xml is > > present, an "ls /usr/share/NovaxTSP/P0086_2003.xml" on the target is > > succesful... :( What am i doing wrong? > > Asking on the Paramiko mailinglist might be more fruitful:http://www.lag.net/mailman/listinfo/paramiko Yep, thanks. I guess I try my luck there then. Thanks! Ron From ldo at geek-central.gen.new_zealand Thu Sep 2 22:25:31 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 03 Sep 2010 14:25:31 +1200 Subject: Windows vs. file.read References: Message-ID: In message , MRAB wrote: > On 02/09/2010 08:49, Lawrence D'Oliveiro wrote: >> In message, MRAB >> wrote: >> >>> You should open the files in binary mode, not text mode, ie file(path, >>> "rb"). Text mode is the default. Not a problem on *nix because the line >>> ending is newline. >> >> We used to pride ourselves on not having to worry about text versus >> binary I/O modes on *nix, but I?m beginning to think the reality is we >> have to adopt it. >> >> To start with, it means we can automatically handle different newline >> conventions with text files originating on different systems. > > In Python 3 the difference is important because binary mode works with > bytes and text mode works with strings, plus the file encoding and line > endings. Yeah, that seems like a reasonable approach?make you decide up-front what exactly is the sort of file content you?re dealing with. From nagle at animats.com Fri Sep 3 00:22:12 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Sep 2010 21:22:12 -0700 Subject: Does MySQLdb rollback on control-C? Maybe not. Message-ID: <4c8077f1$0$1628$742ec2ed@news.sonic.net> I would expect MySQLdb to rollback on a control-C, but it doesn't seem to have done so. I have a program which does a thousand or so INSERT operations in one transaction on an InnoDB table. I kill it with a control-C on Windows, and it aborts. But it looks like some of the INSERT operations took place. Here's the abort, from the middle of an INSERT operation. Filing index item already in database under another date: edgar/data/1455650/0000950123-10-062814.txt Traceback (most recent call last): .... File "C:\projects\sitetruth\edgar\edgarfilingindex.py", line 93, in dbinsert cursor.execute(sql, values) # do the insert File "C:\python26\lib\site-packages\MySQLdb\cursors.py", line 166, in execute self.errorhandler(self, exc, value) File "C:\python26\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue KeyboardInterrupt Terminate batch job (Y/N)? y Checking with the manual MySQL client, looking at the table before and after the run, the table did change when the program ran. Not good. The INSERT looks like this: INSERT INTO edgarfilingindex (cik, company_name, form_type, date_filed, file_name, date_indexed, confidence) VALUES (%s,%s,%s,%s,%s,%s,%s) SHOW CREATE TABLE returns this: CREATE TABLE `edgarfilingindex` ( ... ) ENGINE=InnoDB DEFAULT CHARSET=utf8 so it's definitely an InnoDB table. I have print statements at all commit calls, and there don't seem to be any unwanted commits happening. I'm not doing anything that forces a commit, like RENAME or ALTER or CREATE; it's just simple INSERT operations. I'm not doing an explicit START TRANSACTION, but I shouldn't have to. I put a SHOW VARIABLES LIKE "autocommit" in the program, and it comes back with ("autocommit", "OFF"). So that's not the problem. I even did an explicit START TRANSACTION at the beginning of the update, and it doesn't help. Something is broken. Python 2.6, MySQLdb 1.2.2-py2.6, MySQL 5.1.47-com, Windows 7. John Nagle From sarvilive at gmail.com Fri Sep 3 01:30:59 2010 From: sarvilive at gmail.com (sarvi) Date: Thu, 2 Sep 2010 22:30:59 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> <4c8014c2$0$1602$742ec2ed@news.sonic.net> Message-ID: <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> On Sep 2, 2:19?pm, John Nagle wrote: > On 9/2/2010 1:29 AM, sarvi wrote: > > > When I think about it these restrictions below seem a very reasonable > > tradeoff for performance. > > ? ? Yes. > > > And I can use this for just the modules/sections that are performance > > critical. > > ? ? Not quite. ?Neither Shed Skin nor RPython let you call from > restricted code to unrestricted code. ?That tends to happen > implicitly as objects are passed around. ?It's the global > analysis that makes this work; when you call something, you > need to know more about it than how to call it. It should technically be possible to allow Python to call a module written in RPython? It should also compile RPython to a python module.so right? Sarvi > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle From arnodel at googlemail.com Fri Sep 3 02:17:27 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 03 Sep 2010 07:17:27 +0100 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> <87aao1c8dk.fsf@castleamber.com> Message-ID: Terry Reedy writes: > On 9/1/2010 8:11 PM, John Bokma wrote: [...] >>>> Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, >>>> 2nd edition. > > Given that the Wikipedia article references that section also, I > wonder if it really disagrees with the definition above. In simple terms, O(1) is *bounded* time. This is not the same as constant, even though it is true that the misleading expression "constant time" is widely used. I emphasized the difference as you seemed to say that describing list element access as O(1) was misleading because for example accessing contiguous elements would be significantly faster that accessing distant ones. This may or may not be the case, but it remains true that this time is bounded and this is what O(1) really means. -- Arnaud From melodybelena at gmail.com Fri Sep 3 02:36:11 2010 From: melodybelena at gmail.com (shai garcia) Date: Fri, 03 Sep 2010 06:36:11 GMT Subject: python database Message-ID: <2010932369usenet@eggheadcafe.com> can you pls help me to make a database program in python? It is a Quiz system which is database driven. The program has a choices which add question, edit, delete, list, take a quiz, quiz results, and exit. in take a quiz choice,questions should be randomly displayed and the result and name of the examinee should be saved as well as the date and time taken. pls help..tnx.Godbless Submitted via EggHeadCafe - Software Developer Portal of Choice Book Review: Excel 2010 - The Missing Manual [OReilly] http://www.eggheadcafe.com/tutorials/aspnet/7d211741-221d-46c7-b9c3-d34bf84568be/book-review-excel-2010--the-missing-manual-oreilly.aspx From melodybelena at gmail.com Fri Sep 3 02:38:55 2010 From: melodybelena at gmail.com (shai garcia) Date: Fri, 03 Sep 2010 06:38:55 GMT Subject: python database Message-ID: <20109323853usenet@eggheadcafe.com> can you pls help me to make a database program in python? It is a Quiz system which is database driven. The program has a choices which add question, edit, delete, list, take a quiz, quiz results, and exit. in take a quiz choice,questions should be randomly displayed and the result and name of the examinee should be saved as well as the date and time taken. pls help..tnx.Godbless Submitted via EggHeadCafe - Software Developer Portal of Choice Kentico CMS for ASP.NET Sites http://www.eggheadcafe.com/tutorials/aspnet/ee551a85-2206-446e-bc7d-c978f60ec671/kentico-cms-for-aspnet-sites.aspx From ldo at geek-central.gen.new_zealand Fri Sep 3 02:39:06 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 03 Sep 2010 18:39:06 +1200 Subject: Obscure MySQLdb question - duplicating a database handle References: <4c801218$0$1622$742ec2ed@news.sonic.net> Message-ID: In message <4c801218$0$1622$742ec2ed at news.sonic.net>, John Nagle wrote: > The problem is that I want errorlog to commit its message to > the table used for error logging, but don't want to commit > whatever the caller was doing - that may well revert. Any particular reason you?re using a database table for logging? It?s usually easier to write to text files for this purpose. From ldo at geek-central.gen.new_zealand Fri Sep 3 02:45:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 03 Sep 2010 18:45:44 +1200 Subject: killing all subprocess childrens References: Message-ID: In message , Astan Chee wrote: > What I'm trying to do (and wondering if its possible) is to make sure > that any children (and any descendants) of this process is killed when > the main java process is killed (or dies). > How do I do this in windows, linux and OSX? A linux-specific solution could be implemented in terms of cgroups . I can?t see any way to automatically ensure all descendants are killed, but the parent can at least scan the cgroup when the immediate child exits, and kill every leftover process it finds. From eckhardt at satorlaser.com Fri Sep 3 02:52:07 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 03 Sep 2010 08:52:07 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: Tim Wintle wrote: > [..] under the hood, cpython does something like this (in psudo-code) > > itterator = xrange(imax) > while 1: > next_attribute = itterator.next > try: > i = next_attribute() > except: > break > a = a + 10 There is one thing that strikes me here: The code claims that each iteration there is a lookup of the 'next' field in the iterator. I would expect that this is looked up once before the loop only. Can you confirm that or am I misinterpreting your intention here? Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From stefan_ml at behnel.de Fri Sep 3 02:56:23 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Sep 2010 08:56:23 +0200 Subject: PyPy and RPython In-Reply-To: <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> <4c8014c2$0$1602$742ec2ed@news.sonic.net> <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> Message-ID: sarvi, 03.09.2010 07:30: > It should technically be possible to allow Python to call a module > written in RPython? What's "Python" here? CPython? Then likely yes. I don't see a benefit, though. > It should also compile RPython to a python module.so right? Why (and how) would CPython do that? If you want a binary extension module for CPython, you can try to push the RPython module through Cython. However, in that case, you wouldn't be restricted to RPython in the first place. Stefan From ben+python at benfinney.id.au Fri Sep 3 02:59:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 03 Sep 2010 16:59:40 +1000 Subject: python database References: <2010932369usenet@eggheadcafe.com> Message-ID: <87eidbfh2b.fsf@benfinney.id.au> shai garcia writes: > can you pls help me to make a database program in python? Thank you for your interest in Python, and I hope you will have much success as you learn about it. Your best way of using this forum to help you is to ask *specific* questions about problems as you go along. Do your research of the documentation for Python , the Python Package Index , the Python Wiki and so on; then start. Having started, work through the problems that come along as you go, and come here to ask about problems in *your* work, showing the code which confuses you and explaining the resources you've already researched. This will be much more instructive for you, and a much better use of the time of the volunteers here. > Submitted via [something that spews adverts on the end of messages] Please don't use these advertising services to post your messages. Instead, post them using a normal mail service that won't advertise at us. -- \ ?The difference between a moral man and a man of honor is that | `\ the latter regrets a discreditable act, even when it has worked | _o__) and he has not been caught.? ?Henry L. Mencken | Ben Finney From nagle at animats.com Fri Sep 3 02:59:57 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Sep 2010 23:59:57 -0700 Subject: PyPy and RPython In-Reply-To: <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> <4c8014c2$0$1602$742ec2ed@news.sonic.net> <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> Message-ID: <4c809cea$0$1614$742ec2ed@news.sonic.net> On 9/2/2010 10:30 PM, sarvi wrote: > On Sep 2, 2:19 pm, John Nagle wrote: >> On 9/2/2010 1:29 AM, sarvi wrote: >> >>> When I think about it these restrictions below seem a very reasonable >>> tradeoff for performance. >> >> Yes. >> >>> And I can use this for just the modules/sections that are performance >>> critical. >> >> Not quite. Neither Shed Skin nor RPython let you call from >> restricted code to unrestricted code. That tends to happen >> implicitly as objects are passed around. It's the global >> analysis that makes this work; when you call something, you >> need to know more about it than how to call it. > > It should technically be possible to allow Python to call a module > written in RPython? The problem is that, in a language where everything is an object, everything you call calls you back. The basic performance problem with CPython comes from the fact that it uses the worst-case code for almost everything. Avoiding that requires global analysis to detect the places where the code clearly isn't doing anything weird and simpler code can be used. Again, look at Shed Skin, which represents considerable progress made by one guy. With more resources, that could be a very good system. John Nagle From stefan_ml at behnel.de Fri Sep 3 03:00:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Sep 2010 09:00:13 +0200 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: Ulrich Eckhardt, 03.09.2010 08:52: > Tim Wintle wrote: >> [..] under the hood, cpython does something like this (in psudo-code) >> >> itterator = xrange(imax) >> while 1: >> next_attribute = itterator.next >> try: >> i = next_attribute() >> except: >> break >> a = a + 10 > > There is one thing that strikes me here: The code claims that each iteration > there is a lookup of the 'next' field in the iterator. I would expect that > this is looked up once before the loop only. > > Can you confirm that or am I misinterpreting your intention here? It needs to do that. Nothing keeps you from redefining "next" in each call. That's even a well known way to implement state machines. However, as usual, the details are a bit different in CPython, which has a C level slot for the "next" method. So the lookup isn't as heavy as it looks. Stefan From lucaberto at libero.it Fri Sep 3 03:58:12 2010 From: lucaberto at libero.it (luca72) Date: Fri, 3 Sep 2010 00:58:12 -0700 (PDT) Subject: pyqt unhandled RuntimeError \"no access to protected functions or signals for objects not created from Python Message-ID: <66fb86ba-5632-4a85-9762-38e17273e86d@x42g2000yqx.googlegroups.com> Hello i have also write to pyqt mailing list but maybe you can help me to solve this question: I have write a tcpserver but wheni try to read by the signal readyRead() e get the error this the part of the program: def nuova_connessione(self): print 'Nuova connessione' self.nuovo_socket = self.mio_server.nextPendingConnection() print self.nuovo_socket self.connect(self.nuovo_socket, QtCore.SIGNAL("connected()"), self. connessione) self.connect(self.nuovo_socket, QtCore.SIGNAL("readyRead()"), self. leggo_risposta) self.connect(self.nuovo_socket, QtCore.SIGNAL("disconnected"), self. sconnesso) self.connect(self.nuovo_socket, QtCore.SIGNAL("error(Qtcore. QAbsatctSocket::SocketError)"), self.server_errore) def leggo_risposta(self): cosa_leggo = self.nuovo_socket.readData(self.nuovo_socket. bytesAvailable()) can you help me Thanks From raoulbia at gmail.com Fri Sep 3 04:06:14 2010 From: raoulbia at gmail.com (Baba) Date: Fri, 3 Sep 2010 01:06:14 -0700 (PDT) Subject: bisection method: Simulating a retirement fund References: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> Message-ID: On Sep 2, 11:10?pm, MRAB wrote: > > Why are you saving 'fund' in SavingsRecord if you're returning just the > last and discarding others? Basically you're returning the final value > of fund. Hi MRAB ok i agree that this is not be ideal. I should shorten this to ONLY return SavingsRecord[-1] > When performing this type of 'search' make sure that the interval (high > - low) reduces at every step. > (integer division) and if the 'if' condition happens to be false > then the value of 'low' won't change for the next iteration, leading to an infinite loop. If you look at the output you will see that the interval DOES seem to reduce at each interval as expenses and fundsize reduce gradually. The computation does not lead to an infinite loop. tnx Baba From sarvilive at gmail.com Fri Sep 3 05:07:27 2010 From: sarvilive at gmail.com (sarvi) Date: Fri, 3 Sep 2010 02:07:27 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> <4c8014c2$0$1602$742ec2ed@news.sonic.net> <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> <4c809cea$0$1614$742ec2ed@news.sonic.net> Message-ID: <88614c5d-cd11-4f92-a871-57f4eaaefd75@i4g2000prf.googlegroups.com> Well then, wouldn't it make sense for PyPy to use Shedskin and its definition of Restricted Python? I have heard repeatedly that PyPy RPython is very difficult to use. Then why isn't PyPy using Shedskin to compile its PyPy-Jit? Sarvi On Sep 2, 11:59?pm, John Nagle wrote: > On 9/2/2010 10:30 PM, sarvi wrote: > > > > > > > On Sep 2, 2:19 pm, John Nagle ?wrote: > >> On 9/2/2010 1:29 AM, sarvi wrote: > > >>> When I think about it these restrictions below seem a very reasonable > >>> tradeoff for performance. > > >> ? ? ?Yes. > > >>> And I can use this for just the modules/sections that are performance > >>> critical. > > >> ? ? ?Not quite. ?Neither Shed Skin nor RPython let you call from > >> restricted code to unrestricted code. ?That tends to happen > >> implicitly as objects are passed around. ?It's the global > >> analysis that makes this work; when you call something, you > >> need to know more about it than how to call it. > > > It should technically be possible to allow Python to call a module > > written in RPython? > > ? ? The problem is that, in a language where everything is an object, > everything you call calls you back. > > ? ? The basic performance problem with CPython comes from the fact > that it uses the worst-case code for almost everything. ?Avoiding > that requires global analysis to detect the places where the code > clearly isn't doing anything weird and simpler code can be used. > Again, look at Shed Skin, which represents considerable progress > made by one guy. With more resources, that could be a very > good system. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle From michael at perfect-kreim.de Fri Sep 3 05:21:36 2010 From: michael at perfect-kreim.de (Michael Kreim) Date: Fri, 03 Sep 2010 11:21:36 +0200 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <4C80BE20.2010804@perfect-kreim.de> Hi, thanks a lot for your answers. I learn a lot and I like to sum up your suggestions and show you the results of the time command on my machine: Original code by me: imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a => runs (wall clock time): 1:55.14 Peter Otten suggested to put the code into a function: def f(): imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a f() => runs (wall clock time): 0:47.69 Tim Wintle and Philip Bloom posted some code using a while loop: imax = 1000000000 a = 0 i = 0 while 1: i = i + 1 if (i > imax): break a = a + 10 print a => runs (wall clock time): 3:28.05 imax = 1000000000 a = 0 i = 0 while(i runs (wall clock time): 3:27.74 Hrvoje Niksic suggested the usage of itertools: from itertools import repeat imax = 1000000000 a = 0 for i in repeat(None, imax): a = a + 10 print a => runs (wall clock time): 1:58.25 I wrote a code combining these: def f(): from itertools import repeat imax = 1000000000 a = 0 for i in repeat(None, imax): a = a + 10 print a f() => runs (wall clock time): 0:43.08 Then Roland Koebler suggested psyco but I am sitting on a 64bit machine and so I could not test it (although it looks promising). An anonymous Nobody suggested to use Numpy. I did not do this, because I am very very new to Numpy and I did not figure out a Numpy specific way to do this. Maybe a Numpy expert has something for me? So finally I followed the recommendation of Tim Wintle to use cython. I did not know this before, but I figured out the following: additionWintle2.pyx: def addition(): cdef long imax = 1000000000 cdef long a = 0 cdef long i for i in xrange(imax): a = a + 10 print a setup.py: from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [Extension("additionWintle2", ["additionWintle2.pyx"])] setup( name = 'Cython test', cmdclass = {'build_ext': build_ext}, ext_modules = ext_modules ) $ python setup.py build_ext --inplace run.py: from additionWintle2 import addition addition() running build_ext => runs (wall clock time): 0:00.04 And to compare this. I wrote something similar in Matlab and C++ (although some authors, pointed out that it is not that easy to compare "for" loops in these three languages): addition.cpp #include using namespace std; int main() { long imax = 1e9; long a = 0; long i; for(i=0; i < imax; i++) { a = a + 10; } cout << a << endl; return 0; } => Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.32 addition.m imax = 1e9; a = 0; for i=0:imax-1 a = a + 10; end disp(a); exit; => Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.39 With best regards, Michael From jc.lopes at gmail.com Fri Sep 3 05:35:10 2010 From: jc.lopes at gmail.com (jc.lopes) Date: Fri, 3 Sep 2010 02:35:10 -0700 (PDT) Subject: Where do I report a bug to the pythonware PIL Message-ID: <82e8e2d1-e86f-4b61-8902-7a51f55942d6@u6g2000yqh.googlegroups.com> Does anyone knows what is the proper way to submit a bug report to pythonware PIL? thanks JC Lopes From stefan_ml at behnel.de Fri Sep 3 05:39:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Sep 2010 11:39:21 +0200 Subject: Speed-up for loops In-Reply-To: <4C80BE20.2010804@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> <4C80BE20.2010804@perfect-kreim.de> Message-ID: Michael Kreim, 03.09.2010 11:21: > So finally I followed the recommendation of Tim Wintle to use cython. I > did not know this before, but I figured out the following: > additionWintle2.pyx: > > def addition(): > cdef long imax = 1000000000 > cdef long a = 0 > cdef long i > for i in xrange(imax): > a = a + 10 > print a > > => runs (wall clock time): 0:00.04 Note that this isn't the "real" runtime. If you look up the binary code that the C compiler spits out, you'll most likely find the final result for "a" written down as a literal that gets returned from the function. C compilers do these things to benchmarks these days. Stefan From vgnulinux at gmail.com Fri Sep 3 06:30:08 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Fri, 3 Sep 2010 16:00:08 +0530 Subject: Python for embedded systems development Message-ID: Hi, Is there anyone using python for embedded systems development ? I have no idea where to start with. Google was of little help. Will appreciate if someone could guide me on "from where to start". Regards Vgnu -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Fri Sep 3 07:12:00 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 03 Sep 2010 13:12:00 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <871v9bjd33.fsf@busola.homelinux.net> Ulrich Eckhardt writes: > Tim Wintle wrote: >> [..] under the hood, cpython does something like this (in psudo-code) >> >> itterator = xrange(imax) >> while 1: >> next_attribute = itterator.next >> try: >> i = next_attribute() >> except: >> break >> a = a + 10 > > There is one thing that strikes me here: The code claims that each > iteration there is a lookup of the 'next' field in the iterator. I > would expect that this is looked up once before the loop only. It is looked up every time, but the lookup is efficient because "next" is one of the special methods that have a slot in the C struct that defines a Python type. A closer code would be something like: next_function = iterator->ob_type->tp_next; ...which is as fast as it gets. CPython implements this in Python/ceval.c, just look for FOR_ITER. From python at bdurham.com Fri Sep 3 07:24:13 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 03 Sep 2010 07:24:13 -0400 Subject: Speed-up for loops In-Reply-To: <4C80BE20.2010804@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> <4C80BE20.2010804@perfect-kreim.de> Message-ID: <1283513053.20882.1393180723@webmail.messagingengine.com> Michael, Thanks for summarizing and sharing your results. Very interesting. Regards, Malcolm From vs at it.uu.se Fri Sep 3 07:29:21 2010 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 03 Sep 2010 13:29:21 +0200 Subject: Financial time series data Message-ID: <4C80DC11.50504@it.uu.se> A more direct question on accessing stock information from Yahoo. First, use your browser to go to: http://finance.yahoo.com/q/cp?s=%5EGSPC+Components Now, you see the first 50 rows of a 500 row table of information on S&P 500 index. You can LM click on 1 -50 of 500 |First|Previous|Next|Last below the table to position to any of the 10 pages. I would like to use Python to do the following. *Loop on each of the 10 pages and for each page extract information for each row --- How can this be accomplished automatically in Python?* Let's take the first page (as shown by default). It is easy to see the link to the data for "A" is http://finance.yahoo.com/q?s=A. That is, I can just move my cursor over the "A" and I see this URL in the message at the bottom of my browser (Explorer 8). If I LM click on "A" then I will go to this link --- Do this! You should now see a table which shows information on this stock and *this is the information that I would like to extract*. I would like to do this for all 500 stocks without the need to enter the symbols for them (e.g. "A", "AA", etc.). It seems clear that this should be possible since all the symbols are in the first column of each of the 50 tables --- but it is not at all clear how to extract these automatically in Python. Hopefully, you understand my problem. Again, I would like Python to cycle through these 10 pages and extract this information for each symbol in this table. --V -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Sep 3 08:21:55 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 3 Sep 2010 08:21:55 -0400 Subject: MySQL Problem In-Reply-To: <4C7FF4C0.1010503@gmaiil.com> References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: On Thu, Sep 2, 2010 at 3:02 PM, Ian wrote: > On 02/09/2010 19:34, Victor Subervi wrote: > >> for some reason running the command through python *omits* this one data!! >> The only difference is that a flag in spreadsheets (Temp) is set to 1. Why >> on earth doesn't it work in python?? >> > Some ideas to follow up. (These are only guesses). > > 1) One of the enum type fields contains an invalid value (perhaps a value > removed from the column definition). > There are no enum type fields. > > 2) The second id field (products.id?) appears to be very large. I wonder > what would happen if it was larger than the auto-increment value? > It's not an ID field. It doesn't auto_increment. > > 3) A field in the one of the rows in the missing data contains bytes that > are invalid in the character encoding you are using in python. > I changed the only bytes I thought might affect it. Furthermore, I successfully added the blasted data to that field so it would show up in the spreadsheet through another form. More on that later. > > 4) The python field type used for some column in the missing row, contains > a value that cannot be held in the python variable assigned. > If that were so, none of the data would show up. Please look at this comparison: FIELD BAD DATA GOOD DATA ID 609 161 Client Lincoln_Properties Lincoln_Properties Multi 0 0 Item 2030572 40x48Green Markup 0.00 99.32 Temp 1 Null ID 343 37 Item 2030572 40x48Green Description Americo 20" Beige Floor Pad Green Can Liners UOM 5/cs 1000/cs Cost 15.88 17.56 ID 335 37 ProductsID 343 37 CategoryID 49 23 ID 49 23 Category Mats Can Liners Parent Restaurant Paper/Pla Bags I have changed the value of Temp to Null and Markup to 11.11 to see if that would somehow make a difference. It didn't. Then I used my TTW form for adding data "regularly" to spreadsheets and it worked. The form I'm testing enables the client to add data himself. The code is the same in both cases: "regular" cursor.execute('insert into spreadsheets values (Null, %s, 0, %s, 0, Null)', (client, prod)) "special" cursor.execute('insert into spreadsheets values (Null, %s, 0, %s, 0, Null)', (client, product[1])) I checked permissions and changed ownership to make the two scripts identical. Again, the data gets entered into MySQL correctly...it just doesn't show up with the rest of the data in the TTW form!! Why?? TIA, beno > > Regards > > Ian > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nanjundi at gmail.com Fri Sep 3 09:07:38 2010 From: nanjundi at gmail.com (Nanjundi) Date: Fri, 3 Sep 2010 06:07:38 -0700 (PDT) Subject: Financial time series data References: Message-ID: On Sep 2, 1:12?pm, Virgil Stokes wrote: > ? Has anyone written code or worked with Python software for downloading > financial time series data (e.g. from Yahoo financial)? If yes, ?would you > please contact me. > > --Thanks, > V. Stokes matplotlib has a finance module you can refer to. (matplotlib.finance.fetch_historical_yahoo) see the example: http://matplotlib.sourceforge.net/examples/pylab_examples/finance_work2.html From mrmakent at cox.net Fri Sep 3 09:21:27 2010 From: mrmakent at cox.net (Mike Kent) Date: Fri, 3 Sep 2010 06:21:27 -0700 (PDT) Subject: python database References: <2010932369usenet@eggheadcafe.com> Message-ID: <40f41e67-9da0-41da-ab55-eb5bed596856@k1g2000prl.googlegroups.com> On Sep 3, 2:36?am, shai garcia wrote: > can you pls help me to make a database program in python? It's better if you do your homework yourself. You learn more that way. Now, if you have a specific question about some detail of your assignment, and can show us that you've really tried to do the work yourself, that's another matter. From arts.richard at gmail.com Fri Sep 3 09:25:45 2010 From: arts.richard at gmail.com (Richard Arts) Date: Fri, 3 Sep 2010 15:25:45 +0200 Subject: MySQL Problem In-Reply-To: References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: These are also mere suggestions. The statements you use in your print statement and the one you use to feed the cursor differ slightly. The latter is missing quotes around your search criterium. Isn't it possible to fetch results row by row and see if the missing row is in the set? That way you can get a better feeling about the nature of the error. > cursor.execute('insert into spreadsheets values (Null, %s, 0, %s, 0, Null)', (client, prod)) Out of curiosity, why would you want to insert null values in id fields? That's a disaster waiting to happen. Regards, Richard From tim.wintle at teamrubber.com Fri Sep 3 09:26:48 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 03 Sep 2010 14:26:48 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <1283520408.3209.126.camel@tim-laptop> On Fri, 2010-09-03 at 08:52 +0200, Ulrich Eckhardt wrote: > Tim Wintle wrote: > > [..] under the hood, cpython does something like this (in psudo-code) > > > > itterator = xrange(imax) > > while 1: > > next_attribute = itterator.next > > try: > > i = next_attribute() > > except: > > break > > a = a + 10 > > There is one thing that strikes me here: The code claims that each iteration > there is a lookup of the 'next' field in the iterator. I would expect that > this is looked up once before the loop only. > > Can you confirm that or am I misinterpreting your intention here? As Stefan and Hrvoje have posted, there is a lookup - but in 2.4 and above it's straight off the C structure and compiled efficiently. (I've been looking at 2.3's source recently and had forgotten the optimisation) Tim From victorsubervi at gmail.com Fri Sep 3 09:29:29 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 3 Sep 2010 09:29:29 -0400 Subject: MySQL Problem In-Reply-To: References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: This is an addendum to my last post. Please observe the following: mysql> select * from spreadsheets where Temp=1; +-----+--------------------+-------+---------+--------+------+ | ID | Client | Multi | Item | Markup | Temp | +-----+--------------------+-------+---------+--------+------+ | 611 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | | 621 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | +-----+--------------------+-------+---------+--------+------+ 2 rows in set (0.00 sec) mysql> describe spreadsheets; +--------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+------------------+------+-----+---------+----------------+ | ID | int(11) unsigned | NO | PRI | NULL | auto_increment | | Client | varchar(40) | YES | | NULL | | | Multi | tinyint(1) | YES | | NULL | | | Item | varchar(40) | YES | | NULL | | | Markup | float(6,2) | YES | | NULL | | | Temp | tinyint(1) | YES | | NULL | | +--------+------------------+------+-----+---------+----------------+ 6 rows in set (0.00 sec) Yet from my script: cursor.execute('select * from spreadsheets where Temp=1') print cursor.fetchall() print nothing but an empty set: () Why?? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Sep 3 09:37:15 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 3 Sep 2010 09:37:15 -0400 Subject: MySQL Problem In-Reply-To: References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: On Fri, Sep 3, 2010 at 9:25 AM, Richard Arts wrote: > These are also mere suggestions. > > The statements you use in your print statement and the one you use to > feed the cursor differ slightly. The latter is missing quotes around > your search criterium. > > Isn't it possible to fetch results row by row and see if the missing > row is in the set? That way you can get a better feeling about the > nature of the error. > Well, I just tried, out of curiosity, inserting 0 instead of 1 and guess what? It shows up. So by simply changing that my problem is solved...but I sure as heck would like to know why! > > > cursor.execute('insert into spreadsheets values (Null, %s, 0, %s, 0, > Null)', (client, prod)) > > Out of curiosity, why would you want to insert null values in id > fields? That's a disaster waiting to happen. > Hardly. This is the standard way of inserting into auto_increment fields. That triggers the auto_increment! That makes it much easier to insert the correct value of the field. beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthra.norell at bluewin.ch Fri Sep 3 09:45:36 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 03 Sep 2010 15:45:36 +0200 Subject: Financial time series data In-Reply-To: <4C80DC11.50504@it.uu.se> References: <4C80DC11.50504@it.uu.se> Message-ID: <1283521536.2364.139.camel@hatchbox-one> On Fri, 2010-09-03 at 13:29 +0200, Virgil Stokes wrote: > A more direct question on accessing stock information from Yahoo. > > First, use your browser to go to: http://finance.yahoo.com/q/cp?s=% > 5EGSPC+Components > > Now, you see the first 50 rows of a 500 row table of information on > S&P 500 index. You can LM click on > > 1 -50 of 500 |First|Previous|Next|Last > > below the table to position to any of the 10 pages. > > I would like to use Python to do the following. > > Loop on each of the 10 pages and for each page extract information for > each row --- How can this be accomplished automatically in Python? > > Let's take the first page (as shown by default). It is easy to see the > link to the data for "A" is http://finance.yahoo.com/q?s=A. That is, I > can just move > my cursor over the "A" and I see this URL in the message at the bottom > of my browser (Explorer 8). If I LM click on "A" then I will go to > this > link --- Do this! > > You should now see a table which shows information on this stock and > this is the information that I would like to extract. I would like to > do this for all 500 stocks without the need to enter the symbols for > them (e.g. "A", "AA", etc.). It seems clear that this should be > possible since all the symbols are in the first column of each of the > 50 tables --- but it is not at all clear how to extract these > automatically in Python. > > Hopefully, you understand my problem. Again, I would like Python to > cycle through these 10 pages and extract this information for each > symbol in this table. > > --V > > > Here's a quick hack to get the SP500 symbols from the visual page with the index letters. From this collection you can then order fifty at a time from the download facility. (If you get a better idea from Yahoo, you'll post it of course.) def get_SP500_symbols (): import urllib symbols = [] url = 'http://finance.yahoo.com/q/cp?s=^GSPC&alpha=%c' for c in [chr(n) for n in range (ord ('A'), ord ('Z') + 1)]: print url % c f = urllib.urlopen (url % c) html = f.readlines () f.close () for line in html: if line.lstrip ().startswith (' Hi I am new to python and have installed python 3.1.2. I have began using IDLE and like it very good. But when an IDLE window is active. There is a thick black frame around the white text field. Is there some way I can get rid of this frame? The frame is very distracting when I write. Kristoffer From alex at moreati.org.uk Fri Sep 3 11:14:21 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Fri, 3 Sep 2010 08:14:21 -0700 (PDT) Subject: Where do I report a bug to the pythonware PIL References: <82e8e2d1-e86f-4b61-8902-7a51f55942d6@u6g2000yqh.googlegroups.com> Message-ID: On Sep 3, 10:35?am, "jc.lopes" wrote: > Does anyone knows what is the proper way to submit a bug report to > pythonware PIL? > > thanks > JC Lopes The Python Image SIG list http://mail.python.org/mailman/listinfo/image-sig "Free Support: If you don't have a support contract, please send your question to the Python Image SIG mailing list. The same applies for bug reports and patches." -- http://www.pythonware.com/products/pil/ They don't appear to have a dedicated mailing list or public bug tracker. From lucaberto at libero.it Fri Sep 3 11:16:34 2010 From: lucaberto at libero.it (luca72) Date: Fri, 3 Sep 2010 08:16:34 -0700 (PDT) Subject: pyqt signals Message-ID: Hello i have write this but i not able to connect the emit of the class Socket to the Form class, can you help me? class Socket(QtNetwork.QTcpSocket): def __init__(self, parent=None): super(Socket, self).__init__(parent) self.connect(self, QtCore.SIGNAL("readyRead()"), self.leggi_richiesta) def leggi_richiesta(self): messaggio = self.readData(self.bytesAvailable()) print 'dati_letti = ', messaggio self.emit(QtCore.SIGNAL("messaggio"), messaggio) print 'segnale emesso' class Form(QWidget, Ui_Form): """ Class documentation goes here. """ def __init__(self, parent = None): """ Constructor """ connesso_in_arr =False self.coda = False QWidget.__init__(self, parent) self.setupUi(self) self.dati = False self.lu = TcpServer() self.lu self.connect(Socket(self), QtCore.SIGNAL('messaggio'), self.leggo_risposta) def leggo_risposta(self, messaggio): self.plainTextEdit_2.appendPlainText(messaggio) Thanks Luca From robert.kern at gmail.com Fri Sep 3 11:17:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 03 Sep 2010 10:17:32 -0500 Subject: Where do I report a bug to the pythonware PIL In-Reply-To: <82e8e2d1-e86f-4b61-8902-7a51f55942d6@u6g2000yqh.googlegroups.com> References: <82e8e2d1-e86f-4b61-8902-7a51f55942d6@u6g2000yqh.googlegroups.com> Message-ID: On 9/3/10 4:35 AM, jc.lopes wrote: > Does anyone knows what is the proper way to submit a bug report to > pythonware PIL? http://mail.python.org/mailman/listinfo/image-sig -- 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 rurpy at yahoo.com Fri Sep 3 11:54:52 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 3 Sep 2010 08:54:52 -0700 (PDT) Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <7a38148b-79e9-40ce-9700-2c0d1c9b3ee4@a4g2000prm.googlegroups.com> <4a3665a0-fc7f-425a-878e-6f8dcc5ed319@y11g2000yqm.googlegroups.com> Message-ID: <3647e26e-8734-42cf-af14-84d1fea78ddc@m35g2000prn.googlegroups.com> On 09/02/2010 02:47 PM, Terry Reedy wrote: > On 9/1/2010 10:57 PM, rurpy at yahoo.com wrote: > >> So while you may "think" most people rarely read >> the docs for basic language features and objects >> (I presume you don't mean to restrict your statement >> to only sets), I and most people I know *do* read >> them. And when read them I expect them, as any good >> reference documentation does, to completely and >> accurately describe the behavior of the item I am >> reading about. If big-O performance is deemed an >> intrinsic behavior of an (operation of) an object, >> it should be described in the documentation for >> that object. > > However, big-O performance is intentionally NOT so deemed. The discussion, as I understood it, was about whether or not it *should* be so deemed. > And I have > and would continue to argue that it should not be, for multiple reasons. Yes, you have. And others have argued the opposite. Personally, I did not find your arguments very convincing, particularly that it would be misleading or that the limits necessarily imposed by a real implementation somehow invalidates the usefulness of O() documentation. But I acknowledged that there was not universal agreement that O() behavior should be documented in the the reference docs by qualifying my statement with the word "if". But mostly my comments were directed towards some of the side comments in Raymond's post I thought should not pass unchallenged. I think that some of the attitudes expressed (and shared by others) are likely the direct cause of many of the faults I find in the currrent documentation. From john at castleamber.com Fri Sep 3 13:08:02 2010 From: john at castleamber.com (John Bokma) Date: Fri, 03 Sep 2010 12:08:02 -0500 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> <87aao1c8dk.fsf@castleamber.com> Message-ID: <87sk1q21sd.fsf@castleamber.com> Terry Reedy writes: > On 9/1/2010 8:11 PM, John Bokma wrote: [...] > Right. And if 'small values of n' include all possible values, then > rejecting a particular O(log n) algorithm as 'unacceptable' relative > to all O(1) algorithms is pretty absurd. I have little time, but want to reply to this one: anyone using big-Oh and claiming that an O(log n) algorithm is 'unacceptable' relative to all O(1) algorithms has no clue what he/she is talking about. big-Oh says something about the order of /growth/ of the running time of an algorithm. And since 1 is a constant O(1) means that the order of /growth/ of the running time is constant (independend of the input size. Since "the growth of the running time is constant" is quite a mouth full, it's often shortened to 'constant time' since from the context it's clear what's being meant. But this doesn't mean that if the algorithm gets an input size of 100000 versus 1 that it takes the same number of seconds for the latter to process. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From python at mrabarnett.plus.com Fri Sep 3 13:12:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 03 Sep 2010 18:12:49 +0100 Subject: bisection method: Simulating a retirement fund In-Reply-To: References: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> Message-ID: <4C812C91.80308@mrabarnett.plus.com> On 03/09/2010 09:06, Baba wrote: > On Sep 2, 11:10 pm, MRAB wrote: >> >> Why are you saving 'fund' in SavingsRecord if you're returning just the >> last and discarding others? Basically you're returning the final value >> of fund. > > Hi MRAB > > ok i agree that this is not be ideal. I should shorten this to ONLY > return SavingsRecord[-1] > > >> When performing this type of 'search' make sure that the interval (high >> - low) reduces at every step.> (integer division) and if the 'if' condition happens to be false >> then the value of 'low' won't change for the next iteration, leading to an infinite loop. > > > If you look at the output you will see that the interval DOES seem to > reduce at each interval as expenses and fundsize reduce gradually. The > computation does not lead to an infinite loop. > It doesn't in that particular case, but it might in some other cases. From anthra.norell at bluewin.ch Fri Sep 3 13:48:13 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 03 Sep 2010 19:48:13 +0200 Subject: Financial time series data In-Reply-To: <4C810AA1.7060700@it.uu.se> References: <4C80DC11.50504@it.uu.se> <1283521536.2364.139.camel@hatchbox-one> <4C810AA1.7060700@it.uu.se> Message-ID: <1283536093.2894.12.camel@hatchbox-one> On Fri, 2010-09-03 at 16:48 +0200, Virgil Stokes wrote: > On 03-Sep-2010 15:45, Frederic Rentsch wrote: > > On Fri, 2010-09-03 at 13:29 +0200, Virgil Stokes wrote: > >> A more direct question on accessing stock information from Yahoo. > >> > >> First, use your browser to go to: http://finance.yahoo.com/q/cp?s=% > >> 5EGSPC+Components > >> > >> Now, you see the first 50 rows of a 500 row table of information on > >> S&P 500 index. You can LM click on > >> > >> 1 -50 of 500 |First|Previous|Next|Last > >> > >> below the table to position to any of the 10 pages. > >> > >> I would like to use Python to do the following. > >> > >> Loop on each of the 10 pages and for each page extract information for > >> each row --- How can this be accomplished automatically in Python? > >> > >> Let's take the first page (as shown by default). It is easy to see the > >> link to the data for "A" is http://finance.yahoo.com/q?s=A. That is, I > >> can just move > >> my cursor over the "A" and I see this URL in the message at the bottom > >> of my browser (Explorer 8). If I LM click on "A" then I will go to > >> this > >> link --- Do this! > >> > >> You should now see a table which shows information on this stock and > >> this is the information that I would like to extract. I would like to > >> do this for all 500 stocks without the need to enter the symbols for > >> them (e.g. "A", "AA", etc.). It seems clear that this should be > >> possible since all the symbols are in the first column of each of the > >> 50 tables --- but it is not at all clear how to extract these > >> automatically in Python. > >> > >> Hopefully, you understand my problem. Again, I would like Python to > >> cycle through these 10 pages and extract this information for each > >> symbol in this table. > >> > >> --V > >> > >> > >> > > Here's a quick hack to get the SP500 symbols from the visual page with > > the index letters. From this collection you can then order fifty at a > > time from the download facility. (If you get a better idea from Yahoo, > > you'll post it of course.) > > > > > > > > def get_SP500_symbols (): > > import urllib > > symbols = [] > > url = 'http://finance.yahoo.com/q/cp?s=^GSPC&alpha=%c' > > for c in [chr(n) for n in range (ord ('A'), ord ('Z') + 1)]: > > print url % c > > f = urllib.urlopen (url % c) > > html = f.readlines () > > f.close () > > for line in html: > > if line.lstrip ().startswith (' > line_split = line.split (':') > > s = [item.strip ().upper () for item in line_split [5].replace ('"', > > '').split (',')] > > symbols.extend (s [:-3]) > > > > return symbols > > # Not quite 500 (!?) > > > > > > Frederic > > > > > > > I made a few modifications --- very minor. But, I believe that it is a little > faster. > > import urllib2 > > def get_SP500_symbolsX (): > symbols = [] > for page in range(0,9): > url = 'http://finance.yahoo.com/q/cp?s=%5EGSPC&c='+str(page) > print url > f = urllib2.urlopen (url) > html = f.readlines () > f.close () > for line in html: > if line.lstrip ().startswith (' line_split = line.split (':') > s = [item.strip ().upper () for item in line_split [5].replace > ('"','').split (',')] > symbols.extend (s [:-3]) > > return symbols > # Not quite 500 -- which is correct (for example p. 2 has only 49 symbols!) > # Actually the S&P 500 as shown does not contain 500 stocks (symbols) > > > symbols = get_SP500_symbolsX() > pass Oh, yes, and there's no use reading lines to the end once the symbols are in the bag. The symbol-line-finder conditional section should end with "break". And do let us know if you get an answer from Yahoo. Hacks like this are unreliable. They fail almost certainly the next time a page gets redesigned, which can be any time. Frederic From alistair.calder at gmail.com Fri Sep 3 13:52:01 2010 From: alistair.calder at gmail.com (alistair) Date: Fri, 3 Sep 2010 10:52:01 -0700 (PDT) Subject: New to python - parse data into Google Charts Message-ID: <42b45d97-b475-4bd8-b386-9c6db73316f9@f20g2000pro.googlegroups.com> I'm new to python and my programming years are a ways behind me, so I was looking for some help in parsing a file into a chart using the Google Charts API. The file is simply a text file containing: Date, Total Accesses, Unique Accesses. I'd like date across the bottom, access numbers on the vertical axis and lines for the amounts. I'm not even really sure how to get started if someone wants to give me some pointers or throw together a short example, I would greatly appreciate it. Here is a sample of the data: 2010-08-01, 2324, 1800 2010-08-02, 3832, 2857 2010-08-03, 7916, 4875 2010-08-04, 7004, 4247 2010-08-05, 6392, 4026 2010-08-06, 5396, 3513 2010-08-07, 3238, 2285 2010-08-08, 3579, 2588 2010-08-09, 7710, 4867 2010-08-10, 6662, 4123 2010-08-11, 6524, 4045 2010-08-12, 6438, 3965 2010-08-13, 5472, 3543 2010-08-14, 3059, 2193 2010-08-15, 3255, 2379 2010-08-16, 7149, 4482 2010-08-17, 6727, 4247 2010-08-18, 6989, 4328 2010-08-19, 6738, 4192 2010-08-20, 5929, 3816 2010-08-21, 3245, 2302 2010-08-22, 4091, 2900 2010-08-23, 8237, 4857 2010-08-24, 7895, 4575 2010-08-25, 7788, 4564 2010-08-26, 7616, 4527 2010-08-27, 6671, 4159 2010-08-28, 3595, 2484 2010-08-29, 4377, 2991 2010-08-30, 9238, 5427 2010-08-31, 9274, 5406 From robert.kern at gmail.com Fri Sep 3 14:05:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 03 Sep 2010 13:05:22 -0500 Subject: Performance: sets vs dicts. In-Reply-To: <87sk1q21sd.fsf@castleamber.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> <87aao1c8dk.fsf@castleamber.com> <87sk1q21sd.fsf@castleamber.com> Message-ID: On 9/3/10 12:08 PM, John Bokma wrote: > Terry Reedy writes: > >> On 9/1/2010 8:11 PM, John Bokma wrote: > > [...] > >> Right. And if 'small values of n' include all possible values, then >> rejecting a particular O(log n) algorithm as 'unacceptable' relative >> to all O(1) algorithms is pretty absurd. > > I have little time, but want to reply to this one: anyone using big-Oh > and claiming that an O(log n) algorithm is 'unacceptable' relative to > all O(1) algorithms has no clue what he/she is talking about. > > big-Oh says something about the order of /growth/ of the running time of > an algorithm. And since 1 is a constant O(1) means that the order of > /growth/ of the running time is constant (independend of the input > size. That's an ambiguous wording that is likely to confuse people. It seems like you are saying that the O() behavior is the order of the first derivative of the running time as a function of some interesting parameter of the problem, which it is not. O() notation *describes* the growth, but it *is not* the order of the growth itself. -- 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 pavlovevidence at gmail.com Fri Sep 3 14:28:07 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 3 Sep 2010 11:28:07 -0700 (PDT) Subject: bisection method: Simulating a retirement fund References: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> Message-ID: On Sep 2, 1:37?pm, Baba wrote: > level: beginner In this economy, simulating the value of retirement funds with bisection is easy. Look: def retirement_fund_value(n_years,initial_value): for i in xrange(n_years): value /= 2 # <- bisect value of fund return value Carl Banks From nfdisco at gmail.com Fri Sep 3 15:35:48 2010 From: nfdisco at gmail.com (ernest) Date: Fri, 3 Sep 2010 12:35:48 -0700 (PDT) Subject: what should __iter__ return? Message-ID: Hi, What is better: def __iter__(self): for i in len(self): yield self[i] or def __iter__(self): return iter([self[i] for i in range(len(self))]) The first one, I would say is more correct, however what if in a middle of an iteration the object changes in length? Then, the iterator will fail with IndexError (if items have been removed), or it will fail to iterate over the whole sequence (if items have been added). What do you think? Cheers. Ernest From mrmakent at cox.net Fri Sep 3 15:41:39 2010 From: mrmakent at cox.net (Mike Kent) Date: Fri, 3 Sep 2010 12:41:39 -0700 (PDT) Subject: Does MySQLdb rollback on control-C? Maybe not. References: <4c8077f1$0$1628$742ec2ed@news.sonic.net> Message-ID: On Sep 3, 12:22?am, John Nagle wrote: > ? ? I would expect MySQLdb to rollback on a control-C, but it doesn't > seem to have done so. ? > Something is broken. I wouldn't expect it to, I'd expect to roll back on an exception, or commit if not. Perhaps this will help you. I use it in production code. ## # This is a transaction context manager. It will ensure that the code in # the context block will be executed inside a transaction. If any exception # occurs, the transaction will be rolled back, and the exception reraised. # If no exception occurs, the transaction will be committed. # db is a database connection object. from contextlib import contextmanager @contextmanager def transaction(db): db.begin() try: yield None except: db.rollback() raise else: db.commit() From mrmakent at cox.net Fri Sep 3 15:51:26 2010 From: mrmakent at cox.net (Mike Kent) Date: Fri, 3 Sep 2010 12:51:26 -0700 (PDT) Subject: New to python - parse data into Google Charts References: <42b45d97-b475-4bd8-b386-9c6db73316f9@f20g2000pro.googlegroups.com> Message-ID: <9222c04c-3f7f-4d36-afde-ec9dc5dfa740@i17g2000vbq.googlegroups.com> On Sep 3, 1:52?pm, alistair wrote: > I'm new to python and my programming years are a ways behind me, so I > was looking for some help in parsing a file into a chart using the > Google Charts API. > Try this: http://pygooglechart.slowchop.com/ From hobson42 at gmaiil.com Fri Sep 3 15:54:08 2010 From: hobson42 at gmaiil.com (Ian) Date: Fri, 03 Sep 2010 20:54:08 +0100 Subject: MySQL Problem In-Reply-To: References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: <4C815260.5090904@gmaiil.com> On 03/09/2010 14:29, Victor Subervi wrote: > This is an addendum to my last post. Please observe the following: > > mysql> select * from spreadsheets where Temp=1; > +-----+--------------------+-------+---------+--------+------+ > | ID | Client | Multi | Item | Markup | Temp | > +-----+--------------------+-------+---------+--------+------+ > | 611 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | > | 621 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | > +-----+--------------------+-------+---------+--------+------+ > 2 rows in set (0.00 sec) > > mysql> describe spreadsheets; > +--------+------------------+------+-----+---------+----------------+ > | Field | Type | Null | Key | Default | Extra | > +--------+------------------+------+-----+---------+----------------+ > | ID | int(11) unsigned | NO | PRI | NULL | auto_increment | > | Client | varchar(40) | YES | | NULL | | > | Multi | tinyint(1) | YES | | NULL | | > | Item | varchar(40) | YES | | NULL | | > | Markup | float(6,2) | YES | | NULL | | > | Temp | tinyint(1) | YES | | NULL | | > +--------+------------------+------+-----+---------+----------------+ > 6 rows in set (0.00 sec) > > Yet from my script: > > cursor.execute('select * from spreadsheets where Temp=1') > print cursor.fetchall() > > print nothing but an empty set: () Why?? > TIA, > beno Hi Victor Find out exactly what character encoding are you using for each of the following places when using MySQL client. The MySQL installation The database definition The table definition The Field definition The Link between Python and MySQL The Python source / The Msql Client. And then find out what encoding is being forced/used by the code you have written in Python in each of the above situations? You may have to go to the source of the library routine to find this out. What I suspect may be happening is this. Say you have a field containing a character/code point that is in UTF-8 but not in the ISO-8859-1 set. If such a field was written using UTF-8 throughout, but then read using ISO-8859-1 or similar then the read will generate an error. That error may be being ignored or suppressed causing the code to drop your data rows. IIRC, MySQL calls UTF-8 by the (incorrect) name of utf-8. My recommendation is for you to use UTF-8 for everything. UTF-8 can store any character in any language(1), is really efficient for English text, and acceptable for other languages. Performance it excellent, because it involves no encoding/decoding as the data moves between disk, MySQL link or Python. (1) There are some minor human languages that cannot be encoded - usually because no written form has yet been devised or the code points have not been agreed. These languages will not be met in practise. Regards Ian From nobody at nowhere.com Fri Sep 3 15:54:45 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 03 Sep 2010 20:54:45 +0100 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: On Fri, 03 Sep 2010 11:21:36 +0200, Michael Kreim wrote: > An anonymous Nobody suggested to use Numpy. I did not do this, because I > am very very new to Numpy and I did not figure out a Numpy specific way > to do this. Maybe a Numpy expert has something for me? The problem with giving examples is that your original example is too contrived. Taken literally, it can be optimised to print imax * 10 A less contrived example would actually do something within the loop, in order to justify the existence of the loop. NumPy provides predefined loops which correspond to map, reduce, accumulate and zip, for all of the standard arithmetic operators and common mathematical functions. E.g. if your loop was: a = 0 for i in xrange(imax): a += i**2 print a the NumPy version would be: print numpy.sum(numpy.arange(imax)**2) The arange() function is similar to range() but generates an array. The ** operator is implemented for arrays; sum() sums the elements of the array. The main downside is that the intermediate array(s) must be constructed in memory, which rules out its use for very long sequences. From thomas at jollybox.de Fri Sep 3 15:58:38 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 3 Sep 2010 21:58:38 +0200 Subject: what should __iter__ return? In-Reply-To: References: Message-ID: <201009032158.39479.thomas@jollybox.de> On Friday 03 September 2010, it occurred to ernest to exclaim: > Hi, > > What is better: > > def __iter__(self): > for i in len(self): > yield self[i] > > or > > def __iter__(self): > return iter([self[i] for i in range(len(self))]) > > The first one, I would say is more correct, > however what if in a middle of an iteration > the object changes in length? Then, the > iterator will fail with IndexError (if items > have been removed), or it will fail to iterate > over the whole sequence (if items have > been added). > > What do you think? Hmm. Modifying an object while iterating over it isn't a great idea, ever: >>> L = [1,2,3,4] >>> i = iter(L) >>> next(i) 1 >>> next(i) 2 >>> del L[0] >>> next(i) 4 You second version is wasteful. It creates a copy of the object just for iteration. I don't think that's something you should be doing. If you want "correct" behaviour as with lists, you might want something like this: def __iter__(self): class _Iter: def __init__(it): it.i = -1 def __next__(it): it.i += 1 try: return self[it.i] except IndexError: raise StopIteration return _Iter() > > Cheers. > Ernest From python at mrabarnett.plus.com Fri Sep 3 16:02:35 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 03 Sep 2010 21:02:35 +0100 Subject: what should __iter__ return? In-Reply-To: References: Message-ID: <4C81545B.3060708@mrabarnett.plus.com> On 03/09/2010 20:35, ernest wrote: > Hi, > > What is better: > > def __iter__(self): > for i in len(self): > yield self[i] > > or > > def __iter__(self): > return iter([self[i] for i in range(len(self))]) > > The first one, I would say is more correct, > however what if in a middle of an iteration > the object changes in length? Then, the > iterator will fail with IndexError (if items > have been removed), or it will fail to iterate > over the whole sequence (if items have > been added). > > What do you think? > I'd say the first one is less correct because you can't iterate over an int. :-) From bartc at freeuk.com Fri Sep 3 16:17:44 2010 From: bartc at freeuk.com (BartC) Date: Fri, 3 Sep 2010 21:17:44 +0100 Subject: Speed-up for loops In-Reply-To: References: Message-ID: "Michael Kreim" wrote in message news:mailman.362.1283422325.29448.python-list at python.org... > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Unfortunately my Python Code was much slower and I do not understand why. > > Are there any ways to speed up the for/xrange loop? > Or do I have to live with the fact that Matlab beats Python in this > example? I'm not sure the Python developers were interested in getting fast loops. For-loops which iterate between two numbers are amongst the easiest things to make fast in a language. Yet originally you had to use: for i in range(N): which (if I understood correctly) actually created a list of N objects, populated it with the values 0, 1, 2...N-1 (presumably using a more sensible loop), then iterated between the values of the list! So Python had the distinction of being one of the slowest languages in which to do nothing (ie. running an empty loop). -- Bartc From stefan_ml at behnel.de Fri Sep 3 16:31:40 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Sep 2010 22:31:40 +0200 Subject: Speed-up for loops In-Reply-To: References: Message-ID: BartC, 03.09.2010 22:17: > for i in range(N): > > which (if I understood correctly) actually created a list of N objects, > populated it with the values 0, 1, 2...N-1 (presumably using a more > sensible loop), then iterated between the values of the list! I guess what applies here is "special cases aren't special enough to break the rules". The performance is good enough in most cases, it only hurts when the range is large and the loop body is small in comparison, such as in the most obvious stupid benchmarks. Also, xrange() is a pretty old addition the the language and now replaces range() in Python 3. Stefan From gavin.das1 at gmail.com Fri Sep 3 17:27:35 2010 From: gavin.das1 at gmail.com (Gavin) Date: Fri, 3 Sep 2010 14:27:35 -0700 (PDT) Subject: Date Parsing Question Message-ID: Hi, I'm using the python-dateutil package : http://labix.org/python-dateutil to parse a set of randomly formatted strings into dates. Because the formats are varied, I can't use time.strptime() because I don't know what the format is upfront. python-dateutil seems to work very well if everything is in English, however, it does not seem to work for other languages and the documentation does not seem to have any information about locale support. Here's an example showing my problem: Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from dateutil.parser import * >>> import datetime >>> import time >>> date_string1 = time.strftime("%Y-%B-%d %H:%M:%S",(2010,10,3,1,1,1,1,1,1)) >>> print date_string1 2010-October-03 01:01:01 >>> parse(date_string1) datetime.datetime(2010, 10, 3, 1, 1, 1) everything is ok so far, now retry with a date in german: >>> import locale >>> locale.setlocale(locale.LC_ALL, "german") 'German_Germany.1252' >>> locale.getlocale() ('de_DE', 'cp1252') >>> date_string1 = time.strftime("%Y-%B-%d %H:%M:%S",(2010,10,3,1,1,1,1,1,1)) >>> print date_string1 2010-Oktober-03 01:01:01 >>> parse(date_string1) Traceback (most recent call last): File "", line 1, in NameError: name 'date_string' is not defined >>> parse(date_string1) Traceback (most recent call last): File "", line 1, in File "c:\python26\lib\site-packages\python_dateutil-1.5-py2.6.egg \dateutil\parser.py", line 697, in parse return DEFAULTPARSER.parse(timestr, **kwargs) File "c:\python26\lib\site-packages\python_dateutil-1.5-py2.6.egg \dateutil\parser.py", line 303, in parse raise ValueError, "unknown string format" ValueError: unknown string format Am I out of luck with this package? Just wondering if anyone has used this to work with non-english dates. I'm also open to other ideas to handle this. Appreciate the assistance, Gavin From hobson42 at gmaiil.com Fri Sep 3 17:27:52 2010 From: hobson42 at gmaiil.com (Ian) Date: Fri, 03 Sep 2010 22:27:52 +0100 Subject: Help needed with Windows Service in Python In-Reply-To: <4C804386.90304@gmail.com> References: <4C7FC11C.7030904@ianhobson.co.uk> <4C804386.90304@gmail.com> Message-ID: <4C816858.9050105@gmaiil.com> On 03/09/2010 01:38, Mark Hammond wrote: > I expect that the Windows Event Log might have some clues, as would > attempting to use it in "debug" mode. Thanks Mark. The error log holds the trackback - it identified the line with the typo. Now the typo is fixed, the service starts and stops properly. Regards Ian From hobson42 at gmaiil.com Fri Sep 3 17:31:45 2010 From: hobson42 at gmaiil.com (Ian) Date: Fri, 03 Sep 2010 22:31:45 +0100 Subject: Help needed with Windows Service in Python In-Reply-To: <288bf7ad-9251-40d7-9270-e938170a8ed0@x25g2000yqj.googlegroups.com> References: <288bf7ad-9251-40d7-9270-e938170a8ed0@x25g2000yqj.googlegroups.com> Message-ID: <4C816941.1020408@gmaiil.com> On 02/09/2010 20:55, Edward Kozlowski wrote: > On Sep 2, 2:38 pm, Ian wrote: >> On 02/09/2010 20:06, Edward Kozlowski wrote: >> >> >> >>> On Sep 2, 10:22 am, Ian Hobson wrote: >>>> Hi All, >>>> I am attempting to create a Windows Service in Python. >>>> I have the framework (from Mark Hammond and Andy Robinason's book) >>>> running - see below. It starts fine - but it will not stop. :( >>>> net stop "Python Service" >>>> and using the services GUI both leave the services showing it as "stopping" >>>> I guess this means SvcStop is called but it is not enough to get it out >>>> of the machine. >>>> Does anyone know why not? >>>> Python 2.7 with win32 extensions, sunning on Windows 7. >>>> Many thanks >>>> Ian >>>> the (complete) source code is >>>> #!/usr/bin/env python >>>> # coding=utf8 >>>> # service.py = testing services and Named pipes >>>> # >>>> import win32serviceutil >>>> import win32service >>>> import win32event >>>> class PythonService(win32serviceutil.ServiceFramework): >>>> _svc_name_ = "Python Service" >>>> _svc_display_name_ = "Test Service in Python" >>>> def __init__(self, args): >>>> win32serviceutil.ServiceFramework.__init__(self,args) >>>> self.hWaitStop = win32event.CreateEvent(None,0,0,None) >>>> def SvcStop(self): >>>> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) >>>> wind32event.SetEvent(self.hWaitStop) >>>> def SvcDoRun(self): >>>> win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) >>>> if __name__ == '__main__': >>>> win32serviceutil.HandleCommandLine(PythonService) >>> Looks to me like there may be a typo in your code. >>> You probably meant win32event.SetEvent(self.hWaitStop), not >>> wind32event. >>> Regards, >>> -Edward Kozlowski >> A huge big thank you Edward. That was the problem. >> >> Regards >> >> Ian > You're most welcome. > > If you're looking at running services in Windows using Python, one > other hangup I ran into was that my services would freeze for no > reason. At Pycon '09, I learned that there were buffers for stdout > and stderr that were filling. I wish I could remember who gave the > talk that included the jewel of knowledge, because I'd love to give > credit where it's due... > > After I redirected stdout and stderr to files, my problems with the > services freezing went away. > > Regards, > -Edward Kozlowski Hi Edward, Thanks for the heads up. That is really worth knowing. Ian From nagle at animats.com Fri Sep 3 17:34:10 2010 From: nagle at animats.com (John Nagle) Date: Fri, 03 Sep 2010 14:34:10 -0700 Subject: Does MySQLdb rollback on control-C? Maybe not. In-Reply-To: References: <4c8077f1$0$1628$742ec2ed@news.sonic.net> Message-ID: <4c8169ce$0$1655$742ec2ed@news.sonic.net> On 9/3/2010 12:41 PM, Mike Kent wrote: > On Sep 3, 12:22 am, John Nagle wrote: >> I would expect MySQLdb to rollback on a control-C, but it doesn't >> seem to have done so. > >> Something is broken. > > I wouldn't expect it to, I'd expect to roll back on an exception, or > commit if not. MySQL does rollback properly on connection failure or program exit. It turns out I had a commit on that database handle in logging code. John Nagle From kkf628 at gmail.com Fri Sep 3 18:16:07 2010 From: kkf628 at gmail.com (=?ISO-8859-1?Q?Kristoffer_F=F8llesdal?=) Date: Fri, 3 Sep 2010 15:16:07 -0700 (PDT) Subject: IDLE / Black frame on Mac References: <3677b256-0eab-4912-b87b-d7327341fd36@x20g2000pro.googlegroups.com> Message-ID: *Forgot to tell that I am using a Mac with Snow Leopard. From db3l.net at gmail.com Fri Sep 3 18:41:45 2010 From: db3l.net at gmail.com (David Bolen) Date: Fri, 03 Sep 2010 18:41:45 -0400 Subject: Date Parsing Question References: Message-ID: Gavin writes: > python-dateutil seems to work very well if everything is in English, > however, it does not seem to work for other languages and the > documentation does not seem to have any information about locale > support. Probably because I don't think there is much built in. You'll want to supply your own parserinfo to the parse function. I haven't had to parse non-english localized date strings myself yet, but yes, the default parserinfo used by the module is in English. Looks like the docs don't get into it too much, but if you review the parser.py source in the package you can see the default parserinfo definition. I would think defining your own (or subclass of the default) and replacing the WEEKDAYS and MONTHS values would work (you can get localized lists directly from the calendar module) and maybe adding to the jump table if you want to parser longer phrases. At a first glance, the lexer within the module does seem like there may be some possible issues with more esoteric encodings or unicode, but just something to stay aware of. If you already have a i18n/l10n setup in your application (or need to have finer grained control than a global locale setting), you could instead override the lookup methods, though there's a bit more work to do since the initial lookup tables will probably need to be created in each of the locales you may wish to switch between. -- David From alistair.calder at gmail.com Fri Sep 3 18:45:34 2010 From: alistair.calder at gmail.com (alistair) Date: Fri, 3 Sep 2010 15:45:34 -0700 (PDT) Subject: New to python - parse data into Google Charts References: <42b45d97-b475-4bd8-b386-9c6db73316f9@f20g2000pro.googlegroups.com> <9222c04c-3f7f-4d36-afde-ec9dc5dfa740@i17g2000vbq.googlegroups.com> Message-ID: <5d59fb9a-e34e-4027-a562-b96526dc2761@w15g2000pro.googlegroups.com> On Sep 3, 12:51?pm, Mike Kent wrote: > On Sep 3, 1:52?pm, alistair wrote: > > > I'm new to python and my programming years are a ways behind me, so I > > was looking for some help in parsing a file into a chart using the > > Google Charts API. > > Try this:http://pygooglechart.slowchop.com/ Thanks for that. I guess I should have noted that I am new enough that I'm not even really sure how I would go about using this. From ldo at geek-central.gen.new_zealand Fri Sep 3 19:02:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 04 Sep 2010 11:02:18 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> Message-ID: In message <7xvd6sv0n4.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: >>> AddrObj = PyTuple_GetItem(TheBufferInfo, 0); >>> LenObj = PyTuple_GetItem(TheBufferInfo, 1); >>> >>> the first PyTuple_GetItem succeeds and the second one fails. >> >> Admittedly, I did take a shortcut here: array.buffer_info returns a tuple >> of two items, so I?m not expecting one GetItem to succeed and the other >> to fail. > > FromArray is a parameter to the function, with no type check to make > sure it's really an array. In fact your code allows for the possibility > that it doesn't support the buffer_info operation (if I understand the > purpose of the null return check after the PyObject_CallMethod) which > means it's prepared for the argument to -not- be an array. That reinforces my point, about how easy it was to check the correctness of the code. In this case one simple fix, like this diff --git a/spuhelper.c b/spuhelper.c index 83fd4eb..2ba8197 100644 --- a/spuhelper.c +++ b/spuhelper.c @@ -151,10 +151,12 @@ static void GetBufferInfo if (TheBufferInfo == 0) break; AddrObj = PyTuple_GetItem(TheBufferInfo, 0); - LenObj = PyTuple_GetItem(TheBufferInfo, 1); if (PyErr_Occurred()) break; Py_INCREF(AddrObj); + LenObj = PyTuple_GetItem(TheBufferInfo, 1); + if (PyErr_Occurred()) + break; Py_INCREF(LenObj); *addr = PyInt_AsUnsignedLongMask(AddrObj); *len = PyInt_AsUnsignedLongMask(LenObj); would render the code watertight. See how easy it is? From ldo at geek-central.gen.new_zealand Fri Sep 3 19:05:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 04 Sep 2010 11:05:03 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <4c78e7a5$0$28655$c3e8da3@news.astraweb.com> <4c7a2c3b$0$22941$e4fe514c@news.xs4all.nl> <7xhbidndc6.fsf@ruckus.brouhaha.com> <8e15pqFn89U1@mid.individual.net> <7xmxs4uzjl.fsf@ruckus.brouhaha.com> <7xiq2que93.fsf@ruckus.brouhaha.com> Message-ID: In message <7xiq2que93.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: >> >>> Refcounting is susceptable to the same pauses for reasons already >>> discussed. >> >> Doesn?t seem to happen in the real world, though. > > def f(n): > from time import time > a = [1] * n > t0 = time() > del a > t1 = time() > return t1 - t0 > > for i in range(9): > print i, f(10**i) > > > on my system prints: > > 0 2.86102294922e-06 > 1 2.14576721191e-06 > 2 3.09944152832e-06 > 3 1.00135803223e-05 > 4 0.000104904174805 > 5 0.00098991394043 > 6 0.00413608551025 > 7 0.037693977356 > 8 0.362598896027 > > Looks pretty linear as n gets large. 0.36 seconds (the last line) is a > noticable pause. Which just proves the point. You had to deliberately set up the situation to make that happen. And it remains just as easy to pinpoint where it is happening, so you can control it. With a garbage collector, you don?t have that control. Even if you try to avoid freeing a single large structure at once, it?s still liable to batch up a lot of small objects to free at once, so the problem can still happen. From ldo at geek-central.gen.new_zealand Fri Sep 3 19:31:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 04 Sep 2010 11:31:26 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> Message-ID: In message <7xmxs2uez1.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: > >> Whereas garbage collection will happen at some indeterminate time long >> after the last access to the object, when it very likely will no longer >> be in the cache, and have to be brought back in just to be freed, > > GC's for large systems generally don't free (or even examine) individual > garbage objects. They copy the live objects to a new contiguous heap > without ever touching the garbage, and then they release the old heap. And suddenly you?ve doubled the memory requirements. And on top of that, since you?re moving the valid objects into different memory, you?re forcing cache misses on all of them as well. This is the continuing problem with garbage collection: all the attempts to make it cheaper just end up moving the costs somewhere else. From ldo at geek-central.gen.new_zealand Fri Sep 3 19:33:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 04 Sep 2010 11:33:08 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> Message-ID: In message <7xr5heufhb.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Java has considerably greater reputation for reliability than C or C++. Wonder why Sun?s licence explicitly forbade its use in danger-critical areas like nuclear power plants and the like, then? > Ada is a different story, but Ada programs (because of the application > area Ada is used in) tend not to use a lot of dynamic memory allocation > in the first place. A little googling shows there are GC extensions > available for Ada, though I don't know if they are used much. Let?s put it this way: the life-support system on the International Space Station is written in Ada. Would you trust your life to code written in Java? From no.email at nospam.invalid Fri Sep 3 22:21:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 03 Sep 2010 19:21:42 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> Message-ID: <7xbp8el03t.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: >> Java has considerably greater reputation for reliability than C or C++. > > Wonder why Sun?s licence explicitly forbade its use in danger-critical > areas like nuclear power plants and the like, then? Probably because Sun lawyers demanded it. Is there a Sun C or C++ compiler with a license that doesn't have that restriction? Even if there is, it just means those languages are so unreliable that the lawyers felt confident that any meltdown could be blamed on a bug in the user's rather than the compiler ;-). > Let?s put it this way: the life-support system on the International Space > Station is written in Ada. Would you trust your life to code written in > Java? The scary thing is I don't know whether I'm already doing that. Life support systems have hard real-time requirements (Ada's forte) but I'd expect lots of military decision-support systems are written in Java. Maybe one of them will raise a false alert and somebody will launch a war. From chinnamma5463 at gmail.com Fri Sep 3 22:26:30 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:26:30 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: The Amazing Google Adsense Program is now towering like a Colossus in the Internet. It has helped approximately smart Internet Marketers to get on to enormous amounts of while by the same calculate it is appealing to annotation with the intention of many extra Internet Marketers and Internet Home-Based Business Entrepreneurs are receiving their initially shell out check from Google Adsense very than the foremost connect curriculum. visit http://www.adsensesubstitutes.com/ for more details. From chinnamma5463 at gmail.com Fri Sep 3 22:27:45 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:27:45 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: <81955314-2a1c-479e-89c6-d0922a3b0c28@q40g2000prg.googlegroups.com> If you control a website and wish to promote it for money at home, therefore the Google AdSense syllabus is inescapable merely in support of you. It has befall a bonus in support of a luck of sites whether they are small or sizeable or form. Taking part in information, this has befall such a all the rage tool with the purpose of a number of web designers control making websites solely in support of the intent of AdSense. visit http://www.adsensesubstitutes.com/adsense-program.htm From chinnamma5463 at gmail.com Fri Sep 3 22:29:25 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:29:25 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: It's an untoward information with the purpose of many AdSense users are getting their accounts terminated by the time they've complete nothing unsuitable. Considering the money individual can promote to from operational AdSense employment, the loss of one's bank account can be a real blow. Especially if the holder doesn't know why their bank account is being revoked! visit http://www.adsensesubstitutes.com/adsense-clicks.htm From chinnamma5463 at gmail.com Fri Sep 3 22:30:08 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:30:08 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: <0e653e52-8a82-4f76-829a-2b2a94b5b1ce@a4g2000prm.googlegroups.com> Google is arguably the majority all the rage website on the internet. With Google's AdSense syllabus, Google allows you to earn money by iplacing ads on your website. The majority of Google's revenue comes from advertising. Search engines forever control ads with the purpose of are tagged by the given keywords with the purpose of you enter, and the ads appear along with the search results visit http://www.adsensesubstitutes.com/adsense-earn-money.htm From chinnamma5463 at gmail.com Fri Sep 3 22:31:37 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:31:37 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: <301ca28a-026d-42fc-ba57-95d10d1d97a6@p22g2000pre.googlegroups.com> On the wild frontiers of the internet, in attendance are hundreds or thousands of prospectors, all striving to clash with the after that sizeable smash into. One of the majority all the rage methods of mining in support of internet gold is to employment Google AdSense. visit http://www.adsensesubstitutes.com/adsense-making-money.htm From chinnamma5463 at gmail.com Fri Sep 3 22:32:17 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:32:17 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: I'm pretty certain with the purpose of we all can promote to this allegation - "I know quite a luck approaching AdSense". This of track will be authentic in a convinced context. For illustration what time you are conversation to an recluse, someone who doesn't apply AdSense to his or her website, so therefore all right, you will know quite a luck approaching AdSense. But on a level singing sports ground sat after that to any more AdSense extreme, might you promote to the same allegation? visit http://www.adsensesubstitutes.com/Adsense-help.htm From chinnamma5463 at gmail.com Fri Sep 3 22:33:10 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:33:10 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: <8fe7292d-7ae1-4092-b9e8-c7649fa1faa6@l38g2000pro.googlegroups.com> Recently I found I had a a small amount of websites I had basically abandoned, Mostly as the products had befall with a reduction of desirable and were Veto longer worth the effort of promoting. I unfaltering more exactly than Accede to the sites simply sit in attendance price me hosting money - I Be supposed to try to optimize the sites in support of Google AdSense and see to it that if I Might promote to a few profits from the sites next to all. visit http://www.adsensesubstitutes.com/adSense-tutorial.htm From python at mrabarnett.plus.com Fri Sep 3 22:46:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Sep 2010 03:46:08 +0100 Subject: Queue cleanup In-Reply-To: <7xbp8el03t.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> <7xbp8el03t.fsf@ruckus.brouhaha.com> Message-ID: <4C81B2F0.8070807@mrabarnett.plus.com> On 04/09/2010 03:21, Paul Rubin wrote: > Lawrence D'Oliveiro writes: >>> Java has considerably greater reputation for reliability than C or C++. >> >> Wonder why Sun?s licence explicitly forbade its use in danger-critical >> areas like nuclear power plants and the like, then? > > Probably because Sun lawyers demanded it. Is there a Sun C or C++ > compiler with a license that doesn't have that restriction? Even if > there is, it just means those languages are so unreliable that the > lawyers felt confident that any meltdown could be blamed on a bug in the > user's rather than the compiler ;-). > >> Let?s put it this way: the life-support system on the International Space >> Station is written in Ada. Would you trust your life to code written in >> Java? > > The scary thing is I don't know whether I'm already doing that. Life > support systems have hard real-time requirements (Ada's forte) but I'd > expect lots of military decision-support systems are written in Java. > Maybe one of them will raise a false alert and somebody will launch a > war. I thought it was just that if it wasn't explicitly forbidden then someone might try to use it and then sue if something went wrong, even though common sense would have said that it was a bad idea in the first place! :-) From no.email at nospam.invalid Fri Sep 3 22:59:17 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 03 Sep 2010 19:59:17 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> Message-ID: <7x7hj2kyd6.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: >> GC's for large systems generally don't free (or even examine) individual >> garbage objects. They copy the live objects to a new contiguous heap >> without ever touching the garbage, and then they release the old heap. > > And suddenly you?ve doubled the memory requirements. And on top of that, > since you?re moving the valid objects into different memory, you?re forcing > cache misses on all of them as well. A minimal naive implementation indeed doubles the memory requirements, but from a Python perspective where every integer takes something like 24 bytes already, even that doesn't seem so terrible. More sophisticated implementations use multiple small heaps or other tricks. It still costs something in memory footprint, but less than the minimal implementation's 2x cost. The new heap is filled sequentially so accesses to it will have good locality. You do have to jump around within the old heap, but again, with generational schemes, in the more frequent collections, the old heap fits entirely in cache. For example, GHC's minor heap size is 256kB. For major collections, GHC switches (or used to) from copying to a mark/compact scheme once the amount of live data in the heap goes over some amount, giving the best of both worlds. It's also the case that programs with very large memory consumption tend to use most of the memory for large arrays that don't contain pointers (think of a database server with a huge cache). That means the gc doesn't really have to think about all that much of the memory. > This is the continuing problem with garbage collection: all the attempts to > make it cheaper just end up moving the costs somewhere else. Same thing with manual allocation. That moves the costs off the computer and onto the programmer. Not good, most of the time. Really, I'm no gc expert, but the stuff you're saying about gc is quite ill-informed. You might want to check out some current literature. From nad at acm.org Fri Sep 3 23:19:09 2010 From: nad at acm.org (Ned Deily) Date: Fri, 03 Sep 2010 20:19:09 -0700 Subject: IDLE / Black frame on Mac References: <3677b256-0eab-4912-b87b-d7327341fd36@x20g2000pro.googlegroups.com> Message-ID: In article , Kristoffer Follesdal wrote: > *Forgot to tell that I am using a Mac with Snow Leopard. Which version of Python 3.1.2? From the python.org installer? MacPorts? Built from source - if so, which version of Tk? -- Ned Deily, nad at acm.org From trent at snakebite.org Sat Sep 4 02:21:42 2010 From: trent at snakebite.org (Trent Nelson) Date: Sat, 4 Sep 2010 02:21:42 -0400 Subject: Financial time series data In-Reply-To: <4C80DC11.50504@it.uu.se> References: <4C80DC11.50504@it.uu.se> Message-ID: <4C81E576.8080803@snakebite.org> On 03-Sep-10 7:29 AM, Virgil Stokes wrote: > A more direct question on accessing stock information from Yahoo. > > First, use your browser to go to: > http://finance.yahoo.com/q/cp?s=%5EGSPC+Components > > Now, you see the first 50 rows of a 500 row table of information on S&P > 500 index. You can LM click on > > 1 -50 of 500 |First|Previous|Next|Last > > below the table to position to any of the 10 pages. > > I would like to use Python to do the following. > > *Loop on each of the 10 pages and for each page extract information for > each row --- How can this be accomplished automatically in Python?* > > Let's take the first page (as shown by default). It is easy to see the > link to the data for "A" is http://finance.yahoo.com/q?s=A. That is, I > can just move > my cursor over the "A" and I see this URL in the message at the bottom > of my browser (Explorer 8). If I LM click on "A" then I will go to this > link --- Do this! > > You should now see a table which shows information on this stock and > *this is the information that I would like to extract*. I would like to > do this for all 500 stocks without the need to enter the symbols for > them (e.g. "A", "AA", etc.). It seems clear that this should be possible > since all the symbols are in the first column of each of the 50 tables > --- but it is not at all clear how to extract these automatically in > Python. > > Hopefully, you understand my problem. Again, I would like Python to > cycle through these 10 pages and extract this information for each > symbol in this table. > > --V You want the 'get_historical_prices' method of the (beautifully elegant) 'ystockquote.py': http://www.goldb.org/ystockquote.html. Just specify start date and end date and wallah, you get an array of historical price data for any symbol you pass in. I used this module with great success to download ten years of historical data for every symbol I've ever traded. Regards, Trent. From trent at snakebite.org Sat Sep 4 02:24:11 2010 From: trent at snakebite.org (Trent Nelson) Date: Sat, 4 Sep 2010 02:24:11 -0400 Subject: Financial time series data In-Reply-To: <1283536093.2894.12.camel@hatchbox-one> References: <4C80DC11.50504@it.uu.se> <1283521536.2364.139.camel@hatchbox-one> <4C810AA1.7060700@it.uu.se> <1283536093.2894.12.camel@hatchbox-one> Message-ID: <4C81E60B.9090900@snakebite.org> On 03-Sep-10 1:48 PM, Frederic Rentsch wrote: > And do let us know if you get an answer from Yahoo. Hacks like this > are unreliable. They fail almost certainly the next time a page gets > redesigned, which can be any time. Indeed -- see my other post (regarding ystockquote.py). There's a CSV HTTP API that should be used if you want to obtain any Yahoo! Finance data programmatically. Trent. From no.email at nospam.invalid Sat Sep 4 04:50:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Sep 2010 01:50:07 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> Message-ID: <7xeid9dha8.fsf@ruckus.brouhaha.com> Dennis Lee Bieber writes: > Not to mention having to ensure that one finds ALL the references to > the object so that they can be updated to the new address! Somehow I > don't see a C compiler being smart enough to find intermediary pointer We're not talking about C compilers, which can cast any value at all into pointers. Languages designed for garbage collection are normally type-safe and gc is a well-understood problem, though (like compilers) the higher-performing ones are complicated. But, nothing in principle stops anyone from implementing Python with such methods. From anthra.norell at bluewin.ch Sat Sep 4 05:14:24 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Sat, 04 Sep 2010 11:14:24 +0200 Subject: Financial time series data In-Reply-To: <4C813761.8020500@it.uu.se> References: <4C813761.8020500@it.uu.se> Message-ID: <1283591664.2345.27.camel@hatchbox-one> On Fri, 2010-09-03 at 19:58 +0200, Virgil Stokes wrote: > import urllib2 > import re > > def get_SP500_symbolsX (): > symbols = [] > lsttradestr = re.compile('Last Trade:') > k = 0 > for page in range(10): > url = 'http://finance.yahoo.com/q/cp?s=%5EGSPC&c='+str(page) > print url > f = urllib2.urlopen (url) > html = f.readlines () > f.close () > for line in html: > if line.lstrip ().startswith (' line_split = line.split (':') > s = [item.strip ().upper () for item in line_split [5].replace > ('"','').split (',')] > for symb in s: > url = "http://finance.yahoo.com/q?s="+symb > f = urllib2.urlopen(url) > html = f.readlines() > f.close() > > for line in html: > if lsttradestr.search(line): > k += 1 > print 'k = %3d (%s)' %(k,symb) > # Here is where I will extract the numerical values and place > # .... > # them in an approrpriate file > symbols.extend (s [:-3]) > > return symbols > # Not quite 500 -- which is correct (for example p. 2 has only 49 symbols!) > # Actually the S&P 500 as shown does not contain 500 stocks (symbols) > > > symbols = get_SP500_symbolsX() > pass > > And thanks for your help Frederic --- Have a good day! :-) > > --V Good going! You get the idea. Here's my try for a cleaned-up version that makes the best use of the facility and takes only fifteen seconds to complete (on my machine). You may want to look at historical quotes too. Trent Nelson seems to have a ready-made solution for this. --------------------------- import urllib2 import re def get_current_SP500_quotes_from_Yahoo (): symbol_reader = re.compile ('([a-z-.]+,)+[a-z-.]+') # Make sure you include all characters that may show up in symbols, csv_data = '' for page in range (10): url = 'http://finance.yahoo.com/q/cp?s=%5EGSPC&c=' + str (page) print url f = urllib2.urlopen (url) html = f.readlines () f.close () for line in html: if line.lstrip ().startswith (' Message-ID: <689931a1-1c49-478d-bacf-3f42f4dd42b9@13g2000prf.googlegroups.com> I write some object for Taiwan Stock ... http://github.com/toomore/goristock But still dev ... On Sep 3, 1:12?am, Virgil Stokes wrote: > ? Has anyone written code or worked with Python software for downloading > financial time series data (e.g. from Yahoo financial)? If yes, ?would you > please contact me. > > --Thanks, > V. Stokes From kkf628 at gmail.com Sat Sep 4 05:26:18 2010 From: kkf628 at gmail.com (=?ISO-8859-1?Q?Kristoffer_F=F8llesdal?=) Date: Sat, 4 Sep 2010 02:26:18 -0700 (PDT) Subject: IDLE / Black frame on Mac References: <3677b256-0eab-4912-b87b-d7327341fd36@x20g2000pro.googlegroups.com> Message-ID: <2d0cc097-4064-47e2-a609-f1c9f9f13ee2@l20g2000yqm.googlegroups.com> On Sep 4, 5:19?am, Ned Deily wrote: > In article > , > ?Kristoffer Follesdal wrote: > > > *Forgot to tell that I am using a Mac with Snow Leopard. > > Which version of Python 3.1.2? ?From the python.org installer? ? > MacPorts? ?Built from source - if so, which version of Tk? > > -- > ?Ned Deily, > ?n... at acm.org I used the installer from python.org. Tk version 8.4. From mohammad.rahmani at gmail.com Sat Sep 4 07:25:18 2010 From: mohammad.rahmani at gmail.com (atronoush) Date: Sat, 4 Sep 2010 04:25:18 -0700 (PDT) Subject: pyla: python little algorithms Message-ID: <0c7993e3-f115-440b-97d8-3db39b6bf6f9@x25g2000yqj.googlegroups.com> Dear all, pyla stands for Python Little Algorithm is a project in pure Python and includes simple, easy to use, yet powerful libraries for - 2D/3D plotting using Gnuplot - Matrix/Vector operations - ODE solvers - Optimization and nonlinear algebraic equation solvers - ... Homepage: pyla home is: http://pyla.codeplex.com pyla documentation is on Tiddlywiki (www.tiddlywiki.org) a lightweight and portable wiki. Current Status: Currently the gplot library with status alpha has been released, other libraries is planned to be released bi-monthly. Contribution: We welcome all kind of contribution to this project. pyla is free, and open source.. All the best Mohammad Rahmani Chem Eng Dep Amirkabir Uni of Tech From aahz at pythoncraft.com Sat Sep 4 08:26:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Sep 2010 05:26:16 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> <7x7hj2kyd6.fsf@ruckus.brouhaha.com> Message-ID: [gc] In article <7x7hj2kyd6.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > >A minimal naive implementation indeed doubles the memory requirements, >but from a Python perspective where every integer takes something like >24 bytes already, even that doesn't seem so terrible. Many people still use 32-bit Python -- an int is twelve bytes there. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From aahz at pythoncraft.com Sat Sep 4 09:10:32 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Sep 2010 06:10:32 -0700 Subject: String substitution VS proper mysql escaping References: <4C6BA2C4.4000309@gmail.com> Message-ID: In article , =?UTF-8?B?zp3Or866zr/Pgg==?= wrote: > >After all () used to define tuples and [] usedd to define lists. Why >commas? No, "()" does *not* define tuples, except for the empty tuple. The comma defines tuples, with parentheses simply used for visual effect: >>> 1, 2, 3 (1, 2, 3) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From whatsjacksemail at gmail.com Sat Sep 4 09:36:38 2010 From: whatsjacksemail at gmail.com (Jack Keegan) Date: Sat, 4 Sep 2010 14:36:38 +0100 Subject: State Machines in Python Message-ID: Hi girls & guys, Just joined the group. I'm new to Python but been picking it up pretty easy. I love it! I'm hoping to use it to make a controlling application for an experiment. Basically I want to use it to interface with some data acquisition (DAQ) hardware to accept incoming signals and respond sending signals to the outputs. I'm looking for an efficient State Machine algorithm as I need the timing to be as good as possible. As there is no switch statement in Python, I've been looking around for a good implementation. Most of the algorithms I've come across seem to be based on parsing applications. I'd like something more suited to my needs. I'd like to avoid excessive use of 'if-elif-else' statements as each would have to be checked to find the right conditions which would have an time overhead involved. I have seen an implementation of the switch using dictionaries but someone had commented that creating and throwing away dictionaries also comes at a cost. I was wondering if any of you could advise or point me in the right direction. Any help would be greatly appreciated. Thanks, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Sat Sep 4 09:49:53 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Sep 2010 09:49:53 -0400 Subject: State Machines in Python In-Reply-To: References: Message-ID: <20100904094953.a084b648.darcy@druid.net> On Sat, 4 Sep 2010 14:36:38 +0100 Jack Keegan wrote: > Just joined the group. I'm new to Python but been picking it up pretty easy. Welcome aboard. > As there is no switch statement in Python, I've been looking around for a > good implementation. Most of the algorithms I've come across seem to be There's no switch statement because there's no real need for one. Check out the following sample code and see if it gives you some ideas. #! /usr/bin/env python # -*- coding: utf-8 -*- # Sample state machine import sys data = dict(counter = 0, flag = False) def state1(d): d['counter'] += 1 print "In state 1, counter = %(counter)d" % d if d['flag']: sys.exit(0) return state2 def state2(d): d['counter'] += 1 print "In state 2, counter = %(counter)d" % d return state3 def state3(d): d['counter'] += 1 d['flag'] = True print "In state 3, counter = %(counter)d" % d return state1 state = state1 while True: state = state(data) -- 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 stefan_ml at behnel.de Sat Sep 4 10:41:46 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Sep 2010 16:41:46 +0200 Subject: State Machines in Python In-Reply-To: References: Message-ID: Jack Keegan, 04.09.2010 15:36: > Hi girls& guys, > > Just joined the group. I'm new to Python but been picking it up pretty easy. > I love it! Welcome to the group. > I'm hoping to use it to make a controlling application for an > experiment. Basically I want to use it to interface with some data > acquisition (DAQ) hardware to accept incoming signals and respond sending > signals to the outputs. I'm looking for an efficient State Machine algorithm > as I need the timing to be as good as possible. > As there is no switch statement in Python, I've been looking around for a > good implementation. Most of the algorithms I've come across seem to be > based on parsing applications. I'd like something more suited to my needs. > I'd like to avoid excessive use of 'if-elif-else' statements as each would > have to be checked to find the right conditions which would have an time > overhead involved. I have seen an implementation of the switch using > dictionaries but someone had commented that creating and throwing away > dictionaries also comes at a cost. > I was wondering if any of you could advise or point me in the right > direction. Dictionaries are a common way to do it, and there are different recipes. A second way is a class that dispatches to its methods. A third (IMHO rather beautiful) way is coroutines: http://gnosis.cx/publish/programming/charming_python_b5.html http://www.dabeaz.com/coroutines/Coroutines.pdf However, you'll have to do some benchmarking if you care about performance. Dictionaries are fast and likely the fastest way to do it, but coroutines are a lot more versatile. Stackless Python might also be worth a look in this context, it's fast *and* versatile. You should also be aware that there are various event driven frameworks (like Twisted, eventlet and others) that make asynchronous event handling fast and easy, and that use much higher-level abstractions than pure state machines. Stefan From stef.mientki at gmail.com Sat Sep 4 12:26:17 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 04 Sep 2010 18:26:17 +0200 Subject: State Machines in Python In-Reply-To: References: Message-ID: <4C827329.4050706@gmail.com> On 04-09-2010 15:36, Jack Keegan wrote: > Hi girls & guys, > > Just joined the group. I'm new to Python but been picking it up pretty easy. I love it! I'm hoping > to use it to make a controlling application for an experiment. Basically I want to use it to > interface with some data acquisition (DAQ) hardware to accept incoming signals and respond sending > signals to the outputs. I'm looking for an efficient State Machine algorithm as I need the timing > to be as good as possible. What is as good as possible, 1 usec, 1 msec ? What operating system are you using ? Are you planning feedback ? For a comparison, I did a few years ago sampling in Python, with NI cards (they ensure time accuracy which can never be achieved in software), 50 kHz (divided over 1 to 8 channels), 32 bit, storage and graphical display, and processor activity was about 10%. Maybe you should also look at what those radio guys from gnu radio achive. cheers, Stef > As there is no switch statement in Python, I've been looking around for a good implementation. > Most of the algorithms I've come across seem to be based on parsing applications. I'd like > something more suited to my needs. I'd like to avoid excessive use of 'if-elif-else' statements as > each would have to be checked to find the right conditions which would have an time overhead > involved. I have seen an implementation of the switch using dictionaries but someone had commented > that creating and throwing away dictionaries also comes at a cost. > I was wondering if any of you could advise or point me in the right direction. > > Any help would be greatly appreciated. > > Thanks, > > Jack From martin at v.loewis.de Sat Sep 4 12:51:29 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 04 Sep 2010 18:51:29 +0200 Subject: Installation problem: Python 2.6.6 (32-Bit) on Windows 7 (32-Bit) In-Reply-To: <0781783a-b182-455f-8522-ed5a37db6e14@o7g2000prg.googlegroups.com> References: <0781783a-b182-455f-8522-ed5a37db6e14@o7g2000prg.googlegroups.com> Message-ID: <4C827911.1020705@v.loewis.de> Am 01.09.2010 21:18, schrieb Cappy2112: > Has anyone else had problems running the msi for Python 2.6.6 on > Windows 7 Professional? I specifically tested whether "compile .py" works before the release, and it worked fine on my machine. I suspect you have a source file on your disk that it tries to compile and it won't, because of a syntax error. Regards, Martin From martin at v.loewis.de Sat Sep 4 12:52:15 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 04 Sep 2010 18:52:15 +0200 Subject: what is this kind of string: b'string' ? In-Reply-To: References: Message-ID: <4C82793F.4040704@v.loewis.de> Am 01.09.2010 23:32, schrieb Stef Mientki: > in winpdb I see strings like this: > >>>> a = b'string' >>>> a > 'string' >>>> type(a) > > > what's the "b" doing in front of the string ? It's redundant. Regards, Martin From stefan_ml at behnel.de Sat Sep 4 13:27:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Sep 2010 19:27:34 +0200 Subject: what is this kind of string: b'string' ? In-Reply-To: <4C82793F.4040704@v.loewis.de> References: <4C82793F.4040704@v.loewis.de> Message-ID: Martin v. Loewis, 04.09.2010 18:52: > Am 01.09.2010 23:32, schrieb Stef Mientki: >> in winpdb I see strings like this: >> >> >>> a = b'string' >> >>> a >> 'string' >> >>> type(a) >> >> >> what's the "b" doing in front of the string ? > > It's redundant. Not completely. (I know that you know this, but to those who don't, your answer may be misleading.) If you use 2to3 to convert the above to Python 3 code, it will leave the 'b' in front of the string, so the resulting string literal will be a bytes string in Python 3. If you remove it, the string will become a unicode literal. Since the code is syntax compatible with Python 3, simply running it in a Python 3 interpreter will also show this behaviour. So it's redundant in Python 2, but it's no longer redundant when you plan to migrate the code to Python 3. Stefan From martin at v.loewis.de Sat Sep 4 13:35:24 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 04 Sep 2010 19:35:24 +0200 Subject: what is this kind of string: b'string' ? In-Reply-To: References: <4C82793F.4040704@v.loewis.de> Message-ID: <4C82835C.70008@v.loewis.de> Am 04.09.2010 19:27, schrieb Stefan Behnel: > Martin v. Loewis, 04.09.2010 18:52: >> Am 01.09.2010 23:32, schrieb Stef Mientki: >>> in winpdb I see strings like this: >>> >>> >>> a = b'string' >>> >>> a >>> 'string' >>> >>> type(a) >>> >>> >>> what's the "b" doing in front of the string ? >> >> It's redundant. > > Not completely. (I know that you know this, but to those who don't, your > answer may be misleading.) Actually, I didn't think of this (knowing something and being aware of it are different things ...) I personally don't use it in the 2to3 way, because it requires Python 2.6. For code that needs to go back further, I typically do b('string') with a custom b() function. That's less efficient, of course, since it causes a function call on evaluation. Thanks, Martin From roy at panix.com Sat Sep 4 13:58:00 2010 From: roy at panix.com (Roy Smith) Date: Sat, 04 Sep 2010 13:58:00 -0400 Subject: State Machines in Python References: Message-ID: In article , "D'Arcy J.M. Cain" wrote: > On Sat, 4 Sep 2010 14:36:38 +0100 > Jack Keegan wrote: > > Just joined the group. I'm new to Python but been picking it up pretty easy. > > Welcome aboard. > > > As there is no switch statement in Python, I've been looking around for a > > good implementation. Most of the algorithms I've come across seem to be > > There's no switch statement because there's no real need for one. > Check out the following sample code and see if it gives you some ideas. > > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > # Sample state machine > > import sys > > data = dict(counter = 0, flag = False) > > def state1(d): > d['counter'] += 1 > print "In state 1, counter = %(counter)d" % d > if d['flag']: sys.exit(0) > return state2 > > def state2(d): > d['counter'] += 1 > print "In state 2, counter = %(counter)d" % d > return state3 > > def state3(d): > d['counter'] += 1 > d['flag'] = True > print "In state 3, counter = %(counter)d" % d > return state1 > > state = state1 > while True: > state = state(data) This is the pattern I've always used. Simple and effective for any state machine which is small enough to code by hand. I generally have my state methods return (next_state, output) tuples, but that's a detail. From python at mrabarnett.plus.com Sat Sep 4 14:13:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Sep 2010 19:13:28 +0100 Subject: State Machines in Python In-Reply-To: References: Message-ID: <4C828C48.8050404@mrabarnett.plus.com> On 04/09/2010 18:58, Roy Smith wrote: > In article, > "D'Arcy J.M. Cain" wrote: > >> On Sat, 4 Sep 2010 14:36:38 +0100 >> Jack Keegan wrote: >>> Just joined the group. I'm new to Python but been picking it up pretty easy. >> >> Welcome aboard. >> >>> As there is no switch statement in Python, I've been looking around for a >>> good implementation. Most of the algorithms I've come across seem to be >> >> There's no switch statement because there's no real need for one. >> Check out the following sample code and see if it gives you some ideas. >> >> #! /usr/bin/env python >> # -*- coding: utf-8 -*- >> >> # Sample state machine >> >> import sys >> >> data = dict(counter = 0, flag = False) >> >> def state1(d): >> d['counter'] += 1 >> print "In state 1, counter = %(counter)d" % d >> if d['flag']: sys.exit(0) >> return state2 >> >> def state2(d): >> d['counter'] += 1 >> print "In state 2, counter = %(counter)d" % d >> return state3 >> >> def state3(d): >> d['counter'] += 1 >> d['flag'] = True >> print "In state 3, counter = %(counter)d" % d >> return state1 >> >> state = state1 >> while True: >> state = state(data) > > This is the pattern I've always used. Simple and effective for any > state machine which is small enough to code by hand. I generally have > my state methods return (next_state, output) tuples, but that's a detail. I suppose that if they are that similar then you could generate the code from a list or table of the states. From pramo4d at gmail.com Sat Sep 4 14:28:06 2010 From: pramo4d at gmail.com (Pramod) Date: Sat, 4 Sep 2010 11:28:06 -0700 (PDT) Subject: Error in Following python program Message-ID: <53ebbc6c-5624-4d74-9fa2-007895a8787e@m17g2000prl.googlegroups.com> #/usr/bin/python from numpy import matrix n=input('Enter matrix range') fr=open('mat.txt','r') print ('Enter elements into the matrix\n') a=matrix([[input()for j in range(n)] for i in range(n)]) for i in range(n): for j in range(n): print a[i][j] print '\n' When i run the above program the following error is Coming please Error is Enter matrix range3 Enter elements into the matrix 1 2 3 4 5 6 7 8 9 [[1 2 3]] Traceback (most recent call last): File "2.py", line 10, in print a[i][j] File "/usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py", line 265, in __getitem__ out = N.ndarray.__getitem__ please resolve my problem Thanks in advance ~ From darcy at druid.net Sat Sep 4 14:30:22 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Sep 2010 14:30:22 -0400 Subject: State Machines in Python In-Reply-To: References: Message-ID: <20100904143022.a8e855c0.darcy@druid.net> On Sat, 04 Sep 2010 13:58:00 -0400 Roy Smith wrote: > > while True: > > state = state(data) > > This is the pattern I've always used. Simple and effective for any > state machine which is small enough to code by hand. I generally have > my state methods return (next_state, output) tuples, but that's a detail. What is "output" for? Is it a string or something else? What do you do with it? Notice that I create a dictionary which is passed around so that states can pass whatever information back that they deem useful and any state can pick up whatever info it needs. for example, in my sample code every state uses the counter but only two states use the flag element. -- 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 Sat Sep 4 14:32:02 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Sep 2010 14:32:02 -0400 Subject: State Machines in Python In-Reply-To: <4C828C48.8050404@mrabarnett.plus.com> References: <4C828C48.8050404@mrabarnett.plus.com> Message-ID: <20100904143202.82382f0e.darcy@druid.net> On Sat, 04 Sep 2010 19:13:28 +0100 MRAB wrote: > I suppose that if they are that similar then you could generate the > code from a list or table of the states. They generally aren't as simple as the little example script that I cobbled together. -- 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 mrabarnett.plus.com Sat Sep 4 14:46:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Sep 2010 19:46:23 +0100 Subject: Error in Following python program In-Reply-To: <53ebbc6c-5624-4d74-9fa2-007895a8787e@m17g2000prl.googlegroups.com> References: <53ebbc6c-5624-4d74-9fa2-007895a8787e@m17g2000prl.googlegroups.com> Message-ID: <4C8293FF.7030300@mrabarnett.plus.com> On 04/09/2010 19:28, Pramod wrote: > #/usr/bin/python > from numpy import matrix > n=input('Enter matrix range') > fr=open('mat.txt','r') > print ('Enter elements into the matrix\n') > a=matrix([[input()for j in range(n)] for i in range(n)]) > for i in range(n): > for j in range(n): > print a[i][j] > print '\n' > > When i run the above program the following error is Coming please > Error is > Enter matrix range3 > Enter elements into the matrix > > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > [[1 2 3]] > Traceback (most recent call last): > File "2.py", line 10, in > print a[i][j] > File "/usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py", > line 265, in __getitem__ > out = N.ndarray.__getitem__ > > please resolve my problem Thanks in advance > ~ The matrix is 2-dimensional, which in numpy is means you need to write: a[i, i] not: a[i][j] and no, they're not the same! :-) From stefan_ml at behnel.de Sat Sep 4 14:46:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Sep 2010 20:46:54 +0200 Subject: State Machines in Python In-Reply-To: <20100904143022.a8e855c0.darcy@druid.net> References: <20100904143022.a8e855c0.darcy@druid.net> Message-ID: D'Arcy J.M. Cain, 04.09.2010 20:30: > On Sat, 04 Sep 2010 13:58:00 -0400 > Roy Smith wrote: >>> while True: >>> state = state(data) >> >> This is the pattern I've always used. Simple and effective for any >> state machine which is small enough to code by hand. I generally have >> my state methods return (next_state, output) tuples, but that's a detail. > > What is "output" for? Is it a string or something else? What do you > do with it? Notice that I create a dictionary which is passed around > so that states can pass whatever information back that they deem useful > and any state can pick up whatever info it needs. for example, in my > sample code every state uses the counter but only two states use the > flag element. I guess the idea is that each of the states can't arbitrarily modify the global status (dict) but is restricted to designating a next state and returning something. So you don't take the risk of introducing side effects somewhere because all state implementations are pure functions (at least as far as the state machine itself is concerned). Stefan From __peter__ at web.de Sat Sep 4 14:49:58 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 04 Sep 2010 20:49:58 +0200 Subject: Error in Following python program References: <53ebbc6c-5624-4d74-9fa2-007895a8787e@m17g2000prl.googlegroups.com> Message-ID: Pramod wrote: > #/usr/bin/python > from numpy import matrix > n=input('Enter matrix range') > fr=open('mat.txt','r') > print ('Enter elements into the matrix\n') > a=matrix([[input()for j in range(n)] for i in range(n)]) > for i in range(n): > for j in range(n): > print a[i][j] > print '\n' > > When i run the above program the following error is Coming please > Error is > Enter matrix range3 > Enter elements into the matrix > > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > [[1 2 3]] > Traceback (most recent call last): > File "2.py", line 10, in > print a[i][j] > File "/usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py", > line 265, in __getitem__ > out = N.ndarray.__getitem__ > > please resolve my problem Thanks in advance You can either use an array instead of a matrix and continue to access the elements like you did in your code >>> a = numpy.array([[1,2],[3,4]]) >>> a[1][1] 4 or continue to use the matrix and access its elements with a tuple >>> b = numpy.matrix([[1,2],[3,4]]) >>> b[1,1] 4 If you pass only one index you get another, smaller matrix: >>> b[1] matrix([[3, 4]]) Once you see this printed it should be clear that b[1][1] asks for the non- existent second row of the above matrix. Hence the error: >>> b[1][1] Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py", line 265, in __getitem__ out = N.ndarray.__getitem__(self, index) IndexError: index out of bounds By the way, these matrices are really strange beasts: >>> b[0][0] matrix([[1, 2]]) >>> b[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0] matrix([[1, 2]]) Peter From roy at panix.com Sat Sep 4 15:45:17 2010 From: roy at panix.com (Roy Smith) Date: Sat, 04 Sep 2010 15:45:17 -0400 Subject: State Machines in Python References: Message-ID: In article , "D'Arcy J.M. Cain" wrote: > On Sat, 04 Sep 2010 13:58:00 -0400 > Roy Smith wrote: > > > while True: > > > state = state(data) > > > > This is the pattern I've always used. Simple and effective for any > > state machine which is small enough to code by hand. I generally have > > my state methods return (next_state, output) tuples, but that's a detail. > > What is "output" for? Is it a string or something else? I've often used this pattern for parsing a text file and extracting interesting data. At various points during the input stream, you will have read an entire piece of data, and return it as the output of the state machine. Not every state will result in output being produced. As a trivial example, let's say I had a file format which stored network addresses in a deliberately silly style: -------------------- # This is a comment host = 10.2.3.4 port = 999 proto = TCP port = 1001 proto = TCP host = 192.168.1.1 status = ignore host = 1.2.3.4 port = 22 host = 127.0.0.1 proto = UDP port = 1001 host = 192.168.1.1 -------------------- I want to parse out (host, port, proto) triples, i.e. the state machine should produce the following output: (10.2.3.4, 9099, TCP) (192.168.1.1, 1001, TCP) (192.168.1.1, 1001, UDP) As the end of each data block is recognized, a 3-tuple would be returned. Other state transitions would return None as the output. Then, the main loop can be something like: state = start for line in input: next_state, output = state(line) if output: print output state = next_state I'm not saying it has to be done that way, just that I've found it a handy pattern for the stuff I've done. From no.email at nospam.invalid Sat Sep 4 16:02:37 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Sep 2010 13:02:37 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> Message-ID: <7xeid9gtuq.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > That reinforces my point, about how easy it was to check the correctness of > the code. In this case one simple fix, like this ... > would render the code watertight. See how easy it is? Well, no, it's irrelevant how easy it is to fix the issue after it's pointed out. What matters is how easy it was to create it in the first place. You posted a 30-line code sample as obviously free of memory leaks, but even a good programmer like you didn't notice that it had the potential for a nasty memory overwrite error after an unbalanced decref. Keep in mind that a memory leak usually just means the program can eventually bog down and stops working, but an overwrite error is often a security hole that can lead to total compromise of your entire computer. Now extrapolate that error rate from 30 lines to a program the size of Firefox (something like 5 MLOC), and you should see how fraught with danger that style of programming is. Even the most skilled and careful programmers are going to slip up once in a while. Part of the problem is C itself. No language can eliminate many complicated bugs without creating severe usability problems, but good languages (unlike C) can eliminate most "silly" bugs. I had a "dark night of the soul" after reading some of the bug-finding papers at http://www.stanford.edu/~engler/ and have been terrified of C ever since. I'm just always skeptical when anyone says they're sure any piece of C code is obviously bug-free. It's quite easy to get overconfident about it (as I've done myself more than once). I spent about 5 minutes reviewing your patched code (and the underlying implementations of the C API functions it calls) and didn't see any other issues, and the code is probably ok now, but I'd have to spend a lot more time tracing through the API layer before I could be really sure. Anyway, you should check your patch into github if you haven't. From nagle at animats.com Sat Sep 4 16:48:27 2010 From: nagle at animats.com (John Nagle) Date: Sat, 04 Sep 2010 13:48:27 -0700 Subject: Queue cleanup In-Reply-To: References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> Message-ID: <4c82b097$0$1661$742ec2ed@news.sonic.net> On 8/28/2010 5:42 AM, Aahz wrote: > In article<4c78572c$0$28655$c3e8da3 at news.astraweb.com>, > Steven D'Aprano wrote: >> On Fri, 27 Aug 2010 09:16:52 -0700, Aahz wrote: >>> In article, MRAB >>> wrote: >>>> >>>> An object will be available for garbage collection when nothing refers >>>> to it either directly or indirectly. If it's unreferenced then it will >>>> go away. >>> >>> This isn't actually garbage collection as most people think of it. >>> Refcounting semantics mean that objects get reaped as soon as nothing >>> points at them. OTOH, CPython does also have garbage collection to back >>> up refcounting so that when you have unreferenced object cycles they >>> don't stay around. >> >> I've repeatedly asked, both here and elsewhere, why reference counting >> isn't "real" garbage collection. Nobody has been able to give me a >> satisfactory answer. As far as I can tell, it's a bit of pretentiousness >> with no basis in objective fact. > > You'll notice that I was very careful to qualify my statement with "as > most people think of it". Also, because CPython has two different memory > management mechanisms, refcounting and cycle detection, and the module > that controls cycle detection is called "gc", I think it's simpler to > follow along with the Python docs -- and critically important to remind > people that there are in fact two different systems. Personally, I'd like to have reference counting only, an enforced prohibition on loops (backpointers must be weak pointers), RAII, and reliably ordered finalization. A big advantage of reference counting is that finalization happens in the thread that releases the object, and in the correct order. GC and finalization/destructors do not play well together at all. Microsoft once tried to get the hard cases to work right. See "managed C++". Not a happy story. John Nagle From noagbodjivictor at gmail.com Sat Sep 4 17:22:39 2010 From: noagbodjivictor at gmail.com (nvictor) Date: Sat, 4 Sep 2010 14:22:39 -0700 (PDT) Subject: the script is failing without a useful report Message-ID: <9f67347a-9419-49e5-93de-be3c214f4896@d8g2000yqf.googlegroups.com> hi all, need your help. i get a traceback that doesn't tell much about the actual error in my code: Traceback (most recent call last): File ".\eightqueens.py", line 32, in generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) here is the full source: def generate(n, x, col, up, down): for h in range(8): # place a queen if col[h] and up[n-h] and down[n+h]: x[n] = h col[h] = False up[n-h] = False down[n+h] = False n += 1 # 8 queen placed? if n == 8: print x else: generate(n, x, col, up, down) # displace a queen n -= 1 col[h] = True up[n-h] = True down[n+h] = True if __name__ == '__main__': n = 0 x = [None]*8 col = [True]*8 up = [True]*15 down = [True]*15 generate(n, x, col, up, down) thanks a lot in advance From python at mrabarnett.plus.com Sat Sep 4 18:22:01 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Sep 2010 23:22:01 +0100 Subject: the script is failing without a useful report In-Reply-To: <9f67347a-9419-49e5-93de-be3c214f4896@d8g2000yqf.googlegroups.com> References: <9f67347a-9419-49e5-93de-be3c214f4896@d8g2000yqf.googlegroups.com> Message-ID: <4C82C689.7080508@mrabarnett.plus.com> On 04/09/2010 22:22, nvictor wrote: > hi all, > > need your help. i get a traceback that doesn't tell much about the > actual error in my code: > > Traceback (most recent call last): > File ".\eightqueens.py", line 32, in > generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > > here is the full source: > > def generate(n, x, col, up, down): > for h in range(8): > # place a queen > if col[h] and up[n-h] and down[n+h]: > x[n] = h > col[h] = False > up[n-h] = False > down[n+h] = False > n += 1 > > # 8 queen placed? > if n == 8: print x > else: generate(n, x, col, up, down) > > # displace a queen > n -= 1 > col[h] = True > up[n-h] = True > down[n+h] = True > > > if __name__ == '__main__': > n = 0 > x = [None]*8 > col = [True]*8 > up = [True]*15 > down = [True]*15 > generate(n, x, col, up, down) > The traceback ends with: RuntimeError: maximum recursion depth exceeded I think what's happening is that if the 'if' condition just after the "# place a queen" comment is false then 'n' won't be incremented, and therefore 'generate' will call itself with the exactly same values which were passed in, resulting in infinite recursion (or at least until the limit is reached). From noagbodjivictor at gmail.com Sat Sep 4 18:28:13 2010 From: noagbodjivictor at gmail.com (nvictor) Date: Sat, 4 Sep 2010 15:28:13 -0700 (PDT) Subject: the script is failing without a useful report References: <9f67347a-9419-49e5-93de-be3c214f4896@d8g2000yqf.googlegroups.com> Message-ID: <79d6c5f9-86f8-4849-84b9-f2eaef8484b8@k10g2000yqa.googlegroups.com> thank you so much. From gabriele.lanaro at gmail.com Sat Sep 4 18:54:14 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Sun, 5 Sep 2010 00:54:14 +0200 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: Maybe for the simple sum you can just use the sum builtin: python -m timeit -s 'sum((10,)*10000)' 10000000 loops, best of 3: 0.0985 usec per loop About the loop in general it's a good practice to use list comprehension and generator expressions 2010/9/2 Michael Kreim > Hi, > > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > > $ cat addition.m > imax = 1e9; > a = 0; > for i=0:imax-1 > a = a + 10; > end > disp(a); > exit; > > The results look like this: > $ /usr/bin/time --verbose python addition.py > 10000000000 > Command being timed: "python addition.py" > User time (seconds): 107.30 > System time (seconds): 0.08 > Percent of CPU this job got: 97% > Elapsed (wall clock) time (h:mm:ss or m:ss): 1:50.09 > [...] > > $ /usr/bin/time --verbose matlab -nodesktop -nosplash -r "addition" > [...] > 1.0000e+10 > Command being timed: "matlab -nodesktop -nosplash -r addition" > User time (seconds): 7.65 > System time (seconds): 0.18 > Percent of CPU this job got: 94% > Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.25 > [...] > > Unfortunately my Python Code was much slower and I do not understand why. > > Are there any ways to speed up the for/xrange loop? > Or do I have to live with the fact that Matlab beats Python in this > example? > > Thanks a lot for your answers. > > With best regards, > > Michael > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jrmy.lnrd at gmail.com Sat Sep 4 19:04:35 2010 From: jrmy.lnrd at gmail.com (genxtech) Date: Sat, 4 Sep 2010 16:04:35 -0700 (PDT) Subject: Question about Reading Files Message-ID: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Hello. I am still really new to python and I have a project where I am trying to use the data files from another program and write a new program with new user interface and all. My first step was to open one of the files in 'rb' mode and print the contents, but I am unfamiliar with the format. Here is what was printed to the terminal: b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$ \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc \x00\x00\x0c\x19\x00\x00' I am using Python 3.1 on a Fedora 13 box if that makes any difference. Any advise on how to decode the data would be greatly appreciated. From jrmy.lnrd at gmail.com Sat Sep 4 19:13:44 2010 From: jrmy.lnrd at gmail.com (genxtech) Date: Sat, 4 Sep 2010 16:13:44 -0700 (PDT) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: I forgot to mention that the output was the first 100 bytes of the output From mats.rauhala at gmail.com Sat Sep 4 19:23:02 2010 From: mats.rauhala at gmail.com (Mats Rauhala) Date: Sat, 4 Sep 2010 23:23:02 +0000 (UTC) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: On 2010-09-04, genxtech wrote: > Hello. I am still really new to python and I have a project where I > am trying to use the data files from another program and write a new > program with new user interface and all. My first step was to open > one of the files in 'rb' mode and print the contents, but I am > unfamiliar with the format. Here is what was printed to the terminal: > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > Any advise on how to decode the data would be greatly appreciated. It's difficult to elaborate with only that information. What you have done now is opened a file in read binary mode (r = read, b = binary) and then tried to print it. Python has escaped the data as hex (\x01) and is basically a hex dump of the data file. For decoding the data, you either need to somehow figure out the format of the data and then decode it accordingly. If you're on unix box the 'file' command might be of help. If you're not on a unix box, you could check out how the file command tries to find the type of the file. The man page for magic [1] could be of help. Also see list of magic numbers [2] [1] http://linux.die.net/man/5/magic [2] http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html From python at mrabarnett.plus.com Sat Sep 4 20:03:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Sep 2010 01:03:05 +0100 Subject: Question about Reading Files In-Reply-To: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: <4C82DE39.2020208@mrabarnett.plus.com> On 05/09/2010 00:04, genxtech wrote: > Hello. I am still really new to python and I have a project where I > am trying to use the data files from another program and write a new > program with new user interface and all. My first step was to open > one of the files in 'rb' mode and print the contents, but I am > unfamiliar with the format. Here is what was printed to the terminal: > > b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f > \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y > \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$ > \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n > \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc > \x00\x00\x0c\x19\x00\x00' > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > Any advise on how to decode the data would be greatly appreciated. I googled and found this: http://stackoverflow.com/questions/2754751/what-file-format-contents-starts-with-ures which suggests "Universal Resource Editor (URE) that comes with the OS/2 Toolkit". From jrmy.lnrd at gmail.com Sat Sep 4 20:07:01 2010 From: jrmy.lnrd at gmail.com (genxtech) Date: Sat, 4 Sep 2010 17:07:01 -0700 (PDT) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: On Sep 4, 7:23?pm, Mats Rauhala wrote: > On 2010-09-04, genxtech wrote: > > > Hello. ?I am still really new to python and I have a project where I > > am trying to use the data files from another program and write a new > > program with new user interface and all. ?My first step was to open > > one of the files in 'rb' mode and print the contents, but I am > > unfamiliar with the format. ?Here is what was printed to the terminal: > > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > > Any advise on how to decode the data would be greatly appreciated. > > It's difficult to elaborate with only that information. What you have > done now is opened a file in read binary mode (r = read, b = binary) and > then tried to print it. Python has escaped the data as hex (\x01) and is > basically a hex dump of the data file. > > For decoding the data, you either need to somehow figure out the format > of the data and then decode it accordingly. If you're on unix box the > 'file' command might be of help. > > If you're not on a unix box, you could check out how the file command > tries to find the type of the file. The man page for magic [1] could be > of help. Also see list of magic numbers [2] > > [1]http://linux.die.net/man/5/magic > [2]http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html I am using Fedora 13. When I run the file command the response is that it is a 'data' file. If there are any tips on how to programatically figure out the format, I would greatly appreciate it. From ldo at geek-central.gen.new_zealand Sat Sep 4 21:41:38 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 05 Sep 2010 13:41:38 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> <7xbp8el03t.fsf@ruckus.brouhaha.com> Message-ID: In message , MRAB wrote: > Lawrence D'Oliveiro writes: >> >> Wonder why Sun?s licence explicitly forbade its use in danger-critical >> areas like nuclear power plants and the like, then? > > I thought it was just that if it wasn't explicitly forbidden then > someone might try to use it and then sue if something went wrong, even > though common sense would have said that it was a bad idea in the first > place! :-) But you?ll notice that Free Software comes with no such restrictions. In fact, it is contrary to commonly-accepted Free Software guidelines to impose any sort of restrictions on areas of use. From ldo at geek-central.gen.new_zealand Sat Sep 4 21:44:06 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 05 Sep 2010 13:44:06 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> Message-ID: In message <4c82b097$0$1661$742ec2ed at news.sonic.net>, John Nagle wrote: > Personally, I'd like to have reference counting only, an enforced > prohibition on loops (backpointers must be weak pointers), RAII, > and reliably ordered finalization. Is there a cheap way of checking at runtime for circular structures? > A big advantage of reference counting is that finalization happens > in the thread that releases the object, and in the correct order. > GC and finalization/destructors do not play well together at all. > Microsoft once tried to get the hard cases to work right. See > "managed C++". Not a happy story. Thank you for that. Another arrow for my anti-GC quiver. :) From ldo at geek-central.gen.new_zealand Sat Sep 4 22:33:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 05 Sep 2010 14:33:03 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> <7x7hj2kyd6.fsf@ruckus.brouhaha.com> Message-ID: In message <7x7hj2kyd6.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: > >> In message <7xmxs2uez1.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >> >>> GC's for large systems generally don't free (or even examine) individual >>> garbage objects. They copy the live objects to a new contiguous heap >>> without ever touching the garbage, and then they release the old heap. >> >> And suddenly you?ve doubled the memory requirements. And on top of that, >> since you?re moving the valid objects into different memory, you?re >> forcing cache misses on all of them as well. > > A minimal naive implementation indeed doubles the memory requirements, > but from a Python perspective where every integer takes something like > 24 bytes already, even that doesn't seem so terrible. Doubling 24 is less terrible than doubling 4 or 8?? You?re kidding, right? > More sophisticated implementations use multiple small heaps or other > tricks. More and more complications to patch up the idea. At some point, you have to admit there is something fundamentally flawed about the whole concept. > The new heap is filled sequentially so accesses to it will have good > locality. Unfortunately, that?s not how locality of reference works. It doesn?t matter whether the objects being accessed are close together in memory or far apart (not with modern fully-associative caches, anyway), what does matter is the frequency distribution of references, namely that the vast majority of references are to a tiny minority of objects. Your generational garbage collector completely breaks this assumption, by regularly forcing an access to every single object in the heap. Cache- thrashing, anyone? > It's also the case that programs with very large memory consumption tend > to use most of the memory for large arrays that don't contain pointers > (think of a database server with a huge cache). That means the gc > doesn't really have to think about all that much of the memory. But your generational garbage collector still has to copy those very large objects to the new heap, with all the cache-hostile consequences therefrom. By the way, isn?t this the opposite of the array-of-pointers example you were using earlier to try to cast reference-counting in a bad light? It seems to me a reference count would work very well for such a large, simple object. >> This is the continuing problem with garbage collection: all the attempts >> to make it cheaper just end up moving the costs somewhere else. > > Same thing with manual allocation. That moves the costs off the > computer and onto the programmer. Not good, most of the time. Unfortunately, your argument falls down. It is a truism that hardware costs continue to come down, while programmers remain expensive. As I said before, computing performance has improved by something like five orders of magnitude over the last half-century. This has rendered all kinds of techniques, like high-level languages, dynamic memory allocation, stacks, hardware floating-point, memory protection and so on, which were once considered controversial because of their expense, cheap enough to become commonplace. But not garbage collection. This is because of the asymmetric way in which hardware has become faster: the biggest improvements have been in the parts that were already the fastest to begin with (the CPU), while RAM speeds have improved much less, and backing-store speeds least of all. Hence the need for intermediate layers of cache to bridge the gap. But the effectiveness of that caching depends crucially on certain assumptions about the runtime behaviour of the programs: and garbage collection breaks those assumptions. > Really, I'm no gc expert, but the stuff you're saying about gc is quite > ill-informed. You might want to check out some current literature. You may want to enlighten yourself by meditating on this seeming paradox of modern computing hardware: memory is cheap, but accessing memory is expensive. From no.email at nospam.invalid Sat Sep 4 23:56:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Sep 2010 20:56:18 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> <7x7hj2kyd6.fsf@ruckus.brouhaha.com> Message-ID: <7xk4n0c07x.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: >> A minimal naive implementation indeed doubles the memory requirements, >> but from a Python perspective where every integer takes something like >> 24 bytes already, even that doesn't seem so terrible. > > Doubling 24 is less terrible than doubling 4 or 8?? You?re kidding, right? No, it would be doubling 4 or 8 bytes. The extra overhead like the reference count would not be there to bloat up the integer like in Python. >> More sophisticated implementations use multiple small heaps or other tricks. > More and more complications to patch up the idea. At some point, you have to > admit there is something fundamentally flawed about the whole concept. Oh sheesh, that's silly. Every area of programming where performance matters is full of optimization tricks. Look at any serious database implementation for example. Or any compiler. Look at Python's implementation of dictionaries. Yeah, the optimizations add complexity to improve performance, sometimes even in heuristic ways that can fail. That doesn't mean the concepts are fundamentally flawed. GC is no different. >> The new heap is filled sequentially so accesses to it will have good >> locality. > what does matter is the frequency distribution of references, Sorry, just I meant during the gc operation itself. The gc's access pattern in the new heap is completely sequential as the gc just copies stuff to it linearly from from the old heap, bumping a pointer upwards. The access pattern when the user application is running is of course not predictable. > Your generational garbage collector completely breaks this assumption, by > regularly forcing an access to every single object in the heap. Cache- > thrashing, anyone? In the minor collections, the whole minor heap fits in cache, so there's no thrashing. The major collections can use a different strategy, or you can simply rely on their relative infrequency. Why do you speculate like this? If you run a GHC program with profiling active, it tells you exactly how much time is spent in minor gc and how much time is in major gc, and it's all generally pretty tolerable unless your program has bugs. (Unfortunately Haskell programs are notoriously susceptable to a certain type of bug that causes them to still give the right answers, but use much more memory than they should. The usual sign of that happening is high gc load). >> It's also the case that programs with very large memory consumption tend >> to use most of the memory for large arrays that don't contain pointers > But your generational garbage collector still has to copy those very large > objects to the new heap, with all the cache-hostile consequences therefrom. Not necessarily, depends on how you write the program and how the gc works. > By the way, isn?t this the opposite of the array-of-pointers example you > were using earlier to try to cast reference-counting in a bad light? I wasn't trying to cast reference counting in a bad light, I was pointing out that reference counting can experience pauses just like traditional gc approaches. Most programs including "soft" real time programs can tolerate an occasional pause. If your program is not one of those, and you need guaranteed upper bounds on pauses so you can't use traditional gc, switching from gc to reference counting won't save you. > It seems to me a reference count would work very well for such a > large, simple object. Mark/sweep would do it too. Some gc's use a hybrid approach, with mark/sweep for older or larger objects. > But not garbage collection. This is because of the asymmetric way in > which hardware has become faster:... the effectiveness of that > caching depends crucially on certain assumptions about the runtime > behaviour of the programs: and garbage collection breaks those > assumptions. ... > You may want to enlighten yourself by meditating on this seeming paradox of > modern computing hardware: memory is cheap, but accessing memory is > expensive. I'm interested in receiving enlightment if you've got some pointers into the research literature that back up your views. Right now it sounds like you're going by some intuitions you have that aren't backed up by evidence. Anyone who has performance-tuned a program knows that intuition can give reasonable starting points for experiments and measurements, but once the results start coming in, a lot of the intuitions end up invalidated. By now, there is enough experimental and theoretical literature about gc that opinions like yours, that don't seem to be grounded in any knowledge of that literature, are not very persuasive no matter how superficially attractive the raw intuition might be. Especially in your case, where you seem to have decided ahead of time what conclusion you want to reach and are looking for ways to justify it. From shivramsharan at gmail.com Sun Sep 5 00:29:49 2010 From: shivramsharan at gmail.com (shivram) Date: Sat, 4 Sep 2010 21:29:49 -0700 (PDT) Subject: Network and socket programming in python Message-ID: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> i want to learn network and socket programming but i would like to do this in python.Reason behind this is that python is very simple and the only language i know . anybody can suggest me which book should i pick. the book should have following specification-- 1)not tedious to follow 2)lots of example 3)starts with some networking stuff and then get into codes thanks in advance with regards. From nagle at animats.com Sun Sep 5 01:23:44 2010 From: nagle at animats.com (John Nagle) Date: Sat, 04 Sep 2010 22:23:44 -0700 Subject: Queue cleanup In-Reply-To: References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> Message-ID: <4c83295b$0$1665$742ec2ed@news.sonic.net> On 9/4/2010 6:44 PM, Lawrence D'Oliveiro wrote: > In message<4c82b097$0$1661$742ec2ed at news.sonic.net>, John Nagle wrote: > >> Personally, I'd like to have reference counting only, an enforced >> prohibition on loops (backpointers must be weak pointers), RAII, >> and reliably ordered finalization. > > Is there a cheap way of checking at runtime for circular structures? It's an interesting technical problem to design a system where circular references are detected immediately, at the moment of creation. However, Python already detects loops during garbage collection. If you set gc.set_debug(gc.DEBUG_SAVEALL) all the loops show up in "gc.garbage". >> A big advantage of reference counting is that finalization happens >> in the thread that releases the object, and in the correct order. >> GC and finalization/destructors do not play well together at all. >> Microsoft once tried to get the hard cases to work right. See >> "managed C++". Not a happy story. > > Thank you for that. Another arrow for my anti-GC quiver. :) Unoptimized reference counting, which is what CPython does, isn't all that great either. The four big bottlenecks in Python are boxed numbers, attribute lookups, reference count updates, and the GIL. John Nagle From jason.heeris at gmail.com Sun Sep 5 01:40:49 2010 From: jason.heeris at gmail.com (Jason) Date: Sat, 4 Sep 2010 22:40:49 -0700 (PDT) Subject: Subclassing by monkey-patching Message-ID: I'm attempting to implement a recursive directory monitor based on the GIO file monitor in PyGTK. My approach is basically to take the gio.FileMonitor returned by the method gio.File.monitor_directory(), connect to the "changed" signal, and add or remove monitors on create/ delete events for subdirectories. I'd really like to do this by subclassing gio.FileMonitor. But the problem I'm having is that it's never explicitly initialised in user code (but somewhere in gio.File.monitor_directory() ). So there's no point in just declaring a subclass ? where would I actually create an instance? Is there a way I can write the subclass but then somehow... extend an existing instance all at once rather than monkeypatch methods on one by one? So I could take an existing instance of a FileMonitor and make it an instance of my subclass? This would even allow me to override the gio.File.monitor_directory() method to take the monitor returned by the original method and decide whether to make it recursive based on a parameter passed to monitor_directory(). Cheers, Jason PS. Asked a similar question on the pygtk list a few days ago: http://www.daa.com.au/pipermail/pygtk/2010-September/018965.html From cournape at gmail.com Sun Sep 5 01:45:22 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 5 Sep 2010 14:45:22 +0900 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: On Thu, Sep 2, 2010 at 7:02 PM, Michael Kreim wrote: > Hi, > > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 1000000000 > a = 0 > for i in xrange(imax): > ? ?a = a + 10 > print a > > $ cat addition.m > imax = 1e9; > a = 0; > for i=0:imax-1 > ? ?a = a + 10; > end > disp(a); > exit; > > The results look like this: > $ /usr/bin/time --verbose python addition.py > 10000000000 > ? ? ? ?Command being timed: "python addition.py" > ? ? ? ?User time (seconds): 107.30 > ? ? ? ?System time (seconds): 0.08 > ? ? ? ?Percent of CPU this job got: 97% > ? ? ? ?Elapsed (wall clock) time (h:mm:ss or m:ss): 1:50.09 > ? ? ? ?[...] > > $ /usr/bin/time --verbose matlab -nodesktop -nosplash -r "addition" > [...] > ? ?1.0000e+10 > ? ? ? ?Command being timed: "matlab -nodesktop -nosplash -r addition" > ? ? ? ?User time (seconds): 7.65 > ? ? ? ?System time (seconds): 0.18 > ? ? ? ?Percent of CPU this job got: 94% > ? ? ? ?Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.25 > ? ? ? ?[...] > > Unfortunately my Python Code was much slower and I do not understand why. Getting the above kind of code fast requires the interpreter to be clever enough so that it will use native machine operations on a int type instead of converting back and forth between internal representations. Matlab since version 6 I believe, has a JIT to do just that. There is no mature JIT-like implementation of python which will give you the same speed up for this exact case today. > Or do I have to live with the fact that Matlab beats Python in this example? Yes. Without a JIT, python cannot hope to get the same kind of speeds for this kind of examples. That being said, neither matlab nor matlab are especially good at doing what you do in your example - for this exact operation, doing it in C or other compiled languages will be at least one order of magnitude faster. Generally, you use matlab's vectorized operations, and in that case, numpy gives you similar performances (sometimes faster, sometimes slower, but in the same ballpark in general). cheers, David From no.email at nospam.invalid Sun Sep 5 02:51:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Sep 2010 23:51:03 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> <4c83295b$0$1665$742ec2ed@news.sonic.net> Message-ID: <7xd3ssbs4o.fsf@ruckus.brouhaha.com> John Nagle writes: > Unoptimized reference counting, which is what CPython does, isn't > all that great either. The four big bottlenecks in Python are boxed > numbers, attribute lookups, reference count updates, and the GIL. The performance hit of having to lock the refcounts before update has been the historical reason for keeping the GIL. The LOCK prefix takes something like 100 cycles on an x86. Is optimizing the refcount updates going to anywhere near make up for that? Python's "with" statement as an approach to RAII has seemed ok to me. I can't think of a time when I've really had to use a finalizer for something with dynamic extent. They've always seemed like a code smell to me. From arnodel at googlemail.com Sun Sep 5 03:23:42 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 05 Sep 2010 08:23:42 +0100 Subject: Subclassing by monkey-patching References: Message-ID: Jason writes: [...] > Is there a way I can write the subclass but then somehow... extend an > existing instance all at once rather than monkeypatch methods on one > by one? So I could take an existing instance of a FileMonitor and make > it an instance of my subclass? This would even allow me to override > the gio.File.monitor_directory() method to take the monitor returned > by the original method and decide whether to make it recursive based > on a parameter passed to monitor_directory(). There is a straightforward way: >>> class A(object): ... def __init__(self, x): ... self.x = x ... >>> class B(A): ... def x2(self): ... return self.x**2 ... >>> a = A(42) # Create an instance of A >>> a.__class__ = B # Change its class to B >>> a.x2() 1764 However, I've never really tried it so I don't know what ways it could break. HTH -- Arnaud From __peter__ at web.de Sun Sep 5 03:53:39 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Sep 2010 09:53:39 +0200 Subject: Subclassing by monkey-patching References: Message-ID: Arnaud Delobelle wrote: > Jason writes: > [...] >> Is there a way I can write the subclass but then somehow... extend an >> existing instance all at once rather than monkeypatch methods on one >> by one? So I could take an existing instance of a FileMonitor and make >> it an instance of my subclass? This would even allow me to override >> the gio.File.monitor_directory() method to take the monitor returned >> by the original method and decide whether to make it recursive based >> on a parameter passed to monitor_directory(). > > There is a straightforward way: > >>>> class A(object): > ... def __init__(self, x): > ... self.x = x > ... >>>> class B(A): > ... def x2(self): > ... return self.x**2 > ... >>>> a = A(42) # Create an instance of A >>>> a.__class__ = B # Change its class to B >>>> a.x2() > 1764 > > However, I've never really tried it so I don't know what ways it could > break. I think this is fine for classes written Python but won't work here: >>> m = gio.File(".").monitor_directory() >>> C = type(m) >>> class CC(C): ... def whatever(self): ... print 42 ... >>> m.__class__ = CC Traceback (most recent call last): File "", line 1, in TypeError: __class__ assignment: '__main__.GInotifyDirectoryMonitor' deallocator differs from 'CC' A possible alternative may be a class that wraps a FileMonitor instead of subclassing it. Peter From __peter__ at web.de Sun Sep 5 04:16:30 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Sep 2010 10:16:30 +0200 Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: genxtech wrote: > Hello. I am still really new to python and I have a project where I > am trying to use the data files from another program and write a new > program with new user interface and all. My first step was to open > one of the files in 'rb' mode and print the contents, but I am > unfamiliar with the format. Here is what was printed to the terminal: > > b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f > \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y > \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$ > \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n > \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc > \x00\x00\x0c\x19\x00\x00' > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > Any advise on how to decode the data would be greatly appreciated. What's the name of the file? What's the program that uses the file? If the source code is available, what library does that program use to read the file? Peter From nicholas.cole at gmail.com Sun Sep 5 04:49:00 2010 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 5 Sep 2010 09:49:00 +0100 Subject: Python 2.7 module path problems on OS X Message-ID: Dear List, I have a horrible feeling that this is in some way related to the new user installation directory in 2.7,or some problem with the framework built, but I'm having great trouble with the module search path on 2.7. I usually install modules to install_lib = ~/Library/Python/$py_version_short/site-packages I assumed that this would continue to work on 2.7. Unfortunately, it seems not to. The installation is fine, but sys.path only includes '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages' Whereas on 2.6 on my system the default is the more extensive: '/Users/nicholas/Library/Python/2.6/site-packages/docutils-0.5-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/py2app-0.4.3-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/macholib-1.2.1-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/modulegraph-0.7.3-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/altgraph-0.6.7-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/bdist_mpkg-0.4.4-py2.6.egg', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Python/2.6/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode', '/Users/nicholas/Library/Python/2.6/site-packages' I'm sorry to ask such a trivial question on the list, but I'm used to python installations "Just working"! Can anyone suggest a good fix? Best wishes, Nicholas From jason.heeris at gmail.com Sun Sep 5 04:54:05 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 5 Sep 2010 01:54:05 -0700 (PDT) Subject: Subclassing by monkey-patching References: Message-ID: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> On Sep 5, 3:53?pm, Peter Otten <__pete... at web.de> wrote: > >>> m = gio.File(".").monitor_directory() > >>> C = type(m) 'C' will not necessarily be 'gio.FileMonitor' ? I think the internals of the GIO methods might further "subclass" it in some way depending on what underlying monitors are available. > A possible alternative may be a class that wraps a FileMonitor instead of > subclassing it. I've been avoiding this because it involves a lot of boilerplate: the signals needs to be replicated and passed through, same for all GObject properties, same for the usual methods. I'd basically have to re-write the entire class in Python, and then tack on my methods. Otherwise I have to write two sets of methods for anything that touches this wrapped object. Still, if it's the only way, sure. ? Jason From nad at acm.org Sun Sep 5 05:20:24 2010 From: nad at acm.org (Ned Deily) Date: Sun, 05 Sep 2010 02:20:24 -0700 Subject: Python 2.7 module path problems on OS X References: Message-ID: In article , Nicholas Cole wrote: > I have a horrible feeling that this is in some way related to the new > user installation directory in 2.7,or some problem with the framework > built, but I'm having great trouble with the module search path on > 2.7. > > I usually install modules to install_lib = > ~/Library/Python/$py_version_short/site-packages There are differences in defaults between different Python versions and instances of the same version as built by different providers. The pattern above is the default location for site-packages for Apple-supplied Pythons in recent versions of OS X, in particular the default /usr/bin/python2.6 in OS X 10.6 and /usr/bin/python2.5 in 10.5. >> I assumed that this would continue to work on 2.7. > > Unfortunately, it seems not to. The installation is fine, but sys.path > only includes > > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib- > scriptpackages', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages > ' OTOH, the Python instances installed by the python.org OS X installers (or ones built similarly) default to using the site-packages directory in the framework directory as shown in that last path. > Whereas on 2.6 on my system the default is the more extensive: > [...] > > I'm sorry to ask such a trivial question on the list, but I'm used to > python installations "Just working"! Can anyone suggest a good fix? I'm not sure why you think it is broken. The Apple 2.6 and the python.org 2.7 have different site-package directories in different locations. That is to be expected. The Apple-supplied Python comes with some additional packages pre-installed, like setuptools, PyObjC, and wx. But you would need to install new versions of these for 2.7 anyway. f you use "easy_install" (aka setuptools or Distribute), keep in mind that every instance of Python needs to have its own version. So, for 2.7, you should follow the installation instructions for either setuptools or Distribute and install a version for 2.7 using python2.7. Its easy_install command will be in the framework bin directory, /Library/Frameworks/Python.framework/Versions/2.7/bin, which is the default location for scripts to be installed. You should ensure that that directory appears on your shell PATH before /usr/bin (where the Apple-supplied easy_install is); if you used the default settings for the python.org installer, it will have attempted to modify your shell startup files, like .bash_profile, to do that for you. Then you can use that easy_install (also available as easy_install-2.7) to install whatever packages you need for 2.7. Or you can use pip. Or just manually installing using the package's setup.py script. All of them use the Python instance's version of Distutils and it will do the right thing for each instance as long as you don't try to influence things by using non-default settings or setting Python-related environment variables, like PYTHONPATH. -- Ned Deily, nad at acm.org From nicholas.cole at gmail.com Sun Sep 5 05:27:41 2010 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 5 Sep 2010 10:27:41 +0100 Subject: Python 2.7 module path problems on OS X In-Reply-To: References: Message-ID: On Sun, Sep 5, 2010 at 10:20 AM, Ned Deily wrote: > I'm not sure why you think it is broken. ?The Apple 2.6 and the > python.org 2.7 have different site-package directories in different > locations. ?That is to be expected. ?The Apple-supplied Python comes > with some additional packages pre-installed, like setuptools, PyObjC, > and wx. ?But you would need to install new versions of these for 2.7 > anyway. > Sorry. I wasn't clear. Of course I understand that each version of python needs its own additional packages, and I was expecting to re-install them. But I don't want to install system-wide -- I'd like to have my own, user-specific, site-packages. On previous versions of python, I've installed into ~/Library/Python/$py_version_short/site-packages under my home directory. In my recollection, this has worked in the past for python installed from python.org, but perhaps that recollection is wrong. At any rate, it doesn't work with python 2.7. Best wishes, Nicholas From mblume at socha.net Sun Sep 5 05:29:41 2010 From: mblume at socha.net (mblume) Date: 05 Sep 2010 09:29:41 GMT Subject: Network and socket programming in python References: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> Message-ID: <4c836305$0$4016$5402220f@news.sunrise.ch> Am Sat, 04 Sep 2010 21:29:49 -0700 schrieb shivram: > > i want to learn network and socket programming but i would like to do > this in python.Reason behind this is that python is very simple and the > only language i know . > anybody can suggest me which book should i pick. the book should have > following specification-- 1)not tedious to follow > 2)lots of example > 3)starts with some networking stuff and then get into codes > > thanks in advance with regards. > Ever heard of Google? "python network tutorial" / "python socket tutorial" should get you started. HTH. Martin From madhurrajn at gmail.com Sun Sep 5 06:05:54 2010 From: madhurrajn at gmail.com (Madhur) Date: Sun, 5 Sep 2010 03:05:54 -0700 (PDT) Subject: High CPU utilization with Pylab Message-ID: <34646c22-e7d5-47b5-9a8a-eaeb472fde0f@e14g2000yqe.googlegroups.com> I am trying to plot a runtime graph using pylab. But the very purpose of functionality is lost because of high CPU percentage hogged by plotting the graph. Here is the piece of code which I have written. def timerfunc(ulcm, dlcm): count=0 xaxis=[] yaxis=[] ion() while 1: xaxis.append(count) dr=(((dlcm.sum)/dlcm.timer)*8) dlcm.counter=0 yaxis.append(dr) dlcm.sum=0 h=plot(xaxis,yaxis,'b') draw() count=count+1 time.sleep(dlcm.timer/1000.0) if (count>100): xlim(count-100, count) Here is the function which plots the graph. Is there something which does not makes sense .? -Madhur From mats.rauhala at gmail.com Sun Sep 5 06:28:38 2010 From: mats.rauhala at gmail.com (Mats Rauhala) Date: Sun, 5 Sep 2010 10:28:38 +0000 (UTC) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: On 2010-09-05, genxtech wrote: > I am using Fedora 13. When I run the file command the response is > that it is a 'data' file. If there are any tips on how to > programatically figure out the format, I would greatly appreciate it. I tried python-magic from the fedora repositories, but was unable to get it working. However there was another project at github [1] which seems to be working, at least with python 2.6. An easy way to test whether it works is by unpacking it, going to the directory, opening the interactive shell and running 'import magic' and 'magic.from_file("testdata/test.pdf")' See help(magic) for more help [1] http://github.com/ahupp/python-magic From debatem1 at gmail.com Sun Sep 5 06:29:44 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 5 Sep 2010 03:29:44 -0700 Subject: Network and socket programming in python In-Reply-To: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> References: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> Message-ID: On Sat, Sep 4, 2010 at 9:29 PM, shivram wrote: > i want to learn network and socket programming but i would like to do > this in python.Reason behind this is that python is very simple and > the only language i know . > anybody can suggest me which book should i pick. > the book should have following specification-- > 1)not tedious to follow > 2)lots of example > 3)starts with some networking stuff and then get into codes > > thanks in advance with regards. "Foundations of Python Network Programming" by John Goerzen. Geremy Condra From 71david at libero.it Sun Sep 5 06:48:59 2010 From: 71david at libero.it (David) Date: Sun, 5 Sep 2010 12:48:59 +0200 Subject: High CPU utilization with Pylab References: <34646c22-e7d5-47b5-9a8a-eaeb472fde0f@e14g2000yqe.googlegroups.com> Message-ID: Il Sun, 5 Sep 2010 03:05:54 -0700 (PDT), Madhur ha scritto: > Is there something which does not makes sense .? 1. How, a computer, is supposed to handle your infinite loop? 2. Running ghraphs shuold be handled in totally different way: look at the "stripcharting" demo in this zip http://agni.phys.iit.edu/~kmcivor/wxmpl/downloads/wxmpl-1.3.1.zip From __peter__ at web.de Sun Sep 5 06:56:28 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Sep 2010 12:56:28 +0200 Subject: Subclassing by monkey-patching References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> Message-ID: Jason wrote: > On Sep 5, 3:53 pm, Peter Otten <__pete... at web.de> wrote: >> >>> m = gio.File(".").monitor_directory() >> >>> C = type(m) > > 'C' will not necessarily be 'gio.FileMonitor' ? I think the internals > of the GIO methods might further "subclass" it in some way depending > on what underlying monitors are available. That would only be relevant if it had worked, I think ;) >> A possible alternative may be a class that wraps a FileMonitor instead of >> subclassing it. > > I've been avoiding this because it involves a lot of boilerplate: the > signals needs to be replicated and passed through, same for all > GObject properties, same for the usual methods. I'd basically have to > re-write the entire class in Python, and then tack on my methods. > Otherwise I have to write two sets of methods for anything that > touches this wrapped object. > > Still, if it's the only way, sure. Does it have to be gio.FileMonitor? pyinotify can automatically add new subdirectories out of the box. Peter From bartc at freeuk.com Sun Sep 5 07:28:47 2010 From: bartc at freeuk.com (BartC) Date: Sun, 5 Sep 2010 12:28:47 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: "David Cournapeau" wrote in message news:mailman.455.1283665528.29448.python-list at python.org... > On Thu, Sep 2, 2010 at 7:02 PM, Michael Kreim > wrote: >> imax = 1000000000 >> a = 0 >> for i in xrange(imax): >> a = a + 10 >> print a >> Unfortunately my Python Code was much slower [than Matlab] and I do not >> understand why. > > Getting the above kind of code fast requires the interpreter to be > clever enough so that it will use native machine operations on a int > type instead of converting back and forth between internal > representations. Writing for i in xrange(1000000000) you'd think would give it a clue, but it makes no difference. > Matlab since version 6 I believe, has a JIT to do > just that. There is no mature JIT-like implementation of python which > will give you the same speed up for this exact case today. >> Or do I have to live with the fact that Matlab beats Python in this >> example? > > Yes. Without a JIT, python cannot hope to get the same kind of speeds > for this kind of examples. > > That being said, neither matlab nor matlab are especially good at > doing what you do in your example - for this exact operation, doing it > in C or other compiled languages will be at least one order of > magnitude faster. One order of magnitude (say 10-20x slower) wouldn't be so bad. That's what you might expect for a dynamically typed, interpreted language. But on my machine this code was more like 50-200x slower than C, for unaccelerated Python. > Generally, you use matlab's vectorized operations, > and in that case, numpy gives you similar performances (sometimes > faster, sometimes slower, but in the same ballpark in general). That would simply be delegating Python to a scripting language. It would be nice if you could directly code low-level algorithms in it without relying on accelerators, and not have to wait two and a half minutes (or whatever) for a simple test to complete. -- bartc From shivramsharan at gmail.com Sun Sep 5 07:57:36 2010 From: shivramsharan at gmail.com (simpu) Date: Sun, 5 Sep 2010 04:57:36 -0700 (PDT) Subject: Network and socket programming in python References: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> Message-ID: <29f5a052-86e5-42d0-bdc2-5156c1f1e85c@13g2000prf.googlegroups.com> On Sep 5, 3:29?pm, geremy condra wrote: > On Sat, Sep 4, 2010 at 9:29 PM, shivram wrote: > > i want to learn network and socket programming but i would like to do > > this in python.Reason behind this is that python is very simple and > > the only language i know . > > anybody can suggest me which book should i pick. > > the book should have following specification-- > > 1)not tedious to follow > > 2)lots of example > > 3)starts with some networking stuff and then get into codes > > > thanks in advance with regards. > > "Foundations of Python Network Programming" by John Goerzen. > > Geremy Condra thank you so much for your concern From ctops.legal at gmail.com Sun Sep 5 08:44:16 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 05:44:16 -0700 (PDT) Subject: Python [repair_cycorder_mov.py] Message-ID: Trying to learn Python for a specific purpose to repair a quicktime file that's corrupted, is it even possible to create a proof-of- concept python script that generates a valid 'moov' atom from a corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to finalize file). [IMG]http://a.imageshack.us/img337/5503/cycorder.jpg[/IMG] By [URL=http://profile.imageshack.us/user/ctops].[/URL] [IMG]http://a.imageshack.us/img375/9254/finallm.jpg[/IMG] By [URL=http://profile.imageshack.us/user/ctops].[/URL]
From ctops.legal at gmail.com Sun Sep 5 08:51:53 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 05:51:53 -0700 (PDT) Subject: Python script for repairing .mov file Message-ID: <3d8ef7ff-772d-4580-9e18-30046a049b35@s9g2000yqd.googlegroups.com> Trying to learn Python for a specific purpose to repair a quicktime file that's corrupted, is it even possible to create a proof-of- concept python script that generates a valid 'moov' atom from a corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to finalize file). Mac--> http://a.imageshack.us/img337/5503/cycorder.jpg Windows--> http://a.imageshack.us/img375/9254/finallm.jpg Source sample Quicktime mov file 22mb; https://docs.google.com/leaf? id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2VlLTkxMTAtODVmZWM3NWNhNDBi&sort=name&? layout=list&num=50 Source thread; http://modmyi.com/forums/windows-specific-modding-discussion/587461-editing-mov-files-corrupt-cycorder-videos-8.html From ctops.legal at gmail.com Sun Sep 5 08:54:47 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 05:54:47 -0700 (PDT) Subject: Python script for repairing .mov file ? Message-ID: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> Trying to learn Python for a specific purpose to repair a quicktime file that's corrupted, is it even possible to create a proof-of- concept python script that generates a valid 'moov' atom from a corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to finalize file). Mac--> http://a.imageshack.us/img337/5503/cycorder.jpg Windows--> http://a.imageshack.us/img375/9254/finallm.jpg Source sample Quicktime mov file 22mb; https://docs.google.com/leaf?id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2VlLTkxMTAtODVmZWM3NWNhNDBi&sort=name&layout=list&num=50 Source thread; http://modmyi.com/forums/windows-specific-modding-discussion/587461-editing= -mov-files-corrupt-cycorder-videos-8.html From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 10:00:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 14:00:35 GMT Subject: Python [repair_cycorder_mov.py] References: Message-ID: <4c83a283$0$28657$c3e8da3@news.astraweb.com> On Sun, 05 Sep 2010 05:44:16 -0700, ctops.legal wrote: > Trying to learn Python for a specific purpose to repair a quicktime file > that's corrupted, is it even possible to create a proof-of- concept > python script that generates a valid 'moov' atom from a corrupt .mov > video ?, "file size 1.3gb" (Kodak camera failed to finalize file). Yes, Python is a Turing complete programming language. Anything you can do in any programming language, you can do in Python. By the way, there's no need to send three messages in 10 minutes asking the same question, and adding FORM METHOD links to your post will probably just get it flagged as spam by many people. -- Steven From agoretoy at gmail.com Sun Sep 5 10:09:07 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 5 Sep 2010 09:09:07 -0500 Subject: ssh browser? where? Message-ID: why not ssh browser traffic? why use SSL certificate authorities which can't be trusted in the first place? Is SSH not proven to be secure? To this day I have not seen ssh module for say Apache web server, why not? I understand this maybe wrong list to ask this question, but I love you guys so much at python and I think your smart... :) Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollybox.de Sun Sep 5 10:31:49 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 5 Sep 2010 16:31:49 +0200 Subject: ssh browser? where? In-Reply-To: References: Message-ID: <201009051631.50658.thomas@jollybox.de> On Sunday 05 September 2010, it occurred to alex goretoy to exclaim: > why not ssh browser traffic? why use SSL certificate authorities which > can't be trusted in the first place? > Is SSH not proven to be secure? > > To this day I have not seen ssh module for say Apache web server, why not? > > I understand this maybe wrong list to ask this question, but I love you > guys so much at python and I think your smart... :) Umn. Yes, wrong list. Still, SSH is "secure shell". Shell ? WWW. TLS/SSL is secure. Once you have an encrypted connection to the correct party, the information you send over that connection is just as illegible to the outsider as it'd be over an SSH connection. If you're connected to someone other than you think you are connected to, then all the encryption in the world won't help you. (man-in-the-middle attack) With SSH, this isn't that big a problem: you only connect to a machine over SSH if you have an account there. Since this tends to be a relatively small number of machines, it's relatively easy to manually check the server's key fingerprint. The authenticity of the server's key must be checked to prevent an attack, and the status quo with SSH is that the user does it, which is arguably the most secure model anyway. On the web, you might connect to any number of servers. Manually checking every single key would be a gargantuan and certainly not very rewarding task. THAT's where certificate authorities come in. They're a reasonable way to automatically check the validity of a server's key, so you don't have to. Now, in theory, you should verify the integrity of the certificate authorities yourself before trusting their judgement, but in practice, you leave that daunting task to your operating system and/or web browser vendor. There are a number of weak spots, but there are also rather strict audits going on all over the place. If we were to use SSH on the web, which is certainly not the point of SSH, we'd still need some kind of certificate authority to make the whole system workable. From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 11:00:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 15:00:32 GMT Subject: Speed-up for loops References: Message-ID: <4c83b08f$0$28657$c3e8da3@news.astraweb.com> On Fri, 03 Sep 2010 21:17:44 +0100, BartC wrote: > I'm not sure the Python developers were interested in getting fast > loops. > > For-loops which iterate between two numbers are amongst the easiest > things to make fast in a language. Yet originally you had to use: > > for i in range(N): I don't have any versions of Python prior to version 1.5, but as far back as that there was always a choice between creating a list with range() and a lazy iterator with xrange(). > which (if I understood correctly) actually created a list of N objects, > populated it with the values 0, 1, 2...N-1 (presumably using a more > sensible loop), then iterated between the values of the list! By "more sensible", do you mean "in C code"? If so, then you are correct. > So Python had the distinction of being one of the slowest languages in > which to do nothing (ie. running an empty loop). Nonsense. [steve at sylar ~]$ time python test.py real 0m3.441s user 0m2.969s sys 0m0.024s [steve at sylar ~]$ time perl test.pl real 0m3.490s user 0m2.722s sys 0m0.011s [steve at sylar ~]$ time ruby test.rb real 0m11.875s user 0m6.740s sys 0m3.995s The difference between an empty loop in Python and Perl is insignificant, and much faster than Ruby (at least the specific version of Ruby installed on my machine, 1.8.6). And if you want to see the code I ran: [steve at sylar ~]$ cat test.* # perl for ($i = 0; $i < 10_000_000; ++$i) { 1; } # python for i in xrange(10000000): 1 # ruby for i in 0...10000000 1 end Just for comparisons' sake: [steve at sylar ~]$ gpc empty_test.p [steve at sylar ~]$ time ./a.out real 0m0.106s user 0m0.070s sys 0m0.004s [steve at sylar ~]$ cat empty_test.p program main(input, output); var i: integer; begin for i := 0 to 10000000 do begin end; end. Of course, a real optimizing compiler would realise that the Pascal code did nothing at all, and compile it all away to an empty a.out file... -- Steven From agoretoy at gmail.com Sun Sep 5 11:02:39 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 5 Sep 2010 10:02:39 -0500 Subject: ssh browser? where? In-Reply-To: <201009051631.50658.thomas@jollybox.de> References: <201009051631.50658.thomas@jollybox.de> Message-ID: >>> If we were to use SSH on the web, which is certainly not the point of SSH, >>> we'd still need some kind of certificate authority to make the whole system >>> workable. Yeah, you are correct. I thought about that after having posted these questions. Even though it was SSH there still would be wiggle room for a mitm. I had a dream last night that my future employer was asking me what SSH was. lol I appreciate your response and making it clear as day. Still though, I think there maybe something for testing here. I personally verify and scope out my cert manually. Well for the sites I visit often. But I understand not everyone will be likely to do this. Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From almar.klein at gmail.com Sun Sep 5 11:07:46 2010 From: almar.klein at gmail.com (Almar Klein) Date: Sun, 5 Sep 2010 17:07:46 +0200 Subject: Python script for repairing .mov file ? In-Reply-To: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> References: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> Message-ID: On 5 September 2010 14:54, ctops.legal wrote: > Trying to learn Python for a specific purpose to repair a quicktime > file that's corrupted, is it even possible to create a proof-of- > concept python script that generates a valid 'moov' atom from a > corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to > finalize file). > Why would you use Python for this? Would ffmpeg or mencoder not be more suitable? Anyway, there's pymedia, but I have no experience with it. I'm not sure what I should see in the links. The "Soure thread" one is broken by the way (404 error). Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 11:15:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 15:15:49 GMT Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <4c83b425$0$28657$c3e8da3@news.astraweb.com> On Sun, 05 Sep 2010 12:28:47 +0100, BartC wrote: >> Getting the above kind of code fast requires the interpreter to be >> clever enough so that it will use native machine operations on a int >> type instead of converting back and forth between internal >> representations. > > Writing for i in xrange(1000000000) you'd think would give it a clue, > but it makes no difference. CPython takes a very conservative view towards runtime optimizations. Optimizations don't happen for free, you know, they have costs. Memory is one cost, but human time and effort is another. But if you want a JIT compiler, see Psycho, or try PyPy, which is very exciting and I hope will one day be ready to take over from CPython as the first choice for production use. [...] > One order of magnitude (say 10-20x slower) wouldn't be so bad. That's > what you might expect for a dynamically typed, interpreted language. > > But on my machine this code was more like 50-200x slower than C, for > unaccelerated Python. I'd say that 50-200 times slower than C is exactly what I'd expect from a dynamically typed language like Python without any fancy JIT tricks. Getting such a language to within an order of magnitude of C is quite an achievement. >> Generally, you use matlab's vectorized operations, and in that case, >> numpy gives you similar performances (sometimes faster, sometimes >> slower, but in the same ballpark in general). > > That would simply be delegating Python to a scripting language. That's sheer unadulterated nonsense. In any case, Python was designed as a glue language, specifically to be a high-level user-friendly language for gluing components written in C together. That's what Python *is* -- it provides a bunch of primitives, written in C (or Java, or dot-Net, pick whichever implementation you like) and manipulated in a friendly, safe language. Calling numpy for fast vectorized operations is *exactly* the right solution, if you need high-performance maths calculations. Use the right tool for the job, don't insist that your spanner should double as a screwdriver. > It would > be nice if you could directly code low-level algorithms in it without > relying on accelerators, and not have to wait two and a half minutes (or > whatever) for a simple test to complete. Yes, and it would be nice if my clothes washed and ironed themselves, but they don't. Somebody has to do the work. Are you volunteering to write the JIT compiler for CPython? Will you contribute to the PyPy project, or help maintain Psycho, or are you just bitching? The simple fact is that there are far more important things for Python developers to spend their time and effort on than optimizations like this. If such an optimization comes out of the PyPy project, I'll be cheering them on -- but it's a lot of effort for such a trivial gain. The example given by the Original Poster is contrived. Nobody sensibly writes an integer multiplication as a repeated addition like that, and any real code that would need to be put in a for loop is almost certainly going to be too complicated for the JIT compiler to benefit greatly. The loop overhead itself will almost certainly be overwhelmed by the work done in the loop: [steve at sylar ~]$ time python -c "a = 0 > for i in xrange(10000000): > a += 10 > " real 0m6.906s user 0m5.820s sys 0m0.022s which is about double the time for an empty loop of the same size. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 11:30:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 15:30:29 GMT Subject: doctest annoyance/puzzle Message-ID: <4c83b795$0$28657$c3e8da3@news.astraweb.com> I'm writing a "literate programming" document, example.txt, which mixes text and code in ReST format: This is my excellent module for making spam. It has one public function, ``make_spam``, which takes a single argument for how much spam to make: >>> from module import make_spam >>> make_spam(3) 'spam spam spam' If you ask for too little spam, you get a bonus: >>> make_spam(-3) 'spam spam spam GLORIOUS SPAM!!!' I run the doctests with: python2.6 -m doctest examples.txt and the first example passes, but the second fails with NameError: make_spam not defined. I have a work-around, I do an import at the start of *every* doctest block, but that's ugly. More complex (realistic) examples sometimes need setup code, which I'd like to survive from one block to the next: >>> it = iter(make_spam(5).split()) >>> next(it) 'spam' text goes here >>> next(it) 'spam' but of course that also fails. This surprises me, because doctests in functions or classes can mix descriptive text between tests without this problem. Am I doing something wrong, or is doctest fundamentally broken when executing tests in a text file? -- Steven From vicente.soler at gmail.com Sun Sep 5 12:00:23 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 5 Sep 2010 09:00:23 -0700 (PDT) Subject: personal firewall software is blocking the connection Message-ID: I'am getting this annoying message all the time when using IDLE. ... personal firewall software is blocking the connection When I am editing a source *.py file and I click on F5 (run) I get the above message. What can I do? I am using Norton Internet Security. I try to find if 127.0.0.1 is blocked, but I do not know where to look. Can anybody help? From vicente.soler at gmail.com Sun Sep 5 12:10:52 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 5 Sep 2010 09:10:52 -0700 (PDT) Subject: IDLE: personal firewall software is blocking the connection References: Message-ID: <90be5563-b7d5-41b0-8ceb-955c1b1b49fc@x42g2000yqx.googlegroups.com> On 5 sep, 18:00, vsoler wrote: > I'am getting this annoying message all the time when using IDLE. > > ... ?personal firewall software is blocking the connection > > When I am editing a source *.py file and I click on F5 (run) I get the > above message. > > What can I do? > > I am using Norton Internet Security. I try to find if 127.0.0.1 is > blocked, but I do not know where to look. > > Can anybody help? From marduk at letterboxes.org Sun Sep 5 12:23:24 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Sun, 05 Sep 2010 12:23:24 -0400 Subject: Python [repair_cycorder_mov.py] In-Reply-To: <4c83a283$0$28657$c3e8da3@news.astraweb.com> References: <4c83a283$0$28657$c3e8da3@news.astraweb.com> Message-ID: <1283703804.559960.0.camel@paska> On Sun, 2010-09-05 at 14:00 +0000, Steven D'Aprano wrote: > By the way, there's no need to send three messages in 10 minutes > asking > the same question, and adding FORM METHOD links to your post will > probably just get it flagged as spam by many people. Apparently it has, as I only got this response. From stefan_ml at behnel.de Sun Sep 5 12:27:46 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 05 Sep 2010 18:27:46 +0200 Subject: Speed-up for loops In-Reply-To: <4c83b08f$0$28657$c3e8da3@news.astraweb.com> References: <4c83b08f$0$28657$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano, 05.09.2010 17:00: > Of course, a real optimizing compiler would realise that the Pascal code > did nothing at all, and compile it all away to an empty a.out file... Which is just one of the reasons why this kind if "benchmark" provides no insight into anything that should have an impact on a programmer's daily job. Stefan From sschwarzer at sschwarzer.net Sun Sep 5 12:41:15 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 05 Sep 2010 18:41:15 +0200 Subject: doctest annoyance/puzzle In-Reply-To: <4c83b795$0$28657$c3e8da3@news.astraweb.com> References: <4c83b795$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C83C82B.5030108@sschwarzer.net> Hi Steven, On 2010-09-05 17:30, Steven D'Aprano wrote: > I run the doctests with: > > python2.6 -m doctest examples.txt > > and the first example passes, but the second fails with NameError: > make_spam not defined. I run my doctests by calling doctest.testfile(filename) for each file in a loop. This way, names and their associated objects survice from one code block to the next. I just read that the way you use doctest should behave the same, according to the documentation. In case of a text file I just tested, it does; all tests pass despite the text snippets between the code blocks. What do you get if you test your text file by explicitly calling doctest.testfile? Stefan From roy at panix.com Sun Sep 5 13:09:03 2010 From: roy at panix.com (Roy Smith) Date: Sun, 05 Sep 2010 13:09:03 -0400 Subject: Extracting item from list of tuples? Message-ID: I'm using httplib, and want to get the Location header from the response. The getheaders() method gives you back a list of (name, value) tuples. It would be a lot more convenient if it gave you back a dict, but it is what it is. Anyway, I came up with: location = [t[1] for t in headers if t[0] == 'location'][0] which works, but is getting on towards the cryptic end of things. Is there a better idiom for this? From bartc at freeuk.com Sun Sep 5 13:09:47 2010 From: bartc at freeuk.com (BartC) Date: Sun, 5 Sep 2010 18:09:47 +0100 Subject: Speed-up for loops In-Reply-To: <4c83b425$0$28657$c3e8da3@news.astraweb.com> References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c83b425$0$28657$c3e8da3 at news.astraweb.com... > On Sun, 05 Sep 2010 12:28:47 +0100, BartC wrote: >> It would >> be nice if you could directly code low-level algorithms in it without >> relying on accelerators, and not have to wait two and a half minutes (or >> whatever) for a simple test to complete. > > Yes, and it would be nice if my clothes washed and ironed themselves, but > they don't. > > Somebody has to do the work. Are you volunteering to write the JIT > compiler for CPython? Will you contribute to the PyPy project, or help > maintain Psycho, or are you just bitching? I've thought about it (writing an independent interpreter). But I don't know enough of the language, and a lot of it I don't understand (eg. OOP). Besides, I think the language itself deliberately makes it difficult to get it up to speed. Some of the reasons might be the ones set down here, in Chapter 2: http://codespeak.net/svn/user/antocuni/phd/thesis/thesis.pdf (Instead, I've confined my efforts to my own projects; the last interpreter I worked on did in fact get within a magnitude of C in performance, without using JIT or other fancy tricks.) > The simple fact is that there are far more important things for Python > developers to spend their time and effort on than optimizations like this. I don't know, there's seem to be an awful lot of effort going into addressing exactly this issue (eg. PyPy, Pscyo, Unladen Swallow, Shedskin....) > If such an optimization comes out of the PyPy project, I'll be cheering > them on -- but it's a lot of effort for such a trivial gain. > > The example given by the Original Poster is contrived. Nobody sensibly > writes an integer multiplication as a repeated addition like that, and > any real code that would need to be put in a for loop is almost certainly > going to be too complicated for the JIT compiler to benefit greatly. The > loop overhead itself will almost certainly be overwhelmed by the work > done in the loop: OK, you're saying there's no point in reducing the loop overhead, because the loop body is going to be even slower. All those compilers that offer loop unrolling are therefore wasting their time... -- Bartc From thomas at jollybox.de Sun Sep 5 13:14:44 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 5 Sep 2010 19:14:44 +0200 Subject: Extracting item from list of tuples? In-Reply-To: References: Message-ID: <201009051914.44213.thomas@jollybox.de> On Sunday 05 September 2010, it occurred to Roy Smith to exclaim: > I'm using httplib, and want to get the Location header from the > response. The getheaders() method gives you back a list of (name, > value) tuples. It would be a lot more convenient if it gave you back a > dict, but it is what it is. It may not be a dict, but you can always make it one: >>> L = [('a',1), ('b', 42), ('c', 0)] >>> dict(L) {'a': 1, 'c': 0, 'b': 42} >>> From philip at semanchuk.com Sun Sep 5 13:26:20 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 5 Sep 2010 13:26:20 -0400 Subject: Extracting item from list of tuples? In-Reply-To: References: Message-ID: <4453332A-820F-4890-95D7-443C3B2B8AD2@semanchuk.com> On Sep 5, 2010, at 1:09 PM, Roy Smith wrote: > I'm using httplib, and want to get the Location header from the > response. The getheaders() method gives you back a list of (name, > value) tuples. It would be a lot more convenient if it gave you > back a > dict, but it is what it is. > > Anyway, I came up with: > > location = [t[1] for t in headers if t[0] == 'location'][0] > > which works, but is getting on towards the cryptic end of things. Is > there a better idiom for this? Are you concerned about efficiency? If it's not important, being less terse would make it less cryptic: location = None for name, value in headers: if name == "location": location = value break If you prefer terse, IMHO this is less cryptic (but untested): location = [value for name, value in headers if name == 'location'] [0] Be careful if you decide to turn the list of tuples into a dictionary. HTTP headers can repeat and straightforward code to turn the (name, value) pairs into a dict could end up overwriting data. Cheers P From __peter__ at web.de Sun Sep 5 13:45:53 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Sep 2010 19:45:53 +0200 Subject: Extracting item from list of tuples? References: Message-ID: Philip Semanchuk wrote: > > On Sep 5, 2010, at 1:09 PM, Roy Smith wrote: > >> I'm using httplib, and want to get the Location header from the >> response. The getheaders() method gives you back a list of (name, >> value) tuples. It would be a lot more convenient if it gave you >> back a >> dict, but it is what it is. >> >> Anyway, I came up with: >> >> location = [t[1] for t in headers if t[0] == 'location'][0] >> >> which works, but is getting on towards the cryptic end of things. Is >> there a better idiom for this? > > Are you concerned about efficiency? If it's not important, being less > terse would make it less cryptic: > location = None > for name, value in headers: > if name == "location": > location = value > break This is actually more efficient because unlike Roy's (and your other solution) it doesn't build a list, and it doesn't waste cycles in the loop once the location is found. You can write it as a generator expression like so: location = next((value for name, value in headers if name == "location"), None) But just converting the headers to a dict is clearer and probably even faster because it moves the loop from Python to C. > If you prefer terse, IMHO this is less cryptic (but untested): > > location = [value for name, value in headers if name == 'location'] > [0] > > > Be careful if you decide to turn the list of tuples into a dictionary. > HTTP headers can repeat and straightforward code to turn the (name, > value) pairs into a dict could end up overwriting data. From nagle at animats.com Sun Sep 5 14:22:37 2010 From: nagle at animats.com (John Nagle) Date: Sun, 05 Sep 2010 11:22:37 -0700 Subject: Queue cleanup In-Reply-To: <7xd3ssbs4o.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> <4c83295b$0$1665$742ec2ed@news.sonic.net> <7xd3ssbs4o.fsf@ruckus.brouhaha.com> Message-ID: <4c83dfed$0$1662$742ec2ed@news.sonic.net> On 9/4/2010 11:51 PM, Paul Rubin wrote: > John Nagle writes: >> Unoptimized reference counting, which is what CPython does, isn't >> all that great either. The four big bottlenecks in Python are boxed >> numbers, attribute lookups, reference count updates, and the GIL. > > The performance hit of having to lock the refcounts before update has > been the historical reason for keeping the GIL. The LOCK prefix takes > something like 100 cycles on an x86. Is optimizing the refcount updates > going to anywhere near make up for that? I've argued for an approach in which only synchronized or immutable objects can be shared between threads. Then, only synchronized objects have refcounts. See "http://www.animats.com/papers/languages/pythonconcurrency.html" Guido doesn't like it. He doesn't like any "restrictions". So we're stuck dragging around the boat anchor. I'd hoped that the Unladen Swallow people might come up with some really clever solution, but they seem to be stuck. It's been almost a year since the last quarterly release. Maybe Google is putting their effort into Go. What's so striking is that Shed Skin can deliver 20x to 60x speedups over CPython, while PyPy and Unladen Swallow have trouble getting 1.5x. The question is how much one has to restrict the language to get a serious performance improvement. > Python's "with" statement as an approach to RAII has seemed ok to me. I > can't think of a time when I've really had to use a finalizer for > something with dynamic extent. They've always seemed like a code smell > to me. The problem appears when you have an object that owns something, like a window or a database connection. "With" is single-level. John Nagle From ctops.legal at gmail.com Sun Sep 5 14:28:03 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 11:28:03 -0700 (PDT) Subject: Python script for repairing .mov file ? References: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> Message-ID: <29fef8e4-3b90-47ca-9312-6d804556fdab@t2g2000yqe.googlegroups.com> On Sep 5, 8:54?am, "ctops.legal" wrote: > Trying to learn Python for a specific purpose to repair a quicktime > file that's corrupted, is it even ?possible to create a proof-of- > concept python script that generates a valid 'moov' atom from a > corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to > finalize file). > > Mac-->http://a.imageshack.us/img337/5503/cycorder.jpg > > Windows-->http://a.imageshack.us/img375/9254/finallm.jpg > > Source sample Quicktime mov file 22mb; > > https://docs.google.com/leaf?id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2VlLTkxMTAtODVmZWM3NWNhNDBi&hl=en > > Source thread;http://modmyi.com/forums/windows-specific-modding-discussion/587461-e... > -mov-files-corrupt-cycorder-videos-8.html From philip at semanchuk.com Sun Sep 5 14:30:52 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 5 Sep 2010 14:30:52 -0400 Subject: Extracting item from list of tuples? In-Reply-To: References: Message-ID: On Sep 5, 2010, at 1:45 PM, Peter Otten wrote: > Philip Semanchuk wrote: > >> >> On Sep 5, 2010, at 1:09 PM, Roy Smith wrote: >> >>> I'm using httplib, and want to get the Location header from the >>> response. The getheaders() method gives you back a list of (name, >>> value) tuples. It would be a lot more convenient if it gave you >>> back a >>> dict, but it is what it is. >>> >>> Anyway, I came up with: >>> >>> location = [t[1] for t in headers if t[0] == 'location'][0] >>> >>> which works, but is getting on towards the cryptic end of things. >>> Is >>> there a better idiom for this? >> >> Are you concerned about efficiency? If it's not important, being less >> terse would make it less cryptic: >> location = None >> for name, value in headers: >> if name == "location": >> location = value >> break > > This is actually more efficient because unlike Roy's (and your other > solution) it doesn't build a list, and it doesn't waste cycles in > the loop > once the location is found. Upon further reflection, though, I realize that my solution is not equivalent to the original. In the case of duplicated headers, the original would return the last value of the location header, my code would return the first. For the HTTP Location header this is only a theoretical problem because the HTTP spec doesn't provide for sending more than one. However if this code were made into a function for retrieving the value of an arbitrary header (as seems likely), one would have to decide how to handle repeating headers. Neither my code nor the original handle that possibility. Nor does a naive conversion into a dict, as I mentioned before. Cheers P > You can write it as a generator expression like > so: > > location = next((value for name, value in headers if name == > "location"), > None) > > But just converting the headers to a dict is clearer and probably even > faster because it moves the loop from Python to C. > >> If you prefer terse, IMHO this is less cryptic (but untested): >> >> location = [value for name, value in headers if name == >> 'location'] >> [0] >> >> >> Be careful if you decide to turn the list of tuples into a >> dictionary. >> HTTP headers can repeat and straightforward code to turn the (name, >> value) pairs into a dict could end up overwriting data. > > -- > http://mail.python.org/mailman/listinfo/python-list From ctops.legal at gmail.com Sun Sep 5 14:31:21 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 11:31:21 -0700 (PDT) Subject: Python script for repairing .mov file ? References: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> Message-ID: <0c453d2b-f055-423b-b032-0083e04ebc48@s9g2000yqd.googlegroups.com> On Sep 5, 8:54?am, "ctops.legal" wrote: > Trying to learn Python for a specific purpose to repair a quicktime > file that's corrupted, is it even ?possible to create a proof-of- > concept python script that generates a valid 'moov' atom from a > corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to > finalize file). > > Mac-->http://a.imageshack.us/img337/5503/cycorder.jpg > > Windows-->http://a.imageshack.us/img375/9254/finallm.jpg > > Source sample Quicktime mov file 22mb; > > https://docs.google.com/leaf?id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2Vl... > > Source thread;http://modmyi.com/forums/windows-specific-modding-discussion/587461-e... > -mov-files-corrupt-cycorder-videos-8.html GOOD Link for source mov file--> https://docs.google.com/uc?id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2VlLTkxMTAtODVmZWM3NWNhNDBi&export=download&hl=en From stefan_ml at behnel.de Sun Sep 5 14:50:55 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 05 Sep 2010 20:50:55 +0200 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: BartC, 05.09.2010 19:09: > I've thought about it (writing an independent interpreter). But I don't > know enough of the language, and a lot of it I don't understand (eg. > OOP). Besides, I think the language itself deliberately makes it > difficult to get it up to speed. Some of the reasons might be the ones > set down here, in Chapter 2: > > http://codespeak.net/svn/user/antocuni/phd/thesis/thesis.pdf Second sentence of the abstract: """ However, all the existing implementations prevent programmers from developing very efficient code. """ For an incorrect statement, that's a pretty bold one, even in the context given by the abstract. The author is lucky not to be an English native speaker, which explains some of the offensive wording in the intro. Also, I'm impressed by an accepted Ph.D. thesis that comes along with just a bit more than four pages of references, and that fails to reference basically everything that the Python ecosystem provides for fast computation. I wouldn't mind a "faster Python", but as long as Python continues to be a language that allows you to very quickly get to the point where you can benchmark and optimise your code, and as long as CPython then makes it easy to do that, I won't be the one jumping up and down for a small factor of "general" improvement, especially when it comes at the price of switching to a completely different runtime. After all, it's really hard to appreciate that a program can now wait 5% more often on I/O than before. Larger performance improvements are usually due to algorithmic changes (including data structure adaptations and caching), rarely due to changes in the interpreter, especially when it's as old and well optimised as CPython. I think the CPython interpreter does a really good job in providing a stable and predictable runtime environment and executing code in it, and the CPython ecosystem does a really good job in providing tools that make code run fast that needs to, be it due to efficient usage of I/O, CPU, memory, or whatever. I'm not trying to put down the achievements of the author of the cited thesis, not at all. I'm sure the results are interesting for some people and for some kinds of applications, just like the different Python implementations are interesting for some people and some applications. But an awful lot of existing apps won't benefit at all from a fast CLI based Python implementation, simply because it doesn't have access (or at least no efficient access) to many of the existing tools in the CPython ecosystem. >> The simple fact is that there are far more important things for Python >> developers to spend their time and effort on than optimizations like >> this. > > I don't know, there's seem to be an awful lot of effort going into > addressing exactly this issue (eg. PyPy, Pscyo, Unladen Swallow, > Shedskin....) Those are very different efforts that address very different issues. > All those compilers that offer loop unrolling are therefore wasting > their time... Sometimes they do, yes. Stefan From nad at acm.org Sun Sep 5 15:57:41 2010 From: nad at acm.org (Ned Deily) Date: Sun, 05 Sep 2010 12:57:41 -0700 Subject: Python 2.7 module path problems on OS X References: Message-ID: In article , Nicholas Cole wrote: > On Sun, Sep 5, 2010 at 10:20 AM, Ned Deily wrote: > > I'm not sure why you think it is broken. ?The Apple 2.6 and the > > python.org 2.7 have different site-package directories in different > > locations. ?That is to be expected. ?The Apple-supplied Python comes > > with some additional packages pre-installed, like setuptools, PyObjC, > > and wx. ?But you would need to install new versions of these for 2.7 > > anyway. > > > Sorry. I wasn't clear. Of course I understand that each version of > python needs its own additional packages, and I was expecting to > re-install them. But I don't want to install system-wide -- I'd like > to have my own, user-specific, site-packages. On previous versions of > python, I've installed into > ~/Library/Python/$py_version_short/site-packages under my home > directory. > > In my recollection, this has worked in the past for python installed > from python.org, but perhaps that recollection is wrong. At any rate, > it doesn't work with python 2.7. Ah, my apologies. I overlooked the "~/Library" part. So what you have been using is the setuptools Mac OS X "User" Installation configuration: (http://peak.telecommunity.com/DevCenter/EasyInstall#mac-os-x-user-instal lation). Yes, it seems an incompatibility has been introduced in 2.7 for OS X. There has been an on-going and as yet unresolved discussion on the python-dev list about the topic of user directory and config file locations so things will likely change and get more consistent in the future. But this particular problem is more immediate. I believe the problem here is that the default user directory path was changed between 2.6 and 2.7 from: ~/Library/Python/m.n/site-packages to ~/Library/Python/m.n/lib/python/site-packages I will track that down further and open an issue for it, if necessary. In the meantime, here's a little snippet that I think should work around the problem for the moment without requiring a change to your configuration files. (For simplicity of installation, it uses the Distribute fork of setuptools). The main point is to create a symlink between the old and new locations. Let me know if this works for you: $ cat .pydistutils.cfg [install] install_lib = ~/Library/Python/$py_version_short/site-packages install_scripts = ~/bin $ rm -r ~/Library/Python/2.7 # REMOVES ANY EXISTING LOCAL PACKAGES $ mkdir -p ~/Library/Python/2.7/lib/python/site-packages $ ( cd ~/Library/Python/2.7 ; ln -s lib/python/site-packages site-packages ) $ curl -s http://python-distribute.org/distribute_setup.py -o /tmp/distr.py $ python2.7 /tmp/distr.py Extracting in /var/folders/pD/pD-bOKKQHluYv0YkNWJhPE+++TI/-Tmp-/tmpF5sVf7 Now working in /var/folders/pD/pD-bOKKQHluYv0YkNWJhPE+++TI/-Tmp-/tmpF5sVf7/distribute-0. 6.14 Installing Distribute [...] $ ~/bin/easy_install easy_install easy_install-2.6 easy_install-2.7 $ ~/bin/easy_install-2.7 appscript [...] $ python2.7 -c "from appscript import *;print(app('Finder').version())" 10.5.8 $ ls -l ~/Library/Python/2.7 total 8 drwxr-x--- 3 nad staff 102 Sep 5 12:20 lib/ lrwxr-x--- 1 nad staff 24 Sep 5 12:20 site-packages@ -> lib/python/site-packages $ ls -L ~/Library/Python/2.7/site-packages appscript-0.21.1-py2.7-macosx-10.3-fat.egg/ easy-install.pth distribute-0.6.14-py2.7.egg/ setuptools.pth -- Ned Deily, nad at acm.org From speeze.pearson at gmail.com Sun Sep 5 16:19:46 2010 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Sun, 5 Sep 2010 13:19:46 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' Message-ID: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Hi! I'm writing a package with several files in it, and I've found that "isinstance" doesn't work the way I expect under certain circumstances. Short example: here are two files. # fileone.py import filetwo class AClass( object ): pass if __name__ == '__main__': a = AClass() filetwo.is_aclass( a ) # filetwo.py import fileone def is_aclass( a ): print "The argument is", ("" if isinstance(a, fileone.AClass) else "not"), "an instance of fileone.AClass" If you run fileone.py, it will tell you that "The argument is not an instance of fileone.AClass", which seems strange to me, given that the fileone module is the one that CREATES the object with its own AClass class. And if you replace "if __name__ == '__main__'" with "def main()", start Python, import fileone, and call fileone.main(), it tells you that the argument IS an instance of AClass. So, the module's name change to __main__ when you run it on its own... well, it looks like it puts all of the things defined in fileone in the __main__ namespace INSTEAD of in the fileone module's namespace, and then when filetwo imports fileone, the class is created again, this time as fileone.AClass, and though it's identical in function to __main__.AClass, one "is not" the other. Is this kind of doubled-back 'isinstance' inherently sinful? I mean, I could solve this problem by giving all of my classes "classname" attributes or something, but maybe it's just a sign that I shouldn't have to do this in the first place. From arnodel at googlemail.com Sun Sep 5 17:18:25 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 05 Sep 2010 22:18:25 +0100 Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: Spencer Pearson writes: > Hi! I'm writing a package with several files in it, and I've found > that "isinstance" doesn't work the way I expect under certain > circumstances. > > Short example: here are two files. > # fileone.py > import filetwo > > class AClass( object ): > pass > > if __name__ == '__main__': > a = AClass() > filetwo.is_aclass( a ) > > # filetwo.py > > import fileone > > def is_aclass( a ): > print "The argument is", ("" if isinstance(a, fileone.AClass) else > "not"), "an instance of fileone.AClass" > > > If you run fileone.py, it will tell you that "The argument is not an > instance of fileone.AClass", which seems strange to me, given that the > fileone module is the one that CREATES the object with its own AClass > class. And if you replace "if __name__ == '__main__'" with "def > main()", start Python, import fileone, and call fileone.main(), it > tells you that the argument IS an instance of AClass. > > So, the module's name change to __main__ when you run it on its own... > well, it looks like it puts all of the things defined in fileone in > the __main__ namespace INSTEAD of in the fileone module's namespace, > and then when filetwo imports fileone, the class is created again, > this time as fileone.AClass, and though it's identical in function to > __main__.AClass, one "is not" the other. > > Is this kind of doubled-back 'isinstance' inherently sinful? I mean, I > could solve this problem by giving all of my classes "classname" > attributes or something, but maybe it's just a sign that I shouldn't > have to do this in the first place. The behaviour is normal. I suppose you could do something like this (untested): # fileone.py if __name__ == '__main__': from fileone import * a = AClass() filetwo.is_aclass( a ) import sys; sys.exit() import filetwo class AClass( object ): pass -- Arnaud From raoulbia at gmail.com Sun Sep 5 17:47:33 2010 From: raoulbia at gmail.com (Baba) Date: Sun, 5 Sep 2010 14:47:33 -0700 (PDT) Subject: accessing a text file Message-ID: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> level: beginner how can i access the contents of a text file in Python? i would like to compare a string (word) with the content of a text file (word_list). i want to see if word is in word_list. let's assume the TXT file is stored in the same directory as the PY file. def is_valid_word(word, word_list) thanks Baba From nitinpawar432 at gmail.com Sun Sep 5 17:59:23 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Mon, 6 Sep 2010 03:29:23 +0530 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: may be something like this f = open ("file",r) data = f.read() f.close if word in data: print word, "is present in file" On Mon, Sep 6, 2010 at 3:17 AM, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Sun Sep 5 18:01:19 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 5 Sep 2010 18:01:19 -0400 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba > -- > http://mail.python.org/mailman/listinfo/python-list > Please do us a favor and at least try to figure things out on your own, rather than coming here every time you have a question. The very first result when you try searching "python read text file" is the section in the Python tutorial that explains how to do this. http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files From seth at sthrs.me Sun Sep 5 18:04:12 2010 From: seth at sthrs.me (Seth Rees) Date: Sun, 05 Sep 2010 17:04:12 -0500 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: On 09/05/10 16:47, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba f = open('text.txt') data = f.read() # You may want to convert it to a list data = data.split() # Returns true if word is in data, false otherwise word in data From python at mrabarnett.plus.com Sun Sep 5 18:05:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Sep 2010 23:05:12 +0100 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: <4C841418.4050903@mrabarnett.plus.com> On 05/09/2010 22:47, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > That's a very basic question. I suggest you read a tutorial such as "Dive Into Python": http://diveintopython.org/toc/index.html > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > From alex.kapps at web.de Sun Sep 5 18:06:49 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Mon, 06 Sep 2010 00:06:49 +0200 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: <4C841479.7050404@web.de> Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba Completely untested: def is_valid_word(word, filename): for line in open(filename): if word in line.split(): return True return False From bussiere at gmail.com Sun Sep 5 18:57:30 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Mon, 6 Sep 2010 00:57:30 +0200 Subject: include a file in a python program Message-ID: i've got a python.txt that contain python and it must stay as it (python.txt) how can i include it in my program ? import python.txt doesn't work is there a way : a) to make an include("python.txt") b) tell him to treat .txt as .py file that i can make an import python ? i'am using python3 Regards Bussiere fan of torchwood Google Fan boy From zhushazang at yahoo.com.br Sun Sep 5 19:00:10 2010 From: zhushazang at yahoo.com.br (Zhu Sha Zang) Date: Sun, 05 Sep 2010 20:00:10 -0300 Subject: accessing a text file In-Reply-To: <4C841479.7050404@web.de> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <4C841479.7050404@web.de> Message-ID: <4C8420FA.1070903@yahoo.com.br> Em 05-09-2010 19:06, Alexander Kapps escreveu: > Baba wrote: >> level: beginner >> >> how can i access the contents of a text file in Python? >> >> i would like to compare a string (word) with the content of a text >> file (word_list). i want to see if word is in word_list. let's assume >> the TXT file is stored in the same directory as the PY file. >> >> def is_valid_word(word, word_list) >> >> >> thanks >> Baba > > > Completely untested: > > def is_valid_word(word, filename): > for line in open(filename): > if word in line.split(): > return True > return False Damn, easy like C/C++/Java Thanks a lot! -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 19:06:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 23:06:29 GMT Subject: doctest annoyance/puzzle References: <4c83b795$0$28657$c3e8da3@news.astraweb.com> <4C83C82B.5030108@sschwarzer.net> Message-ID: <4c842275$0$28657$c3e8da3@news.astraweb.com> On Sun, 05 Sep 2010 18:41:15 +0200, Stefan Schwarzer wrote: > Hi Steven, > > On 2010-09-05 17:30, Steven D'Aprano wrote: >> I run the doctests with: >> >> python2.6 -m doctest examples.txt >> >> and the first example passes, but the second fails with NameError: >> make_spam not defined. > > I run my doctests by calling > > doctest.testfile(filename) > > for each file in a loop. This way, names and their associated objects > survice from one code block to the next. That's fine if you're calling it from Python, but I want a way to run the tests from the shell, and the advertised way to do that is by calling doctest.py as a script. The module calls testfile, so it should work. And now it's working for me. I have *no idea* what happened there... it wasn't working for me before, and now it is. Sorry for the noise :( -- Steven From pavlovevidence at gmail.com Sun Sep 5 19:09:12 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 5 Sep 2010 16:09:12 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: On Sep 5, 1:19?pm, Spencer Pearson wrote: > Hi! I'm writing a package with several files in it, and I've found > that "isinstance" doesn't work the way I expect under certain > circumstances. > > Short example: here are two files. > # fileone.py > import filetwo > > class AClass( object ): > ? pass > > if __name__ == '__main__': > ? a = AClass() > ? filetwo.is_aclass( a ) > > # filetwo.py > > import fileone > > def is_aclass( a ): > ? print "The argument is", ("" if isinstance(a, fileone.AClass) else > "not"), "an instance of fileone.AClass" > > If you run fileone.py, it will tell you that "The argument is not an > instance of fileone.AClass", which seems strange to me, given that the > fileone module is the one that CREATES the object with its own AClass > class. And if you replace "if __name__ == '__main__'" with "def > main()", start Python, import fileone, and call fileone.main(), it > tells you that the argument IS an instance of AClass. > > So, the module's name change to __main__ when you run it on its own... > well, it looks like it puts all of the things defined in fileone in > the __main__ namespace INSTEAD of in the fileone module's namespace, > and then when filetwo imports fileone, the class is created again, > this time as fileone.AClass, and though it's identical in function to > __main__.AClass, one "is not" the other. Correct. Python always treats the main script as a module called __main__. If you then try to import the main script file from another module, Python will actually import it again with whatever its usual name is. This is easily one of the most confusing and unfortunate aspects of Python. > Is this kind of doubled-back 'isinstance' inherently sinful? I mean, I > could solve this problem by giving all of my classes "classname" > attributes or something, but maybe it's just a sign that I shouldn't > have to do this in the first place. Even if there are better ways than isinstance, the weird behavior of __main__ shouldn't be the reason not to use it. My recommendation for most programmers is to treat Python files either as scripts (which you start Python interpreter with) or modules (which you import from within Python); never both. Store most functionality in modules and keep startup scripts small. If you do this, the weird semantics of __main__ is a moot point. If you want to be able to run a module as a script while avoiding side effects due to it being named __main__, the easiest thing to do is to put something like the following boilerplate at the top of the module (this causes the module to rename itself). import sys if __name__ == '__main__': is_main = True # since you're overwriting __name__ you'll need this later __name__ = 'foo' sys.modules['foo'] = sys.modules['__main__'] else: is_main = False All of this gets a lot more complicated when packages are involved. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 19:12:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 23:12:19 GMT Subject: include a file in a python program References: Message-ID: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> On Mon, 06 Sep 2010 00:57:30 +0200, bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it > (python.txt) Why? Is it against the law to change it? *wink* > how can i include it in my program ? > import python.txt doesn't work You could write a custom importer to handle it, but I can't help you with that. Try Google. > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? fp = open("python.txt") text = fp.read() fp.close() exec(text) But keep in mind that the contents of python.txt will be executed as if you had typed it yourself. If you don't trust the source with your life (or at least with the contents of your computer), don't execute it. -- Steven From roy at panix.com Sun Sep 5 19:14:52 2010 From: roy at panix.com (Roy Smith) Date: Sun, 05 Sep 2010 19:14:52 -0400 Subject: include a file in a python program References: Message-ID: In article , bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it (python.txt) > > how can i include it in my program ? > import python.txt doesn't work > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? > i'am using python3 The simple solution (at least for unix-ish systems) would be to make a symlink python.py -> python.txt. If you don't have the ability to do that externally, you could even have your python program create the symlink on the fly, import the module, then delete the symlink. The symlink could even be in /tmp. Another possible solution is to read the entire file into a string and then eval() the string. I'm assuming eval() still exists in python 3; does it? Yet another possibility (never tried this, but it seems reasonable) would be to compile() your text file (http://docs.python.org/py3k/library/functions.html#compile). Of course, it would be a lot easier if you just renamed the file, but I'll take it as a given that there are external forces which prevent you from doing that. From roy at panix.com Sun Sep 5 19:17:09 2010 From: roy at panix.com (Roy Smith) Date: Sun, 05 Sep 2010 19:17:09 -0400 Subject: include a file in a python program References: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> Message-ID: In article <4c8423d3$0$28657$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > fp = open("python.txt") > text = fp.read() > fp.close() > exec(text) > But keep in mind that the contents of python.txt will be executed as if > you had typed it yourself. If you don't trust the source with your life > (or at least with the contents of your computer), don't execute it. Well, this is true, but eval() or exec() isn't really exposing him to anything that import isn't. From python at mrabarnett.plus.com Sun Sep 5 19:27:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Sep 2010 00:27:13 +0100 Subject: include a file in a python program In-Reply-To: References: Message-ID: <4C842751.7090105@mrabarnett.plus.com> On 05/09/2010 23:57, bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it (python.txt) > > how can i include it in my program ? > import python.txt doesn't work > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? > i'am using python3 import imp python = imp.load_source("python", "python.txt") > Regards > Bussiere > fan of torchwood > Google Fan boy A fan of Torchwood and Google, but not Python? :-) From tjreedy at udel.edu Sun Sep 5 19:39:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Sep 2010 19:39:31 -0400 Subject: include a file in a python program In-Reply-To: References: Message-ID: On 9/5/2010 6:57 PM, bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it (python.txt) If you are working for someone who is such an idiot as to impose such a condition on you, you have our condolences. > how can i include it in my program ? > import python.txt doesn't work A file run directly as a script can be named anything. But as far as I know, imported code must be xxx.py, either in a directory or zipfile. > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? 1. Write a custom importer (hard, I have no idea how). 2. Copy the .txt file to .py, either before running the main program or within a custom import function. -- Terry Jan Reedy From tjreedy at udel.edu Sun Sep 5 19:41:39 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Sep 2010 19:41:39 -0400 Subject: include a file in a python program In-Reply-To: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> References: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 9/5/2010 7:12 PM, Steven D'Aprano wrote: > fp = open("python.txt") > text = fp.read() > fp.close() > exec(text) > > But keep in mind that the contents of python.txt will be executed as if > you had typed it yourself. If you don't trust the source with your life > (or at least with the contents of your computer), don't execute it. Also, this executes the code within the namespace of the calling code rather than within a fresh module namespace. That could be either better or worse. -- Terry Jan Reedy From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 19:45:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 23:45:25 GMT Subject: include a file in a python program References: Message-ID: <4c842b95$0$28657$c3e8da3@news.astraweb.com> On Mon, 06 Sep 2010 00:27:13 +0100, MRAB wrote: > import imp > python = imp.load_source("python", "python.txt") Nice! -- Steven From davea at ieee.org Sun Sep 5 20:07:32 2010 From: davea at ieee.org (Dave Angel) Date: Sun, 05 Sep 2010 20:07:32 -0400 Subject: Class changes in circular imports when __name__ == '__main__' In-Reply-To: References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: <4C8430C4.6000206@ieee.org> On 2:59 PM, Carl Banks wrote: > On Sep 5, 1:19 pm, Spencer Pearson wrote: >> Hi! I'm writing a package with several files in it, and I've found >> that "isinstance" doesn't work the way I expect under certain >> circumstances. >> >> Short example: here are two files. >> # fileone.py >> import filetwo >> >> class AClass( object ): >> pass >> >> if __name__ ='__main__': >> a =Class() >> filetwo.is_aclass( a ) >> >> # filetwo.py >> >> import fileone >> >> def is_aclass( a ): >> print "The argument is", ("" if isinstance(a, fileone.AClass) else >> "not"), "an instance of fileone.AClass" >> >> If you run fileone.py, it will tell you that "The argument is not an >> instance of fileone.AClass", which seems strange to me, given that the >> fileone module is the one that CREATES the object with its own AClass >> class. And if you replace "if __name__ ='__main__'" with "def >> main()", start Python, import fileone, and call fileone.main(), it >> tells you that the argument IS an instance of AClass. >> >> So, the module's name change to __main__ when you run it on its own... >> well, it looks like it puts all of the things defined in fileone in >> the __main__ namespace INSTEAD of in the fileone module's namespace, >> and then when filetwo imports fileone, the class is created again, >> this time as fileone.AClass, and though it's identical in function to >> __main__.AClass, one "is not" the other. > Correct. Python always treats the main script as a module called > __main__. If you then try to import the main script file from another > module, Python will actually import it again with whatever its usual > name is. > > This is easily one of the most confusing and unfortunate aspects of > Python. > > >> Is this kind of doubled-back 'isinstance' inherently sinful? I mean, I >> could solve this problem by giving all of my classes "classname" >> attributes or something, but maybe it's just a sign that I shouldn't >> have to do this in the first place. > Even if there are better ways than isinstance, the weird behavior of > __main__ shouldn't be the reason not to use it. > > My recommendation for most programmers is to treat Python files either > as scripts (which you start Python interpreter with) or modules (which > you import from within Python); never both. Store most functionality > in modules and keep startup scripts small. If you do this, the weird > semantics of __main__ is a moot point. > > If you want to be able to run a module as a script while avoiding side > effects due to it being named __main__, the easiest thing to do is to > put something like the following boilerplate at the top of the module > (this causes the module to rename itself). > > import sys > if __name__ ='__main__': > is_main =rue # since you're overwriting __name__ you'll need > this later > __name__ =foo' > sys.modules['foo'] =ys.modules['__main__'] > else: > is_main =alse > > > All of this gets a lot more complicated when packages are involved. > > > Carl Banks > Perhaps a better answer would be to import __main__ from the second module. But to my way of thinking, the answer should be to avoid ever having circular imports. This is just the most blatant of the problems that circular imports can cause. I don't know of any cases where circular dependencies are really necessary, but if one decides to use them, then two things should be done: 1) do almost nothing in top-level code in any module involved in such circular dependency. Top-level should have all of the imports, and none of the executable code. 2) do not ever involve the startup script in the loop. If necessary, make it two lines, importing,then calling the real mainline. DaveA From jason.heeris at gmail.com Sun Sep 5 20:57:10 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 5 Sep 2010 17:57:10 -0700 (PDT) Subject: Subclassing by monkey-patching References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> Message-ID: On Sep 5, 6:56?pm, Peter Otten <__pete... at web.de> wrote: > Does it have to be gio.FileMonitor? pyinotify can automatically add new > subdirectories out of the box. Well, since it's for a core part of the software, I'd like it to be cross platform ? not in the sense of Windows/Mac, but FreeBSD, Solaris, etc. But it's looking more and more like I should give up that particular goal. Cheers, Jason From jrmy.lnrd at gmail.com Sun Sep 5 21:06:44 2010 From: jrmy.lnrd at gmail.com (genxtech) Date: Sun, 5 Sep 2010 18:06:44 -0700 (PDT) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: On Sep 5, 4:16?am, Peter Otten <__pete... at web.de> wrote: > genxtech wrote: > > Hello. ?I am still really new to python and I have a project where I > > am trying to use the data files from another program and write a new > > program with new user interface and all. ?My first step was to open > > one of the files in 'rb' mode and print the contents, but I am > > unfamiliar with the format. ?Here is what was printed to the terminal: > > > b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f > > \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y > > \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$ > > \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n > > \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc > > \x00\x00\x0c\x19\x00\x00' > > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > > Any advise on how to decode the data would be greatly appreciated. > > What's the name of the file? > What's the program that uses the file? > If the source code is available, what library does that program use to read > the file? > > Peter Unfortunately the source code isn't available, so I'm trying to figure out a way to get the format of the file on my own. From jason.heeris at gmail.com Sun Sep 5 22:29:31 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 5 Sep 2010 19:29:31 -0700 (PDT) Subject: Subclassing by monkey-patching References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> Message-ID: On Sep 6, 8:57?am, Jason wrote: > But it's looking more and more like I should give up > that particular goal. ...buuuuut on the other hand I just knocked together a pyinotify threaded watch system in about 50 lines. It's tempting to tell users of other platforms to write their own and submit a patch. Maybe this is all barking up the wrong tree. Cheers, Jason From pavlovevidence at gmail.com Sun Sep 5 23:15:20 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 5 Sep 2010 20:15:20 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: On Sep 5, 5:07?pm, Dave Angel wrote: > On 2:59 PM, Carl Banks wrote: > > All of this gets a lot more complicated when packages are involved. > > Perhaps a better answer would be to import __main__ from the second module. Then what if the module is imported from a different script? It'll try to import __main__ but get a different script than expected. > But to my way of thinking, the answer should be to avoid ever having > circular imports. ?This is just the most blatant of the problems that > circular imports can cause. > > I don't know of any cases where circular dependencies are really > necessary, but if one decides to use them, then two things should be done: I don't think they're ever necessary but sometimes it's convenient. This could be one of those cases. One of the less misguided reasons to invoke a module as a script is to run tests on the module. When you do that you might need to call an outside module to set up a test environment, and that module might happen to import the calling module. You could refactor the test to avoid the circular import, but that kind of defeats the convenience of stowing the test in the module. > 1) do almost nothing in top-level code in any module involved in such > circular dependency. ?Top-level should have all of the imports, and none > of the executable code. > 2) do not ever involve the startup script in the loop. ?If necessary, > make it two lines, importing,then calling the real mainline. All good advice for that situation. I would add that if you define a base class in one module and subclass in another, you want to keep those modules out of cycles. The problem with circular imports is that you don't usually know what order the modules will be imported, but you need to be sure the base class is defined when you subclass. (I learned that lesson the hard way, and I had to hack up an import hook to enforce that imports occurred in the correct order.) Carl Banks From antonyjeevaraj at rediffmail.com Mon Sep 6 00:26:33 2010 From: antonyjeevaraj at rediffmail.com (jameser) Date: Sun, 5 Sep 2010 21:26:33 -0700 (PDT) Subject: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV Message-ID: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV Generate $50 to $100 whenever you have a couple of hours free time to spare. You could make $50 or more in the next 2 hours. Starting right Now!Today! GET PAID TO: Take online surveys and make from $5 to $75, or more Participate in focus groups and make up to $150 an hour Take phone surveys and you can earn as much as $120 an hour Try new products (and keep the free products too) Preview new movie trailers for $4 to $25 an hour http://snipurl.com/11i6lw Earn from your free website Awesome earnings get paid for your honest work Join as a free member and get paid to your bank account To join the Network follow the link http://snipurl.com/11i6lw Get paid for your real work and earn awesome $$$$ From niklasro at gmail.com Mon Sep 6 03:50:29 2010 From: niklasro at gmail.com (Niklasro(.appspot)) Date: Mon, 6 Sep 2010 00:50:29 -0700 (PDT) Subject: include a file in a python program References: Message-ID: On Sep 5, 10:57?pm, bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it (python.txt) > > how can i include it in my program ? > import python.txt doesn't work > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? > i'am using python3 > Regards > Bussiere > fan of torchwood > Google Fan boy You can do it with tkinter to also enable GUI. From niklasro at gmail.com Mon Sep 6 03:52:12 2010 From: niklasro at gmail.com (Niklasro(.appspot)) Date: Mon, 6 Sep 2010 00:52:12 -0700 (PDT) Subject: Learning variable visibility Message-ID: Hi How do I declare a variable visibility across files? Will import name where name is name of the file do? Thanks for instructing Niklas Rosencrantz From niklasro at gmail.com Mon Sep 6 03:54:33 2010 From: niklasro at gmail.com (Niklasro) Date: Mon, 6 Sep 2010 00:54:33 -0700 (PDT) Subject: GUibuilder evaluation Message-ID: Hello Making a GUI, could you recommend tkinter or any other proposal? Thanks From raoulbia at gmail.com Mon Sep 6 03:55:28 2010 From: raoulbia at gmail.com (Baba) Date: Mon, 6 Sep 2010 00:55:28 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> On 6 sep, 00:01, Benjamin Kaplan wrote: > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > > level: beginner > > > how can i access the contents of a text file in Python? > > > i would like to compare a string (word) with the content of a text > > file (word_list). i want to see if word is in word_list. let's assume > > the TXT file is stored in the same directory as the PY file. > > > def is_valid_word(word, word_list) > > > thanks > > Baba > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Please do us a favor and at least try to figure things out on your > own, rather than coming here every time you have a question. The very > first result when you try searching "python read text file" is the > section in the Python tutorial that explains how to do this. > > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... Hi Benjamin I did find that page prior to posting the question but i still wanted to have a second opinion to complement that info so as to make things easier The first line of my post clearly states that i am a beginner. It's nice to provide links which can help answer the question but please be so polite and keep personal comments for yourself. To all other respondants: thank you for your kind instructions and directions. Thanks Baba From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 6 04:08:06 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 06 Sep 2010 10:08:06 +0200 Subject: Subclassing by monkey-patching In-Reply-To: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> Message-ID: <4c84a166$0$499$426a74cc@news.free.fr> Jason a ?crit : > On Sep 5, 3:53 pm, Peter Otten <__pete... at web.de> wrote: >>>>> m = gio.File(".").monitor_directory() >>>>> C = type(m) > > 'C' will not necessarily be 'gio.FileMonitor' ? I think the internals > of the GIO methods might further "subclass" it in some way depending > on what underlying monitors are available. > >> A possible alternative may be a class that wraps a FileMonitor instead of >> subclassing it. > > I've been avoiding this because it involves a lot of boilerplate: the > signals needs to be replicated and passed through, same for all > GObject properties, same for the usual methods. Python is not Java !-) http://docs.python.org/reference/datamodel.html#object.__getattr__ From raoulbia at gmail.com Mon Sep 6 04:10:28 2010 From: raoulbia at gmail.com (Baba) Date: Mon, 6 Sep 2010 01:10:28 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: <44cb0ed6-63ca-4c1a-8501-e284010993fa@v41g2000yqv.googlegroups.com> On 6 sep, 00:04, Seth Rees wrote: > On 09/05/10 16:47, Baba wrote: > > > level: beginner > > > how can i access the contents of a text file in Python? > > > i would like to compare a string (word) with the content of a text > > file (word_list). i want to see if word is in word_list. let's assume > > the TXT file is stored in the same directory as the PY file. > > > def is_valid_word(word, word_list) > > > thanks > > Baba > > ? ?f = open('text.txt') > ? ?data = f.read() > ? ?# You may want to convert it to a list > ? ?data = data.split() > ? ?# Returns true if word is in data, false otherwise > ? ?word in data Thanks Seth! From georg at python.org Mon Sep 6 04:22:17 2010 From: georg at python.org (Georg Brandl) Date: Mon, 06 Sep 2010 10:22:17 +0200 Subject: [RELEASED] Python 3.2 alpha 2 Message-ID: <4C84A4B9.2040406@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the second 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) iEYEARECAAYFAkyEpLkACgkQN9GcIYhpnLCzSwCdFyPz1dPEehJZmeW8wDltqkqe /ogAnim1J99qDpeLmcUDTf0YBh1W95vf =x+ee -----END PGP SIGNATURE----- From nicholas.cole at gmail.com Mon Sep 6 04:29:48 2010 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Mon, 6 Sep 2010 09:29:48 +0100 Subject: Python 2.7 module path problems on OS X In-Reply-To: References: Message-ID: On Sun, Sep 5, 2010 at 8:57 PM, Ned Deily wrote: > In article > , > ?Nicholas Cole wrote: > >> On Sun, Sep 5, 2010 at 10:20 AM, Ned Deily wrote: >> > I'm not sure why you think it is broken. ?The Apple 2.6 and the >> > python.org 2.7 have different site-package directories in different >> > locations. ?That is to be expected. ?The Apple-supplied Python comes >> > with some additional packages pre-installed, like setuptools, PyObjC, >> > and wx. ?But you would need to install new versions of these for 2.7 >> > anyway. >> > >> Sorry. I wasn't clear. ?Of course I understand that each version of >> python needs its own additional packages, and I was expecting to >> re-install them. ?But I don't want to install system-wide -- ?I'd like >> to have my own, user-specific, site-packages. ?On previous versions of >> python, I've ?installed into >> ~/Library/Python/$py_version_short/site-packages under my home >> directory. >> >> In my recollection, this has worked in the past for python installed >> from python.org, but perhaps that recollection is wrong. ?At any rate, >> it doesn't ?work with python 2.7. > > Ah, my apologies. ?I overlooked the "~/Library" part. ?So what you have > been using is the setuptools Mac OS X "User" Installation configuration: > (http://peak.telecommunity.com/DevCenter/EasyInstall#mac-os-x-user-instal > lation). ? Yes, it seems an incompatibility has been introduced in 2.7 > for OS X. ?There has been an on-going and as yet unresolved discussion > on the python-dev list about the topic of user directory and config file > locations so things will likely change and get more consistent in the > future. ?But this particular problem is more immediate. ?I believe the > problem here is that the default user directory path was changed between > 2.6 and 2.7 from: > > ? ?~/Library/Python/m.n/site-packages > > to > > ? ?~/Library/Python/m.n/lib/python/site-packages > > I will track that down further and open an issue for it, if necessary. > In the meantime, here's a little snippet that I think should work around > the problem for the moment without requiring a change to your > configuration files. ?(For simplicity of installation, it uses the > Distribute fork of setuptools). ?The main point is to create a symlink > between the old and new locations. Let me know if this works for you: Dear Ned, Thank you very much for your help and for the code snippet. I don't know enough about the background to open an issue myself, so I am grateful that you might take this on. Just to throw in my $0.02, I do think is important to be able to have a distutils configuration that works across versions (since so many of us have several versions installed for testing purposes), and so I do view this incompatibility is a bug! But thank you very much for solving my immediate problem. Best wishes, Nicholas From wbelguidoum at gmail.com Mon Sep 6 06:15:35 2010 From: wbelguidoum at gmail.com (wissem belguidoum) Date: Mon, 6 Sep 2010 03:15:35 -0700 (PDT) Subject: GUibuilder evaluation References: Message-ID: <4ec74e1e-91fd-4bec-954b-e6b9db468a91@t2g2000yqe.googlegroups.com> On 6 sep, 09:54, Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? > Thanks Hi, I am considering to learn Qt, which is a multi-platform widget liberary and a RAD IDE..., basically for C++ programing but there is a binding called PyQt for python. Good luck. From wbelguidoum at gmail.com Mon Sep 6 06:19:08 2010 From: wbelguidoum at gmail.com (wissem belguidoum) Date: Mon, 6 Sep 2010 03:19:08 -0700 (PDT) Subject: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV References: Message-ID: <7dac7c3d-ae61-4d7e-8f9c-f53e7d9a69d9@11g2000yqq.googlegroups.com> On 6 sep, 06:26, jameser wrote: > MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV > > Generate $50 to $100 whenever you > have a couple of hours free time to spare. > You could make $50 or more in the next 2 hours. > Starting right Now!Today! > > GET PAID TO: > Take online surveys and make from $5 to $75, or more > Participate in focus groups and make up to $150 an hour > Take phone surveys and you can earn as much as $120 an hour > Try new products (and keep the free products too) > Preview new movie trailers for $4 to $25 an hour > > http://snipurl.com/11i6lw > > Earn from your free website > Awesome earnings get paid for your honest work > Join as a free member and get paid to your bank account > To join the Network follow the link > > http://snipurl.com/11i6lw > > Get paid for your real work and earn awesome $$$$ Is this a kind of trap to make an email database ? Reminder : this is a python programming language group. From bartc at freeuk.com Mon Sep 6 06:38:22 2010 From: bartc at freeuk.com (BartC) Date: Mon, 6 Sep 2010 11:38:22 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: "Stefan Behnel" wrote in message news:mailman.470.1283712666.29448.python-list at python.org... > BartC, 05.09.2010 19:09: >> All those compilers that offer loop unrolling are therefore wasting >> their time... > > Sometimes they do, yes. Modifying the OP's code a little: a = 0 for i in xrange(100000000): # 100 million a = a + 10 # add 10 or 100 print a Manually unrolling such a loop four times (ie. 4 copies of the body, and counting only to 25 million) increased the speed by between 16% and 47% (ie. runtime reducing by between 14% and 32%). This depended on whether I added +10 or +100 (ie. whether long integers are needed), whether it was inside or outside a function, and whether I was running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange' as a synonym for 'range'?) These are just some simple tests on my particular machine and implementations, but they bring up some points: (1) Loop unrolling does seem to have a benefit, when the loop body is small. (2) Integer arithmetic seems to go straight from 32-bits to long integers; why not use 64-bits before needing long integers? (3) Since the loop variable is never used, why not have a special loop statement that repeats code so many times? This can be very fast, since the loop counter need not be a Python object, and probably there would be no need for unrolling at all: repeat 100000000: # for example a = a + 10 -- Bartc From yoavglazner at gmail.com Mon Sep 6 06:40:23 2010 From: yoavglazner at gmail.com (Glazner) Date: Mon, 6 Sep 2010 03:40:23 -0700 (PDT) Subject: Subclassing by monkey-patching References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> <4c84a166$0$499$426a74cc@news.free.fr> Message-ID: <1618881c-b5bb-404b-8a7b-2f40c22d2b98@g17g2000yqe.googlegroups.com> On Sep 6, 11:08?am, Bruno Desthuilliers wrote: > Jason a ?crit : > > > On Sep 5, 3:53 pm, Peter Otten <__pete... at web.de> wrote: > >>>>> m = gio.File(".").monitor_directory() > >>>>> C = type(m) > > > 'C' will not necessarily be 'gio.FileMonitor' ? I think the internals > > of the GIO methods might further "subclass" it in some way depending > > on what underlying monitors are available. > > >> A possible alternative may be a class that wraps a FileMonitor instead of > >> subclassing it. > > > I've been avoiding this because it involves a lot of boilerplate: the > > signals needs to be replicated and passed through, same for all > > GObject properties, same for the usual methods. > > Python is not Java !-)http://docs.python.org/reference/datamodel.html#object.__getattr__ Yep, thats what i do... def MySubclass(object): def __init__(self): self._ins = SomeObject() def __getattr__(self,name): return getattr(self._ins,name) From vgnulinux at gmail.com Mon Sep 6 07:02:56 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Mon, 6 Sep 2010 16:32:56 +0530 Subject: Embedded Systems development using Python Message-ID: Hi List, Can Python be used for embedded systems development ? If Yes can anyone point me to a tutorial/reference website which explains about this. Thanks and Regards Vgnu -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.fodrek at stuba.sk Mon Sep 6 07:11:10 2010 From: peter.fodrek at stuba.sk (Peter Fodrek) Date: Mon, 6 Sep 2010 13:11:10 +0200 Subject: Embedded Systems development using Python In-Reply-To: References: Message-ID: <201009061311.10248.peter.fodrek@stuba.sk> On Monday 06 September 2010 13:02:56 VGNU Linux wrote: > Hi List, > Can Python be used for embedded systems development ? It is hard to say yes or no. For hard Real-time systems or hard Real-time parts of complex system answer is no, in another type of embedded systems yes or maybe > If Yes can anyone point me to a tutorial/reference website which explains > about this. There are no tutorials to do so as I know. Peter From stefan_ml at behnel.de Mon Sep 6 07:20:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 06 Sep 2010 13:20:01 +0200 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: BartC, 06.09.2010 12:38: > why doesn't Python 3 just accept 'xrange' as a synonym for 'range'? Because Python 3 deliberately breaks backwards compatibility in order to clean up the language. > These are just some simple tests on my particular machine and > implementations, but they bring up some points: > > (1) Loop unrolling does seem to have a benefit, when the loop body is > small. Nobody said otherwise. However, "small" is a pretty weak characterisation here. And don't expect CPython to do it for you, because doing it automatically requires the ability to see that there are no side effects. It's a lot more costly to assure that than what you actually gain with the optimisation. As your example shows, doing this optimisation manually is pretty straight forward, so there isn't really a need to let the runtime do it for you. > (2) Integer arithmetic seems to go straight from 32-bits to long > integers; why not use 64-bits before needing long integers? You are making assumptions based on Python 2, I guess. Try Python 3.1 or later instead, where the int and long types are unified. Also, the implementation is a bit more complex than you appear to be thinking. Don't forget that it has received serious benchmarking based optimisations. > (3) Since the loop variable is never used, why not have a special loop > statement that repeats code so many times? Because special cases are not special enough to break the rules. As others have stated before, you can use itertools to reduce that part of the looping overhead, if it really hurts your concrete code. There also were lots of examples in this thread on different looping solutions and their performance differences. Any of them may fit your needs in a given situation. > This can be very fast, since > the loop counter need not be a Python object It still has to count, though. Stefan From stefan_ml at behnel.de Mon Sep 6 07:22:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 06 Sep 2010 13:22:58 +0200 Subject: Embedded Systems development using Python In-Reply-To: References: Message-ID: VGNU Linux, 06.09.2010 13:02: > Can Python be used for embedded systems development ? It can and has been. What kind of embedded system with what set of capabilities are you thinking about? TV sets? Mobile phones? Smart dust? Stefan From kushal.kumaran+python at gmail.com Mon Sep 6 07:49:33 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 6 Sep 2010 17:19:33 +0530 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: On Mon, Sep 6, 2010 at 4:08 PM, BartC wrote: > "Stefan Behnel" wrote in message > news:mailman.470.1283712666.29448.python-list at python.org... >> >> BartC, 05.09.2010 19:09: > >>> All those compilers that offer loop unrolling are therefore wasting >>> their time... >> >> Sometimes they do, yes. > > Modifying the OP's code a little: > > a = 0 > for i in xrange(100000000): ? ? ?# 100 million > ? ?a = a + 10 ? ? ? ? ? ? ? ? ?# add 10 or 100 > print a > > Manually unrolling such a loop four times (ie. 4 copies of the body, and > counting only to 25 million) increased the speed by between 16% and 47% (ie. > runtime reducing by between 14% and 32%). > > This depended on whether I added +10 or +100 (ie. whether long integers are > needed), whether it was inside or outside a function, and whether I was > running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange' as a > synonym for 'range'?) > > These are just some simple tests on my particular machine and > implementations, but they bring up some points: > > (1) Loop unrolling does seem to have a benefit, when the loop body is small. > > (2) Integer arithmetic seems to go straight from 32-bits to long integers; > why not use 64-bits before needing long integers? > On 64-bit systems, integer arithmetic will go from 64-bit native integers to long. Will using any emulated 64-bit type on a 32-bit system actually be better than the python long implementation? >From my 64-bit linux system: In [1]: n = 2 ** 40 In [2]: type(n) Out[2]: In [3]: n = 2 ** 80 In [4]: type(n) Out[4]: > (3) Since the loop variable is never used, why not have a special loop > statement that repeats code so many times? This can be very fast, since the > loop counter need not be a Python object, and probably there would be no > need for unrolling at all: > > repeat 100000000: ? ? ? ?# for example > ? a = a + 10 > -- regards, kushal From vgnulinux at gmail.com Mon Sep 6 07:52:09 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Mon, 6 Sep 2010 17:22:09 +0530 Subject: Embedded Systems development using Python In-Reply-To: References: Message-ID: Hi, A small device like a mobile but with only 2 major buttons, with GPS and GPRS capabilities. Can anyone tell me from where to start learning about this ? Regards Vivek On Mon, Sep 6, 2010 at 4:52 PM, Stefan Behnel wrote: > VGNU Linux, 06.09.2010 13:02: > > Can Python be used for embedded systems development ? >> > > It can and has been. > > What kind of embedded system with what set of capabilities are you thinking > about? TV sets? Mobile phones? Smart dust? > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Mon Sep 6 07:56:39 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Sep 2010 13:56:39 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: <20100906135639.61959ec3@pitrou.net> On Mon, 06 Sep 2010 13:20:01 +0200 Stefan Behnel wrote: > > > (2) Integer arithmetic seems to go straight from 32-bits to long > > integers; why not use 64-bits before needing long integers? > > You are making assumptions based on Python 2, I guess. Try Python 3.1 or > later instead, where the int and long types are unified. Also, the > implementation is a bit more complex than you appear to be thinking. Don't > forget that it has received serious benchmarking based optimisations. The optimizations are mainly related to big integer arithmetics, though. For small ints the main cost is interpretation and unboxing overhead as always. Regards Antoine. From joakim.hove at gmail.com Mon Sep 6 08:28:15 2010 From: joakim.hove at gmail.com (Joakim Hove) Date: Mon, 6 Sep 2010 05:28:15 -0700 (PDT) Subject: ctypes and garbage collection Message-ID: <7b7975ef-9948-463d-8eb3-77ba3097f68c@z28g2000yqh.googlegroups.com> Hello, I have used ctypes to wrap a C-library - it has been a really painless experience! The C-library instantiates a quite large "container-like" structure. There are then several functions to inspect the content of the container, get at items and free the whole thing: /* C - code */ c_container_type * c_container_alloc( const char * filename ); c_node_type * c_container_get_node( c_container_type * container , const char * node_id ); void c_container_free( c_container_type * container ); .... Observe that the c_container_get_node() function does _not_ allocate memory, it just returns a opaque handle to a node structure, still fully owned by the container structure. I have wrapped this with Python/ctypes roughly like this (severly trimmed pseudo code): class Container: def __init__(self , filename): self.c_ptr = c_container_alloc( filename ) def __del__( self ): c_container_free( self.c_ptr ) def get_node( self , node_id): Node( c_container_get_node( self , node_id )) class Node: def __init__( self , c_ptr ): self.c_ptr = c_ptr def __del__( self ): pass Now, a use scenario might be like this: 1. Instantiate a Container() instance. 2. Instantiate a Node() instance with the Container.get_node() function. 3. Forget about the Container instance and work happily with the Node instance. 4. Out of the blue comes the gc - and then? Will the Node instance be enough to protect the Container instance from beeing garbage collected? I thought maybe the get_node() function should have something like a incref() call, and the Node.__del__() function a corresponding decref()? Or ?? Regards Joakim Hove From bc at freeuk.com Mon Sep 6 08:32:46 2010 From: bc at freeuk.com (BartC) Date: Mon, 6 Sep 2010 13:32:46 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: "Stefan Behnel" wrote in message news:mailman.485.1283772019.29448.python-list at python.org... > BartC, 06.09.2010 12:38: >> (2) Integer arithmetic seems to go straight from 32-bits to long >> integers; why not use 64-bits before needing long integers? > > You are making assumptions based on Python 2, I guess. Try Python 3.1 or > later instead, where the int and long types are unified. Also, the > implementation is a bit more complex than you appear to be thinking. Don't > forget that it has received serious benchmarking based optimisations. That's true; wider arithmetic was less of an overhead in Python 3. This shows the effect of making several small optimisations which might otherwise be dismissed: with the +100 test, the Python 3 faster wider arithmetic, *plus* the 4x loop unrolling, resulted in an 85% speed increase compared with Python 2 using the original loop. Which is pretty good considering Python 3 is generally slower than '2'. >> This can be very fast, since >> the loop counter need not be a Python object > > It still has to count, though. That might be just a couple of machine instructions. Plus the bytecode overhead. -- Bartc From eckhardt at satorlaser.com Mon Sep 6 09:11:14 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 06 Sep 2010 15:11:14 +0200 Subject: ctypes and garbage collection References: <7b7975ef-9948-463d-8eb3-77ba3097f68c@z28g2000yqh.googlegroups.com> Message-ID: Joakim Hove wrote: > I have used ctypes to wrap a C-library > [...] > Observe that the c_container_get_node() function does _not_ allocate > memory, it just returns a opaque handle to a node structure, still > fully owned by the container structure. [...] > > class Container: > def __init__(self , filename): > self.c_ptr = c_container_alloc( filename ) > > def __del__( self ): > c_container_free( self.c_ptr ) > > def get_node( self , node_id): > Node( c_container_get_node( self , node_id )) > > > class Node: > def __init__( self , c_ptr ): > self.c_ptr = c_ptr > > def __del__( self ): > pass > > > Now, a use scenario might be like this: > > 1. Instantiate a Container() instance. > 2. Instantiate a Node() instance with the Container.get_node() > function. > 3. Forget about the Container instance and work happily with the Node > instance. > 4. Out of the blue comes the gc - and then? Will the Node instance be > enough to protect the Container instance from beeing garbage > collected? No. You should be able to even see that by logging calls to alloc/free of your library. > I thought maybe the get_node() function should have something like a > incref() call, and the Node.__del__() function a corresponding > decref()? Or ?? I'd add an "__owner" field to the node, initialised with the owning container instance. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From joakim.hove at gmail.com Mon Sep 6 09:22:22 2010 From: joakim.hove at gmail.com (Joakim Hove) Date: Mon, 6 Sep 2010 06:22:22 -0700 (PDT) Subject: ctypes and garbage collection References: <7b7975ef-9948-463d-8eb3-77ba3097f68c@z28g2000yqh.googlegroups.com> Message-ID: <95c2745a-637f-4e98-b6f2-d6a83d006d11@i5g2000yqe.googlegroups.com> > I'd add an "__owner" field to the node, initialised with the owning > container instance. I will - thank you! Joakim From solipsis at pitrou.net Mon Sep 6 09:30:51 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Sep 2010 15:30:51 +0200 Subject: Embedded Systems development using Python References: Message-ID: <20100906153051.2537c9d0@pitrou.net> On Mon, 6 Sep 2010 17:22:09 +0530 VGNU Linux wrote: > Hi, > > A small device like a mobile but with only 2 major buttons, with GPS and > GPRS capabilities. > Can anyone tell me from where to start learning about this ? Read the official docs for the C API: http://docs.python.org/extending/embedding.html http://docs.python.org/extending/index.html http://docs.python.org/c-api/ You'll probably need at least a 32-bit CPU and some non-negligible amount of RAM. If not, then you'll want to take a look at alternatve implementations of Python: http://wiki.python.org/moin/EmbeddedPython Regards Antoine. From denisg640 at gmail.com Mon Sep 6 09:47:19 2010 From: denisg640 at gmail.com (Denis Gomes) Date: Mon, 6 Sep 2010 09:47:19 -0400 Subject: GUibuilder evaluation In-Reply-To: <4ec74e1e-91fd-4bec-954b-e6b9db468a91@t2g2000yqe.googlegroups.com> References: <4ec74e1e-91fd-4bec-954b-e6b9db468a91@t2g2000yqe.googlegroups.com> Message-ID: Hello, There are really three you can choose from if you are serious about making GUI applications. PyQt as already suggested. wxPython and pyGTK. Tkinter is good in my opinion if you are making smaller gui based programs. PyQt has an extensive number of additional features, including networking, OpenGL, Multimedia, Database etc. It is used for the KDE desktop environment. PyQt has a very powerful Designer which you can used to generate python code very fast for complex guis. wxPython is only GUI centric, but it does have a host of widgets you can play with and pre-made examples you can use to speed up your programming. It also has a gui building called Boa Constructor which is functional but not in the same class as the qt designer (this is my opinion, try it). As for pyGTK, it is used for Gnome. I am not to familiar with it but it looks like a good gui toolkit as well. So my advice is to try all three and see which one you like the best and go from there. Denis On Mon, Sep 6, 2010 at 6:15 AM, wissem belguidoum wrote: > On 6 sep, 09:54, Niklasro wrote: > > Hello > > Making a GUI, could you recommend tkinter or any other proposal? > > Thanks > > Hi, > > I am considering to learn Qt, which is a multi-platform widget > liberary and a RAD IDE..., > basically for C++ programing but there is a binding called PyQt for > python. > > Good luck. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ctops.legal at gmail.com Mon Sep 6 09:49:14 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Mon, 6 Sep 2010 06:49:14 -0700 (PDT) Subject: Python [repair_cycorder_mov.py] References: <4c83a283$0$28657$c3e8da3@news.astraweb.com> Message-ID: <7b9d1b08-26a8-45f8-b429-7bc57d74b17f@11g2000yqq.googlegroups.com> On Sep 5, 12:23?pm, Albert Hopkins wrote: > On Sun, 2010-09-05 at 14:00 +0000, Steven D'Aprano wrote: > > By the way, there's no need to send three messages in 10 minutes > > asking > > the same question, and adding FORM METHOD links to your post will > > probably just get it flagged as spam by many people. > > Apparently it has, as I only got this response. Yea I guess I need to get my Forte Agent out and dust it off. From ian at ianhobson.co.uk Mon Sep 6 10:29:44 2010 From: ian at ianhobson.co.uk (Ian Hobson) Date: Mon, 06 Sep 2010 15:29:44 +0100 Subject: redirecting stdout and stderr for a windows service Message-ID: <4C84FAD8.6000108@ianhobson.co.uk> Hi all, I am trying to redirect stdout and stderr on a python windows service, so that the service will not stall after 256 chars is written, and so I can use print for simple debugging. I have the following 4 lines (copy/pasted) in the source of my code. if __name__ == '__main__': sys.stdout = sys.stderr = open("d:\logfile.txt", "a") print "Starting up" win32serviceutil.HandleCommandLine(PythonService) When I run them as a free standing program, logfile.txt is created the text placed in it, and it crashed on the last line - no permissions to create a service. (Micro-cluless has no sudo command in Win7. :( ) When I start the code as a service, it does not create the log file does not put anything in it, but the last line is executed and the service starts! There are no Events on the event log. When I stop the service, it stops. Still no log file. Still no events. I tried running the service with my account and not the system user. This gave me "run as service" permissions, but did not alter the results. What is happening? And how can I set up logging so that the service can simply restart, leaving the trackback in the log file for me to come to later. All help gratefully received. I've lost most of my remaining hair today on this one. Ian From sajuptpm at gmail.com Mon Sep 6 10:54:23 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Mon, 6 Sep 2010 07:54:23 -0700 (PDT) Subject: list of tuples with dynamic change in position Message-ID: I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)), (('y','x'),(3,0))] some functions using this list and fetch data using index l[0][1], l[1] [1] I need to change position of each values in the list and that dont affect fuctions which are using this list. I must have to use list of tuples. Have any way to do it using list of tuples. From thomas at jollybox.de Mon Sep 6 10:58:39 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Mon, 6 Sep 2010 16:58:39 +0200 Subject: accessing a text file In-Reply-To: <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> Message-ID: <201009061658.39729.thomas@jollybox.de> On Monday 06 September 2010, it occurred to Baba to exclaim: > On 6 sep, 00:01, Benjamin Kaplan wrote: > > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > > > level: beginner > > > > > > how can i access the contents of a text file in Python? > > > > > > i would like to compare a string (word) with the content of a text > > > file (word_list). i want to see if word is in word_list. let's assume > > > the TXT file is stored in the same directory as the PY file. > > > > > > def is_valid_word(word, word_list) > > > > > > thanks > > > Baba > > > -- > > > > > >http://mail.python.org/mailman/listinfo/python-list > > > > Please do us a favor and at least try to figure things out on your > > own, rather than coming here every time you have a question. The very > > first result when you try searching "python read text file" is the > > section in the Python tutorial that explains how to do this. > > > > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > Hi Benjamin > > I did find that page prior to posting the question but i still wanted > to have a second opinion to complement that info so as to make things > easier The first line of my post clearly states that i am a beginner. > It's nice to provide links which can help answer the question but > please be so polite and keep personal comments for yourself. > That is of course perfectly legitimate. It would however have been polite to state that in the question. Show us that you're doing your homework, and not just using the list as a cheap path to having to think less yourself. Phrasing your post as "I would like to compare a ... I found the open() function here: [link]. Is this what I should use of is there any other/better way?" makes a completely different impression. Also, keeping personal comments to one's self is just not how it works. On a list like this especially, answers along the lines of "That's the way to do what you were asking for, but are you sure the question went into the right direction? Have you thought of [...]?" can often be very helpful. > > To all other respondants: thank you for your kind instructions and > directions. > From sajuptpm at gmail.com Mon Sep 6 11:09:44 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Mon, 6 Sep 2010 08:09:44 -0700 (PDT) Subject: list of tuples with dynamic change in position References: Message-ID: I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)), (('y','x'),(3,0))] and postion of values in the tuple change dynamicaly. I need a way to access correct value even if change in position. From eckhardt at satorlaser.com Mon Sep 6 11:15:55 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 06 Sep 2010 17:15:55 +0200 Subject: list of tuples with dynamic change in position References: Message-ID: sajuptpm wrote: > I need to change position of each values in the list and that dont > affect fuctions which are using this list. So you want to change the list's content but you don't want anyone to be able to detect the difference? That doesn't make sense. > I must have to use list of tuples. > Have any way to do it using list of tuples. Why don't you explain what you want to achieve instead of asking for a solution that doesn't make sense? Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From eckhardt at satorlaser.com Mon Sep 6 11:17:46 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 06 Sep 2010 17:17:46 +0200 Subject: redirecting stdout and stderr for a windows service References: Message-ID: Ian Hobson wrote: > sys.stdout = sys.stderr = open("d:\logfile.txt", "a") "\l" is probably not what you want. Consider using "\\l" or r"\l" instead. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From invalid at invalid.invalid Mon Sep 6 11:24:38 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 6 Sep 2010 15:24:38 +0000 (UTC) Subject: Embedded Systems development using Python References: Message-ID: On 2010-09-06, Stefan Behnel wrote: > VGNU Linux, 06.09.2010 13:02: >> Can Python be used for embedded systems development ? > > It can and has been. > > What kind of embedded system with what set of capabilities are you thinking > about? TV sets? Mobile phones? Smart dust? [The OP never showed up on my sever for some reason] If you google for "deeply embedded python", you'll find some raterh old links: http://tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy http://groups.google.com/group/python-on-a-chip/web/list-of-small-python-implementations http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html A few years ago I used Python on a prototype for a bicycle computer with GPS, four buttons, and a small LCD screen. It was more or less comparable to a PDA with Linux running on an 200MHz XScale with something like 16MB of flash and 32MB of SDRAM. IIRC, that project used OpenEmbedded, and all I had to do was build the Python package that's already there in OE. I don't remember if I was using PySDL or PyQt for the UI -- I remember experimenting with both on desktop hosts at the time. I don't think that product ever saw daylight. There was just now way they could have competed with Garmin. -- Grant From grflanagan at gmail.com Mon Sep 6 11:40:17 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 06 Sep 2010 16:40:17 +0100 Subject: list of tuples with dynamic change in position In-Reply-To: References: Message-ID: sajuptpm wrote: > I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)), > (('y','x'),(3,0))] and postion of values in the tuple change > dynamicaly. I need a way to access correct value even if change in > position. from itertools import starmap, izip, imap list(imap(dict, starmap(izip, d))) [{'a': 9, 's': 5}, {'u': 9, 'w': 2}] From augdawg09 at gmail.com Mon Sep 6 11:48:29 2010 From: augdawg09 at gmail.com (aug dawg) Date: Mon, 6 Sep 2010 11:48:29 -0400 Subject: Arguments from the command line Message-ID: I've seen Python programs that can be activated from the command line. For example: hg This displays a list of commands for the Mercurial revision control system. But another command is this: hg commit "This is a commit name" Mercurial is written in Python. I know that commit is a function that commits to a repo, but what command does the program use in order to get the commit name, like "This is a commit name" (This would make a commit with "This is a commit name" as the commit name) -------------- next part -------------- An HTML attachment was scrubbed... URL: From raoulbia at gmail.com Mon Sep 6 11:53:53 2010 From: raoulbia at gmail.com (Baba) Date: Mon, 6 Sep 2010 08:53:53 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> Message-ID: On 6 sep, 16:58, Thomas Jollans wrote: > On Monday 06 September 2010, it occurred to Baba to exclaim: > > > > > On 6 sep, 00:01, Benjamin Kaplan wrote: > > > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > > > > level: beginner > > > > > how can i access the contents of a text file in Python? > > > > > i would like to compare a string (word) with the content of a text > > > > file (word_list). i want to see if word is in word_list. let's assume > > > > the TXT file is stored in the same directory as the PY file. > > > > > def is_valid_word(word, word_list) > > > > > thanks > > > > Baba > > > > -- > > > > >http://mail.python.org/mailman/listinfo/python-list > > > > Please do us a favor and at least try to figure things out on your > > > own, rather than coming here every time you have a question. The very > > > first result when you try searching "python read text file" is the > > > section in the Python tutorial that explains how to do this. > > > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > > Hi Benjamin > > > I did find that page prior to posting the question but i still wanted > > to have a second opinion to complement that info so as to make things > > easier The first line of my post clearly states that i am a beginner. > > It's nice to provide links which can help answer the question but > > please be so polite and keep personal comments for yourself. > > That is of course perfectly legitimate. It would however have been polite to > state that in the question. Show us that you're doing your homework, and not > just using the list as a cheap path to having to think less yourself. > > Phrasing your post as "I would like to compare a ... I found the open() > function here: [link]. Is this what I should use of is there any other/better > way?" makes a completely different impression. > > Also, keeping personal comments to one's self is just not how it works. On a > list like this especially, answers along the lines of "That's the way to do > what you were asking for, but are you sure the question went into the right > direction? Have you thought of [...]?" can often be very helpful. > > > > > To all other respondants: thank you for your kind instructions and > > directions. > > Thanks Thomas. Look up some of my questions this group and read through them and come back to tell me if a) i use this forum to learn without making any efforts myself or b) i use this forum to get started using the expertise of more knowledgeable programmers while at the same time particiapting. Anyway having this discussion is beside the point. Any Expert out there who thinks we beginners are some dumb idiots who are too stupid to think for themselves and are lucky to have a bunch of geniuses like you to help, get lost or make yourself a cup of tea but please give me a break from teaching me lessons... There's lots of nice people out there who are being awsemome by dedicating a bit of their time to some of our easy questions and it is them that i wish to send a BIG thanks! Much appreciated. I have made some good progress since starting to learn Python and this group has been great help! tnx Raoul From hugo.yoshi at gmail.com Mon Sep 6 12:08:27 2010 From: hugo.yoshi at gmail.com (Hugo Arts) Date: Mon, 6 Sep 2010 18:08:27 +0200 Subject: [Tutor] Arguments from the command line In-Reply-To: References: Message-ID: On Mon, Sep 6, 2010 at 5:48 PM, aug dawg wrote: > I've seen Python programs that can be activated from the command line. For > example: > hg > > This displays a list of commands for the Mercurial revision control system. > But another command is this: > hg commit "This is a commit name" > Mercurial is written in Python. I know that commit is a function that > commits to a repo, but what command does the program use in order to get the > commit name, like "This is a commit name" (This would make a commit with > "This is a commit name" as the commit name) > sys.argv is a list of all arguments from the command line. However, you'll rarely deal with it directly, there's various modules that deal with handling arguments. I believe the current one is argparse: http://docs.python.org/library/argparse.html#module-argparse Hugo From breamoreboy at yahoo.co.uk Mon Sep 6 12:08:32 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Sep 2010 17:08:32 +0100 Subject: Arguments from the command line In-Reply-To: References: Message-ID: On 06/09/2010 16:48, aug dawg wrote: > I've seen Python programs that can be activated from the command line. For > example: > > hg > > This displays a list of commands for the Mercurial revision control system. > But another command is this: > > hg commit "This is a commit name" > > Mercurial is written in Python. I know that commit is a function that > commits to a repo, but what command does the program use in order to get the > commit name, like "This is a commit name" (This would make a commit with > "This is a commit name" as the commit name) > > See sys.argv at http://docs.python.org/library/sys.html Cheers. Mark Lawrence. From aahz at pythoncraft.com Mon Sep 6 12:14:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Sep 2010 09:14:01 -0700 Subject: Iterative vs. Recursive coding References: <71e72427-7604-4286-b119-08ba669e9240@f42g2000yqn.googlegroups.com> <4c6dcbc5$0$11111$c3e8da3@news.astraweb.com> <4c6e9de9$0$23142$426a74cc@news.free.fr> Message-ID: In article <4c6e9de9$0$23142$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: >Steven D'Aprano a ??crit : >> On Thu, 19 Aug 2010 22:00:16 +0000, Martin Gregorie wrote: >>> >>> Recursion can be quite a trick to get your mind round at first >> >> Really? Do people actually find the *concept* of recursion to be tricky? > >I onced worked in a shop (Win32 desktop / accouting applications mainly) >where I was the only guy that could actually understand recursion. FWIW, >I also was the only guy around that understood "hairy" (lol) concepts >like callback functions, FSM, polymorphism, hashtables, linked lists, >ADTs, algorithm complexity etc... To some extent, the question here is the definition of "understand" being used. It probably would be reasonable to say that I have only a cookbook level understanding of recursion, and the same would apply to callback functions, FSM, linked lists, and so on. (I mostly think I do really understand polymorphism and hashtables.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From debatem1 at gmail.com Mon Sep 6 12:14:41 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 6 Sep 2010 09:14:41 -0700 Subject: accessing a text file In-Reply-To: References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> Message-ID: On Mon, Sep 6, 2010 at 8:53 AM, Baba wrote: > On 6 sep, 16:58, Thomas Jollans wrote: >> On Monday 06 September 2010, it occurred to Baba to exclaim: >> >> >> >> > On 6 sep, 00:01, Benjamin Kaplan wrote: >> > > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: >> > > > level: beginner >> >> > > > how can i access the contents of a text file in Python? >> >> > > > i would like to compare a string (word) with the content of a text >> > > > file (word_list). i want to see if word is in word_list. let's assume >> > > > the TXT file is stored in the same directory as the PY file. >> >> > > > def is_valid_word(word, word_list) >> >> > > > thanks >> > > > Baba >> > > > -- >> >> > > >http://mail.python.org/mailman/listinfo/python-list >> >> > > Please do us a favor and at least try to figure things out on your >> > > own, rather than coming here every time you have a question. The very >> > > first result when you try searching "python read text file" is the >> > > section in the Python tutorial that explains how to do this. >> >> > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >> >> > Hi Benjamin >> >> > I did find that page prior to posting the question but i still wanted >> > to have a second opinion to complement that info so as to make things >> > easier The first line of my post clearly states that i am a beginner. >> > It's nice to provide links which can help answer the question but >> > please be so polite and keep personal comments for yourself. >> >> That is of course perfectly legitimate. It would however have been polite to >> state that in the question. Show us that you're doing your homework, and not >> just using the list as a cheap path to having to think less yourself. >> >> Phrasing your post as "I would like to compare a ... I found the open() >> function here: [link]. Is this what I should use of is there any other/better >> way?" makes a completely different impression. >> >> Also, keeping personal comments to one's self is just not how it works. On a >> list like this especially, answers along the lines of "That's the way to do >> what you were asking for, but are you sure the question went into the right >> direction? Have you thought of [...]?" can often be very helpful. >> >> >> >> > To all other respondants: thank you for your kind instructions and >> > directions. >> >> > > Thanks Thomas. Look up some of my questions ?this group and read > through them and come back to tell me if a) i use this forum to learn > without making any efforts myself Just a quick point- when you ask someone for help, it's considered impolite to tell them what to do. I'd also point out that you gave no indication that you'd worked on this at all before posting it. In that regard, Thomas's concern seems completely justified to me. > or b) i use this forum to get > started using the expertise of more knowledgeable programmers while at > the same time particiapting. Again, Thomas's concern seems justified to me. Things would probably go more smoothly if you gave a better indication of what you had done so far on the problem in the future. > Anyway having this discussion is beside > the point. Any Expert out there who thinks we beginners are some dumb > idiots who are too stupid to think for themselves and are lucky to > have a bunch of geniuses like you to help, get lost or make yourself a > cup of tea but please give me a break from teaching me lessons... I don't think all beginners are idiots, or even most of them- but this isn't the right attitude to be taking. Both Thomas and myself thought that this was inappropriate enough to mention it, and if two people spoke up you can bet a lot more were thinking it quietly. My suggestion would be to moderate your approach and demonstrate what you've done so far (if only to increase the signal-to-noise ratio as your problems become more challenging) when posting. I'd also refrain from telling people to get lost; it doesn't make people happy to help you, you know? Geremy Condra From aahz at pythoncraft.com Mon Sep 6 12:17:32 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Sep 2010 09:17:32 -0700 Subject: Iterative vs. Recursive coding References: <71e72427-7604-4286-b119-08ba669e9240@f42g2000yqn.googlegroups.com> <4c6f966e$0$28653$c3e8da3@news.astraweb.com> <4c70344a$0$1659$742ec2ed@news.sonic.net> Message-ID: In article <4c70344a$0$1659$742ec2ed at news.sonic.net>, John Nagle wrote: > > Realistically, recursion isn't that important in Python. It's >there if you need it, and sometimes useful, but generally not used >much without good reason. In some functional languages, recursion >is routinely used in place of iteration, but Python isn't built for >that. In Python, most of the use cases for trivial recursion >are better handled with iteration or generators. Depends how you define "important". It's certainly a critical feature for Python that you *can* use recursion; it's usually the simplest way of walking a tree structure (such as a directory tree). Python would be an extraordinarily limited language if recursion were not available. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From bgailer at gmail.com Mon Sep 6 12:20:12 2010 From: bgailer at gmail.com (bob gailer) Date: Mon, 06 Sep 2010 12:20:12 -0400 Subject: [Tutor] Arguments from the command line In-Reply-To: References: Message-ID: <4C8514BC.7080106@gmail.com> On 9/6/2010 11:48 AM, aug dawg wrote: > I've seen Python programs that can be activated from the command line. > For example: > > hg > > This displays a list of commands for the Mercurial revision control > system. But another command is this: > > hg commit "This is a commit name" > > Mercurial is written in Python. I know that commit is a function that > commits to a repo, but what command does the program use in order to > get the commit name, like "This is a commit name" (This would make a > commit with "This is a commit name" as the commit name) hg.py: import sys print sys.argv $hg commit "This is a commit name" ['C:\\hg.py', 'commit', 'This is a commit name'] -- Bob Gailer 919-636-4239 Chapel Hill NC From raoulbia at gmail.com Mon Sep 6 12:29:15 2010 From: raoulbia at gmail.com (Baba) Date: Mon, 6 Sep 2010 09:29:15 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> Message-ID: <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> On 6 sep, 18:14, geremy condra wrote: > On Mon, Sep 6, 2010 at 8:53 AM, Baba wrote: > > On 6 sep, 16:58, Thomas Jollans wrote: > >> On Monday 06 September 2010, it occurred to Baba to exclaim: > > >> > On 6 sep, 00:01, Benjamin Kaplan wrote: > >> > > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > >> > > > level: beginner > > >> > > > how can i access the contents of a text file in Python? > > >> > > > i would like to compare a string (word) with the content of a text > >> > > > file (word_list). i want to see if word is in word_list. let's assume > >> > > > the TXT file is stored in the same directory as the PY file. > > >> > > > def is_valid_word(word, word_list) > > >> > > > thanks > >> > > > Baba > >> > > > -- > > >> > > >http://mail.python.org/mailman/listinfo/python-list > > >> > > Please do us a favor and at least try to figure things out on your > >> > > own, rather than coming here every time you have a question. The very > >> > > first result when you try searching "python read text file" is the > >> > > section in the Python tutorial that explains how to do this. > > >> > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > >> > Hi Benjamin > > >> > I did find that page prior to posting the question but i still wanted > >> > to have a second opinion to complement that info so as to make things > >> > easier The first line of my post clearly states that i am a beginner. > >> > It's nice to provide links which can help answer the question but > >> > please be so polite and keep personal comments for yourself. > > >> That is of course perfectly legitimate. It would however have been polite to > >> state that in the question. Show us that you're doing your homework, and not > >> just using the list as a cheap path to having to think less yourself. > > >> Phrasing your post as "I would like to compare a ... I found the open() > >> function here: [link]. Is this what I should use of is there any other/better > >> way?" makes a completely different impression. > > >> Also, keeping personal comments to one's self is just not how it works. On a > >> list like this especially, answers along the lines of "That's the way to do > >> what you were asking for, but are you sure the question went into the right > >> direction? Have you thought of [...]?" can often be very helpful. > > >> > To all other respondants: thank you for your kind instructions and > >> > directions. > > > Thanks Thomas. Look up some of my questions ?this group and read > > through them and come back to tell me if a) i use this forum to learn > > without making any efforts myself > > Just a quick point- when you ask someone for help, it's considered > impolite to tell them what to do. > > I'd also point out that you gave no indication that you'd worked on > this at all before posting it. In that regard, Thomas's concern seems > completely justified to me. > > > or b) i use this forum to get > > started using the expertise of more knowledgeable programmers while at > > the same time particiapting. > > Again, Thomas's concern seems justified to me. Things would probably > go more smoothly if you gave a better indication of what you had done > so far on the problem in the future. > > > Anyway having this discussion is beside > > the point. Any Expert out there who thinks we beginners are some dumb > > idiots who are too stupid to think for themselves and are lucky to > > have a bunch of geniuses like you to help, get lost or make yourself a > > cup of tea but please give me a break from teaching me lessons... > > I don't think all beginners are idiots, or even most of them- but this > isn't the right attitude to be taking. Both Thomas and myself thought > that this was inappropriate enough to mention it, and if two people > spoke up you can bet a lot more were thinking it quietly. My > suggestion would be to moderate your approach and demonstrate what > you've done so far (if only to increase the signal-to-noise ratio as > your problems become more challenging) when posting. I'd also refrain > from telling people to get lost; it doesn't make people happy to help > you, you know? > > Geremy Condra Thanks Jeremy, i will take your advice on board! Noone likes to be taught lessons i think so it is only normal that i reacted. If i had received a friendly response from Benjamin (as opposed to "Please do us a favor and at least try to figure things out on your own") making me aware of the etiquette that my post should also show that i have researched my question somehow and if his tone would have been mannered then we would not be having this discussion now. Ok now i need to go back to actual Pythoon learning, i'm getting distracted. Kind regards, Baba From user at example.net Mon Sep 6 12:31:20 2010 From: user at example.net (J.O. Aho) Date: Mon, 06 Sep 2010 18:31:20 +0200 Subject: GUibuilder evaluation In-Reply-To: References: Message-ID: <8ekjapFu3oU2@mid.individual.net> Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? QT Designer from Nokia, I can run my GUI programs both on my desktop and on my cellphone without modifications. -- //Aho From sal_lopez at me.com Mon Sep 6 12:55:03 2010 From: sal_lopez at me.com (Sal Lopez) Date: Mon, 06 Sep 2010 09:55:03 -0700 Subject: using modules Message-ID: The following code runs OK under 3.1: @filename=cats_and_dogs.py #!/usr/bin/python def make_sound(animal): print(animal + ' says ' + sounds[animal]) sounds = { "cat": "meow", "dog": "woof" } for i in sounds.keys(): make_sound(i) # output: # dog says woof # cat says meow When I move the def to it's own file to create a module, it barfs: @filename= cats_and_dogs.py #!/usr/bin/python import defs sounds = { "cat": "meow", "dog": "woof" } for i in sounds.keys(): defs.make_sound(i) @filename=defs.py def make_sound(animal): print(animal + ' says ' + sounds[animal]) Traceback (most recent call last): File "./cats_and_dogs.py", line 11, in defs.make_sound(i) File "defs.py", line 4, in make_sound print(animal + ' says ' + sounds[animal]) NameError: global name 'sounds' is not defined I thought that importing the function(s) made them local to the main program? Any assistance is appreciated. From tinnews at isbd.co.uk Mon Sep 6 13:18:34 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Mon, 6 Sep 2010 18:18:34 +0100 Subject: filecmp.cmp() doesn't seem to do what it says in the documentation Message-ID: I'm using filecmp.cmp() to compare some files (surprise!). The documentation says:- Unless shallow is given and is false, files with identical os.stat() signatures are taken to be equal. I'm not setting shallow explicitly so it's True, thus the function should be comparing the os.stat() results. However this doesn't seem to be the case as even if I touch one of the files to change it's access/modification date filecmp.cmp() still returns True. Here is an example:- chris$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import filecmp >>> print filecmp.cmp("/media/disk/DCIM/103_FUJI/DSCF3084.JPG", "/home/chris/pictures/2010/4/24dscf3084.jpg") True >>> chris$ ls -l /media/disk/DCIM/103_FUJI/DSCF3084.JPG /home/chris/pictures/2010/4/24dscf3084.jpg -rwxr-xr-x 1 chris chris 1783277 2010-09-06 17:36 /home/chris/pictures/2010/4/24dscf3084.jpg -rwxr-xr-x 1 chris root 1783277 2010-09-06 17:53 /media/disk/DCIM/103_FUJI/DSCF3084.JPG chris$ The file modification times are different, surely filecmp.cmp() should be returning false. I actually think the way it's working makes more sense as I don't care if the modification time has changed if the files are exactly the same length still. -- Chris Green From python at mrabarnett.plus.com Mon Sep 6 13:24:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Sep 2010 18:24:23 +0100 Subject: [RELEASED] Python 3.2 alpha 2 In-Reply-To: <4C84A4B9.2040406@python.org> References: <4C84A4B9.2040406@python.org> Message-ID: <4C8523C7.5090309@mrabarnett.plus.com> On 06/09/2010 09:22, Georg Brandl wrote: [snip] > 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/ > I did notice the spelling mistake "dynmaic" at: http://docs.python.org/dev/whatsnew/3.2.html From alan.gauld at btinternet.com Mon Sep 6 13:45:04 2010 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 6 Sep 2010 18:45:04 +0100 Subject: Arguments from the command line References: Message-ID: "aug dawg" wrote > Mercurial is written in Python. I know that commit is a function > that > commits to a repo, but what command does the program use in order to > get the > commit name, like "This is a commit name" (This would make a commit > with > "This is a commit name" as the commit name) Take a look at the Talking to the User topic in my tutorial which has a section on reading command line arguments. Interestingly, most of the queries I get on that section are from GUI users who don't understand the concept of command line arguments! :-) -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ From cmpython at gmail.com Mon Sep 6 13:52:02 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Sep 2010 10:52:02 -0700 (PDT) Subject: GUibuilder evaluation References: Message-ID: On Sep 6, 3:54?am, Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? > Thanks Your message referred to a GUI *builder*, whereas tkinter is a GUI *toolkit* (that is, a collection of widgets). A builder is an application that allows you to make GUI apps more I assume you want to choose a GUI toolkit. If you search the archive of this list or Google generally (like "GUI toolkits Python") you will have many minutes of reading material for you to check out. From chardster at gmail.com Mon Sep 6 14:17:34 2010 From: chardster at gmail.com (Richard Thomas) Date: Mon, 6 Sep 2010 11:17:34 -0700 (PDT) Subject: using modules References: Message-ID: On Sep 6, 5:55?pm, Sal Lopez wrote: > The following code runs OK under 3.1: > > @filename=cats_and_dogs.py > > #!/usr/bin/python > > def make_sound(animal): > ? ? print(animal + ' says ' + sounds[animal]) > > sounds = { "cat": "meow", "dog": "woof" } > > for i in sounds.keys(): > ? ? make_sound(i) > > # output: > # dog says woof > # cat says meow > > When I move the def to it's own file to create a module, it barfs: > > @filename= cats_and_dogs.py > #!/usr/bin/python > > import defs > > sounds = { "cat": "meow", "dog": "woof" } > > for i in sounds.keys(): > ? ? defs.make_sound(i) > > @filename=defs.py > def make_sound(animal): > ? ? print(animal + ' says ' + sounds[animal]) > > Traceback (most recent call last): > File "./cats_and_dogs.py", line 11, in > defs.make_sound(i) > File "defs.py", line 4, in make_sound > print(animal + ' says ' + sounds[animal]) > NameError: global name 'sounds' is not defined > > I thought that importing the function(s) made them local to the main program? Any assistance is appreciated. ? ? ? ? ? ? ? The make_sound function has two scopes in which to resolve the name 'sounds' the first is its local scope i.e. the scope of things defined in the function itself but that just contains 'animal'. The second is its global scope which is another name for its module's namespace. In this case that's the namespace of the 'defs' module. The namespace of the main module (the module that you ran), is separate. You could do this: import defs defs.sounds = {'cat': 'meow', ... } Or even: #defs.py sounds = {} #main.py import defs defs.sounds.update({'cat': 'meow', ... }) Regards, Richard. From tjreedy at udel.edu Mon Sep 6 14:27:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Sep 2010 14:27:25 -0400 Subject: filecmp.cmp() doesn't seem to do what it says in the documentation In-Reply-To: References: Message-ID: On 9/6/2010 1:18 PM, tinnews at isbd.co.uk wrote: > I'm using filecmp.cmp() to compare some files (surprise!). > > The documentation says:- > Unless shallow is given and is false, files with identical > os.stat() signatures are taken to be equal. Reword and read carefully: if shallow == True and signatures are identical, then files are taken to be equal. Here is the corresponding code from Lib/filecmp.py: if shallow and s1 == s2: return True Does not say the result for non-identical signatures ;-). > I'm not setting shallow explicitly so it's True, thus the function > should be comparing the os.stat() results. However this doesn't seem > to be the case as even if I touch one of the files to change it's > access/modification date filecmp.cmp() still returns True. Because it goes on to actually compare the files, and they are equal. ... result = _cache.get((f1, f2)) if result and (s1, s2) == result[:2]: return result[2] outcome = _do_cmp(f1, f2) _cache[f1, f2] = s1, s2, outcome return outcome Most of the stdlib files in Python are quite readable. I recommend it when you have questions. -- Terry Jan Reedy From no.email at nospam.invalid Mon Sep 6 14:31:11 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 06 Sep 2010 11:31:11 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> <4c83295b$0$1665$742ec2ed@news.sonic.net> <7xd3ssbs4o.fsf@ruckus.brouhaha.com> <4c83dfed$0$1662$742ec2ed@news.sonic.net> Message-ID: <7xk4myd8r4.fsf@ruckus.brouhaha.com> John Nagle writes: > I've argued for an approach in which only synchronized or immutable > objects can be shared between threads. Then, only synchronized objects > have refcounts. See > "http://www.animats.com/papers/languages/pythonconcurrency.html" I'm going to have to read this carefully, but my first reaction is that doing it right would take substantial changes to the language, to the point where it wouldn't really be Python any more. More generally, if you want to program in Erlang, why not use Erlang for that? > I can't think of a time when I've really had to use a finalizer for > something with dynamic extent. They've always seemed like a code > smell to me. The problem appears when you have an object that owns something, like a window or a database connection. "With" is single-level. But expecting such an object to be gc'd seems like a code smell in its own right. I once implemented something like that in a Lisp system, and it was just disconcerting as hell to see windows on the screen blink out of existence unpredictably. The issue is maybe your function returns and you expect the window to vanish, but something somewhere has saved another temporary reference to it so it doesn't go away til later. If you want something with external semantics (like a window or file handle) to be released at a particular time, the program should do that explicitly. Don't use a finalizer that you expect storage reclamation to invoke. There is just too little control in a Python program over the creation of references. From egrefen at gmail.com Mon Sep 6 15:01:27 2010 From: egrefen at gmail.com (Edward Grefenstette) Date: Mon, 6 Sep 2010 12:01:27 -0700 (PDT) Subject: Database problems Message-ID: <869189cf-7439-43ce-9bf1-fb1f4cbf0c5f@n3g2000yqb.googlegroups.com> Dear Pythonistas, For a project I'm working on, I need to store fairly large dictionaries (several million keys) in some form (obviously not in memory). The obvious course of action was to use a database of some sort. The operation is pretty simple, a function is handed a generator that gives it keys and values, and it maps the keys to the values in a non- relational database (simples!). I wrote some code implementing this using anydbm (which used dbhash on my system), and it worked fine for about a million entries, but then crashed raising a DBPageNotFoundError. I did a little digging around and couldn't figure out what was causing this or how to fix it. I then quickly swapped anydbm for good ol' fashioned dbm which uses gdbm, and it ran even faster a little longer, but after a million entries or so it raised the ever-so-unhelpful "gdbm fatal: write error". I then threw caution to the winds and tried simply using cPickle's dump in the hope of obtaining some data persistence, but it crashed fairly early with a "IOError: [Errno 122] Disk quota exceeded". Now the question is: is it something wrong with these dbms? Can they not deal with very large sets of data? If not, is there a more optimal tool for my needs? Or is the problem unrelated and has something to do with my lab computer? Best, Edward From tjreedy at udel.edu Mon Sep 6 15:08:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Sep 2010 15:08:05 -0400 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 9/6/2010 7:20 AM, Stefan Behnel wrote: > BartC, 06.09.2010 12:38: >> (3) Since the loop variable is never used, why not have a special loop >> statement that repeats code so many times? There sort-of is, just slightly more general. > Because special cases are not special enough to break the rules. As > others have stated before, you can use itertools to reduce that part of > the looping overhead, if it really hurts your concrete code. I ran the following test: >>> from itertools import repeat >>> n = 10**8 >>> for dummy in repeat(None,n): pass # 7 sec >>> for dummy in range(n): pass # 11 sec Times are for my older machine, subjectively counted. The difference is subjectively clear. Both functions count in C. I presume the difference is the cost of creating and deleting unneeded Python int objects. This difference is the reason the timeit module uses itertools.repeat for the inner loop that repeats the code to be timed. -- Terry Jan Reedy From benjamin.kaplan at case.edu Mon Sep 6 15:12:53 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 6 Sep 2010 15:12:53 -0400 Subject: Database problems In-Reply-To: <869189cf-7439-43ce-9bf1-fb1f4cbf0c5f@n3g2000yqb.googlegroups.com> References: <869189cf-7439-43ce-9bf1-fb1f4cbf0c5f@n3g2000yqb.googlegroups.com> Message-ID: On Mon, Sep 6, 2010 at 3:01 PM, Edward Grefenstette wrote: > Dear Pythonistas, > > For a project I'm working on, I need to store fairly large > dictionaries (several million keys) in some form (obviously not in > memory). The obvious course of action was to use a database of some > sort. > > The operation is pretty simple, a function is handed a generator that > gives it keys and values, and it maps the keys to the values in a non- > relational database (simples!). > > I wrote some code implementing this using anydbm (which used dbhash on > my system), and it worked fine for about a million entries, but then > crashed raising a DBPageNotFoundError. I did a little digging around > and couldn't figure out what was causing this or how to fix it. > > I then quickly swapped anydbm for good ol' fashioned dbm which uses > gdbm, and it ran even faster a little longer, but after a million > entries or so it raised the ever-so-unhelpful "gdbm fatal: write > error". > > I then threw caution to the winds and tried simply using cPickle's > dump in the hope of obtaining some data persistence, but it crashed > fairly early with a "IOError: [Errno 122] Disk quota exceeded". > > Now the question is: is it something wrong with these dbms? Can they > not deal with very large sets of data? If not, is there a more optimal > tool for my needs? Or is the problem unrelated and has something to do > with my lab computer? > > Best, > Edward > -- Just as a guess, I'd say that you have a disk quota that you're hitting with your several million key dbm. You might want to talk to the lab administrator about raising the quota. From cmpython at gmail.com Mon Sep 6 15:15:58 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Sep 2010 12:15:58 -0700 (PDT) Subject: GUibuilder evaluation References: Message-ID: <2963f85b-3bbf-46e5-9eee-758ee71a4f21@l6g2000yqb.googlegroups.com> On Sep 6, 3:54?am, Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? > Thanks Your message referred to a GUI *builder*, whereas tkinter is a GUI *toolkit* (that is, a collection of widgets). A builder is an application that allows one to make GUI apps more I assume you want to choose a GUI toolkit. If you search the archive of this list or Google generally (like "GUI toolkits Python") you will have many minutes of reading material for you to check out. From usernet at ilthio.net Mon Sep 6 15:16:18 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 6 Sep 2010 19:16:18 +0000 (UTC) Subject: Database problems References: <869189cf-7439-43ce-9bf1-fb1f4cbf0c5f@n3g2000yqb.googlegroups.com> Message-ID: On 2010-09-06, Edward Grefenstette wrote: > I then threw caution to the winds and tried simply using cPickle's > dump in the hope of obtaining some data persistence, but it crashed > fairly early with a "IOError: [Errno 122] Disk quota exceeded". The error is telling you that you have attempted to write the file; but, in the process you exceeded your disk quota (the space you are allowed to use) and the operating system would not permit you to finish the file. > Now the question is: is it something wrong with these dbms? Can they > not deal with very large sets of data? If not, is there a more optimal > tool for my needs? Or is the problem unrelated and has something to do > with my lab computer? The problem is that you are attempting to use more disk space then you are permitted to use on your account (at least for the selected filesystem). Possible solutions are to save the data somewhere else where you have a greater quota, delete some other files from your account to make room for the new file, or talk to whoever administrates the systems and see if they will add enough space to your quota to permit you to write this large file. From cmpython at gmail.com Mon Sep 6 15:18:05 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Sep 2010 12:18:05 -0700 (PDT) Subject: GUibuilder evaluation References: Message-ID: On Sep 6, 3:54?am, Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? > Thanks Your message referred to a GUI *builder*, whereas tkinter is a GUI *toolkit* (that is, a collection of widgets). A GUI builder is an application that allows one to make GUI apps more easily. I assume you mean a GUI toolkit. If you search the archive of this list or Google generally (like "GUI toolkits Python") you will have many minutes of reading material for you to evaluate which toolkit you'd like to try. From tjreedy at udel.edu Mon Sep 6 15:21:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Sep 2010 15:21:55 -0400 Subject: using modules In-Reply-To: References: Message-ID: On 9/6/2010 12:55 PM, Sal Lopez wrote: > The following code runs OK under 3.1: > > @filename=cats_and_dogs.py > > #!/usr/bin/python > > def make_sound(animal): > print(animal + ' says ' + sounds[animal]) > > sounds = { "cat": "meow", "dog": "woof" } > > for i in sounds.keys(): > make_sound(i) > > # output: > # dog says woof > # cat says meow > > When I move the def to it's own file to create a module, it barfs: > > @filename= cats_and_dogs.py > #!/usr/bin/python > > import defs > > sounds = { "cat": "meow", "dog": "woof" } > > for i in sounds.keys(): > defs.make_sound(i) > > @filename=defs.py > def make_sound(animal): > print(animal + ' says ' + sounds[animal]) > > Traceback (most recent call last): > File "./cats_and_dogs.py", line 11, in > defs.make_sound(i) > File "defs.py", line 4, in make_sound > print(animal + ' says ' + sounds[animal]) > NameError: global name 'sounds' is not defined > > > I thought that importing the function(s) made them local to the main program? Any assistance is appreciated. Python code execute within the context of the builtin namespace, a module namespace (misleadingly called 'globals'), a local namespace (the same as the module namespace for top-level code), and for nested functions, intermediate namespaces. "import defs" binds the name 'defs' to the module object. Code in the defs module still executes within the defs context where it is defined. This is lexical name resolution. The same is still true if you import the function with "from defs import make_sound". What you were expecting is dynamic name resolution, where names are resolved within the calling context rather than the definition context. I believe this is dynamic scoping. This has been tried in other languages. For more, try https://secure.wikimedia.org/wikipedia/en/wiki/Dynamic_scoping -- Terry Jan Reedy From tinnews at isbd.co.uk Mon Sep 6 16:11:18 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Mon, 6 Sep 2010 21:11:18 +0100 Subject: filecmp.cmp() doesn't seem to do what it says in the documentation References: Message-ID: <6gufl7-c9g.ln1@chris.zbmc.eu> Terry Reedy wrote: > On 9/6/2010 1:18 PM, tinnews at isbd.co.uk wrote: > > I'm using filecmp.cmp() to compare some files (surprise!). > > > > The documentation says:- > > Unless shallow is given and is false, files with identical > > os.stat() signatures are taken to be equal. > > Reword and read carefully: if shallow == True and signatures are > identical, then files are taken to be equal. > > Here is the corresponding code from Lib/filecmp.py: > if shallow and s1 == s2: > return True > > Does not say the result for non-identical signatures ;-). > > > I'm not setting shallow explicitly so it's True, thus the function > > should be comparing the os.stat() results. However this doesn't seem > > to be the case as even if I touch one of the files to change it's > > access/modification date filecmp.cmp() still returns True. > > Because it goes on to actually compare the files, and they are equal. > > ... > result = _cache.get((f1, f2)) > if result and (s1, s2) == result[:2]: > return result[2] > outcome = _do_cmp(f1, f2) > _cache[f1, f2] = s1, s2, outcome > return outcome > > Most of the stdlib files in Python are quite readable. I recommend it > when you have questions. > Well I still don't think it's what the documentation says, it would be much better if it told you that 'if the os.stat() signatures are not identical then the file contents are actually compared'. The implication to me when I read the documentation was that if shallow was True and the os.stat() signatures were not identical then False would be returned. Where does it say otehrwise? -- Chris Green From kyosohma at gmail.com Mon Sep 6 16:16:58 2010 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 6 Sep 2010 13:16:58 -0700 (PDT) Subject: The PSF Blog Gets a Transfusion! Message-ID: The Python Software Foundation?s Blog staff has been recently expanded by a new set of top-notch bloggers to bring you the latest in PSF news, ranging from the scintillating projects that the PSF has its fingers in to the mundane, but necessary board minutes. Don?t despair if you hate reading blogs! The blog also has a handy RSS feed and a mailing list! You can take your pick of these delivery methods by visiting the blog, at http://pyfound.blogspot.com/ From hobson42 at gmaiil.com Mon Sep 6 17:33:50 2010 From: hobson42 at gmaiil.com (Ian) Date: Mon, 06 Sep 2010 22:33:50 +0100 Subject: redirecting stdout and stderr for a windows service In-Reply-To: <4C84FAD8.6000108@ianhobson.co.uk> References: <4C84FAD8.6000108@ianhobson.co.uk> Message-ID: <4C855E3E.9090109@gmaiil.com> On 06/09/2010 15:29, Ian Hobson wrote: > Hi all, > Forget this. The problem is that it is a Windows Service, so it is not initialised in the normal way. PythonService.exe loads other code (named __main__) that loads the service proper, so the if test was never true! Regards Ian From shahama23 at hotmail.com Mon Sep 6 17:42:23 2010 From: shahama23 at hotmail.com (shahama23) Date: Mon, 6 Sep 2010 14:42:23 -0700 (PDT) Subject: YOU MUST KNOW THIS MAN Message-ID: <3ac1efd3-febe-4e48-ab97-fcf2593776f2@b34g2000yqm.googlegroups.com> In The Name Of Allaah, Most Gracious, Most Merciful YOU MUST KNOW THIS MAN MUHAMMAD (May peace and blessings of God Almighty be upon him) You may be an atheist or an agnostic; or you may belong to anyone of the religious denominations that exist in the world today. You may be a Communist or a believer in democracy and freedom. No matter what you are, and no matter what your religious and political beliefs, personal and social habits happen to be - YOU MUST STILL KNOW THIS MAN! He was by far the most remarkable man that ever set foot on this earth. He preached a religion, founded a state, built a nation, laid down a moral code, initiated numberless social and political reforms, established a dynamic and powerful society to practice and represent his teachings, and completely revolutionized the worlds of human thought and action for all times to come. HIS NAME IS MUHAMMAD, peace and blessings of Almighty God be upon him and he accomplished all these wonders in the unbelievably short span of twenty-three years. Muhammad, peace and blessings of God Almighty be upon him was born in Arabia on the 20th of August, in the year 570 of the Christian era, and when he died after 63 years, the whole of the Arabian Peninsula had changed from paganism and idol-worship to the worship of One God; from tribal quarrels and wars to national solidarity and cohesion; from drunkenness and debauchery to sobriety and piety; from lawlessness and anarchy to disciplined living; from utter moral bankruptcy to the highest standards of moral excellence. Human history has never known such a complete transformation of a people or a place before or since! The Encyclopedia Britannica calls him "the most successful of all religious personalities of the world". Bernard Shaw said about him that if Muhammad were alive today he would succeed in solving all those problems which threaten to destroy human civilization in our times. Thomas Carlysle was simply amazed as to how one man, single- handedly, could weld warring tribes and wandering Bedouins into a most powerful and civilized nation in less than two decades. Napoleon and Gandhi never tired of dreaming of a society along the lines established by this man in Arabia fourteen centuries ago. Indeed no other human being ever accomplished so much, in such diverse fields of human thought and behavior, in so limited a space of time, as did Muhammad, peace and blessings of God Almighty be upon him. He was a religious teacher, a social reformer, a moral guide, a political thinker, a military genius, an administrative colossus, a faithful friend, a wonderful companion, a devoted husband, a loving father - all in one. No other man in history ever excelled or equaled him in any of these difficult departments of life. The world has had its share of great personalities. But these were one sided figures who distinguished themselves in but one or two fields such as religious thought or military leadership. None of the other great leaders of the world ever combined in himself so many different qualities to such an amazing level of perfection as did Muhammad, peace and blessings of God Almighty be upon him. The lives and teachings of other great personalities of the world are shrouded in the mist of time. There is so much speculation about the time and the place of their birth, the mode and style of their life, the nature and detail of their teachings and the degree and measure of their success or failure that it is impossible for humanity today to reconstruct accurately and precisely the lives and teachings of those men. Not so this man Muhammad, peace and blessings of God Almighty be upon him. Not only was he born in the fullest blaze of recorded history, but every detail of his private and public life, of his actions and utterances, has been accurately documented and faithfully preserved to our day. The authenticity of the information so preserved is vouched for not only by faithful followers but also by unbiased critics and open-minded scholars. At the level of ideas there is no system of thought and belief-secular or religious, social or political-which could surpass or equal ISLAAM- the system which Muhammad peace and blessings of God Almighty be upon him propounded. In a fast changing world, while other systems have undergone profound transformations, Islaam alone has remained above all change and mutation, and retained its original form for the past 1400 years. What is more, the positive changes that are taking place in the world of human thought and behavior, truly and consistently reflect the healthy influence of Islam in these areas. Further, it is not given to the best of thinkers to put their ideas completely into practice, and to see the seeds of their labors grow and bear fruit, in their own lifetime. Except of course, Muhammad, peace and blessings of God Almighty be upon him, who not only preached the most wonderful ideas but also successfully translated each one of them into practice in his own lifetime. At the time of his death his teachings were not mere precepts and ideas straining for fulfillment, but had become the very core of the life of tens of thousands of perfectly trained individuals, each one of whom was a marvelous personification of everything that Muhammad peace and blessings of God Almighty be upon him taught and stood for. At what other time or place and in relation to what other political, social, religious system, philosophy or ideology-did the world ever witness such a perfectly amazing phenomenon? Indeed no other system or ideology secular or religious, social or political, ancient or modern - could ever claim the distinction of having been put into practice in its fullness and entirety EVEN ONCE in this world, either before or after the death of its founder. Except of course ISLAAM, the ideology preached by Muhammad, peace and blessings of God Almighty be upon him which was established as a complete way of life by the teacher himself, before he departed from this world. History bears testimony to this fact and the greatest skeptics have no option but to concede this point. In spite of these amazing achievements and in spite of the countless absolutely convincing and authentic miracles performed by him and the phenomenal success which crowned his efforts, he did not for a moment claim to be God or God's incarnation or Son - but only a human being who was chosen and ordained by God to be a teacher of truth to man kind and a complete model and pattern for their actions. He was nothing more or less than a human being. But he was a man with a noble and exalted mission-and his unique mission was to unite humanity on the worship of ONE AND ONLY GOD and to teach them the way to honest and upright living in accordance with the laws and commands of God. He always described himself as A MESSENGER AND SERVANT OF GOD, and so indeed every single action and movement of his proclaimed him to be. A world which has not hesitated to raise to Divinity individuals whose very lives and missions have been lost in legend and who historically speaking did not accomplish half as much-or even one tenth-as was accomplished by Muhammad, peace and blessings of God Almighty be upon him should stop to take serious note of this remarkable man's claim to be God's messenger to mankind. Today after the lapse of some 1400 years the life and teachings of Prophet Muhammad, peace and blessings of God Almighty be upon him, have survived without the slightest loss, alteration or interpolation. Today they offer the same undying hope for treating mankind's many ills which they did when Prophet Muhammad, peace and blessings of God Almighty be upon him, was alive. This is our honest claim and this is the inescapable conclusion forced upon us by a critical and unbiased study of history. The least YOU should do as a thinking, sensitive, concerned human being is to stop for one brief moment and ask yourself: Could it be that these statements, extraordinary and revolutionary as they sound, are really true? Supposing they really are true, and you did not know this man Muhammad, peace and blessings of God Almighty be upon him or hear about his teachings? Or did not know him well and intimately enough to be able to benefit from his guidance and example? Isn't it time you responded to this tremendous challenge and made some effort to know him? It will not cost you anything but it may well prove to be the beginning of a completely new era in your life. Come, let us make a new discovery of the life of this wonderful man Muhammad, peace and blessings of God Almighty be upon him the like of whom never walked on this earth, and whose example and teachings can change YOUR LIFE and OUR WORLD for the better. May God shower His choicest blessings upon him! And this link will help you more to know more about this man http://mohammad.islamway.com/ From ben+python at benfinney.id.au Mon Sep 6 19:36:52 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 09:36:52 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> Message-ID: <87wrqyculn.fsf@benfinney.id.au> Baba writes: > Thanks Jeremy, i will take your advice on board! Noone likes to be > taught lessons i think so it is only normal that i reacted. Please reconsider this response. Many of us use this forum precisely because we *do* like to be taught lessons. If you don't want to be taught lessons, this is not the forum to use. > If i had received a friendly response from Benjamin (as opposed to > "Please do us a favor and at least try to figure things out on your > own") Again, please reconsider your perception of the messages you received. Those messages are polite; they're even explicit about how you can improve your future messages. They are polite enough to regard you as a person who can improve. We value respect for people here, and that's what you've been shown consistently. But respect for opinions, or for delicacy about learning, is not welcome here. In other words, we treat people as adults by default. I hope you'll continue to participate in that spirit. -- \ ?I was gratified to be able to answer promptly and I did. I | `\ said I didn't know.? ?Mark Twain, _Life on the Mississippi_ | _o__) | Ben Finney From pavlovevidence at gmail.com Mon Sep 6 19:40:07 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 6 Sep 2010 16:40:07 -0700 (PDT) Subject: filecmp.cmp() doesn't seem to do what it says in the documentation References: <6gufl7-c9g.ln1@chris.zbmc.eu> Message-ID: <08e5d3b1-355d-463e-80d0-0916a3fdb6a6@13g2000prf.googlegroups.com> On Sep 6, 1:11?pm, tinn... at isbd.co.uk wrote: > Terry Reedy wrote: > > On 9/6/2010 1:18 PM, tinn... at isbd.co.uk wrote: > > > I'm using filecmp.cmp() to compare some files (surprise!). > > > > The documentation says:- > > > ? ? ?Unless shallow is given and is false, files with identical > > > ? ? ?os.stat() signatures are taken to be equal. > > > Reword and read carefully: if shallow == True and signatures are > > identical, then files are taken to be equal. > > > Here is the corresponding code from Lib/filecmp.py: > > ? ? ?if shallow and s1 == s2: > > ? ? ? ? ?return True > > > Does not say the result for non-identical signatures ;-). > > > > I'm not setting shallow explicitly so it's True, thus the function > > > should be comparing the os.stat() results. ?However this doesn't seem > > > to be the case as even if I touch one of the files to change it's > > > access/modification date filecmp.cmp() still returns True. > > > Because it goes on to actually compare the files, and they are equal. > > > ... > > ? ? ?result = _cache.get((f1, f2)) > > ? ? ?if result and (s1, s2) == result[:2]: > > ? ? ? ? ?return result[2] > > ? ? ?outcome = _do_cmp(f1, f2) > > ? ? ?_cache[f1, f2] = s1, s2, outcome > > ? ? ?return outcome > > > Most of the stdlib files in Python are quite readable. I recommend it > > when you have questions. > > Well I still don't think it's what the documentation says, it would be > much better if it told you that 'if the os.stat() signatures are not > identical then the file contents are actually compared'. ?The > implication to me when I read the documentation was that if shallow > was True and the os.stat() signatures were not identical then False > would be returned. ?Where does it say otehrwise? To me, "comparing files" means to compare the contents and nothing else, so when documentation says "Compare the files named f1 and f2" I think it has that covered. I understand the os.stat comparison to be a (non-foolproof) optimization. Anyway, if you just want to compare the os.stat parameters you should just use os.stat. os.stat(filename1) == os.stat(filename2) Then if you want, you can write a function to compare only the stats you are interested in. def mystatcmp(filename1,filename2): s1 = os.stat(filename1) s2 = os.stat(filename2) return s1.st_size == s2.st_size and s1.st_mtime == s2.st_mtime Carl Banks From davea at ieee.org Mon Sep 6 19:44:17 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 06 Sep 2010 19:44:17 -0400 Subject: Class changes in circular imports when __name__ == '__main__' In-Reply-To: References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: <4C857CD1.50604@ieee.org> On 2:59 PM, Carl Banks wrote: > On Sep 5, 5:07 pm, Dave Angel wrote: >> On 2:59 PM, Carl Banks wrote: >>> All of this gets a lot more complicated when packages are involved. >> Perhaps a better answer would be to import __main__ from the second module. > Then what if the module is imported from a different script? It'll > try to import __main__ but get a different script than expected. > > Then the module needs to adjust its expectations. The point is it should never try to import the script by name. DaveA From ben+python at benfinney.id.au Mon Sep 6 20:18:24 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 10:18:24 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> Message-ID: <87sk1mcsof.fsf@benfinney.id.au> Ben Finney writes: > We value respect for people here, and that's what you've been shown > consistently. But respect for opinions, or for delicacy about > learning, is not welcome here. Sloppy wording, I apologise. This should say ?? is not respect for a person?. > In other words, we treat people as adults by default. I hope you'll > continue to participate in that spirit. This is the main thrust of the message. -- \ ?What if the Hokey Pokey IS what it's all about?? ?anonymous | `\ | _o__) | Ben Finney From cuneyt.ertal at gmail.com Mon Sep 6 20:37:33 2010 From: cuneyt.ertal at gmail.com (ceycey) Date: Mon, 6 Sep 2010 17:37:33 -0700 (PDT) Subject: Minimum and Maximum of a list containing floating point numbers Message-ID: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', '9.0601']. What I want to do is to find minimum and maximum number in this list. I used min function, s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', '9.0601'] print min(s) print max(s) these gives me 1.181 9.0601 maximum value is wrong. It must be 10.24. I know why max function gives wrong number. Because max function processed elements of list as strings. How can I convert the elements of list to float so max function finds the correct answer. I hope I can explain my problem. Cuneyt. From contact at xavierho.com Mon Sep 6 20:44:21 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 7 Sep 2010 10:44:21 +1000 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: On 7 September 2010 10:37, ceycey wrote: > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. > How can I convert the elements > of list to float so max function finds the correct answer. > >>> input = ['3.4225', '7.7284', '10.24'] >>> [float(x) for x in input] [3.4225, 7.7284, 10.24] HTH, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Sep 6 20:56:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Sep 2010 01:56:58 +0100 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: <4C858DDA.2090103@mrabarnett.plus.com> On 07/09/2010 01:44, Xavier Ho wrote: > On 7 September 2010 10:37, ceycey > wrote: > > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. > > How can I convert the elements > of list to float so max function finds the correct answer. > > > >>> input = ['3.4225', '7.7284', '10.24'] > >>> [float(x) for x in input] > [3.4225, 7.7284, 10.24] > If you wanted to find the maximum value without converting the list to numbers you could do this: >>> input = ['3.4225', '7.7284', '10.24'] >>> max(input, key=float) '10.24' Incidentally, there's a builtin function called 'input' so using it as a variable name is a discouraged! :-) From python.list at tim.thechases.com Mon Sep 6 21:00:39 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 06 Sep 2010 20:00:39 -0500 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: <4C858EB7.3020802@tim.thechases.com> On 09/06/10 19:37, ceycey wrote: > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. What I want to do is to find minimum and maximum number in > this list. > > I used min function, > > print min(s) > print max(s) > > these gives me > > 1.181 > 9.0601 > > maximum value is wrong. It must be 10.24. > > I know why max function gives wrong number. Because max function > processed elements of list as strings. How can I convert the elements > of list to float so max function finds the correct answer. You can use min(float(v) for v in s) max(float(v) for v in s) to return the floating-point number, or in Python2.5+ you can use min(s, key=float) max(s, key=float) to get the string source. If you need the source string in pre-2.5, you'd have to do something like min((float(v), v) for v in s)[1] # 2.4 min([(float(v), v) for v in s])[1] # 2.3 or earlier and guard against empty input lists. -tkc From ben+python at benfinney.id.au Mon Sep 6 21:00:45 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 11:00:45 +1000 Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: <87fwxmcqpu.fsf@benfinney.id.au> ceycey writes: > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. What I want to do is to find minimum and maximum number in > this list. As you correctly describe later, there aren't any numbers in that list; only strings. > How can I convert the elements of list to float so max function finds > the correct answer. If you're going to use the list of float objects, you can convert them all with a list comprehension. >>> numbers_as_str = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', ... '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', ... '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', ... '9.0601'] >>> numbers_as_float = [float(x) for x in numbers_as_str] >>> print min(numbers_as_float), max(numbers_as_float) 1.1881 10.24 -- \ ?As scarce as truth is, the supply has always been in excess of | `\ the demand.? ?Josh Billings | _o__) | Ben Finney From marduk at letterboxes.org Mon Sep 6 21:01:29 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Mon, 06 Sep 2010 21:01:29 -0400 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: <1283821289.467035.8.camel@paska> On Mon, 2010-09-06 at 17:37 -0700, ceycey wrote: > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. What I want to do is to find minimum and maximum number in > this list. > > I used min function, > > s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', > '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', > '9.0601', '9.0601'] > > print min(s) > print max(s) > > these gives me > > 1.181 > 9.0601 > > maximum value is wrong. It must be 10.24. You are not comparing a list of floats but a list of strings. > I know why max function gives wrong number. Because max function > processed elements of list as strings. How can I convert the elements > of list to float so max function finds the correct answer. min/max in these cases are returning strings as well. So the fact remains that the max function is not giving you a number at all, but a string, and as such is correct. String comparison is not identical to numerical comparison. But to answer your question: >>> s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', ... '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', ... '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', ... '9.0601', '9.0601'] >>> [type(x) for x in s] [, , , , , , , , , , , , , , , , , , , ] >>> type(max(s)) >>> t = [float(x) for x in s] >>> [type(x) for x in t] [, , , , , , , , , , , , , , , , , , , ] >>> min(t) 1.1880999999999999 >>> max(t) 10.24 >>> type(max(s)) >>> type(max(t)) From steve-REMOVE-THIS at cybersource.com.au Mon Sep 6 22:31:17 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 07 Sep 2010 02:31:17 GMT Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> Message-ID: <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: > If you're going to use the list of float objects, you can convert them > all with a list comprehension. [...] > >>> numbers_as_float = [float(x) for x in numbers_as_str] That's awfully verbose. A map is simpler: numbers_as_float = map(float, numbers_as_str) -- Steven From ben+python at benfinney.id.au Mon Sep 6 22:40:57 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 12:40:57 +1000 Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> Message-ID: <87bp8acm2u.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: > > > If you're going to use the list of float objects, you can convert them > > all with a list comprehension. > [...] > > >>> numbers_as_float = [float(x) for x in numbers_as_str] > > That's awfully verbose. A map is simpler: > > numbers_as_float = map(float, numbers_as_str) I'll pay ?verbose?, but not ?awfully?. There is little difference in verbosity between your example and mine. Further, I don't see my example as excessive, which I assume your ?awfully? entails. -- \ ?I call him Governor Bush because that's the only political | `\ office he's ever held legally.? ?George Carlin, 2008 | _o__) | Ben Finney From steve-REMOVE-THIS at cybersource.com.au Mon Sep 6 23:14:06 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 07 Sep 2010 03:14:06 GMT Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c85adfe$0$11115$c3e8da3@news.astraweb.com> On Mon, 06 Sep 2010 11:38:22 +0100, BartC wrote: > Modifying the OP's code a little: > > a = 0 > for i in xrange(100000000): # 100 million > a = a + 10 # add 10 or 100 > print a > > Manually unrolling such a loop four times (ie. 4 copies of the body, and > counting only to 25 million) increased the speed by between 16% and 47% > (ie. runtime reducing by between 14% and 32%). Or you could *really* optimize it, as well as simplifying the code, by writing: n = 100000000 a = 10*n and doing a single multiplication rather than pointless repeated addition. (I assume that the number of loops is meant to be a variable rather than a constant, otherwise a = 1000000000 would be the correct optimization.) Of course, if 10 (or 100) is not a constant but is just standing in for something which varies each iteration: for i in xrange(100000000): a = a + f(i) then unrolling the loop is even less useful. The overhead of the loop itself is likely to be trivial compared to the cost of calling f() 100 million times -- the added complexity to shave 3 seconds off a four minute calculation simply isn't worth it. Besides, loop unrolling really only is valuable for small loops, otherwise the overhead caused by the increased code size makes it a pessimation rather than an optimization. It's very easy for any gains to be lost due to increased cache misses, time needed to copy the code into memory, etc. http://en.wikipedia.org/wiki/Loop_unwinding There's a lot of subtlety in optimization, and what counts as an optimization for low-level operations, and what is an optimization for high-level languages like Python, are rarely the same. > This depended on whether I added +10 or +100 (ie. whether long integers > are needed), whether it was inside or outside a function, and whether I > was running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange' > as a synonym for 'range'?) Why should it? But if you want it, you can do it: xrange = range There, that wasn't hard, was it? > These are just some simple tests on my particular machine and > implementations, but they bring up some points: > > (1) Loop unrolling does seem to have a benefit, when the loop body is > small. > > (2) Integer arithmetic seems to go straight from 32-bits to long > integers; why not use 64-bits before needing long integers? Why? That adds 50% more code, 50% more testing, 50% more places for bugs to hide, 50% more effort required to maintain it, for something which *at best* will be a trivial optimization which at best is of interest to a small minority of Python coders. There's already code to deal with 32 bit its, code to deal with longints, and code to deal with shifting transparently from one to the other. Adding code to deal with 64 bit ints doesn't happen for free. Besides, if you care about the difference between 32 and 64 bit ints, chances are you don't want Python blithely swapping from one to the other when you least expect it. So you'll be using a library that gives you access to whichever ints you want, probably implemented natively rather than as objects. Sounds rather like numpy really :) http://docs.scipy.org/doc/numpy/user/basics.types.html > (3) Since the loop variable is never used, why not have a special loop > statement that repeats code so many times? This can be very fast, since > the loop counter need not be a Python object, and probably there would > be no need for unrolling at all: > > repeat 100000000: # for example > a = a + 10 Because now both the parser and all Python coders need to care about one more reserved word, all so that one Python program in ten thousand can save 0.1 ms occasionally. Optimizations don't happen for free. If the optimization doesn't carry it's own weight, it's a pessimation. To me, it's more important to be able to be able to use repeat as a name: connect_to_server("localhost", repeat=10) than to save a millisecond or so. Besides, if repeat were to become syntax, then I'd MUCH rather have it used for repeat...until (or repeat...while) loops, to avoid the anti- pattern of: x = f() while not condition(x): x = f(x) which would be better as: repeat: x = f() until condition(x) -- Steven From phlip2005 at gmail.com Mon Sep 6 23:48:08 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 6 Sep 2010 20:48:08 -0700 (PDT) Subject: The Samurai Principle Message-ID: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Pythonistas: The "Samurai Principle" says to return victorious, or not at all. This is why django.db wisely throws an exception, instead of simply returning None, if it encounters a "record not found". I illustrated the value of that concept, here: http://c2.com/cgi/wiki?SamuraiPrinciple From steve-REMOVE-THIS at cybersource.com.au Mon Sep 6 23:50:41 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 07 Sep 2010 03:50:41 GMT Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> <87bp8acm2u.fsf@benfinney.id.au> Message-ID: <4c85b691$0$11115$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 12:40:57 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: >> >> > If you're going to use the list of float objects, you can convert >> > them all with a list comprehension. >> [...] >> > >>> numbers_as_float = [float(x) for x in numbers_as_str] >> >> That's awfully verbose. A map is simpler: >> >> numbers_as_float = map(float, numbers_as_str) > > I'll pay ?verbose?, but not ?awfully?. There is little difference in > verbosity between your example and mine. Further, I don't see my example > as excessive, which I assume your ?awfully? entails. Sorry, verbose is not the word I want... I don't know what word I *actually* want, so let me explain. Instead of thinking about a single transformation "change a list of strings to a list of floats", the list comp form forces you to think about the individual list items and the mechanics of looping, and reduces lists to a second-class data type: we can operate on ints without caring about individual bits, but we can't operate on lists without caring about individual list items. Why do I need to care about individual items? The list comp even gives them a name, "x" in your example, even though that name isn't used anywhere else. Why do I need to specify that walking the list must be done from left-to-right rather than whatever order the compiler thinks best, or even in parallel? Answer: I don't, and shouldn't need to. With map, such internal details of how the transformation is performed is hidden. I shouldn't need to specify *how* to convert a list of strings to a list of floats. While a list comp is less verbose than a for-loop, which is less again than a while-loop, they all specify how to do the transformation, which is mental overhead I shouldn't need to care about. Of course, list comps are so seductively easy, and functional programming so conceptually different from what many people are used to, that such over-specification is an awfully easy trap to fall into. I'm sure my own code is filled with similar examples where I use a list comp where a map is more suitable. -- Steven From laicheng_kwan at innomedia.com.sg Tue Sep 7 00:06:47 2010 From: laicheng_kwan at innomedia.com.sg (Kwan Lai Cheng) Date: Tue, 7 Sep 2010 12:06:47 +0800 Subject: Bit fields in python? Message-ID: Hi, I'm trying to rewrite a c program in python & encountered several problems. I have some data structures in my c program like below: typedef struct { unsigned short size; unsigned short reserved:8; unsigned short var_a1:2; unsigned short var_a2:2; unsigned short var_a3:2; unsigned short var_a4:2; unsigned int var_a5; }structa; typedef struct { unsigned short size; unsigned char reserved:4; unsigned char var_b1:1; unsigned char var_b2:1; unsigned char var_b3:1; unsigned char var_b4:1; structa var_structa; }structb; I tried to code the above in python but only got this far: class StructA(object): def __init__(self, size=0) self.size = size class StructB(object): def __init__(self, size=0) Any equivalent for c data structures & bit fields in python? And how do I define var_structa (in structb) in python? Regards, Kwan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue Sep 7 00:20:43 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 14:20:43 +1000 Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> <87bp8acm2u.fsf@benfinney.id.au> <4c85b691$0$11115$c3e8da3@news.astraweb.com> Message-ID: <8739tmchgk.fsf@benfinney.id.au> Steven D'Aprano writes: > Of course, list comps are so seductively easy, and functional > programming so conceptually different from what many people are used > to, that such over-specification is an awfully easy trap to fall into. > I'm sure my own code is filled with similar examples where I use a > list comp where a map is more suitable. Right. I find list comprehensions and generator expressions easy both to write and to read. So I prefer them, and often don't consider more function-based approaches. I don't think my code (nor my examples) suffer much as a result. -- \ ?Rightful liberty is unobstructed action, according to our | `\ will, within limits drawn around us by the equal rights of | _o__) others.? ?Thomas Jefferson | Ben Finney From kurianmthayil at gmail.com Tue Sep 7 00:27:28 2010 From: kurianmthayil at gmail.com (Kurian Thayil) Date: Tue, 7 Sep 2010 09:57:28 +0530 Subject: mail sending -- smtplib Message-ID: Hi All, I am a newbie in python. Just 2-3 days old wanting to learn this amazing programming language. I was trying to send mails using smtplib module, so did some google and found a code snippet. The mail gets sent, but doesn't come in the right format when a for-loop is introduced (Not MIME standard?). Without the for-loop the script works fine. Can anyone advice? * #!/usr/bin/env python import smtplib for i in range(1,5): print "I is ",i fromaddr='kurianmthayil at gmail.com' toaddr='kurianmthayil at gmail.com' print toaddr mssg="""From: Kurian Thayil To: Kurian Thayil MIME-Version: 1.0 Content-type: text/html Subject: 12345 -- Reloaded :) Hey dude.. how are you????



Regards,

Kurian """ print "message is ",mssg smail=smtplib.SMTP('smtp.gmail.com',587) smail.ehlo() smail.starttls() smail.ehlo() smail.login(fromaddr,'***********') smail.sendmail(fromaddr,toaddr,mssg) print "Over" * Regards, Kurian Thayil. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Tue Sep 7 01:08:22 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 6 Sep 2010 22:08:22 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: <39c85ff7-f1bb-47ad-95b3-bcb9ce9c0c5b@i4g2000prf.googlegroups.com> On Sep 6, 4:44?pm, Dave Angel wrote: > On 2:59 PM, Carl Banks wrote:> On Sep 5, 5:07 pm, Dave Angel ?wrote: > >> On 2:59 PM, Carl Banks wrote: > >>> All of this gets a lot more complicated when packages are involved. > >> Perhaps a better answer would be to import __main__ from the second module. > > Then what if the module is imported from a different script? ?It'll > > try to import __main__ but get a different script than expected. > > Then the module needs to adjust its expectations. No, it shouldn't. It shouldn't have any expectations at all, because importing __main__ and expecting to get a particular module is a foolish thing to do. There are a bunch of reasons why __main__ might not be the original script. Example: running the profiler on it. > The point is it > should never try to import the script by name. Importing __main__ directly is worse than the problem it's trying to solve. And "never" is too strong a word. I already in this thread gave a solution whereby the script can be imported by name safely, by renaming itself and assigning itself an item in sys.modules. When you do that, you can import the main script by name. Carl Banks From ragmanme at gmail.com Tue Sep 7 01:19:46 2010 From: ragmanme at gmail.com (Ryan George) Date: Mon, 6 Sep 2010 22:19:46 -0700 (PDT) Subject: How to determine if a Python script is being run right after startup on Windows Message-ID: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> Hello! I'm a newbie to Python (literally just started last Saturday), and I coded a program that selects a random wallpaper from a directory and swaps it with your current one (Windows only.) What I'm looking to do is have it start up with Windows and automatically swap the wallpapers. This part I have already coded, and as far as I know, it should work. However, I want the user to be able to access the GUI after this initial running of the program. The way it is set up now, enabling "Start Up Mode" will cause the program to cycle the wallpapers and then immediately exit. My question is this: is there any way I can determine if the program is being run directly after a startup on a Windows machine? Thanks, Ryan From steve-REMOVE-THIS at cybersource.com.au Tue Sep 7 01:57:30 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 07 Sep 2010 05:57:30 GMT Subject: How to determine if a Python script is being run right after startup on Windows References: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> Message-ID: <4c85d44a$0$28651$c3e8da3@news.astraweb.com> On Mon, 06 Sep 2010 22:19:46 -0700, Ryan George wrote: > My question is this: is there any way I can determine if the program is > being run directly after a startup on a Windows machine? How would you, a human being, determine if the program was being run directly after startup? What counts as "directly"? Within 10 seconds? Before any other program with a GUI? Before *any* other program, including background processes? Before the Windows desktop loads? You also said: "What I'm looking to do is have it start up with Windows and automatically swap the wallpapers. This part I have already coded, and as far as I know, it should work." As far as you know, it SHOULD work? How about trying it and finding out? In any case, it sounds to me that what you need is two programs, one which automatically sets the wallpaper at startup, and a second that is a GUI. -- Steven From sajuptpm at gmail.com Tue Sep 7 02:42:27 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Mon, 6 Sep 2010 23:42:27 -0700 (PDT) Subject: list of tuples with dynamic change in position References: Message-ID: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> More details I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), ((cpu_util,mem_util),(disk_util))] ie, l = [((30,50),(70)), ((50,20),(20))] l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and disk_util desc suppose i changed order that is l = [((mem_util,cpu_util), (disk_util)), ((mem_util,cpu_util),(disk_util))] So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], x[1][0])) # sorting cpu_util asc and disk_util desc I want to use same (common) sort code, that must work even if i changed tuple order. From stefan_ml at behnel.de Tue Sep 7 02:55:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 07 Sep 2010 08:55:54 +0200 Subject: Bit fields in python? In-Reply-To: References: Message-ID: Kwan Lai Cheng, 07.09.2010 06:06: > I'm trying to rewrite a c program in python& encountered several problems. I have some data structures in my c program like below: > > typedef struct > { > unsigned short size; > > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsigned short var_a3:2; > unsigned short var_a4:2; > > unsigned int var_a5; > }structa; > > typedef struct > { > unsigned short size; > > unsigned char reserved:4; > unsigned char var_b1:1; > unsigned char var_b2:1; > unsigned char var_b3:1; > unsigned char var_b4:1; > > structa var_structa; > }structb; > > I tried to code the above in python but only got this far: > > class StructA(object): > def __init__(self, size=0) > self.size = size > > class StructB(object): > def __init__(self, size=0) > > Any equivalent for c data structures& bit fields in python? If you can tell us what these structs are being used for in the original C code, we might be able to point you to a suitable way to implement the same thing efficiently in Python. Stefan From __peter__ at web.de Tue Sep 7 03:16:30 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 09:16:30 +0200 Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> Message-ID: sajuptpm wrote: > More details > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > ((cpu_util,mem_util),(disk_util))] > ie, l = [((30,50),(70)), ((50,20),(20))] > > l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and > disk_util desc > > suppose i changed order that is l = [((mem_util,cpu_util), > (disk_util)), ((mem_util,cpu_util),(disk_util))] > So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], > x[1][0])) # sorting cpu_util asc and disk_util desc > > > I want to use same (common) sort code, that must work even if i > changed tuple order. Use namedtuples: from collections import namedtuple Pair = namedtuple("Pair", "pair disk_util") A = namedtuple("A", "cpu_util mem_util") B = namedtuple("B", "mem_util cpu_util") # you can safely omit this step for class_ in A, B, Pair: del class_.__repr__ items = [((30,50), 70), ((50,20),20)] a = [Pair(A(x, y), z) for (x, y), z in items] b = [Pair(B(y, x), z) for (x, y), z in items] def sort(items): items.sort(key=lambda x: x.pair.mem_util, reverse=True) items.sort(key=lambda x: x.pair.cpu_util) sort(a) print a sort(b) print b Peter From grflanagan at gmail.com Tue Sep 7 03:47:48 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Tue, 7 Sep 2010 00:47:48 -0700 (PDT) Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> Message-ID: <00f05409-3b64-4d8a-a5c4-92d22e7ba0c1@m1g2000yqo.googlegroups.com> On 7 Sep, 07:42, sajuptpm wrote: > More details > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > ((cpu_util,mem_util),(disk_util))] > ie, l = [((30,50),(70)), ((50,20),(20))] > > l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and > disk_util desc > > suppose i changed order that is l = [((mem_util,cpu_util), > (disk_util)), ((mem_util,cpu_util),(disk_util))] > So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], > x[1][0])) # sorting cpu_util asc and disk_util desc > > I want to use same (common) sort code, that must work even if i > changed tuple order. If you have a sort function that works just leave it as it is and rearrange your data before passing it to the sort function. Eg. ---------------------------------- d1 = [ ((30,50),(90,)), ((30,50),(70,)), ((50,20),(20,)), ((20,20),(50,)), ((20,20),(60,)), ((20,20),(10,)), ] d2 = [ ((50,30),(90,)), ((50,30),(70,)), ((20,50),(20,)), ((20,20),(50,)), ((20,20),(60,)), ((20,20),(10,)), ] def _sort_the_tuples(iterable): #print list(iterable) return sorted(iterable, key=lambda t: (-t[0][0], t[1][0])) def sort_the_tuples(iterable, rearrange=lambda X: X): return _sort_the_tuples(rearrange(t) for t in iterable) assert sort_the_tuples(d1) == \ sort_the_tuples(d2, lambda X: ((X[0][1], X[0][0]), (X[1][0],))) -------------------------------- The point of my previous response was to deal with a list of dictionaries and sort by attribute rather than index, but whatever works. Regards From ragmanme at gmail.com Tue Sep 7 04:10:14 2010 From: ragmanme at gmail.com (Ryan George) Date: Tue, 7 Sep 2010 01:10:14 -0700 (PDT) Subject: How to determine if a Python script is being run right after startup on Windows References: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> <4c85d44a$0$28651$c3e8da3@news.astraweb.com> Message-ID: Hello Stephen, Thanks for the prompt response! >How would you, a human being, determine if the program was being run directly after startup? I'm not going to claim that I am a computer systems expert; I don't know a whole lot about what goes on in the Windows start up. I know services and programs are started, Internet connections are made, and connections to devices on your computer are tested. However, these are all things that could happen at any time (programs: obviously; Internet could disconnect; unplugging or plugging in a mouse, for example). That's why I came here. Maybe someone knew something I didn't. I know you're trying to get me to come to my own conclusion of my own accord, but I have been attacking this problem for 8 hours. If the answer was within my knowledge, I believe would have discovered it by now. >What counts as "directly"? Within 10 seconds? Before any other program with a GUI? Before *any* other program, including background processes? Before the Windows desktop loads? Maybe I should have made my purpose clearer. What I want the program to do is perform its normal function (ie: swap your wallpaper with a random one from a given directory) automatically after Windows completely starts up, and then exit so as not to remain in memory. With this new information, the answer to all of these questions should be obvious. Since it depends on calls to the Windows API, this program should be one of the last things to start, if not THE last thing. >As far as you know, it SHOULD work? How about trying it and finding out? Again, I probably should have been clearer. This functionality DOES work. The program will swap the wallpapers, then exit. The only thing I haven't tested is if it will work at start up, which would have required a reboot of my computer, something I really didn't want to have to do. I was in the process of coding other, more critical features with around 20 different tabs opened in Firefox, as well as participating communications with someone who was designing a logo for me. I will be testing it next time I boot my computer. >In any case, it sounds to me that what you need is two programs, one which automatically sets the wallpaper at startup, and a second that is a GUI. Yes, that is an option. However, my previous wallpaper cycler was able to do what I am describing without two separate programs and I have just discovered how. It was a switch on the executable that isn't present when you try to run the program normally. This was probably the first thing I should have looked into and I don't know why I did not. As long as I can pass variables through a command line when executing a Python script, I see no reason why this shouldn't work. This technically isn't the system letting the program know that it is running after a start up, but rather a user telling a program that "I am running you after a start up." Little bit of a different approach, but hey, whatever works right? From eckhardt at satorlaser.com Tue Sep 7 04:16:33 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Tue, 07 Sep 2010 10:16:33 +0200 Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> Message-ID: <109hl7-ao8.ln1@satorlaser.homedns.org> sajuptpm wrote: > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > ((cpu_util,mem_util),(disk_util))] > ie, l = [((30,50),(70)), ((50,20),(20))] > > l.sort(key=lambda x:(-x[0][0], x[1][0])) > # sorting cpu_util asc and disk_util desc One thing here: Without knowing what special meaning the indices have, this code is impossible to understand. In my opinion, that code should rather be l.sort(key=lambda x: (-x.cpu_util, x.disk_util)) You could then save the comment, which btw may or may not describe the actual code. > suppose i changed order that is l = [((mem_util,cpu_util), > (disk_util)), ((mem_util,cpu_util),(disk_util))] > So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], > x[1][0])) # sorting cpu_util asc and disk_util desc > > I want to use same (common) sort code, that must work even if i > changed tuple order. You don't have to use a lambda function. You can as well define the sorting order in the same place of your code where you define the order inside the elements, that way you would only have to adjust the sorting in one place. Otherwise, you will have to embed the order of the tuple inside the tuple or the containing list. One approach would be to have a dictionary (which has no order), or you use a separate type instead: class record(object): pass r = record() r.cpu_util = 12 r.disk_util = 42 l.append(r) However, this basically all boils down to either "don't use the sorting (dict)" or "keep records sorted", so it doesn't really answer your question. However, I'm afraid there is no answer to your question as it stands. Maybe I could help you better if you explained why the order changes etc, because normally I don't deal with data that has such a volatile meaning, I rather normalize it on input and then use it in the same way afterwards. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Tue Sep 7 04:36:56 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 10:36:56 +0200 Subject: Newby Needs Help with Python code References: <861505.20099.qm@web33506.mail.mud.yahoo.com> Message-ID: Nally Kaunda-Bukenya wrote: > I am very sorry to bother you, but I need help understanding the code that > you assisted me with. It does exactly what I needed done, I can't thank > you enough for that. I am just learning Python, and would appreciate all > the help. please see my comments below and help me understand the code. Please don't email me directly, send questions to the list instead to give more people a chance to answer. > Code below: > > #WHAT IS A DICT? SAME AS LIST? This is a very basic question which is dealt with in every tutorial. Look here for a starting point: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers > #iterate over the Outfalls_ND table twice, the first time to calculate the > #sums per OUTFALL_ID and put them into a dict. With the second pass the > #Tot_Outf_Area column is updated > import arcgisscripting > def rows(cur): > while True: > row = cur.Next() > if row is None: > break #?? > yield row #?? break terminates a loop, yield gives back a result without terminating the function which is then called "generator". For now I recommend that you treat this generator as a black box. > gp = arcgisscripting.create() > gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb" > TABLE = "Outfalls_ND" > GROUP = "OUTFALL_ID" #does upper case mean anything?? (group below is lower > case?) Python is case-sensitive, so GROUP and group (and Group or grouP) are different names. I am following a convention here that uppercase names are used for constants, i. e. the value of GROUP never changes after the first assignment. > SUM = "AREA_ACRES" > TOTAL = "Tot_Outf_Area" > > aggregate = {} > cur = gp.UpdateCursor(TABLE) > for row in rows(cur): #is this diff from for rows in cur? > group = row.GetValue(GROUP) #loop thru rows and search for outfall_ID > amount = row.GetValue(SUM) #loop thru rows and search for area_acres > aggregate[group] = aggregate.get(group, 0.0) + amount #need help > w/explanation on aggregate fn > #aggregate[group] is what is it? is this a list of unique outfall_ID's? > #aggregate.get (group, 0.0) how do you get 0.0? > #I tried this code on a diff field and got this error: TypeError: > unsupported operand #type(s) for +: 'float' and 'NoneType' > > cur = gp.UpdateCursor(TABLE) > for row in rows(cur): > group = row.GetValue(GROUP) > row.SetValue(TOTAL, aggregate[group]) #?? > cur.UpdateRow(row) Sorry, I don't think answering any of the above questions worthwhile until you've worked through an introductory text. Once you /have/ a basic understanding you can often find out the answers by asking python itself. Just fire up the interactive interpreter and type >>> help(dict.get) If the explanation given there is not sufficient you can use the online documentation as a fallback: http://docs.python.org/library/stdtypes.html#mapping-types-dict Good look with your efforts! Peter From laicheng_kwan at innomedia.com.sg Tue Sep 7 04:39:48 2010 From: laicheng_kwan at innomedia.com.sg (Kwan Lai Cheng) Date: Tue, 7 Sep 2010 16:39:48 +0800 Subject: Bit fields in python? References: Message-ID: <13E27E02A9B14910A389A4495E729543@cs0403293> ----- Original Message ----- From: Stefan Behnel To: Sent: Tuesday, September 07, 2010 2:55 PM Subject: Re: Bit fields in python? > > If you can tell us what these structs are being used for in the original C > code, we might be able to point you to a suitable way to implement the > same > thing efficiently in Python. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > It's a test program for testing the DSP (Digital Signal Processor). Basically what it does is that it sends commands to the DSP via a driver and waits for a response from the DSP. The structures represent the data that I might receive from the DSP. For example if I send command A, DSP will send data in the format of structa to me, so I will cast the data I received to structa, and print the struct field values on screen. Each field in the structures represent some status or info about the DSP, different bits in an unsigned char or unsigned short field might represent different DSP status. I just found out that there's a ctypes module (http://docs.python.org/library/ctypes.html) in python that might solve my problem. I understand that it is already included in Python 2.5 & I'm using Python 2.6.2. However when I tried "from ctypes import *", I got "No module named _ctypes". What am I missing here? From jerry.fleming at saybot.com Tue Sep 7 05:39:18 2010 From: jerry.fleming at saybot.com (Jerry Fleming) Date: Tue, 07 Sep 2010 17:39:18 +0800 Subject: sqlalchemy: how to define association object with declarative style? Message-ID: Hi, I want to define the relationship for my users and their groups with declarative style (so that the relating model can inherit Timestamp mixin and Tablename mixin): class User(DeclarativeBase, Tablename, TimestampMixin): '''User avatar is named after its id. A user may be a student or teacher or both. ''' id = Column(Integer, Sequence('user_id_seq'), primary_key=True) username = Column(String(30), index=True, nullable=False, unique=True) password = Column(String(30), index=True, nullable=False) class Group(DeclarativeBase, Tablename, TimestampMixin): id = Column(Integer, Sequence('group_id_seq'), primary_key=True) name = Column(Unicode(20), unique=True, nullable=False) display = Column(Unicode(255)) class GroupUser(DeclarativeBase, Tablename, TimestampMixin): id = Column(Integer, Sequence('group_user_id_seq'), primary_key=True) user = Column(Integer, ForeignKey('user.id'), index=True), group = Column(Integer, ForeignKey('group.id'), index=True) I was wondering how to associate User and Group with GroupUser with GroupUser as the association object/proxy? The sqlalchemy docs only mention only mention association tables, or non-declarative manual mapping. Thanks. From thossie at gmail.com Tue Sep 7 05:43:26 2010 From: thossie at gmail.com (Dennis Verdonschot) Date: Tue, 7 Sep 2010 02:43:26 -0700 (PDT) Subject: How to determine if a Python script is being run right after startup on Windows References: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> <4c85d44a$0$28651$c3e8da3@news.astraweb.com> Message-ID: Hi Ryan, Maybe I'm missing something, but wouldn't creating a shortcut and putting that shortcut in your Start - Programs - Startup section of the Windows menu not work for this program? Or if really needed you can edit the start-up programs in the registry. If you add some logging ability to your program you can verify it has been run and you can still use commandline arguments by changing the shortcut. -- Dennis From bartc at freeuk.com Tue Sep 7 06:00:03 2010 From: bartc at freeuk.com (BartC) Date: Tue, 7 Sep 2010 11:00:03 +0100 Subject: Speed-up for loops In-Reply-To: <4c85adfe$0$11115$c3e8da3@news.astraweb.com> References: <4C7F7640.1010102@perfect-kreim.de><4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c85adfe$0$11115$c3e8da3 at news.astraweb.com... > On Mon, 06 Sep 2010 11:38:22 +0100, BartC wrote: >> >> Manually unrolling such a loop four times (ie. 4 copies of the body, and >> counting only to 25 million) increased the speed by between 16% and 47% >> (ie. runtime reducing by between 14% and 32%). > > Or you could *really* optimize it, as well as simplifying the code, by > writing: > > n = 100000000 > a = 10*n > > and doing a single multiplication rather than pointless repeated addition. It's not pointless; it's being used as a test of long it takes to do a=a+10 a hundred million times in a loop. (Similarly, if we wanted to investigate the speed of function calls, then a 'pointless' recursive implementation of fibonacci(36) that needed 76 million (or whatever) calls is far more useful than one that did it with just 1. But a lot of people just don't get this, for example some of the comments here: http://programmingzen.com/2007/11/28/holy-shmoly-ruby-19-smokes-python-away/ ) > Of course, if 10 (or 100) is not a constant but is just standing in for > something which varies each iteration: > > for i in xrange(100000000): > a = a + f(i) > > then unrolling the loop is even less useful. The overhead of the loop > itself is likely to be trivial compared to the cost of calling f() 100 > million times -- the added complexity to shave 3 seconds off a four > minute calculation simply isn't worth it. With Python 3 and def f(x): return x+1, unrolling this loop 4x improved speed by 15%; 4.00 minutes reduces to 3.30 minutes. In this code (adapted from a real piece of Python code): for i in xrange(1000000): a[i]=0 Unrolling 4x produced a 47% speedup. Now your program only takes 2:45 minutes. >(BTW why doesn't Python 3 just accept 'xrange' as a synonym for 'range'?) > > Why should it? But if you want it, you can do it: > > xrange = range > > There, that wasn't hard, was it? I think I just learned more about Python than from months of reading this group. So 'range' is just a class like any other. And that a class is something you can blithely copy from one variable to another. And whenever you see 'range' anywhere, you can't always be certain that someone hasn't done: range = 42 at some point. That explains a lot about the difficulties of implementing Python efficiently. (And the xrange=range trick works well thanks.) >) Integer arithmetic seems to go straight from 32-bits to long >> integers; why not use 64-bits before needing long integers? > > Why? That adds 50% more code, 50% more testing, 50% more places for bugs > to hide, 50% more effort required to maintain it, for something which *at > best* will be a trivial optimization which at best is of interest to a > small minority of Python coders. I would have suggested just using 64-bits anyway (on 32-bit hardware) as, currently, the slight extra overhead would be insignificant, provided it doesn't result in double the memory when there are many integers. As for being of minority interest, with the whole world rapidly becoming 64-bits, I would dispute that... >> repeat 100000000: # for example >> a = a + 10 > > Because now both the parser and all Python coders need to care about one > more reserved word, all so that one Python program in ten thousand can > save 0.1 ms occasionally. That's a minor detail. You can call it whatever you like. -- Bartc From ian at ianhobson.co.uk Tue Sep 7 06:18:10 2010 From: ian at ianhobson.co.uk (Ian Hobson) Date: Tue, 07 Sep 2010 11:18:10 +0100 Subject: Help needed - function apparently global cannot be called. Message-ID: <4C861162.9020100@ianhobson.co.uk> Hi all you experts, This has me beat. Has anyone any ideas about what might be going wrong? This is code from within a windows service (hence no print statements - no sys.stdout to print on!). I am trying to trace through to find where the code is not working. No stdout so I have to log to a file. I have the following code fragments. def log(message): f = open('d:\logfile.txt','a') f.write(message + "\n") f.close() from DelNotePrinter import DelNotePrinter note the order of the above - log is defined before the import. Later in the source I have log('disPrint is:'+disPrint) log('count is:'+count) log(repr(DelNotePrinter)) printer = DelNotePrinter(disPrint,int(count)) The DelNotePrinter.py file cannot us log even though it is declared as global. The code is... # coding=utf8 # DelNotePrinter = code to print delivery notes assorted imports removed for space reasons class DelNotePrinter(object): ''' Print Delivery Note on A5 in portrait ''' def __init__(self,printer,copies): ''' create printer and painter ''' global font,sm,log log('DelNotePrinter: starting') self.printer = QPrinter(QPrinter.HighResolution) etc The file the log writes contains.. disPrint is:HP Deskjet 6940 series count is:1 The > is followed by a newline and end of file! Where is the DelNotePrinter: starting message? If I replace the opening of __init__ with global font,sm,log f = open('d:\logfile.txt','a') f.write('DelNotePrinter: starting' + "\n") f.close() self.printer = QPrinter(QPrinter.HighResolution) then the message IS written to the log file. I have read http://docs.python.org/reference/simple_stmts.html#global very carefully and I still don't understand. Regards Ian p.s. There are no trackbacks, no events on the event log, and no error messages I have been able to find. When run as a script (not a service) DelNotePrinter does produce the expected printout. From krister.svanlund at gmail.com Tue Sep 7 06:19:02 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Tue, 7 Sep 2010 12:19:02 +0200 Subject: How to determine if a Python script is being run right after startup on Windows In-Reply-To: References: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> <4c85d44a$0$28651$c3e8da3@news.astraweb.com> Message-ID: On Tue, Sep 7, 2010 at 11:43 AM, Dennis Verdonschot wrote: > Hi Ryan, > > Maybe I'm missing something, but wouldn't creating a shortcut and > putting that shortcut in your Start - Programs - Startup section of > the Windows menu not work for this program? Or if really needed you > can edit the start-up programs in the registry. > > If you add some logging ability to your program you can verify it has > been run and you can still use commandline arguments by changing the > shortcut. > > -- > Dennis > -- > http://mail.python.org/mailman/listinfo/python-list > I would recommend using a commandline switch (look at sys.argv in documentation) and just start the script with something like python script.py --change-wallpaper or maybe require a switch for getting to the GUI... From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 06:50:19 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 12:50:19 +0200 Subject: Help needed - function apparently global cannot be called. In-Reply-To: References: Message-ID: <4c8618e5$0$8784$426a74cc@news.free.fr> Ian Hobson a ?crit : > Hi all you experts, > > This has me beat. Has anyone any ideas about what might be going wrong? > > This is code from within a windows service (hence no print statements - > no sys.stdout to print on!). > > I am trying to trace through to find where the code is not working. No > stdout so I have to log to a file. Then you'd be better using the logging module from the stdlib. And FWIW, you should try to make you code testable in a non-service context... > I have the following code fragments. > > def log(message): > f = open('d:\logfile.txt','a') > f.write(message + "\n") > f.close() > > from DelNotePrinter import DelNotePrinter The convention is to use all_lower_names for modules - having modules and classes with the same (case-sensitive) name can be very misleading. > note the order of the above - log is defined before the import. And ? Do you think it will affect the imported module in any way ? Like, say, magically "inject" your log function in the DelNotePrinter module ?-) > Later in the source Where ? > I have > > log('disPrint is:'+disPrint) > log('count is:'+count) Do yourself a favor and learn string formating... > log(repr(DelNotePrinter)) > printer = DelNotePrinter(disPrint,int(count)) > The DelNotePrinter.py file cannot us log even though it is declared > as global. In Python, "global" means "module-level", and it's only necessary when you want to rebind a module-level name from within a function or method. The code is... > > # coding=utf8 > # DelNotePrinter = code to print delivery notes > assorted imports removed for space reasons Some of these imports surely explain why you don't just get a NameError when trying to call log() - wild guess : you have some "from xxx import *" statement that does import another callable named 'log'. > class DelNotePrinter(object): > ''' Print Delivery Note on A5 in portrait ''' > def __init__(self,printer,copies): > ''' create printer and painter ''' > global font,sm,log > log('DelNotePrinter: starting') > self.printer = QPrinter(QPrinter.HighResolution) If you want to access a name (function, class, whatever) defined in another module, you have to explicitely import it. > > The file the log writes contains.. > disPrint is:HP Deskjet 6940 series > count is:1 > > > The > is followed by a newline and end of file! Where is the > DelNotePrinter: starting message? We can't tell - but you can get at least some hint, cf below > If I replace the opening of __init__ with > global font,sm,log > f = open('d:\logfile.txt','a') > f.write('DelNotePrinter: starting' + "\n") > f.close() > self.printer = QPrinter(QPrinter.HighResolution) > > then the message IS written to the log file. Obviously, yes. Now please add this to your code: class DelNotePrinter(object): ''' Print Delivery Note on A5 in portrait ''' def __init__(self,printer,copies): ''' create printer and painter ''' global font,sm,log f = open('d:\logfile.txt','a') f.write('DelNotePrinter: starting' + "\n") # check what "log" is bound to in the currrent namespace f.write( "DelNotePrinter : log is '%s' from '%s'" % ( log, log.__module__ )) f.close() self.printer = QPrinter(QPrinter.HighResolution) > I have read http://docs.python.org/reference/simple_stmts.html#global > very carefully and I still don't understand. The statement definition makes no sense if you don't understand namespaces and bindings: http://docs.python.org/reference/executionmodel.html#naming-and-binding From marduk at letterboxes.org Tue Sep 7 07:14:00 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 07 Sep 2010 07:14:00 -0400 Subject: The Samurai Principle In-Reply-To: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: <1283858040.628347.2.camel@paska> On Mon, 2010-09-06 at 20:48 -0700, Phlip wrote: > Pythonistas: > > The "Samurai Principle" says to return victorious, or not at all. This > is why django.db wisely throws an exception, instead of simply > returning None, if it encounters a "record not found". How does that compare to, say, the "Kamikaze Principle"? ;) -a From sajuptpm at gmail.com Tue Sep 7 07:22:08 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Tue, 7 Sep 2010 04:22:08 -0700 (PDT) Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> <109hl7-ao8.ln1@satorlaser.homedns.org> Message-ID: <7bbe7204-f7dd-4054-97bd-7973ade72dc7@n19g2000prf.googlegroups.com> On Sep 7, 1:16?pm, Ulrich Eckhardt wrote: > sajuptpm wrote: > > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > > ((cpu_util,mem_util),(disk_util))] > > ie, l = [((30,50),(70)), ((50,20),(20))] > > > l.sort(key=lambda x:(-x[0][0], x[1][0])) > > # sorting cpu_util asc and disk_util desc > > One thing here: Without knowing what special meaning the indices have, this > code is impossible to understand. In my opinion, that code should rather be > > ? l.sort(key=lambda x: (-x.cpu_util, x.disk_util)) > > You could then save the comment, which btw may or may not describe the > actual code. > > > suppose i changed order that is l = [((mem_util,cpu_util), > > (disk_util)), ((mem_util,cpu_util),(disk_util))] > > So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], > > x[1][0])) # sorting cpu_util asc and disk_util desc > > > I want to use same (common) sort code, that must work even if i > > changed tuple order. > > You don't have to use a lambda function. You can as well define the sorting > order in the same place of your code where you define the order inside the > elements, that way you would only have to adjust the sorting in one place. > > Otherwise, you will have to embed the order of the tuple inside the tuple or > the containing list. One approach would be to have a dictionary (which has > no order), or you use a separate type instead: > > ? class record(object): > ? ? ? pass > > ? r = record() > ? r.cpu_util = 12 > ? r.disk_util = 42 > ? l.append(r) > > However, this basically all boils down to either "don't use the sorting > (dict)" or "keep records sorted", so it doesn't really answer your > question. However, I'm afraid there is no answer to your question as it > stands. Maybe I could help you better if you explained why the order > changes etc, because normally I don't deal with data that has such a > volatile meaning, I rather normalize it on input and then use it in the > same way afterwards. > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 [((cpu_util,mem_util),(disk_util)),((cpu_util,mem_util),(disk_util))] i want to find the loaded machine based on cpu and mem and desk utilization by changing this order. I created a UI using that i can change the order of item in the tuple. But the problem is asc and desc sorting From raoulbia at gmail.com Tue Sep 7 07:39:37 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 04:39:37 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> Message-ID: On 7 sep, 02:18, Ben Finney wrote: > Ben Finney writes: > > We value respect for people here, and that's what you've been shown > > consistently. But respect for opinions, or for delicacy about > > learning, is not welcome here. > > Sloppy wording, I apologise. This should say ?? is not respect for a > person?. > > > In other words, we treat people as adults by default. I hope you'll > > continue to participate in that spirit. > > This is the main thrust of the message. > > -- > ?\ ? ? ? ??What if the Hokey Pokey IS what it's all about?? ?anonymous | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney Yes Master :) From contact at xavierho.com Tue Sep 7 07:46:20 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 7 Sep 2010 21:46:20 +1000 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: <4C858DDA.2090103@mrabarnett.plus.com> References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <4C858DDA.2090103@mrabarnett.plus.com> Message-ID: On 7 September 2010 10:56, MRAB wrote: > > > Incidentally, there's a builtin function called 'input' so using it as > a variable name is a discouraged! :-) Right-o! Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From raoulbia at gmail.com Tue Sep 7 07:59:01 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 04:59:01 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> Message-ID: <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> On 7 sep, 13:39, Baba wrote: > On 7 sep, 02:18, Ben Finney wrote: > > > > > > > Ben Finney writes: > > > We value respect for people here, and that's what you've been shown > > > consistently. But respect for opinions, or for delicacy about > > > learning, is not welcome here. > > > Sloppy wording, I apologise. This should say ?? is not respect for a > > person?. > > > > In other words, we treat people as adults by default. I hope you'll > > > continue to participate in that spirit. > > > This is the main thrust of the message. > > > -- > > ?\ ? ? ? ??What if the Hokey Pokey IS what it's all about?? ?anonymous | > > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | > > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > > Ben Finney > > Yes Master :) Sloppy wording, I apologise. This should say: If you find the question you're reading too easy then just don't answer. Noone is the owner of a democratic forum where freedom to ask the question one likes is paramount (as long of course as it is related to the group)...so let me repeat that, to say "Please do us a favour and at least try to figure things out on your own" is in my view inappropriate. To me it sounds "Do me a favur and get lost". Can you not understand that? I accept that it might not have been meant that way but see, misunderstandings happen easily so a more subtle approach is a wothwhile effort. My point: i always encourage people to get down from their ivory towers and to connect to the people...yes they will sometimes be lazy but they are genuine and very respectful (unlike what you think)... no offence now ok, it's not all that serious...open your mind, let lose all that righteousness and let's enjoy life :) Baba From raoulbia at gmail.com Tue Sep 7 08:05:56 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 05:05:56 -0700 (PDT) Subject: mutate dictionary or list Message-ID: Hi I am working on an exercise which requires me to write a funtion that will check if a given word can be found in a given dictionary (the hand). def is_valid_word(word, hand, word_list): """ Returns True if word is in the word_list and is entirely composed of letters in the hand. Otherwise, returns False. Does not mutate hand or word_list.""" I don't understand this part: Does not mutate hand or word_list I tried to google "python mutate list input" but to no avail It would be great if someone could give me a brief explanantion of the mutation concept. I know that a ditionary is unordered. How Can i however avoid 'acidental' mutation? Thanks Baba From roy at panix.com Tue Sep 7 08:09:12 2010 From: roy at panix.com (Roy Smith) Date: Tue, 07 Sep 2010 08:09:12 -0400 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> 1283665528.29444.python-list@pyyyyyyyyyy <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: In article , "BartC" wrote: > (BTW why doesn't Python 3 just accept 'xrange' as a > synonym for 'range'?) If you've ever tried to maintain a legacy code base, you'll understand why "there's only one way to do it" is A Good Thing. Imagine that you're looking at some code which was written years ago, by people who are no longer around to answer questions. In one place, you see: for i in range(n): blah and in another, you see: for j in xrange(n): blah If you are truly a Python expert, you'll say to yourself, "range and xrange are synonyms", and move on to other things. If, however, you're not really an expert, you'll look at this and say, "Hmmm, in one place they used range(), and in another they used xrange(). Clearly, there's some reason for the difference, I need to figure out what it is, because that's probably key to my understanding why this code isn't working". So, you spend the next two hours pouring over reference manuals trying to understand the subtle difference, until your friend comes over and says, "You dolt, you just wasted half the afternoon. They're the same thing. Move on, this is not the bug you're looking for". If you think stuff like that can't happen, you've probably never jumped into the middle of a legacy code base written in a language you don't know very well. From fabio at aptana.com Tue Sep 7 08:13:04 2010 From: fabio at aptana.com (Fabio Zadrozny) Date: Tue, 7 Sep 2010 09:13:04 -0300 Subject: Pydev 1.6.2 Released Message-ID: Hi All, Pydev 1.6.2 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Pydev is now also distributed with Aptana Studio 3, so it can be gotten in a version that doesn't require installing it as a separate plugin. Get it at: http://aptana.com/products/studio3/download * Django templates editor (requires Aptana Studio 3) o Supports HTML files with HTML, CSS and Javascript o Supports CSS files o Outline page o Code-completion for Django templates based on templates (window > preferences > pydev > django templates editor > templates) o Code-completion for HTML, CSS and Javascript o Syntax highlighting based on the templates with the 'Django tags' context o Colors based on the Aptana themes * Python 2.7 grammar supported * Fixed indexing issue on contents getting getting stale in the cache * Fixed issue where the partitioning became wrong when entering a multiline string * Colors in the compare editor are now correct when using the Aptana themes * Extract method refactoring now works with "import" and "from ... import" inside a method * Source folders now appear before other folders * Fixed False positive on code analysis when using the property decorator What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/ Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From contact at xavierho.com Tue Sep 7 08:13:14 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 7 Sep 2010 22:13:14 +1000 Subject: mutate dictionary or list In-Reply-To: References: Message-ID: On 7 September 2010 22:05, Baba wrote: > > It would be great if someone could give me a brief explanantion of the > mutation concept. > In this case, to mutate is to change. If you must not mutate the list, you must not change it. In another words, reading from the list is fine. Writing to it is not. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From sajuptpm at gmail.com Tue Sep 7 09:24:06 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Tue, 7 Sep 2010 06:24:06 -0700 (PDT) Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) Message-ID: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> I have a list of tuples. l = [((30,50),(70)), ((50,20),(20))] for i in range(10): k = ((i+30,i+50),(i+70))#suppose creating new tuple in each iteration using some random value and in sert it into list. flag=True for i, v in enumerate(l): if v >= k: l.insert(i,k) flag = False break if flag: l.append(k) This code will give a list of tuples sorted in asc order. I need to change this code to sort this list by k[0][0] ascending and k[0][1] descending. What are the modifications needed in this code. I dont want to user sort() method of list. i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in another way .I want to know what the modification needed in the 'if' check to sort this list of tuples in k[0][0] ascending and k[0][1] descending. From phlip2005 at gmail.com Tue Sep 7 09:40:16 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 06:40:16 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> > How does that compare to, say, the "Kamikaze Principle"? ;) Return victorious AND not at all! (All return values are packed up and thrown...;) From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 09:42:14 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 15:42:14 +0200 Subject: accessing a text file In-Reply-To: <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> Message-ID: <4c86412e$0$5821$426a34cc@news.free.fr> Baba a ?crit : (snip) > If i had > received a friendly response from Benjamin (as opposed to "Please do > us a favor and at least try to figure things out on your own") According to usenet standards and given your initial question, this is a _very_ friendly answer. From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 09:55:47 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 15:55:47 +0200 Subject: mutate dictionary or list In-Reply-To: References: Message-ID: <4c86445c$0$12641$426a74cc@news.free.fr> Baba a ?crit : > Hi > > I am working on an exercise which requires me to write a funtion that > will check if a given word can be found in a given dictionary (the > hand). > > def is_valid_word(word, hand, word_list): > """ > Returns True if word is in the word_list and is entirely > composed of letters in the hand. Otherwise, returns False. > Does not mutate hand or word_list.""" > > I don't understand this part: Does not mutate hand or word_list Everything in Python is an object. A few objects are immutable (ints, strings, tuples...), ie you there's no way to modify the state of the object in place. Most objects are mutable, and this obviously includes lists and dicts (you can add / remove / replace list or dicts elements). Now the point is that when passing an object as argument to a function, you don't pass a copy of the object but the object itself, so if the object is mutable, you can mutate if from within the function. A simple (and really dumb) example being worth a thousand words: # mutate.py def update_dict(dic, key, value): print "in update_dic : dic id is %s" % id(dic) dic[key] = value def main(): dic = dict(a=1, b=2) lst = [1, 2, 3] print "in main : dic id is %s" % id(dic) print "dic : %s" % dic print "calling update_dict" update_dict(dic, "c", 3) print "after update_dict" print "in main : dic id is %s" % id(dic) print "dic : %s" % dic if __name__ == '__main__': main() > > I know that a ditionary is unordered. How Can i however avoid > 'acidental' mutation? This has nothing to do with dicts being ordered or not. And there's NO "accidental" mutation - you have to explicitely call a method or operator that mutate the dict. From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 09:56:42 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 15:56:42 +0200 Subject: The Samurai Principle In-Reply-To: <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> Message-ID: <4c864493$0$12641$426a74cc@news.free.fr> Phlip a ?crit : >> How does that compare to, say, the "Kamikaze Principle"? ;) > > Return victorious AND not at all! > > (All return values are packed up and thrown...;) ... and then it raises a SystemError !-) From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 09:58:18 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 15:58:18 +0200 Subject: Help needed - function apparently global cannot be called. In-Reply-To: References: Message-ID: <4c8644f3$0$12641$426a74cc@news.free.fr> Ian Hobson a ?crit : (snip) you may also want to read the recent "using modules" thread... From hobson42 at gmaiil.com Tue Sep 7 10:00:37 2010 From: hobson42 at gmaiil.com (Ian) Date: Tue, 07 Sep 2010 15:00:37 +0100 Subject: Help needed - function apparently global cannot be called. In-Reply-To: <4c8618e5$0$8784$426a74cc@news.free.fr> References: <4c8618e5$0$8784$426a74cc@news.free.fr> Message-ID: <4C864585.3050204@gmaiil.com> Hi Bruno, Thanks for your quick response. I still do not understand. On 07/09/2010 11:50, Bruno Desthuilliers wrote: > Ian Hobson a ?crit : >> Hi all you experts, >> >> This has me beat. Has anyone any ideas about what might be going wrong? >> >> This is code from within a windows service (hence no print statements >> - no sys.stdout to print on!). >> >> I am trying to trace through to find where the code is not working. >> No stdout so I have to log to a file. > > Then you'd be better using the logging module from the stdlib. And > FWIW, you should try to make you code testable in a non-service > context... Thanks for the tip. "Batteries included" means there are so many batteries you miss some. The Module I am trying to use works perfectly as a free standing routine. > >> I have the following code fragments. >> >> def log(message): >> f = open('d:\logfile.txt','a') >> f.write(message + "\n") >> f.close() >> >> from DelNotePrinter import DelNotePrinter > > > The convention is to use all_lower_names for modules - having modules > and classes with the same (case-sensitive) name can be very misleading. > The convention is a good one. > >> note the order of the above - log is defined before the import. > > And ? Do you think it will affect the imported module in any way ? > Like, say, magically "inject" your log function in the DelNotePrinter > module ?-) Just that log is defined before the global log is encountered to that if the compiler needed to set up a link at compile time it was able to do so. > > >> Later in the source > > Where ? > About 350 lines further down. >> I have >> >> log('disPrint is:'+disPrint) >> log('count is:'+count) > > Do yourself a favor and learn string formating... Agreed. :) - These are debug statements to discover what is going on. I have had so much trouble with problems NOT being reported, that I avoid anything that I am not 100% sure must work. > >> log(repr(DelNotePrinter)) >> printer = DelNotePrinter(disPrint,int(count)) > > >> The DelNotePrinter.py file cannot us log even though it is declared >> as global. > > In Python, "global" means "module-level", and it's only necessary when > you want to rebind a module-level name from within a function or method. Exactly! I want to bind the name log to the function I wrote. So I carefully placed log in global scope and told the compiler that when I referred to log I meant the global one I wrote. I expected that to bind log to the function I wrote. The compiler did not complain it was undefined (which would have caused a trackback on the Event log). But neither was the routine called. :( I still don't understand what is going wrong. > > The code is... >> >> # coding=utf8 >> # DelNotePrinter = code to print delivery notes >> assorted imports removed for space reasons > > Some of these imports surely explain why you don't just get a > NameError when trying to call log() - wild guess : you have some "from > xxx import *" statement that does import another callable named 'log'. > I don't think so. The lines are import sys import datetime from PyQt4.QtCore import * from PyQt4.QtGui import * from DataBaseClass import DataBase I know all PyQt classes begin with Q. Database I wrote, and it has no log in it. >> class DelNotePrinter(object): >> ''' Print Delivery Note on A5 in portrait ''' >> def __init__(self,printer,copies): >> ''' create printer and painter ''' >> global font,sm,log >> log('DelNotePrinter: starting') > > >> self.printer = QPrinter(QPrinter.HighResolution) > > If you want to access a name (function, class, whatever) defined in > another module, you have to explicitely import it. > >> >> The file the log writes contains.. >> disPrint is:HP Deskjet 6940 series >> count is:1 >> >> >> The > is followed by a newline and end of file! Where is the >> DelNotePrinter: starting message? > > We can't tell - but you can get at least some hint, cf below > >> If I replace the opening of __init__ with >> global font,sm,log >> f = open('d:\logfile.txt','a') >> f.write('DelNotePrinter: starting' + "\n") >> f.close() >> self.printer = QPrinter(QPrinter.HighResolution) >> >> then the message IS written to the log file. > > Obviously, yes. Now please add this to your code: > > class DelNotePrinter(object): > ''' Print Delivery Note on A5 in portrait ''' > def __init__(self,printer,copies): > ''' create printer and painter ''' > global font,sm,log > f = open('d:\logfile.txt','a') > f.write('DelNotePrinter: starting' + "\n") > > # check what "log" is bound to in the currrent namespace > f.write( > "DelNotePrinter : log is '%s' from '%s'" % ( > log, log.__module__ > )) > f.close() > self.printer = QPrinter(QPrinter.HighResolution) > I tried that (using copy/paste) and got no output! So I modified is slightly to global log f = open('d:\logfile.txt','a') f.write("test message\n") f.write( "DelNotePrinter : log is '%s' from '%s'" % ( log, log.__module__ )) f.close() self.printer = QPrinter(QPrinter.HighResolution) I get my "test message" and then nothing. When I close the service, the next log message comes from the closing code. There are no errors reported, no messages, no Event log entries and nothing further happens. Its as if the thread died. >> I have read http://docs.python.org/reference/simple_stmts.html#global >> very carefully and I still don't understand. > > The statement definition makes no sense if you don't understand > namespaces and bindings: > > http://docs.python.org/reference/executionmodel.html#naming-and-binding > Thanks for the pointer. What a truly execrable piece of writing - full of over-long sentences and multiple subordinate clauses. It routinely uses terms before definition, and sometimes without definition. It is astonishingly bad. The third sentence reads "Each occurrence of a name in the program text refers to the /binding/ of that name established in the innermost function block containing the use." What does that mean? It appears to mean that it is the assignment in the innermost function block that binds for all uses, not the first, not module blocks, not class blocks and not code blocks - but the innermost function block. That might be correct, but somehow I doubt it, for it would mean that earlier bindings are ignored or invalidated or not used or something - even if the inner block is not executed. I am not stupid and English is my mother tongue, and I have read that page many times. The implications of the passage are still opaque to me. How can I call a global function placed at the top of the source. Do I really have to move a 4 line function into its own file and import it again and again and again? Regards Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Sep 7 10:03:44 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 16:03:44 +0200 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: sajuptpm wrote: > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in > another way .I want to know what the modification needed in the 'if' > check to sort this list of tuples in k[0][0] ascending and k[0][1] > descending. It seems you are not getting any closer to your goal. Perhaps it would help if you could explain that goal clearly rather than describing the means you are employing to achieve it. > I have a list of tuples. > > l = [((30,50),(70)), ((50,20),(20))] By the way, (42) is not a tuple, it's an integer. To turn it into a 1-tuple you have to add a ',': >>> (42) 42 >>> (42,) (42,) >>> 42, (42,) Peter From deets at web.de Tue Sep 7 10:12:00 2010 From: deets at web.de (deets at web.de) Date: Tue, 07 Sep 2010 16:12:00 +0200 Subject: mutate dictionary or list References: Message-ID: <87zkvt4p8v.fsf@web.de> Baba writes: > Hi > > I am working on an exercise which requires me to write a funtion that > will check if a given word can be found in a given dictionary (the > hand). > > def is_valid_word(word, hand, word_list): > """ > Returns True if word is in the word_list and is entirely > composed of letters in the hand. Otherwise, returns False. > Does not mutate hand or word_list.""" > > I don't understand this part: Does not mutate hand or word_list > > I tried to google "python mutate list input" but to no avail > > It would be great if someone could give me a brief explanantion of the > mutation concept. Objects can be mutable or immutable. For example, in Python, integers, strings, floats and tuples are immutable. That means that you can't change their value. Mutable objects OTOH can be changed. For example, a list is mutable: l = ["foo"] l.append("bar") # mutating method print l #-> ['foo', 'bar'] That's all there is to it. So for the example at hand, don't use anything that mutates the passed arguments. E.g, if word_list really is a list, and for faster lookup of "word", you want to sort it, you are not allowed to do this: word_list.sort() # mutating!! Instead, you need to do new_word_list = sorted(word_list) # creates a *copy* of word_list, which is sorted. Actually, you can also try & use the module copy's "deepcopy"-function to ensure that you don't mutate the passed objects. Please not that this is *not* a mutating operation: l = [1, 2] h = l l = [3, 4] print h #-> [1, 2] The original list in l is still preserved un-modified, and referenced by the name h. Just binding a different object to an existing name doesn't change anything about the old object referenced by the name. Diez From sajuptpm at gmail.com Tue Sep 7 10:22:02 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Tue, 7 Sep 2010 07:22:02 -0700 (PDT) Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: On Sep 7, 7:03?pm, Peter Otten <__pete... at web.de> wrote: > sajuptpm wrote: > > i need to implement ?l.sort(key=lambda x:(x[0][0], -x[1][0])) in > > another way .I want to know what the modification needed in the 'if' > > check to sort this list of tuples in k[0][0] ascending and k[0][1] > > descending. > > It seems you are not getting any closer to your goal. Perhaps it would help > if you could explain that goal clearly rather than describing the means you > are employing to achieve it. > > > I have a list of tuples. > > > l = [((30,50),(70)), ((50,20),(20))] > > By the way, (42) is not a tuple, it's an integer. To turn it into a 1-tuple > you have to add a ',': > > >>> (42) > 42 > >>> (42,) > (42,) > >>> 42, > > (42,) > > Peter I have a list of tuples. l = [((30,50),(70,)), ((50,20),(20,))] for i in range(10): k = ((i+30,i+50),(i+70))#suppose creating new tuple in each iteration using some random value and in sert it into list. flag=True for i, v in enumerate(l): if v >= k: l.insert(i,k) flag = False break if flag: l.append(k) This code will give a list of tuples sorted in asc order. I need to change this code to sort this list by k[0][0] ascending and k[0][1] descending. What are the modifications needed in this code. I dont want to user sort() method of list. i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in another way .I want to know what the modification needed in the 'if' check to sort this list of tuples in k[0][0] ascending and k[0][1] descending. From debatem1 at gmail.com Tue Sep 7 10:23:04 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 7 Sep 2010 07:23:04 -0700 Subject: The Samurai Principle In-Reply-To: <4c864493$0$12641$426a74cc@news.free.fr> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> Message-ID: On Tue, Sep 7, 2010 at 6:56 AM, Bruno Desthuilliers wrote: > Phlip a ?crit : >>> >>> How does that compare to, say, the "Kamikaze Principle"? ;) >> >> Return victorious AND not at all! >> >> (All return values are packed up and thrown...;) > > ... and then it raises a SystemError !-) general protection fault Geremy Condra From bussiere at gmail.com Tue Sep 7 10:31:34 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Tue, 7 Sep 2010 16:31:34 +0200 Subject: knowing the caller of an import && exec question Message-ID: i've got toto.py : import titi def niwhom(): pass and titi.py : def nipang(): pass how can i know in titi.py that's it's toto.py that is calling titi.py and the path of toto ? And why : bidule.py : class bidetmusique: pass truc.py : X = __import__("bidule") why exec("X.bidetmusique()") return none and X.bidetmusique() return an object ? How could i do to make this string "X.bidetmusique()" return an object ? Regards and thanks Bussiere Eat the strawberry Google Fan boy From __peter__ at web.de Tue Sep 7 10:32:12 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 16:32:12 +0200 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: sajuptpm wrote: > On Sep 7, 7:03 pm, Peter Otten <__pete... at web.de> wrote: >> sajuptpm wrote: >> > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in >> > another way .I want to know what the modification needed in the 'if' >> > check to sort this list of tuples in k[0][0] ascending and k[0][1] >> > descending. >> >> It seems you are not getting any closer to your goal. Perhaps it would >> help if you could explain that goal clearly rather than describing the >> means you are employing to achieve it. >> >> > I have a list of tuples. >> >> > l = [((30,50),(70)), ((50,20),(20))] >> >> By the way, (42) is not a tuple, it's an integer. To turn it into a >> 1-tuple you have to add a ',': >> >> >>> (42) >> 42 >> >>> (42,) >> (42,) >> >>> 42, >> >> (42,) >> >> Peter > > > I have a list of tuples. > > l = [((30,50),(70,)), ((50,20),(20,))] > > for i in range(10): > k = ((i+30,i+50),(i+70))#suppose creating new tuple in each > iteration > using some random value and in sert it into list. > > flag=True > for i, v in enumerate(l): > if v >= k: > l.insert(i,k) > flag = False > break > if flag: > l.append(k) > > This code will give a list of tuples sorted in asc order. > I need to change this code to sort this list by k[0][0] ascending and > k[0][1] descending. > What are the modifications needed in this code. > I dont want to user sort() method of list. > > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in > another way .I want to know what the modification needed in the 'if' > check to sort this list of tuples in k[0][0] ascending and k[0][1] > descending. As a thought experiment assume that your audience had never heard of tuples or even Python. How would you then explain your goal? Peter From ben+python at benfinney.id.au Tue Sep 7 10:37:29 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Sep 2010 00:37:29 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> Message-ID: <87tym1bowm.fsf@benfinney.id.au> Baba writes: > to say "Please do us a favour and at least try to figure things out on > your own" is in my view inappropriate. That's what the person wanted you to see. How would you prefer that exact information to be imparted to you? How could it have been communicated so that it was not misunderstood? > To me it sounds "Do me a favur and get lost". Can you not understand > that? Honestly, I cannot read that meaning into the messages you've received in this forum. Please help us by showing how you think people could say what was said above without losing information. > no offence now ok, it's not all that serious...open your mind, let > lose all that righteousness and let's enjoy life :) All well and good, but let's try to see what went wrong in communication here and fix it. -- \ ?Faith, n. Belief without evidence in what is told by one who | `\ speaks without knowledge, of things without parallel.? ?Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney From aahz at pythoncraft.com Tue Sep 7 10:46:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Sep 2010 07:46:16 -0700 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: In article , BartC wrote: >"Steven D'Aprano" wrote in message >news:4c85adfe$0$11115$c3e8da3 at news.astraweb.com... >> >> xrange = range >> >> There, that wasn't hard, was it? > >I think I just learned more about Python than from months of reading this >group. > >So 'range' is just a class like any other. And that a class is something you >can blithely copy from one variable to another. And whenever you see 'range' >anywhere, you can't always be certain that someone hasn't done: > >range = 42 > >at some point. That explains a lot about the difficulties of implementing >Python efficiently. (And the xrange=range trick works well thanks.) Actually, range() is a function. But the same point applies, squared -- you really can never know what kind of object is hiding behind a name in the general case. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From ben+python at benfinney.id.au Tue Sep 7 10:46:43 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Sep 2010 00:46:43 +1000 Subject: mutate dictionary or list References: <87zkvt4p8v.fsf@web.de> Message-ID: <87pqwpboh8.fsf@benfinney.id.au> deets at web.de writes: > Objects can be mutable or immutable. For example, in Python, integers, > strings, floats and tuples are immutable. That means that you can't > change their value. Yes. Importantly, wherever you see code that you *think* is changing the value of an immutable object, you're thinking incorrectly. (There's no shame in that; other languages give us preconceptions that can be hard to shake off.) The only way to get a different value from an integer object is to ask Python for a different integer object; the original is unchanged. The same goes for tuples, strings, and all the other immutable types. > Mutable objects OTOH can be changed. [?] Some good articles to explain Python's object model: -- \ ?We can't depend for the long run on distinguishing one | `\ bitstream from another in order to figure out which rules | _o__) apply.? ?Eben Moglen, _Anarchism Triumphant_, 1999 | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 10:48:31 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 16:48:31 +0200 Subject: knowing the caller of an import && exec question In-Reply-To: References: Message-ID: <4c8650b8$0$9920$426a74cc@news.free.fr> bussiere bussiere a ?crit : > i've got toto.py : > > import titi > def niwhom(): > pass > > and titi.py : > > def nipang(): > pass > > how can i know in titi.py that's it's toto.py that is calling titi.py > and the path of toto ? You'd have to inspect the call stack. Not for the faint at heart... > And > > why : > > bidule.py : > class bidetmusique: > pass The naming convention is to capitalize class names, ie "Bidetmusique" or "BidetMusique" Heureusement qu'il n'y a pas grand monde ici pour comprendre le fran?ais, parce que comme nommage, ?a bat des records, l? !-) > > truc.py : > X = __import__("bidule") > > why exec("X.bidetmusique()") return none exec doesn't "return" anything - it executes code in a given context, eventually modifying the context. Now given your above code, a new bidetmusique instance is indeed created, but since it's not bound to anything, it's immediatly discarded. > and X.bidetmusique() return an object ? cf above > How could i do to make this string "X.bidetmusique()" return an object ? exec is 99 time out of 10 (nope, not a typo) the wrong solution. You already found how to dynamically import a module by name (I mean, name given as as string), all you need know is to find out how to dynamically retrieve a module attribute given it's name as string. And the answer is "getattr": # truc.py : X = __import__("bidule") cls = getattr(X, "bidetmusique") obj = cls() print obj HTH From contactprashantat at gmail.com Tue Sep 7 10:48:57 2010 From: contactprashantat at gmail.com (Prashant Kumar) Date: Tue, 7 Sep 2010 07:48:57 -0700 (PDT) Subject: Volunteer help with porting Message-ID: <5f12e647-14a7-43c4-ae5f-2dc91c7ddc5f@q40g2000prg.googlegroups.com> Hi everyone, My name is Prashant Kumar and I wish to contribute to the Python development process by helping convert certain existing python over to python3k. Is there anyway I could obtain a list of libraries which need to be ported over to python3k, sorted by importance(by importance i mean packages which serve as a dependency for larger number of packages being more important). I had originally mailed the python-dev mailing list and was pointed to this ML so that I could get details regarding 3rd party libraries which need to be ported. Thanks, Prashant Kumar From invalid at invalid.invalid Tue Sep 7 10:50:05 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 7 Sep 2010 14:50:05 +0000 (UTC) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> Message-ID: On 2010-09-07, Baba wrote: > Sloppy wording, I apologise. This should say: If you find the > question you're reading too easy then just don't answer. Noone is the > owner of a democratic forum where freedom to ask the question one > likes is paramount (as long of course as it is related to the > group)...so let me repeat that, to say "Please do us a favour and at > least try to figure things out on your own" is in my view > inappropriate. You need to read this: http://www.catb.org/esr/faqs/smart-questions.html > To me it sounds "Do me a favur and get lost". No, it means "Do yourself a favor, learn how to do things yourself." Remember: you're then one asking people to give you something for free. It's not up to them to conform to your expectations, rather you need to conform to theirs. Otherwise, they'll just ignore you. -- Grant Edwards grant.b.edwards Yow! FOOLED you! Absorb at EGO SHATTERING impulse gmail.com rays, polyester poltroon!! From pruebauno at latinmail.com Tue Sep 7 10:52:22 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 7 Sep 2010 07:52:22 -0700 (PDT) Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> Message-ID: <10aba5d5-e24a-4392-aa4a-fccb63afef7b@i5g2000yqe.googlegroups.com> On Sep 6, 10:31?pm, Steven D'Aprano wrote: > On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: > > If you're going to use the list of float objects, you can convert them > > all with a list comprehension. > [...] > > ? ? >>> numbers_as_float = [float(x) for x in numbers_as_str] > > That's awfully verbose. A map is simpler: > > numbers_as_float = map(float, numbers_as_str) > > -- > Steven In Python 3.x it has one disadvantage: >>> numbers_as_float = map(float, numbers_as_str) >>> max(numbers_as_float) 10.24 >>> min(numbers_as_float) Traceback (most recent call last): File "", line 1, in min(numbers_as_float) ValueError: min() arg is an empty sequence >>> From no.email at please.post Tue Sep 7 11:33:55 2010 From: no.email at please.post (kj) Date: Tue, 7 Sep 2010 15:33:55 +0000 (UTC) Subject: audio time-stretching? Message-ID: Does anyone know of a Python module for *moderate* "time-stretching"[1] an MP3 (or AIFF) file? FWIW, the audio I want to time-stretch is human speech. TIA! ~K [1] By "moderate time stretching" I mean, for example, taking an audio that would normally play in 5 seconds, and stretch it so that it plays in 7.5 seconds, keeping the pitch unchanged. A lot of software out there does this badly; e.g. the time-stretched audio springs extraneous "beats" of intensity that are very obtrusive and annoying; I guess it's some weird wave self-interference effect. Also, I stress *moderate* time stretching to explicitly rule out the extreme (~50X) time-stretching that software like PaulStretch is designed to accomplish. From phlip2005 at gmail.com Tue Sep 7 12:02:49 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 09:02:49 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> Message-ID: <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Back to the topic, I tend to do this: for record in Model.objects.filter(pk=42): return record return sentinel Having lots of short methods helps, because return provides both control-flow and a result value. But it abuses 'for' to mean 'if'. I feel _reeeeally_ guilty about that! But I miss this, from (cough) RoR: record = Model.find(42) || sentinel Django should provide this: record = Model.objects.get(pk=42, _if_does_not_exist=sentinel) sentinel could be a lambda that concocts a new record (where such a record should not be created with get_or_create()). That would be efficient when you don't spend time constructing it just so the happy- path of .get() can throw it away. Or sentinel could be None, or a NullObject that efficiently behaves like a record but provides stubbed-out behaviors. My committees will be submitting these proposals to the Django committees shortly... C-: -- Phlip From debatem1 at gmail.com Tue Sep 7 12:48:52 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 7 Sep 2010 09:48:52 -0700 Subject: accessing a text file In-Reply-To: References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> Message-ID: On Tue, Sep 7, 2010 at 4:39 AM, Baba wrote: > On 7 sep, 02:18, Ben Finney wrote: >> Ben Finney writes: >> > We value respect for people here, and that's what you've been shown >> > consistently. But respect for opinions, or for delicacy about >> > learning, is not welcome here. >> >> Sloppy wording, I apologise. This should say ?? is not respect for a >> person?. >> >> > In other words, we treat people as adults by default. I hope you'll >> > continue to participate in that spirit. >> >> This is the main thrust of the message. >> >> -- >> ?\ ? ? ? ??What if the Hokey Pokey IS what it's all about?? ?anonymous | >> ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | >> _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| >> Ben Finney > > Yes Master :) This is in almost impressively poor taste. I know I'm done helping you now. Geremy Condra From briandenzer at gmail.com Tue Sep 7 13:01:01 2010 From: briandenzer at gmail.com (Brian D) Date: Tue, 7 Sep 2010 10:01:01 -0700 (PDT) Subject: What the \xc2\xa0 ?!! Message-ID: <662d8f01-f1f6-44a4-86e3-694b9b6a73ba@v41g2000yqv.googlegroups.com> In an HTML page that I'm scraping using urllib2, a \xc2\xa0 bytestring appears. The page's charset = utf-8, and the Chrome browser I'm using displays the characters as a space. The page requires authentication: https://www.nolaready.info/myalertlog.php When I try to concatenate strings containing the bytestring, Python chokes because it refuses to coerce the bytestring into ascii. wfile.write('|'.join(valueList)) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 163: ordinal not in range(128) In searching for help with this issue, I've learned that the bytestring *might* represent a non-breaking space. When I scrape the page using urllib2, however, the characters print as ?? in a Windows command prompt (though I wouldn't be surprised if this is some erroneous attempt by the antiquated command window to handle something it doesn't understand). If I use IDLE to attempt to decode the single byte referenced in the error message, and convert it into UTF-8, another error message is generated: >>> weird = unicode('\xc2', 'utf-8') Traceback (most recent call last): File "", line 1, in weird = unicode('\xc2', 'utf-8') UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 0: unexpected end of data If I attempt to decode the full bytestring, I don't obtain a human- readable string (expecting, perhaps, a non-breaking space): >>> weird = unicode('\xc2\xa0', 'utf-8') >>> par = ' - '.join(['This is', weird]) >>> par u'This is - \xa0' I suspect that the bytestring isn't UTF-8, but what is it? Latin1? >>> weirder = unicode('\xc2\xa0', 'latin1') >>> weirder u'\xc2\xa0' >>> 'This just gets ' + weirder u'This just gets \xc2\xa0' Or is it a Microsoft bytestring? >>> weirder = unicode('\xc2\xa0', 'mbcs') >>> 'This just gets ' + weirder u'This just gets \xc2\xa0' None of these codecs seem to work. Back to the original purpose, as I'm scraping the page, I'm storing the field/value pair in a dictionary with each iteration through table elements on the page. This is all fine, until a value is found that contains the offending bytestring. I have attempted to coerce all value strings into an encoding, but Python doesn't seem to like that when the string is already Unicode: valuesDict[fieldString] = unicode(value, 'UTF-8') TypeError: decoding Unicode is not supported The solution I've arrived at is to specify the encoding for value strings both when reading and writing value strings. for k, v in valuesDict.iteritems(): valuePair = ':'.join([k, v.encode('UTF-8')]) [snip] ... wfile.write('|'.join(valueList)) I'm not sure I have a question, but does this sound familiar to any Unicode experts out there? How should I handle these odd bytestring values? Am I doing it correctly, or what could I improve? Thanks! From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 13:12:02 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 19:12:02 +0200 Subject: The Samurai Principle In-Reply-To: <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <4c86725a$0$16728$426a74cc@news.free.fr> Phlip a ?crit : > Back to the topic, I tend to do this: > > for record in Model.objects.filter(pk=42): > return record > > return sentinel WTF alert here... > Having lots of short methods helps, because return provides both > control-flow and a result value. But it abuses 'for' to mean 'if'. I > feel _reeeeally_ guilty about that! > But I miss this, from (cough) RoR: > > record = Model.find(42) || sentinel > > Django should provide this: > > record = Model.objects.get(pk=42, _if_does_not_exist=sentinel) queryset.get can be used with multiple conditions - it's not necessarily restricted to pk lookups. However you name your "_if_does_not_exist" kwarg, it will be difficult to garantee that there will never be no nameclash with any possible valid model lookup argument... But if you feel like you found the correct name, you can of course monkeypatch queryset !-) From deets at web.de Tue Sep 7 13:15:47 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 07 Sep 2010 19:15:47 +0200 Subject: What the \xc2\xa0 ?!! References: <662d8f01-f1f6-44a4-86e3-694b9b6a73ba@v41g2000yqv.googlegroups.com> Message-ID: <87pqwp4gqk.fsf@web.de> Brian D writes: > In an HTML page that I'm scraping using urllib2, a \xc2\xa0 > bytestring appears. > > The page's charset = utf-8, and the Chrome browser I'm using displays > the characters as a space. > > The page requires authentication: > https://www.nolaready.info/myalertlog.php > > When I try to concatenate strings containing the bytestring, Python > chokes because it refuses to coerce the bytestring into ascii. > > wfile.write('|'.join(valueList)) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 163: ordinal not in range(128) > > In searching for help with this issue, I've learned that the > bytestring *might* represent a non-breaking space. It in fact does. > > When I scrape the page using urllib2, however, the characters print > as ?? in a Windows command prompt (though I wouldn't be surprised if > this is some erroneous attempt by the antiquated command window to > handle something it doesn't understand). Yes, it's trying to interpret that as two cp1252 (or whatever) bytes instead of one unbreakable space. > > If I use IDLE to attempt to decode the single byte referenced in the > error message, and convert it into UTF-8, another error message is > generated: > >>>> weird = unicode('\xc2', 'utf-8') > > Traceback (most recent call last): > File "", line 1, in > weird = unicode('\xc2', 'utf-8') > UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 0: > unexpected end of data Which is to be expected, as you ripped a UTF-8 escape sequence in half. > > If I attempt to decode the full bytestring, I don't obtain a human- > readable string (expecting, perhaps, a non-breaking space): You obtain a non-breakable space. What do you think it should look like in your terminal? It looks like ... nothing. Because it looks like a space. > >>>> weird = unicode('\xc2\xa0', 'utf-8') >>>> par = ' - '.join(['This is', weird]) >>>> par > u'This is - \xa0' > > I suspect that the bytestring isn't UTF-8, but what is it? Latin1? No, it is UTF-8 > >>>> weirder = unicode('\xc2\xa0', 'latin1') >>>> weirder > u'\xc2\xa0' >>>> 'This just gets ' + weirder > u'This just gets \xc2\xa0' > > Or is it a Microsoft bytestring? This is not weird, this is the python interpreter giving you the representation of a unicode-object when you do not print, so you can see what it looks like. And because you wrongly decoded it as latin1, it's garbage anyway. > >>>> weirder = unicode('\xc2\xa0', 'mbcs') >>>> 'This just gets ' + weirder > u'This just gets \xc2\xa0' > > None of these codecs seem to work. UTF-8 worked just fine. > > Back to the original purpose, as I'm scraping the page, I'm storing > the field/value pair in a dictionary with each iteration through table > elements on the page. This is all fine, until a value is found that > contains the offending bytestring. I have attempted to coerce all > value strings into an encoding, but Python doesn't seem to like that > when the string is already Unicode: > > valuesDict[fieldString] = unicode(value, 'UTF-8') > TypeError: decoding Unicode is not supported > > The solution I've arrived at is to specify the encoding for value > strings both when reading and writing value strings. > > for k, v in valuesDict.iteritems(): > valuePair = ':'.join([k, v.encode('UTF-8')]) > [snip] ... > wfile.write('|'.join(valueList)) > > I'm not sure I have a question, but does this sound familiar to any > Unicode experts out there? > > How should I handle these odd bytestring values? Am I doing it > correctly, or what could I improve? The overall solution is to decode the page or parts of it in whatever decoding it is delivered. You mentioned that the page is delivered in UTF-8, so you should use whatever gives you that information to decode the returned body. Diez From phlip2005 at gmail.com Tue Sep 7 13:20:35 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 10:20:35 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> Message-ID: <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> On Sep 7, 10:12?am, Bruno Desthuilliers wrote: > Phlip a ?crit : > > > Back to the topic, I tend to do this: > > > ? for record in Model.objects.filter(pk=42): > > ? ? ?return record > > > ? return sentinel > > WTF alert here... I don't see how anyone could WTF that. Are you pretending to be a newb who doesn't understanding it? F'em. > > Having lots of short methods helps, because return provides both > > control-flow and a result value. But it abuses 'for' to mean 'if'. I > > feel _reeeeally_ guilty about that! > > But I miss this, from (cough) RoR: > > > ? record = Model.find(42) || sentinel > > > Django should provide this: > > > ? record = Model.objects.get(pk=42, _if_does_not_exist=sentinel) > > queryset.get can be used with multiple conditions - it's not necessarily > ? restricted to pk lookups. However you name your "_if_does_not_exist" > kwarg, it will be difficult to garantee that there will never be no > nameclash with any possible valid model lookup argument... it can also be another method - .if_does_not_exist(sentinel). With a less sucky name. I would guess that Django provides some basic rules for avoiding name collisions. Nobody should call a field "pk__in", but if they do, they are screwed! But that's not important right now. > But if you feel like you found the correct name, you can of course > monkeypatch queryset !-) K now I gotta learn to add a new method to an existing class! From niklasro at gmail.com Tue Sep 7 13:27:23 2010 From: niklasro at gmail.com (Niklasro) Date: Tue, 7 Sep 2010 10:27:23 -0700 (PDT) Subject: datetime questions Message-ID: <454773b5-42e2-4223-9418-34faf12b5a90@t20g2000yqa.googlegroups.com> Hello Learning python datetime somewhat similar to SQL type timestamp my attempt creating a 24 h 2 months ago is str(datetime.now () - timedelta (days = 60)) +' cron '+ str(datetime.now () - timedelta (days = 59)) Do you agree? Can I improve this declaration? Regards Niklas Rosencrantz From ian.g.kelly at gmail.com Tue Sep 7 13:36:29 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Sep 2010 11:36:29 -0600 Subject: The Samurai Principle In-Reply-To: <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: > Back to the topic, I tend to do this: > > ?for record in Model.objects.filter(pk=42): > ? ? return record > > ?return sentinel How is that any better than just catching the exception? try: return Model.objects.get(pk=42) except Model.DoesNotExist: return sentinel The flow of control is much clearer this way. Cheers, Ian From aahz at pythoncraft.com Tue Sep 7 13:39:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Sep 2010 10:39:58 -0700 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: In article , Roy Smith wrote: > >Imagine that you're looking at some code which was written years ago, by >people who are no longer around to answer questions. In one place, you >see: > >for i in range(n): > blah > >and in another, you see: > >for j in xrange(n): > blah > >If you are truly a Python expert, you'll say to yourself, "range and >xrange are synonyms", and move on to other things. If, however, you're >not really an expert, you'll look at this and say, "Hmmm, in one place >they used range(), and in another they used xrange(). Clearly, there's >some reason for the difference, I need to figure out what it is, because >that's probably key to my understanding why this code isn't working". >So, you spend the next two hours pouring over reference manuals trying >to understand the subtle difference, until your friend comes over and >says, "You dolt, you just wasted half the afternoon. They're the same >thing. Move on, this is not the bug you're looking for". ...and if you're a Python guru, you might spend a little bit of time trying to figure out if the range() is causing the problem due to allocating a large chunk of memory.... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From raoulbia at gmail.com Tue Sep 7 13:45:52 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 10:45:52 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> Message-ID: <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> On 7 sep, 16:50, Grant Edwards wrote: > On 2010-09-07, Baba wrote: > > > Sloppy wording, I apologise. This should say: If you find the > > question you're reading too easy then just don't answer. Noone is the > > owner of a democratic forum where freedom to ask the question one > > likes is paramount (as long of course as it is related to the > > group)...so let me repeat that, to say "Please do us a favour and at > > least try to figure things out on your own" is in my view > > inappropriate. > > You need to read this: > > ?http://www.catb.org/esr/faqs/smart-questions.html > > > To me it sounds "Do me a favur and get lost". > > No, it means "Do yourself a favor, learn how to do things yourself." > > Remember: you're then one asking people to give you something for > free. It's not up to them to conform to your expectations, rather you > need to conform to theirs. ?Otherwise, they'll just ignore you. > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! FOOLED you! ?Absorb > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? EGO SHATTERING impulse > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ?rays, polyester poltroon!! "Please do us a favour" sounds condescending to me at least but maybe we Europeans are a bit touchy... However the following Wiki excerpt seems to go in my direction: "When someone makes a mistake -- whether it's a spelling error or a spelling flame, a stupid question or an unnecessarily long answer -- be kind about it. If it's a minor error, you may not need to say anything. Even if you feel strongly about it, think twice before reacting. Having good manners yourself doesn't give you license to correct everyone else. If you do decide to inform someone of a mistake, point it out politely, and preferably by private email rather than in public. Give people the benefit of the doubt; assume they just don't know any better. And never be arrogant or self-righteous about it." http://en.wikipedia.org/wiki/Netiquette Baba From phlip2005 at gmail.com Tue Sep 7 13:52:44 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 10:52:44 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On Sep 7, 10:36?am, Ian Kelly wrote: > On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: > > Back to the topic, I tend to do this: > > > ?for record in Model.objects.filter(pk=42): > > ? ? return record > > > ?return sentinel > > How is that any better than just catching the exception? > > try: > ? ? return Model.objects.get(pk=42) > except Model.DoesNotExist: > ? ? return sentinel > > The flow of control is much clearer this way. It reminds me of Visual Basic. And no it's not "much clearer". Exceptions are for catastrophic errors that the caller should care not to handle. A "record not found" is not a catastrophe. Read my original post. AAAND you need to test that the DoesNotExist occurs for the exact reason you expect. Your except is not complete. Making it complete is very hard, and will break as soon as the model changes. From johnroth1 at gmail.com Tue Sep 7 14:14:36 2010 From: johnroth1 at gmail.com (John Roth) Date: Tue, 7 Sep 2010 11:14:36 -0700 (PDT) Subject: What the \xc2\xa0 ?!! References: <662d8f01-f1f6-44a4-86e3-694b9b6a73ba@v41g2000yqv.googlegroups.com> Message-ID: <23f4a0f0-d38a-4e60-9ae7-a0ff27467e0f@y12g2000prb.googlegroups.com> On Sep 7, 11:01?am, Brian D wrote: > In an HTML page that I'm scraping using urllib2, a ?\xc2\xa0 > bytestring appears. > > The page's charset = utf-8, and the Chrome browser I'm using displays > the characters as a space. > > The page requires authentication:https://www.nolaready.info/myalertlog.php > > When I try to concatenate strings containing the bytestring, Python > chokes because it refuses to coerce the bytestring into ascii. > > wfile.write('|'.join(valueList)) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 163: ordinal not in range(128) > > In searching for help with this issue, I've learned that the > bytestring *might* represent a non-breaking space. > > When I scrape the page using urllib2, however, the characters print > as ??? ?in a Windows command prompt (though I wouldn't be surprised if > this is some erroneous attempt by the antiquated command window to > handle something it doesn't understand). > > If I use IDLE to attempt to decode the single byte referenced in the > error message, and convert it into UTF-8, another error message is > generated: > > >>> weird = unicode('\xc2', 'utf-8') > > Traceback (most recent call last): > ? File "", line 1, in > ? ? weird = unicode('\xc2', 'utf-8') > UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 0: > unexpected end of data > > If I attempt to decode the full bytestring, I don't obtain a human- > readable string (expecting, perhaps, a non-breaking space): > > >>> weird = unicode('\xc2\xa0', 'utf-8') > >>> par = ' - '.join(['This is', weird]) > >>> par > > u'This is - \xa0' > > I suspect that the bytestring isn't UTF-8, but what is it? Latin1? > > >>> weirder = unicode('\xc2\xa0', 'latin1') > >>> weirder > u'\xc2\xa0' > >>> 'This just gets ' + weirder > > u'This just gets \xc2\xa0' > > Or is it a Microsoft bytestring? > > >>> weirder = unicode('\xc2\xa0', 'mbcs') > >>> 'This just gets ' + weirder > > u'This just gets \xc2\xa0' > > None of these codecs seem to work. > > Back to the original purpose, as I'm scraping the page, I'm storing > the field/value pair in a dictionary with each iteration through table > elements on the page. This is all fine, until a value is found that > contains the offending bytestring. I have attempted to coerce all > value strings into an encoding, but Python doesn't seem to like that > when the string is already Unicode: > > valuesDict[fieldString] = unicode(value, 'UTF-8') > TypeError: decoding Unicode is not supported > > The solution I've arrived at is to specify the encoding for value > strings both when reading and writing value strings. > > for k, v in valuesDict.iteritems(): > ? ? valuePair = ':'.join([k, v.encode('UTF-8')]) > ? ? [snip] ... > ? ? wfile.write('|'.join(valueList)) > > I'm not sure I have a question, but does this sound familiar to any > Unicode experts out there? > > How should I handle these odd bytestring values? Am I doing it > correctly, or what could I improve? > > Thanks! Since it's UTF-8, one should go to one of the UTF-8 pages that describes how to decode it. As it turns out, its unicode hex value is A0, which is indeed a non-breaking space. This is probably as good as any page: http://en.wikipedia.org/wiki/UTF-8 John Roth From tjreedy at udel.edu Tue Sep 7 14:15:39 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 14:15:39 -0400 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) In-Reply-To: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: On 9/7/2010 9:24 AM, sajuptpm wrote: > I have a list of tuples. > > l = [((30,50),(70)), ((50,20),(20))] > > for i in range(10): > k = ((i+30,i+50),(i+70)) The (i+70) parens do nothing, as already explained to (20) Your set of test data are not very good as they do not test all the insertion possibilities. The value of the third number is not relevant to the problem and might as well be 0 for testing purposes. #suppose creating new tuple in each iteration > using some random value and in sert it into list. > > flag=True > for i, v in enumerate(l): You are reusing 'i' as index variable when it is already in use as index variable for the outer loop. This is a confusing and a bad idea in general, even if it happens to work. > if v>= k: > l.insert(i,k) > flag = False > break This block should be indented under the inner for loop > if flag: > l.append(k) flay can be avoided by using else clause of for statement > This code will give a list of tuples sorted in asc order. > I need to change this code to sort this list by k[0][0] ascending and > k[0][1] descending. > What are the modifications needed in this code. Change the v>=k test to be the one you want. Here is my code: l = [((30,51),0), ((30,49),0), ((32,20),0)] for i in range(5): k = ((i+29,i+51), 0) for i, v in enumerate(l): v00 = v[0][0] k00 = k[0][0] if v00 > k00 or v00==k00 and v[0][1] <= k[0][1]: l.insert(i,k) break else: l.append(k) print(l) # prints [((29, 51), 0), ((30, 52), 0), ((30, 51), 0), ((30, 49), 0), ((31, 53), 0), ((32, 54), 0), ((32, 20), 0), ((33, 55), 0)] > I dont want to user sort() method of list. Why not? Even for the example above, .sort is faster than doing the insert sort in Python code! Indent the above with def f1():. Then def f2(): l = [((30,51),0), ((30,49),0), ((32,20),0)] for i in range(5): l.append(((i+29,i+51), 0)) l.sort(key=lambda x:(x[0][0], -x[0][1])) import timeit print(timeit.timeit(f1,'from __main__ import f1,f2',number=100000)) print(timeit.timeit(f2,'from __main__ import f1,f2',number=100000)) #prints 2.51296240165 1.63514413145 > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in That should be -x[0][1] It is a good idea to test code before posting. Any reason for the 'need' other than a wrong idea about relative speed? -- Terry Jan Reedy From ian.g.kelly at gmail.com Tue Sep 7 14:21:16 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Sep 2010 12:21:16 -0600 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 11:52 AM, Phlip wrote: > And no it's not "much clearer". It's clearer because it does exactly what it says it does, unlike your approach that masquerades as a loop. > Exceptions are for catastrophic errors No, they're for flagging "exceptional" states. /Errors/ are for catastrophic errors. The fact that errors are a subset of exceptions is just for convenience in handling. > AAAND you need to test that the DoesNotExist occurs for the exact > reason you expect. I'm not following you here. The only possible reason the exception can occur is if no matching row exists. If there were some other reason for raising an exception, then a different exception would be raised. > Your except is not complete. Making it complete is > very hard, and will break as soon as the model changes. Still not following you. What is it missing, and how will it break? From tjreedy at udel.edu Tue Sep 7 14:28:38 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 14:28:38 -0400 Subject: Bit fields in python? In-Reply-To: References: Message-ID: On 9/7/2010 12:06 AM, Kwan Lai Cheng wrote: > Hi, > I'm trying to rewrite a c program in python & encountered several > problems. I have some data structures in my c program like below: > typedef struct > { > unsigned short size; > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsigned short var_a3:2; > unsigned short var_a4:2; > unsigned int var_a5; > }structa; In Python, we cannot directly name bitfields within an int. However, we can *read, set, and flip bits with the bit operators and bit masks *define a dict that maps bitfield names to bit indexes *define named functions that use the above. *wrap or subclass int with a class that has attributes that map to a bitfield. I am pretty sure there is public code that does all of the above. Searching pypi.python.org for 'bitfield', I found BitDecoder 0.5.1 Decode bit-fields to human readable description This program (and Python module) will decode a value as per a bitfield definition. This is very useful for hardware registers that have meanings to parts of the bits in seperate. Google for more. -- Terry Jan Reedy From python.list at tim.thechases.com Tue Sep 7 14:36:08 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 07 Sep 2010 13:36:08 -0500 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <4C868618.2060507@tim.thechases.com> On 09/07/10 12:52, Phlip wrote: >> try: >> return Model.objects.get(pk=42) >> except Model.DoesNotExist: >> return sentinel >> >> The flow of control is much clearer this way. > > It reminds me of Visual Basic. > > And no it's not "much clearer". Exceptions are for catastrophic errors > that the caller should care not to handle. A "record not found" is not > a catastrophe. Exceptions are not limited to catastrophic errors, simply exceptional (not the common) cases. E.g. iterators raising StopException when exhausted. >>> i = iter(range(2)) >>> i.next() 0 >>> i.next() 1 >>> i.next() Traceback (most recent call last): File "", line 1, in StopIteration >>> i = iter(range(2)) >>> for v in i: ... print v ... 0 1 Running out of things to iterate over is pretty non-catastrophic in my book. :) Using exceptions as in the grandparent's post seem perfectly fine to me. The other option would be to LBYL: items = list(MyModel.objects.filter(...)) if len(items) == 1: do_something(items[0]) else: what_the(...) -tkc From phlip2005 at gmail.com Tue Sep 7 14:53:37 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 11:53:37 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On Sep 7, 11:36?am, Tim Chase wrote: > > And no it's not "much clearer". Exceptions are for catastrophic errors > > that the caller should care not to handle. A "record not found" is not > > a catastrophe. > > Exceptions are not limited to catastrophic errors, simply > exceptional (not the common) cases. ?E.g. iterators raising > StopException when exhausted. Exceptions are not "because we should only return one type of thing". They are for situations which the caller should care not to handle. Exceptions are for propagating. A "record not found" is an exemplary example of a situation the caller _should_ handle. > ? ?items = list(MyModel.objects.filter(...)) > ? ?if len(items) == 1: > ? ? ?do_something(items[0]) > ? ?else: > ? ? ?what_the(...) Both your version and mine read an entire cursor. But mine only rezzed the first object, whereas yours rezzed every object in the cursor, just to throw most of them away! From nagle at animats.com Tue Sep 7 15:02:07 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Sep 2010 12:02:07 -0700 Subject: Bug in Python 2.6 urlencode Message-ID: <4c868c2d$0$1581$742ec2ed@news.sonic.net> There's a bug in Python 2.6's "urllib.urlencode". If you pass in a Unicode character outside the ASCII range, instead of it being encoded properly, an exception is raised. File "C:\python26\lib\urllib.py", line 1267, in urlencode v = quote_plus(str(v)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 0: ordinal not in range(128) This will probably work in 3.x, because there, "str" converts to Unicode, and quote_plus can handle Unicode. This is one of those legacy bugs left from the pre-Unicode era. There's a workaround. Call urllib.urlencode with a second parameter of 1. This turns on the optional feature of accepting tuples in the argument to be encoded, and the code goes through a newer code path that works. Is it worth reporting 2.x bugs any more? Or are we in the version suckage period, where version N is abandonware and version N+1 isn't deployable yet. John Nagle From nagle at animats.com Tue Sep 7 15:13:41 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Sep 2010 12:13:41 -0700 Subject: Bit fields in python? In-Reply-To: References: Message-ID: <4c868ee2$0$1650$742ec2ed@news.sonic.net> On 9/6/2010 11:55 PM, Stefan Behnel wrote: > Kwan Lai Cheng, 07.09.2010 06:06: >> I'm trying to rewrite a c program in python& encountered several >> problems. I have some data structures in my c program like below: >> def __init__(self, size=0) >> >> Any equivalent for c data structures& bit fields in python? > > If you can tell us what these structs are being used for in the original > C code, we might be able to point you to a suitable way to implement the > same thing efficiently in Python. Python has the "struct" module for formatting binary data. http://docs.python.org/library/struct.html But it doesn't handle bit fields. Its lowest resolution is one byte. John Nagle From nad at acm.org Tue Sep 7 15:23:57 2010 From: nad at acm.org (Ned Deily) Date: Tue, 07 Sep 2010 12:23:57 -0700 Subject: Bug in Python 2.6 urlencode References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> Message-ID: In article <4c868c2d$0$1581$742ec2ed at news.sonic.net>, John Nagle wrote: > Is it worth reporting 2.x bugs any more? Or are we in the > version suckage period, where version N is abandonware and > version N+1 isn't deployable yet. Yes!! 2.7 is being actively maintained for bug fixes. (2.6 only for any security issues that might arise.) It's easy enough to see this if you take a glance at current activity on any of several Python development related mailing lists: http://www.python.org/community/lists/ -- Ned Deily, nad at acm.org From no.email at nospam.invalid Tue Sep 7 15:29:34 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Sep 2010 12:29:34 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> <7xbp8el03t.fsf@ruckus.brouhaha.com> Message-ID: <7x4oe18i8x.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > But you?ll notice that Free Software comes with no such > restrictions. In fact, it is contrary to commonly-accepted Free > Software guidelines to impose any sort of restrictions on areas of use. Free software comes with an explicit disclaimer of liability (you get what you pay for). The Sun stuff ($$$$$) may have either an express or implied warranty that could mean they get hit up for damages if the software is wrong. IANAL YMMV etc. From python.list at tim.thechases.com Tue Sep 7 15:45:04 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 07 Sep 2010 14:45:04 -0500 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <4C869640.9030907@tim.thechases.com> On 09/07/10 13:53, Phlip wrote: > On Sep 7, 11:36 am, Tim Chase wrote: > >>> And no it's not "much clearer". Exceptions are for catastrophic errors >>> that the caller should care not to handle. A "record not found" is not >>> a catastrophe. >> >> Exceptions are not limited to catastrophic errors, simply >> exceptional (not the common) cases. E.g. iterators raising >> StopException when exhausted. > > Exceptions are not "because we should only return one type of thing". > They are for situations which the caller should care not to handle. > Exceptions are for propagating. A "record not found" is an exemplary > example of a situation the caller _should_ handle. Um...first you state "Exceptions are for catastrophic errors that the caller should not care to handle. A 'record not found' is not a catastrophe" and then you contradictingly go on to state "A 'record not found' is an exemplary example of a situation the caller _should_ handle". I'm not sure I follow your logic here. Exceptions allow both (1) the ability to handle the exceptional condition locally if you want to (including suppressing it) and (2) propagate the exception if you want to make the caller handle it. And if you really want, you can just subclass QuerySet to provide your own get_or_none() method to return your sentinel. >> items = list(MyModel.objects.filter(...)) >> if len(items) == 1: >> do_something(items[0]) >> else: >> what_the(...) > > Both your version and mine read an entire cursor. But mine only rezzed > the first object, whereas yours rezzed every object in the cursor, > just to throw most of them away! If a .get() returns more than one object (non-unique criteria are used), what _should_ it return? Agreed, if it pulls back a bajillion records, that's bad, so if you're concerned your conditions might do that despite the expectation they bring back 1-and-only-1 (.get() currently raises an exception if it brings back more than one result db/models/query.py around line 342 where MultipleObjectsReturned is raised), then I'd just slice them: items = list(MyModel.objects.filter(...)[:1]) if items: do_something(items[0]) else: what_the(...) -tkc From raoulbia at gmail.com Tue Sep 7 15:46:36 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 12:46:36 -0700 (PDT) Subject: compare dictionaries Message-ID: level: beginner word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} i want to know if word is entirely composed of letters in dict2 my approach: step 1 : convert word to dictionary(dict1) step2: for k in dict1.keys(): if k in dict2: if dict1[k] != dict2[k]: return False return True return False return True by adding a print statement i can see that this simply ends too early e.g. as soon as the first IF condition is met the loop exits i think this is easy but google and python doc didn't return any good hints so i'm trying here. Thanks Baba From rami.chowdhury at merton.oxon.org Tue Sep 7 15:54:17 2010 From: rami.chowdhury at merton.oxon.org (Rami Chowdhury) Date: Wed, 8 Sep 2010 01:54:17 +0600 Subject: Help needed - function apparently global cannot be called. In-Reply-To: <4C864585.3050204@gmaiil.com> References: <4c8618e5$0$8784$426a74cc@news.free.fr> <4C864585.3050204@gmaiil.com> Message-ID: Hi Ian, On Tue, Sep 7, 2010 at 20:00, Ian wrote: > On 07/09/2010 11:50, Bruno Desthuilliers wrote: > > note the order of the above - log is defined before the import. > > And ? Do you think it will affect the imported module in any way ? Like, > say, magically "inject" your log function in the DelNotePrinter module ?-) > > Just that log is defined before the global log is encountered to that if > the compiler needed to set up a link at compile time it was able to do so. > > I think I see where you're going wrong -- this bit me too when I was learning Python, having come from PHP. Unlike PHP, when you import a module in Python it does *not* inherit the importing module's namespace. So the "log" function you're accessing in DelNotePrinter.py is not the one you defined above the import statement. > In Python, "global" means "module-level", and it's only necessary when you > want to rebind a module-level name from within a function or method. > > Exactly! I want to bind the name log to the function I wrote. > As Bruno pointed out, the "global" statement is only necessary if you want to "rebind" a name -- i.e. if you want to modify how an object appears to the global scope. It's not necessary if you simply want to call a function. > > I have read http://docs.python.org/reference/simple_stmts.html#globalvery carefully and I still don't understand. > > > The statement definition makes no sense if you don't understand namespaces > and bindings: > > http://docs.python.org/reference/executionmodel.html#naming-and-binding > > Thanks for the pointer. What a truly execrable piece of writing - full of > over-long sentences and multiple subordinate clauses. It routinely uses > terms before definition, and sometimes without definition. It is > astonishingly bad. > Perhaps you could help rewrite it? I'm sure the maintainers would be very happy to get a documentation patch. > > The third sentence reads "Each occurrence of a name in the program text > refers to the *binding* of that name established in the innermost function > block containing the use." What does that mean? It appears to mean that it > is the assignment in the innermost function block that binds for all uses, > not the first, not module blocks, not class blocks and not code blocks - but > the innermost function block. That might be correct, but somehow I doubt it, > for it would mean that earlier bindings are ignored or invalidated or not > used or something - even if the inner block is not executed. > > I am not stupid and English is my mother tongue, and I have read that page > many times. The implications of the passage are still opaque to me. > > How can I call a global function placed at the top of the source. Do I > really have to move a 4 line function into its own file and import it again > and again and again? > The short answer is yes. If you have this and similar functions that you call from various modules, then it's ideal to put them in a utility module of their own. However, as imported modules are cached in Python, this isn't as expensive as you might think if you are more used to other languages. -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -------------- next part -------------- An HTML attachment was scrubbed... URL: From sschwarzer at sschwarzer.net Tue Sep 7 16:01:42 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Tue, 07 Sep 2010 22:01:42 +0200 Subject: Help needed - function apparently global cannot be called. In-Reply-To: References: Message-ID: <4C869A26.8060209@sschwarzer.net> Hi Ian, On 2010-09-07 12:18, Ian Hobson wrote: > f = open('d:\logfile.txt','a') Just a note: Using a backslash in a non-raw string will get you in trouble as soon as the backslash is followed by a character which makes a special character sequence, like "\n". For example, f = open('d:\nice_filename.txt', 'a') will give surprising results. :-) Either double the backslash, use a raw string, or, in the special case of file system paths, possibly use a forward slash. Stefan From no.email at nospam.invalid Tue Sep 7 16:06:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Sep 2010 13:06:01 -0700 Subject: compare dictionaries References: Message-ID: <7x4oe15nfa.fsf@ruckus.brouhaha.com> Baba writes: > word= 'even' > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > i want to know if word is entirely composed of letters in dict2 set(word) <= set(dict2.keys()) From bdesth.quelquechose at free.quelquepart.fr Tue Sep 7 16:06:37 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 22:06:37 +0200 Subject: The Samurai Principle In-Reply-To: <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> Message-ID: <4c86b6cc$0$10872$426a74cc@news.free.fr> Phlip a ?crit : > On Sep 7, 10:12 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Phlip a ?crit : >> >>> Back to the topic, I tend to do this: >>> for record in Model.objects.filter(pk=42): >>> return record >>> return sentinel >> WTF alert here... > > I don't see how anyone could WTF that. Are you pretending to be a newb > who doesn't understanding it? F'em. F'... newbies is definitly not the pythonic mindset. Python's mindset is about doing the most obvious thing, no trying to be smart. The obvious code here is: try: return Model.objects.get(pk=42) except Model.DoesNotExist: return sentinel so yes, your above snippet is bordering on WTF since it's not immediatly obvious - it takes at least one more second for me to parse, and I'm definitly not a Python nor Django newbie. That's something I'd immediatly rewrite if I had to work on this code. > I would guess that Django provides some basic rules for avoiding name > collisions. yes : common sense. > Nobody should call a field "pk__in" Nope, but "default" - which would be the obvious keyword here - is also a perfectly legitimate field name. >> But if you feel like you found the correct name, you can of course >> monkeypatch queryset !-) > > Know I gotta learn to add a new method to an existing class! It's as straightforward as possible once you know Python's object model: def somefunc(self, whatever): self.do_something_with(whatever) import somemodule somemodule.SomeClass.mymethod = somefunc From gherron at digipen.edu Tue Sep 7 16:08:27 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 07 Sep 2010 13:08:27 -0700 Subject: compare dictionaries In-Reply-To: References: Message-ID: <4C869BBB.8020706@digipen.edu> On 09/07/2010 12:46 PM, Baba wrote: > word= 'even' > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > Just go through each letter of word checking for its existence in dict2. Return False if one misses, and True if you get through the whole word: def ...(): for c in word: if c not in dict2: return False #if any character is not in dict return True # otherwise If you know of generator expressions, and remember that True and False are 1 and 0 respectively, then this works def ...(): return sum(c in dict2 for c in word) == len(word) Gary Herron -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From roberto.pagliari at gmail.com Tue Sep 7 16:12:25 2010 From: roberto.pagliari at gmail.com (Bob) Date: Tue, 7 Sep 2010 13:12:25 -0700 (PDT) Subject: can't send email Message-ID: Hello. I'm trying to send email using python 2.6.1 under snow leopard, but I can't get it to work. I'm trying one of the many examples I found on the web EXAMPLE 1 import smtplib fromaddr = 'fromuser at gmail.com' toaddrs = 'touser at gmail.com' msg = 'There was a terrible error that occured and I wanted you to know!' # Credentials (if needed) username = 'username' password = 'password' # The actual mail send server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username,password) server.sendmail(fromaddr, toaddrs, msg) server.quit() EXAMPLE 2 # Import smtplib for the actual sending function import smtplib # Import the email modules we'll need from email.mime.text import MIMEText # Open a plain text file for reading. For this example, assume that # the text file contains only ASCII characters. fp = open(textfile, 'rb') # Create a text/plain message msg = MIMEText(fp.read()) fp.close() # me == the sender's email address # you == the recipient's email address msg['Subject'] = 'The contents of %s' % textfile msg['From'] = me msg['To'] = you # Send the message via our own SMTP server, but don't include the # envelope header. s = smtplib.SMTP() s.sendmail(me, [you], msg.as_string()) s.quit() The error I get is this python email.py Traceback (most recent call last): File "email.py", line 2, in import smtplib File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/smtplib.py", line 46, in import email.utils File "/Users/Bob/Code/email.py", line 5, in from email.mime.text import MIMEText ImportError: No module named mime.text I'm using the native python version installed by apple, so I don't know why email and email.utils and mime are not found. I checked on the filesystem and they are present... Thanks From bdesth.quelquechose at free.quelquepart.fr Tue Sep 7 16:15:42 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 22:15:42 +0200 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <4c86b8ed$0$9874$426a74cc@news.free.fr> Phlip a ?crit : > On Sep 7, 10:36 am, Ian Kelly wrote: >> On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: >>> Back to the topic, I tend to do this: >>> for record in Model.objects.filter(pk=42): >>> return record >>> return sentinel >> How is that any better than just catching the exception? >> >> try: >> return Model.objects.get(pk=42) >> except Model.DoesNotExist: >> return sentinel >> >> The flow of control is much clearer this way. > > It reminds me of Visual Basic. Strange enough, your own code snippet reminds me of what I used to find when fixing VB programs some ten years ago. > And no it's not "much clearer". It is for any Python programmer - it's even TheOneObviousWay. > Exceptions are for catastrophic errors Chapter and verse, please ? Exceptions are for exceptional situations. When you call queryset.get, you do expect to have one single instance matching the lookup - specialy when doing a pk lookup. > AAAND you need to test that the DoesNotExist occurs for the exact > reason you expect. Bullshit. The only reason you'd get this exception is because there's no record matching your where clause. > Your except is not complete. Why so ? > Making it complete is > very hard, and will break as soon as the model changes. Why so ? From raoulbia at gmail.com Tue Sep 7 16:26:10 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 13:26:10 -0700 (PDT) Subject: compare dictionaries References: Message-ID: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> On 7 sep, 22:08, Gary Herron wrote: > On 09/07/2010 12:46 PM, Baba wrote: > > > word= 'even' > > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > Just go through each letter of word checking for its existence in > dict2. ?Return False if one misses, and True if you get through the > whole word: > > def ...(): > ? ?for c in word: > ? ? ?if c not in dict2: > ? ? ? ?return False #if any character is not in dict > ? ?return True ? ? ?# otherwise > > If you know of generator expressions, and remember that True and False > are 1 and 0 respectively, then this works > > def ...(): > ? ? ?return sum(c in dict2 ? for c in word) == len(word) > > Gary Herron > > -- > Gary Herron, PhD. > Department of Computer Science > DigiPen Institute of Technology > (425) 895-4418 ok but how do we address the fact that letter e needs to have the value 2 in the dictionary if it was to be True? in my example this condition is not met so the check would return False. Word is not entirely composed of letters in dict2, one of the letter is not in dict2 i.e. the 2nd e So finding a matching key seems to be the easy part, checking if the number of ocurrences of letter in 'word' == letter.value seems to be the tricky part From chris at rebertia.com Tue Sep 7 16:27:43 2010 From: chris at rebertia.com (Chris Rebert) Date: Tue, 7 Sep 2010 13:27:43 -0700 Subject: can't send email In-Reply-To: References: Message-ID: On Tue, Sep 7, 2010 at 1:12 PM, Bob wrote: > Hello. > I'm trying to send email using python 2.6.1 under snow leopard, but I > can't get it to work. I'm trying one of the many examples I found on > the web > The error I get is this > > python email.py > Traceback (most recent call last): > ?File "email.py", line 2, in > ? ?import smtplib > ?File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/smtplib.py", line 46, in > ? ?import email.utils > ?File "/Users/Bob/Code/email.py", line 5, in > ? ?from email.mime.text import MIMEText > ImportError: No module named mime.text > > > I'm using the native python version installed by apple, so I don't > know why email and email.utils and mime are not found. I checked on > the filesystem and they are present... Your /Users/Bob/Code/email.py file is shadowing the std lib "email" module. Rename your file to something else so that it no longer conflicts. Cheers, Chris -- http://blog.rebertia.com From roberto.pagliari at gmail.com Tue Sep 7 16:29:22 2010 From: roberto.pagliari at gmail.com (Bob) Date: Tue, 7 Sep 2010 13:29:22 -0700 (PDT) Subject: can't send email References: Message-ID: On Sep 7, 10:27?pm, Chris Rebert wrote: > On Tue, Sep 7, 2010 at 1:12 PM, Bob wrote: > > Hello. > > I'm trying to send email using python 2.6.1 under snow leopard, but I > > can't get it to work. I'm trying one of the many examples I found on > > the web > > > The error I get is this > > > python email.py > > Traceback (most recent call last): > > ?File "email.py", line 2, in > > ? ?import smtplib > > ?File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/smtplib.py", line 46, in > > ? ?import email.utils > > ?File "/Users/Bob/Code/email.py", line 5, in > > ? ?from email.mime.text import MIMEText > > ImportError: No module named mime.text > > > I'm using the native python version installed by apple, so I don't > > know why email and email.utils and mime are not found. I checked on > > the filesystem and they are present... > > Your /Users/Bob/Code/email.py file is shadowing the std lib "email" > module. Rename your file to something else so that it no longer > conflicts. > > Cheers, > Chris > --http://blog.rebertia.com yes I just realized that... it works now!! thanks From nad at acm.org Tue Sep 7 16:30:14 2010 From: nad at acm.org (Ned Deily) Date: Tue, 07 Sep 2010 13:30:14 -0700 Subject: can't send email References: Message-ID: In article , Bob wrote: >[...] > The error I get is this > > python email.py > Traceback (most recent call last): > File "email.py", line 2, in > import smtplib > File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/smtplib.py", line 46, in > import email.utils > File "/Users/Bob/Code/email.py", line 5, in > from email.mime.text import MIMEText > ImportError: No module named mime.text Your module email.py is hiding the standard library's email package. Rename your file from email.py to something that doesn't conflict. -- Ned Deily, nad at acm.org From python at mrabarnett.plus.com Tue Sep 7 16:37:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Sep 2010 21:37:58 +0100 Subject: compare dictionaries In-Reply-To: <7x4oe15nfa.fsf@ruckus.brouhaha.com> References: <7x4oe15nfa.fsf@ruckus.brouhaha.com> Message-ID: <4C86A2A6.6040501@mrabarnett.plus.com> On 07/09/2010 21:06, Paul Rubin wrote: > Baba writes: >> word= 'even' >> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >> >> i want to know if word is entirely composed of letters in dict2 > > set(word)<= set(dict2.keys()) Do the numbers in dict2 represent the maximum number of times that the letter can be used? If yes, then build a similar dict for the word with the number of times that each letter occurs in the word and then check for every pair in the dict whether the key (ie, letter) occurs in dict2 and that the value (number of occurrences) isn't too many. From anand.shashwat at gmail.com Tue Sep 7 16:42:11 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 8 Sep 2010 02:12:11 +0530 Subject: compare dictionaries In-Reply-To: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> References: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> Message-ID: On Wed, Sep 8, 2010 at 1:56 AM, Baba wrote: > On 7 sep, 22:08, Gary Herron wrote: > > On 09/07/2010 12:46 PM, Baba wrote: > > > > > word= 'even' > > > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > > > Just go through each letter of word checking for its existence in > > dict2. Return False if one misses, and True if you get through the > > whole word: > > > > def ...(): > > for c in word: > > if c not in dict2: > > return False #if any character is not in dict > > return True # otherwise > > > > If you know of generator expressions, and remember that True and False > > are 1 and 0 respectively, then this works > > > > def ...(): > > return sum(c in dict2 for c in word) == len(word) > > > > Gary Herron > > > > -- > > Gary Herron, PhD. > > Department of Computer Science > > DigiPen Institute of Technology > > (425) 895-4418 > > ok but how do we address the fact that letter e needs to have the > value 2 in the dictionary if it was to be True? in my example this > condition is not met so the check would return False. Word is not > entirely composed of letters in dict2, one of the letter is not in > dict2 i.e. the 2nd e > Seems You did not understood Gary's solution. It is correct. Also, you asked for 'i want to know if word is entirely composed of letters in dict2' which you are getting. Did you tried running the code ? > So finding a matching key seems to be the easy part, checking if the > number of ocurrences of letter in 'word' == letter.value seems to be > the tricky part > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Sep 7 17:08:49 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 23:08:49 +0200 Subject: compare dictionaries References: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> Message-ID: Baba wrote: > On 7 sep, 22:08, Gary Herron wrote: >> On 09/07/2010 12:46 PM, Baba wrote: >> >> > word= 'even' >> > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >> >> Just go through each letter of word checking for its existence in >> dict2. Return False if one misses, and True if you get through the >> whole word: >> >> def ...(): >> for c in word: >> if c not in dict2: >> return False #if any character is not in dict >> return True # otherwise >> >> If you know of generator expressions, and remember that True and False >> are 1 and 0 respectively, then this works >> >> def ...(): >> return sum(c in dict2 for c in word) == len(word) >> >> Gary Herron >> >> -- >> Gary Herron, PhD. >> Department of Computer Science >> DigiPen Institute of Technology >> (425) 895-4418 > > ok but how do we address the fact that letter e needs to have the > value 2 in the dictionary if it was to be True? in my example this > condition is not met so the check would return False. Word is not > entirely composed of letters in dict2, one of the letter is not in > dict2 i.e. the 2nd e > > So finding a matching key seems to be the easy part, checking if the > number of ocurrences of letter in 'word' == letter.value seems to be > the tricky part Just compare the two dictionaries dict1 == dict2 Or, if you want to allow dict2 to contain higher but not lower values all(v <= dict2.get(k, 0) for k, v in dict1.iteritems()) Peter From roberto.pagliari at gmail.com Tue Sep 7 17:26:11 2010 From: roberto.pagliari at gmail.com (Bob) Date: Tue, 7 Sep 2010 14:26:11 -0700 (PDT) Subject: formatted input Message-ID: Hi All, I have another question about formatted input. Suppose I am reading a text file, and that I want it to be something like this word11 = num11, word12 = num12, word13 = num13 etc... word21 = num21, word22 = num12, word23 = num23 etc... etc... where wordx1 belongs to a certain dictionary of words, say dic1, while wordx2 belongs to dic2, the numbers within some range and so on. I was wondering if there is something in the standard library I may use to check whether the file I am reading has a correct syntax according to my rules/dictionaries instead of implementing my own routine that would look like (pseudocode) for each line put words into a list check condition for each word Thanks From raoulbia at gmail.com Tue Sep 7 17:36:38 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 14:36:38 -0700 (PDT) Subject: compare dictionaries References: <7x4oe15nfa.fsf@ruckus.brouhaha.com> Message-ID: <78fb4e82-0e9b-4f0c-b5da-9da6588d6a89@q2g2000yqq.googlegroups.com> On 7 sep, 22:37, MRAB wrote: > On 07/09/2010 21:06, Paul Rubin wrote: > > > Baba ?writes: > >> word= 'even' > >> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > >> i want to know if word is entirely composed of letters in dict2 > > > set(word)<= set(dict2.keys()) > > Do the numbers in dict2 represent the maximum number of times that the > letter can be used? > > If yes, then build a similar dict for the word with the number of times > that each letter occurs in the word and then check for every pair in > the dict whether the key (ie, letter) occurs in dict2 and that the > value (number of occurrences) isn't too many. Hi MRAB Thanks for the hint. In my case i need to do the opposite: the number of times that each letter ocurs in the word needs to be smaller or equal to the number of times it apears in dict2. That way i am guaranteed that word is entirely made up of elements of dict2. Your hint pointed me in the right direction. for k in word.keys(): if k not in hand: return False elif k in hand: if word[k] > hand[k]: return False return True Baba From hobson42 at gmaiil.com Tue Sep 7 17:50:24 2010 From: hobson42 at gmaiil.com (Ian) Date: Tue, 07 Sep 2010 22:50:24 +0100 Subject: Help needed - function apparently global cannot be called. In-Reply-To: References: <4c8618e5$0$8784$426a74cc@news.free.fr> <4C864585.3050204@gmaiil.com> Message-ID: <4C86B3A0.6040709@gmaiil.com> Hi Rami, Stefan, Bruno. First a big thanks for your replies. On 07/09/2010 20:54, Rami Chowdhury wrote: > Hi Ian, > > I think I see where you're going wrong -- this bit me too when I was > learning Python, having come from PHP. Unlike PHP, when you import a > module in Python it does *not* inherit the importing module's > namespace. So the "log" function you're accessing in DelNotePrinter.py > is not the one you defined above the import statement. > Hmm. My php background shows that much. Huh? :) I guess so. > >> >> http://docs.python.org/reference/executionmodel.html#naming-and-binding >> >> > Thanks for the pointer. What a truly execrable piece of writing - > full of over-long sentences and multiple subordinate clauses. It > routinely uses terms before definition, and sometimes without > definition. It is astonishingly bad. > > > Perhaps you could help rewrite it? I'm sure the maintainers would be > very happy to get a documentation patch. I would be happy to re-write it but I do need to understand the subject better before that can happen. Clear and wrong will not help anyone. :) > > Do I really have to move a 4 line function into its own file and > import it again and again and again? > > > The short answer is yes. If you have this and similar functions that > you call from various modules, then it's ideal to put them in a > utility module of their own. However, as imported modules are cached > in Python, this isn't as expensive as you might think if you are more > used to other languages. > OK. Now I understand the need, the solution is easy. My first exploration of the wonders of writing windows services has had five things wrong with it: 1) Its windows - spit, crash, complicated, can't start a command line with elevated permissions, nash teeth, rip hair out. 2) Its services - so no stdout, or stderr, errors not reported, no "current directory" - burn and crash programming all over again. Deep joy! 3) pythonservice.exe - so module not called __main__ and initialisation not performed (unseen - see 2) - More fun. 4) multi-threading - I got really confused from this example http://docs.python.org/library/multiprocessing.html#exchanging-objects-between-processes becasue I got the wrong sort of Queue, so it stalled when it failed to call task_done() (there isn't such a method - but no error reported see 2). 5) Names pipes. The latest is that writing - yes writing - to the named pipe causes the reader to fail with (232, 'ConnectNamedPipe', 'The pipe is being closed.') if I write using php - yet I can write with python no trouble. There are down sides to "batteries included". When there are so many batteries, it can be hard to know if what you have is "good enough" or should you search for a more suitable one. Logging would have helped me a lot (assuming it would work in service environment with the permissions it would have had - a serious assumption). If it failed, it would have failed and hidden the problem. Oh to get on to proper GUI programming with python and PyQt! The next project. Wey Hey! Thanks again Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Tue Sep 7 17:56:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Sep 2010 14:56:07 -0700 Subject: compare dictionaries References: <7x4oe15nfa.fsf@ruckus.brouhaha.com> <78fb4e82-0e9b-4f0c-b5da-9da6588d6a89@q2g2000yqq.googlegroups.com> Message-ID: <7xy6bddxqg.fsf@ruckus.brouhaha.com> Baba writes: > for k in word.keys(): > if k not in hand: > return False > elif k in hand: > if word[k] > hand[k]: > return False > return True Untested: all(word[k] <= hand.get(k,0) for k in word) From deets at web.de Tue Sep 7 18:03:21 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 08 Sep 2010 00:03:21 +0200 Subject: formatted input References: Message-ID: Bob writes: > Hi All, > I have another question about formatted input. Suppose I am reading a > text file, and that I want it to be something like this > > word11 = num11, word12 = num12, word13 = num13 etc... > word21 = num21, word22 = num12, word23 = num23 etc... > etc... > > where wordx1 belongs to a certain dictionary of words, say dic1, while > wordx2 belongs to dic2, the numbers within some range and so on. I was > wondering if there is something in the standard library I may use to > check whether the file I am reading has a correct syntax according to > my rules/dictionaries instead of implementing my own routine that > would look like > (pseudocode) > for each line > put words into a list > check condition for each word No, there is no such thing. Either write something from scratch using string methods, or use pyparsing which is certainly up to the task (and much more) Diez From cournape at gmail.com Tue Sep 7 18:18:50 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 8 Sep 2010 07:18:50 +0900 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: > > One order of magnitude (say 10-20x slower) wouldn't be so bad. That's what > you might expect for a dynamically typed, interpreted language. 10/20x slower than C is only reached by extremely well optimized dynamic languages. It would be a tremendous achievement. If that's what you are after, look at LUA with its JIT, or scheme + stalin. For cases where vectorization is indeed not applicable (recursive algorithms), like in some signal processing, there are specialized tools which are very expressive while retaining good speed (faust is an interesting one for audio signal processing). > That would simply be delegating Python to a scripting language. That's a strange thing to say if you compare it to matlab. > It would be > nice if you could directly code low-level algorithms in it without relying > on accelerators It would be nice, but the fact is that python cannot do it - and is quite far from being able to do it. I don't think it is as important as you think it is, because things like numpy are extremely powerful in many cases. cheers, David From phlip2005 at gmail.com Tue Sep 7 18:20:27 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 15:20:27 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> <4c86b6cc$0$10872$426a74cc@news.free.fr> Message-ID: <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> On Sep 7, 1:06?pm, Bruno Desthuilliers wrote: > try: > ? ?return Model.objects.get(pk=42) > except Model.DoesNotExist: > ? ?return sentinel Visual Basic Classic had a Collection Class, which worked essentially like a real language's Hash, Map, or Dict. Except - it had no operation to test membership. It also could not enumerate by key and value (which would be 'for k,v in dict.items()'). To test for membership, you _had_ to catch an exception - using VB's tragically clumsy exception model. Hours of fun. That leads us to this topic: http://www.google.com/search?q=don't+use+exceptions+for+normal+control+flow From knny.myer at gmail.com Tue Sep 7 18:35:44 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Tue, 7 Sep 2010 18:35:44 -0400 Subject: formatted input In-Reply-To: References: Message-ID: <20100907223543.GA26961@5732Z> Bob (roberto.pagliari at gmail.com) wrote: > Hi All, > I have another question about formatted input. Suppose I am reading a > text file, and that I want it to be something like this > > word11 = num11, word12 = num12, word13 = num13 etc... > word21 = num21, word22 = num12, word23 = num23 etc... > etc... > > where wordx1 belongs to a certain dictionary of words, say dic1, while > wordx2 belongs to dic2, the numbers within some range and so on. I was > wondering if there is something in the standard library I may use to > check whether the file I am reading has a correct syntax according to > my rules/dictionaries instead of implementing my own routine that > would look like Python's `re` module > (pseudocode) > for each line > put words into a list > check condition for each word import re match_1 = re.compile("^words1") match_2 = re.compile("^words2") # Return a match object each re.match(match_1, "word11") re.match(match_2, "word21") I'm sure there are might be other ways to do the same thing. -- - Kenny Meyer To understand recursion, we must first understand recursion. -- From gherron at digipen.edu Tue Sep 7 18:49:35 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 07 Sep 2010 15:49:35 -0700 Subject: compare dictionaries In-Reply-To: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> References: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> Message-ID: <4C86C17F.6060304@digipen.edu> On 09/07/2010 01:26 PM, Baba wrote: > On 7 sep, 22:08, Gary Herron wrote: > >> On 09/07/2010 12:46 PM, Baba wrote: >> >> >>> word= 'even' >>> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >>> >> Just go through each letter of word checking for its existence in >> dict2. Return False if one misses, and True if you get through the >> whole word: >> >> def ...(): >> for c in word: >> if c not in dict2: >> return False #if any character is not in dict >> return True # otherwise >> >> If you know of generator expressions, and remember that True and False >> are 1 and 0 respectively, then this works >> >> def ...(): >> return sum(c in dict2 for c in word) == len(word) >> >> Gary Herron >> >> -- >> Gary Herron, PhD. >> Department of Computer Science >> DigiPen Institute of Technology >> (425) 895-4418 >> > ok but how do we address the fact that letter e needs to have the > value 2 in the dictionary if it was to be True? in my example this > condition is not met so the check would return False. Word is not > entirely composed of letters in dict2, one of the letter is not in > dict2 i.e. the 2nd e > Huh??? I answered the problem as it was stated in the email -- it said nothing about *counting* the occurrences of letters. In order to not waste our (voluntary) time, perhaps you should carefully re-state the problem you'd liked solved. Then we'll see what we can come up with. > So finding a matching key seems to be the easy part, checking if the > number of ocurrences of letter in 'word' == letter.value seems to be > the tricky part > > -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From python at mrabarnett.plus.com Tue Sep 7 19:17:26 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Sep 2010 00:17:26 +0100 Subject: compare dictionaries In-Reply-To: <78fb4e82-0e9b-4f0c-b5da-9da6588d6a89@q2g2000yqq.googlegroups.com> References: <7x4oe15nfa.fsf@ruckus.brouhaha.com> <78fb4e82-0e9b-4f0c-b5da-9da6588d6a89@q2g2000yqq.googlegroups.com> Message-ID: <4C86C806.6010003@mrabarnett.plus.com> On 07/09/2010 22:36, Baba wrote: > On 7 sep, 22:37, MRAB wrote: >> On 07/09/2010 21:06, Paul Rubin wrote: >> >>> Baba writes: >>>> word= 'even' >>>> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >> >>>> i want to know if word is entirely composed of letters in dict2 >> >>> set(word)<= set(dict2.keys()) >> >> Do the numbers in dict2 represent the maximum number of times that the >> letter can be used? >> >> If yes, then build a similar dict for the word with the number of times >> that each letter occurs in the word and then check for every pair in >> the dict whether the key (ie, letter) occurs in dict2 and that the >> value (number of occurrences) isn't too many. > > Hi MRAB > > Thanks for the hint. In my case i need to do the opposite: the number > of times that each letter ocurs in the word needs to be smaller or > equal to the number of times it apears in dict2. That way i am > guaranteed that word is entirely made up of elements of dict2. > > Your hint pointed me in the right direction. > > for k in word.keys(): > if k not in hand: > return False > elif k in hand: > if word[k]> hand[k]: > return False > return True > If the first condition is True then the second will be False, so there's no need to check it: for k in word.keys(): if k not in hand: return False else: if word[k] > hand[k]: return False return True This can be shortened still further. From greg.ewing at canterbury.ac.nz Tue Sep 7 19:25:42 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Sep 2010 11:25:42 +1200 Subject: Queue cleanup In-Reply-To: <7xeid9gtuq.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> Message-ID: <8eo005FoboU1@mid.individual.net> Paul Rubin wrote: > Now extrapolate that error rate from 30 lines to a program the size of > Firefox (something like 5 MLOC), and you should see how fraught with > danger that style of programming is. But you don't write 5 MLOC of code using that programming style. You use it to write a small core something along the lines of, oh, I don't know, a Python interpreter, and then write the rest of the code on top of that platform. -- Greg From bussieremaillist at gmail.com Tue Sep 7 19:37:57 2010 From: bussieremaillist at gmail.com (bussiere maillist) Date: Wed, 8 Sep 2010 01:37:57 +0200 Subject: include a file in a python program In-Reply-To: References: Message-ID: Thanks all for your response i will try out this week, you have give me sufficient hint. Thanks again. Bussiere On Mon, Sep 6, 2010 at 9:50 AM, Niklasro(.appspot) wrote: > On Sep 5, 10:57?pm, bussiere bussiere wrote: >> i've got a python.txt that contain python and it must stay as it (python.txt) >> >> how can i include it in my program ? >> import python.txt doesn't work >> is there a way : >> a) to make an include("python.txt") >> b) tell him to treat .txt as .py file that i can make an import python ? >> i'am using python3 >> Regards >> Bussiere >> fan of torchwood >> Google Fan boy > > You can do it with tkinter to also enable GUI. > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin.kaplan at case.edu Tue Sep 7 19:38:13 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 7 Sep 2010 19:38:13 -0400 Subject: The Samurai Principle In-Reply-To: <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> <4c86b6cc$0$10872$426a74cc@news.free.fr> <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 6:20 PM, Phlip wrote: > On Sep 7, 1:06?pm, Bruno Desthuilliers > wrote: > >> try: >> ? ?return Model.objects.get(pk=42) >> except Model.DoesNotExist: >> ? ?return sentinel > > Visual Basic Classic had a Collection Class, which worked essentially > like a real language's Hash, Map, or Dict. > > Except - it had no operation to test membership. It also could not > enumerate by key and value (which would be 'for k,v in dict.items()'). > To test for membership, you _had_ to catch an exception - using VB's > tragically clumsy exception model. > > Hours of fun. That leads us to this topic: > > http://www.google.com/search?q=don't+use+exceptions+for+normal+control+flow > -- An experienced C programmer can program C in any language, but that doesn't mean it's a good idea to. When you're using a language, you should use the style that the language emphasizes. While you shouldn't use exceptions for control flow in C++, Java, or C#, there's nothing wrong with using them as such in Python. From bussiere at gmail.com Tue Sep 7 19:47:47 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Wed, 8 Sep 2010 01:47:47 +0200 Subject: include a file in a python program Message-ID: Thanks all for your response i will try out this week, you have give me sufficient hints. Thanks again. Bussiere From jtgalyon at gmail.com Tue Sep 7 19:53:30 2010 From: jtgalyon at gmail.com (Jason Galyon) Date: Tue, 07 Sep 2010 18:53:30 -0500 Subject: (Webinar) Connecting the Dots: US SEC, ABS Mandates, Financial Modeling and Python In-Reply-To: <4C86A9B1.10203@activestate.com> References: <4C86A9B1.10203@activestate.com> Message-ID: <1283903610.6863.2.camel@rivendell.clangalyon.com> Will this webcast/webinar perform on Linux? Jason On Tue, 2010-09-07 at 14:08 -0700, Kendra Penrose wrote: > Connecting the Dots: US SEC, ABS Mandates, Financial Modeling and Python > > Date: Wednesday September 22, 2010python-announce-list at python.org, > Time: 10:00am PST/1:00pm EST/ 17:00 UTC > Space is limited so register now at > https://www1.gotomeeting.com/register/151429928 > > Join us for a webinar co-hosted by Ann Rutledge, R&R Consulting, and > Diane Mueller, ActiveState, focused on the recent US SEC regulation, ABS > Mandates, Financial Modeling and Python. > > Recently, the US SEC published a proposal (33-9117) covering a series of > new initiatives to address the current lack of transparency of > asset-backed securities (ABS). This new series of SEC proposed > initiatives are a way of putting "teeth" into Reg AB that would give the > SEC (and the market) enough data to police and prevent events like the > recent subprime crisis. > > In this webinar, Ann Rutledge and Diane Mueller will discuss a new key > technical requirement in the SEC proposal; the provision of a Python > computer program and the market data required to properly monitor and > analyse these complex ABS transactions. The role of the proposed program > is to enable the capture of all the complicated terms of an ABS deal in > code that can be used to analyze the cash flows in each deal and how the > returns will get split up between different parties. Currently, > investors, fund managers, and investment managers receive a complex, > textual description of this information in the prospectus, which makes > it difficult to perform or visualize a rigorous quantitative or if-then > analysis of the asset-backed securities. > > By attending this webinar you will learn: > * some historical challenges regarding regulation of the asset-backed > securities (ABS) market > * technical benefits of Python and XML for capturing essential financial > information in ABS transactions > * about opportunities for collaboration between between regulators, > accounting standards bodies, and the open source software community > > If you are in the finance industry and are affected by the new SEC > regulations, you don't want to miss this webinar! > > Register at https://www1.gotomeeting.com/register/151429928 From ben+python at benfinney.id.au Tue Sep 7 20:07:19 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Sep 2010 10:07:19 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> Message-ID: <87aantayiw.fsf@benfinney.id.au> Baba writes: > However the following Wiki excerpt seems to go in my direction: No, it doesn't. It advises that people show kindness; as I've been arguing, that's exactly what you were shown. You haven't shown how the information being imparted could have been fully imparted in a way that's kinder, nor that it would be reasonable to do so. To put it another way: if you feel offended by an utterance, then insufficient kindness on the part of the speaker is not the only explanation. -- \ ?Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.? ?Anthony Taylor | Ben Finney From tjreedy at udel.edu Tue Sep 7 20:19:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 20:19:02 -0400 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de><4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: On 9/7/2010 6:00 AM, BartC wrote: >> Why should it? But if you want it, you can do it: >> >> xrange = range >> >> There, that wasn't hard, was it? > > I think I just learned more about Python than from months of reading this > group. > > So 'range' is just a class like any other. And that a class is something > you > can blithely copy from one variable to another. There is no copying of the class object. A new name is associated with the object. Any object can be given any number of names (aliases) that refer to the one and same object. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 7 20:43:04 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 20:43:04 -0400 Subject: Bug in Python 2.6 urlencode In-Reply-To: <4c868c2d$0$1581$742ec2ed@news.sonic.net> References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> Message-ID: On 9/7/2010 3:02 PM, John Nagle wrote: > There's a bug in Python 2.6's "urllib.urlencode". If you pass > in a Unicode character outside the ASCII range, instead of it > being encoded properly, an exception is raised. > > File "C:\python26\lib\urllib.py", line 1267, in urlencode > v = quote_plus(str(v)) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in > position 0: ordinal not in range(128) > > This will probably work in 3.x, because there, "str" converts > to Unicode, and quote_plus can handle Unicode. This is one of > those legacy bugs left from the pre-Unicode era. > > There's a workaround. Call urllib.urlencode with a second > parameter of 1. This turns on the optional feature of > accepting tuples in the argument to be encoded, and the > code goes through a newer code path that works. > > Is it worth reporting 2.x bugs any more? Or are we in the > version suckage period, where version N is abandonware and > version N+1 isn't deployable yet. You may report 2.7 bugs, but please verify that the behavior is a bug in 2.7. However, bugs that have been fixed by the switch to switch to unicode for text are unlikely to be fixed a second time in 2.7. You might suggest an enhancement to the doc for urlencode if that workaround is not clear. Or perhaps that workaround suggests that in this case, a fix would not be too difficult, and you can supply a patch. The basic deployment problem is that people who want to use unicode text also want to use libraries that have not been ported to use unicode text. That is the major issue for many porting projects. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 7 20:51:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 20:51:42 -0400 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On 9/7/2010 2:53 PM, Phlip wrote: > They are for situations which the caller should care not to handle. Python is simply not designed that way. Exception raising and catching is a common flow-control method in Python. If you cannot stand that, Python is not for you. -- Terry Jan Reedy From ldo at geek-central.gen.new_zealand Tue Sep 7 21:23:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 08 Sep 2010 13:23:22 +1200 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: In message <74587da9-8861-4400-bbd7-1ea4f8182bb1 at l38g2000pro.googlegroups.com>, Phlip wrote: > Pythonistas: > > The "Samurai Principle" says to return victorious, or not at all. This > is why django.db wisely throws an exception, instead of simply > returning None, if it encounters a "record not found". Does catching the exception not defeat the ?Samurai Principle?? From greg.ewing at canterbury.ac.nz Tue Sep 7 21:40:48 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Sep 2010 13:40:48 +1200 Subject: what should __iter__ return? In-Reply-To: References: Message-ID: <8eo7tiF10cU1@mid.individual.net> Thomas Jollans wrote: > Hmm. Modifying an object while iterating over it isn't a great idea, ever: I wouldn't say never. Algorithms that calculate some kind of transitive closure can be expressed rather neatly by appending items to a list being iterated over. You can accommodate that kind of thing by writing the iterator like this: def __iter__(self): i = 0 while i < len(self): yield self[i] i += 1 -- Greg From bartc at freeuk.com Tue Sep 7 21:45:43 2010 From: bartc at freeuk.com (BartC) Date: Wed, 8 Sep 2010 02:45:43 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: "David Cournapeau" wrote in message news:mailman.546.1283897932.29448.python-list at python.org... > On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: > >> >> One order of magnitude (say 10-20x slower) wouldn't be so bad. That's >> what >> you might expect for a dynamically typed, interpreted language. > > 10/20x slower than C is only reached by extremely well optimized > dynamic languages. It would be a tremendous achievement. If that's Well, that is what I do (mess around with languages and stuff). Getting back to the OP's code again (trivial and pointless as it might seem), I got these results: C (gcc 3.4.5 -O3) 0.8 secs C (DMC-o) 2.3 secs C (lccwin32 -O) 2.9 secs My last interpreter 12.6 secs dynamically typed language (or 4.5 secs when told the type of 'a'; but that's cheating a little..) Python 3 177.0 secs That's why I was questioning the latter's performance in for-loops. But now that I know a bit more about Python (having dynamic everything) the figure is not so surprising. However, it's still slow! > what you are after, look at LUA with its JIT, or scheme + stalin. I've seen LuaJIT in action. It's timing for this test is 1.5 secs: forget being only 10x slower than C, it's faster than some C versions! (I'm sure it must be cheating somewhere...) -- bartc From python at mrabarnett.plus.com Tue Sep 7 22:07:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Sep 2010 03:07:09 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <4C86EFCD.1050009@mrabarnett.plus.com> On 08/09/2010 02:45, BartC wrote: > > > "David Cournapeau" wrote in message > news:mailman.546.1283897932.29448.python-list at python.org... >> On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: >> >>> >>> One order of magnitude (say 10-20x slower) wouldn't be so bad. That's >>> what >>> you might expect for a dynamically typed, interpreted language. >> >> 10/20x slower than C is only reached by extremely well optimized >> dynamic languages. It would be a tremendous achievement. If that's > > Well, that is what I do (mess around with languages and stuff). > > Getting back to the OP's code again (trivial and pointless as it might > seem), I got these results: > > C (gcc 3.4.5 -O3) 0.8 secs > C (DMC-o) 2.3 secs > C (lccwin32 -O) 2.9 secs > My last interpreter 12.6 secs dynamically typed language > (or 4.5 secs when told the type of 'a'; but that's > cheating a little..) > Python 3 177.0 secs > > That's why I was questioning the latter's performance in for-loops. But now > that I know a bit more about Python (having dynamic everything) the figure > is not so surprising. However, it's still slow! > >> what you are after, look at LUA with its JIT, or scheme + stalin. > > I've seen LuaJIT in action. It's timing for this test is 1.5 secs: > forget being only 10x slower than C, it's faster than some C versions! > (I'm sure it must be cheating somewhere...) > If you'd like to direct your skills to making CPython faster, without diminishing its flexibility, I'm sure it'll be welcomed. The source is all public, you know! :-) From nagle at animats.com Tue Sep 7 23:21:37 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Sep 2010 20:21:37 -0700 Subject: Bug in Python 2.6 urlencode In-Reply-To: References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> Message-ID: <4c87013f$0$1625$742ec2ed@news.sonic.net> On 9/7/2010 5:43 PM, Terry Reedy wrote: > On 9/7/2010 3:02 PM, John Nagle wrote: >> There's a bug in Python 2.6's "urllib.urlencode". If you pass >> in a Unicode character outside the ASCII range, instead of it >> being encoded properly, an exception is raised. >> >> File "C:\python26\lib\urllib.py", line 1267, in urlencode >> v = quote_plus(str(v)) >> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in >> position 0: ordinal not in range(128) >> >> This will probably work in 3.x, because there, "str" converts >> to Unicode, and quote_plus can handle Unicode. This is one of >> those legacy bugs left from the pre-Unicode era. >> >> There's a workaround. Call urllib.urlencode with a second >> parameter of 1. This turns on the optional feature of >> accepting tuples in the argument to be encoded, and the >> code goes through a newer code path that works. >> >> Is it worth reporting 2.x bugs any more? Or are we in the >> version suckage period, where version N is abandonware and >> version N+1 isn't deployable yet. > > You may report 2.7 bugs, but please verify that the behavior is a bug in > 2.7. However, bugs that have been fixed by the switch to switch to > unicode for text are unlikely to be fixed a second time in 2.7. You > might suggest an enhancement to the doc for urlencode if that workaround > is not clear. Or perhaps that workaround suggests that in this case, a > fix would not be too difficult, and you can supply a patch. > > The basic deployment problem is that people who want to use unicode text > also want to use libraries that have not been ported to use unicode > text. That is the major issue for many porting projects. In other words, we're in the version suckage period. John Nagle From greg.ewing at canterbury.ac.nz Tue Sep 7 23:31:11 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Sep 2010 15:31:11 +1200 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: <8eoeceFu9qU1@mid.individual.net> Lawrence D'Oliveiro wrote: > Does catching the exception not defeat the ?Samurai Principle?? Not if it lets you turn defeat into victory. Or redefine victory so that it includes defeat. Or something. -- Greg From phlip2005 at gmail.com Tue Sep 7 23:35:45 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 20:35:45 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> On Sep 7, 6:23?pm, Lawrence D'Oliveiro wrote: > Does catching the exception not defeat the ?Samurai Principle?? Read my comic: http://c2.com/cgi/wiki?SamuraiPrinciple Exceptions are very dangerous by themselves, because if you don't trap them just right they can cause side-effects. They are worse than GOTO. From greg.ewing at canterbury.ac.nz Tue Sep 7 23:37:40 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Sep 2010 15:37:40 +1200 Subject: Queue cleanup In-Reply-To: References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> Message-ID: <8eoeovF1atU1@mid.individual.net> Lawrence D'Oliveiro wrote: > But alone of all of these, garbage collection still remains just as costly > to implement as ever. That should tell you something about how poorly it > matches the characteristics of modern computing hardware. So maybe we need to redesign the hardware. Perhaps reference counts could be stored in their own special area of memory, updated in parallel with main memory accesses so that they don't slow anything down. Make it multiported so that all your cores can access it at once without locking. Maybe even build it out of counters instead of registers, so there's no data bus, only an address bus and inc/dec control lines. -- Greg From phlip2005 at gmail.com Tue Sep 7 23:38:14 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 20:38:14 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <642cd655-ade1-40d9-8d02-66ca9354d3c3@q21g2000prm.googlegroups.com> On Sep 7, 5:51?pm, Terry Reedy wrote: > On 9/7/2010 2:53 PM, Phlip wrote: > > > They are for situations which the caller should care not to handle. > > Python is simply not designed that way. Exception raising and catching > is a common flow-control method in Python. If you cannot stand that, > Python is not for you. While I'm at it, I'm going to log into comp.lang.java.misc and explain to everyone why static typing is overkill, and implementation inheritance is good for you. Everyone gets defensive about the design flaws in their own language. But the django.db situation is not even a design flaw; just a misinterpretation of the Samurai Principle. int('yo') shall throw an exception, but a missing record could be the result you were looking for, so it's not exceptional. From phlip2005 at gmail.com Tue Sep 7 23:44:14 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 20:44:14 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> <4c86b6cc$0$10872$426a74cc@news.free.fr> <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> Message-ID: <663aa068-437f-4d79-9b05-c86c8ff16d54@m35g2000prn.googlegroups.com> On Sep 7, 4:38?pm, Benjamin Kaplan wrote: > When you're using a language, you should use the style that the > language emphasizes. You mean like this? uri = reverse('my_uri_name', kwargs=dict(pk=record.pk)) That 'kwargs' there is ... a lapse of judgement. It is exposing a technical detail (the "keyword arguments") instead of naming the variable after its intent. It should be 'params=', at least, to match the URI standards. I'm just sayin'... From ben+python at benfinney.id.au Wed Sep 8 00:08:04 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Sep 2010 14:08:04 +1000 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> <4c86b6cc$0$10872$426a74cc@news.free.fr> <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> <663aa068-437f-4d79-9b05-c86c8ff16d54@m35g2000prn.googlegroups.com> Message-ID: <8762ygc1y3.fsf@benfinney.id.au> Phlip writes: > On Sep 7, 4:38?pm, Benjamin Kaplan wrote: > > > When you're using a language, you should use the style that the > > language emphasizes. > > You mean like this? > > uri = reverse('my_uri_name', kwargs=dict(pk=record.pk)) Do you think that style is emphasised by Python? What gives you that impression? -- \ ?Program testing can be a very effective way to show the | `\ presence of bugs, but is hopelessly inadequate for showing | _o__) their absence.? ?Edsger W. Dijkstra | Ben Finney From stefan_ml at behnel.de Wed Sep 8 00:48:16 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 08 Sep 2010 06:48:16 +0200 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: BartC, 08.09.2010 03:45: > Getting back to the OP's code again (trivial and pointless as it might > seem), I got these results: > > C (gcc 3.4.5 -O3) 0.8 secs > C (DMC-o) 2.3 secs > C (lccwin32 -O) 2.9 secs >[...] > I've seen LuaJIT in action. It's timing for this test is 1.5 secs: > forget being only 10x slower than C, it's faster than some C versions! > (I'm sure it must be cheating somewhere...) Sure it does. C is statically compiled, while LuaJIT is a JIT compiler. It unjustly uses *runtime* information to compile the code. You can get a similar advantage with some C compilers by using profile based optimisation. BTW, I wonder why the code takes a whole 0.8 seconds to run in your gcc test. Maybe you should use a newer GCC version. It shouldn't take more than a couple of milliseconds (for program startup, OS calls, etc.), given that the output is a constant. Stefan From eliben at gmail.com Wed Sep 8 00:53:04 2010 From: eliben at gmail.com (Eli Bendersky) Date: Wed, 8 Sep 2010 07:53:04 +0300 Subject: Bit fields in python? In-Reply-To: References: Message-ID: > > > I'm trying to rewrite a c program in python & encountered several problems. > I have some data structures in my c program like below: > > typedef struct > { > unsigned short size; > > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsigned short var_a3:2; > unsigned short var_a4:2; > > unsigned int var_a5; > }structa; > > typedef struct > { > unsigned short size; > > unsigned char reserved:4; > unsigned char var_b1:1; > unsigned char var_b2:1; > unsigned char var_b3:1; > unsigned char var_b4:1; > > structa var_structa; > }structb; > > I tried to code the above in python but only got this far: > > class StructA(object): > def __init__(self, size=0) > self.size = size > > class StructB(object): > def __init__(self, size=0) > > Any equivalent for c data structures & bit fields in python? And how do I > define var_structa (in structb) in python? > > Bitfields are most commonly used for extreme space optimization - i.e. shoving several variables and flags with carefully limited ranges into a single work. In Python you rarely work this way (where such an optimization is warranted, Python isn't the best tool for the job). However, as in your use case, it is sometimes needed in Python in order to communicate with other devices over the network or some other link. In my work with Python and embedded devices I've found the construct library (http://construct.wikispaces.com/) very useful. It allows to you very easily define complex formats for frames/messages on the bit and byte level. The idea is to use construct to encode and decode messages being sent to an embedded device. It works great. If you have further questions about this approach, feel free to ask. Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Wed Sep 8 00:56:47 2010 From: nad at acm.org (Ned Deily) Date: Tue, 07 Sep 2010 21:56:47 -0700 Subject: Bug in Python 2.6 urlencode References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> <4c87013f$0$1625$742ec2ed@news.sonic.net> Message-ID: In article <4c87013f$0$1625$742ec2ed at news.sonic.net>, John Nagle wrote: > On 9/7/2010 5:43 PM, Terry Reedy wrote: > > On 9/7/2010 3:02 PM, John Nagle wrote: > >> There's a bug in Python 2.6's "urllib.urlencode". If you pass > >> in a Unicode character outside the ASCII range, instead of it > >> being encoded properly, an exception is raised. > >> > >> File "C:\python26\lib\urllib.py", line 1267, in urlencode > >> v = quote_plus(str(v)) > >> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in > >> position 0: ordinal not in range(128) > >> > >> This will probably work in 3.x, because there, "str" converts > >> to Unicode, and quote_plus can handle Unicode. This is one of > >> those legacy bugs left from the pre-Unicode era. > >> > >> There's a workaround. Call urllib.urlencode with a second > >> parameter of 1. This turns on the optional feature of > >> accepting tuples in the argument to be encoded, and the > >> code goes through a newer code path that works. > >> > >> Is it worth reporting 2.x bugs any more? Or are we in the > >> version suckage period, where version N is abandonware and > >> version N+1 isn't deployable yet. > > > > You may report 2.7 bugs, but please verify that the behavior is a bug in > > 2.7. However, bugs that have been fixed by the switch to switch to > > unicode for text are unlikely to be fixed a second time in 2.7. You > > might suggest an enhancement to the doc for urlencode if that workaround > > is not clear. Or perhaps that workaround suggests that in this case, a > > fix would not be too difficult, and you can supply a patch. > > > > The basic deployment problem is that people who want to use unicode text > > also want to use libraries that have not been ported to use unicode > > text. That is the major issue for many porting projects. > > In other words, we're in the version suckage period. It took me all of one minute to find where a similar issue was reported previously (http://bugs.python.org/issue1349732). One of the comments on the issue explains how to use the "doseq" form and an explicit encode to handle Unicode items. I don't see where that part of the suggestion made it into the documentation. I'm sure if you make a specific doc change suggestion, it will be incorporated into the 2.7 docs. If you think a code change is needed, suggest a specific patch. -- Ned Deily, nad at acm.org From pdlemper at earthlink.net Wed Sep 8 01:09:59 2010 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Wed, 08 Sep 2010 00:09:59 -0500 Subject: compare dictionaries References: Message-ID: On Tue, 7 Sep 2010 12:46:36 -0700 (PDT), Baba wrote: >level: beginner > >word= 'even' >dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > >i want to know if word is entirely composed of letters in dict2 > >my approach: >step 1 : convert word to dictionary(dict1) > >step2: >for k in dict1.keys(): > if k in dict2: > if dict1[k] != dict2[k]: > return False > return True > return False > return True > Assign letters to their corresponding primes with the following function - def alphaprime(c) : if c == 'a' return 2 elif c == 'b' return 3 elif c == 'c' return 5 ... elif c == 'y' return 97 elif c == 'z' return 101 else : return 0 Using above calculate a composite for the letters in the dictionary. Of course begin with 1 and multiply by the associated prime for each letter and repeat for each recurrence of that letter. Call this dictionarycomposite. Do the same for the word, parsing sequentially and multiplying by the prime for each letter. Call this wordcomposite. Now if dictionarycomposite % wordcomposite == 0 the word can be spelled with the letters in the dictionary. I used this in a word game : works fast. The Fundamental Theorum of Arithmetic may apply. Dave WB3DWE From nagle at animats.com Wed Sep 8 01:17:38 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Sep 2010 22:17:38 -0700 Subject: Bug in Python 2.6 urlencode In-Reply-To: References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> <4c87013f$0$1625$742ec2ed@news.sonic.net> Message-ID: <4c871c6f$0$1584$742ec2ed@news.sonic.net> On 9/7/2010 9:56 PM, Ned Deily wrote: > In article<4c87013f$0$1625$742ec2ed at news.sonic.net>, > John Nagle wrote: >> On 9/7/2010 5:43 PM, Terry Reedy wrote: >>> On 9/7/2010 3:02 PM, John Nagle wrote: >>>> There's a bug in Python 2.6's "urllib.urlencode". If you pass >>>> in a Unicode character outside the ASCII range, instead of it >>>> being encoded properly, an exception is raised. .... >> >> In other words, we're in the version suckage period. > > It took me all of one minute to find where a similar issue was reported > previously (http://bugs.python.org/issue1349732). One of the comments > on the issue explains how to use the "doseq" form and an explicit encode > to handle Unicode items. I don't see where that part of the suggestion > made it into the documentation. I'm sure if you make a specific doc > change suggestion, it will be incorporated into the 2.7 docs. If you > think a code change is needed, suggest a specific patch. That's a very funny bug report. The report was created back in 2005: Title: urllib.urlencode provides two features in one param Type: feature request Stage: committed/rejected It wasn't listed as an actual bug. On 2005-12-29, "Mike Brown" writes "However, I was unable to reproduce your observation that doseq=0 results in urlencode not knowing how to handle unicode. The object is just passed to str()." This was back in the Python 2.4 days, when "str" restriction to ASCII wasn't enforced. Perhaps the original reporter and the developer were using different versions. Five years later (!) Terry J. Reedy writes '"put something somewhere" will not get action.' In July 2010, Senthil Kumaran writes "This was fixed as part of Issue8788. Closing this." Issue 8788 is a documentation fix only. John Nagle From kurianmthayil at gmail.com Wed Sep 8 02:02:10 2010 From: kurianmthayil at gmail.com (Kurian Thayil) Date: Wed, 8 Sep 2010 11:32:10 +0530 Subject: mail sending -- smtplib In-Reply-To: References: Message-ID: Got it fixed. It was a very silly mistake. mssg variable had each line with indent. Removed the indent and it worked. Regards, Kurian Thayil. On Tue, Sep 7, 2010 at 9:57 AM, Kurian Thayil wrote: > Hi All, > > I am a newbie in python. Just 2-3 days old wanting to learn this amazing > programming language. I was trying to send mails using smtplib module, so > did some google and found a code snippet. The mail gets sent, but doesn't > come in the right format when a for-loop is introduced (Not MIME standard?). > Without the for-loop the script works fine. Can anyone advice? > * > #!/usr/bin/env python > > import smtplib > > for i in range(1,5): > print "I is ",i > fromaddr='kurianmthayil at gmail.com' > toaddr='kurianmthayil at gmail.com' > print toaddr > mssg="""From: Kurian Thayil > To: Kurian Thayil > MIME-Version: 1.0 > Content-type: text/html > Subject: 12345 -- Reloaded :) > > Hey dude.. how are you???? > >



> Regards, >

> Kurian > """ > print "message is ",mssg > > smail=smtplib.SMTP('smtp.gmail.com',587) > > smail.ehlo() > smail.starttls() > smail.ehlo() > smail.login(fromaddr,'***********') > > smail.sendmail(fromaddr,toaddr,mssg) > print "Over" > * > > Regards, > > Kurian Thayil. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Sep 8 02:32:48 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Sep 2010 00:32:48 -0600 Subject: The Samurai Principle In-Reply-To: <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 9:35 PM, Phlip wrote: > Exceptions are very dangerous by themselves, because if you don't trap > them just right they can cause side-effects. And returning None on failure is dangerous, because if the programmer does not take care to handle that case, the program may attempt to regard it as actual data. This in turn results in hard-to-track bugs elsewhere in the program, a fate much worse than an unhandled exception. It's better to fail noisily than to fail silently. > They are worse than GOTO. This assertion is questionable at best. Exceptions are structured; goto is unstructured, giving you much more rope to hang yourself with. From sajuptpm at gmail.com Wed Sep 8 02:39:13 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Tue, 7 Sep 2010 23:39:13 -0700 (PDT) Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: <7d2b1ed5-8cdd-4dcd-a8d0-065fda18e895@u5g2000prn.googlegroups.com> Detailed Description --------------------- l1 = [] l2 = [ ((3,8),(1,2)), ((1,3),(1,7)), ((7,0),(1,8)), ((4,2),(1,2)), ((2,9),(9,1)) ] I need to take each item from l2 and insert into l1 with first element(column)(3,1,7,4,2) sorted in ascending order and second element(column)(8,3,0,2,9) sorted in descending order. #SORTING for k in l2: flag=True for i, v in enumerate(l1): if v <= k: l1.insert(i,k) flag = False break if flag: l1.append(k) for a in l1: print a output ------- ((7, 0), (1, 8)) ((4, 2), (1, 2)) ((3, 8), (1, 2)) ((2, 9), (9, 1)) ((1, 3), (1, 7)) This will not give l1 with first element(column)(3,1,7,4,2) sorted in ascending order and second element(column)(8,3,0,2,9) sorted in descending order. -------------- I added a -ve signe to all first elements l2 = [ ((-3,8),(1,2)), ((-1,3),(1,7)), ((-7,0),(1,8)), ((-4,2),(1,2)), ((-2,9),(9,1)) ] #SORTING for k in l2: flag=True for i, v in enumerate(l1): if v <= k: l1.insert(i,k) flag = False break if flag: l1.append(k) for a in l1: print a output ------- ((-1, 3), (1, 7)) ((-2, 9), (9, 1)) ((-3, 8), (1, 2)) ((-4, 2), (1, 2)) ((-7, 0), (1, 8)) Now output is similar to first elements asc and second elements desc.But the problem is the -ve sign, i dont need that. Have any other method to do it?? From eckhardt at satorlaser.com Wed Sep 8 02:39:39 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 08 Sep 2010 08:39:39 +0200 Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> <109hl7-ao8.ln1@satorlaser.homedns.org> <7bbe7204-f7dd-4054-97bd-7973ade72dc7@n19g2000prf.googlegroups.com> Message-ID: sajuptpm wrote: > i want to find the loaded machine based on cpu and mem and desk > utilization by changing this order. > > I created a UI using that i can change the order of item in the tuple. > But the problem is asc and desc sorting How about only changing the order in which the elements are displayed? In other words, the internal data is fixed, but both the sorting of the list and the order in which the parts of the records are displayed can be changed. Just my 2c Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From slaunger at gmail.com Wed Sep 8 02:55:48 2010 From: slaunger at gmail.com (Kim Hansen) Date: Wed, 8 Sep 2010 08:55:48 +0200 Subject: LZO decompressing with Python 2.5x on Windows for C dummies Message-ID: Hi list, I have some binary data files which contain embedded LZO compressed payloads mixed with normal C-struct like headers. I would like to have the ability to LZO decompress these payloads using a python 2.5.x script. I was hoping that there was an up-to-date plug-and-play LZO library available for Windows somewhere. However, I have not managed to find such a one. The closest I have gotten is on the official LZO home page: http://www.oberhumer.com/opensource/lzo/ There is a link to some old LZO 1.08 bindings for Python 2.2 there as a tar.gz (released back in 2002!) http://www.oberhumer.com/opensource/lzo/download/LZO-v1/python-lzo-1.08.tar.gz I managed to unpack that using the python tarfile module (very handy for the purpose) In essence, the tarball contains a setup.py lzomodule.c Makefile and some documentation It does not contain anything that appears to be binaries for Windows. The instructions indicate that I am supposed to build it myself using the Makefile. I do not have make nor a C-compiler installed, and I fear that if I were to compile it, it would be a very tedious process for me, and I would rather like to avoid it if at all possible. Concerning the Windows LZO binaries I have previously struggled with pytables and using LZO on Windows with HDF5 files, and in relation to that Francesc Alted was so kind to build Windows LZO ver. 1.08 binaries as discussed here http://www.pytables.org/moin/FAQ#A.5BWindows.5DCan.27tfindLZObinariesforWindows and available here as a zip file http://www.pytables.org/download/lzo-win Amongst others, this zip file has a Gwin32\bin\lzo1.dll file. By copying that to the ptables filder in my python25 installation I have managed to get LZO working with pytables. Getting back to the python bindings, the setup.py does contain a section, which indicates that it adresses a Windows platform also: ... if sys.platform == "win32": # Windows users have to configure the LZO_DIR path parameter to match # their LZO source installation. The path set here is just an example # and thus unlikely to match your installation. LZO_DIR = r"c:\src\lzo-1.08" include_dirs.append(os.path.join(CURL_DIR, "include")) extra_objects.append(os.path.join(CURL_DIR, "lzo.lib")) ... If I were clever enough I now guess I should be able to unpack the pytables lzo Windows binaries to some suitable place (any recommendations?) and modify the setup.py such that it correctly "binds the dll" (this is black magic to me). One thing, which concerns me, is that a file lzo.lib is mentioned in the current setup.py, but there is not a file with that name in the GnuWin32 zip zip file from Francesc in the lib folder of the zip I do find two lib files.: liblzo.lib liblzo-bcc.lib but are any of these related to the lzo.lib mentioned in the setup.py? It does not help that I have a very poor understanding of how Python binds to native libraries, nor how things should be "installed" manually. My next question, if somehow someone is able to guide me a little in the process, then how do I use the library once available. The README indicates that I should use the internal Python documentation- So I guess i should just open an IPython shell do an import lzo? and then tab on lzo. and see what is available? Sorry for the long post. Kind regards, Kim -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Sep 8 02:57:52 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Sep 2010 00:57:52 -0600 Subject: The Samurai Principle In-Reply-To: <642cd655-ade1-40d9-8d02-66ca9354d3c3@q21g2000prm.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <642cd655-ade1-40d9-8d02-66ca9354d3c3@q21g2000prm.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 9:38 PM, Phlip wrote: > Everyone gets defensive about the design flaws in their own language. > But the django.db situation is not even a design flaw; just a > misinterpretation of the Samurai Principle. int('yo') shall throw an > exception, but a missing record could be the result you were looking > for, so it's not exceptional. I consider it exceptional because it breaks the rule that Model.objects.get(...) returns an instance of Model. If it can also return None, then this needs to be checked for every time the method is called, because None does not implement the Model interface and will break if you try to use it like that. You're still doing exception handling; you're just doing it with an if instead of a try-except. I prefer to do exception handling in a block clearly marked as an exception handler. Out of curiosity, would you also regard the case where two matching records are found instead of one as not exceptional? After all, it could be the result you were looking for. What should QuerySet.get return in that case, if it doesn't raise an exception? From __peter__ at web.de Wed Sep 8 04:08:30 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 08 Sep 2010 10:08:30 +0200 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> <7d2b1ed5-8cdd-4dcd-a8d0-065fda18e895@u5g2000prn.googlegroups.com> Message-ID: sajuptpm wrote: > Now output is similar to first elements asc and second elements > desc.But the problem is the -ve sign, i dont need that. > > Have any other method to do it?? Sort twice: >>> for item in items: ... print item ... ('adams', 'anne') ('miller', 'arnold') ('miller', 'bill') ('adams', 'berta') ('adams', 'charlotte') ('miller', 'thomas') >>> items.sort(key=lambda x: x[1], reverse=True) >>> items.sort(key=lambda x: x[0]) >>> for item in items: ... print item ... ('adams', 'charlotte') ('adams', 'berta') ('adams', 'anne') ('miller', 'thomas') ('miller', 'bill') ('miller', 'arnold') See? First column ascending, second column descending within groups of rows with equal first column. Peter From tanja2late at googlemail.com Wed Sep 8 04:51:12 2010 From: tanja2late at googlemail.com (Tanje Toolate) Date: Wed, 8 Sep 2010 01:51:12 -0700 (PDT) Subject: console-editor written in python Message-ID: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> hi there, greetings. i am looking for a small, console-based (opensource) texteditor, written in python (or as shellscript!), but i'm not finding something usable. very find would be emacs-keybindings ... dank u well, tanja From raoulbia at gmail.com Wed Sep 8 06:04:24 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 8 Sep 2010 03:04:24 -0700 (PDT) Subject: mutate dictionary or list References: <87zkvt4p8v.fsf@web.de> <87pqwpboh8.fsf@benfinney.id.au> Message-ID: <6ff00c38-35a9-427e-937a-3f3cb99c2c6c@i5g2000yqe.googlegroups.com> On 7 sep, 16:46, Ben Finney wrote: > de... at web.de writes: > > Objects can be mutable or immutable. For example, in Python, integers, > > strings, floats and tuples are immutable. That means that you can't > > change their value. > > Yes. Importantly, wherever you see code that you *think* is changing the > value of an immutable object, you're thinking incorrectly. (There's no > shame in that; other languages give us preconceptions that can be hard > to shake off.) > > The only way to get a different value from an integer object is to ask > Python for a different integer object; the original is unchanged. The > same goes for tuples, strings, and all the other immutable types. > > > Mutable objects OTOH can be changed. > > [?] > > Some good articles to explain Python's object model: > > ? ? ? > ? ? ? > > -- > ?\ ? ? ? ? ? ? ?We can't depend for the long run on distinguishing one | > ? `\ ? ? ? ? bitstream from another in order to figure out which rules | > _o__) ? ? ? ? ? ? ? apply.? ?Eben Moglen, _Anarchism Triumphant_, 1999 | > Ben Finney Thanks all for feedback! Baba From raoulbia at gmail.com Wed Sep 8 06:30:00 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 8 Sep 2010 03:30:00 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> Message-ID: <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> On 8 sep, 02:07, Ben Finney wrote: > Baba writes: > > However the following Wiki excerpt seems to go in my direction: > > No, it doesn't. It advises that people show kindness; as I've been > arguing, that's exactly what you were shown. You haven't shown how the > information being imparted could have been fully imparted in a way > that's kinder, nor that it would be reasonable to do so. > > To put it another way: if you feel offended by an utterance, then > insufficient kindness on the part of the speaker is not the only > explanation. > > -- > ?\ ? ? ??Software patents provide one more means of controlling access | > ? `\ ? ? ?to information. They are the tool of choice for the internet | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? highwayman.? ?Anthony Taylor | > Ben Finney Hi Ben, Thanks for your feedback. My question is: Who owns this forum? If we all do then we are allowed to post questions that are simple and that could otherwise be answered by doing research. It is just unfriendly to tell someone to go and look it up by themselves. Who is licensed to judge what can and cannot be posted as a question? A teacher of mine used to say: "There are no stupid questions, there are only stupid answers." It is arrogant to tell someone in a Forum to "look it up yourself ,this question is too basic". Can you not understand that accessing a file can seem daunting at first? Believe me, documentation can be offputting too when you only start with programming. Per se the beauty of forums like these is that there are human beings willing to make such tasks as finding out how to access a text file less 'scary'. Whoever thinks he or she has a license to tell someone to look up the answer by themselves should think again. I reckon the only license we have is not to answer at all. I acknowledge that Benjamin pointed me to the right place to find an answer but somehow the "Please do us a favour" sounded bit arrogant, as if he owned the place (same goes for all those who sided against me here: do you own this forum?)...i'd be glad if there was a python for beginners forum but in the meantime i have to say i find it awesome to have this forum to get help. It makes a BIG difference. So sorry if i upset anyone, we all have our opinions and get carried away and can be stubborn, i DO respect everyone in this forum and i think it goes bothways. I've learned a few things in this post... So now, to use Benjamin words: Please do me a favour and let's move on :) Baba Baba From laicheng_kwan at innomedia.com.sg Wed Sep 8 06:43:20 2010 From: laicheng_kwan at innomedia.com.sg (Kwan Lai Cheng) Date: Wed, 8 Sep 2010 18:43:20 +0800 Subject: Bit fields in python? References: Message-ID: <2DB4DD760DFD46EBA608F9D121999F89@cs0403293> Thanks everyone for all the suggestions! New to python, so reading up on the struct module & Construct library now, hope to get my problem fixed soon. ----- Original Message ----- Bitfields are most commonly used for extreme space optimization - i.e. shoving several variables and flags with carefully limited ranges into a single work. In Python you rarely work this way (where such an optimization is warranted, Python isn't the best tool for the job). However, as in your use case, it is sometimes needed in Python in order to communicate with other devices over the network or some other link. In my work with Python and embedded devices I've found the construct library (http://construct.wikispaces.com/) very useful. It allows to you very easily define complex formats for frames/messages on the bit and byte level. The idea is to use construct to encode and decode messages being sent to an embedded device. It works great. If you have further questions about this approach, feel free to ask. Eli ------------------------------------------------------------------------------ -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Wed Sep 8 06:46:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 03:46:18 -0700 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <7xhbi0y0lh.fsf@ruckus.brouhaha.com> Baba writes: > It is just unfriendly > to tell someone to go and look it up by themselves. Someone seeing too many unthoughtful questions from you might tell you to look it up yourself, in the hopes of getting you to change your questioning style, so that your future questions will be more thoughtful and worth answering. But according to you that would be unfriendly. Another thing they could do is say nothing, but quietly configure their news-reading software to ignore your questions completely. Then none of your future questions would have any hope of being answered. Would that be less unfriendly, or more unfriendly? From debatem1 at gmail.com Wed Sep 8 06:55:21 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 8 Sep 2010 03:55:21 -0700 Subject: Bit fields in python? In-Reply-To: References: Message-ID: On Tue, Sep 7, 2010 at 9:53 PM, Eli Bendersky wrote: >> >> I'm trying to rewrite a c program in python & encountered several >> problems. I have some data structures in my c program like below: >> >> typedef struct >> { >> ??? unsigned short size; >> >> ??? unsigned short reserved:8; >> ??? unsigned short var_a1:2; >> ??? unsigned short var_a2:2; >> ??? unsigned short var_a3:2; >> ??? unsigned short var_a4:2; >> >> ??? unsigned int var_a5; >> }structa; >> >> ?typedef struct >> { >> ??? unsigned short size; >> >> ??? unsigned?char reserved:4; >> ??? unsigned?char var_b1:1; >> ??? unsigned?char var_b2:1; >> ??? unsigned?char var_b3:1; >> ??? unsigned?char var_b4:1; >> >> ????structa var_structa; >> }structb; >> >> I tried to code the above in python but only got this far: >> >> class StructA(object): >> ??? def __init__(self, size=0) >> ??? self.size = size >> >> class StructB(object): >> ??? def __init__(self, size=0) >> >> Any equivalent for c data structures & bit fields in python??And how do I >> define var_structa (in structb) in python? >> > > Bitfields are most commonly used for extreme space optimization - i.e. > shoving several variables and flags with carefully limited ranges into a > single work. In Python you rarely work this way (where such an optimization > is warranted, Python isn't the best tool for the job). However, as in your > use case, it is sometimes needed in Python in order to communicate with > other devices over the network or some other link. > > In my work with Python and embedded devices I've found the construct library > (http://construct.wikispaces.com/) very useful. It allows to you very easily > define complex formats for frames/messages on the bit and byte level. The > idea is to use construct to encode and decode messages being sent to an > embedded device. It works great. > > If you have further questions about this approach, feel free to ask. > > Eli That's really an excellent find. Thanks for bringing it up. Geremy Condra From eckhardt at satorlaser.com Wed Sep 8 06:55:56 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 08 Sep 2010 12:55:56 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de><4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: BartC wrote: > So 'range' is just a class like any other. And that a class is something > you can blithely copy from one variable to another. And whenever you see > 'range' anywhere, you can't always be certain that someone hasn't done: > > range = 42 > > at some point. True. I read an explanation here that IMHO pretty well explains what's going on: The "range" above is a label, attached with a piece of string to an object. The object in this case is the integer 42. The same object can have multiple labels attached to it, so "foo = bar" will just create a new label "foo" and attach it to the object that the label "bar" is already attached to. Note that I said object, which includes class instances like the int 42 above, but also the classes themselves, functions (or bound functions[1]) and modules (I hope I didn't miss any). > That explains a lot about the difficulties of implementing Python > efficiently. Yes, "range" is not a keyword or something intrinsic to the interpreter. It is just a name that is looked up whenever it is encountered, and that costs time. However, you also get some nice flexibility at that cost. Cheers! Uli [1] bound function = class function where the instance parameter is bound. Example: x = [] a = x.append a(42) # calls x.append(42) -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From raoulbia at gmail.com Wed Sep 8 07:28:32 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 8 Sep 2010 04:28:32 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> Message-ID: <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> On 8 sep, 12:46, Paul Rubin wrote: > Baba writes: > > It is just unfriendly > > to tell someone to go and look it up by themselves. > > Someone seeing too many unthoughtful questions from you might tell you > to look it up yourself, in the hopes of getting you to change your > questioning style, so that your future questions will be more thoughtful > and worth answering. ?But according to you that would be unfriendly. > > Another thing they could do is say nothing, but quietly configure their > news-reading software to ignore your questions completely. ?Then none of > your future questions would have any hope of being answered. ?Would that > be less unfriendly, or more unfriendly? Hi Paul I would support option 1 but phrased more thoughtfully than Benjamin did (that way no feelings will be hurt): "Dear xyz, Your question can easily be researched online. We suggest you give it a try and to look it up yourself. This will be beneficial both to you and to us. We do encourage to ask questions only when they have been researched first. We care about the quality of posts but we also understand that as a beginner one can tend to look for an easy or quick way to find answers. So in the meantime here's something to get you started: link" But where do you draw the line? Can we not just let people ask questions regardless? And let those answer who want to and those who don't just ignore the question? That seems so much easier to me. From cjwilliams43 at gmail.com Wed Sep 8 07:45:28 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Wed, 08 Sep 2010 07:45:28 -0400 Subject: console-editor written in python In-Reply-To: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: On 08-Sep-10 04:51 AM, Tanje Toolate wrote: > hi there, > > > greetings. > > i am looking for a small, console-based (opensource) texteditor, > written in python (or as shellscript!), but i'm not finding something > usable. > > very find would be emacs-keybindings ... > > > dank u well, > > > tanja What operating system do you use? Colin W. From tanja2late at googlemail.com Wed Sep 8 07:50:56 2010 From: tanja2late at googlemail.com (Tanje Toolate) Date: Wed, 8 Sep 2010 04:50:56 -0700 (PDT) Subject: console-editor written in python References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: > > What operating system do you use? > > Colin W. usually linux. sometimes bsd. tanja From tanja2late at googlemail.com Wed Sep 8 07:51:05 2010 From: tanja2late at googlemail.com (Tanje Toolate) Date: Wed, 8 Sep 2010 04:51:05 -0700 (PDT) Subject: console-editor written in python References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: <9eb44d17-8526-4655-b2f4-99ecca226141@b34g2000yqm.googlegroups.com> > > What operating system do you use? > > Colin W. usually linux. sometimes bsd. tanja From sustainable.future115 at gmail.com Wed Sep 8 08:25:20 2010 From: sustainable.future115 at gmail.com (......) Date: Wed, 8 Sep 2010 05:25:20 -0700 (PDT) Subject: Why Insulation is a Good Investment Message-ID: <49729c8c-8791-4a5e-80ae-cc3a4eab80c3@f25g2000yqc.googlegroups.com> Why Insulation is a Good Investment Investing in products to make homes more energy efficient pays significant dividends over a lifetime ? with none of the wild fluctuations of Wall Street. Insulation contributes to: - Greater comfort - Even temperature distribution - Improved acoustics - Better moisture control, which can reduce floor squeaks, drywall cracks, structure damage and condensation - Potential for increased resale value: Installing proper insulation levels can also make your home more attractive to potential buyers. In fact, most buyers list energy-efficiency as a prime consideration. The reason? Buyers know they can buy a more expensive home if heating and cooling bills can be kept down. - A more environmentally friendly home - Lower energy bills* Unless your home was constructed with special attention to energy efficiency, adding insulation will probably reduce your utility bills. - 60% of the existing homes in the United States are not insulated to the best level. - According toa study done by Harvard University's School of Public Health, 60% of the exising homes are likely to use more energy than newer homes, leading to very high heating and air-conditioning bills. - Even if you own a new home, adding insulation may save enough money in reduced utility bills to pay for itself within a few years and will continue to save you money for as long as you own the home.* Source: http://www.simplyinsulate.com/content/why/benefits.html From no.email at nospam.invalid Wed Sep 8 08:39:22 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 05:39:22 -0700 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> Message-ID: <7xmxrsif45.fsf@ruckus.brouhaha.com> Baba writes: > But where do you draw the line? Can we not just let people ask > questions regardless? And let those answer who want to and those who > don't just ignore the question? That seems so much easier to me. The first few times, it's easy to ignore the questions. After a few more times, it becomes easier to ignore the person asking the questions, and not even look at the questions. The answer to many of your questions also is not "research it online", but rather, "figure it out with your own creativity". That's what being a programmer is about--figuring out solutions that don't already exist elsewhere. From thracs at gmail.com Wed Sep 8 08:57:44 2010 From: thracs at gmail.com (Ann Thracs) Date: Wed, 8 Sep 2010 05:57:44 -0700 (PDT) Subject: One Jew RASPUTIN hires another gentile RASPUTIN - to look good in comparison - always, profligate white led by a misleader jew - roman polansky, bernard madoff, moshe katsav, Craigslist Killer Philip Markoff jew Message-ID: <45c75078-8d58-41db-a074-a49aadfa1d70@b34g2000yqm.googlegroups.com> One Jew RASPUTIN hires another gentile RASPUTIN - to look good in comparison - always, profligate white led by a misleader jew - roman polansky, bernard madoff, moshe katsav, Craigslist Killer Philip Markoff jew HP CEO Mark Hurd Resigns After Sexual-Harassment Probe JORDAN ROBERTSON and RACHEL METZ | 08/ 6/10 11:53 PM | AP Resignation On August 6, 2010, he resigned from all of his positions at HP, following discovery of inappropriate conduct in an investigation into a claim of sexual harassment made by former reality TV actress Jodie Fisher. THE ZIONIST JEW LARRY ELLISON WHOSE COMPANY STOLE SAUDI MONEY TO DEVELOP ARABIC SUPPORT OF ORACLE TO HELP ISRAEL MONITOR THE PALESTINIAN PRISON AND LABOR CAMP - ONE NEEDS TO DO INVESTIGATION TO FIND THE BONES - A LOT OF BONES IN HIS CLOSET . A thorough good investigation into oracle's past should prove this. There should be a wikileaks on corporate crimes as well. http://www.zpub.com/un/un-le.html "Hi there, can I buy you a car?" According to accusations from an ongoing trial, that's the approach the Oracle CEO used to convince company secretaries to, ahem, "date" the boss. The case involves a 33- year-old former employee [FALSELY AND WRONGLY] accused of forging an email message. The woman [Adelyn Lee], who was fired shortly after an affair with Ellison, obtained a $100,000 settlement from him. Larry Ellison's All-Time Top Pickup Line http://www.thesmokinggun.com/documents/crime/polanski-predator jew roman polanski raped 13 year old girl semantha geimer, orally, vaginally and anally without any mercy jew roman polanski raped 13 year old girl semantha geimer, orally, vaginally and anally without any mercy SAN FRANCISCO ? Hewlett-Packard Co. ousted its CEO on Friday for allegedly falsifying documents to conceal a relationship with a former contractor and help her get paid for work she didn't do. News of Mark Hurd's abrupt departure sent HP's stock tumbling. Shares of the world's biggest maker of personal computers and printers have doubled in value during his five-year stewardship, and HP became the world's No. 1 technology company by revenue in that time. The company said it learned about the relationship several weeks ago, when the woman, who did marketing work for HP, sent a letter accusing Hurd, 53, and the company of sexual harassment. An investigation found that Hurd falsified expense reports and other financial documents to conceal the relationship. The company said it found that its sexual harassment policy wasn't violated but that its standards of business conduct were. Hurd's "systematic pattern" of submitting falsified financial reports to hide the relationship From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 09:13:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 13:13:09 GMT Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: <4c878be5$0$11113$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 11:00:03 +0100, BartC wrote: >> for i in xrange(100000000): >> a = a + f(i) >> >> then unrolling the loop is even less useful. The overhead of the loop >> itself is likely to be trivial compared to the cost of calling f() 100 >> million times -- the added complexity to shave 3 seconds off a four >> minute calculation simply isn't worth it. > > With Python 3 and def f(x): return x+1, unrolling this loop 4x improved > speed by 15%; 4.00 minutes reduces to 3.30 minutes. I'm afraid that I can't replicate those figures. In my test, unrolling the loop causes a massive SLOWDOWN of 37%, not a speed up. Here is my test code: def f(x): return x+1 def test_loop(n): a = 0 for i in range(n): a += f(i) return a def test_unrolled(n): a = 0 for i in range(n//4): a += f(4*i) a += f(4*i+1) a += f(4*i+2) a += f(4*i+3) return a from timeit import Timer n = 10000000 assert test_loop(n) == test_unrolled(n) t1 = Timer('test_loop(n)', 'from __main__ import test_loop; n=%d' % n) t2 = Timer('test_unrolled(n)', 'from __main__ import test_unrolled; n=%d' % n) And here are the results using Python 3.1. Times are the best of 5 for 10 calls each to the loop_* functions, results given in seconds: >>> min(t1.repeat(number=10, repeat=5))/10 5.97409288883209 >>> min(t2.repeat(number=10, repeat=5))/10 8.25656900405883 I repeated it with a larger loop variable. Since the time per test was so large (over ten minutes per call on my machine!), I didn't see the need to run multiple trials: n *= 100 assert test_loop(n) == test_unrolled(n) t3 = Timer('test_loop(n)', 'from __main__ import test_loop; n=%d' % n) t4 = Timer('test_unrolled(n)', 'from __main__ import test_unrolled; n=%d' % n) And the results: >>> t3.timeit(number=1) 653.3572518825531 >>> t4.timeit(number=1) 864.6454808712006 That's slightly better (32% slower instead of 37% slower), but still a massive performance hit. Given these results, I'm prepared to say that loop unrolling in Python is almost certainly going to be a pessimation, not an optimization, no matter what you have inside the loop. -- Steven From alain at dpt-info.u-strasbg.fr Wed Sep 8 09:58:01 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 08 Sep 2010 15:58:01 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> <4c878be5$0$11113$c3e8da3@news.astraweb.com> Message-ID: <87sk1k9w2e.fsf@dpt-info.u-strasbg.fr> Steven D'Aprano writes: >> With Python 3 and def f(x): return x+1, unrolling this loop 4x improved >> speed by 15%; 4.00 minutes reduces to 3.30 minutes. > I'm afraid that I can't replicate those figures. In my test, unrolling > the loop causes a massive SLOWDOWN of 37%, not a speed up. Here is my > test code: > > def f(x): > return x+1 > > def test_loop(n): > a = 0 > for i in range(n): > a += f(i) > return a > > def test_unrolled(n): > a = 0 > for i in range(n//4): > a += f(4*i) > a += f(4*i+1) > a += f(4*i+2) > a += f(4*i+3) > return a > > from timeit import Timer > n = 10000000 > assert test_loop(n) == test_unrolled(n) > t1 = Timer('test_loop(n)', > 'from __main__ import test_loop; n=%d' % n) > t2 = Timer('test_unrolled(n)', > 'from __main__ import test_unrolled; n=%d' % n) > > And here are the results using Python 3.1. Times are the best of 5 for 10 > calls each to the loop_* functions, results given in seconds: > >>>> min(t1.repeat(number=10, repeat=5))/10 > 5.97409288883209 >>>> min(t2.repeat(number=10, repeat=5))/10 > 8.25656900405883 Running this test with python 2.6 (on my laptop) led to: >>> min(t1.repeat(number=10, repeat=5))/10 2.10715539455 >>> min(t2.repeat(number=10, repeat=5))/10 2.43037149906 That's a 15% slowdown. Which is reasonable since you add four multiplies in the loop body. Changing your unrolled loop to: def test_unrolled(n): a = 0 for i in range(n//4): b = 4*i a += f(b) a += f(b+1) a += f(b+2) a += f(b+3) return a makes both versions run in approximately the same time (2.135 vs. 2.136). > That's slightly better (32% slower instead of 37% slower), but still a > massive performance hit. Given these results, I'm prepared to say that > loop unrolling in Python is almost certainly going to be a pessimation, > not an optimization, no matter what you have inside the loop. I don't really see why it should be the case. Do you have any idea? I don't think either that it should speed things up significantly. Loop unrolling in binary code is relevant mostly because it allows better instruction scheduling (i.e., scheduling has fewer constraints in longer instruction sequences). Python programs are way too far from binary code for scheduling opts to apply. -- Alain. From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 09:58:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 13:58:05 GMT Subject: Automatic delegation in Python 3 Message-ID: <4c87966d$0$11113$c3e8da3@news.astraweb.com> Delegation in old-style classes worked fine: # Python 2.6 >>> class Delegate: ... def __init__(self, x): ... self.__dict__['x'] = x ... def __getattr__(self, name): ... return getattr(self.x, name) ... def __setattr__(self, name, value): ... setattr(self.x, name, value) ... >>> obj = Delegate({}) >>> obj[1] = None >>> obj {1: None} But when I try the equivalent recipe with a new-style class, it behaves differently: >>> class Delegate2(object): ... def __init__(self, x): ... self.__dict__['x'] = x ... def __getattr__(self, name): ... return getattr(self.x, name) ... def __setattr__(self, name, value): ... setattr(self.x, name, value) ... >>> obj = Delegate2({}) >>> obj <__main__.Delegate2 object at 0x8f6130c> Okay, I get that one... because I'm inheriting from object, __getattr__ picks up object's __str__ method and uses that. But then there's this: >>> obj[1] = 0 Traceback (most recent call last): File "", line 1, in TypeError: 'Delegate2' object does not support item assignment But these work: >>> obj.__setitem__ >>> obj.__setitem__(1, None) >>> obj.x {1: None} What's going on here? I *think* this has something to do with special double-underscore methods being looked up on the class, not the instance, for new-style classes, but I'm not entirely sure. Unfortunately, I need to use delegation, not inheritance, and I need to use a new-style class, since I will be using Python 3. How can I do automatic delegation in Python 3? Is my only hope to give up on the elegance of automatic delegation, and code all the special methods as manual delegation? class Delegate2(object): def __setitem__(self, key, value): self.x[key] = value # and so on for everything else I care about... -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 10:21:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 14:21:11 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: <4c879bd7$0$11113$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 20:35:45 -0700, Phlip wrote: > Exceptions are very dangerous by themselves, because if you don't trap > them just right they can cause side-effects. Huh? If you don't trap them just right, the cause a stack trace, which is a side-effect I suppose. But it's an *intended* side-effect, since the alternative would be a core dump (or worse, an incorrect program that *doesn't* crash). This is a good thing! -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 10:26:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 14:26:34 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <642cd655-ade1-40d9-8d02-66ca9354d3c3@q21g2000prm.googlegroups.com> Message-ID: <4c879d19$0$11113$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 20:38:14 -0700, Phlip wrote: > On Sep 7, 5:51?pm, Terry Reedy wrote: >> On 9/7/2010 2:53 PM, Phlip wrote: >> >> > They are for situations which the caller should care not to handle. >> >> Python is simply not designed that way. Exception raising and catching >> is a common flow-control method in Python. If you cannot stand that, >> Python is not for you. > > While I'm at it, I'm going to log into comp.lang.java.misc and explain > to everyone why static typing is overkill, and implementation > inheritance is good for you. > > Everyone gets defensive about the design flaws in their own language. > But the django.db situation is not even a design flaw; just a > misinterpretation of the Samurai Principle. int('yo') shall throw an > exception, but a missing record could be the result you were looking > for, so it's not exceptional. I think you've misunderstood the meaning of "exception" if you think that. It doesn't mean "error". Nor does it mean "rare". (Although, given that exceptions in Python are expensive, one would hope they're not *too* common.) The unexceptional case of looking up a record is to find it. That, after all, is the purpose of the lookup function -- to find the given record. That's what it is designed to do, and anything else is considered exceptional. Whether the lookup function returns a special "not found" result, or raises an exception, or sets some magic global error code somewhere, it's still an exceptional case. -- Steven From aahz at pythoncraft.com Wed Sep 8 10:42:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Sep 2010 07:42:28 -0700 Subject: problem with simple multiprocessing script on OS X References: <5fcea7ea-13ad-41af-8a68-9d418f9cdf93@i31g2000yqm.googlegroups.com> <45015919-6de0-4ed3-b4fe-62824e16cd43@t11g2000vbc.googlegroups.com> Message-ID: In article , Darren Dale wrote: > >About a year ago, I contributed a patch to h5py which checks to see if >h5py is being imported into an active IPython session. If so, then a >custom tab completer is loaded to make it easier to navigate hdf5 >files. In the development version of IPython, a function that used to >return None if there was no instance of an IPython interactive shell >now creates and returns a new instance. This was the cause of the >error I was reporting. Hoist on your own petard, eh? ;-) Thanks for reporting the solution. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From invalid at invalid.invalid Wed Sep 8 10:44:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Sep 2010 14:44:12 +0000 (UTC) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> <4c879bd7$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-08, Steven D'Aprano wrote: > On Tue, 07 Sep 2010 20:35:45 -0700, Phlip wrote: > >> Exceptions are very dangerous by themselves, because if you don't trap >> them just right they can cause side-effects. > > Huh? > > If you don't trap them just right, they cause a stack trace, Not always. That is the effect of not trapping them at all. However, you can trap them incorrectly -- which can result in hard-to-track down problems. The main example of this is a "bare except" clause that not only catches and handles the "expected" exception but also catches (and mishandles/ignores) an unexpected one. > which is a side-effect I suppose. But it's an *intended* side-effect, > since the alternative would be a core dump (or worse, an incorrect > program that *doesn't* crash). This is a good thing! -- Grant Edwards grant.b.edwards Yow! -- I have seen the at FUN -- gmail.com From thomas at jollybox.de Wed Sep 8 10:49:31 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 8 Sep 2010 16:49:31 +0200 Subject: console-editor written in python In-Reply-To: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: <201009081649.32381.thomas@jollybox.de> On Wednesday 08 September 2010, it occurred to Tanje Toolate to exclaim: > hi there, > > > greetings. > > i am looking for a small, console-based (opensource) texteditor, > written in python (or as shellscript!), but i'm not finding something > usable. Why? (Also, I can't imagine anyone writing a shell script that deserves, or even aspires to deserve, the name "text editor"). > > very find would be emacs-keybindings ... Why not just use a real emacs ? From invalid at invalid.invalid Wed Sep 8 10:57:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Sep 2010 14:57:32 +0000 (UTC) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: On 2010-09-08, Baba wrote: > Thanks for your feedback. My question is: Who owns this forum? If we > all do then we are allowed to post questions that are simple and that > could otherwise be answered by doing research. Of course you're allowed to post such questions. And people are allowed to ignore you, to answer your question sarcastically, to attempt to teach you how to answer your own questions, or to respond in other ways. It's up to _you_ to make the effort to try to insure that you get a useful response. To that end here is how that is accomplished: http://catb.org/esr/faqs/smart-questions.html Maybe you don't _like_ the fact that you are expected to show just a tiny bit of inititiative and care in researching and posting your question, but that's pretty much the way it it works. I'm sure you'd prefer that everything was handed to you for free on a silver platter with a side order of beer and cookies. I'd prefer I was 20 years younger and 30 pounds lighter. Life's tough that way. > It is just unfriendly to tell someone to go and look it up by > themselves. 1) It isn't if give them a hint on where to look it up. 2) Posting questions like yours is considered unfriendly. > Who is licensed to judge what can and cannot be posted as a question? Nobody. Post whatever questions you want however you want in whatever language you want. If you don't care about actually _answering_ your question, feel free to continue in the same vein in which you started. If you _do_ care about getting a prompt, accurate answer, then: http://catb.org/esr/faqs/smart-questions.html > A teacher of mine used to say: "There are no stupid questions, there > are only stupid answers." Ask that teacher for help then. > It is arrogant to tell someone in a Forum to "look it up yourself, > this question is too basic". Perhaps it is. But remember you're the one asking strangers for a free service, so it's up to you to "play by the rules" in return for that free service. One of the rules is that you first try to answer the question yourself. > Can you not understand that accessing a file can seem daunting at > first? Maybe so, but reading a tutorial isn't. -- Grant Edwards grant.b.edwards Yow! I need to discuss at BUY-BACK PROVISIONS gmail.com with at least six studio SLEAZEBALLS!! From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 11:13:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 15:13:25 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> <4c879bd7$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c87a815$0$11113$c3e8da3@news.astraweb.com> On Wed, 08 Sep 2010 14:44:12 +0000, Grant Edwards wrote: > On 2010-09-08, Steven D'Aprano > wrote: >> On Tue, 07 Sep 2010 20:35:45 -0700, Phlip wrote: >> >>> Exceptions are very dangerous by themselves, because if you don't trap >>> them just right they can cause side-effects. >> >> Huh? >> >> If you don't trap them just right, they cause a stack trace, > > Not always. That is the effect of not trapping them at all. However, > you can trap them incorrectly -- which can result in hard-to-track down > problems. > > The main example of this is a "bare except" clause that not only catches > and handles the "expected" exception but also catches (and > mishandles/ignores) an unexpected one. Ah, fair enough. That would be a false positive error -- catching too much rather than too little. Still, that's no better, or worse, than misinterpreting special error codes that are returned by functions. The main error mode there is catching too little -- people neglect to check the error code, and therefore have buggy code: p = some_string.find('#') print some_string[:p] And who hasn't done this more than once? re.search(pattern, some_string).group() -- Steven From kixo82 at googlemail.com Wed Sep 8 11:25:33 2010 From: kixo82 at googlemail.com (mex) Date: Wed, 8 Sep 2010 08:25:33 -0700 (PDT) Subject: console-editor written in python References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: On 8 Sep., 16:49, Thomas Jollans wrote: > On Wednesday 08 September 2010, it occurred to Tanje Toolate to exclaim: > > > hi there, > > > greetings. > > > i am looking for a small, console-based (opensource) texteditor, > > written in python (or as shellscript!), but i'm not finding something > > usable. > > Why? > (Also, I can't imagine anyone writing a shell script that deserves, or even > aspires to deserve, the name "text editor"). > > > > > very find would be emacs-keybindings ... > > Why not just use a real emacs ? why? because! ok, the part with the shellscript was a joke ... we usually use joe/jmacs but run into issues lately on customer- environments with precompiled versions of this editor. a python-based console- editor would be perfekt. tanja From bruno.42.desthuilliers at websiteburo.invalid Wed Sep 8 12:15:08 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 08 Sep 2010 18:15:08 +0200 Subject: accessing a text file In-Reply-To: <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> Message-ID: <4c87b67e$0$21620$426a74cc@news.free.fr> Baba a ?crit : > > "Dear xyz, > Your question can easily be researched online. We suggest you give it > a try and to look it up yourself. This will be beneficial both to you > and to us. We do encourage to ask questions only when they have been > researched first." On usenet - as well as on most technical forums / mailing lists / etc -, this usually condensed in a well-known four letters acronym : "RTFM" Hopefully c.l.py is an unusually friendly and polite place, so we tend to say it a bit more elegantly and most of the time we do indeed provide a link. This being said and given your attitude - you may not realize it, but by now you would have been flamed to hell and back on quite a few other newsgroups -, I'm very tempted to switch to option 2. From ron.eggler at gmail.com Wed Sep 8 12:59:18 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 8 Sep 2010 09:59:18 -0700 (PDT) Subject: listening socket Message-ID: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> Hi, I'm trying to create a listening socket connection on port 1514. I tried to follow the documentation at: http://docs.python.org/release/2.5.2/lib/socket-example.html and came up with following lines: import socket host = '' # Symbolic name meaning all available interfaces port = 1514 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while 1: data = conn.recv(1024) if not data: break conn.send(data) conn.close() but that is not working, i'm getting this: import: unable to open X server `' @ error/import.c/ImportImageCommand/ 362. ./sockettest.py: line 4: host: command not found ./sockettest.py: line 5: port: command not found ./sockettest.py: line 6: syntax error near unexpected token `(' ./sockettest.py: line 6: `s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)' now why would it try to open an x server??? :o From benjamin.kaplan at case.edu Wed Sep 8 13:06:44 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 8 Sep 2010 13:06:44 -0400 Subject: listening socket In-Reply-To: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> References: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> Message-ID: On Wed, Sep 8, 2010 at 12:59 PM, cerr wrote: > Hi, > > I'm trying to create a listening socket connection on port 1514. > I tried to follow the documentation at: > http://docs.python.org/release/2.5.2/lib/socket-example.html > and came up with following lines: > import socket > > host = '' ? ? ? ? ? ? ? ? # Symbolic name meaning all available > interfaces > port = 1514 ? ? ? ? ? ? ? # Arbitrary non-privileged port > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((host, port)) > s.listen(1) > conn, addr = s.accept() > print 'Connected by', addr > while 1: > ? ?data = conn.recv(1024) > ? ?if not data: break > ? ?conn.send(data) > conn.close() > but that is not working, i'm getting this: > import: unable to open X server `' @ error/import.c/ImportImageCommand/ > 362. > ./sockettest.py: line 4: host: command not found > ./sockettest.py: line 5: port: command not found > ./sockettest.py: line 6: syntax error near unexpected token `(' > ./sockettest.py: line 6: `s = socket.socket(socket.AF_INET, > socket.SOCK_STREAM)' > > now why would it try to open an x server??? :o > -- Because it's not executing it as a Python program. It's trying to execute it as a shell script. If you want to run a script as a Python program, either call the interpreter directly python sockettest.py or include a Shebang line as the first line of the file that tells the computer what interpreter to use #!/usr/bin/env python The file extension itself is meaningless to a Unix shell- it's just a part of the file name. From stef.mientki at gmail.com Wed Sep 8 13:09:12 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 08 Sep 2010 19:09:12 +0200 Subject: are there pros or contras, keeping a connection to a (sqlite) database ? Message-ID: <4C87C338.2070607@gmail.com> hello, I wrap my database in some class, and on creation of the instance, a connection to the database is created, and will stay connected until the program exists, something like this: self.conn = sqlite3.connect ( self.filename ) Now I wonder if there are pros or contras to keep the connection to the database continuously "open" ? thanks, Stef Mientki From ron.eggler at gmail.com Wed Sep 8 13:11:16 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 8 Sep 2010 10:11:16 -0700 (PDT) Subject: listening socket References: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> Message-ID: On Sep 8, 10:06?am, Benjamin Kaplan wrote: > On Wed, Sep 8, 2010 at 12:59 PM, cerr wrote: > > Hi, > > > I'm trying to create a listening socket connection on port 1514. > > I tried to follow the documentation at: > >http://docs.python.org/release/2.5.2/lib/socket-example.html > > and came up with following lines: > > import socket > > > host = '' ? ? ? ? ? ? ? ? # Symbolic name meaning all available > > interfaces > > port = 1514 ? ? ? ? ? ? ? # Arbitrary non-privileged port > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > s.bind((host, port)) > > s.listen(1) > > conn, addr = s.accept() > > print 'Connected by', addr > > while 1: > > ? ?data = conn.recv(1024) > > ? ?if not data: break > > ? ?conn.send(data) > > conn.close() > > but that is not working, i'm getting this: > > import: unable to open X server `' @ error/import.c/ImportImageCommand/ > > 362. > > ./sockettest.py: line 4: host: command not found > > ./sockettest.py: line 5: port: command not found > > ./sockettest.py: line 6: syntax error near unexpected token `(' > > ./sockettest.py: line 6: `s = socket.socket(socket.AF_INET, > > socket.SOCK_STREAM)' > > > now why would it try to open an x server??? :o > > -- > > Because it's not executing it as a Python program. It's trying to > execute it as a shell script. If you want to run a script as a Python > program, either call the interpreter directly > python sockettest.py > > or include a Shebang line as the first line of the file that tells the > computer what interpreter to use > #!/usr/bin/env python > > The file extension itself is meaningless to a Unix shell- it's just a > part of the file name. hoops right... heh, thanks... :$ clearly doing too many things at the same time... From ptmcg at austin.rr.com Wed Sep 8 13:17:37 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 8 Sep 2010 10:17:37 -0700 (PDT) Subject: mutate dictionary or list References: Message-ID: <80fde7c8-2169-473f-aeaf-1971cc3c4dbf@i5g2000yqe.googlegroups.com> On Sep 7, 7:05?am, Baba wrote: > Hi > > I am working on an exercise which requires me to write a funtion that > will check if a given word can be found in a given dictionary (the > hand). > > def is_valid_word(word, hand, word_list): > ? ? """ > ? ? Returns True if word is in the word_list and is entirely > ? ? composed of letters in the hand. Otherwise, returns False. > ? ? Does not mutate hand or word_list.""" > > I don't understand this part: Does not mutate hand or word_list > I would re-read your exercise description. hand is *not* a dictionary, but is most likely a list of individual letters. word_list too is probably *not* a dictionary, but a list of valid words (although this does bear a resemblance to what people in everyday life call a "dictionary"). Where did you get the idea that there was a dictionary in this problem? The "Does not mutate hand or word_list." is a constraint that you are not allowed to update the hand or word_list arguments. For instance, you must not call word_list.sort() in order to search for the given word using some sort of binary search. You must not determine if all the letters in word come from hand by modifying the hand list (like dropping letters from hand as they are found in word). There are ways to copy arguments if you use a destructive process on their contents, so that the original stays unmodified - but that sounds like part of the exercise for you to learn about. -- Paul From invalid at invalid.invalid Wed Sep 8 13:44:01 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Sep 2010 17:44:01 +0000 (UTC) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> <4c879bd7$0$11113$c3e8da3@news.astraweb.com> <4c87a815$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-08, Steven D'Aprano wrote: > On Wed, 08 Sep 2010 14:44:12 +0000, Grant Edwards wrote: >> >>> If you don't trap them just right, they cause a stack trace, >> >> Not always. That is the effect of not trapping them at all. However, >> you can trap them incorrectly -- which can result in hard-to-track down >> problems. >> >> The main example of this is a "bare except" clause that not only catches >> and handles the "expected" exception but also catches (and >> mishandles/ignores) an unexpected one. > > Ah, fair enough. That would be a false positive error -- catching too > much rather than too little. > > Still, that's no better, or worse, than misinterpreting special error > codes that are returned by functions. No, I didn't mean to imply that was the case. I agree with your conclusion. I find it much easier to screw things up using the "exceptional return value" method than the "exception raise" method. -- Grant Edwards grant.b.edwards Yow! Psychoanalysis?? at I thought this was a nude gmail.com rap session!!! From invalid at invalid.invalid Wed Sep 8 13:47:38 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Sep 2010 17:47:38 +0000 (UTC) Subject: listening socket References: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> Message-ID: On 2010-09-08, Benjamin Kaplan wrote: > On Wed, Sep 8, 2010 at 12:59 PM, cerr wrote: >> but that is not working, i'm getting this: >> import: unable to open X server `' @ error/import.c/ImportImageCommand/ [...] >> now why would it try to open an x server??? :o > > Because it's not executing it as a Python program. It's trying to > execute it as a shell script. What's even more fun is if you do have an X server, and the shell is able to run the import program, and it does open the X server, and so on... [Not that things like that ever happen to _me_] -- Grant Edwards grant.b.edwards Yow! I feel partially at hydrogenated! gmail.com From nagle at animats.com Wed Sep 8 14:39:50 2010 From: nagle at animats.com (John Nagle) Date: Wed, 08 Sep 2010 11:39:50 -0700 Subject: are there pros or contras, keeping a connection to a (sqlite) database ? In-Reply-To: References: Message-ID: <4c87d873$0$1590$742ec2ed@news.sonic.net> On 9/8/2010 10:09 AM, Stef Mientki wrote: > hello, > > I wrap my database in some class, and on creation of the instance, a connection to the database is > created, > and will stay connected until the program exists, something like this: > > self.conn = sqlite3.connect ( self.filename ) > > Now I wonder if there are pros or contras to keep the connection to the database continuously "open" ? > > thanks, > Stef Mientki Open is OK. Open is good, because the database system gets to cache some data. Open with an uncommitted transaction may leave the file locked, preventing access by other processes. So make sure you commit before you go idle. John Nagle From ron.eggler at gmail.com Wed Sep 8 14:43:50 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 8 Sep 2010 11:43:50 -0700 (PDT) Subject: executing script in fork Message-ID: <72682e09-3946-48ef-a726-d692932a0c5c@k1g2000prl.googlegroups.com> Hi There, I want to trigger another script and having it running forked to my mother process. I googled around and came up with following: commandlist=['./GPSsim.pl',proto,'files/gps.txt'] subprocess.Popen(commandlist) print "GPS simulator started" This however doesn't seem disconnect stdout but it still throws me back to the shell. How can I launch it with disconnected stdout and still continue running further code in my mother script? Thanks, Ron From bartc at freeuk.com Wed Sep 8 14:45:26 2010 From: bartc at freeuk.com (BartC) Date: Wed, 8 Sep 2010 19:45:26 +0100 Subject: Speed-up for loops In-Reply-To: <4c878be5$0$11113$c3e8da3@news.astraweb.com> References: <4C7F7640.1010102@perfect-kreim.de><4c83b425$0$28657$c3e8da3@news.astraweb.com><4c85adfe$0$11115$c3e8da3@news.astraweb.com> <4c878be5$0$11113$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c878be5$0$11113$c3e8da3 at news.astraweb.com... > On Tue, 07 Sep 2010 11:00:03 +0100, BartC wrote: > >>> for i in xrange(100000000): >>> a = a + f(i) >> With Python 3 and def f(x): return x+1, unrolling this loop 4x improved >> speed by 15%; 4.00 minutes reduces to 3.30 minutes. > > > I'm afraid that I can't replicate those figures. In my test, unrolling > the loop causes a massive SLOWDOWN of 37%, not a speed up. Here is my > test code: You're absolutely right. I completely forgot about modulating the i index for each duplicated line. > def test_unrolled(n): > a = 0 > for i in range(n//4): > a += f(4*i) > a += f(4*i+1) > a += f(4*i+2) > a += f(4*i+3) > return a Although tidying up your calculations (as already posted) gives code that is neither faster nor slower. I'd hoped that using the following would help, but did nothing in Python 3, and gave only 8-10% speedup in Python 2: for i in xrange(0,n,4): a=a+f(i) a=a+f(i+1) a=a+f(i+2) a=a+f(i+3) (On my other example of setting list elements to 0, this did improve speed by some 10% in Python 3, and 28% in '2'.) So using manual unrolling for an indexed loop is not going to be the right approach (it's also fiddly, and there is the problem of N not being a multiple of 4 or whatever). We're trying to avoid the iteration overhead, yet we're adding it in the code anyway, and as user-level code. But, I still think that internal support for such a thing might be worthwhile, when it can make certain assumptions about the loop range and index type. -- Bartc From tjreedy at udel.edu Wed Sep 8 14:55:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Sep 2010 14:55:30 -0400 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) In-Reply-To: <7d2b1ed5-8cdd-4dcd-a8d0-065fda18e895@u5g2000prn.googlegroups.com> References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> <7d2b1ed5-8cdd-4dcd-a8d0-065fda18e895@u5g2000prn.googlegroups.com> Message-ID: I believe I answered your question a day ago. If it has not reached you yet, try the gmane.org archives. -- Terry Jan Reedy From jonnojohnson at gmail.com Wed Sep 8 14:55:50 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 13:55:50 -0500 Subject: Slice a list of lists? Message-ID: I know that I can index into a list of lists like this: a=[[1,2,3],[4,5,6],[7,8,9]] a[0][2]=3 a[2][0]=7 but when I try to use fancy indexing to select the first item in each list I get: a[0][:]=[1,2,3] a[:][0]=[1,2,3] Why is this and is there a way to select [1,4,7]? From kdombrowski at gmail.com Wed Sep 8 14:58:22 2010 From: kdombrowski at gmail.com (Kenneth Dombrowski) Date: Wed, 8 Sep 2010 14:58:22 -0400 Subject: cPickle segfault with nested dicts in threaded env Message-ID: Hi all, Before creating an issue @ bugs.python.org I wanted to run the following by everyone We are having a difficult time with what looks like a cPickle issue when given a data structure containing >15 nested dictionaries, but only when threading is involved Environment is FreeBSD 8, Python 2.5.5 The following diff contains an addition for /usr/ports/lang/python25/work/Python-2.5.5/Lib/test/test_cpickle.py which reproduces the issue kenneth at kenneth0 Python-2.5.5 $ cat /tmp/test_cpickle.nested_dicts_in_threaded_env.diff 1a2 > import copy 2a4 > import threading 93a96,105 > def test_nested_dicts_in_threaded_env(self): > # segfaults on python2.5.5/FreeBSD 8.0-RELEASE-p2 > def threadloop(): > x = {} > for i in range(16): > x = {i:copy.copy(x)} > cPickle.dumps(x, 2) > t = threading.Thread(target=threadloop) > t.start() > Any thoughts will be appreciated, thanks for looking, Kenneth From usenot at geekmail.INVALID Wed Sep 8 15:08:11 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 8 Sep 2010 15:08:11 -0400 Subject: Slice a list of lists? References: Message-ID: <20100908150811.12e3ec3a@geekmail.INVALID> On Wed, 8 Sep 2010 13:55:50 -0500 Jonno wrote: > I know that I can index into a list of lists like this: > a=[[1,2,3],[4,5,6],[7,8,9]] > a[0][2]=3 > a[2][0]=7 > > but when I try to use fancy indexing to select the first item in each > list I get: Let me write out in words what you're doing, and it should become clear: > a[0][:]=[1,2,3] Here you're making a list of all elements of the first element of a. > a[:][0]=[1,2,3] > And here you're selecting the first element of all elements of a. Huh. Not quite as clear as I hoped. But ponder on this for a few moments. It'll dawn on you eventually. > Why is this and is there a way to select [1,4,7]? zip(*a)[0] (or rather list(zip(*a)[0]), if you definitely need a list and not a tuple) /W -- INVALID? DE! From benjamin.kaplan at case.edu Wed Sep 8 15:11:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 8 Sep 2010 15:11:51 -0400 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: > I know that I can index into a list of lists like this: > a=[[1,2,3],[4,5,6],[7,8,9]] > a[0][2]=3 > a[2][0]=7 > > but when I try to use fancy indexing to select the first item in each > list I get: > a[0][:]=[1,2,3] > a[:][0]=[1,2,3] > > Why is this and is there a way to select [1,4,7]? > -- It's not fancy indexing. It's called taking a slice of the existing list. Look at it this way a[0] means take the first element of a. The first element of a is [1,2,3] a[0][:] means take all the elements in that first element of a. All the elements of [1,2,3] are [1,2,3]. a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. a[:][0] means take the first element of all the elements of a. The first element of a[:] is [1,2,3]. There is no simple way to get [1,4,7] because it is just a list of lists and not an actual matrix. You have to extract the elements yourself. col = [] for row in a: col.append(row[0]) You can do this in one line using a list comprehension: [ row[0] for row in a ] > http://mail.python.org/mailman/listinfo/python-list > From usenot at geekmail.INVALID Wed Sep 8 15:12:30 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 8 Sep 2010 15:12:30 -0400 Subject: Slice a list of lists? References: <20100908150811.12e3ec3a@geekmail.INVALID> Message-ID: <20100908151230.37687067@geekmail.INVALID> Let me rephrase what I wrote a bit. On Wed, 8 Sep 2010 15:08:11 -0400 Andreas Waldenburger wrote: > > a[0][:]=[1,2,3] > Here you're making a list of all elements of the first element of a. > That is, you're making a copy of the first element of a. > > a[:][0]=[1,2,3] > > > And here you're selecting the first element of all elements of a. > That is, you're taking the first element of a copy of a. I hope this is a little less confusing. /W -- INVALID? DE! From usenot at geekmail.INVALID Wed Sep 8 15:17:08 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 8 Sep 2010 15:17:08 -0400 Subject: Slice a list of lists? References: Message-ID: <20100908151708.3dc68090@geekmail.INVALID> On Wed, 8 Sep 2010 15:11:51 -0400 Benjamin Kaplan wrote: > There is no simple way to get [1,4,7] because it is just a list of > lists and not an actual matrix. You have to extract the elements > yourself. > > col = [] > for row in a: > col.append(row[0]) > > > You can do this in one line using a list comprehension: > [ row[0] for row in a ] I would suggest this (esp. the list comprehension version) over my suggestion of zip(). WAAAYYYY more readable. Apparently I'm getting rusty. /W -- INVALID? DE! From python at mrabarnett.plus.com Wed Sep 8 15:30:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Sep 2010 20:30:34 +0100 Subject: [Python-ideas] with statement syntax forces ugly line breaks? In-Reply-To: References: <20100908175029.6617ae3b@dino> Message-ID: <4C87E45A.1080207@mrabarnett.plus.com> On 08/09/2010 19:07, Georg Brandl wrote: > Thus spake the Lord: Thou shalt indent with four spaces. No more, no > less. Four shall be the number of spaces thou shalt indent, and the > number of thy indenting shall be four. Eight shalt thou not indent, > nor either indent thou two, excepting that thou then proceed to four. > Tabs are right out. > FYI, that should be "thine indenting". "My/thy" before a consonant, "mine/thine" before a vowel. Compare with "a/an", which we still do. From tjreedy at udel.edu Wed Sep 8 15:45:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Sep 2010 15:45:46 -0400 Subject: Automatic delegation in Python 3 In-Reply-To: <4c87966d$0$11113$c3e8da3@news.astraweb.com> References: <4c87966d$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 9/8/2010 9:58 AM, Steven D'Aprano wrote: > Delegation in old-style classes worked fine: > > # Python 2.6 >>>> class Delegate: > ... def __init__(self, x): > ... self.__dict__['x'] = x > ... def __getattr__(self, name): > ... return getattr(self.x, name) > ... def __setattr__(self, name, value): > ... setattr(self.x, name, value) > ... >>>> obj = Delegate({}) >>>> obj[1] = None Since you are not setting a attribute, I was initially surprised that this worked. Then I remembered that this is executed for old-style classes as obj.__getattr__('__setitem__')(1,None) and that __setattr__ above is not involved. This is possible because old-style user classes were a world apart form builtin types. Once user-classes were integrated into the builting class/type hierarchy, they had to follow the same rules as the latter. One problem is that classes are also instances of their metaclass. This is somewhat explained in 3.3.8 'Special method lookup' (which I have read at least 3 times before understanding). As you discovered, this is not a complete win. The bottom line of 3.3.8: "Bypassing the __getattribute__() machinery in this fashion provides significant scope for speed optimisations within the interpreter, at the cost of some flexibility in the handling of special methods (the special method must be set on the class object itself in order to be consistently invoked by the interpreter)." You are seeing the cost. > Unfortunately, I need to use delegation, not inheritance, and I need to > use a new-style class, since I will be using Python 3. How can I do > automatic delegation in Python 3? Is my only hope to give up on the > elegance of automatic delegation, and code all the special methods as > manual delegation? Based on the above, it seems so. But I would search a bit more for delegation and proxy object and python 3 to see what others have done. -- Terry Jan Reedy From emile at fenx.com Wed Sep 8 15:51:41 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 08 Sep 2010 12:51:41 -0700 Subject: Slice a list of lists? In-Reply-To: <20100908151708.3dc68090@geekmail.INVALID> References: <20100908151708.3dc68090@geekmail.INVALID> Message-ID: On 9/8/2010 12:17 PM Andreas Waldenburger said... > On Wed, 8 Sep 2010 15:11:51 -0400 Benjamin Kaplan > wrote: > >> There is no simple way to get [1,4,7] because it is just a list of >> lists and not an actual matrix. You have to extract the elements >> yourself. >> >> col = [] >> for row in a: >> col.append(row[0]) >> >> >> You can do this in one line using a list comprehension: >> [ row[0] for row in a ] > > I would suggest this (esp. the list comprehension version) over my > suggestion of zip(). WAAAYYYY more readable. Apparently I'm getting > rusty. > zip is very handy for inverting rows and cols (x's and y's, whatever) >>> a = [(1,2),(3,4),(5,6),(7,8),(9,10)] >>> zip(*a) [(1, 3, 5, 7, 9), (2, 4, 6, 8, 10)] So, I like zip if you're dealing with a in a matrix-ish manner, and list comps for picking selected items out of a list. Emile From thomas at jollybox.de Wed Sep 8 15:55:56 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 8 Sep 2010 21:55:56 +0200 Subject: cPickle segfault with nested dicts in threaded env In-Reply-To: References: Message-ID: <201009082155.56851.thomas@jollybox.de> On Wednesday 08 September 2010, it occurred to Kenneth Dombrowski to exclaim: > Environment is FreeBSD 8, Python 2.5.5 Which architecture? Also, Python 2.5 is frightfully old. There's not really any problem with still using it, but nobody's maintaining it upstream, so don't bother reporting a bug with Python 2.5, as you'll just be told to test a newer version. Check if this still occurs in Python 2.7 and/or Python 3.1, and, if it does, then please do report the bug. Chances are this was actually fixed a couple of years ago. See: http://bugs.python.org/issue3640 (and http://bugs.python.org/issue3338) From pavlovevidence at gmail.com Wed Sep 8 16:03:13 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 8 Sep 2010 13:03:13 -0700 (PDT) Subject: cPickle segfault with nested dicts in threaded env References: Message-ID: <4ce8d0a7-6784-4936-ba82-2ef2f393e8cc@q21g2000prm.googlegroups.com> On Sep 8, 11:58?am, Kenneth Dombrowski wrote: > Hi all, > > Before creating an issue @ bugs.python.org I wanted to run the > following by everyone > > We are having a difficult time with what looks like a cPickle issue > when given a data structure containing >15 nested dictionaries, but > only when threading is involved > > Environment is FreeBSD 8, Python 2.5.5 Since Python 2.7 is released, Python 2.5 is no longer accepting bug fixes, only security fixes. So be aware. > The following diff contains an addition for > /usr/ports/lang/python25/work/Python-2.5.5/Lib/test/test_cpickle.py > which reproduces the issue > > kenneth at kenneth0 Python-2.5.5 $ cat > /tmp/test_cpickle.nested_dicts_in_threaded_env.diff > 1a2 > > > import copy > 2a4 > > import threading > 93a96,105 > > ? ? def test_nested_dicts_in_threaded_env(self): > > ? ? ? ? # segfaults on python2.5.5/FreeBSD 8.0-RELEASE-p2 > > ? ? ? ? def threadloop(): > > ? ? ? ? ? ? x = {} > > ? ? ? ? ? ? for i in range(16): > > ? ? ? ? ? ? ? ? x = {i:copy.copy(x)} > > ? ? ? ? ? ? cPickle.dumps(x, 2) > > ? ? ? ? t = threading.Thread(target=threadloop) > > ? ? ? ? t.start() > > Any thoughts will be appreciated, thanks for looking, Bug. Python should never segfault (unless you're doing bad things with ctypes). Even if threading isn't supported in this case, it should fail with an exception or have undefined behavior, not segfault. I would check to see if the same problem exists on 2.7, and file a bug report if so. If they fix it in 2.7 maybe you could apply the same fix to your own 2.5. Carl Banks From jonnojohnson at gmail.com Wed Sep 8 16:06:15 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 15:06:15 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan wrote: > On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >> I know that I can index into a list of lists like this: >> a=[[1,2,3],[4,5,6],[7,8,9]] >> a[0][2]=3 >> a[2][0]=7 >> >> but when I try to use fancy indexing to select the first item in each >> list I get: >> a[0][:]=[1,2,3] >> a[:][0]=[1,2,3] >> >> Why is this and is there a way to select [1,4,7]? >> -- > > It's not fancy indexing. It's called taking a slice of the existing > list. Look at it this way > a[0] means take the first element of a. The first element of a is [1,2,3] > a[0][:] means take all the elements in that first element of a. All > the elements of [1,2,3] are [1,2,3]. > > a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. > a[:][0] means take the first element of all the elements of a. The > first element of a[:] is [1,2,3]. > > There is no simple way to get [1,4,7] because it is just a list of > lists and not an actual matrix. You have to extract the elements > yourself. > > col = [] > for row in a: > ? ?col.append(row[0]) > > > You can do this in one line using a list comprehension: > [ row[0] for row in a ] > Thanks! (to Andreas too). Totally makes sense now. From tjreedy at udel.edu Wed Sep 8 16:17:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Sep 2010 16:17:02 -0400 Subject: what should __iter__ return? In-Reply-To: <8eo7tiF10cU1@mid.individual.net> References: <8eo7tiF10cU1@mid.individual.net> Message-ID: On 9/7/2010 9:40 PM, Gregory Ewing wrote: > Thomas Jollans wrote: > >> Hmm. Modifying an object while iterating over it isn't a great idea, >> ever: > > I wouldn't say never. How about "Modifying a collection while iterating over it without understanding the dangers is a bad idea." " Algorithms that calculate some kind of > transitive closure can be expressed rather neatly by appending > items to a list being iterated over. Which is one reason list modification while iterating is not prohibited. Deleting items while forward iterating and adding items while backward iterating may miss items unexpectedly. Adding items ahead of forward iteration and deleting items behind backward iterating are ok. The most common example of the latter is successively popping item off a stack. -- Terry Jan Reedy From jonnojohnson at gmail.com Wed Sep 8 16:18:56 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 15:18:56 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 3:06 PM, Jonno wrote: > On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan > wrote: >> On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >>> I know that I can index into a list of lists like this: >>> a=[[1,2,3],[4,5,6],[7,8,9]] >>> a[0][2]=3 >>> a[2][0]=7 >>> >>> but when I try to use fancy indexing to select the first item in each >>> list I get: >>> a[0][:]=[1,2,3] >>> a[:][0]=[1,2,3] >>> >>> Why is this and is there a way to select [1,4,7]? >>> -- >> >> It's not fancy indexing. It's called taking a slice of the existing >> list. Look at it this way >> a[0] means take the first element of a. The first element of a is [1,2,3] >> a[0][:] means take all the elements in that first element of a. All >> the elements of [1,2,3] are [1,2,3]. >> >> a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. >> a[:][0] means take the first element of all the elements of a. The >> first element of a[:] is [1,2,3]. >> >> There is no simple way to get [1,4,7] because it is just a list of >> lists and not an actual matrix. You have to extract the elements >> yourself. >> >> col = [] >> for row in a: >> ? ?col.append(row[0]) >> >> >> You can do this in one line using a list comprehension: >> [ row[0] for row in a ] >> > Thanks! (to Andreas too). Totally makes sense now. > Now if I want to select the first item in every 2nd item of list a (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of indices to use in a more complex for loop? From jonnojohnson at gmail.com Wed Sep 8 16:23:35 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 15:23:35 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: > On Wed, Sep 8, 2010 at 3:06 PM, Jonno wrote: >> On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan >> wrote: >>> On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >>>> I know that I can index into a list of lists like this: >>>> a=[[1,2,3],[4,5,6],[7,8,9]] >>>> a[0][2]=3 >>>> a[2][0]=7 >>>> >>>> but when I try to use fancy indexing to select the first item in each >>>> list I get: >>>> a[0][:]=[1,2,3] >>>> a[:][0]=[1,2,3] >>>> >>>> Why is this and is there a way to select [1,4,7]? >>>> -- >>> >>> It's not fancy indexing. It's called taking a slice of the existing >>> list. Look at it this way >>> a[0] means take the first element of a. The first element of a is [1,2,3] >>> a[0][:] means take all the elements in that first element of a. All >>> the elements of [1,2,3] are [1,2,3]. >>> >>> a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. >>> a[:][0] means take the first element of all the elements of a. The >>> first element of a[:] is [1,2,3]. >>> >>> There is no simple way to get [1,4,7] because it is just a list of >>> lists and not an actual matrix. You have to extract the elements >>> yourself. >>> >>> col = [] >>> for row in a: >>> ? ?col.append(row[0]) >>> >>> >>> You can do this in one line using a list comprehension: >>> [ row[0] for row in a ] >>> >> Thanks! (to Andreas too). Totally makes sense now. >> > > Now if I want to select the first item in every 2nd item of list a > (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of > indices to use in a more complex for loop? > Seems like the simplest way would be: [row[0] for row in a][::2] From tjreedy at udel.edu Wed Sep 8 16:27:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Sep 2010 16:27:02 -0400 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On 9/8/2010 2:55 PM, Jonno wrote: > I know that I can index into a list of lists like this: > a=[[1,2,3],[4,5,6],[7,8,9]] > a[0][2]=3 > a[2][0]=7 > > but when I try to use fancy indexing to select the first item in each > list I get: > a[0][:]=[1,2,3] > a[:][0]=[1,2,3] > > Why is this and is there a way to select [1,4,7]? You are trying to look at a list of lists as an array and have discovered where the asymmetry of the former makes the two non-equivalent. To slice multi-dimensional arrays any which way, you need an appropriate package, such as numpy. -- Terry Jan Reedy From benjamin.kaplan at case.edu Wed Sep 8 16:28:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 8 Sep 2010 16:28:51 -0400 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 4:23 PM, Jonno wrote: > On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: >> On Wed, Sep 8, 2010 at 3:06 PM, Jonno wrote: >>> On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan >>> wrote: >>>> On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >>>>> I know that I can index into a list of lists like this: >>>>> a=[[1,2,3],[4,5,6],[7,8,9]] >>>>> a[0][2]=3 >>>>> a[2][0]=7 >>>>> >>>>> but when I try to use fancy indexing to select the first item in each >>>>> list I get: >>>>> a[0][:]=[1,2,3] >>>>> a[:][0]=[1,2,3] >>>>> >>>>> Why is this and is there a way to select [1,4,7]? >>>>> -- >>>> >>>> It's not fancy indexing. It's called taking a slice of the existing >>>> list. Look at it this way >>>> a[0] means take the first element of a. The first element of a is [1,2,3] >>>> a[0][:] means take all the elements in that first element of a. All >>>> the elements of [1,2,3] are [1,2,3]. >>>> >>>> a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. >>>> a[:][0] means take the first element of all the elements of a. The >>>> first element of a[:] is [1,2,3]. >>>> >>>> There is no simple way to get [1,4,7] because it is just a list of >>>> lists and not an actual matrix. You have to extract the elements >>>> yourself. >>>> >>>> col = [] >>>> for row in a: >>>> ? ?col.append(row[0]) >>>> >>>> >>>> You can do this in one line using a list comprehension: >>>> [ row[0] for row in a ] >>>> >>> Thanks! (to Andreas too). Totally makes sense now. >>> >> >> Now if I want to select the first item in every 2nd item of list a >> (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of >> indices to use in a more complex for loop? >> > Seems like the simplest way would be: > [row[0] for row in a][::2] Yes. You could either do that, or do [row[0] for row in a[::2]]. It doesn't make that much of a difference, unless memory is really tight (doing the ::2 first means your list is smaller to begin with) > -- > http://mail.python.org/mailman/listinfo/python-list > From usenot at geekmail.INVALID Wed Sep 8 16:44:52 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 8 Sep 2010 16:44:52 -0400 Subject: Slice a list of lists? References: Message-ID: <20100908164452.688dd8fd@geekmail.INVALID> On Wed, 8 Sep 2010 15:23:35 -0500 Jonno wrote: > On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: > [snip] > > Now if I want to select the first item in every 2nd item of list a > > (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of > > indices to use in a more complex for loop? > > > Seems like the simplest way would be: > [row[0] for row in a][::2] What you're doing here is selecting every second item of the list of first items of the items in a, not the first items of every second item in a (head spinning yet?). If I'm not completely mindbent right now, these are logically equivalent, but not computationally. Compare [row[0] for row in a][::2] # (your Python code) with [row[0] for row in a[::2]] # (as per your description) The first one is more work for your computer, because it'll pick out the first elements of *all* of the items in a, whereas the second only picks out the first elements of every second item in a (which is only half the amount of "picks" compared to the former). I just thought I'd mention it. Because it might make a difference in one of your programs some day. And because I'm a pedant ;). /W -- INVALID? DE! From thomas at jollybox.de Wed Sep 8 16:51:50 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 8 Sep 2010 22:51:50 +0200 Subject: Automatic delegation in Python 3 In-Reply-To: <4c87966d$0$11113$c3e8da3@news.astraweb.com> References: <4c87966d$0$11113$c3e8da3@news.astraweb.com> Message-ID: <201009082251.50668.thomas@jollybox.de> On Wednesday 08 September 2010, it occurred to Steven D'Aprano to exclaim: > What's going on here? I *think* this has something to do with special > double-underscore methods being looked up on the class, not the instance, > for new-style classes, but I'm not entirely sure. Yes, special methods are looked up on the type. So you have to make sure the type has the methods. > > Unfortunately, I need to use delegation, not inheritance, and I need to > use a new-style class, since I will be using Python 3. How can I do > automatic delegation in Python 3? Is my only hope to give up on the > elegance of automatic delegation, and code all the special methods as > manual delegation? Well, yes, you have to implement all the required special methods in the Delegate class. But there's no reason you have to do it manually. (I've never actually used this in the wild, but it looks like it works) >>> def makeDelegate(o): ... T = type(o) ... class Delegate: ... def __getattr__(self, name): ... return getattr(o, name) ... def __setattr__(self, name, value): ... setattr(self, name, value) ... def makewrapper(method): ... def wrapper(self, *args, **kwargs): ... return method(o, *args, **kwargs) ... return wrapper ... for methodname in dir(T): ... method = getattr(T, methodname) ... if methodname not in ('__getattr__', '__setattr__', ... '__init__', '__new__', '__class__'): ... try: ... setattr(Delegate, methodname, makewrapper(method)) ... except: pass ... return Delegate() ... >>> D = makeDelegate({'a': 1}) >>> D {'a': 1} >>> D['a'] 1 >>> D['a'] = 2 >>> D {'a': 2} >>> D.get('b') >>> D['b'] = True >>> D.get('b') True >>> From jonnojohnson at gmail.com Wed Sep 8 16:54:44 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 15:54:44 -0500 Subject: Slice a list of lists? In-Reply-To: <20100908164452.688dd8fd@geekmail.INVALID> References: <20100908164452.688dd8fd@geekmail.INVALID> Message-ID: On Wed, Sep 8, 2010 at 3:44 PM, Andreas Waldenburger wrote: > On Wed, 8 Sep 2010 15:23:35 -0500 Jonno wrote: > >> On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: >> [snip] >> > Now if I want to select the first item in every 2nd item of list a >> > (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of >> > indices to use in a more complex for loop? >> > >> Seems like the simplest way would be: >> [row[0] for row in a][::2] > > What you're doing here is selecting every second item of the list of > first items of the items in a, not the first items of every second item > in a (head spinning yet?). > > If I'm not completely mindbent right now, these are logically > equivalent, but not computationally. > > Compare > ? ?[row[0] for row in a][::2] ?# (your Python code) > with > ? ?[row[0] for row in a[::2]] ?# (as per your description) > > The first one is more work for your computer, because it'll pick out > the first elements of *all* of the items in a, whereas the second only > picks out the first elements of every second item in a (which is only > half the amount of "picks" compared to the former). > > I just thought I'd mention it. Because it might make a difference in > one of your programs some day. And because I'm a pedant ;). Thanks again. It is nice to know how to do things properly even though in my case it probably won't make much difference. Terry, I would have used numpy arrays (I actually use them later in the code) except the lists in my list aren't all of the same length. From raoulbia at gmail.com Wed Sep 8 17:08:00 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 8 Sep 2010 14:08:00 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> <7xmxrsif45.fsf@ruckus.brouhaha.com> Message-ID: <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> On 8 sep, 14:39, Paul Rubin wrote: > Baba writes: > > But where do you draw the line? Can we not just let people ask > > questions regardless? And let those answer who want to and those who > > don't just ignore the question? That seems so much easier to me. > > The first few times, it's easy to ignore the questions. ?After a few > more times, it becomes easier to ignore the person asking the questions, > and not even look at the questions. > > The answer to many of your questions also is not "research it online", > but rather, "figure it out with your own creativity". ?That's what being > a programmer is about--figuring out solutions that don't already exist > elsewhere. Hi Paul If i look where i was 4 weeks ago and the progress i made in learning Python i am quite delighted. This forum has helped me and i appreciate it. I don't think i will ever tell a beginner to "do me a favour" and to look things up by himself nor will i use the RTFM line (refering to Bruno's post), i'd just be nice and helpful as everyone here is. Didn't realise ego's were that big but so is mine i suppose... kind regards Baba From russandheather at gmail.com Wed Sep 8 17:18:52 2010 From: russandheather at gmail.com (Russell Warren) Date: Wed, 8 Sep 2010 14:18:52 -0700 (PDT) Subject: Confused about nested scopes and when names get added to namespaces Message-ID: I'm having trouble understanding when variables are added to namespaces. I thought I understood it, but my nested function examples below have me very confused. In each test function below I have an x variable (so "x" is in the namespace of each test function). I also have a nested function in each (innerFunc) that has different flavors of trying to access or assign a variable named "x". --- def test1(): print "running test1..." x = 1 def innerFunc(): print "inner locals():", print "%s" % locals() # x not present (yet) x = 2 print x innerFunc() print "x left as %s\n" % x def test2(): print "running test2..." x = 1 def innerFunc(): print "inner locals():", print "%s" % locals() # x not present innerFunc() print "x left as %s\n" % x def test3(): print "running test3..." x = 1 def innerFunc(): print "inner locals():", print "%s" % locals() # how is x in locals in this case?? print x innerFunc() print "x left as %s\n" % x test1() test2() test3() --- With the nested scope rules, I thought that *at the time of* trying to access an object with a given name, if the name was not available in the namespace of the local function python would then check the namespace of the parent function. My tests above don't seem to match this. Specifically my "at the time of" assumption. What is happening in test3? How is it that "x" ends up in the local namespace before it is ever referenced? It seems that, prior to execution time, the python compiler is "magically" determining that I'm referencing a particular name before assignment and shoving it into the local namespace so it can be used. I did not think the compiler went into function bodies, aside from basic syntax checking. Further confusing me (or confirming the compiler behavior) is adding a 4th test with only one added line... def test4(): print "running test4..." x = 1 def innerFunc(): print "inner locals():", print "%s" % locals() # how is x in locals in this case?? print x x = 2 #ONLY ADDED LINE TO TEST3 innerFunc() print "x left as %s\n" % x In this case I get "UnboundLocalError: local variable 'x' referenced before assignment". I think this means that the compiler (prior to runtime) inspected the code, determined I will do an assignment, decided _not_ to bring the parent's x into the local namespace, and as a result caused the unbound name problem at runtime. It seems that the parent's "x" is brought directly into the local namespace (when appropriate), rather than the namespace lookup just moving up the hierarchy when not found. This is confusing to me and is making me question my understanding of namespace lookups. Are nested scopes a special case where the lookup is handled differently? What if I want to change the value of the parent's "x"? test4 implies that I can't. Have I got this right? Can someone please clarify what is going on? From russandheather at gmail.com Wed Sep 8 17:19:45 2010 From: russandheather at gmail.com (Russell Warren) Date: Wed, 8 Sep 2010 14:19:45 -0700 (PDT) Subject: Confused about nested scopes and when names get added to namespaces References: Message-ID: <3d88fe15-0044-4817-8a51-918b97b2cb39@11g2000yqq.googlegroups.com> My tests were run in python 2.6.5. From robert.kern at gmail.com Wed Sep 8 17:26:15 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 08 Sep 2010 16:26:15 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On 9/8/10 3:27 PM, Terry Reedy wrote: > On 9/8/2010 2:55 PM, Jonno wrote: >> I know that I can index into a list of lists like this: >> a=[[1,2,3],[4,5,6],[7,8,9]] >> a[0][2]=3 >> a[2][0]=7 >> >> but when I try to use fancy indexing to select the first item in each >> list I get: >> a[0][:]=[1,2,3] >> a[:][0]=[1,2,3] >> >> Why is this and is there a way to select [1,4,7]? > > You are trying to look at a list of lists as an array and have discovered where > the asymmetry of the former makes the two non-equivalent. To slice > multi-dimensional arrays any which way, you need an appropriate package, such as > numpy. A motivating example: [~] |1> import numpy [~] |2> a = numpy.array([[1,2,3],[4,5,6],[7,8,9]]) [~] |3> a array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) [~] |4> a[0,2] 3 [~] |5> a[2,0] 7 [~] |6> a[0,:] array([1, 2, 3]) [~] |7> a[:,0] array([1, 4, 7]) -- 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 Wed Sep 8 17:59:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 21:59:56 GMT Subject: what should __iter__ return? References: <8eo7tiF10cU1@mid.individual.net> Message-ID: <4c88075c$0$11113$c3e8da3@news.astraweb.com> On Wed, 08 Sep 2010 16:17:02 -0400, Terry Reedy wrote: > On 9/7/2010 9:40 PM, Gregory Ewing wrote: >> Thomas Jollans wrote: >> >>> Hmm. Modifying an object while iterating over it isn't a great idea, >>> ever: >> >> I wouldn't say never. > > How about "Modifying a collection while iterating over it without > understanding the dangers is a bad idea." "... unless you're being paid by the hour for debugging your code." *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 18:02:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 22:02:07 GMT Subject: Automatic delegation in Python 3 References: <4c87966d$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c8807df$0$11113$c3e8da3@news.astraweb.com> On Wed, 08 Sep 2010 15:45:46 -0400, Terry Reedy wrote: [...] >> Unfortunately, I need to use delegation, not inheritance, and I need to >> use a new-style class, since I will be using Python 3. How can I do >> automatic delegation in Python 3? Is my only hope to give up on the >> elegance of automatic delegation, and code all the special methods as >> manual delegation? > > Based on the above, it seems so. But I would search a bit more for > delegation and proxy object and python 3 to see what others have done. That's what I was afraid of. Oh well. Thanks to those who answered. -- Steven From cmpython at gmail.com Wed Sep 8 18:29:56 2010 From: cmpython at gmail.com (CM) Date: Wed, 8 Sep 2010 15:29:56 -0700 (PDT) Subject: are there pros or contras, keeping a connection to a (sqlite) database ? References: Message-ID: On Sep 8, 1:09?pm, Stef Mientki wrote: > ?hello, > > I wrap my database in some class, and on creation of the instance, a connection to the database is > created, > and will stay connected until the program exists, something like this: > > ? ? self.conn = sqlite3.connect ( self.filename ) > > Now I wonder if there are pros or contras to keep the connection to the database continuously ?"open" ? > > thanks, > Stef Mientki I do the same thing--good to hear from John that keeping it open is OK. But another question that this provokes, at least for me is: what happens when you call .connect() on the same database multiple times from within different parts of the same app? Is that bad? And is it that there now multiple connections to the database, or one connection that has multiple names in different namespaces within the app? I'm not even sure what a "connection" really is; I assumed it was nothing more than a rule that says to write to the database with the file named in the parentheses. Further elaboration from the community would be helpful. Thanks, Che From barshirtcliff at gmail.com Wed Sep 8 18:32:24 2010 From: barshirtcliff at gmail.com (Bar Shirtcliff) Date: Wed, 8 Sep 2010 16:32:24 -0600 Subject: accessing a text file In-Reply-To: <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> <7xmxrsif45.fsf@ruckus.brouhaha.com> <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> Message-ID: <19592.3832.281882.702641@bar-macbook.local> | Hi Paul | | If i look where i was 4 weeks ago and the progress i made in learning | Python i am quite delighted. This forum has helped me and i appreciate | it. I don't think i will ever tell a beginner to "do me a favour" and | to look things up by himself nor will i use the RTFM line (refering to | Bruno's post), i'd just be nice and helpful as everyone here is. | Didn't realise ego's were that big but so is mine i suppose... | HEREow can you be learning so much python if you're constantly expressing your personal tastes and generally posturing on the Python forum? I know how words can capture one into a realm of pretended meaning and significance. The nice thing about programming, as opposed to the humanities, is that it's about actually doing things, or rather, actually building things that do things for you. Let's get to it! Best, Bar -- ---------------------------------------------------------------------- "All men are born mad. Some remain so." --Samuel Beckett From aahz at pythoncraft.com Wed Sep 8 18:45:29 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Sep 2010 15:45:29 -0700 Subject: Confused about nested scopes and when names get added to namespaces References: Message-ID: In article , Russell Warren wrote: > >def test4(): > print "running test4..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # how is x in locals in this case?? > print x > x = 2 #ONLY ADDED LINE TO TEST3 > innerFunc() > print "x left as %s\n" % x > >In this case I get "UnboundLocalError: local variable 'x' referenced >before assignment". I think this means that the compiler (prior to >runtime) inspected the code, determined I will do an assignment, >decided _not_ to bring the parent's x into the local namespace, and as >a result caused the unbound name problem at runtime. Bingo! >It seems that the parent's "x" is brought directly into the local >namespace (when appropriate), rather than the namespace lookup just >moving up the hierarchy when not found. This is confusing to me and >is making me question my understanding of namespace lookups. Are >nested scopes a special case where the lookup is handled differently? > >What if I want to change the value of the parent's "x"? test4 implies >that I can't. You need Python 3.x and the "nonlocal" keyword. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From emile at fenx.com Wed Sep 8 18:47:38 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 08 Sep 2010 15:47:38 -0700 Subject: Confused about nested scopes and when names get added to namespaces In-Reply-To: References: Message-ID: On 9/8/2010 2:18 PM Russell Warren said... > I'm having trouble understanding when variables are added to > namespaces. I thought I understood it, but my nested function > examples below have me very confused. Take a look at PEP 227 where nested scopes are introduced. http://www.python.org/dev/peps/pep-0227/ From the PEP: If a name is used within a code block, but it is not bound there and is not declared global, the use is treated as a reference to the nearest enclosing function region. > > In each test function below I have an x variable (so "x" is in the > namespace of each test function). I also have a nested function in > each (innerFunc) that has different flavors of trying to access or > assign a variable named "x". > > --- > def test1(): > print "running test1..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # x not present (yet) > x = 2 > print x > innerFunc() > print "x left as %s\n" % x > > def test2(): > print "running test2..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # x not present > innerFunc() > print "x left as %s\n" % x > > def test3(): > print "running test3..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # how is x in locals in this case?? > print x > innerFunc() > print "x left as %s\n" % x > > test1() > test2() > test3() > > --- > > With the nested scope rules, I thought that *at the time of* trying to > access an object with a given name, if the name was not available in > the namespace of the local function python would then check the > namespace of the parent function. My tests above don't seem to match > this. Specifically my "at the time of" assumption. > > What is happening in test3? How is it that "x" ends up in the local > namespace before it is ever referenced? It seems that, prior to > execution time, the python compiler is "magically" determining that > I'm referencing a particular name before assignment and shoving it > into the local namespace so it can be used. I did not think the > compiler went into function bodies, aside from basic syntax checking. > > Further confusing me (or confirming the compiler behavior) is adding a > 4th test with only one added line... > > def test4(): > print "running test4..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # how is x in locals in this case?? > print x > x = 2 #ONLY ADDED LINE TO TEST3 > innerFunc() > print "x left as %s\n" % x > > In this case I get "UnboundLocalError: local variable 'x' referenced > before assignment". I think this means that the compiler (prior to > runtime) inspected the code, determined I will do an assignment, x is local by virtue of being assigned to within the function. > decided _not_ to bring the parent's x into the local namespace, and as > a result caused the unbound name problem at runtime. > > It seems that the parent's "x" is brought directly into the local > namespace (when appropriate), rather than the namespace lookup just > moving up the hierarchy when not found. This is confusing to me and > is making me question my understanding of namespace lookups. Are > nested scopes a special case where the lookup is handled differently? > > What if I want to change the value of the parent's "x"? test4 implies > that I can't. You can't ever unless x is mutable. > > Have I got this right? Can someone please clarify what is going on? > I don't have time to go into further details at the moment. HTH, Emile From no.email at nospam.invalid Wed Sep 8 18:52:47 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 15:52:47 -0700 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> <4c879bd7$0$11113$c3e8da3@news.astraweb.com> <4c87a815$0$11113$c3e8da3@news.astraweb.com> Message-ID: <7xaanr3l1c.fsf@ruckus.brouhaha.com> Grant Edwards writes: > I find it much easier to screw things up using the > "exceptional return value" method than the "exception raise" method. That may be partly due to Python's not-so-good facilities for implementing the "exceptional return value" method. To be fair, plenty of other languages have similar shortcomings and it's mostly in more recent languages that the problem has really been recognized, and addressed with features like option types. From no.email at nospam.invalid Wed Sep 8 18:55:31 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 15:55:31 -0700 Subject: cPickle segfault with nested dicts in threaded env References: <4ce8d0a7-6784-4936-ba82-2ef2f393e8cc@q21g2000prm.googlegroups.com> Message-ID: <7x62yf3kws.fsf@ruckus.brouhaha.com> Carl Banks writes: > Since Python 2.7 is released, Python 2.5 is no longer accepting bug > fixes, only security fixes. So be aware. Segfaults should be treated as security holes unless there's convincing reasons that no exploit is possible. So the bug should be reported against 2.5 as well as later versions. From barshirtcliff at gmail.com Wed Sep 8 18:56:11 2010 From: barshirtcliff at gmail.com (Bar Shirtcliff) Date: Wed, 8 Sep 2010 16:56:11 -0600 Subject: accessing a text file In-Reply-To: <19592.3832.281882.702641@bar-macbook.local> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> <7xmxrsif45.fsf@ruckus.brouhaha.com> <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> <19592.3832.281882.702641@bar-macbook.local> Message-ID: <19592.5259.240514.451281@bar-macbook.local> | HEREow can you be learning so much python if you're constantly expressing typo there. I'm not sure how that happens, sometimes, but it's an untimely abbrev-expansion, in emacs VM. I meant to say, "How can you..." Cheers, Bar From jmayfield at cradlepoint.com Wed Sep 8 19:03:04 2010 From: jmayfield at cradlepoint.com (Justin Mayfield) Date: Wed, 8 Sep 2010 17:03:04 -0600 Subject: Bit fields in python? In-Reply-To: References: Message-ID: <4C881628.1010304@cradlepoint.com> Instead of rewriting your code you might consider wrapping it with the C-API. I prefer this approach (over ctypes) for anything "low level". http://docs.python.org/c-api/ On 09/06/2010 10:06 PM, Kwan Lai Cheng wrote: > Hi, > I'm trying to rewrite a c program in python & encountered several > problems. I have some data structures in my c program like below: > typedef struct > { > unsigned short size; > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsigned short var_a3:2; > unsigned short var_a4:2; > unsigned int var_a5; > }structa; > typedef struct > { > unsigned short size; > unsigned char reserved:4; > unsigned char var_b1:1; > unsigned char var_b2:1; > unsigned char var_b3:1; > unsigned char var_b4:1; > structa var_structa; > }structb; > I tried to code the above in python but only got this far: > class StructA(object): > def __init__(self, size=0) > self.size = size > class StructB(object): > def __init__(self, size=0) > Any equivalent for c data structures & bit fields in python? And how > do I define var_structa (in structb) in python? > Regards, > Kwan. > !SIG:4c85bc4844361237431282! -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Sep 8 19:13:37 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 09 Sep 2010 00:13:37 +0100 Subject: accessing a text file In-Reply-To: <19592.5259.240514.451281@bar-macbook.local> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> <7xmxrsif45.fsf@ruckus.brouhaha.com> <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> <19592.3832.281882.702641@bar-macbook.local> <19592.5259.240514.451281@bar-macbook.local> Message-ID: <4C8818A1.30202@mrabarnett.plus.com> On 08/09/2010 23:56, Bar Shirtcliff wrote: > | HEREow can you be learning so much python if you're constantly expressing > > typo there. I'm not sure how that happens, sometimes, but it's an > untimely abbrev-expansion, in emacs VM. > > I meant to say, "How can you..." > An unkind soul would say that "it's a poor workman who blames his tools", but as it's emacs... ;-) From speeze.pearson at gmail.com Wed Sep 8 19:42:07 2010 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Wed, 8 Sep 2010 16:42:07 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> <39c85ff7-f1bb-47ad-95b3-bcb9ce9c0c5b@i4g2000prf.googlegroups.com> Message-ID: All right, thank you for helping! I'd had a little voice in the back of my mind nagging me that it might not be logical to include a bunch of classes and function definitions in my startup file, but I never got around to splitting it up. The module/script distinction makes sense, and it seems more elegant, too. Also, my program works now that I've rearranged things, which is a plus. Thanks! From ldo at geek-central.gen.new_zealand Wed Sep 8 20:38:04 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 09 Sep 2010 12:38:04 +1200 Subject: [Tutor] Arguments from the command line References: Message-ID: In message , Hugo Arts wrote: > sys.argv is a list of all arguments from the command line ... Interesting that Python didn?t bother to mimic the underlying POSIX convention of passing the command line as arguments to the mainline routine. I always felt it was more useful to have command arguments directly accessible as globals, rather than having to pass them from the mainline. From ldo at geek-central.gen.new_zealand Wed Sep 8 20:41:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 09 Sep 2010 12:41:20 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> Message-ID: In message <7xeid9gtuq.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: > >> That reinforces my point, about how easy it was to check the correctness >> of the code. In this case one simple fix, like this ... >> would render the code watertight. See how easy it is? > > Well, no, it's irrelevant how easy it is to fix the issue after it's > pointed out. In that case, I can similarly discount your attempts to fix up issues with garbage collectors after they?re pointed out, can I not? > Part of the problem is C itself. And yet, what are these complicated garbage collectors, that you intend relying on to work correctly with all their layers of tricks upon tricks, written in? C. From no.email at nospam.invalid Wed Sep 8 21:20:48 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 18:20:48 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> Message-ID: <7xfwxj67bj.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > In that case, I can similarly discount your attempts to fix up issues with > garbage collectors after they?re pointed out, can I not? Adapting GC algorithms to improve their performance or better use the capabilities of new hardware is much different than saying they didn't work in the first place. They've been around for 5 decades, they (like Python programs) work fine if you don't mind the performance cost, and for many applications that cost is acceptable even for quite simple and naive GC's. The continued work is to get that cost down even further. (And before criticizing GC performance, Have you ever profiled CPython to see how much time it's spending messing with reference counts? I didn't think so). >> Part of the problem is C itself. > And yet, what are these complicated garbage collectors, that you intend > relying on to work correctly with all their layers of tricks upon tricks, > written in? C. What tricks on tricks? Even the fanciest GC's are orders of magnitude less complicated than any serious database, optimizing compiler, OS kernel, file system, etc. Real-world software is complicated. Get used to that fact, and look for ways to manage the complexity and keep complex programs safe. Choosing to program with unsafe methods because you wish the complexity didn't exist is just deluded. It actually seems pretty crazy to me to write a garbage collector in C today even though it a GC needs unsafe pointer operations in a few places. C made some sense in the 1980's when computers were smaller and people didn't know better. A lot of the C code around today is legacy code from that era. These days it makes more sense to use a safe language with a few isolated "jailbreaks" (like an OS kernel that has a few lines of assembly code) than to write the whole thing in a language whose unsafety is everywhere. Here's a good paper by R. Fateman (criticizing C) that I just came across: http://www.franz.com/resources/educational_resources/white_papers/fault.prevention.pdf He suggests using Lisp instead, but one can't have everything ;-). FWIW, here are a couple pages about verifying GC's: http://flint.cs.yale.edu/flint/publications/hgc.html http://www.cs.technion.ac.il/~erez/Papers/verified-gc-popl09.pdf etc. I just don't understand that weird agenda you seem to have. But whatever. From ben+python at benfinney.id.au Wed Sep 8 21:31:04 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Sep 2010 11:31:04 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <87sk1jaejr.fsf@benfinney.id.au> Baba writes: > Thanks for your feedback. My question is: Who owns this forum? If we > all do then we are allowed to post questions that are simple and that > could otherwise be answered by doing research. That's a rather subservient perspective. Why are you seeking permission to ask questions? Why do you raise the issue of whether one is *allowed* to ask questions? If you take advice and requests as commandments, then I think that's pretty close to the root of the communication failures here. When someone asks you to change your behaviour, or describes the possible consequences that your behaviour entails, they're treating you as a responsible adult, not as a slave or infant. > It is just unfriendly to tell someone to go and look it up by > themselves. Yes, to *tell* them to do it would be unfriendly. You, however, received *requests* that you do so, with reasons why. Please help us all ? and you are included in ?us all? ? by learning the difference between a command and a request. -- \ ?It is difficult to get a man to understand something when his | `\ salary depends upon his not understanding it.? ?Upton Sinclair, | _o__) 1935 | Ben Finney From ben+python at benfinney.id.au Wed Sep 8 21:33:18 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Sep 2010 11:33:18 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <87occ7aeg1.fsf@benfinney.id.au> Grant Edwards writes: > I'm sure you'd prefer that everything was handed to you for free on a > silver platter with a side order of beer and cookies. I'd prefer I was > 20 years younger and 30 pounds lighter. Life's tough that way. Hell no. I'd prefer to have the total of my life experience and just have my *body* be twenty years younger :-) -- \ ?The greatest tragedy in mankind's entire history may be the | `\ hijacking of morality by religion.? ?Arthur C. Clarke, 1991 | _o__) | Ben Finney From invalid at invalid.invalid Wed Sep 8 22:03:15 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 9 Sep 2010 02:03:15 +0000 (UTC) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <87occ7aeg1.fsf@benfinney.id.au> Message-ID: On 2010-09-09, Ben Finney wrote: > Grant Edwards writes: > >> I'm sure you'd prefer that everything was handed to you for free on a >> silver platter with a side order of beer and cookies. I'd prefer I was >> 20 years younger and 30 pounds lighter. Life's tough that way. > > Hell no. I'd prefer to have the total of my life experience and just > have my *body* be twenty years younger :-) I'd have to think about that for a while. A little bit of innocent optimism might be nice... -- Grant From robert.kern at gmail.com Wed Sep 8 23:23:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 08 Sep 2010 22:23:46 -0500 Subject: [Tutor] Arguments from the command line In-Reply-To: References: Message-ID: On 9/8/10 7:38 PM, Lawrence D'Oliveiro wrote: > In message, Hugo Arts > wrote: > >> sys.argv is a list of all arguments from the command line ... > > Interesting that Python didn?t bother to mimic the underlying POSIX > convention of passing the command line as arguments to the mainline routine. There *is* no mainline routine in Python. -- 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 aahz at pythoncraft.com Wed Sep 8 23:53:10 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Sep 2010 20:53:10 -0700 Subject: cPickle segfault with nested dicts in threaded env References: Message-ID: In article , Thomas Jollans wrote: > >Also, Python 2.5 is frightfully old. [...] "Frightfully"??? I'm sure plenty of people are still using Python 2.3 in production environments (certainly my last job did as of 1.5 years ago, and I would be mildly surprised if they upgraded by now). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From steve-REMOVE-THIS at cybersource.com.au Thu Sep 9 00:02:12 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 09 Sep 2010 04:02:12 GMT Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> Message-ID: <4c885c44$0$28664$c3e8da3@news.astraweb.com> On Thu, 09 Sep 2010 12:41:20 +1200, Lawrence D'Oliveiro wrote: >> Part of the problem is C itself. > > And yet, what are these complicated garbage collectors, that you intend > relying on to work correctly with all their layers of tricks upon > tricks, written in? C. Not necessarily. Pascal, despite the contempt it is held in by university computer science departments, isn't quite dead, and some Pascal compilers use garbage collectors written in Pascal. FreePascal, I believe, is one of them. Likewise for other not-dead-yet low-level languages like Ada and Forth. As surprising as it seems to many, C is not the only low-level language around suitable for writing high-quality, efficient code. Just ask the Lisp community, which is thriving. For some definition of thriving. Admittedly C has far more attention to it than the others, so [insert weasel words here] the best C compilers tend to produce more efficient code than the best of the others, but Pascal, Ada and similar give you more security than C. I believe that when computer scientists of the future look back at the last few decades, they will judge that on balance C did more harm than good. Not that C is the only language that people can write buggy or insecure code, but C does tend to give the bugs so much help... :) -- Steven From steve-REMOVE-THIS at cybersource.com.au Thu Sep 9 00:58:02 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 09 Sep 2010 04:58:02 GMT Subject: [Tutor] Arguments from the command line References: Message-ID: <4c886959$0$28664$c3e8da3@news.astraweb.com> On Thu, 09 Sep 2010 12:38:04 +1200, Lawrence D'Oliveiro wrote: > In message , Hugo > Arts wrote: > >> sys.argv is a list of all arguments from the command line ... > > Interesting that Python didn?t bother to mimic the underlying POSIX > convention of passing the command line as arguments to the mainline > routine. What mainline routine? > I always felt it was more useful to have command arguments directly > accessible as globals, rather than having to pass them from the > mainline. http://c2.com/cgi/wiki?GlobalVariablesAreBad That's why we have namespaces. If you need the command line arguments, you just import sys and you have access to them. -- Steven From ldo at geek-central.gen.new_zealand Thu Sep 9 01:45:04 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 09 Sep 2010 17:45:04 +1200 Subject: [Tutor] Arguments from the command line References: Message-ID: In message , Dennis Lee Bieber wrote: > None of them have command line arguments "passed" in to some > starting point -- all had to use some runtime library function to ask > for the command line contents. It?s always a language-specific routine, since at the underlying POSIX level (exposed by C), the command line is passed as arguments to the mainline routine. From yue.nicholas at gmail.com Thu Sep 9 04:30:28 2010 From: yue.nicholas at gmail.com (Nicholas) Date: Thu, 9 Sep 2010 01:30:28 -0700 (PDT) Subject: [Q] Function Point Analysis (FPA) - Equivalent lines of code of Python Message-ID: <168f109f-834f-4e99-88cf-35e1ffdc6297@b4g2000pra.googlegroups.com> Hi, In FPA, there are tables which shows equivalent lines of code for each Function Point (FP) for a number of programming languages. e.g. http://www.qsm.com/?q=resources/function-point-languages-table/index.html However, I have yet to find the figures for Python. Is someone able to advise the closest language equivalent. Regards From news1234 at free.fr Thu Sep 9 04:41:50 2010 From: news1234 at free.fr (News123) Date: Thu, 09 Sep 2010 10:41:50 +0200 Subject: are there pros or contras, keeping a connection to a (sqlite) database ? In-Reply-To: References: Message-ID: <4c889dce$0$4622$426a34cc@news.free.fr> On 09/09/2010 12:29 AM, CM wrote: > On Sep 8, 1:09 pm, Stef Mientki wrote: >> hello, >> >> I wrap my database in some class, and on creation of the instance, a connection to the database is >> created, >> and will stay connected until the program exists, something like this: >> >> self.conn = sqlite3.connect ( self.filename ) >> >> Now I wonder if there are pros or contras to keep the connection to the database continuously "open" ? >> >> thanks, >> Stef Mientki > > I do the same thing--good to hear from John that keeping it open is > OK. > > But another question that this provokes, at least for me is: what > happens when you call .connect() on the same database multiple times > from within different parts of the same app? Is that bad? And is it > that there now multiple connections to the database, or one connection > that has multiple names in different namespaces within the app? CM, Do you talk about a multithreaded environment? or only about an environment with logically separate blocks (or with generators), and multiple objects each keeping their own connection. As far as I know sqlite can be compiled to be thread safe, but is not necessarily be default. No idea about the library used b python. I personally just started sqlite in one of my apps with multithrading and in order to be safe I went for the conservative approach connect, perform transactions, commit and close. However this is probably overkill and later in time I might also ty to keep connections open in order to increse performance. > I'm not even sure what a "connection" really is; I assumed it was > nothing more than a rule that says to write to the database with the > file named in the parentheses. > > Further elaboration from the community would be helpful. > > Thanks, > Che From no.email at nospam.invalid Thu Sep 9 04:45:04 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 09 Sep 2010 01:45:04 -0700 Subject: [Q] Function Point Analysis (FPA) - Equivalent lines of code of Python References: <168f109f-834f-4e99-88cf-35e1ffdc6297@b4g2000pra.googlegroups.com> Message-ID: <7x4odz5mr3.fsf@ruckus.brouhaha.com> Nicholas writes: > e.g. http://www.qsm.com/?q=resources/function-point-languages-table/index.html > However, I have yet to find the figures for Python. > Is someone able to advise the closest language equivalent. That table looks pretty bogus, but of the languages on the list, perl is probably about the closest to python in spirit and code density. From jaksonaquino at gmail.com Thu Sep 9 06:07:56 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Thu, 9 Sep 2010 07:07:56 -0300 Subject: SendKeys and Python 2.7 Message-ID: Hi, I would like to send code from Vim [1] to R [2] on Microsoft Windows. Vim needs python 2.7 but the pre-compiled SendKeys module [3] is only avaiable for python 2.6. How can I make SendKeys work with python 2.7? I don't know how to compile python code. Is there an alternative to SendKeys? I'm sending to R only "^v" to paste the content of the clipboard. Thanks, Jakson Aquino [1] http://www.vim.org/ [2] http://www.r-project.org/ [3] http://www.rutherfurd.net/python/sendkeys/#binaries From martin at address-in-sig.invalid Thu Sep 9 06:12:44 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 9 Sep 2010 10:12:44 +0000 (UTC) Subject: [Tutor] Arguments from the command line References: Message-ID: On Wed, 08 Sep 2010 21:58:49 -0700, Dennis Lee Bieber wrote: > On Thu, 09 Sep 2010 12:38:04 +1200, Lawrence D'Oliveiro > declaimed the following in > gmane.comp.python.general: > >> In message , Hugo >> Arts wrote: >> >> > sys.argv is a list of all arguments from the command line ... >> >> Interesting that Python didn?t bother to mimic the underlying POSIX >> convention of passing the command line as arguments to the mainline >> routine. >> > What "mainline routine"... The only programming language(s) I've > ever used that requires there be something called "main" in order to > start a program is the C/C++ family. > Java uses a method defined as "public static void main(String[] args)" > My college COBOL never used multifile assignments, so I'm not sure > if there was a difference between main and linked modules. > There isn't, but command line argument passing is implementation- dependent and is complicated by the ability to define callable sub- programs in the same source file as the main program. The most general method is to use ACCEPT statements. MicroFocus COBOL uses "ACCEPT ... FROM ARGUMENT-NUMBER", AIX COBOL uses a special system call and ICL 2900 COBOL and IBM COBOL/400, where the command line uses function call notation, map the command line arguments into a LINKAGE SECTION. In short: this area of COBOL is a mess. PL/I specifies the main procedure with an OPTIONS(MAIN) clause and declares the integer ARGC_ and pointer ARGV_ variables in it, which are used like their C equivalents. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From morfeokmg at gmail.com Thu Sep 9 07:25:51 2010 From: morfeokmg at gmail.com (Mauricio Martinez Garcia) Date: Thu, 9 Sep 2010 06:25:51 -0500 Subject: cath a timeout of httplib (Python 2.6.5) Message-ID: Hi!. I have a problem with httplib and timeout. (I use python 2.6.5 and httplib) I have the next code for the http connection (its a WebService Client). =================================================================== def ejecutaComandos(self,opcion, URL, commandString, conn, id): #pdb.set_trace() #fechatransacciones = conciliatorTime() #status = conn.status #date_transacc = fechatransacciones.getCompleteDate() try: try: enviaCommand = conn.request("POST", str(URL), commandString) respuestaCommand = conn.getresponse() except Exception as e: print 'Error de conexion: ',e #intentar=raw_input("Desea intentar nuevamente (S/N) : ") exit(1) respuestaWSDL = respuestaCommand.read() #print respuestaCommand nom_rand = str(random.choice('lmnopqrstuvwxyzABCDEFGHIJ'))+str(random.choice('abcdefghijk')) FileRand = nom_rand+'_tmp.xml' newFile = creaArchivos(FileRand,self.output) a = newFile.creaFile('w') #a = open('../output/responseXML.tmp', 'w') a.write(respuestaWSDL) a.close() #print XP_LOG+'respuesta de HLAPI recibida...'+str(date_transacc) #return respuestaWSDL return a.name #except httplib.HTTPException as he: except Exception as he: print "Error de ejecucion ...: %s " % (he) else: print "Error inesperado..." =================================================================== I need resend the command when a timeout error present, my idea its use a "while". =================================================================== while (intentar=='S'): try: enviaCommand = conn.request("POST", str(URL), commandString) respuestaCommand = conn.getresponse() raise Exception except Exception as e: print 'Error de conexion: ',e intentar=raw_input("Desea intentar nuevamente (S/N) : ") if (intentar=='N'): exit(1) =================================================================== But the information of "enviaCommand" it is lost, and it been only "None", then fail resend. As I can resend the information without the command loses itself. Greetings and tanks!. -- Mauricio Martinez Garcia morfeokmg at gmail.com "Si encuentras un tr?bol de cuatro hojas..., hallaras la felicidad. Pero ?Sabes?, seguramente no la encontrar?s, porque la felicidad se encuentra en silencio guardada en una jaula. EL trebol de Cuatro hojas nunca ser? de nadie... ?Que te parece si te adue?as de un tr?bol de tres hojas?..." "???????, ???????, ????????, ??????, ????, ????????, ????, ??????, ??????, ????, ???????, ???????, ????????????, ???????????, ?????????????, ?????????, ?????????, ???????, ??????, ?????????, ?????????, ????, ???????, ????"???", ?????? ??, ????? ?????? ?????? ???????? ??"???" ???????? ??????????" -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Thu Sep 9 07:28:40 2010 From: robin at reportlab.com (Robin Becker) Date: Thu, 09 Sep 2010 12:28:40 +0100 Subject: 32 bit bdist_wininst vs x64 platform Message-ID: <4C88C4E8.6080003@chamonix.reportlab.co.uk> A reportlab user is using 32 bit python on x64 win 2003. he has a problem installing our bdist_wininst exe because the installer cannot find python. Apparently the installer is looking at HKLM\Software to locate python, but on x64 32 bit program requests get redirected to HKLM\Software\Wow6432Node (Extended explanation in KB article 896459). Is this fixable by me making a local patch to my distutils to check for the real platform and modifying the RegOpenKeyEx call? Or is there some distutils magic that I'm missing? Does anyone know if the bdist_msi might be better? -- Robin Becker From Dominique.Holzwarth at ch.talaris.com Thu Sep 9 07:46:26 2010 From: Dominique.Holzwarth at ch.talaris.com (Holzwarth, Dominique (Berne Branch)) Date: Thu, 9 Sep 2010 12:46:26 +0100 Subject: importing module Message-ID: Hi all Lets assume I have the following structure of directories and python modules: Root-dir |_dir1 |_ script1.py |_dir2 |_ script2.py |_sudir2 |_ script3.py Is it possible to import script1 into script2 and script3? Or do have to put script1.py into the Lib\site-packages folder of my Python installation so that it'll be in the standard module search path? Thx & greets Dominique ***************************************************************************** This e-mail and any files attached are strictly confidential, may be legally privileged and are intended solely for the addressee. If you are not the intended recipient please notify the sender immediately by return email and then delete the e-mail and any attachments immediately. The views and or opinions expressed in this e-mail are not necessarily the views of Talaris Holdings Limited or any of its subsidiaries and the Talaris Group of companies, their directors, officers and employees make no representation about and accept no liability for its accuracy or completeness. You should ensure that you have adequate virus protection as the Talaris Group of companies do not accept liability for any viruses. Talaris Holdings Limited Registered No. 6569609 and Talaris Limited Registered No 6569621 are both registered in England with their registered office at: Talaris House, Crockford Lane, Chineham Business Park, Basingstoke, RG24 8QZ ***************************************************************************** From marduk at letterboxes.org Thu Sep 9 07:51:23 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 09 Sep 2010 07:51:23 -0400 Subject: SendKeys and Python 2.7 In-Reply-To: References: Message-ID: <1284033083.3449.8.camel@paska> On Thu, 2010-09-09 at 07:07 -0300, Jakson A. Aquino wrote: > Vim needs python 2.7 >From where do you base this assertion? I have been using vim 7.3 (with embedded python) with python 2.6 pretty much since it has been released. :version VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Aug 29 2010 07:21:44) [...] :python import sys; print sys.version 2.6.5 (release26-maint, Aug 28 2010, 21:57:54) [GCC 4.4.4] From heniser at yahoo.com Thu Sep 9 08:23:14 2010 From: heniser at yahoo.com (Ryan) Date: Thu, 9 Sep 2010 05:23:14 -0700 (PDT) Subject: Catching a SIGSEGV signal on an import Message-ID: Is there anyway to catch a SIGSEGV signal that results from an import? I'd like to get a list of all modules on the sys.path. The module pkgutil has a nice method, walk_packages, to do just that. But, there is a third party extension that throws a SIGSEGV when imported. I tried to create a signal handler with the signal module like: #!/bin/env python import pkgutil import signal import traceback def handler(signal, stackframe): raise ImportError # Handle seg faults that may occur during an import signal.signal(signal.SIGSEGV, handler) if __name__ == "__main__": goodMods = [] def onerror(pkgName): sys.stdout.write('Unable to import package %s\n' % pkgName) traceback.print_exc(file=sys.stdout) sys.stdout.write('\n') #sys.stdout.flush() for importer, mod, ispkg in pkgutil.walk_packages(path=None, onerror=onerror): goodMods.append(mod) for m in goodMods: sys.stdout.write(m + '\n') sys.stdout.flush() This sometimes works. But, since SIGSEGV is asynchronous it is not guaranteed to work all the time. In general, is there anyway to catch a SIGSEGV on import? If so, is there a way to use that with pkgutil.walk_packages to get all the modules on sys.path? Thanks, Ryan From __peter__ at web.de Thu Sep 9 08:51:21 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Sep 2010 14:51:21 +0200 Subject: importing module References: Message-ID: Holzwarth, Dominique (Berne Branch) wrote: > Hi all > > Lets assume I have the following structure of directories and python > modules: > > Root-dir > |_dir1 > |_ script1.py > |_dir2 > |_ script2.py > |_sudir2 > |_ script3.py > > Is it possible to import script1 into script2 and script3? Or do have to > put script1.py into the Lib\site-packages folder of my Python installation > so that it'll be in the standard module search path? You have three options - put script1.py into a directory in python's search path - modify the PYTHONPATH environment variable to include /path/to/dir1 - add a .pth file in a directory already in python's search path http://docs.python.org/library/site.html#module-site http://docs.python.org/install/#inst-search-path Peter From mwilson at the-wire.com Thu Sep 9 10:23:03 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 09 Sep 2010 10:23:03 -0400 Subject: [Tutor] Arguments from the command line References: Message-ID: Dennis Lee Bieber wrote: > On Thu, 09 Sep 2010 12:38:04 +1200, Lawrence D'Oliveiro > declaimed the following in > gmane.comp.python.general: > >> In message , Hugo >> Arts wrote: >> >> > sys.argv is a list of all arguments from the command line ... >> >> Interesting that Python didn?t bother to mimic the underlying POSIX >> convention of passing the command line as arguments to the mainline >> routine. >> > What "mainline routine"... The only programming language(s) I've > ever used that requires there be something called "main" in order to > start a program is the C/C++ family. [ ... ] > My college COBOL never used multifile assignments, so I'm not sure > if there was a difference between main and linked modules. Historical COBOL had a PROCEDURE DIVISION which marked the start of execution. But historical COBOL didn't pass parameters anyway. You read your optional arguments from a file, or accepted a few from an input device. I don't know PL/I generally, but with Multics PL/I any externally accessible procedure could be called from the command line: any_program$ea_proc a b c passing (for example) 'a', 'b', and 'c' as parameters. If the parameters were declared as variable-length character strings: ea_proc: proc (x, y, z); dcl (x, y, z) char (*); ... this would even work. Illustrating that the command-line-parameter-passing question is a deal with the operating system at least as much as it's a language issue. Posix aren't the only O/S. Mel. From giacomo.boffi at polimi.it Thu Sep 9 10:52:21 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Thu, 09 Sep 2010 16:52:21 +0200 Subject: [Tutor] Arguments from the command line References: Message-ID: <8662yfklzu.fsf@aiuole.stru.polimi.it> Dennis Lee Bieber writes: > FORTRAN just differentiates by having the main file start with > PROGRAM random_name > whereas subfiles are all either (or both) > SUBROUTINE another_name(args) > FUNCTION that_other_name(args) no BLOCKDATA? From kdombrowski at gmail.com Thu Sep 9 11:06:42 2010 From: kdombrowski at gmail.com (Kenneth Dombrowski) Date: Thu, 9 Sep 2010 11:06:42 -0400 Subject: cPickle segfault with nested dicts in threaded env In-Reply-To: <7x62yf3kws.fsf@ruckus.brouhaha.com> References: <4ce8d0a7-6784-4936-ba82-2ef2f393e8cc@q21g2000prm.googlegroups.com> <7x62yf3kws.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Sep 8, 2010 at 6:55 PM, Paul Rubin wrote: > Carl Banks writes: >> Since Python 2.7 is released, Python 2.5 is no longer accepting bug >> fixes, only security fixes. ?So be aware. > > Segfaults should be treated as security holes unless there's convincing > reasons that no exploit is possible. ?So the bug should be reported > against 2.5 as well as later versions. Hi Paul, Thanks for the input, it sounds reasonable to me. I reported it & the maintainers can decide what to do with it: http://bugs.python.org/issue9812 Thanks again everyone, Kenneth From ctops.legal at gmail.com Thu Sep 9 11:07:43 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Thu, 9 Sep 2010 08:07:43 -0700 (PDT) Subject: Python script for repairing .mov file ? Message-ID: <2d1b137c-3722-420c-bbe3-55719482cc08@g10g2000vbc.googlegroups.com> Jave is much better; http://yfrog.com/naattempt1hj From fritz at loseries.info Thu Sep 9 11:20:03 2010 From: fritz at loseries.info (Fritz Loseries) Date: Thu, 09 Sep 2010 17:20:03 +0200 Subject: how to extract an implicit dict expression (with statement return) Message-ID: <4C88FB23.1060605@loseries.info> Hi, I do not know how to subject my problem in a better way. I have the following statement: return [ dict(x1 = elem.x1, x2 = elem.x2, x3 = elem.x3,) for elem in method(in_values) ] How can I transform it to an explicit description: result = ... return result Could not found a description for the here used form of for and what [...] means. Need this for debugging. Thanks for any help. Regards, Fritz From benjamin.kaplan at case.edu Thu Sep 9 11:28:05 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 9 Sep 2010 11:28:05 -0400 Subject: how to extract an implicit dict expression (with statement return) In-Reply-To: <4C88FB23.1060605@loseries.info> References: <4C88FB23.1060605@loseries.info> Message-ID: On Thu, Sep 9, 2010 at 11:20 AM, Fritz Loseries wrote: > Hi, > > I do not know how to subject my problem in a better way. > > I have the following statement: > > ? ?return [ dict(x1 = elem.x1, x2 = elem.x2, x3 = elem.x3,) > ? ? ? ? ? ? ? ?for elem in method(in_values) > ? ? ? ? ? ? ?] > > How can I transform it to an explicit description: > > ? ?result = ... > ? ?return result > > Could not found a description for the here used form of for and what > [...] means. > > Need this for debugging. > Thanks for any help. > > Regards, > > Fritz [ ] defines a list literal >>> [1,2,3] [1, 2, 3] >>> type(_) This particular syntax [ ____ for ___ in ___] is a list comprehension. It's creating an inline for-loop to generate a list. You can just lift the whole expression for the assignment. result = [ dict(x1 = elem.x1, x2 = elem.x2, x3 = elem.x3,) ? ? ? ? ? ? ? ?for elem in method(in_values) ? ? ? ? ? ? ?] return result > > -- > http://mail.python.org/mailman/listinfo/python-list > From breamoreboy at yahoo.co.uk Thu Sep 9 12:07:14 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Sep 2010 17:07:14 +0100 Subject: [Python-ideas] with statement syntax forces ugly line breaks? In-Reply-To: <4C87E45A.1080207@mrabarnett.plus.com> References: <20100908175029.6617ae3b@dino> <4C87E45A.1080207@mrabarnett.plus.com> Message-ID: On 08/09/2010 20:30, MRAB wrote: > On 08/09/2010 19:07, Georg Brandl wrote: >> Thus spake the Lord: Thou shalt indent with four spaces. No more, no >> less. Four shall be the number of spaces thou shalt indent, and the >> number of thy indenting shall be four. Eight shalt thou not indent, >> nor either indent thou two, excepting that thou then proceed to four. >> Tabs are right out. >> > FYI, that should be "thine indenting". > > "My/thy" before a consonant, "mine/thine" before a vowel. Compare with > "a/an", which we still do. Hopefully correct, but certainly better than you knowledge of Spanish :) Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Thu Sep 9 12:13:22 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Sep 2010 17:13:22 +0100 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On 08/09/2010 21:23, Jonno wrote: > On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: >> On Wed, Sep 8, 2010 at 3:06 PM, Jonno wrote: >>> On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan >>> wrote: >>>> On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >>>>> I know that I can index into a list of lists like this: >>>>> a=[[1,2,3],[4,5,6],[7,8,9]] >>>>> a[0][2]=3 >>>>> a[2][0]=7 >>>>> >>>>> but when I try to use fancy indexing to select the first item in each >>>>> list I get: >>>>> a[0][:]=[1,2,3] >>>>> a[:][0]=[1,2,3] >>>>> >>>>> Why is this and is there a way to select [1,4,7]? >>>>> -- >>>> >>>> It's not fancy indexing. It's called taking a slice of the existing >>>> list. Look at it this way >>>> a[0] means take the first element of a. The first element of a is [1,2,3] >>>> a[0][:] means take all the elements in that first element of a. All >>>> the elements of [1,2,3] are [1,2,3]. >>>> >>>> a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. >>>> a[:][0] means take the first element of all the elements of a. The >>>> first element of a[:] is [1,2,3]. >>>> >>>> There is no simple way to get [1,4,7] because it is just a list of >>>> lists and not an actual matrix. You have to extract the elements >>>> yourself. >>>> >>>> col = [] >>>> for row in a: >>>> col.append(row[0]) >>>> >>>> >>>> You can do this in one line using a list comprehension: >>>> [ row[0] for row in a ] >>>> >>> Thanks! (to Andreas too). Totally makes sense now. >>> >> >> Now if I want to select the first item in every 2nd item of list a >> (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of >> indices to use in a more complex for loop? >> > Seems like the simplest way would be: > [row[0] for row in a][::2] The fastest way to find out is probably typing at the interactive prompt. Just jump in at the deep end and see what happens. Then wait until someone tells you to use the timeit module. Cheers. Mark Lawrence. From python at mrabarnett.plus.com Thu Sep 9 12:26:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 09 Sep 2010 17:26:27 +0100 Subject: [Python-ideas] with statement syntax forces ugly line breaks? In-Reply-To: References: <20100908175029.6617ae3b@dino> <4C87E45A.1080207@mrabarnett.plus.com> Message-ID: <4C890AB3.9030400@mrabarnett.plus.com> On 09/09/2010 17:07, Mark Lawrence wrote: > On 08/09/2010 20:30, MRAB wrote: >> On 08/09/2010 19:07, Georg Brandl wrote: >>> Thus spake the Lord: Thou shalt indent with four spaces. No more, no >>> less. Four shall be the number of spaces thou shalt indent, and the >>> number of thy indenting shall be four. Eight shalt thou not indent, >>> nor either indent thou two, excepting that thou then proceed to four. >>> Tabs are right out. >>> >> FYI, that should be "thine indenting". >> >> "My/thy" before a consonant, "mine/thine" before a vowel. Compare with >> "a/an", which we still do. > X-Antispam: NO; Spamcatcher 6.0.4. Score 1 > > Hopefully correct, but certainly better than you knowledge of Spanish :) > Or /your/ knowledge of English! (Muphry's Law) :-) From jonnojohnson at gmail.com Thu Sep 9 12:33:45 2010 From: jonnojohnson at gmail.com (Jonno) Date: Thu, 9 Sep 2010 11:33:45 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Thu, Sep 9, 2010 at 10:58 AM, Robert Kern wrote: > Please keep responses on the mailing list. However, I will reply below > this one time. > > On Thu, Sep 9, 2010 at 10:35, Jonno wrote: >> On Wed, Sep 8, 2010 at 4:26 PM, Robert Kern wrote: >>> A motivating example: >>> >>> [~] >>> |1> import numpy >>> >>> [~] >>> |2> a = numpy.array([[1,2,3],[4,5,6],[7,8,9]]) >>> >>> [~] >>> |3> a >>> >>> array([[1, 2, 3], >>> ? ? ? [4, 5, 6], >>> ? ? ? [7, 8, 9]]) >>> >>> [~] >>> |4> a[0,2] >>> 3 >>> >>> [~] >>> |5> a[2,0] >>> 7 >>> >>> [~] >>> |6> a[0,:] >>> array([1, 2, 3]) >>> >>> [~] >>> |7> a[:,0] >>> array([1, 4, 7]) >>> >>> >>> -- >>> Robert Kern >> >> Thanks Robert. I'm actually much more familiar and comfortable with >> arrays so I know how to slice them. The problem is that the data comes >> from lines in a file which are not all of equal length. >> My understanding is that I need to manipulate the data as lists until >> I can get all the lists of equal length at which point I can make an >> array from it. > > If you have ragged arrays, then you do not want to slice down columns > to begin with. You might run into a row that does not have a value at > that column. If you need to slice down columns (whether the object > remains a list of lists or a numpy array), then you need to create a > rectangular array regardless. Do that first, then I recommend using > numpy arrays. Slicing down columns (probably) won't help you with > that. Understood. My data actually has 2 features which make it non-rectangular in most circumstances. One is the extra element at the start of every nth line (I now know how to remove that) and the second is that some lines contain more data than others. My data is essentially a m,m,n array but data from each row is shifted to the next line when the line is full (4 columns). A new row then starts a new line. I want to pick out the data and assign it to an array but I'm wondering whether I should first try to take the data on the extra lines, remove it and stick it on the end of the original line (the data from one "row" could extend onto multiple lines). Or whether I'm better trying to create the array using loops to index my way through the lines the way they already are laid out. Hope this makes sense. From ethan at stoneleaf.us Thu Sep 9 15:23:17 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Sep 2010 12:23:17 -0700 Subject: Difference between queues and pipes in multiprocessing In-Reply-To: References: <5E121D65-6150-4CC6-A35D-7834A81131AC@gmail.com> Message-ID: <4C893425.8090300@stoneleaf.us> James Mills wrote: > On Wed, Aug 4, 2010 at 7:20 PM, Navkirat Singh wrote: >> I was wondering what are the differences between queues and pipes implemented using multiprocessing python module. Am I correct if I say, in pipes, if another process writes to one receiving end concurrently, then an error will be raised and in queues the later processes data will just queued up? > > basically a Queue is a syncronization primitive used to > share and pass data to and from parent/child processes. > > A pipe is as the name suggests, a socket pair connected > end-to-end allowing for full-duplex communications. > Isn't a pipe's communications one-way, requiring two of them to achieve full-duplex? ~Ethan~ From stephen.boulet at gmail.com Thu Sep 9 15:43:43 2010 From: stephen.boulet at gmail.com (Stephen Boulet) Date: Thu, 9 Sep 2010 12:43:43 -0700 (PDT) Subject: Printing the name of a variable Message-ID: Does an arbitrary variable carry an attribute describing the text in its name? I'm looking for something along the lines of: x = 10 print x.name >>> 'x' Perhaps the x.__getattribute__ method? Thanks. From marduk at letterboxes.org Thu Sep 9 16:11:27 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 09 Sep 2010 16:11:27 -0400 Subject: Printing the name of a variable In-Reply-To: References: Message-ID: <1284063087.3181.17.camel@paska> On Thu, 2010-09-09 at 12:43 -0700, Stephen Boulet wrote: > Does an arbitrary variable carry an attribute describing the text in > its name? I'm looking for something along the lines of: > > x = 10 > print x.name > >>> 'x' > > Perhaps the x.__getattribute__ method? Thanks. Variables are not objects and so they have no attributes. You can't really de-reference the object being referenced as it can potentially contain multiple references, but an innacurate way of doing this would be, e.g. >>> x = [1, 2, 3] >>> y = x >>> g = globals() >>> varnames = [i for i in g if g[i] is x] ['x', 'y'] But this cries the question: why do you want to do this? And usually that question is asked when someone thinks that a: you shouldn't need to do this and b: whatever the desired effect there is probably a better way of accomplishing it. From markhirota at gmail.com Thu Sep 9 16:22:39 2010 From: markhirota at gmail.com (Mark Hirota) Date: Thu, 9 Sep 2010 13:22:39 -0700 Subject: Why does linecache avoid ? How can I get equivalent of inspect.getsource() for an interactive session? Message-ID: Here's my goal: To enable a function for interactive session use that, when invoked, will "put" source code for a specified object into a plaintext file. Based on some initial research, this seems similar to ipython's %save magic command (?) Example: def put(filename, object): f = open(filename, "w") f.write(inspect.getsource(object)) f.close() Of course, in an interactive session, if you define a function: >>> def addit(a,b): return a+b And then try to run inspect.getsource() on it, you'll get an exception: >>> inspect.getsource(addit) Traceback (most recent call last): File "", line 1, in File "C:\Python26\lib\inspect.py", line 689, in getsource lines, lnum = getsourcelines(object) File "C:\Python26\lib\inspect.py", line 678, in getsourcelines lines, lnum = findsource(object) File "C:\Python26\lib\inspect.py", line 526, in findsource raise IOError('could not get source code') IOError: could not get source code This appears to be due to the fact that the linecache standard library module doesn't include (?) Can anyone help shed some light on why this is -- and perhaps provide feedback on whether this goal is feasible? Thanks! From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu Sep 9 16:40:39 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Thu, 09 Sep 2010 22:40:39 +0200 Subject: SendKeys and Python 2.7 References: Message-ID: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Hi! Example for send ^V (with PyWin32): import time,win32api,win32con win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) time.sleep(0.05) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) @-salutations -- Michel Claveau From nobody at nowhere.com Thu Sep 9 17:03:59 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 09 Sep 2010 22:03:59 +0100 Subject: Difference between queues and pipes in multiprocessing References: <5E121D65-6150-4CC6-A35D-7834A81131AC@gmail.com> Message-ID: On Thu, 09 Sep 2010 12:23:17 -0700, Ethan Furman wrote: >> basically a Queue is a syncronization primitive used to >> share and pass data to and from parent/child processes. >> >> A pipe is as the name suggests, a socket pair connected >> end-to-end allowing for full-duplex communications. >> > > Isn't a pipe's communications one-way, requiring two of them to achieve > full-duplex? He's talking about multiprocessing.Pipe(), not a Unix pipe. On Unix, multiprocessing.Pipe() uses a socket pair if duplex==True and a pipe if duplex==False. On Windows it uses a named pipe (which can be either unidirectional or bidirectional). From nobody at nowhere.com Thu Sep 9 17:09:29 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 09 Sep 2010 22:09:29 +0100 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: On Wed, 08 Sep 2010 03:30:00 -0700, Baba wrote: > Who is licensed to judge what can and cannot be posted as a question? Exactly the same set of people who are licensed to judge what can and cannot be posted as an answer. If you don't like the responses you get here, you could try posting your questions on 4chan. If nothing else, that will give you a whole new perspective on what an "unfriendly" response really looks like. From nobody at nowhere.com Thu Sep 9 17:20:36 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 09 Sep 2010 22:20:36 +0100 Subject: Catching a SIGSEGV signal on an import References: Message-ID: On Thu, 09 Sep 2010 05:23:14 -0700, Ryan wrote: > But, since SIGSEGV is asynchronous SIGSEGV is almost always synchronous. > In general, is there anyway to catch a SIGSEGV on import? No. If SIGSEGV is raised, it often indicates that memory has been corrupted. At that point, you can't assume that the Python runtime is still functional. In general, even attempting to catch it is a bad idea. Particularly in a high-level language; getting it right in C is hard enough. From no.email at nospam.invalid Thu Sep 9 17:35:12 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 09 Sep 2010 14:35:12 -0700 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <7x39ti4n3j.fsf@ruckus.brouhaha.com> Nobody writes: > If you don't like the responses you get here, you could try posting your > questions on 4chan. If nothing else, that will give you a whole new > perspective on what an "unfriendly" response really looks like. +1 QOTW From raoulbia at gmail.com Thu Sep 9 17:39:36 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 9 Sep 2010 14:39:36 -0700 (PDT) Subject: analysis of algoritms Message-ID: Hi In below code "the outer loop test in step 4 will execute ( n + 1 ) times (note that an extra step is required to terminate the for loop, hence n + 1 and not n executions), which will consume T4( n + 1 ) time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) 1 get a positive integer from input 2 if n > 10 3 print "This might take a while..." 4 for i = 1 to n 5 for j = 1 to i 6 print i * j 7 print "Done!" Why does step 4 execute n+1 times? what is the exta step mentioned above tnx Baba From tjreedy at udel.edu Thu Sep 9 17:40:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Sep 2010 17:40:14 -0400 Subject: Printing the name of a variable In-Reply-To: References: Message-ID: On 9/9/2010 3:43 PM, Stephen Boulet wrote: In Python, 'variable' is a synonym for name and identifier,' An object can have 0 to many names attached to it. An object can also be a member of 0 to many collections. Modules, classes, and functions have 'definition name' strings attached to them as their .__name__ attribute. This attribute is used to display the 'value' of these objects, as in >>> def f(): pass >>> f The __name__ attribute is also used in the idiom >>> if __name__ == '__main__': print("I am the main module") I am the main module to determine if a module is being run as the main module as imported into another module. -- Terry Jan Reedy From ron.eggler at gmail.com Thu Sep 9 17:45:06 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 9 Sep 2010 14:45:06 -0700 (PDT) Subject: how to kill a subprocess Message-ID: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> Hi There, I'm calling a python script from a php script which again calls a perl script with subprocess.popen(). This seems to work fine so far only that once the python script completed it is becoming a zombie because the perl script in the background is still running... so before i exit the python script, i would need to kill my perl subprocess. How can i do so? Thank you for hints & suggestions! Ron From almar.klein at gmail.com Thu Sep 9 17:54:29 2010 From: almar.klein at gmail.com (Almar Klein) Date: Thu, 9 Sep 2010 23:54:29 +0200 Subject: analysis of algoritms In-Reply-To: References: Message-ID: On 9 September 2010 23:39, Baba wrote: > Hi > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1 get a positive integer from input > 2 if n > 10 > 3 print "This might take a while..." > 4 for i = 1 to n > 5 for j = 1 to i > 6 print i * j > 7 print "Done!" > > Why does step 4 execute n+1 times? what is the exta step mentioned > above > Because it does two things: - increase i - check whether i is still smaller than n. If it is not, the loop is terminated Still, this is quite a simplification of what's really going on... Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From gasproni at asprotunity.com Thu Sep 9 18:03:28 2010 From: gasproni at asprotunity.com (aspro) Date: Thu, 9 Sep 2010 15:03:28 -0700 (PDT) Subject: [ANN] ACCU 2011 Conference Call for Proposals -- deadline approaching Message-ID: <7a15d251-b28e-4120-b534-e37b4d175737@c13g2000vbr.googlegroups.com> Hi all, This is a reminder that the deadline for the ACCU 2011 CfP is approaching fast--26th of September 2010. If you have not sent your proposals yet, below there are more details on how to do so. Call for Proposals - ACCU 2011 April 13-16, 2011. Barcelo Oxford Hotel, Oxford, UK Submission deadline: 26th of September 2010 Email proposals to: Giovanni Asproni, conference at accu.org http://www.accu.org/conference twitter: @accu2011 #accu2011 We invite you to propose a session for this leading software development conference. We have a long tradition of high quality sessions covering many aspects of software development, from programming languages (e.g., Java, C#, Python, Erlang, Haskell, Ruby, Groovy, C, C++, etc.), and technologies (libraries, frameworks, databases, etc.) to subjects about the wider development environment such as testing, architecture and design, development process, analysis, patterns, project management, and softer aspects such as team building, communication and leadership. Sessions may be either tutorial-based, presentations of case studies, or take the form of interactive workshops. We are always open to novel formats, so please contact us with your idea. The standard length of a session is 90 minutes, with some exceptions. In order to allow less experienced speakers to speak at the conference without the pressure of filling a full 90 minutes, we reserve a number of shorter 45 minute sessions. If you would like to run a session please let us know by emailing your proposals to conference at accu.org by the 26th of September 2010 at the latest. Please include the following to support your proposal: * Title (a working title if necessary) * Type (tutorial, workshop, case study, etc.) * Duration (45/90 min) * Speaker name(s) * Speaker biography (max 150 words) * Description (approx 250 words) Proposals about specific products and technologies will be taken under consideration only if they are open source and available for free (at least for non-commercial use). If you are interested in talking about a proprietary technology, there is the possibility of "sponsored sessions" which are presented outside the standard conference schedule. Please, email conference at accu.org for more information. If you are interested in knowing more about the conference you may like to consult the website for previous years' editions at http://www.accu.org/conference for background information. Speakers running one or more full 90 minute sessions receive a special conference package including free attendance, and assistance with their travel and accommodation costs. Speakers filling a 45 minute slot qualify for free conference attendance on the day of their session. The conference has always benefited from the strength of its programme. Please help us make 2011 another successful event. Giovanni Asproni Conference Chair From robert.kern at gmail.com Thu Sep 9 18:10:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 09 Sep 2010 17:10:22 -0500 Subject: analysis of algoritms In-Reply-To: References: Message-ID: On 9/9/10 4:39 PM, Baba wrote: > Hi > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1 get a positive integer from input > 2 if n> 10 > 3 print "This might take a while..." > 4 for i = 1 to n > 5 for j = 1 to i > 6 print i * j > 7 print "Done!" > > Why does step 4 execute n+1 times? what is the exta step mentioned > above You may wish to ask the question on the associated Discussion page for that article. Hopefully the author of that statement will notice it there. They are almost certainly not here. That said, an extra step is required because a real implementation of that algorithm in a language will create a variable `i` initialized to 1, increment it each round through the loop, and check it before running the loop. When the check indicates that it equals n + 1 (not n!) it will exit the loop. That particular pseudocode notation hides that detail. Of course, there are ways to implement that pseudocode that do not require the last check, but none of real importance. -- 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 gh at ghaering.de Thu Sep 9 18:16:58 2010 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 10 Sep 2010 00:16:58 +0200 Subject: are there pros or contras, keeping a connection to a (sqlite) database ? In-Reply-To: References: Message-ID: On Thu, Sep 9, 2010 at 12:29 AM, CM wrote: > [...] > I'm not even sure what a "connection" really is; I assumed it was > nothing more than a rule that says to write to the database with the > file named in the parentheses. [...] The following list is not exclusive, but these are the first things that I can think of. - SQLite connections have state like uncommitted transactions - SQLite connections have page caches and metadata caches (tables, structures and indices) Opening and closing SQLite connections is very cheap, but keeping connections open is usually a better approach. You have to have a "global" setting like the path to the database file anyway; so you can wrap a "global" connection object in a factory function just as well. In database applications that use the raw DB-APi i usually start with something like: def get_con(): # return database connection ... HTH -- Gerhard From cmpython at gmail.com Thu Sep 9 18:17:30 2010 From: cmpython at gmail.com (CM) Date: Thu, 9 Sep 2010 15:17:30 -0700 (PDT) Subject: are there pros or contras, keeping a connection to a (sqlite) database ? References: <4c889dce$0$4622$426a34cc@news.free.fr> Message-ID: <5870be5c-8c72-48c1-8af5-411c9fbb42e8@w4g2000vbh.googlegroups.com> On Sep 9, 4:41?am, News123 wrote: > On 09/09/2010 12:29 AM, CM wrote: > > > On Sep 8, 1:09 pm, Stef Mientki wrote: > >> ?hello, > > >> I wrap my database in some class, and on creation of the instance, a connection to the database is > >> created, > >> and will stay connected until the program exists, something like this: > > >> ? ? self.conn = sqlite3.connect ( self.filename ) > > >> Now I wonder if there are pros or contras to keep the connection to the database continuously ?"open" ? > > >> thanks, > >> Stef Mientki > > > I do the same thing--good to hear from John that keeping it open is > > OK. > > > But another question that this provokes, at least for me is: ?what > > happens when you call .connect() on the same database multiple times > > from within different parts of the same app? ?Is that bad? ?And is it > > that there now multiple connections to the database, or one connection > > that has multiple names in different namespaces within the app? > > CM, > > Do you talk about a multithreaded environment? > or only about an environment with logically separate blocks (or with > generators), > and multiple objects each keeping their own connection. More the latter. My calls to make a connection to the database are from within different classes that serve different aspects of the GUI. I have something like an anti-MVC pattern here, like ravioli code, where each GUI element gets what it needs from the database. They are all running in the main GUI thread. There is also, though, a wxPython timer (wxTimer) that will occasionally initiate a read or write to the database, though it will already have an open connection. Why? How would this matter? > As far as I know sqlite can be compiled to be thread safe, but is not > necessarily be default. > No idea about the library used b python. I haven't dealt with the issue of thread safety before, haven't thought about it really. > I personally just started sqlite in one of my apps with multithrading > and in order to be safe I went for the conservative approach > connect, perform transactions, commit and close. > However this is probably overkill and later in time I might also ty to > keep connections open in order to increse performance. So far the "many calls to .connect() approach" has not seemed problematic for my app. But I have nothing to compare it to. Che From thomas at jollybox.de Thu Sep 9 18:19:51 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 10 Sep 2010 00:19:51 +0200 Subject: Why does linecache avoid ? How can I get equivalent of inspect.getsource() for an interactive session? In-Reply-To: References: Message-ID: <201009100019.52461.thomas@jollybox.de> On Thursday 09 September 2010, it occurred to Mark Hirota to exclaim: > Here's my goal: > > To enable a function for interactive session use that, when invoked, > will "put" source code for a specified object into a plaintext file. > Based on some initial research, this seems similar to ipython's %save > magic command (?) > > Example: > > def put(filename, object): > f = open(filename, "w") > f.write(inspect.getsource(object)) > f.close() > > Of course, in an interactive session, if you define a function: > >>> def addit(a,b): return a+b > > And then try to run inspect.getsource() on it, you'll get an exception: > >>> inspect.getsource(addit) What inspect.getsource is is simply this: It finds out which module the object belongs to, checks the __file__ of that module, opens it (or the corresponsing .py file), and finds the right bit. This won't work for extension modules as they have no Python source, and it won't work for objects created on the interactive console or using exec, or eval, as they have no source file. > > Traceback (most recent call last): > File "", line 1, in > File "C:\Python26\lib\inspect.py", line 689, in getsource > lines, lnum = getsourcelines(object) > File "C:\Python26\lib\inspect.py", line 678, in getsourcelines > lines, lnum = findsource(object) > File "C:\Python26\lib\inspect.py", line 526, in findsource > raise IOError('could not get source code') > IOError: could not get source code > > This appears to be due to the fact that the linecache standard library > module doesn't include (?) > > Can anyone help shed some light on why this is -- and perhaps provide > feedback on whether this goal is feasible? > > Thanks! From nagle at animats.com Thu Sep 9 18:21:35 2010 From: nagle at animats.com (John Nagle) Date: Thu, 09 Sep 2010 15:21:35 -0700 Subject: Queue cleanup In-Reply-To: <7xfwxj67bj.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> <7xfwxj67bj.fsf@ruckus.brouhaha.com> Message-ID: <4c895deb$0$1638$742ec2ed@news.sonic.net> On 9/8/2010 6:20 PM, Paul Rubin wrote: > What tricks on tricks? Even the fanciest GC's are orders of magnitude > less complicated than any serious database, optimizing compiler, OS > kernel, file system, etc. Real-world software is complicated. Get used > to that fact, and look for ways to manage the complexity and keep > complex programs safe. Choosing to program with unsafe methods because > you wish the complexity didn't exist is just deluded. Garbage collectors are difficult from a theoretical standpoint, and it's very difficult to make a correct concurrent garbage collector without using formal methods. But garbage collectors are not large pieces of code. John Nagle From alain at dpt-info.u-strasbg.fr Thu Sep 9 18:22:46 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 10 Sep 2010 00:22:46 +0200 Subject: analysis of algoritms References: Message-ID: <8762yea761.fsf@dpt-info.u-strasbg.fr> Baba writes: > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1 get a positive integer from input > 2 if n > 10 > 3 print "This might take a while..." > 4 for i = 1 to n > 5 for j = 1 to i > 6 print i * j > 7 print "Done!" > > Why does step 4 execute n+1 times? what is the exta step mentioned > above In "the outer loop test [...]", the important word is _test_. Line 4 has to test the value of i against n, which results in true n times and in false once (where it jumps to instruction 7). Note that this would be true even with python loops using range(n) or xrange(n), where the test is not an integer comparison. (Note also how this last remark tries to avoid complete off-topic-ness of this discussion in this group :-) -- Alain. From ethan at stoneleaf.us Thu Sep 9 18:24:20 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Sep 2010 15:24:20 -0700 Subject: Difference between queues and pipes in multiprocessing In-Reply-To: References: <5E121D65-6150-4CC6-A35D-7834A81131AC@gmail.com> Message-ID: <4C895E94.804@stoneleaf.us> Nobody wrote: > On Thu, 09 Sep 2010 12:23:17 -0700, Ethan Furman wrote: > >>> basically a Queue is a syncronization primitive used to >>> share and pass data to and from parent/child processes. >>> >>> A pipe is as the name suggests, a socket pair connected >>> end-to-end allowing for full-duplex communications. >>> >> Isn't a pipe's communications one-way, requiring two of them to achieve >> full-duplex? > > He's talking about multiprocessing.Pipe(), not a Unix pipe. > > On Unix, multiprocessing.Pipe() uses a socket pair if duplex==True and a > pipe if duplex==False. On Windows it uses a named pipe (which can be > either unidirectional or bidirectional). > Ah. I was confusing it with os.pipe(). Many thanks. ~Ethan~ From davea at ieee.org Thu Sep 9 18:26:52 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 09 Sep 2010 18:26:52 -0400 Subject: analysis of algoritms In-Reply-To: References: Message-ID: <4C895F2C.9020203@ieee.org> On 2:59 PM, Baba wrote: > Hi > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1 get a positive integer from input > 2 if n> 10 > 3 print "This might take a while..." > 4 for i = 1 to n > 5 for j = 1 to i > 6 print i * j > 7 print "Done!" > > Why does step 4 execute n+1 times? what is the exta step mentioned > above > > tnx > Baba > Why are you posting a question about BASIC syntax in a Python forum? Python has no such statement, and its close approximations work much differently. If you really want an abstract answer, then you should be decomposing those BASIC statements into smaller atoms. The for statement is composed of at least three "atoms", one of which is probably executed n+1 times. A BASIC for statement for i=1 to n decomposes into approximately: 4a, i = 1 4b compare i to n 4c skip if greater 5, 6 do some stuff 4d increment i Note that the increment happens after steps 5 and 6, but it's part of line 4 Also note that the exact details depend thoroughly on the brand and version of BASIC, there being at least 60 versions out there. For example, I can think of at least three cases for what i will equal on line 7. Incidentally, in some versions of BASIC, 4b and 4c might come after 4d, and only be executed n times. DaveA From alain at dpt-info.u-strasbg.fr Thu Sep 9 18:29:27 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 10 Sep 2010 00:29:27 +0200 Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> Message-ID: <871v92a6uw.fsf@dpt-info.u-strasbg.fr> cerr writes: > I'm calling a python script from a php script which again calls a perl > script with subprocess.popen(). > This seems to work fine so far only that once the python script > completed it is becoming a zombie because the perl script in the > background is still running... so before i exit the python script, i > would need to kill my perl subprocess. > How can i do so? x.terminate() (and then x.wait()) where x is the value returned by subprocess.Popen(). -- Alain. P/S: I'm not sure why the python process survives, and I think your use of "zombie" is not correct (afaik a zombie is an exited process whose parent hasn't called wait() yet) From ron.eggler at gmail.com Thu Sep 9 18:52:21 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 9 Sep 2010 15:52:21 -0700 (PDT) Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> Message-ID: <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> On Sep 9, 3:29?pm, Alain Ketterlin wrote: > cerr writes: > > I'm calling a python script from a php script which again calls a perl > > script with subprocess.popen(). > > This seems to work fine so far only that once the python script > > completed it is becoming a zombie because the perl script in the > > background is still running... so before i exit the python script, i > > would need to kill my perl subprocess. > > How can i do so? > > x.terminate() (and then x.wait()) where x is the value returned by > subprocess.Popen(). Well, this is what I have: writelog("starting GPS simulator") commandlist=[GPSsim,proto,GPSfile] writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) process=subprocess.Popen(commandlist) writelog("GPS simulator started") ... ... os.kill(process.pid,9) os.wait() but this is not working for me... :( any clues? > P/S: I'm not sure why the python process survives, and I think your use > of "zombie" is not correct (afaik a zombie is an exited process whose > parent hasn't called wait() yet) This is what I have: localhost cgi-bin # ps ax | grep py 11853 ? Z 0:00 [python2.6] 12029 pts/1 S+ 0:00 grep --colour=auto py The 'Z' you see there stands for Zombie From python at mrabarnett.plus.com Thu Sep 9 19:18:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Sep 2010 00:18:24 +0100 Subject: how to kill a subprocess In-Reply-To: <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> Message-ID: <4C896B40.9040807@mrabarnett.plus.com> On 09/09/2010 23:52, cerr wrote: > On Sep 9, 3:29 pm, Alain Ketterlin > wrote: >> cerr writes: >>> I'm calling a python script from a php script which again calls a perl >>> script with subprocess.popen(). >>> This seems to work fine so far only that once the python script >>> completed it is becoming a zombie because the perl script in the >>> background is still running... so before i exit the python script, i >>> would need to kill my perl subprocess. >>> How can i do so? >> >> x.terminate() (and then x.wait()) where x is the value returned by >> subprocess.Popen(). > Well, this is what I have: > > writelog("starting GPS simulator") > commandlist=[GPSsim,proto,GPSfile] > writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) > process=subprocess.Popen(commandlist) > writelog("GPS simulator started") > ... > ... > os.kill(process.pid,9) > os.wait() > > but this is not working for me... :( any clues? > >> P/S: I'm not sure why the python process survives, and I think your use >> of "zombie" is not correct (afaik a zombie is an exited process whose >> parent hasn't called wait() yet) > > This is what I have: > > localhost cgi-bin # ps ax | grep py > 11853 ? Z 0:00 [python2.6] > 12029 pts/1 S+ 0:00 grep --colour=auto py > > The 'Z' you see there stands for Zombie > How about: process.kill() # New in Python 2.6 or: os.kill(process.pid, 9) then: process.wait() or: os.waitpid(process.pid, 0) From jaksonaquino at gmail.com Thu Sep 9 19:24:30 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Thu, 9 Sep 2010 20:24:30 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP wrote: > Hi! > > Example for send ^V ?(with PyWin32): > > ?import time,win32api,win32con > ?win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) > ?win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) > ?time.sleep(0.05) > ?win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) > ?win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) Thank you very much! Your code solved my problem. I added some lines to set the focus into R before the ^V and then back to Vim: import time,win32api,win32con,win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.AppActivate("R Console") win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) time.sleep(0.05) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) shell.AppActivate("Vim") Best regards, Jakson Aquino From wbrehaut at mcsnet.ca Thu Sep 9 19:27:37 2010 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Thu, 09 Sep 2010 17:27:37 -0600 Subject: analysis of algoritms References: Message-ID: On Thu, 09 Sep 2010 18:26:52 -0400, Dave Angel wrote: > On 2:59 PM, Baba wrote: >> Hi >> >> In below code "the outer loop test in step 4 will execute ( n + 1 ) >> times (note that an extra step is required to terminate the for loop, >> hence n + 1 and not n executions), which will consume T4( n + 1 ) >> time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) >> >> 1 get a positive integer from input >> 2 if n> 10 >> 3 print "This might take a while..." >> 4 for i = 1 to n >> 5 for j = 1 to i >> 6 print i * j >> 7 print "Done!" >> >> Why does step 4 execute n+1 times? what is the exta step mentioned >> above >> >> tnx >> Baba >> >Why are you posting a question about BASIC syntax in a Python forum? >Python has no such statement, and its close approximations work much >differently. > >If you really want an abstract answer, then you should be decomposing >those BASIC statements into smaller atoms. The for statement is >composed of at least three "atoms", one of which is probably executed >n+1 times. > >A BASIC for statement for i=1 to n >decomposes into approximately: > >4a, i = 1 >4b compare i to n >4c skip if greater > 5, 6 do some stuff >4d increment i REM And the vuitally important: 4e GOTO 4b But, as Robert noted, this is undoubtedly "pseudocode" rather than BASIC. Pity it's not Python-oriented pseudocode... >Note that the increment happens after steps 5 and 6, but it's part of line 4 > >Also note that the exact details depend thoroughly on the brand and >version of BASIC, there being at least 60 versions out there. For >example, I can think of at least three cases for what i will equal on >line 7. > >Incidentally, in some versions of BASIC, 4b and 4c might come after 4d, >and only be executed n times. > >DaveA From magawake at gmail.com Thu Sep 9 20:05:22 2010 From: magawake at gmail.com (Mag Gam) Date: Thu, 9 Sep 2010 20:05:22 -0400 Subject: reading multiple files Message-ID: I have 3 files which are constantly being updated therefore I use tail -f /var/log/file1, tail -f /var/log/file2, and tail -f /var/log/file3 For 1 file I am able to manage by tail -f /var/log/file1 | python prog.py prog.py looks like this: f=sys.stdin for line in f: print line But how can I get data from /var/log/file2 and /var/log/file3 ? I prefer a native python way instead of doing tail -f TIA From alain at dpt-info.u-strasbg.fr Thu Sep 9 20:31:25 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 10 Sep 2010 02:31:25 +0200 Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> Message-ID: <87wrqu8mn6.fsf@dpt-info.u-strasbg.fr> cerr writes: >> x.terminate() (and then x.wait()) where x is the value returned by >> subprocess.Popen(). > Well, this is what I have: > > writelog("starting GPS simulator") > commandlist=[GPSsim,proto,GPSfile] > writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) > process=subprocess.Popen(commandlist) > writelog("GPS simulator started") > ... > ... > os.kill(process.pid,9) > os.wait() > > but this is not working for me... :( any clues? Should be ok. A minor point: os.kill(...) and os.wait() have equivalent (portable) convenience methods on Popen. Also, it may be better to send SIGTERM (15) instead of SIGKILL, to ensure the victim can die gracefully (e.g., remove temp files). >> P/S: I'm not sure why the python process survives, and I think your use >> of "zombie" is not correct (afaik a zombie is an exited process whose >> parent hasn't called wait() yet) > > This is what I have: > > localhost cgi-bin # ps ax | grep py > 11853 ? Z 0:00 [python2.6] > 12029 pts/1 S+ 0:00 grep --colour=auto py > > The 'Z' you see there stands for Zombie This is from "man ps": Processes marked are dead processes (so-called "zombies") that remain because their parent has not destroyed them properly. These processes will be destroyed by init(8) if the parent process exits. So the problem is with what launches this python process (11853). If this process is the python interpreter running the program above, check how you launch it. If this process is something else, check its parent process. -- Alain. From cpblpublic at gmail.com Thu Sep 9 20:36:34 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Thu, 9 Sep 2010 17:36:34 -0700 (PDT) Subject: weighted mean; weighted standard error of the mean (sem) Message-ID: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> I am looking for some reaally basic statistical tools. I have some sample data, some sample weights for those measurements, and I want to calculate a mean and a standard error of the mean. Here are obvious places to look: numpy scipy.stats statsmodels It seems to me that numpy's "mean" and "average" functions have their names backwards. That is, often a mean is defined more generally than average, and includes the possibility of weighting, but in this case it is "average" that has a weights argument. Can these functions be merged/renamed/deprecated in the future? It's clear to me that "mean" should allow for weights. None of these modules, above, offer standard error of the mean which incorporates weights. numpy's "sem" doesn't, and that's the closest thing. numpy's "var" doesn't allow weights. There aren't any weighted variances in the above modules. Again, are there favoured codes for these functions? Can they be incorporated appropriately in the future? Most immediately, I'd love to get code for weighted sem. I'll write it otherwise, but if I do I'd love to know whom to bug to get it incorporated into numpy.sem ... Thanks! None of them have this basic function. Has anyone written one? From bartc at freeuk.com Thu Sep 9 21:06:51 2010 From: bartc at freeuk.com (BartC) Date: Fri, 10 Sep 2010 02:06:51 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <%xfio.95946$c_6.89631@newsfe30.ams2> "Stefan Behnel" wrote in message news:mailman.563.1283921317.29448.python-list at python.org... > BartC, 08.09.2010 03:45: >> Getting back to the OP's code again (trivial and pointless as it might >> seem), I got these results: >> >> C (gcc 3.4.5 -O3) 0.8 secs >> C (DMC-o) 2.3 secs >> C (lccwin32 -O) 2.9 secs > BTW, I wonder why the code takes a whole 0.8 seconds to run in your gcc > test. Maybe you should use a newer GCC version. It shouldn't take more > than a couple of milliseconds (for program startup, OS calls, etc.), given > that the output is a constant. It turns out the 0.8 second version cheats. It counts to a billion, but does not do the work asked (a=a+10). The fastest time that will do what it is requested, is about 1.2 seconds, when register-based, and about 3 seconds when memory-based. This reduces the slowdown on Python 3 from 220x to 150x, and down to 60x when register-versions are not counted (as use of registers can't be guaranteed). (Python 2 was about 20% faster.) -- Bartc From alain at dpt-info.u-strasbg.fr Thu Sep 9 21:19:39 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 10 Sep 2010 03:19:39 +0200 Subject: reading multiple files References: Message-ID: <87sk1i8kes.fsf@dpt-info.u-strasbg.fr> Mag Gam writes: > I have 3 files which are constantly being updated therefore I use tail > -f /var/log/file1, tail -f /var/log/file2, and tail -f /var/log/file3 > > For 1 file I am able to manage by > tail -f /var/log/file1 | python prog.py > > prog.py looks like this: > f=sys.stdin > for line in f: > print line > > But how can I get data from /var/log/file2 and /var/log/file3 ? Use shell tricks, e.g., with bash: yourpythonprog <(tail -f .../file1) <(tail -f .../file2) <(...) and let your prog open its three parameters like regular files (they are fifos actually). If your shell doesn't support <(...), create the fifos and redirect tail output before launching your prog. If you want "purer" python, launch the three "tail -f" with subprocess, and use the select module to get input (you didn't explain the logic you will follow to track three files---you may not need select if you expect one line from each file before waiting for the next line of any). > I prefer a native python way instead of doing tail -f Emulating tail will require a lot of stat/seeks, and finding lines will require an additional level of complexity. Also, tail -f has a cost [*]. The only way to avoid it is to use inotify, which seems to have a python interface, available at http://pyinotify.sourceforge.net/ (I've never used it). Again, emulating tail -f with inotify is significant work. -- Alain. [*] Paul Rubin is one of the authors, I think he reads this group. From tim.leslie at gmail.com Thu Sep 9 21:27:07 2010 From: tim.leslie at gmail.com (Tim Leslie) Date: Fri, 10 Sep 2010 11:27:07 +1000 Subject: weighted mean; weighted standard error of the mean (sem) In-Reply-To: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> References: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> Message-ID: On 10 September 2010 10:36, C Barrington-Leigh wrote: > > Most immediately, I'd love to get code for weighted sem. I'll write it > otherwise, but if I do I'd love to know whom to bug to get it > incorporated into numpy.sem ... The best place to ask about numpy related stuff is the numpy mailing list at: http://mail.scipy.org/mailman/listinfo/numpy-discussion This is also the best place to present a patch if you have code to contribute. In my experience the numpy devs are always happy to have new contributors, but be sure to discuss the problem first, as the folk over there might be able to provide a solution which doesn't require a new patch. Cheers, Tim > > Thanks! > > None of them have this basic function. Has anyone written one? > -- > http://mail.python.org/mailman/listinfo/python-list > From python at rcn.com Thu Sep 9 21:37:49 2010 From: python at rcn.com (Raymond Hettinger) Date: Thu, 9 Sep 2010 18:37:49 -0700 (PDT) Subject: How Python works: What do you know about support for negative indices? Message-ID: Hello Folks. It doesn't seem to be common knowledge when and how a[x] gets translated to a[x+len(x)]. So, here's a short info post on how Python supports negative indices for sequences. I've put the answer below, but if you want to quickly test your own knowledge, ask yourself which of these support negative indices: 'abcde'[-2] # builtin string class, bracket syntax 'abcde'.__getitem__(-2) # builtin class, magic method collections.deque('abcde')[-2] # extension class, bracket syntax collections.deque('abcde').__getitem__[-2] # extension class, magic method class S(str): pass class T(str): def __getitem__(self, i): print(i) return 'd' class U(str): def __getitem__(self, i): print(i) return 'd' def __len__(self): return 5 class V(str): 'str subclass overriding key methods' def __getitem__(self, i): print(i) return 'd' def __len__(self): return 5 def __iter__(self): return iter('abcde') def __contains__(self, val): return val in 'abcde' class W: 'object subclass registered as Sequence' def __init__(self, data): self.data = data def __getitem__(self, i): print(i) return 'd' def __len__(self): return 5 def __iter__(self): return iter('abcde') def __contains__(self, val): return val in 'abcde' collections.Sequence.register(V) class X(collections.Sequence): 'Subclass the Sequence abstract base class' def __init__(self, data): self.data = data def __getitem__(self, i): print(i) return 'd' def __len__(self): return 5 def __iter__(self): return iter('abcde') def __contains__(self, val): return val in 'abcde' Essentially, the example raise these questions: * Are negative indices tied to the grammar (i.e. binary subscription)? * Does it matter if you call a magic method instead of using brackets? * Are they tied to particular concrete classes (str, list, tuple, deque, dict)? * If so, how does subclassing affect index handling? * What parts of user defined classes affect handling of indices? * Are they part of the abstract layer (PyObject_GetItem)? * Are they tied to the Sequence ABC? * How are mapping lookups differentiated (d[-2] where d is a Mapping)? ------------- Answers below -------------- | | | | | | | | | | | | | | | | The first five examples support negative indices. The builtin sequence types: str, deque, list and tuple, all have negative index support built in to their concrete implementations (such as str.__getitem__) and that behavior persists for subclassers as long as they don't override __getitem__. The parse of "a['x']" matches the "subscription" rule in Grammar/ Grammar. That compiles the BINARY_SUBSCR opcode which pops off the evaluated expressions for "a" and "x" and calls the abstract layer, PyObject_GetItem() which routes most calls to the concrete implementation (i.e. myobj.__getitem__). The exception to concrete dispatch is a fast path for builtin classes or their subclasses that 1) are recognized as sequences (i.e. not a dictionary and have not overridden __getitem__) 2) where "x" is an index (i.e. not a float) If so, it is passed to an intermediate abstract layer, PySequence_SetItem() which will apply negative index handling iff the sequence defines a __len__ method. In other words, the handling of negative indices is always up to the concrete class. It is not part of the grammar, or the definition of subscriptions, or the dispatch sequence. The docs guarantee that Python's builtin sequences implement support for negative indices ( http://docs.python.org/dev/reference/expressions.html#subscriptions ) and they all do so through their individual __getitem__ implementations. Builtin Python sequences also have a fast path that make negative index handling automatic, but this is just an invisible optimization and can be bypassed by calling myobj.__getitem__ directly. Note on slicing: slices are handled the same way (at least in 3.x), so it is the responsibility of concrete classes to add support if they choose to do so. Some, like lists tuples and string do support slicing and some objects like deque do not. Interestingly, the grammar has rules for slicing, but that is implemented as making a slice instance as the argument to the lookup. The actual lookup work is dispatched to the concrete class and there is no fast path along the way. Hope you all found this to be informative, Raymond From cpblpublic at gmail.com Thu Sep 9 21:43:47 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Thu, 9 Sep 2010 18:43:47 -0700 (PDT) Subject: weighted mean; weighted standard error of the mean (sem) References: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> Message-ID: <88998386-68b7-41bc-9d89-0a33ca1195e1@w15g2000pro.googlegroups.com> > The best place to ask about numpy related stuff is the numpy mailing list at: > > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > This is also the best place to present a patch if you have code to > contribute. In my experience the numpy devs are always happy to have > new contributors, but be sure to discuss the problem first, as the > folk over there might be able to provide a solution which doesn't > require a new patch. Thanks, Tim, Ooops -- the sem() I mentioned is sciypy.stats.sem, not in numpy... Does your advice hold? Thanks, c From tim.leslie at gmail.com Thu Sep 9 22:03:06 2010 From: tim.leslie at gmail.com (Tim Leslie) Date: Fri, 10 Sep 2010 12:03:06 +1000 Subject: weighted mean; weighted standard error of the mean (sem) In-Reply-To: <88998386-68b7-41bc-9d89-0a33ca1195e1@w15g2000pro.googlegroups.com> References: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> <88998386-68b7-41bc-9d89-0a33ca1195e1@w15g2000pro.googlegroups.com> Message-ID: On 10 September 2010 11:43, C Barrington-Leigh wrote: > >> The best place to ask about numpy related stuff is the numpy mailing list at: >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> This is also the best place to present a patch if you have code to >> contribute. In my experience the numpy devs are always happy to have >> new contributors, but be sure to discuss the problem first, as the >> folk over there might be able to provide a solution which doesn't >> require a new patch. > > > Thanks, Tim, > > Ooops -- the sem() I mentioned is ?sciypy.stats.sem, not in numpy... > Does your advice hold? > Thanks, For discussion out that function you probably want the scipy-user mailing list. For completeness, here's the full list of related mailing lists: http://www.scipy.org/Mailing_Lists Cheers, Tim > c > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Thu Sep 9 22:05:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 10 Sep 2010 12:05:49 +1000 Subject: Printing the name of a variable References: Message-ID: <878w3a9wua.fsf@benfinney.id.au> Albert Hopkins writes: > On Thu, 2010-09-09 at 12:43 -0700, Stephen Boulet wrote: > > Does an arbitrary variable carry an attribute describing the text in > > its name? > > Variables are not objects and so they have no attributes. Another way of thinking about is that there are no variables, only bindings between references and objects. The bindings are not directly accessible and have no attributes. Any object may have zero, one, or many references to it at any given time. Those references might be names, or something else (such as an index in a container). Python does nothing to make the references accessible to the object. If you want to keep track of such associations, you need to employ some mechanism to do so explicitly. > You can't really de-reference the object being referenced as it can > potentially contain multiple references Including the case where an object has no explicit references beyond the current expression. > But this cries the question: why do you want to do this? And usually > that question is asked when someone thinks that a: you shouldn't need > to do this and b: whatever the desired effect there is probably a > better way of accomplishing it. To anticipate a common case: if you feel you need to maintain a mapping between names and objects, Python's built-in mapping type is ?dict?; use that. -- \ ?If you do not trust the source do not use this program.? | `\ ?Microsoft Vista security dialogue | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Sep 9 22:21:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 10 Sep 2010 12:21:40 +1000 Subject: How Python works: What do you know about support for negative indices? References: Message-ID: <874ody9w3v.fsf@benfinney.id.au> Raymond Hettinger writes: > It doesn't seem to be common knowledge when and how a[x] gets > translated to a[x+len(x)]. So, here's a short info post on how Python > supports negative indices for sequences. Thanks for this. Could you post your messages using a channel that doesn't arbitrarily split your paragraphs into long-short-long-short lines? It makes paragraphs burdensome to read, and I skipped most of the message because of that. I encourage anyone whose messages are munged like that to seek correction from their mail service provider, and switch to a different one until it's fixed. -- \ ?Oh, I realize it's a penny here and a penny there, but look at | `\ me: I've worked myself up from nothing to a state of extreme | _o__) poverty.? ?Groucho Marx | Ben Finney From magawake at gmail.com Thu Sep 9 22:35:06 2010 From: magawake at gmail.com (Mag Gam) Date: Thu, 9 Sep 2010 22:35:06 -0400 Subject: reading multiple files In-Reply-To: <87sk1i8kes.fsf@dpt-info.u-strasbg.fr> References: <87sk1i8kes.fsf@dpt-info.u-strasbg.fr> Message-ID: Thanks for your response. I was going by this thread, http://mail.python.org/pipermail/tutor/2009-January/066101.html makes you wonder even if its possible. I will try your first solution by doing mkfifo on the files. On Thu, Sep 9, 2010 at 9:19 PM, Alain Ketterlin wrote: > Mag Gam writes: > >> I have 3 files which are constantly being updated therefore I use tail >> -f /var/log/file1, tail -f /var/log/file2, and tail -f /var/log/file3 >> >> For 1 file I am able to manage by >> tail -f /var/log/file1 | python prog.py >> >> prog.py looks like this: >> f=sys.stdin >> for line in f: >> ? print line >> >> But how can I get data from /var/log/file2 and /var/log/file3 ? > > Use shell tricks, e.g., with bash: > > yourpythonprog <(tail -f .../file1) <(tail -f .../file2) <(...) > > and let your prog open its three parameters like regular files (they are > fifos actually). If your shell doesn't support <(...), create the fifos > and redirect tail output before launching your prog. > > If you want "purer" python, launch the three "tail -f" with subprocess, > and use the select module to get input (you didn't explain the logic you > will follow to track three files---you may not need select if you expect > one line from each file before waiting for the next line of any). > >> I prefer a native python way instead of doing tail -f > > Emulating tail will require a lot of stat/seeks, and finding lines will > require an additional level of complexity. > > Also, tail -f has a cost [*]. The only way to avoid it is to use > inotify, which seems to have a python interface, available at > http://pyinotify.sourceforge.net/ (I've never used it). Again, emulating > tail -f with inotify is significant work. > > -- Alain. > > [*] Paul Rubin is one of the authors, I think he reads this group. > -- > http://mail.python.org/mailman/listinfo/python-list > From mwilson at the-wire.com Thu Sep 9 23:10:54 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 09 Sep 2010 23:10:54 -0400 Subject: Printing the name of a variable References: Message-ID: Stephen Boulet wrote: > Does an arbitrary variable carry an attribute describing the text in > its name? I'm looking for something along the lines of: > > x = 10 > print x.name >>>> 'x' > > Perhaps the x.__getattribute__ method? Thanks. Hmm. "Recent scholarship suggests that the Iliad and the Odyssey may not have been written by Homer, but by someone else with the same name." Mel. From metolone+gmane at gmail.com Fri Sep 10 01:37:14 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 9 Sep 2010 22:37:14 -0700 Subject: How Python works: What do you know about support for negativeindices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: "Ben Finney" wrote in message news:874ody9w3v.fsf at benfinney.id.au... > Raymond Hettinger writes: > >> It doesn't seem to be common knowledge when and how a[x] gets >> translated to a[x+len(x)]. So, here's a short info post on how Python >> supports negative indices for sequences. > > Thanks for this. Could you post your messages using a channel that > doesn't arbitrarily split your paragraphs into long-short-long-short > lines? It makes paragraphs burdensome to read, and I skipped most of the > message because of that. > > I encourage anyone whose messages are munged like that to seek > correction from their mail service provider, and switch to a different > one until it's fixed. > > -- > \ ?Oh, I realize it's a penny here and a penny there, but look at | > `\ me: I've worked myself up from nothing to a state of extreme | > _o__) poverty.? ?Groucho Marx | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list It came across fine for me (on much maligned Outlook Express, no less). -Mark From nhodgson at bigpond.net.au Fri Sep 10 02:27:02 2010 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 10 Sep 2010 16:27:02 +1000 Subject: How Python works: What do you know about support for negativeindices? In-Reply-To: References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: <4dkio.6129$FH2.3731@viwinnwfe02.internal.bigpond.com> Mark Tolonen: > It came across fine for me (on much maligned Outlook Express, no less). Yes, looks fine to me both in Thunderbird (news, not mailing list) and at Google Groups. There is a single text part with all lines except an URL easily within 80 columns. Perhaps there is a problem in Ben's reader or in the mailing list gateway. Neil From skippy.hammond at gmail.com Fri Sep 10 03:09:27 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 10 Sep 2010 17:09:27 +1000 Subject: 32 bit bdist_wininst vs x64 platform In-Reply-To: <4C88C4E8.6080003@chamonix.reportlab.co.uk> References: <4C88C4E8.6080003@chamonix.reportlab.co.uk> Message-ID: <4C89D9A7.9070403@gmail.com> Hi Robin, On 9/09/2010 9:28 PM, Robin Becker wrote: > A reportlab user is using 32 bit python on x64 win 2003. he has a > problem installing our bdist_wininst exe because the installer cannot > find python. That should work fine - lots of pywin32 users do exactly that. > Apparently the installer is looking at HKLM\Software to locate python, > but on x64 32 bit program requests get redirected to > HKLM\Software\Wow6432Node (Extended explanation in KB article 896459). > > Is this fixable by me making a local patch to my distutils to check for > the real platform and modifying the RegOpenKeyEx call? Or is there some > distutils magic that I'm missing? As you mention, 32bit apps querying the registry get redirected in some cases - but so long as the 32bit bdist_wininst stub is used, that too will get redirected, so it should all work out fine. Is it possible they are attempting to install an x64 version of reportlab on a 32bit python? Mark From paul.nospam at rudin.co.uk Fri Sep 10 03:13:33 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 10 Sep 2010 08:13:33 +0100 Subject: Printing the name of a variable References: Message-ID: <87eid2xe8y.fsf@rudin.co.uk> Stephen Boulet writes: > Does an arbitrary variable carry an attribute describing the text in > its name? I'm looking for something along the lines of: > > x = 10 > print x.name >>>> 'x' > > Perhaps the x.__getattribute__ method? Thanks. The first thing is... what is your use case for this? I'd guess that you probably don't want to do this even if you think you do :) The thing referred to by x is the number 10. When you write x.name (or property) then you're dealing with the number 10, not with some representation of the variable x. There may be many variables (or none) that refer to that number at any given time during the execution of your code... and the object itself "knows" nothing about any of these. A good way to think about variable lookup is as a dictionary . It's something like "variables['x'].name". Once the "varables['x'] bit has been evaluated the link with 'x' is gone... we just have the result of the lookup. If you want to know how it actually works, then read up on python namespaces and scopes, e.g. here: . From eckhardt at satorlaser.com Fri Sep 10 03:36:08 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 10 Sep 2010 09:36:08 +0200 Subject: How Python works: What do you know about support for negative indices? References: Message-ID: <8o3pl7-8ch.ln1@satorlaser.homedns.org> Raymond Hettinger wrote: > collections.deque('abcde').__getitem__[-2] # extension class, magic > method Small nit: You don't mean [square] brackets here, right? Otherwise, good posting, thank you! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From bussiere at gmail.com Fri Sep 10 03:40:42 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Fri, 10 Sep 2010 09:40:42 +0200 Subject: inspect the call stack Message-ID: i v'e got this : i've got toto.py : import titi def niwhom(): pass and titi.py : def nipang(): pass how can i know in titi.py that's it's toto.py that is calling titi.py and the path of toto ? how can i inspect the call stack or an other way ? Regards Bussiere Google Fan boy From robin at reportlab.com Fri Sep 10 04:52:57 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 10 Sep 2010 09:52:57 +0100 Subject: 32 bit bdist_wininst vs x64 platform In-Reply-To: <4C89D9A7.9070403@gmail.com> References: <4C88C4E8.6080003@chamonix.reportlab.co.uk> <4C89D9A7.9070403@gmail.com> Message-ID: <4C89F1E9.1060308@chamonix.reportlab.co.uk> .......... > > As you mention, 32bit apps querying the registry get redirected in some cases - > but so long as the 32bit bdist_wininst stub is used, that too will get > redirected, so it should all work out fine. Is it possible they are attempting > to install an x64 version of reportlab on a 32bit python? .......... I'm a bit puzzled about this as well, they mentioned something about the python being embedded so perhaps that's the problem. I am trying to ascertain the exact context. -- Robin Becker From ldo at geek-central.gen.new_zealand Fri Sep 10 05:26:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 10 Sep 2010 21:26:26 +1200 Subject: SendKeys and Python 2.7 References: Message-ID: In message , Jakson A. Aquino wrote: > I would like to send code from Vim [1] to R [2] on Microsoft Windows. Why such a roundabout way? Why not just run R in a subprocess and feed it a script to run? > [1] http://www.vim.org/ > [2] http://www.r-project.org/ From ldo at geek-central.gen.new_zealand Fri Sep 10 05:27:56 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 10 Sep 2010 21:27:56 +1200 Subject: [Tutor] Arguments from the command line References: <8662yfklzu.fsf@aiuole.stru.polimi.it> Message-ID: In message <8662yfklzu.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: > Dennis Lee Bieber writes: > >> FORTRAN just differentiates by having the main file start with >> PROGRAM random_name >> whereas subfiles are all either (or both) >> SUBROUTINE another_name(args) >> FUNCTION that_other_name(args) > > no BLOCKDATA? I think you mean COMMON. From ldo at geek-central.gen.new_zealand Fri Sep 10 05:28:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 10 Sep 2010 21:28:47 +1200 Subject: [Tutor] Arguments from the command line References: Message-ID: In message , Mel wrote: > But historical COBOL didn't pass parameters anyway. You read > your optional arguments from a file, or accepted a few from an input > device. I think it could also read from switches. As in front-panel on/off switches. From giacomo.boffi at polimi.it Fri Sep 10 05:44:32 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Fri, 10 Sep 2010 11:44:32 +0200 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: <864odyszjz.fsf@aiuole.stru.polimi.it> Ben Finney writes: > Raymond Hettinger writes: > >> It doesn't seem to be common knowledge when and how a[x] gets >> translated to a[x+len(x)]. So, here's a short info post on how Python >> supports negative indices for sequences. > > Thanks for this. Could you post your messages using a channel that > doesn't arbitrarily split your paragraphs into long-short-long-short > lines? hi Ben, i see that you uses gnus... well, it's gnus that does the unwanted formatting try C-u g, as dettailed below, ciao g runs `gnus-summary-show-article' `gnus-summary-show-article' is an interactive compiled Lisp function -- loaded from "gnus-sum" (gnus-summary-show-article &optional ARG) Documentation: Force redisplaying of the current article. If ARG (the prefix) is a number, show the article with the charset defined in `gnus-summary-show-article-charset-alist', or the charset input. If ARG (the prefix) is non-nil and not a number, show the raw article without any article massaging functions being run. Normally, the key strokes are `C-u g'. -- la lenza penzola -- PMF, in IHC From tartley at tartley.com Fri Sep 10 06:13:31 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 10 Sep 2010 03:13:31 -0700 (PDT) Subject: Printing the name of a variable References: Message-ID: <76613ad4-5d89-4f68-a075-79db0c15fa5d@y3g2000vbm.googlegroups.com> On Sep 9, 9:11?pm, Albert Hopkins wrote: > On Thu, 2010-09-09 at 12:43 -0700, Stephen Boulet wrote: > > Does an arbitrary variable carry an attribute describing the text in > > its name? I'm looking for something along the lines of: > > > x = 10 > > print x.name > > >>> 'x' > > > Perhaps the x.__getattribute__ method? Thanks. > > Variables are not objects and so they have no attributes. > > You can't really de-reference the object being referenced as it can > potentially contain multiple references, but an innacurate way of doing > this would be, e.g. > > >>> x = [1, 2, 3] > >>> y = x > >>> g = globals() > >>> varnames = [i for i in g if g[i] is x] > > ['x', 'y'] > > But this cries the question: why do you want to do this? ?And usually > that question is asked when someone thinks that a: you shouldn't need to > do this and b: whatever the desired effect there is probably a better > way of accomplishing it. I have in the past wondered about creating a kind of graphical debugger, that rendered representations of all the objects in globals and/or locals, to give you a visual representation of your variables and their states. Would this be a valid use case to try and look up the variable names which reference various in-memory objects? From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 06:14:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Sep 2010 10:14:40 GMT Subject: How Python works: What do you know about support for negative indices? References: Message-ID: <4c8a0510$0$11111$c3e8da3@news.astraweb.com> On Thu, 09 Sep 2010 18:37:49 -0700, Raymond Hettinger wrote: > Hello Folks. > > It doesn't seem to be common knowledge when and how a[x] gets translated > to a[x+len(x)]. So, here's a short info post on how Python supports > negative indices for sequences. [...] > Hope you all found this to be informative, Thanks Raymond! -- Steven From giacomo.boffi at polimi.it Fri Sep 10 06:25:17 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Fri, 10 Sep 2010 12:25:17 +0200 Subject: [Tutor] Arguments from the command line References: <8662yfklzu.fsf@aiuole.stru.polimi.it> Message-ID: <86wrqtsxo2.fsf@aiuole.stru.polimi.it> Lawrence D'Oliveiro writes: > In message <8662yfklzu.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: > >> Dennis Lee Bieber writes: >> >>> FORTRAN just differentiates by having the main file start with >>> PROGRAM random_name >>> whereas subfiles are all either (or both) >>> SUBROUTINE another_name(args) >>> FUNCTION that_other_name(args) >> >> no BLOCKDATA? > > I think you mean COMMON. i meant BLOCKDATA From simon at brunningonline.net Fri Sep 10 06:26:24 2010 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 10 Sep 2010 11:26:24 +0100 Subject: Printing the name of a variable In-Reply-To: References: Message-ID: On 9 September 2010 20:43, Stephen Boulet wrote: > Does an arbitrary variable carry an attribute describing the text in > its name? I'm looking for something along the lines of: > > x = 10 > print x.name >>>> 'x' -- Cheers, Simon B. From fetchinson at googlemail.com Fri Sep 10 06:46:18 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 10 Sep 2010 12:46:18 +0200 Subject: How Python works: What do you know about support for negative indices? In-Reply-To: <874ody9w3v.fsf@benfinney.id.au> References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: > Raymond Hettinger writes: > >> It doesn't seem to be common knowledge when and how a[x] gets >> translated to a[x+len(x)]. So, here's a short info post on how Python >> supports negative indices for sequences. > > Thanks for this. Could you post your messages using a channel that > doesn't arbitrarily split your paragraphs into long-short-long-short > lines? It came across fine for me as well (gmail with basic html interface). > It makes paragraphs burdensome to read, and I skipped most of the > message because of that. You might want to switch to a client where you do not have this problem. > I encourage anyone whose messages are munged like that to seek > correction from their mail service provider, and switch to a different > one until it's fixed. I encourage anyone who has problems with reading various emails, newsgroup postings, forums and what not, to start using modern tools that work with the vast majority of other tools. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From robin at reportlab.com Fri Sep 10 07:57:21 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 10 Sep 2010 12:57:21 +0100 Subject: 32 bit bdist_wininst vs x64 platform In-Reply-To: <4C89F1E9.1060308@chamonix.reportlab.co.uk> References: <4C88C4E8.6080003@chamonix.reportlab.co.uk> <4C89D9A7.9070403@gmail.com> <4C89F1E9.1060308@chamonix.reportlab.co.uk> Message-ID: <4C8A1D21.4040303@chamonix.reportlab.co.uk> On 10/09/2010 09:52, Robin Becker wrote: > .......... >> >> As you mention, 32bit apps querying the registry get redirected in some cases - >> but so long as the 32bit bdist_wininst stub is used, that too will get >> redirected, so it should all work out fine. Is it possible they are attempting >> to install an x64 version of reportlab on a 32bit python? > .......... > > I'm a bit puzzled about this as well, they mentioned something about the python > being embedded so perhaps that's the problem. I am trying to ascertain the exact > context. > > I found out that although the end users had installed the amd64 python they were using reportlab-2.4.win32-py2.6.exe which is 32 bit. That complained until they fixed everything up by brute force registry copying. Fortunately, I don't think the pyds are importable and reportlab is robust enough to fall back to a working state even without those. -- Robin Becker From bruno.42.desthuilliers at websiteburo.invalid Fri Sep 10 10:50:58 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 10 Sep 2010 16:50:58 +0200 Subject: include a file in a python program In-Reply-To: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> References: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c8a45b9$0$12932$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Mon, 06 Sep 2010 00:57:30 +0200, bussiere bussiere wrote: > >> i've got a python.txt that contain python and it must stay as it >> (python.txt) > > Why? Is it against the law to change it? *wink* > >> how can i include it in my program ? >> import python.txt doesn't work > > > You could write a custom importer to handle it, but I can't help you with > that. Try Google. > >> is there a way : >> a) to make an include("python.txt") >> b) tell him to treat .txt as .py file that i can make an import python ? > > fp = open("python.txt") > text = fp.read() > fp.close() > exec(text) or just: execfile("python.txt") > But keep in mind that the contents of python.txt will be executed as if > you had typed it yourself. If you don't trust the source with your life > (or at least with the contents of your computer), don't execute it. +10 From bruno.42.desthuilliers at websiteburo.invalid Fri Sep 10 10:56:17 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 10 Sep 2010 16:56:17 +0200 Subject: inspect the call stack In-Reply-To: References: Message-ID: <4c8a46f8$0$4568$426a34cc@news.free.fr> bussiere bussiere a ?crit : > i v'e got this : > i've got toto.py : > > import titi > def niwhom(): > pass > > and titi.py : > > def nipang(): > pass > > how can i know in titi.py that's it's toto.py that is calling titi.py > and the path of toto ? > > how can i inspect the call stack or an other way ? http://www.google.fr/search?q=python+inspect+the+call+stack First answer should point you to the relevant part of the FineManual(tm): http://docs.python.org/library/inspect.html And while we're at it, what about not opening a new thread for a question already partially answered ? From michael.a.powe at gmail.com Fri Sep 10 12:09:15 2010 From: michael.a.powe at gmail.com (naugiedoggie) Date: Fri, 10 Sep 2010 09:09:15 -0700 (PDT) Subject: Trap Authentication Errors in HTTP Request Message-ID: Hello, I have a script that authenticates to a web service provider to retrieve data. This script provides an authentication header built in a very basic way like this: # Creates an authentication object with the credentials for a given URL def createPasswordManager(headers) : passwordManager = urllib2.HTTPPasswordMgrWithDefaultRealm() passwordManager.add_password(None,overview_url,headers[0],headers[1]) return passwordManager # Creates an authentication handler for the authentication object created above def createAuthenticationHandler(passwordManager) : authenticationHandler = urllib2.HTTPBasicAuthHandler(passwordManager) return authenticationHandler # Creates an opener that sets the credentials in the Request def createOpener(authHandler) : return urllib2.build_opener(authHandler) This script makes multiple calls for data. I would like to trap an exception for authentication failure so that it doesn't go through its entire list of calls when there's a problem with the login. The assumption is that if there is a login failure, the script is using incorrect authentication information. I have the call for data retrieval wrapped in try/except, to catch HTTPError, but apparently no '401' is explicitly thrown when authentication fails. And I don't see an explicit Exception that is thrown in urllib2 for handling these failures. How can I achieve my goal of trapping these exceptions and exiting cleanly? Thanks. mp From jakecjacobson at gmail.com Fri Sep 10 12:20:46 2010 From: jakecjacobson at gmail.com (jakecjacobson) Date: Fri, 10 Sep 2010 09:20:46 -0700 (PDT) Subject: How to Convert IO Stream to XML Document Message-ID: I am trying to build a Python script that reads a Sitemap file and push the URLs to a Google Search Appliance. I am able to fetch the XML document and parse it with regular expressions but I want to move to using native XML tools to do this. The problem I am getting is if I use urllib.urlopen(url) I can convert the IO Stream to a XML document but if I use urllib2.urlopen and then read the response, I get the content but when I use minidom.parse() I get a "IOError: [Errno 2] No such file or directory:" error THIS WORKS but will have issues if the IO Stream is a compressed file def GetPageGuts(net, url): pageguts = urllib.urlopen(url) xmldoc = minidom.parse(pageguts) return xmldoc # THIS DOESN'T WORK, but I don't understand why def GetPageGuts(net, url): request=getRequest_obj(net, url) response = urllib2.urlopen(request) response.headers.items() pageguts = response.read() # Test to see if the response is a gzip/compressed data stream if isCompressedFile(response, url): compressedstream = StringIO.StringIO(pageguts) gzipper = gzip.GzipFile(fileobj = compressedstream) pageguts = gzipper.read() xmldoc = minidom.parse(pageguts) response.close() return xmldoc # I am getting the following error Starting SiteMap Manager ... Traceback (most recent call last): File "./tester.py", line 267, in ? main() File "./tester.py", line 49, in main fetchSiteMap(ResourceDict, line) File "./tester.py", line 65, in fetchSiteMap pageguts = GetPageGuts(ResourceDict['NET'], url) File "./tester.py", line 89, in GetPageGuts xmldoc = minidom.parse(pageguts) File "/usr/lib/python2.4/xml/dom/minidom.py", line 1915, in parse return expatbuilder.parse(file) File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 922, in parse fp = open(file, 'rb') IOError: [Errno 2] No such file or directory: '\n\n\nhttp://www.myorg.org/janes/ sitemaps/binder_sitemap.xml\n2010-09-09\n\n\nhttp://www.myorg.org/janes/sitemaps/ dir_sitemap.xml\n2010-05-05\n \n\nhttp://www.myorg.org/janes/sitemaps/ mags_sitemap.xml\n2010-09-09\n \n\nhttp://www.myorg.org/janes/sitemaps/ news_sitemap.xml\n2010-09-09\n \n\nhttp://www.myorg.org/janes/sitemaps/ sent_sitemap.xml\n2010-09-09\n \n\nhttp://www.myorg.org/janes/sitemaps/ srep_sitemap.xml\n2001-05-04\n \n\nhttp://www.myorg.org/janes/sitemaps/yb_sitemap.xml\n2010-09-09\n\n\n' # A couple of supporting things def getRequest_obj(net, url): request = urllib2.Request(url) request.add_header('User-Agent', 'ICES Sitemap Bot dni-ices- searchadmin at ugov.gov') request.add_header('Accept-encoding', 'gzip') return request def isCompressedFile(r, u): answer=False if r.headers.has_key('Content-encoding'): answer=True else: # Check to see if the URL ends in .gz if u.endswith(".gz"): answer=True return answer From fuglyducky at gmail.com Fri Sep 10 12:27:28 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Fri, 10 Sep 2010 09:27:28 -0700 (PDT) Subject: Ugh! Python 3.1.x and MySQL Message-ID: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> Most of the python books coming out now are Py3K. I just started programming and have a need to access a MySQL database. I would like to use Python to do this. Unfortunately, I cannot find anyone that has created anything that allows my to do this. I've tried installing an ODBC driver and using sqlalchemy, oursql, and a few other things with no luck. So...just wondering if anyone is aware of any libraries/modules that I can use to connect to a MySQL DB using Python 3.1.x? Ideally, I'd like to be able to this from both x86 and x64 systems (if that makes any difference). Thanks for any input you may have!!! From nitinpawar432 at gmail.com Fri Sep 10 12:28:36 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Fri, 10 Sep 2010 21:58:36 +0530 Subject: How to Convert IO Stream to XML Document In-Reply-To: References: Message-ID: try using parse from string ... and try minidom.parse(StringIO.StingIO(string)).documentElement On Fri, Sep 10, 2010 at 9:50 PM, jakecjacobson wrote: > I am trying to build a Python script that reads a Sitemap file and > push the URLs to a Google Search Appliance. I am able to fetch the > XML document and parse it with regular expressions but I want to move > to using native XML tools to do this. The problem I am getting is if > I use urllib.urlopen(url) I can convert the IO Stream to a XML > document but if I use urllib2.urlopen and then read the response, I > get the content but when I use minidom.parse() I get a "IOError: > [Errno 2] No such file or directory:" error > > THIS WORKS but will have issues if the IO Stream is a compressed file > def GetPageGuts(net, url): > pageguts = urllib.urlopen(url) > xmldoc = minidom.parse(pageguts) > return xmldoc > > # THIS DOESN'T WORK, but I don't understand why > def GetPageGuts(net, url): > request=getRequest_obj(net, url) > response = urllib2.urlopen(request) > response.headers.items() > pageguts = response.read() > # Test to see if the response is a gzip/compressed data stream > if isCompressedFile(response, url): > compressedstream = StringIO.StringIO(pageguts) > gzipper = gzip.GzipFile(fileobj = compressedstream) > pageguts = gzipper.read() > xmldoc = minidom.parse(pageguts) > response.close() > return xmldoc > > # I am getting the following error > Starting SiteMap Manager ... > Traceback (most recent call last): > File "./tester.py", line 267, in ? > main() > File "./tester.py", line 49, in main > fetchSiteMap(ResourceDict, line) > File "./tester.py", line 65, in fetchSiteMap > pageguts = GetPageGuts(ResourceDict['NET'], url) > File "./tester.py", line 89, in GetPageGuts > xmldoc = minidom.parse(pageguts) > File "/usr/lib/python2.4/xml/dom/minidom.py", line 1915, in parse > return expatbuilder.parse(file) > File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 922, in > parse > fp = open(file, 'rb') > IOError: [Errno 2] No such file or directory: ' encoding="UTF-8"?>\n\n\nhttp://www.myorg.org/janes/ > sitemaps/binder_sitemap.xml\n2010-09-09\n sitemap>\n\nhttp://www.myorg.org/janes/sitemaps/ > dir_sitemap.xml\n2010-05-05\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > mags_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > news_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > sent_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > srep_sitemap.xml\n2001-05-04\n > \n\nhttp://www.myorg.org/janes/sitemaps/yb_sitemap.xml loc>\n2010-09-09\n\n\n' > > # A couple of supporting things > def getRequest_obj(net, url): > request = urllib2.Request(url) > request.add_header('User-Agent', 'ICES Sitemap Bot dni-ices- > searchadmin at ugov.gov') > request.add_header('Accept-encoding', 'gzip') > return request > > def isCompressedFile(r, u): > answer=False > if r.headers.has_key('Content-encoding'): > answer=True > else: > # Check to see if the URL ends in .gz > if u.endswith(".gz"): > answer=True > return answer > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From jaksonaquino at gmail.com Fri Sep 10 12:49:00 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Fri, 10 Sep 2010 13:49:00 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: Message-ID: On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro wrote: > In message , Jakson A. > Aquino wrote: > >> I would like to send code from Vim [1] to R [2] on Microsoft Windows. > > Why such a roundabout way? Why not just run R in a subprocess and feed it a > script to run? Emacs with ESS runs R in a subprocess (at least I think it does). Vim can't do that. The plugin doesn't simply send code to R. It has many other features that make it easier to edit R scripts. Best, Jakson From python at mrabarnett.plus.com Fri Sep 10 12:52:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Sep 2010 17:52:54 +0100 Subject: [Python-ideas] Why not f(*my_list, *my_other_list) ? In-Reply-To: References: Message-ID: <4C8A6266.5090501@mrabarnett.plus.com> On 10/09/2010 17:37, cool-RR wrote: > I noticed that it's impossible to call a Python function with two > starred argument lists, like this: `f(*my_list, *my_other_list)`. I > mean, if someone wants to feed two lists of arguments into a function, > why not? > > I understand why you can't have two stars in a function definition; But > why can't you have two (or more) stars in a function call? > Would there be any advantage over `f(*(my_list + my_other_list))`? From ian.g.kelly at gmail.com Fri Sep 10 13:03:54 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 10 Sep 2010 11:03:54 -0600 Subject: [Python-ideas] Why not f(*my_list, *my_other_list) ? In-Reply-To: <4C8A6266.5090501@mrabarnett.plus.com> References: <4C8A6266.5090501@mrabarnett.plus.com> Message-ID: On Fri, Sep 10, 2010 at 10:52 AM, MRAB wrote: > On 10/09/2010 17:37, cool-RR wrote: >> >> I noticed that it's impossible to call a Python function with two >> starred argument lists, like this: `f(*my_list, *my_other_list)`. I >> mean, if someone wants to feed two lists of arguments into a function, >> why not? >> >> I understand why you can't have two stars in a function definition; But >> why can't you have two (or more) stars in a function call? >> > Would there be any advantage over `f(*(my_list + my_other_list))`? That fails if my_list and my_other_list are different types, whereas the *args syntax happily accepts any iterable object. From stefan_ml at behnel.de Fri Sep 10 13:13:42 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 10 Sep 2010 19:13:42 +0200 Subject: [Python-ideas] Why not f(*my_list, *my_other_list) ? In-Reply-To: References: <4C8A6266.5090501@mrabarnett.plus.com> Message-ID: Ian Kelly, 10.09.2010 19:03: > On Fri, Sep 10, 2010 at 10:52 AM, MRAB wrote: >> On 10/09/2010 17:37, cool-RR wrote: >>> >>> I noticed that it's impossible to call a Python function with two >>> starred argument lists, like this: `f(*my_list, *my_other_list)`. I >>> mean, if someone wants to feed two lists of arguments into a function, >>> why not? >>> >>> I understand why you can't have two stars in a function definition; But >>> why can't you have two (or more) stars in a function call? >>> >> Would there be any advantage over `f(*(my_list + my_other_list))`? > > That fails if my_list and my_other_list are different types, whereas > the *args syntax happily accepts any iterable object. But I think it's still a rare enough use case to require f(*(tuple(my_list) + tuple(my_other_list))) when you need it, although the concatenation would likely get split up and moved into an explicit variable anyway. Stefan From johnroth1 at gmail.com Fri Sep 10 13:13:53 2010 From: johnroth1 at gmail.com (John Roth) Date: Fri, 10 Sep 2010 10:13:53 -0700 (PDT) Subject: Function Point Analysis (FPA) - Equivalent lines of code of Python References: <168f109f-834f-4e99-88cf-35e1ffdc6297@b4g2000pra.googlegroups.com> Message-ID: <6445cba6-48b4-4f38-9073-34f26592385e@u4g2000prn.googlegroups.com> On Sep 9, 2:30?am, Nicholas wrote: > Hi, > > ? In FPA, there are tables which shows equivalent lines of code for > each Function Point (FP) for a number of programming languages. > > ? e.g.http://www.qsm.com/?q=resources/function-point-languages-table/index.... > > ? However, I have yet to find the figures for Python. > > ? Is someone able to advise the closest language equivalent. > > Regards Function points do not translate to lines of code except when they're standardized across a specific organization's portfolio of software. I agree with Paul, any global table trying to do that is going to be pretty bogus. John Roth From no.email at nospam.invalid Fri Sep 10 13:28:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 10 Sep 2010 10:28:14 -0700 Subject: [Python-ideas] Why not f(*my_list, *my_other_list) ? References: <4C8A6266.5090501@mrabarnett.plus.com> Message-ID: <7x7hit7bkh.fsf@ruckus.brouhaha.com> Ian Kelly writes: >> Would there be any advantage over `f(*(my_list + my_other_list))`? > > That fails if my_list and my_other_list are different types, whereas > the *args syntax happily accepts any iterable object. f(*itertools.chain(my_list, my_other_list)) From ron.eggler at gmail.com Fri Sep 10 13:51:25 2010 From: ron.eggler at gmail.com (cerr) Date: Fri, 10 Sep 2010 10:51:25 -0700 (PDT) Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> Message-ID: <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> On Sep 9, 4:18?pm, MRAB wrote: > On 09/09/2010 23:52, cerr wrote: > > > > > On Sep 9, 3:29 pm, Alain Ketterlin > > wrote: > >> cerr ?writes: > >>> I'm calling a python script from a php script which again calls a perl > >>> script with subprocess.popen(). > >>> This seems to work fine so far only that once the python script > >>> completed it is becoming a zombie because the perl script in the > >>> background is still running... so before i exit the python script, i > >>> would need to kill my perl subprocess. > >>> How can i do so? > > >> x.terminate() (and then x.wait()) where x is the value returned by > >> subprocess.Popen(). > > Well, this is what I have: > > > ? ?writelog("starting GPS simulator") > > ? ?commandlist=[GPSsim,proto,GPSfile] > > ? ?writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) > > ? ?process=subprocess.Popen(commandlist) > > ? ?writelog("GPS simulator started") > > ? ?... > > ? ?... > > ? ?os.kill(process.pid,9) > > ? ?os.wait() > > > but this is not working for me... :( any clues? > > >> P/S: I'm not sure why the python process survives, and I think your use > >> of "zombie" is not correct (afaik a zombie is an exited process whose > >> parent hasn't called wait() yet) > > > This is what I have: > > > localhost cgi-bin # ps ax | grep py > > 11853 ? ? ? ? ?Z ? ? ?0:00 [python2.6] > > 12029 pts/1 ? ?S+ ? ? 0:00 grep --colour=auto py > > > The 'Z' you see there stands for Zombie > > How about: > > ? ? ?process.kill() # New in Python 2.6 > > or: > > ? ? ?os.kill(process.pid, 9) > > then: > > ? ? ?process.wait() > > or: > > ? ? ?os.waitpid(process.pid, 0) HI MRAB, Thanks for your suggestion, changed my code now to: process=subprocess.Popen(commandlist) ... ... process.kill() os.waitpid(process.pid, 0) but it's not killing the process running. it still runs in the background and i don't see any errors, we're running python 2.6.4 any more clues? Thanks, Ron From rami.chowdhury at merton.oxon.org Fri Sep 10 14:10:45 2010 From: rami.chowdhury at merton.oxon.org (Rami Chowdhury) Date: Sat, 11 Sep 2010 00:10:45 +0600 Subject: Ugh! Python 3.1.x and MySQL In-Reply-To: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> References: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> Message-ID: On Fri, Sep 10, 2010 at 22:27, fuglyducky wrote: > Most of the python books coming out now are Py3K. I just started > programming and have a need to access a MySQL database. I would like > to use Python to do this. Unfortunately, I cannot find anyone that has > created anything that allows my to do this. > > I've tried installing an ODBC driver and using sqlalchemy, oursql, and > a few other things with no luck. > > So...just wondering if anyone is aware of any libraries/modules that I > can use to connect to a MySQL DB using Python 3.1.x? > Have you tried OurSQL (http://packages.python.org/oursql/)? > > Ideally, I'd like to be able to this from both x86 and x64 systems (if > that makes any difference). > > Thanks for any input you may have!!! > -- > http://mail.python.org/mailman/listinfo/python-list > -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Fri Sep 10 14:23:34 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 10 Sep 2010 14:23:34 -0400 Subject: bool constructor is inconsistent? Message-ID: IN [3]: bool('False') Out[3]: True In [4]: int('32') Out[4]: 32 From sschwarzer at sschwarzer.net Fri Sep 10 14:35:10 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Fri, 10 Sep 2010 20:35:10 +0200 Subject: bool constructor is inconsistent? In-Reply-To: References: Message-ID: <4C8A7A5E.1010404@sschwarzer.net> Hi Neal, On 2010-09-10 20:23, Neal Becker wrote: > IN [3]: bool('False') > Out[3]: True If you consider strings, only an empty string has a false value. So the string 'False' which is non-empty, results in a true boolean value. For example, you can use if my_string: ... to execute some code if the string is not empty. Stefan From stefan_ml at behnel.de Fri Sep 10 14:36:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 10 Sep 2010 20:36:07 +0200 Subject: bool constructor is inconsistent? In-Reply-To: References: Message-ID: Neal Becker, 10.09.2010 20:23: > IN [3]: bool('False') > Out[3]: True Not inconsistent at all: >>> bool('false') True >>> bool('true') True >>> bool('') False >>> bool(32) True >>> bool(0) False It simply follows Python's boolean coercion rules. If you consider it inconsisten w.r.t. int('32'), then what about >>> list('[]') ['[', ']'] Stefan From emile at fenx.com Fri Sep 10 14:36:14 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 10 Sep 2010 11:36:14 -0700 Subject: bool constructor is inconsistent? In-Reply-To: References: Message-ID: On 9/10/2010 11:23 AM Neal Becker said... > IN [3]: bool('False') > Out[3]: True > > In [4]: int('32') > Out[4]: 32 > >>> eval('False') False >>> eval('32') 32 >>> Otherwise, 'False' is just a string? Emile From lists at cheimes.de Fri Sep 10 14:45:32 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 10 Sep 2010 20:45:32 +0200 Subject: how to kill a subprocess In-Reply-To: <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> Message-ID: Am 10.09.2010 19:51, schrieb cerr: > Thanks for your suggestion, changed my code now to: > > process=subprocess.Popen(commandlist) > ... > ... > process.kill() > os.waitpid(process.pid, 0) > but it's not killing the process running. it still runs in the > background and i don't see any errors, we're running python 2.6.4 > any more clues? It's not an issue with your Python process but with its parent process. The parent process has to call the OS's waitpid() function with the PID of the Python process in order to reap it. Please show us how you are starting and controlling the Python process in your PHP code. Christian From ron.eggler at gmail.com Fri Sep 10 14:56:15 2010 From: ron.eggler at gmail.com (cerr) Date: Fri, 10 Sep 2010 11:56:15 -0700 (PDT) Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> Message-ID: <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> On Sep 10, 11:45?am, Christian Heimes wrote: > Am 10.09.2010 19:51, schrieb cerr: > > > Thanks for your suggestion, changed my code now to: > > > ? process=subprocess.Popen(commandlist) > > ? ... > > ? ... > > ? process.kill() > > ? os.waitpid(process.pid, 0) > > but it's not killing the process running. it still runs in the > > background and i don't see any errors, we're running python 2.6.4 > > any more clues? > > It's not an issue with your Python process but with its parent process. > The parent process has to call the OS's waitpid() function with the PID > of the Python process in order to reap it. Please show us how you are > starting and controlling the Python process in your PHP code. But I wanna kill the child process I start from my python code. It's like PHP -> Python -> Perl and when the connection PHP -> Python seems to work well! From sonukr666 at gmail.com Fri Sep 10 15:10:55 2010 From: sonukr666 at gmail.com (sahilsk) Date: Fri, 10 Sep 2010 12:10:55 -0700 (PDT) Subject: 3D cube navigation Message-ID: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> hi, i need to make a 3d cube as a navigation menu.. each face having separate button .. or effect. any idea, how can i make one such 3D figures with functionality of mouse events? From lists at cheimes.de Fri Sep 10 15:18:27 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 10 Sep 2010 21:18:27 +0200 Subject: how to kill a subprocess In-Reply-To: <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> Message-ID: Am 10.09.2010 20:56, schrieb cerr: > But I wanna kill the child process I start from my python code. > It's like > PHP -> Python -> Perl > > and when the connection PHP -> Python seems to work well! You have said that the Python process becomes a zombie process. This clearly tells me that the issue is in your PHP script. See http://en.wikipedia.org/wiki/Fork-exec Christian From drobinow at gmail.com Fri Sep 10 15:56:38 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 10 Sep 2010 15:56:38 -0400 Subject: bool constructor is inconsistent? In-Reply-To: <4C8A7A5E.1010404@sschwarzer.net> References: <4C8A7A5E.1010404@sschwarzer.net> Message-ID: On Fri, Sep 10, 2010 at 2:35 PM, Stefan Schwarzer wrote: > Hi Neal, > > On 2010-09-10 20:23, Neal Becker wrote: >> IN [3]: bool('False') >> Out[3]: True > > If you consider strings, only an empty string has a false > value. So the string 'False' which is non-empty, results in > a true boolean value. > ... I've always felt that if a humorous post needs a smiley, that it's not funny. However, there is the risk of being misunderstood. From pruebauno at latinmail.com Fri Sep 10 15:57:50 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 10 Sep 2010 12:57:50 -0700 (PDT) Subject: Ugh! Python 3.1.x and MySQL References: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> Message-ID: <6cbd92b3-261d-4d6f-b5de-c3af9f44f16f@l17g2000vbf.googlegroups.com> On Sep 10, 12:27?pm, fuglyducky wrote: > Most of the python books coming out now are Py3K. I just started > programming and have a need to access a MySQL database. I would like > to use Python to do this. Unfortunately, I cannot find anyone that has > created anything that allows my to do this. > > I've tried installing an ODBC driver and using sqlalchemy, oursql, and > a few other things with no luck. > > So...just wondering if anyone is aware of any libraries/modules that I > can use to connect to a MySQL DB using Python 3.1.x? > > Ideally, I'd like to be able to this from both x86 and x64 systems (if > that makes any difference). > > Thanks for any input you may have!!! Google found this: http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/3831691 From ron.eggler at gmail.com Fri Sep 10 16:14:16 2010 From: ron.eggler at gmail.com (cerr) Date: Fri, 10 Sep 2010 13:14:16 -0700 (PDT) Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> Message-ID: <3f38a424-7130-486c-9dbf-bb19a70fce69@k17g2000prf.googlegroups.com> On Sep 10, 12:18?pm, Christian Heimes wrote: > Am 10.09.2010 20:56, schrieb cerr: > > > But I wanna kill the child process I start from my python code. > > It's like > > PHP -> Python -> Perl > > > and when the connection PHP -> Python seems to work well! > > You have said that the Python process becomes a zombie process. This > clearly tells me that the issue is in your PHP script. Seehttp://en.wikipedia.org/wiki/Fork-exec No, the Perl becomes the zombie. From lists at cheimes.de Fri Sep 10 16:36:36 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 10 Sep 2010 22:36:36 +0200 Subject: how to kill a subprocess In-Reply-To: <3f38a424-7130-486c-9dbf-bb19a70fce69@k17g2000prf.googlegroups.com> References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> <3f38a424-7130-486c-9dbf-bb19a70fce69@k17g2000prf.googlegroups.com> Message-ID: Am 10.09.2010 22:14, schrieb cerr: > No, the Perl becomes the zombie. How are you killing the Python process? Are you sending SIGINT, SIGTERM or SIGKILL? SIGKILL can prevent Python from running its cleanup code. Christian From tjreedy at udel.edu Fri Sep 10 17:13:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 10 Sep 2010 17:13:55 -0400 Subject: How Python works: What do you know about support for negative indices? In-Reply-To: References: Message-ID: On 9/9/2010 9:37 PM, Raymond Hettinger wrote: > The docs guarantee that Python's builtin sequences implement support > for negative indices ( http://docs.python.org/dev/reference/expressions.html#subscriptions The relevant paragraphs are " For built-in objects, there are two types of objects that support subscription: If the primary is a mapping, the expression list must evaluate to an object whose value is one of the keys of the mapping, and the subscription selects the value in the mapping that corresponds to that key. (The expression list is a tuple except if it has exactly one item.) If the primary is a sequence, the expression (list) must evaluate to an integer. If this value is negative, the length of the sequence is added to it (so that, e.g., x[-1] selects the last item of x.) The resulting value must be a nonnegative integer less than the number of items in the sequence, and the subscription selects the item whose index is that value (counting from zero). " Reading the third paragraph out of context, one can miss the restriction to built-in objects. I had assumed that the conversion using len(), when available, happened prior to the __getitem__ call. I believe I need to add the restriction in my discussion of negative indexing in my book. I would like the above rewritten something like the following: " Two types of built-in objects support subscription as primaries: mappings and sequences. For built-in mappings, the.... For built-in sequences, the ... " The second paragraph was written before defaultdict and does not apply to them. I presume that it is an extension rather than built-in class for the purpose of the Reference. > Hope you all found this to be informative, Definitely. I save a copy for future reference. -- Terry Jan Reedy From aahz at pythoncraft.com Fri Sep 10 18:14:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 10 Sep 2010 15:14:31 -0700 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: In article , Daniel Fetchinson wrote: >Attribution missing: >> >> I encourage anyone whose messages are munged like that to seek >> correction from their mail service provider, and switch to a different >> one until it's fixed. > >I encourage anyone who has problems with reading various emails, >newsgroup postings, forums and what not, to start using modern tools >that work with the vast majority of other tools. Why? Raymond's post worked fine for me with trn3.6.... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ldo at geek-central.gen.new_zealand Fri Sep 10 18:17:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:17:21 +1200 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: In message , Ian Kelly wrote: > And returning None on failure is dangerous, because if the programmer > does not take care to handle that case, the program may attempt to > regard it as actual data. But None *is* actual data. From ldo at geek-central.gen.new_zealand Fri Sep 10 18:18:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:18:47 +1200 Subject: [Tutor] Arguments from the command line References: <8662yfklzu.fsf@aiuole.stru.polimi.it> <86wrqtsxo2.fsf@aiuole.stru.polimi.it> Message-ID: In message <86wrqtsxo2.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: > Lawrence D'Oliveiro writes: > >> In message <8662yfklzu.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: >> >>> no BLOCKDATA? >> >> I think you mean COMMON. > > i meant BLOCKDATA BLOCKDATA is an initializer. The actual storage is allocated by COMMON. From ldo at geek-central.gen.new_zealand Fri Sep 10 18:19:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:19:49 +1200 Subject: SendKeys and Python 2.7 References: Message-ID: In message , Jakson A. Aquino wrote: > On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro > wrote: > >> In message , Jakson >> A. Aquino wrote: >> >>> I would like to send code from Vim [1] to R [2] on Microsoft Windows. >> >> Why such a roundabout way? Why not just run R in a subprocess and feed it >> a script to run? > > Emacs with ESS runs R in a subprocess (at least I think it does). Vim > can't do that. Why not? > The plugin doesn't simply send code to R. It has many other features > that make it easier to edit R scripts. But those are editing functions, nothing to do with R. From ldo at geek-central.gen.new_zealand Fri Sep 10 18:23:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:23:47 +1200 Subject: [Python-ideas] with statement syntax forces ugly line breaks? References: <20100908175029.6617ae3b@dino> Message-ID: In message , MRAB wrote: > On 08/09/2010 19:07, Georg Brandl wrote: > >> Thus spake the Lord: Thou shalt indent with four spaces. No more, no >> less. Four shall be the number of spaces thou shalt indent, and the >> number of thy indenting shall be four. Eight shalt thou not indent, >> nor either indent thou two, excepting that thou then proceed to four. >> Tabs are right out. >> > FYI, that should be "thine indenting". > > "My/thy" before a consonant, "mine/thine" before a vowel. Compare with > "a/an", which we still do. The funny thing is, that?s technically ?Modern English?... From ldo at geek-central.gen.new_zealand Fri Sep 10 18:32:48 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:32:48 +1200 Subject: [Q] Function Point Analysis (FPA) - Equivalent lines of code of Python References: <168f109f-834f-4e99-88cf-35e1ffdc6297@b4g2000pra.googlegroups.com> <7x4odz5mr3.fsf@ruckus.brouhaha.com> Message-ID: In message <7x4odz5mr3.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Nicholas writes: >> >> http://www.qsm.com/?q=resources/function-point-languages- table/index.html > > That table looks pretty bogus ... Dead giveaways are the disparity between the Ada, C++ and PL/I figures, and the fact that FORTRAN scores lower than C. Plus the inclusion of HTML and Dotnet on a par with the others. And what are ?Web Scripts", if not JavaScript? From jaksonaquino at gmail.com Fri Sep 10 18:34:11 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Fri, 10 Sep 2010 19:34:11 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: Message-ID: On Fri, Sep 10, 2010 at 7:19 PM, Lawrence D'Oliveiro wrote: > In message , Jakson A. > Aquino wrote: >> On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro >> wrote: >>> In message , Jakson >>> A. Aquino wrote: >>>> I would like to send code from Vim [1] to R [2] on Microsoft Windows. >>> >>> Why such a roundabout way? Why not just run R in a subprocess and feed it >>> a script to run? >> >> Emacs with ESS runs R in a subprocess (at least I think it does). Vim >> can't do that. > > Why not? I don't know how to embed R into Vim, but I would be grateful if you could explain how to do it since this could be an opportunity to improve my plugin. From robert.kern at gmail.com Fri Sep 10 18:38:45 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 10 Sep 2010 17:38:45 -0500 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote: > In message, Ian Kelly > wrote: > >> And returning None on failure is dangerous, because if the programmer >> does not take care to handle that case, the program may attempt to >> regard it as actual data. > > But None *is* actual data. And that is exactly the reason why the Samurai Principle says to not return None when the function fails to do what it intended to do. -- 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 krister.svanlund at gmail.com Fri Sep 10 19:09:00 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Sat, 11 Sep 2010 01:09:00 +0200 Subject: 3D cube navigation In-Reply-To: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> Message-ID: On Fri, Sep 10, 2010 at 9:10 PM, sahilsk wrote: > hi, i need to make a 3d cube as a navigation menu.. each face having > separate ?button .. or effect. > any idea, ?how can i make one such 3D figures with functionality of > mouse events? In what environment, what toolkit, for what purpose? From nagle at animats.com Fri Sep 10 19:10:31 2010 From: nagle at animats.com (John Nagle) Date: Fri, 10 Sep 2010 16:10:31 -0700 Subject: Ugh! Python 3.1.x and MySQL In-Reply-To: <6cbd92b3-261d-4d6f-b5de-c3af9f44f16f@l17g2000vbf.googlegroups.com> References: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> <6cbd92b3-261d-4d6f-b5de-c3af9f44f16f@l17g2000vbf.googlegroups.com> Message-ID: <4c8abae2$0$1647$742ec2ed@news.sonic.net> On 9/10/2010 12:57 PM, nn wrote: > On Sep 10, 12:27 pm, fuglyducky wrote: >> Most of the python books coming out now are Py3K. I just started >> programming and have a need to access a MySQL database. I would like >> to use Python to do this. Unfortunately, I cannot find anyone that has >> created anything that allows my to do this. >> >> I've tried installing an ODBC driver and using sqlalchemy, oursql, and >> a few other things with no luck. >> >> So...just wondering if anyone is aware of any libraries/modules that I >> can use to connect to a MySQL DB using Python 3.1.x? >> >> Ideally, I'd like to be able to this from both x86 and x64 systems (if >> that makes any difference). >> >> Thanks for any input you may have!!! > > Google found this: > > http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/3831691 That's progress, but it's a fork of MySQLdb. Can it be checked into the MySQLdb project on SourceForge? John Nagle From phlip2005 at gmail.com Fri Sep 10 19:12:19 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 10 Sep 2010 16:12:19 -0700 (PDT) Subject: 3D cube navigation References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> Message-ID: On Sep 10, 12:10?pm, sahilsk wrote: > hi, i need to make a 3d cube as a navigation menu.. each face having > separate ?button .. or effect. > any idea, ?how can i make one such 3D figures with functionality of > mouse events? omg If you have to ask, you probably are not ready for the answer! Is this a personal project, or are you satisfying a customer? If the latter, is it a desktop project, or a web project? If a web project, can you use a PNG of a rendered cube? Render it with PovRay (which is honestly a ton of fun to author in), then use tags to define clicks on various faces. >From here, the question arises WHY your client wants this. Must the cube rotate? Is it designed to be user hostile? Must the user rotate the cube to find the correct menu item? If you want to spend a couple weeks coding a nice learning project, you could do a rotating cube in HTML5 using the control. Someone probably has an example out there, but efficient trigonometric matrix transformations in JavaScript are not for the faint of heart. If this is for the desktop, get a Python library that wraps something that wraps OpenGL or DirectX. Or just google for "python 3d cube". Have fun! -- Phlip From martin at address-in-sig.invalid Fri Sep 10 19:42:29 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 10 Sep 2010 23:42:29 +0000 (UTC) Subject: Ugh! Python 3.1.x and MySQL References: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> Message-ID: On Fri, 10 Sep 2010 09:27:28 -0700, fuglyducky wrote: > Most of the python books coming out now are Py3K. I just started > programming and have a need to access a MySQL database. I would like to > use Python to do this. Unfortunately, I cannot find anyone that has > created anything that allows my to do this. > > I've tried installing an ODBC driver and using sqlalchemy, oursql, and a > few other things with no luck. > > So...just wondering if anyone is aware of any libraries/modules that I > can use to connect to a MySQL DB using Python 3.1.x? > > Ideally, I'd like to be able to this from both x86 and x64 systems (if > that makes any difference). > You don't say what OS you're using, but if you're on a *NIX, take a look at pyodbc: http://code.google.com/p/pyodbc/ This Python module is a wrapper for unixODBC and consequently works with standard MySQL ODBC drivers. iODBC: http://www.iodbc.org/ is similar If you want something that's Windows compatible I can't help: I don't use either Windows or MySQL. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 20:16:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 00:16:08 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: <4c8aca47$0$11111$c3e8da3@news.astraweb.com> On Sat, 11 Sep 2010 10:17:21 +1200, Lawrence D'Oliveiro wrote: > In message , Ian > Kelly wrote: > >> And returning None on failure is dangerous, because if the programmer >> does not take care to handle that case, the program may attempt to >> regard it as actual data. > > But None *is* actual data. Of course it is. Which makes it hard to distinguish None used as data from None used as a signal for an exceptional case. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 20:20:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 00:20:57 GMT Subject: 3D cube navigation References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> Message-ID: <4c8acb69$0$11111$c3e8da3@news.astraweb.com> On Sat, 11 Sep 2010 01:09:00 +0200, Krister Svanlund wrote: > On Fri, Sep 10, 2010 at 9:10 PM, sahilsk wrote: >> hi, i need to make a 3d cube as a navigation menu.. each face having >> separate ?button .. or effect. >> any idea, ?how can i make one such 3D figures with functionality of >> mouse events? > > In what environment, what toolkit, for what purpose? What do you mean, "what environment"? Surely there's only one? The Original Poster obviously wants a 3D navigation cube for ksh under FreeBSD. *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 20:25:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 00:25:07 GMT Subject: bool constructor is inconsistent? References: Message-ID: <4c8acc63$0$11111$c3e8da3@news.astraweb.com> On Fri, 10 Sep 2010 14:23:34 -0400, Neal Becker wrote: > IN [3]: bool('False') > Out[3]: True > > In [4]: int('32') > Out[4]: 32 Where is the inconsistency? bool('False') returns the same result as for any other non-empty string: >>> bool("not true") True >>> bool("no") True >>> bool("incorrect") True >>> bool("wrong") True >>> bool("Faux") True >>> bool("Falsch") True >>> bool("Falso") True >>> bool("?") True >>> bool("?????") True Treating the string "False" as identical to the named global False would be inconsistent. -- Steven From jaksonaquino at gmail.com Fri Sep 10 20:45:04 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Fri, 10 Sep 2010 21:45:04 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: On Thu, Sep 9, 2010 at 8:24 PM, Jakson A. Aquino wrote: > On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP > wrote: >> Hi! >> >> Example for send ^V ?(with PyWin32): >> >> ?import time,win32api,win32con >> ?win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) >> ?win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) >> ?time.sleep(0.05) >> ?win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) >> ?win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) > > Thank you very much! Your code solved my problem. I added some lines > to set the focus into R before the ^V and then back to Vim: Unfortunately, I was wrong. Your code do send the ^v as expected, but I have problem with the selection of the Windows which will receive the ^v. The code above was OK in a Windows XP running inside VirtualBox, but when tested in a real machine, it proved to be highly inconsistent. Sometimes the ^v gets pasted into R, but more frequently it is pasted into Vim itself or nowhere. Below is the complete code that I'm using. It's a vim script. The python code is delimited by "python << EOL" and "EOL": function! SendToRPy(aString) python << EOL import time import win32api import win32con import win32com.client import win32clipboard import vim aString = vim.eval("a:aString") win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(aString) win32clipboard.CloseClipboard() shell = win32com.client.Dispatch("WScript.Shell") ok = shell.AppActivate("R Console") if ok: win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) time.sleep(0.05) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) shell.AppActivate("Vim") else: vim.command("call RWarningMsg('Is R running?')") time.sleep(1) EOL endfunction When R isn't running, the script correctly shows the warning message "Is R running?". Does anyone know what should I do to correctly use the AppActivate function or is there a better approach to this problem? Thanks! Jakson Aquino From python.list at tim.thechases.com Fri Sep 10 21:01:25 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 10 Sep 2010 20:01:25 -0500 Subject: 3D cube navigation In-Reply-To: <4c8acb69$0$11111$c3e8da3@news.astraweb.com> References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> <4c8acb69$0$11111$c3e8da3@news.astraweb.com> Message-ID: <4C8AD4E5.8050801@tim.thechases.com> On 09/10/10 19:20, Steven D'Aprano wrote: > On Sat, 11 Sep 2010 01:09:00 +0200, Krister Svanlund wrote: >> On Fri, Sep 10, 2010 at 9:10 PM, sahilsk wrote: >>> hi, i need to make a 3d cube as a navigation menu.. each face having >>> separate button .. or effect. >> >> In what environment, what toolkit, for what purpose? > > What do you mean, "what environment"? Surely there's only one? The > Original Poster obviously wants a 3D navigation cube for ksh under > FreeBSD. Drat...all my work on a 3d navigation-cube working under ProDos on the Apple ][e for naught...what am I gonna do with all these 360k 5.25" floppies now?! -tkc From ben+python at benfinney.id.au Fri Sep 10 21:17:16 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 11 Sep 2010 11:17:16 +1000 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: <87vd6d84f7.fsf@benfinney.id.au> Ben Finney writes: > Raymond Hettinger writes: > > > It doesn't seem to be common knowledge when and how a[x] gets > > translated to a[x+len(x)]. So, here's a short info post on how > > Python supports negative indices for sequences. > > Thanks for this. Could you post your messages using a channel that > doesn't arbitrarily split your paragraphs into long-short-long-short > lines? It makes paragraphs burdensome to read, and I skipped most of > the message because of that. For those who think the problem may be with the recipient's software, I see the same annoying line-wrapping problems in the archived message . There's been enough sidetracking of Raymond's thread, though, so that factual contribution will hopefully be my last in this thread on this issue. -- \ ?Choose mnemonic identifiers. If you can't remember what | `\ mnemonic means, you've got a problem.? ?Larry Wall | _o__) | Ben Finney From python at mrabarnett.plus.com Fri Sep 10 21:38:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Sep 2010 02:38:05 +0100 Subject: SendKeys and Python 2.7 In-Reply-To: References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: <4C8ADD7D.4010801@mrabarnett.plus.com> On 11/09/2010 01:45, Jakson A. Aquino wrote: > On Thu, Sep 9, 2010 at 8:24 PM, Jakson A. Aquino wrote: >> On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP >> wrote: >>> Hi! >>> >>> Example for send ^V (with PyWin32): >>> >>> import time,win32api,win32con >>> win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) >>> win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) >>> time.sleep(0.05) >>> win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) >>> win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) >> >> Thank you very much! Your code solved my problem. I added some lines >> to set the focus into R before the ^V and then back to Vim: > > Unfortunately, I was wrong. Your code do send the ^v as expected, but > I have problem with the selection of the Windows which will receive > the ^v. The code above was OK in a Windows XP running inside > VirtualBox, but when tested in a real machine, it proved to be highly > inconsistent. Sometimes the ^v gets pasted into R, but more frequently > it is pasted into Vim itself or nowhere. Below is the complete code > that I'm using. It's a vim script. The python code is delimited by > "python<< EOL" and "EOL": > > function! SendToRPy(aString) > python<< EOL > import time > import win32api > import win32con > import win32com.client > import win32clipboard > import vim > > aString = vim.eval("a:aString") > win32clipboard.OpenClipboard() > win32clipboard.EmptyClipboard() > win32clipboard.SetClipboardText(aString) > win32clipboard.CloseClipboard() > shell = win32com.client.Dispatch("WScript.Shell") > ok = shell.AppActivate("R Console") > if ok: > win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) > win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) > time.sleep(0.05) > win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | > win32con.KEYEVENTF_KEYUP, 0) > win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) > shell.AppActivate("Vim") > else: > vim.command("call RWarningMsg('Is R running?')") > time.sleep(1) > EOL > endfunction > > When R isn't running, the script correctly shows the warning message > "Is R running?". Does anyone know what should I do to correctly use > the AppActivate function or is there a better approach to this > problem? > I'd add some more small sleeps to give Windows/R time to act, IYSWIM. I learned that from experience. :-) From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 22:00:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 02:00:14 GMT Subject: Refactoring similar subclasses Message-ID: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> I have some code that currently takes four different classes, A, B, C and D, and subclasses each of them in the same way: class MyA(A): def method(self, x): result = super(MyA, self).method(x) if result == "spam": return "spam spam spam" return result # many more methods overloaded class MyB(B): def method(self, x): result = super(MyB, self).method(x) if result == "spam": return "spam spam spam" return result # many more methods overloaded and so on, for MyC and MyD. There's a lot of duplicated code in there. What techniques do you suggest for reducing the code duplication? I thought about some variation of: names = "MyA MyB MyC MyD".split() bases = [A, B, C, D] d = dict-of-overloaded-methods for name, base in zip(names, bases): globals()[name] = type(name, [base], d) but I'm not sure that this is a good approach, or how to inject the right arguments to super in the dict. Any suggestions or guidelines? -- Steven From cosmo_general at yahoo.com Fri Sep 10 23:28:52 2010 From: cosmo_general at yahoo.com (Muddy Coder) Date: Fri, 10 Sep 2010 20:28:52 -0700 (PDT) Subject: Hide DOS console for .pyc file Message-ID: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Hi Folks, For a quick testing purpose, I deliver .pyc files to my customer. I don't want the black DOS console appearing behind my GUI, but I have no idea how to do it. Somebody can help? Thanks! Cosmo From kelvin.you at gmail.com Sat Sep 11 00:38:03 2010 From: kelvin.you at gmail.com (=?UTF-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B5aSp5rav5LiN6KeB5a62?=) Date: Fri, 10 Sep 2010 21:38:03 -0700 (PDT) Subject: default value for __init__ doesn't work Message-ID: Please look at below code snippet: class test(): def __init__(self, a, dic={}): self.a = a self.dic = dic print('__init__ params:',a, dic) def get(self): self.dic[1] = 2 self.dic[4] = 5 def foo(): print('in foo function') bar = test(1) bar.get() if __name__ == '__main__': foo() foo() ----------------------- Result: in foo function __init__ params: 1 {} in foo function __init__ params: 1 {1: 2, 4: 5} But my expect result is : in foo function __init__ params: 1 {} in foo function __init__ params: 1 {} it seems that the default value for dic doesn't work on the second call for the class test. It's wired. Who can give a explaination for this scenario? From stefan_ml at behnel.de Sat Sep 11 01:09:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Sep 2010 07:09:56 +0200 Subject: How to Convert IO Stream to XML Document In-Reply-To: References: Message-ID: jakecjacobson, 10.09.2010 18:20: > response = urllib2.urlopen(request) > pageguts = response.read() > xmldoc = minidom.parse(pageguts) Check the minidom docs, there's a parseString() function that does what it says. Also, don't forget to take a look at xml.etree.ElementTree. Depending on what you want to do with the XML result, it'll likely be easier to use and faster than minidom. The function there is called fromstring(), just in case ;) Stefan From benjamin.kaplan at case.edu Sat Sep 11 01:14:54 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 11 Sep 2010 01:14:54 -0400 Subject: default value for __init__ doesn't work In-Reply-To: References: Message-ID: On Sat, Sep 11, 2010 at 12:38 AM, ??????????????? wrote: > Please look at below code snippet: > class test(): > ? ?def __init__(self, a, dic={}): > ? ? ? ?self.a = a > ? ? ? ?self.dic = dic > ? ? ? ?print('__init__ params:',a, dic) > This is a pretty popular mistake to make. Default arguments aren't evaluated when you call the method. They're created when the method is created (meaning when you first run the file and the class itself is defined), and that's it. Because you do self.dic = dic, this means that every instance of the object will receive the same dict object. Change it for one object, and the change will show up in all of them. The solution to this is to use a sentinel value, like None def __init__(self, a, dic=None) : if dic is None : self.dic = {} else : self.dic = dic If None is a valid value for the parameter, make a sentinel object and use that sentinel = object() def __init__(self, a, dic=sentinel) : if dic is sentinel : #you want to use is here, not == ... From kelvin.you at gmail.com Sat Sep 11 01:55:33 2010 From: kelvin.you at gmail.com (=?UTF-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B5aSp5rav5LiN6KeB5a62?=) Date: Fri, 10 Sep 2010 22:55:33 -0700 (PDT) Subject: default value for __init__ doesn't work References: Message-ID: On Sep 11, 1:14?pm, Benjamin Kaplan wrote: > On Sat, Sep 11, 2010 at 12:38 AM, ??????????????? wrote: > > Please look at below code snippet: > > class test(): > > ? ?def __init__(self, a, dic={}): > > ? ? ? ?self.a = a > > ? ? ? ?self.dic = dic > > ? ? ? ?print('__init__ params:',a, dic) > > This is a pretty popular mistake to make. Default arguments aren't > evaluated when you call the method. They're created when the method is > created (meaning when you first run the file and the class itself is > defined), and that's it. Because you do self.dic = dic, this means > that every instance of the object will receive the same dict object. > Change it for one object, and the change will show up in all of them. > The solution to this is to use a sentinel value, like None > > def __init__(self, a, dic=None) : > ? ? if dic is None : > ? ? ? ? self.dic = {} > ? ? else : > ? ? ? ? self.dic = dic > > If None is a valid value for the parameter, make a sentinel object and use that > > sentinel = object() > def __init__(self, a, dic=sentinel) : > ? ? if dic is sentinel : #you want to use is here, not == > ? ? ? ... Got it. Thanks for point out my mistake. You are very nice. From kelvin.you at gmail.com Sat Sep 11 02:05:04 2010 From: kelvin.you at gmail.com (=?UTF-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B5aSp5rav5LiN6KeB5a62?=) Date: Fri, 10 Sep 2010 23:05:04 -0700 (PDT) Subject: default value for __init__ doesn't work References: Message-ID: <1b0dfe29-cdd2-48b1-9dae-3b29e7da4c3a@g21g2000prn.googlegroups.com> On Sep 11, 1:55?pm, ??????????????? wrote: > On Sep 11, 1:14?pm, Benjamin Kaplan wrote: > > > > > On Sat, Sep 11, 2010 at 12:38 AM, ??????????????? wrote: > > > Please look at below code snippet: > > > class test(): > > > ? ?def __init__(self, a, dic={}): > > > ? ? ? ?self.a = a > > > ? ? ? ?self.dic = dic > > > ? ? ? ?print('__init__ params:',a, dic) > > > This is a pretty popular mistake to make. Default arguments aren't > > evaluated when you call the method. They're created when the method is > > created (meaning when you first run the file and the class itself is > > defined), and that's it. Because you do self.dic = dic, this means > > that every instance of the object will receive the same dict object. > > Change it for one object, and the change will show up in all of them. > > The solution to this is to use a sentinel value, like None > > > def __init__(self, a, dic=None) : > > ? ? if dic is None : > > ? ? ? ? self.dic = {} > > ? ? else : > > ? ? ? ? self.dic = dic > > > If None is a valid value for the parameter, make a sentinel object and use that > > > sentinel = object() > > def __init__(self, a, dic=sentinel) : > > ? ? if dic is sentinel : #you want to use is here, not == > > ? ? ? ... > > Got it. Thanks for point out my mistake. You are very nice. I remember the same issue was occurred in my C++ program. There I have a function with a parameter referenced a default object . May be C++ also constructs the the default arguments before the function is called. Thank you again to help me so much! From jearl at notengoamigos.org Sat Sep 11 02:53:34 2010 From: jearl at notengoamigos.org (Jason Earl) Date: Sat, 11 Sep 2010 00:53:34 -0600 Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: <87mxrodb4h.fsf@notengoamigos.org> On Fri, Sep 10 2010, Muddy Coder wrote: > Hi Folks, > > For a quick testing purpose, I deliver .pyc files to my customer. I > don't want the black DOS console appearing behind my GUI, but I have > no idea how to do it. Somebody can help? Thanks! > > > Cosmo I don't really use Windows any more, so I might be off the mark, but I think that you need to look into using pythonw.exe instead of python.exe. Solving your problem might be as easy as changing the name of your file from foo.py to foo.pyw. Jason From __peter__ at web.de Sat Sep 11 02:53:38 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 11 Sep 2010 08:53:38 +0200 Subject: Refactoring similar subclasses References: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I have some code that currently takes four different classes, A, B, C and > D, and subclasses each of them in the same way: > > class MyA(A): > def method(self, x): > result = super(MyA, self).method(x) > if result == "spam": > return "spam spam spam" > return result > # many more methods overloaded > > > class MyB(B): > def method(self, x): > result = super(MyB, self).method(x) > if result == "spam": > return "spam spam spam" > return result > # many more methods overloaded > > > and so on, for MyC and MyD. There's a lot of duplicated code in there. > What techniques do you suggest for reducing the code duplication? I > thought about some variation of: > > names = "MyA MyB MyC MyD".split() > bases = [A, B, C, D] > d = dict-of-overloaded-methods > for name, base in zip(names, bases): > globals()[name] = type(name, [base], d) > > > but I'm not sure that this is a good approach, or how to inject the right > arguments to super in the dict. > > Any suggestions or guidelines? You could use a mixin: class Mixin(object): def method(self, x): result = super(Mixin, self).method(x) if result == "spam": return "spam spam spam" return result # ... for name, base in zip(names, bases): globals()[name] = type(name, (Mixin, base), {}) Peter From ldo at geek-central.gen.new_zealand Sat Sep 11 03:22:58 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 19:22:58 +1200 Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: In message <3a2d194c-9b34-4b84-8680-28bdfb53b975 at y3g2000vbm.googlegroups.com>, Muddy Coder wrote: > For a quick testing purpose, I deliver .pyc files to my customer. I > don't want the black DOS console appearing behind my GUI, but I have > no idea how to do it. Somebody can help? Thanks! Don?t run it on Windows. From ldo at geek-central.gen.new_zealand Sat Sep 11 03:24:04 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 19:24:04 +1200 Subject: SendKeys and Python 2.7 References: Message-ID: In message , Jakson A. Aquino wrote: > On Fri, Sep 10, 2010 at 7:19 PM, Lawrence D'Oliveiro > wrote: > >> In message , Jakson >> A. Aquino wrote: >> >>> On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro >>> wrote: >> >>>> In message , >>>> Jakson A. Aquino wrote: >>>> >>>>> I would like to send code from Vim [1] to R [2] on Microsoft Windows. >>>> >>>> Why such a roundabout way? Why not just run R in a subprocess and feed >>>> it a script to run? >>> >>> Emacs with ESS runs R in a subprocess (at least I think it does). Vim >>> can't do that. >> >> Why not? > > I don't know how to embed R into Vim ... I wasn?t saying ?embed?, I was saying ?run R in a subprocess?. From ldo at geek-central.gen.new_zealand Sat Sep 11 03:25:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 19:25:05 +1200 Subject: SendKeys and Python 2.7 References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: In message , Jakson A. Aquino wrote: > Your code do send the ^v as expected, but I have problem with the > selection of the Windows which will receive the ^v. The code above was OK > in a Windows XP running inside VirtualBox, but when tested in a real > machine, it proved to be highly inconsistent. Sometimes the ^v gets pasted > into R, but more frequently it is pasted into Vim itself or nowhere. No big surprise your roundabout GUI-fiddling approach is flaky. From steve at REMOVE-THIS-cybersource.com.au Sat Sep 11 03:58:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 07:58:08 GMT Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: <4c8b3690$0$11111$c3e8da3@news.astraweb.com> On Fri, 10 Sep 2010 20:28:52 -0700, Muddy Coder wrote: > Hi Folks, > > For a quick testing purpose, I deliver .pyc files to my customer. I > don't want the black DOS console appearing behind my GUI, but I have no > idea how to do it. Somebody can help? Thanks! Google is your friend. Googling for "Python dos window" brings up this as the third hit: http://www.velocityreviews.com/forums/t344026-how-to-run-python-in- windows-w-o-popping-a-dos-box.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Sep 11 04:03:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 08:03:56 GMT Subject: Refactoring similar subclasses References: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> Message-ID: <4c8b37ec$0$11111$c3e8da3@news.astraweb.com> On Sat, 11 Sep 2010 08:53:38 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> I have some code that currently takes four different classes, A, B, C >> and D, and subclasses each of them in the same way: [...] >> Any suggestions or guidelines? > > You could use a mixin: Nice! I'll give it a try. I knew that sooner or later I'd find a reason for mixins :) -- Steven From davea at ieee.org Sat Sep 11 05:37:06 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 11 Sep 2010 05:37:06 -0400 Subject: Hide DOS console for .pyc file In-Reply-To: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: <4C8B4DC2.3000007@ieee.org> On 2:59 PM, Muddy Coder wrote: > Hi Folks, > > For a quick testing purpose, I deliver .pyc files to my customer. I > don't want the black DOS console appearing behind my GUI, but I have > no idea how to do it. Somebody can help? Thanks! > > > Cosmo > In Windows, the executable file statically determines whether a console is created. There are two executables shipped with Python, python.exe and pythonw.exe. You want to use the latter. The real question is how to cause Windows to run that rather than python.exe. Answer depends on how your use is launching his program. If he's starting from a shortcut, change the name of the executable on the shortcut. If he's starting by double-clicking on the script name, change the extension of the script from .py to .pyw You mention that you're shipping only .pyc files. If that's the case, add one more, a .pyw that imports your main script. Of course, that may mean changing that script a little so it works as a module. DaveA From __peter__ at web.de Sat Sep 11 05:44:32 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 11 Sep 2010 11:44:32 +0200 Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > In message > <3a2d194c-9b34-4b84-8680-28bdfb53b975 at y3g2000vbm.googlegroups.com>, Muddy > Coder wrote: > >> For a quick testing purpose, I deliver .pyc files to my customer. I >> don't want the black DOS console appearing behind my GUI, but I have >> no idea how to do it. Somebody can help? Thanks! > > Don?t run it on Windows. If you switch the OS for every minor problem you'll run out of operating systems pretty soon... From jaksonaquino at gmail.com Sat Sep 11 05:46:00 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Sat, 11 Sep 2010 06:46:00 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: On Sat, Sep 11, 2010 at 4:25 AM, Lawrence D'Oliveiro wrote: > In message , Jakson A. > Aquino wrote: > >> Your code do send the ^v as expected, but I have problem with the >> selection of the Windows which will receive the ^v. The code above was OK >> in a Windows XP running inside VirtualBox, but when tested in a real >> machine, it proved to be highly inconsistent. Sometimes the ^v gets pasted >> into R, but more frequently it is pasted into Vim itself or nowhere. > > No big surprise your roundabout GUI-fiddling approach is flaky. Thanks for your comment, but could you please suggest a feasible and non flaky approach? From jaksonaquino at gmail.com Sat Sep 11 05:55:07 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Sat, 11 Sep 2010 06:55:07 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: <4C8ADD7D.4010801@mrabarnett.plus.com> References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> <4C8ADD7D.4010801@mrabarnett.plus.com> Message-ID: On Fri, Sep 10, 2010 at 10:38 PM, MRAB wrote: > I'd add some more small sleeps to give Windows/R time to act, IYSWIM. I > learned that from experience. :-) I've tried adding sleeps, small and large, but they didn't make much of a difference. Anyway, different machines could require different amounts of sleep and, thus, this workaround may not be generalizable enough since the plugin would be used by many people on different systems. Thanks, Jakson From ldo at geek-central.gen.new_zealand Sat Sep 11 06:31:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 22:31:34 +1200 Subject: SendKeys and Python 2.7 References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: In message , Jakson A. Aquino wrote: > On Sat, Sep 11, 2010 at 4:25 AM, Lawrence D'Oliveiro > wrote: > >> In message , Jakson >> A. Aquino wrote: >> >>> Your code do send the ^v as expected, but I have problem with the >>> selection of the Windows which will receive the ^v. The code above was >>> OK in a Windows XP running inside VirtualBox, but when tested in a real >>> machine, it proved to be highly inconsistent. Sometimes the ^v gets >>> pasted into R, but more frequently it is pasted into Vim itself or >>> nowhere. >> >> No big surprise your roundabout GUI-fiddling approach is flaky. > > Thanks for your comment, but could you please suggest a feasible and > non flaky approach? I already did. From ldo at geek-central.gen.new_zealand Sat Sep 11 06:32:27 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 22:32:27 +1200 Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: In message , Peter Otten wrote: > Lawrence D'Oliveiro wrote: > >> In message >> <3a2d194c-9b34-4b84-8680-28bdfb53b975 at y3g2000vbm.googlegroups.com>, Muddy >> Coder wrote: >> >>> For a quick testing purpose, I deliver .pyc files to my customer. I >>> don't want the black DOS console appearing behind my GUI, but I have >>> no idea how to do it. Somebody can help? Thanks! >> >> Don?t run it on Windows. > > If you switch the OS for every minor problem you'll run out of operating > systems pretty soon... Not if you choose a suitably flexible and portable one to begin with. From rafalgulinski at gmail.com Sat Sep 11 06:59:20 2010 From: rafalgulinski at gmail.com (rav) Date: Sat, 11 Sep 2010 03:59:20 -0700 (PDT) Subject: 3D cube navigation References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> Message-ID: <24439775-fae6-415b-8fd3-54a524168a62@y3g2000vbm.googlegroups.com> On Sep 10, 9:10?pm, sahilsk wrote: > hi, i need to make a 3d cube as a navigation menu.. each face having > separate ?button .. or effect. > any idea, ?how can i make one such 3D figures with functionality of > mouse events? One of options is AS3 and Papervision3D - free Flex SDK and many tutorials are available in the web. From sschwarzer at sschwarzer.net Sat Sep 11 09:16:19 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 11 Sep 2010 15:16:19 +0200 Subject: Design: Module interface vs. library interface Message-ID: <4C8B8123.80704@sschwarzer.net> Hello, I maintain ftputil [1], an FTP client library. Users of the library may use it like this: | import ftputil | | with ftputil.FTPHost(server, userid, password) as ftp_host: | # for example, make a remote file and read its content | with ftp_host.open("remote_name", "rb") as remote_fobj: | data = remote_fobj.read() Even though "ftp files" are defined in module `ftp_file` [2] via class `FTPFile`, users of the ftputil library should never use `FTPFile` directly; it's up to `FTPHost.open` to generate these file objects. Now, from the "point of view" of the _module_ `ftp_file`, I'd use | # ftp_file.py | | # used outside this module | __all__ = ['FTPFile'] | | class FTPFile(object): | ... | # ftputil.py | | import ftp_file | | class FTPHost(object): | ... | def open(name, mode): | ... | return ftp_file.FTPFile(...) On the other hand, from the point of view of the _library_ ftputil, `FTPFile` isn't part of the official API, so I may as well write | # ftp_file.py | | # be explicit, no user-public interface | __all__ = [] | | class FTPFile(object): | ... Which approach would you prefer and why? Or some other approach? Would you use a different approach if the library-internal class was named `_FTPFile` instead of `FTPFile`? [1] http://ftputil.sschwarzer.net [2] http://ftputil.sschwarzer.net/trac/browser/ftp_file.py Stefan From bearophileHUGS at lycos.com Sat Sep 11 10:33:29 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Sat, 11 Sep 2010 07:33:29 -0700 (PDT) Subject: Static typing, Python, D, DbC Message-ID: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> I write some Python code almost every day, but lately I am using a lot the D language too. After using D for about three years I now know some of it, but when I need to write short (< about 1000 lines) *correct* programs, Python is still the more productive for me. Static typing, and the usage of transitive const of D are a strange thing. It seems obvious that they lead to safer code, but on the other hand experimentally I have seen that my short Python programs are less buggy than equivalent D ones. Static typing looks safer, but D offers many low level features, and generally it contains many more traps or ways to shoot your own foot, that they more than compensate for the "lack of safety" coming from Python dynamic typing, even when you don't use those low level features. Maybe for large (> about 100_000 lines) programs D may come out to be less bug-prone than Python (thanks to the better data hiding and static typing), but I am not sure of this at all... Static typing also has a significant costs. When you write D2 code often something doesn't work because of some transitive const or immutable (or just because of the large number of bugs that need to be fixed still in the D compiler). So here you pay some cost as debugging time (or time to avoid those problems). And there is a mental cost too, because you need to keep part of your attention on those const- related things instead of your algorithms, etc. ---------------- Lately while I program with Python one of the D features that I most miss is a built-in Design By Contract (see PEP 316), because it avoids (or helps me to quickly find and fix) many bugs. In my opinion DbC is also very good used with doctests. You may implement a poor's man DbC in Python like this: class Foo: def _invariant(self): assert ... assert ... return True def bar(self, ...): assert self._invariant() ... res = ... assert self._invariant() return res But this missed several useful features of DbC. >From the D standard library, I have also appreciated a lazy string split (something like a str.xplit()). In some situations it reduces memory waste and increases code performance. ---------------- I have installed this, on a Windows Vista OS: http://www.python.org/ftp/python/2.7/python-2.7.msi But I have had two problems, the 'random' module was empty, and it didn't import the new division from the future, so I've had to remove it and reinstall 2.6.6. Is this just a problem of mine? Bye, bearophile From aahz at pythoncraft.com Sat Sep 11 10:42:11 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Sep 2010 07:42:11 -0700 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> <87vd6d84f7.fsf@benfinney.id.au> Message-ID: In article <87vd6d84f7.fsf at benfinney.id.au>, Ben Finney wrote: >Ben Finney writes: >> Raymond Hettinger writes: >>> >>> It doesn't seem to be common knowledge when and how a[x] gets >>> translated to a[x+len(x)]. So, here's a short info post on how >>> Python supports negative indices for sequences. >> >> Thanks for this. Could you post your messages using a channel that >> doesn't arbitrarily split your paragraphs into long-short-long-short >> lines? It makes paragraphs burdensome to read, and I skipped most of >> the message because of that. > >For those who think the problem may be with the recipient's software, I >see the same annoying line-wrapping problems in the archived message >. Still looks like *your* problem to me; except for exactly one paragraph, I don't see comb-style formatting in Lynx at that URL. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From zak.mc.kraken at libero.it Sat Sep 11 11:34:35 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sat, 11 Sep 2010 17:34:35 +0200 Subject: bug in python documentation? Message-ID: from http://docs.python.org/library/unittest.html -->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8-- Here is a short script to test three functions from the random module: import random import unittest class TestSequenceFunctions(unittest.TestCase): def setUp(self): self.seq = range(10) def test_shuffle(self): # make sure the shuffled sequence does not lose any elements random.shuffle(self.seq) self.seq.sort() self.assertEqual(self.seq, range(10)) # should raise an exception for an immutable sequence self.assertRaises(TypeError, random.shuffle, (1,2,3)) def test_choice(self): element = random.choice(self.seq) self.assertTrue(element in self.seq) def test_sample(self): with self.assertRaises(ValueError): random.sample(self.seq, 20) for element in random.sample(self.seq, 5): self.assertTrue(element in self.seq) if __name__ == '__main__': unittest.main() --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- but test_sample() it's a strange method: what's that "with self.assertRaises(ValueErrorr)"? infact, running the script I have $ python test_unittest.py .E. ====================================================================== ERROR: test_sample (__main__.TestSequenceFunctions) ---------------------------------------------------------------------- Traceback (most recent call last): File "./test_data_manip.py", line 23, in test_sample with self.assertRaises(ValueError): TypeError: failUnlessRaises() takes at least 3 arguments (2 given) ---------------------------------------------------------------------- Ran 3 tests in 0.001s FAILED (errors=1) $ -- By ZeD From benjamin.kaplan at case.edu Sat Sep 11 11:44:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 11 Sep 2010 11:44:46 -0400 Subject: bug in python documentation? In-Reply-To: References: Message-ID: On Sat, Sep 11, 2010 at 11:34 AM, Vito 'ZeD' De Tullio wrote: > from http://docs.python.org/library/unittest.html > > -->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8-- > > Here is a short script to test three functions from the random module: > > import random > import unittest > > class TestSequenceFunctions(unittest.TestCase): > > ? ?def setUp(self): > ? ? ? ?self.seq = range(10) > > ? ?def test_shuffle(self): > ? ? ? ?# make sure the shuffled sequence does not lose any elements > ? ? ? ?random.shuffle(self.seq) > ? ? ? ?self.seq.sort() > ? ? ? ?self.assertEqual(self.seq, range(10)) > > ? ? ? ?# should raise an exception for an immutable sequence > ? ? ? ?self.assertRaises(TypeError, random.shuffle, (1,2,3)) > > ? ?def test_choice(self): > ? ? ? ?element = random.choice(self.seq) > ? ? ? ?self.assertTrue(element in self.seq) > > ? ?def test_sample(self): > ? ? ? ?with self.assertRaises(ValueError): > ? ? ? ? ? ?random.sample(self.seq, 20) > ? ? ? ?for element in random.sample(self.seq, 5): > ? ? ? ? ? ?self.assertTrue(element in self.seq) > > if __name__ == '__main__': > ? ?unittest.main() > > --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- > > > but test_sample() it's a strange method: what's that "with > self.assertRaises(ValueErrorr)"? > > infact, running the script I have > > $ python test_unittest.py > .E. > ====================================================================== > ERROR: test_sample (__main__.TestSequenceFunctions) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "./test_data_manip.py", line 23, in test_sample > ? ?with self.assertRaises(ValueError): > TypeError: failUnlessRaises() takes at least 3 arguments (2 given) > > ---------------------------------------------------------------------- > Ran 3 tests in 0.001s > > FAILED (errors=1) > $ > > > -- > By ZeD You're looking at the 2.7 documentation. Are you using 2.7? From thomas at jollybox.de Sat Sep 11 11:47:32 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 11 Sep 2010 17:47:32 +0200 Subject: bug in python documentation? In-Reply-To: References: Message-ID: <201009111747.32867.thomas@jollybox.de> On Saturday 11 September 2010, it occurred to Vito 'ZeD' De Tullio to exclaim: > from http://docs.python.org/library/unittest.html > > $ python test_unittest.py > .E. > ====================================================================== > ERROR: test_sample (__main__.TestSequenceFunctions) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "./test_data_manip.py", line 23, in test_sample > with self.assertRaises(ValueError): > TypeError: failUnlessRaises() takes at least 3 arguments (2 given) > > ---------------------------------------------------------------------- > Ran 3 tests in 0.001s > > FAILED (errors=1) > $ Which Python version are you using? To quote the docs you linked: http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises """ Changed in version 2.7: Added the ability to use assertRaises() as a context manager. """ Are you using Python 2.7 (or 3.x)? -------------- next part -------------- An HTML attachment was scrubbed... URL: From zak.mc.kraken at libero.it Sat Sep 11 12:21:49 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sat, 11 Sep 2010 18:21:49 +0200 Subject: bug in python documentation? References: Message-ID: Benjamin Kaplan wrote: > You're looking at the 2.7 documentation. Are you using 2.7? whoops, no: 2.6.5 :\ (but the "new in python X.Y.Z" disclaimer does not apply to the example snippets?) -- By ZeD From thomas at jollybox.de Sat Sep 11 12:28:07 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 11 Sep 2010 18:28:07 +0200 Subject: [Python-ideas] with statement syntax forces ugly line breaks? In-Reply-To: References: <20100908175029.6617ae3b@dino> Message-ID: <201009111828.08299.thomas@jollybox.de> On Saturday 11 September 2010, it occurred to Lawrence D'Oliveiro to exclaim: > In message , MRAB > > wrote: > > On 08/09/2010 19:07, Georg Brandl wrote: > >> Thus spake the Lord: Thou shalt indent with four spaces. No more, no > >> less. Four shall be the number of spaces thou shalt indent, and the > >> number of thy indenting shall be four. Eight shalt thou not indent, > >> nor either indent thou two, excepting that thou then proceed to four. > >> Tabs are right out. > > > > FYI, that should be "thine indenting". > > > > "My/thy" before a consonant, "mine/thine" before a vowel. Compare with > > "a/an", which we still do. > > The funny thing is, that?s technically ?Modern English?... ... and it's regularly used in a number of best-selling books. From lie.1296 at gmail.com Sat Sep 11 12:36:28 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 12 Sep 2010 02:36:28 +1000 Subject: Static typing, Python, D, DbC In-Reply-To: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> Message-ID: <4c8bb00f@dnews.tpgi.com.au> On 09/12/10 00:33, Bearophile wrote: > ---------------- > > Lately while I program with Python one of the D features that I most > miss is a built-in Design By Contract (see PEP 316), because it avoids > (or helps me to quickly find and fix) many bugs. In my opinion DbC is > also very good used with doctests. > You may implement a poor's man DbC in Python like this: I would do it like this: from DbC import DbC class Foo(__metaclass__=DbC): def __invariant(self): ... automatically asserted for all methods ... def __precond(self): ... automatically asserted for all methods ... def __postcond(self): ... automatically asserted for all methods ... @precond(attr=value) # asserts self.attr==value @postcond(func) # a function for more complex assertions def bar(self, ...): ... clean, uncluttered code ... and set DbC.uninstall() to uninstall all precond/postcond/invariants at runtime without any additional overhead. These are all definitely possible with metaclasses and decorators. > From the D standard library, I have also appreciated a lazy string > split (something like a str.xplit()). In some situations it reduces > memory waste and increases code performance. Care to open an issue at the tracker? Considering that many Python 3 builtins is now lazy, there might be a chance this is an oversight, or there might be a reason why string.split is not lazy. From fields.emmett at gmail.com Sat Sep 11 12:59:26 2010 From: fields.emmett at gmail.com (fields) Date: Sat, 11 Sep 2010 09:59:26 -0700 (PDT) Subject: triangle python user's group? References: <3c95f09c-1fa7-4c63-9f13-3f2776c2ab41@j18g2000yqd.googlegroups.com> Message-ID: <40e801f1-de0b-40a3-8a82-b2fb43165a00@v23g2000vbi.googlegroups.com> Tim: trizpug.org - fields On Aug 31, 12:38?pm, "Tim Arnold" wrote: > "Albert Hopkins" wrote in message > > news:mailman.219.1283200967.29448.python-list at python.org... > > > On Mon, 2010-08-30 at 12:38 -0700, Tim Arnold wrote: > >> Hi, > >> Is there a python users group in the Research Triangle Park area > >> (North Carolina, USA)? > > > Google "triangle python user's group" > > > thanks for the pointer.... > --Tim From tjreedy at udel.edu Sat Sep 11 13:19:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 11 Sep 2010 13:19:13 -0400 Subject: Hide DOS console for .pyc file In-Reply-To: References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: On 9/11/2010 6:32 AM, Lawrence D'Oliveiro wrote: > In message, Peter Otten wrote: > >> Lawrence D'Oliveiro wrote: >> >>> In message >>> <3a2d194c-9b34-4b84-8680-28bdfb53b975 at y3g2000vbm.googlegroups.com>, Muddy >>> Coder wrote: >>> >>>> For a quick testing purpose, I deliver .pyc files to my customer. I >>>> don't want the black DOS console appearing behind my GUI, but I have >>>> no idea how to do it. Somebody can help? Thanks! Have them run with pythonw.exe instead of python.exe. That is how IDLE does it. -- Terry Jan Reedy From wolfgang.lipp at gmail.com Sat Sep 11 14:15:32 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sat, 11 Sep 2010 11:15:32 -0700 (PDT) Subject: fast kdtree tree implementation for python 3? Message-ID: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> does anyone have a suggestion for a ready-to-go, fast kdtree implementation for python 3.1 and up, for nearest-neighbor searches? i used to use the one from numpy/scipy, but find it a pain to install for python 3. also, i'm trying to wrap the code from http://code.google.com/p/kdtree/ using cython, but i'm still getting errors. i wish stuff like kdtree, levenshtein edit distance and similar things were available in the standard library. From stef.mientki at gmail.com Sat Sep 11 14:42:47 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 11 Sep 2010 20:42:47 +0200 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? Message-ID: <4C8BCDA7.6080202@gmail.com> thanks, Stef Mientki From robert.kern at gmail.com Sat Sep 11 15:11:12 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 11 Sep 2010 14:11:12 -0500 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? In-Reply-To: <4C8BCDA7.6080202@gmail.com> References: <4C8BCDA7.6080202@gmail.com> Message-ID: SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So it's not clear what you mean when you say the database is "windows-1252". Can you be more specific? -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From stefan_ml at behnel.de Sat Sep 11 15:26:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Sep 2010 21:26:22 +0200 Subject: fast kdtree tree implementation for python 3? In-Reply-To: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: _wolf, 11.09.2010 20:15: > does anyone have a suggestion for a ready-to-go, fast kdtree > implementation for python 3.1 and up, for nearest-neighbor searches? i > used to use the one from numpy/scipy, but find it a pain to install > for python 3. The latest release is supposed to work with Py3. > also, i'm trying to wrap the code from http://code.google.com/p/kdtree/ > using cython, but i'm still getting errors. If you subscribe to the cython-users mailing list, you can ask for help there. > i wish stuff like kdtree, levenshtein edit distance and similar things > were available in the standard library. Since you're looking for an implementation, I guess you won't be the one volunteering to maintain such code in the stdlib, would you? Stefan From nawijn at gmail.com Sat Sep 11 15:56:40 2010 From: nawijn at gmail.com (Marco Nawijn) Date: Sat, 11 Sep 2010 12:56:40 -0700 (PDT) Subject: fast kdtree tree implementation for python 3? References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: On 11 sep, 20:15, _wolf wrote: > does anyone have a suggestion for a ready-to-go, fast kdtree > implementation for python 3.1 and up, for nearest-neighbor searches? i > used to use the one from numpy/scipy, but find it a pain to install > for python 3. also, i'm trying to wrap the code fromhttp://code.google.com/p/kdtree/ > using cython, but i'm still getting errors. > > i wish stuff like kdtree, levenshtein edit distance and similar things > were available in the standard library. Do you know about the kdtree implementation in biopython? I don't know if it is already available for Python 3, but for me it worked fine in Python 2.X. Marco From michael.a.powe at gmail.com Sat Sep 11 16:00:22 2010 From: michael.a.powe at gmail.com (naugiedoggie) Date: Sat, 11 Sep 2010 13:00:22 -0700 (PDT) Subject: SOLVED: Re: Trap Authentication Errors in HTTP Request References: Message-ID: On Sep 10, 12:09?pm, naugiedoggie wrote: > Hello, > > I have a script that authenticates to a web service provider to > retrieve data. ?This script provides an authentication header built in > a very basic way like this: The answer is that there is something whacked in the Windoze implementation for urllib2. It turns out that the script works fine when run in a linux console. '401' error is trapped as expected by an exception handler. In Winblows, the builtin handler for authentication is supposed to take a dump after 5 retries, but this seems to not happen. The retries continue until a recursion exception is fired. At this point the script dumps back to the console. An exception handler for Exception will catch this. Thanks. mp From michael.a.powe at gmail.com Sat Sep 11 16:29:19 2010 From: michael.a.powe at gmail.com (naugiedoggie) Date: Sat, 11 Sep 2010 13:29:19 -0700 (PDT) Subject: Bug: urllib2 basic authentication does not trap auth failure in windows? Message-ID: <3b2de754-4e12-44b5-ac91-152d1173cc80@n7g2000vbo.googlegroups.com> Hello, Is this a known issue? I have a script that authenticates to a web service. urllib2 process for authenticating for basic auth is supposed to dump out after 5 retries. Here's a note from the urllib2.py code: def http_error_auth_reqed(self, auth_header, host, req, headers): authreq = headers.get(auth_header, None) if self.retried > 5: # Don't fail endlessly - if we failed once, we'll probably # fail a second time. Hm. Unless the Password Manager is # prompting for the information. Crap. This isn't great # but it's better than the current 'repeat until recursion # depth exceeded' approach raise HTTPError(req.get_full_url(), 401, "digest auth failed", headers, None) This note is from the digest handler but the basic handler is exactly the same in the important respects. What happens in a windows console is that, in fact, the code dumps with the message 'maximum recursion depth reached.' Whereas, in the linux console, the same script exits appropriately with the trapped 401 error that authentication failed. Thanks. mp From news1234 at free.fr Sat Sep 11 16:39:39 2010 From: news1234 at free.fr (News123) Date: Sat, 11 Sep 2010 22:39:39 +0200 Subject: play sound on Ubuntu 10.4. (pulse audio?) Message-ID: <4c8be910$0$21261$426a74cc@news.free.fr> Hi, >From a python script I'd like to play sound on Ubuntu 10.4 I made two attempts: the first one is drectly writing to '/dev/audio', which works, but only if no other application plays audio (like for example amarok) The second attempt was playing audio via ALSA. The application doesn't fail, but I can hear nothing Now I don't know how to continue More details below 1.) write directly to /dev/audio ==================================== def Beep_dev_au(frequency, duration, amplitude=10): sample = 8000 half_period = int(sample/frequency/2) beep = chr(amplitude)*half_period+chr(0)*half_period beep *= int(duration*frequency/1000) audio = file('/dev/audio', 'wb') audio.write(beep) audio.close() the function works well and beeps if no other application is playing audio. When running it while for example amarok is playing audio, it will fail with: IOError: [Errno 16] Device or resource busy: '/dev/audio' 2. Accessing audio via ALSA ============================= import alsaaudio # def Beep_alsa(frequency, duration=1000, amplitude=1): sample = 44100 pcm = alsaaudio.PCM(type=alsaaudio.PCM_PLAYBACK) pcm.setchannels(1) pcm.setrate(sample) pcm.setformat(alsaaudio.PCM_FORMAT_S16_LE) half_period = int(sample/frequency/2) beep = (chr(0)+chr(amplitude))*half_period+(chr(0)*2)*half_period print "L",len(beep) beep *= int(duration*sample/half_period/2000) pcm.setperiodsize(160) for idx in xrange(0,len(beep),320): frm = beep[idx:idx+320] if len(frm) == 320: pcm.write(frm) this function doesn't raise an exception, but hear nothing. I'm a little lost. As far as I understand Ubuntu uses the pulse audio system by default. (That's probably why ALSA is not working) What would be the correct way to play audio on such a system or even better. What would be the way to detect how to play audio on a linux system without knowing ufront whether the system uses pulse, ALSA or whatever? Thanks for your suggestions. N From michael.a.powe at gmail.com Sat Sep 11 17:03:50 2010 From: michael.a.powe at gmail.com (naugiedoggie) Date: Sat, 11 Sep 2010 14:03:50 -0700 (PDT) Subject: How to Convert IO Stream to XML Document References: Message-ID: <16975673-6aad-426c-84da-f782f3457d41@k30g2000vbn.googlegroups.com> On Sep 10, 12:20?pm, jakecjacobson wrote: > I am trying to build a Python script that reads a Sitemap file and > push the URLs to a Google Search Appliance. ?I am able to fetch the > XML document and parse it with regular expressions but I want to move > to using native XML tools to do this. ?The problem I am getting is if > I use urllib.urlopen(url) I can convert the IO Stream to a XML > document but if I use urllib2.urlopen and then read the response, I > get the content but when I use minidom.parse() I get a "IOError: > [Errno 2] No such file or directory:" error Hello, This may not be helpful, but I note that you are doing two different things with your requests, and judging from the documentation, the objects returned by urllib and urllib2 openers do not appear to be the same. I don't know why you are calling urllib.urlopen(url) and urllib2.urlopen(request), but I can tell you that I have used urllib2 opener to retrieve a web services document in XML and then parse it with minidom.parse(). > > THIS WORKS but will have issues if the IO Stream is a compressed file > def GetPageGuts(net, url): > ? ? ? ? pageguts = urllib.urlopen(url) > ? ? ? ? xmldoc = minidom.parse(pageguts) > ? ? ? ? return xmldoc > > # THIS DOESN'T WORK, but I don't understand why > def GetPageGuts(net, url): > ? ? ? ? request=getRequest_obj(net, url) > ? ? ? ? response = urllib2.urlopen(request) > ? ? ? ? response.headers.items() > ? ? ? ? pageguts = response.read() Did you note the documentation says: "One caveat: the read() method, if the size argument is omitted or negative, may not read until the end of the data stream; there is no good way to determine that the entire stream from a socket has been read in the general case." No EOF marker might be the cause of the parsing problem. Thanks. mp From aahz at pythoncraft.com Sat Sep 11 17:03:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Sep 2010 14:03:58 -0700 Subject: palindrome iteration References: <49c856c4-e6f4-4e4e-b1b4-694a50e56080@f6g2000yqa.googlegroups.com> <4c778ab6$0$4778$426a74cc@news.free.fr> Message-ID: In article , Dave Angel wrote: > >def is_palindrom(s): > s = s.lower() > return s == s[::-1] To deal with "real" palindromes such as, "Madam, I'm Adam," you should probably strip all spaces and punctuation: # untested pat = re.compile(r'[a-z]') def is_palindrome(s): letters = pat.findall(s.lower()) return letters == reversed(letters) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From wolfgang.lipp at gmail.com Sat Sep 11 17:33:21 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sat, 11 Sep 2010 14:33:21 -0700 (PDT) Subject: fast kdtree tree implementation for python 3? References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: > Since you're looking for an implementation, I guess you won't be the one > volunteering to maintain such code in the stdlib, would you? this is indeed a problem. i am probably not the right one for this kind of task. however, i do sometimes feel like the standard library carries too much cruft from yesteryear. things like decent image and sound manipulation, fuzzy string comparison, fast asynchronous HTTP serving and requesting are definitely things i believe a 2010 programming language with batteries included should strive to provide. one avenue to realize this goal could be to prioritize the packages in pypi. pypi is basically a very good idea and has made things like finding and installing packages much easier. however, it is also organized like a dump pile. there are centuries old packages there few people ever use. i suggest to add aging (many old packages are good ones, but also often display a crude form of inner organization; conversely, a library not updated for a long time is unlikely to be a good answer to your problem; aging works in both directions), popularity, and community prioritization (where people vote for essential and relevant solutions) to the standard library as well as to pypi; in other words, to unify the two. batteries included is a very good idea, but there are definitely some old and leaky batteries in there. sadly, since the standard library modules are always included in each installation, there are no figures on how much needed they are after all. one would guess that were such figures available, the aifc library would come near the end of a ranked listing. if the community manages, by download figures and voting, to class packages, a much clearer picture could emerge about the importance of packages. one could put python packages into: * Class A all those packages without which python would not run (such as sys and site); into * Class B ('basics'), officially maintained packages; into * Class C ('community'), packages that are deemed important or desirable and which are open for community contributions (to make it likely they get updated soon enough whenever needed); into * Class D ('debut') all packages submitted to pypi and favorably tested, reviewed and found relevant by a certain number of people; into * Class E ('entry') all packages submitted or found elsewhere on the web, but not approved by the community; into * Class F ('failure') all packages that were proposed but never produced code, and all packages known to be not a good ideas to use (see discussion going on at http://pypi.python.org/pypi/python-cjson). Class F can help people to avoid going down the wrong path when choosing software. well this goes far beyond the kdtree question. maybe i'll make it a proposal for a PEP. From usernet at ilthio.net Sat Sep 11 17:42:42 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 11 Sep 2010 21:42:42 +0000 (UTC) Subject: play sound on Ubuntu 10.4. (pulse audio?) References: <4c8be910$0$21261$426a74cc@news.free.fr> Message-ID: On 2010-09-11, News123 wrote: > What would be the way to detect how to play audio on a linux system > without knowing ufront whether the system uses pulse, ALSA or whatever? I would suggest libao: http://www.xiph.org/ao/ and it's python bindings: http://nixbit.com/cat/multimedia/audio/libao/ From stef.mientki at gmail.com Sat Sep 11 17:45:15 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 11 Sep 2010 23:45:15 +0200 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? In-Reply-To: References: <4C8BCDA7.6080202@gmail.com> Message-ID: <4C8BF86B.6060902@gmail.com> On 11-09-2010 21:11, Robert Kern wrote: > SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So it's not clear what > you mean when you say the database is "windows-1252". Can you be more specific? I doubt that, but I'm not sure ... For some databases written by other programs and written with Python, with cursor = self.conn.cursor () self.conn.text_factory = str Can only be read back with with text_factory = str then the resulting string columns contains normal strings with windows 1252 coding, like character 0xC3 Reading these databases with text_factory = unicode, results in exceptions, when such a string with 0xC3 is encountered. As I want to switch completely to unicode, to prevent these kind of problems in the future. cheers, Stef From nhodgson at bigpond.net.au Sat Sep 11 17:58:29 2010 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sun, 12 Sep 2010 07:58:29 +1000 Subject: How Python works: What do you know about support for negative indices? In-Reply-To: <87vd6d84f7.fsf@benfinney.id.au> References: <874ody9w3v.fsf@benfinney.id.au> <87vd6d84f7.fsf@benfinney.id.au> Message-ID: <9YSio.6159$Yv.899@viwinnwfe01.internal.bigpond.com> Ben Finney: > For those who think the problem may be with the recipient's software, I > see the same annoying line-wrapping problems in the archived message > . That looks well-formatted to me and just the same as I see in a news reader. There appear to be deliberate wraps at sentence end or automatic wraps to fit <80 columns. Which lines are wrong and why are they wrong? Neil From robert.kern at gmail.com Sat Sep 11 18:07:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 11 Sep 2010 17:07:52 -0500 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? In-Reply-To: <4C8BF86B.6060902@gmail.com> References: <4C8BCDA7.6080202@gmail.com> <4C8BF86B.6060902@gmail.com> Message-ID: On 9/11/10 4:45 PM, Stef Mientki wrote: > On 11-09-2010 21:11, Robert Kern wrote: >> SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So it's not clear what >> you mean when you say the database is "windows-1252". Can you be more specific? > I doubt that, but I'm not sure ... From the documentation, it looks like SQLite does not attempt to validate the input as UTF-8 encoded, so it is possible that someone pushed in raw bytes. See "Support for UTF-8 and UTF-16" in the following page: http://www.sqlite.org/version3.html > For some databases written by other programs and > written with Python, with > cursor = self.conn.cursor () > self.conn.text_factory = str > > Can only be read back with with text_factory = str > then the resulting string columns contains normal strings with windows 1252 coding, like character 0xC3 You can probably use self.conn.text_factory = lambda x: x.decode('windows-1252') to read the data, though I've never tried to use that API myself. You will need to write a program yourself that opens one connection to your existing database for reading and another connection to another database (using the defaults) for writing. Then iterate over your tables and copy data from one database to the other. You may also be able to simply dump the database to a text file using "sqlite3 bad-database.db .dump > bad-sql.sql", read the text file into Python as a string, decode it from windows-1252 to unicode and then encode it as utf-8 and write it back out. Then use "sqlite3 good-database.db .read good-sql.sql" to create the new database. I've never tried such a thing, so it may not work. -- 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 cs at zip.com.au Sat Sep 11 18:26:40 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 12 Sep 2010 08:26:40 +1000 Subject: How Python works: What do you know about support for negative indices? In-Reply-To: References: Message-ID: <20100911222640.GA28076@cskk.homeip.net> On 10Sep2010 12:46, Daniel Fetchinson wrote: | > Raymond Hettinger writes: | >> It doesn't seem to be common knowledge when and how a[x] gets | >> translated to a[x+len(x)]. So, here's a short info post on how Python | >> supports negative indices for sequences. | > | > Thanks for this. Could you post your messages using a channel that | > doesn't arbitrarily split your paragraphs into long-short-long-short | > lines? | | It came across fine for me as well (gmail with basic html interface). | | > It makes paragraphs burdensome to read, and I skipped most of the | > message because of that. | | You might want to switch to a client where you do not have this problem. It was fine for me too, using mutt (fixed width text interface, 80 column terminal). -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A monkey has the right to copy what he sees other monkeys doing. Shouldn't humans have equivalent rights? - Alien Being From wolfgang.lipp at gmail.com Sat Sep 11 18:38:16 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sat, 11 Sep 2010 15:38:16 -0700 (PDT) Subject: fast kdtree tree implementation for python 3? References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: <746c2c3c-ba01-418c-b43c-c22c0c279d6f@c32g2000vbq.googlegroups.com> > Do you know about the kdtree implementation in biopython? I don't know > if it is already available for Python 3, but for me it worked fine in > Python 2.X. i heard they use a brute-force approach and it's slow. that's just rumors alright. also, judging from the classes list on http://www.biopython.org/DIST/docs/api/module-tree.html, you will see you can probably tune in to the latest radio moscow news using it. way too much for my needs, i just want to find the nearest neighbor on a 2D-plane. but thanks for the suggestion. From nagle at animats.com Sat Sep 11 18:53:38 2010 From: nagle at animats.com (John Nagle) Date: Sat, 11 Sep 2010 15:53:38 -0700 Subject: Static typing, Python, D, DbC In-Reply-To: <4c8bb00f@dnews.tpgi.com.au> References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> Message-ID: <4c8c086c$0$1597$742ec2ed@news.sonic.net> On 9/11/2010 9:36 AM, Lie Ryan wrote: > On 09/12/10 00:33, Bearophile wrote: > >> ---------------- >> >> Lately while I program with Python one of the D features that I most >> miss is a built-in Design By Contract (see PEP 316), because it avoids >> (or helps me to quickly find and fix) many bugs. In my opinion DbC is >> also very good used with doctests. > >> You may implement a poor's man DbC in Python like this: > > I would do it like this: Design by contract really isn't a good fit to Python. I've done proof of correctness work, and there are suitable languages for it. It needs a language where global static analysis is possible, so you can reliably tell what can changes what. John Nagle From patrick.charron.pc at gmail.com Sat Sep 11 19:58:19 2010 From: patrick.charron.pc at gmail.com (Patrick Charron) Date: Sat, 11 Sep 2010 23:58:19 +0000 (UTC) Subject: audio time-stretching? References: Message-ID: On Tue, 07 Sep 2010 15:33:55 +0000, kj wrote: > Does anyone know of a Python module for *moderate* "time-stretching"[1] > an MP3 (or AIFF) file? > > FWIW, the audio I want to time-stretch is human speech. If you are running your script on Linux you may use gstreamer(pyGST). With gstreamer you can use filter to modify audio and video file or stream. P.S. Maybe gstreamer can work on windows to From ldo at geek-central.gen.new_zealand Sat Sep 11 20:08:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 12 Sep 2010 12:08:26 +1200 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: In message , Robert Kern wrote: > On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote: > >> In message, Ian >> Kelly wrote: >> >>> And returning None on failure is dangerous, because if the programmer >>> does not take care to handle that case, the program may attempt to >>> regard it as actual data. >> >> But None *is* actual data. > > And that is exactly the reason why the Samurai Principle says to not > return None when the function fails to do what it intended to do. How can the function ?fail? when it returns what it is specified to return? From ldo at geek-central.gen.new_zealand Sat Sep 11 20:08:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 12 Sep 2010 12:08:26 +1200 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: In message , Robert Kern wrote: > On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote: > >> In message, Ian >> Kelly wrote: >> >>> And returning None on failure is dangerous, because if the programmer >>> does not take care to handle that case, the program may attempt to >>> regard it as actual data. >> >> But None *is* actual data. > > And that is exactly the reason why the Samurai Principle says to not > return None when the function fails to do what it intended to do. How can the function ?fail? when it returns what it is specified to return? From ben+python at benfinney.id.au Sat Sep 11 20:57:36 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 12 Sep 2010 10:57:36 +1000 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> <87vd6d84f7.fsf@benfinney.id.au> <9YSio.6159$Yv.899@viwinnwfe01.internal.bigpond.com> Message-ID: <87r5gz93sv.fsf@benfinney.id.au> Neil Hodgson writes: > There appear to be deliberate wraps at sentence end or automatic wraps > to fit <80 columns. The automatic wraps in the code presented in the message are wrong. The automatic wraps in the bullet point list are, if not wrong, at least presumably unintended. I hope that clears up what I meant in this case. The effort devoted to explaining this issue far outweighs the burden it caused initially. I'll try to be more explicit when presenting it in future, to forestall this. -- \ ?Of all classes the rich are the most noticed and the least | `\ studied.? ?John Kenneth Galbraith, _The Age of Uncertainty_, | _o__) 1977 | Ben Finney From greg.ewing at canterbury.ac.nz Sat Sep 11 21:11:17 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 12 Sep 2010 13:11:17 +1200 Subject: Queue cleanup In-Reply-To: References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <8eoeovF1atU1@mid.individual.net> Message-ID: <8f2nm9FrnnU1@mid.individual.net> Dennis Lee Bieber wrote: > declaimed the following > >>So maybe we need to redesign the hardware. > > Remember the iAPX-432? > http://en.wikipedia.org/wiki/Intel_iAPX_432#Garbage_collection Not quite what I had in mind. That sounds like a conventional GC algorithm that happens to be implemented in microcode. I'm thinking about ways of designing the memory itself to help with GC. Instead of putting all the smarts in the CPU, move some of them into the RAM. -- Greg From cournape at gmail.com Sat Sep 11 21:50:27 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 12 Sep 2010 10:50:27 +0900 Subject: fast kdtree tree implementation for python 3? In-Reply-To: References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: On Sun, Sep 12, 2010 at 4:26 AM, Stefan Behnel wrote: > _wolf, 11.09.2010 20:15: >> >> does anyone have a suggestion for a ready-to-go, fast kdtree >> implementation for python 3.1 and up, for nearest-neighbor searches? i >> used to use the one from numpy/scipy, but find it a pain to install >> for python 3. > > The latest release is supposed to work with Py3. The latest (1.5) of numpy does, but there is no support of scipy for python 3 yet, unless you use unreleased code. I think it is fair to say it is still rough around the edges, cheers, David From narkewoody at gmail.com Sat Sep 11 23:10:33 2010 From: narkewoody at gmail.com (narke) Date: Sun, 12 Sep 2010 03:10:33 GMT Subject: Distribute Non Library Message-ID: My simple tool writing in python get bigger and bigger and I think I'd better split my code into several files. But, unlike what in some other languages, there is no way to compile these several files into a single executable. Before I splitting my simple tool program, I just put it in /usr/local/bin and run, very simple. Now I have to consider distribute a lot of files in a whole. I know distutils can help, but I feel it is a little uncomfortable, since I am not sharing a library, I am not sharing any thing. I just want to refactory my code. Is there a better solution to my case? Can I simply create a directory in /usr/local/bin and put my script and other used files into the directory? Does distutils help in this case? Thanks in advance. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From robert.kern at gmail.com Sun Sep 12 01:20:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 12 Sep 2010 00:20:46 -0500 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: On 9/11/10 7:08 PM, Lawrence D'Oliveiro wrote: > In message, Robert > Kern wrote: > >> On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote: >> >>> In message, Ian >>> Kelly wrote: >>> >>>> And returning None on failure is dangerous, because if the programmer >>>> does not take care to handle that case, the program may attempt to >>>> regard it as actual data. >>> >>> But None *is* actual data. >> >> And that is exactly the reason why the Samurai Principle says to not >> return None when the function fails to do what it intended to do. > > How can the function ?fail? when it returns what it is specified to return? The Samurai Principle is about what specifications and guarantees a programmer should make about his functions. It gives advice for programmers on how to specify their functions in the face of failure conditions the function itself sees. For example, a function that is supposed to fetch a record from a database given a key, a failure condition would be that the key does not exist in the database. Or the connection times out, or anything else that prevents the function from retrieving a correct record for the key. The Principle says that a programmer should specify his function such that it raises an exception to signify this failure rather than to return None. Of course, a programmer may make his functions' contracts as loose as he pleases, and thus returning None may be "correct" in the sense that it satisfies those contracts. The Principle simply advises that making such contracts is not a good idea. -- 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 mahaboobnisha at gmail.com Sun Sep 12 02:50:06 2010 From: mahaboobnisha at gmail.com (roshini begum) Date: Sat, 11 Sep 2010 23:50:06 -0700 (PDT) Subject: click ads of this site for your good, hot and brite future Message-ID: <11bb80b7-ce6d-4b77-a2c8-d7b85a3c4ebc@b4g2000pra.googlegroups.com> www.127760.blogspot.com From steve at REMOVE-THIS-cybersource.com.au Sun Sep 12 03:55:01 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Sep 2010 07:55:01 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: <4c8c8755$0$11113$c3e8da3@news.astraweb.com> On Sun, 12 Sep 2010 12:08:26 +1200, Lawrence D'Oliveiro wrote: >> And that is exactly the reason why the Samurai Principle says to not >> return None when the function fails to do what it intended to do. > > How can the function ?fail? when it returns what it is specified to > return? Are you trolling? On the unlikely event that you're not, if you have a function called "len", the *intent* of the function is to return the length of its argument. That's why it's called "len" rather than "raise_exception" or "return_none", say. The use of the term "fail" is entirely unexceptional here. It is normal English to say such things as "the function re.match() returns None if the regular expression fails to match" or "if we fail to acquire a lock, raise an Exception". -- Steven From stef.mientki at gmail.com Sun Sep 12 05:14:34 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 12 Sep 2010 11:14:34 +0200 Subject: is there a way to get the encoding of python file Message-ID: <4C8C99FA.2070405@gmail.com> hello, Is it possible to get the encoding of a python file from the first source line, (if there's any), after importing it ( with '__import__' ) # -*- coding: windows-1252 -*- thanks, Stef From stef.mientki at gmail.com Sun Sep 12 05:16:14 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 12 Sep 2010 11:16:14 +0200 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? In-Reply-To: References: <4C8BCDA7.6080202@gmail.com> <4C8BF86B.6060902@gmail.com> Message-ID: <4C8C9A5E.7090001@gmail.com> On 12-09-2010 00:07, Robert Kern wrote: > On 9/11/10 4:45 PM, Stef Mientki wrote: >> On 11-09-2010 21:11, Robert Kern wrote: >>> SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So it's not clear what >>> you mean when you say the database is "windows-1252". Can you be more specific? >> I doubt that, but I'm not sure ... > > From the documentation, it looks like SQLite does not attempt to validate the input as UTF-8 > encoded, so it is possible that someone pushed in raw bytes. See "Support for UTF-8 and UTF-16" in > the following page: > > http://www.sqlite.org/version3.html > >> For some databases written by other programs and >> written with Python, with >> cursor = self.conn.cursor () >> self.conn.text_factory = str >> >> Can only be read back with with text_factory = str >> then the resulting string columns contains normal strings with windows 1252 coding, like >> character 0xC3 > > You can probably use > > self.conn.text_factory = lambda x: x.decode('windows-1252') > > to read the data, though I've never tried to use that API myself. > > You will need to write a program yourself that opens one connection to your existing database for > reading and another connection to another database (using the defaults) for writing. Then iterate > over your tables and copy data from one database to the other. > > You may also be able to simply dump the database to a text file using "sqlite3 bad-database.db > .dump > bad-sql.sql", read the text file into Python as a string, decode it from windows-1252 to > unicode and then encode it as utf-8 and write it back out. Then use "sqlite3 good-database.db > .read good-sql.sql" to create the new database. I've never tried such a thing, so it may not work. > Yes, I think I've to do somethhing like that, to conserve the structure and field types, it's even more complex. cheers, Stef From yoavglazner at gmail.com Sun Sep 12 05:22:10 2010 From: yoavglazner at gmail.com (Glazner) Date: Sun, 12 Sep 2010 02:22:10 -0700 (PDT) Subject: Distribute Non Library References: Message-ID: On Sep 12, 5:10?am, narke wrote: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. ?But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. ?Now I have to consider distribute > a lot of files in a whole. ?I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. ?Is there a better > solution to my case? ?Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? ?Does > distutils help in this case? > > Thanks in advance. try : python mayApp.zip myApp.zip <--> all your files + a __main__.py file as a starting point... From darragh.ssa at gmail.com Sun Sep 12 07:01:00 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 12 Sep 2010 04:01:00 -0700 (PDT) Subject: Minimal-D Message-ID: <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19@n7g2000vbo.googlegroups.com> Hey I'm creating a program called minimal-d which brings together many "things" you would otherwise use seperate to develop. These things are a file-manager,text-editor,ftp-client and sql-client. The program is currently in alpha, but it would be nice if some people tried it out and pointed out some minors,goodies or things that should/ could be appended. It is written in python 2.6 but 2.4 should be good enough, you also need wxPython 2.8. It is wriiten for linux so if you're on windows use it on your own responsability. you can download a .deb or a .tar.gz from launchpad: http://launchpad.net/d-cm my email: darragh.ssa at gmail.com further information: http://kruptology.blogspot.com/2010/09/minimal-d-02.html From thomas at jollybox.de Sun Sep 12 07:50:09 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 12 Sep 2010 13:50:09 +0200 Subject: Distribute Non Library In-Reply-To: References: Message-ID: <201009121350.10287.thomas@jollybox.de> On Sunday 12 September 2010, it occurred to narke to exclaim: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. Now I have to consider distribute > a lot of files in a whole. I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. Is there a better > solution to my case? Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? Does > distutils help in this case? Make it a package (or module), install it with distutils, and create a simple stub script that you put in /usr/local/bin to load it. From lie.1296 at gmail.com Sun Sep 12 08:00:24 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 12 Sep 2010 22:00:24 +1000 Subject: Static typing, Python, D, DbC In-Reply-To: <4c8c086c$0$1597$742ec2ed@news.sonic.net> References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> Message-ID: <4c8cc0da$1@dnews.tpgi.com.au> On 09/12/10 08:53, John Nagle wrote: > On 9/11/2010 9:36 AM, Lie Ryan wrote: >> On 09/12/10 00:33, Bearophile wrote: >> >>> ---------------- >>> >>> Lately while I program with Python one of the D features that I most >>> miss is a built-in Design By Contract (see PEP 316), because it avoids >>> (or helps me to quickly find and fix) many bugs. In my opinion DbC is >>> also very good used with doctests. >> >>> You may implement a poor's man DbC in Python like this: >> >> I would do it like this: > > Design by contract really isn't a good fit to Python. I've > done proof of correctness work, and there are suitable languages > for it. It needs a language where global static analysis is > possible, so you can reliably tell what can changes what. As long as you're not using some funny magic (e.g. monkey patching); then IMO python copes reasonably well. Though, I agree, Python probably isn't really suitable for formal proofing (the best way to assert program's correctness in python is by unittesting, which isn't a formal proof, just one that works most of the time). From bearophileHUGS at lycos.com Sun Sep 12 08:15:03 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 12 Sep 2010 05:15:03 -0700 (PDT) Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> Message-ID: <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> John Nagle: > Design by contract really isn't a good fit to Python. I have used some times the class invariant done manually, as I have shown, and it has avoided me some bugs, so I have experimentally seen you are wrong. > I've done proof of correctness work, and there are suitable languages > for it. It needs a language where global static analysis is > possible, so you can reliably tell what can changes what. I see DbC for Python as a way to avoid or fix some of the bugs of the program, and not to perform proof of correctness of the code. Even if you can't be certain, you are able reduce the probabilities of some bugs to happen. Bye, bearophile From news1234 at free.fr Sun Sep 12 08:53:31 2010 From: news1234 at free.fr (News123) Date: Sun, 12 Sep 2010 14:53:31 +0200 Subject: play sound on Ubuntu 10.4. (pulse audio?) In-Reply-To: References: <4c8be910$0$21261$426a74cc@news.free.fr> Message-ID: <4c8ccd4b$0$12648$426a74cc@news.free.fr> Hi Tim, On 09/11/2010 11:42 PM, Tim Harig wrote: > On 2010-09-11, News123 wrote: >> What would be the way to detect how to play audio on a linux system >> without knowing ufront whether the system uses pulse, ALSA or whatever? > > I would suggest libao: > http://www.xiph.org/ao/ > and it's python bindings: > http://nixbit.com/cat/multimedia/audio/libao/ Thanks a lot. Yes, libao is a nice solution. After having fixed some audio setup issues on my PC I have now the ALSA and the libao solution working. import ao pcm = ao.AudioDevice("pulse", bits=16, rate=sample, channels=1, byte_format=1) pcmdata = create_pcmdata() pcm.play(pcmdata) From sccolbert at gmail.com Sun Sep 12 09:02:56 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 12 Sep 2010 09:02:56 -0400 Subject: palindrome iteration In-Reply-To: References: <49c856c4-e6f4-4e4e-b1b4-694a50e56080@f6g2000yqa.googlegroups.com> <4c778ab6$0$4778$426a74cc@news.free.fr> Message-ID: ;) In [29]: s = 'bannab' In [30]: a = np.frombuffer(s.lower(), dtype='uint8') In [31]: np.all(a == a[::-1]) Out[31]: True In [32]: s = 'bannac' In [33]: a = np.frombuffer(s.lower(), dtype='uint8') In [34]: np.all(a == a[::-1]) Out[34]: False -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at web.de Sun Sep 12 09:04:42 2010 From: deets at web.de (Diez B. Roggisch) Date: Sun, 12 Sep 2010 15:04:42 +0200 Subject: Distribute Non Library References: Message-ID: narke writes: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. Now I have to consider distribute > a lot of files in a whole. I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. Is there a better > solution to my case? Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? Does > distutils help in this case? Consider using setuptools + console entry points. With these, you will automatically generate a shell-script to execute for your otherwise eggified and easy installable package. Diez From reddyrajendraprasad123 at gmail.com Sun Sep 12 09:32:21 2010 From: reddyrajendraprasad123 at gmail.com (Joody) Date: Sun, 12 Sep 2010 06:32:21 -0700 (PDT) Subject: jobs for all-interview tips-career info Message-ID: http://www.interviewtips-jobs.blogspot.com From cmpython at gmail.com Sun Sep 12 11:17:23 2010 From: cmpython at gmail.com (CM) Date: Sun, 12 Sep 2010 08:17:23 -0700 (PDT) Subject: Distribute Non Library References: Message-ID: On Sep 11, 11:10?pm, narke wrote: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. ?But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Sure there is. py2exe, py2app, cx_freeze, etc. From raoulbia at gmail.com Sun Sep 12 11:40:16 2010 From: raoulbia at gmail.com (Baba) Date: Sun, 12 Sep 2010 08:40:16 -0700 (PDT) Subject: analysis of algoritms References: <8762yea761.fsf@dpt-info.u-strasbg.fr> Message-ID: <8650f842-5d76-484e-a282-ab242a8ae4da@k13g2000vbq.googlegroups.com> On Sep 9, 11:22?pm, Alain Ketterlin wrote: > Baba writes: > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > > times (note that an extra step is required to terminate the for loop, > > hence n + 1 and not n executions), which will consume T4( n + 1 ) > > time." (fromhttp://en.wikipedia.org/wiki/Analysis_of_algorithms) > > > 1 ? ?get a positive integer from input > > 2 ? ?if n > 10 > > 3 ? ? ? ?print "This might take a while..." > > 4 ? ?for i = 1 to n > > 5 ? ? ? ?for j = 1 to i > > 6 ? ? ? ? ? ?print i * j > > 7 ? ?print "Done!" > > > Why does step 4 execute n+1 times? what is the exta step mentioned > > above > > In "the outer loop test [...]", the important word is _test_. Line 4 has > to test the value of i against n, which results in true n times and in > false once (where it jumps to instruction 7). > > Note that this would be true even with python loops using range(n) or > xrange(n), where the test is not an integer comparison. > > (Note also how this last remark tries to avoid complete off-topic-ness > of this discussion in this group :-) > > -- Alain. Hi Alain Thanks for the explanation! Baba From sbassi at clubdelarazon.org Sun Sep 12 11:57:24 2010 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Sun, 12 Sep 2010 12:57:24 -0300 Subject: Issue 1 of "PET: English Translation" a Python magazine is out! In-Reply-To: <201009100000.09830.ralsina@netmanagers.com.ar> References: <201009100000.09830.ralsina@netmanagers.com.ar> Message-ID: ---------- Forwarded message ---------- From: Roberto Alsina Date: Fri, Sep 10, 2010 at 12:00 AM Subject: [pyar] Issue 1 of "PET: English Translation" a Python magazine is out! To: python-announce-list at python.org, Python Argentina This magazine is a community effort. It's done by Python guys in Argentina. We are quite proud of it, and we hope you like it too. You can read Issue 1 in our webpage: http://revista.python.org.ar/1/html-en/ It's available in several different formats, including PDF, ePub, Mobipocket, HTML and FB2, and is released under a CC-by-nc-sa license. It has been translated to english by us, and we are not native speakers. Hopefully Shakespeare will not raise from his grave to slap us for grievous offense against his language! But, to save us from the Wrath of Wil, feel free to point out any mistakes and unhappy turns of phrase in the comments. Now that we have the english version out, we have *much bigger* plans for our second issue. We'll keep you posted. _______________________________________________ pyar mailing list pyar at python.org.ar http://listas.python.org.ar/listinfo/pyar PyAr - Python Argentina - Sitio web: http://www.python.org.ar/ -- Sebasti?n Bassi. Lic. en Biotecnologia. Curso de Python en un d?a: http://bit.ly/cursopython Python Book: www.py4bio.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From narkewoody at gmail.com Sun Sep 12 12:29:49 2010 From: narkewoody at gmail.com (narke) Date: Sun, 12 Sep 2010 16:29:49 GMT Subject: Distribute Non Library References: Message-ID: On 2010-09-12, Glazner wrote: > On Sep 12, 5:10?am, narke wrote: >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. ?But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. Before I splitting my simple tool program, I just put it in >> /usr/local/bin and run, very simple. ?Now I have to consider distribute >> a lot of files in a whole. ?I know distutils can help, but I feel it is >> a little uncomfortable, since I am not sharing a library, I am not >> sharing any thing. I just want to refactory my code. ?Is there a better >> solution to my case? ?Can I simply create a directory in /usr/local/bin >> and put my script and other used files into the directory? ?Does >> distutils help in this case? >> >> Thanks in advance. > > try : > python mayApp.zip > > myApp.zip <--> all your files + a __main__.py file as a starting > point... looks also not decent :( i want my tool appear as an executabe, not an zip. but thank you anyway. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From deets at web.de Sun Sep 12 12:48:09 2010 From: deets at web.de (Diez B. Roggisch) Date: Sun, 12 Sep 2010 18:48:09 +0200 Subject: Distribute Non Library References: Message-ID: narke writes: > On 2010-09-12, Glazner wrote: >> On Sep 12, 5:10?am, narke wrote: >>> My simple tool writing in python get bigger and bigger and I think I'd >>> better split my code into several files. ?But, unlike what in some other >>> languages, there is no way to compile these several files into a single >>> executable. Before I splitting my simple tool program, I just put it in >>> /usr/local/bin and run, very simple. ?Now I have to consider distribute >>> a lot of files in a whole. ?I know distutils can help, but I feel it is >>> a little uncomfortable, since I am not sharing a library, I am not >>> sharing any thing. I just want to refactory my code. ?Is there a better >>> solution to my case? ?Can I simply create a directory in /usr/local/bin >>> and put my script and other used files into the directory? ?Does >>> distutils help in this case? >>> >>> Thanks in advance. >> >> try : >> python mayApp.zip >> >> myApp.zip <--> all your files + a __main__.py file as a starting >> point... > > looks also not decent :( i want my tool appear as an executabe, not an > zip. but thank you anyway. Again: http://www.5dollarwhitebox.org/drupal/node/75 Diez From robert.kern at gmail.com Sun Sep 12 13:28:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 12 Sep 2010 12:28:32 -0500 Subject: is there a way to get the encoding of python file In-Reply-To: <4C8C99FA.2070405@gmail.com> References: <4C8C99FA.2070405@gmail.com> Message-ID: On 9/12/10 4:14 AM, Stef Mientki wrote: > hello, > > Is it possible to get the encoding of a python file from the first source line, > (if there's any), > after importing it ( with '__import__' ) > > # -*- coding: windows-1252 -*- The regular expression used to match the encoding declaration is given here: http://docs.python.org/reference/lexical_analysis.html#encoding-declarations -- 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 peterwfh2000 at gmail.com Sun Sep 12 16:17:37 2010 From: peterwfh2000 at gmail.com (PETER WONG F H (+971 50 8320722)) Date: Sun, 12 Sep 2010 13:17:37 -0700 (PDT) Subject: Required RENT Marina and JLT, 050-8320722 Message-ID: <5c65c22d-9cc1-47fa-8a66-ce682b85d4ed@t11g2000vbc.googlegroups.com> Required RENT Marina and JLT, 050-8320722 Dear I have a client who is looking to Rent apartment :- 1. Dubai Marina and JLT :- Studio ,1Bed and 2 Bed only (any building) Please send me your direct availabilities, or call me, viewing tomorrow, thank you! Peter Wong F.H ??? (????RERA BRN: 8866) Dubai Mob ?? : +971 50 83 20 722 Malaysia Mob : +6012-2956466 Fax ?? : +971 4 32 30 895 E-mail ?? : peterwfh2000 at gmail.com Company ?? : Pinky Real Estate Broker????? (????RERA ORN: 1866) Website : http://groups.google.com/group/dubai-property-club/boxsubscribe?p=FixAddr&email&_referer Note: If you want to be removed from our contacts, just reply to this e-mail with REMOVE. The content of this email is only a guide. The information, prices and availability of the properties may change without prior notice From no.email at nospam.invalid Sun Sep 12 16:28:05 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 12 Sep 2010 13:28:05 -0700 Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> Message-ID: <7x1v8y906i.fsf@ruckus.brouhaha.com> Bearophile writes: > I see DbC for Python as a way to avoid or fix some of the bugs of the > program, and not to perform proof of correctness of the code. Even if > you can't be certain, you are able reduce the probabilities of some > bugs to happen. I think DbC as envisioned by the Eiffel guy who coined (and trademarked) the term is that it's a static verification technique, marketing-speak annotating subroutines with pre- and post- conditions that can be checked with Hoare logic. Runtime checks wouldn't qualify as that. From cpblpublic at gmail.com Sun Sep 12 17:06:07 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Sun, 12 Sep 2010 14:06:07 -0700 (PDT) Subject: "pointlabel"-like function for Python: distribute text labels on a 2-d scatter plot to avoid overlapping labels Message-ID: Hello. There is a function for R (http://bm2.genes.nig.ac.jp/RGM2/ R_current/library/maptools/man/pointLabel.html) to help with placing/ locating text labels in an optimized way so as to minimise some measure of text overlap (or likely text overlap). Has anyone written or ported such a thing for Python? Thanks, c From e_d_k at yahoo.com Sun Sep 12 17:47:09 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Sun, 12 Sep 2010 14:47:09 -0700 (PDT) Subject: Static typing, Python, D, DbC In-Reply-To: <7x1v8y906i.fsf@ruckus.brouhaha.com> Message-ID: <567559.41044.qm@web120509.mail.ne1.yahoo.com> --- On Sun, 9/12/10, Paul Rubin wrote: > From: Paul Rubin > Subject: Re: Static typing, Python, D, DbC > To: python-list at python.org > Date: Sunday, September 12, 2010, 4:28 PM > Bearophile > writes: > > I see DbC for Python as a way to avoid or fix some of > the bugs of the > > program, and not to perform proof of correctness of > the code. Even if > > you can't be certain, you are able reduce the > probabilities of some > > bugs to happen. > > I think DbC as envisioned by the Eiffel guy who coined (and > trademarked) > the term is that it's a static verification technique, > marketing-speak > annotating subroutines with pre- and post- conditions that > can be > checked with Hoare logic.? Runtime checks wouldn't > qualify as that. Eiffel throws an exception when a contract is violated. That is run time behavior, not static verification. -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From cpblpublic at gmail.com Sun Sep 12 17:58:41 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Sun, 12 Sep 2010 14:58:41 -0700 (PDT) Subject: "pointlabel"-like function for Python: distribute text labels on a 2-d scatter plot to avoid overlapping labels References: Message-ID: <9c164614-952b-4fbe-b787-96a90b105f68@v6g2000prd.googlegroups.com> > measure of text overlap (or likely text overlap). ?Has anyone written > or ported such a thing for Python? Hm (talking to myself)... the link I gave above has some references, and one of those includes some python code. Seems not packaged up yet for plots, but may be close: http://meta.wikimedia.org/wiki/Map_generator#Placing_labels Anything better? c From paul.hermeneutic at gmail.com Sun Sep 12 18:08:56 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Sun, 12 Sep 2010 16:08:56 -0600 Subject: Current install methodolgy eggs? Message-ID: <8f51bqFrflU1@mid.individual.net> What is the currently favored installation process for Python applications? The last time I looked, it was eggs. Is that still true? Is there any integration of eggs and handling into the base Python distribution? Is PEP 376 intended for applications written in Python, or just the Python distribution? Any good links to source of information. I would like to instill the habit of using a decent install process for even the smallest of utilities. From aahz at pythoncraft.com Sun Sep 12 18:33:22 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Sep 2010 15:33:22 -0700 Subject: How Python works: What do you know about support for negative indices? References: <87vd6d84f7.fsf@benfinney.id.au> <9YSio.6159$Yv.899@viwinnwfe01.internal.bigpond.com> <87r5gz93sv.fsf@benfinney.id.au> Message-ID: In article <87r5gz93sv.fsf at benfinney.id.au>, Ben Finney wrote: >Neil Hodgson writes: >> >> There appear to be deliberate wraps at sentence end or automatic wraps >> to fit <80 columns. > >The automatic wraps in the code presented in the message are wrong. The >automatic wraps in the bullet point list are, if not wrong, at least >presumably unintended. That is considerably different from your original claim that the post contained formatting that was "long-short-long-short", aka comb formatting. >I hope that clears up what I meant in this case. The effort devoted to >explaining this issue far outweighs the burden it caused initially. I'll >try to be more explicit when presenting it in future, to forestall this. s/explicit/accurate/ Had you noted that some lines of code were wrapped short, I would have agreed with you, but I also would have noted that it's not a big deal. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ben+python at benfinney.id.au Sun Sep 12 18:40:02 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 13 Sep 2010 08:40:02 +1000 Subject: Current install methodolgy eggs? References: <8f51bqFrflU1@mid.individual.net> Message-ID: <8762ya8u2l.fsf@benfinney.id.au> Paul Watson writes: > What is the currently favored installation process for Python > applications? ?python ./setup.py install?, using the standard library's Distutils library. Other third-party libraries build on top of that and are generally backward-compatible. > The last time I looked, it was eggs. Is that still true? I don't think eggs were ever the favoured distribution method. They are one *option* provided by Setuptools, but even then a so-called ?sdist? (source distribution) is the favoured distribution format, installed using the above command. > Any good links to source of information. I would like to instill the > habit of using a decent install process for even the smallest of > utilities. This is a dream shared by many, but Distutils has much improvement to be done yet. Recently ? the past couple of years ? a lot of progress has been made on this front, and Python 3.x is getting many of the benefits; look up the ?Distutils2? efforts for more. -- \ ?That's all very good in practice, but how does it work in | `\ *theory*?? ?anonymous | _o__) | Ben Finney From nagle at animats.com Sun Sep 12 18:57:28 2010 From: nagle at animats.com (John Nagle) Date: Sun, 12 Sep 2010 15:57:28 -0700 Subject: Current install methodolgy eggs? In-Reply-To: <8762ya8u2l.fsf@benfinney.id.au> References: <8f51bqFrflU1@mid.individual.net> <8762ya8u2l.fsf@benfinney.id.au> Message-ID: <4c8d5ae1$0$1588$742ec2ed@news.sonic.net> On 9/12/2010 3:40 PM, Ben Finney wrote: > Paul Watson writes: > >> What is the currently favored installation process for Python >> applications? > > ?python ./setup.py install?, using the standard library's Distutils > library. > > Other third-party libraries build on top of that and are generally > backward-compatible. > >> The last time I looked, it was eggs. Is that still true? > > I don't think eggs were ever the favoured distribution method. They are > one *option* provided by Setuptools, but even then a so-called ?sdist? > (source distribution) is the favoured distribution format, installed > using the above command. > >> Any good links to source of information. I would like to instill the >> habit of using a decent install process for even the smallest of >> utilities. > > This is a dream shared by many, but Distutils has much improvement to be > done yet. Recently ? the past couple of years ? a lot of progress has > been made on this front, and Python 3.x is getting many of the benefits; > look up the ?Distutils2? efforts for more. There's some discussion of a common installer on the Python development group, but that's probably the wrong approach. A more effective approach would be something that takes a standard "setup.py" file and wraps it in a Windows installer file, an RPM file, or whatever the platform uses as standard. The "eggs" system never worked very well. It made too many assumptions about where various things were, and when it guessed wrong, you were stuck. John Nagle From contact at xavierho.com Sun Sep 12 19:03:46 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 13 Sep 2010 09:03:46 +1000 Subject: Current install methodolgy eggs? In-Reply-To: <8762ya8u2l.fsf@benfinney.id.au> References: <8f51bqFrflU1@mid.individual.net> <8762ya8u2l.fsf@benfinney.id.au> Message-ID: On 13 September 2010 08:40, Ben Finney > wrote: > Paul Watson writes: > > > What is the currently favored installation process for Python > > applications? > > ?python ./setup.py install?, using the standard library's Distutils > library. > I thought it was python setup.py install or ./setup.py install if you had the permissions set correctly. What distro are you using? Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From bearophileHUGS at lycos.com Sun Sep 12 19:32:29 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 12 Sep 2010 16:32:29 -0700 (PDT) Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> <7x1v8y906i.fsf@ruckus.brouhaha.com> Message-ID: <0151fd8a-87cd-4017-9a63-c9d8be0696ba@a19g2000vbi.googlegroups.com> Paul Rubin: > I think DbC as envisioned by the Eiffel guy who coined (and trademarked) > the term is that it's a static verification technique, marketing-speak > annotating subroutines with pre- and post- conditions that can be > checked with Hoare logic. Runtime checks wouldn't qualify as that. The implementations of DbC in D and C# run their tests at run-time (but in theory an external tool may find a way to perform part of those tests at compile-time). A full implementation of DbC contains several other things beside preconditions and postconditions, see http://www.python.org/dev/peps/pep-0316/ (it misses few things like loop invariants and loop variants). For me DbC is useful almost as unit-testing (I use them at the same time), this is why in the original post I have said it's one of the things I miss most in Python. Bye, bearophile From paul.hermeneutic at gmail.com Sun Sep 12 20:05:13 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Sun, 12 Sep 2010 18:05:13 -0600 Subject: Current install methodolgy eggs? In-Reply-To: <8762ya8u2l.fsf@benfinney.id.au> References: <8f51bqFrflU1@mid.individual.net> <8762ya8u2l.fsf@benfinney.id.au> Message-ID: <8f585sFu3rU1@mid.individual.net> On 2010-09-12 16:40, Ben Finney wrote: > This is a dream shared by many, but Distutils has much improvement to be > done yet. Recently ? the past couple of years ? a lot of progress has > been made on this front, and Python 3.x is getting many of the benefits; > look up the ?Distutils2? efforts for more. Many thanks for your comments, Ben. Looks like I should learn distutils well. I see the distutils2 work going on. I hope it is designed to work with Python 2.x. That would help it get some traction in existing packages. Most platforms have an installation methodology. Oracle Solaris (yea, hard for me to get use to as well) has pkgadd. Microsoft has the .msi installer. Do you think it would be possible to create a toolset that would produce installation kits in each of these forms? That would make the install conform with the standard platform installer. Is this worthwhile thinking about? From narkewoody at gmail.com Sun Sep 12 21:22:17 2010 From: narkewoody at gmail.com (narke) Date: Mon, 13 Sep 2010 01:22:17 GMT Subject: Distribute Non Library References: Message-ID: On 2010-09-12, Diez B. Roggisch wrote: > narke writes: > >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. Before I splitting my simple tool program, I just put it in >> /usr/local/bin and run, very simple. Now I have to consider distribute >> a lot of files in a whole. I know distutils can help, but I feel it is >> a little uncomfortable, since I am not sharing a library, I am not >> sharing any thing. I just want to refactory my code. Is there a better >> solution to my case? Can I simply create a directory in /usr/local/bin >> and put my script and other used files into the directory? Does >> distutils help in this case? > > Consider using setuptools + console entry points. With these, you will > automatically generate a shell-script to execute for your otherwise > eggified and easy installable package. > > Diez That's really attracting. I will try, thanks! -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke test post From narkewoody at gmail.com Sun Sep 12 21:23:04 2010 From: narkewoody at gmail.com (narke) Date: Mon, 13 Sep 2010 01:23:04 GMT Subject: Distribute Non Library References: Message-ID: On 2010-09-12, CM wrote: > On Sep 11, 11:10?pm, narke wrote: >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. ?But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. > > Sure there is. py2exe, py2app, cx_freeze, etc. Also good solution! Thanks for the help. And, cx_freeze looks even workable on my Linux. Great. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke test post From ldo at geek-central.gen.new_zealand Sun Sep 12 21:23:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 13 Sep 2010 13:23:53 +1200 Subject: Minimal-D References: <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19@n7g2000vbo.googlegroups.com> Message-ID: In message <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19 at n7g2000vbo.googlegroups.com>, Kruptein wrote: > Hey I'm creating a program called minimal-d which brings together many > "things" you would otherwise use seperate to develop. These things > are a file-manager,text-editor,ftp-client and sql-client. We have that already. It?s called a ?Linux distro?. From Dave Sun Sep 12 22:24:22 2010 From: Dave (Dave) Date: Sun, 12 Sep 2010 21:24:22 -0500 Subject: Anyone using python on Mint Linux ? Message-ID: Just read that Mint is a fine version of Debian Linux. Any comments about python on this ? Thanks, Dave WB3DWE From no.email at nospam.invalid Sun Sep 12 22:50:23 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 12 Sep 2010 19:50:23 -0700 Subject: Static typing, Python, D, DbC References: Message-ID: <7x39tenyq8.fsf@ruckus.brouhaha.com> Ed Keith writes: >> I think DbC as envisioned by the Eiffel guy... >> the term is that it's a static verification technique, > > Eiffel throws an exception when a contract is violated. That is run > time behavior, not static verification. The runtime checks are for when static analysis hasn't been supplied (that is usually a partly manual process). DBC is always intended to be statically verified as I understand it. Doing it at runtime is just a hackish fallback. From xahlee at gmail.com Sun Sep 12 23:14:09 2010 From: xahlee at gmail.com (Xah Lee) Date: Sun, 12 Sep 2010 20:14:09 -0700 (PDT) Subject: reddit = porn fodder Message-ID: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> reddit = porn fodder Didn't realize, but Reddit is now a porn fodder. http://www.reddit.com/r/LegalTeens/ http://www.reddit.com/r/highheels http://www.reddit.com/r/gonewild/ Its traffic also seems to incleased 10 times since 2008. See: Computer Language Websites Popularity. >From my experience, if you just add one page that is remotely related to sex, that page's traffic will eclipse your other hundred pages. (See: Moving Porn out of XahLee.org.) So, i wonder what percentage of reddit traffic is porn related. (it also means more $$$.) Note that there's lots of semi-porn related sites that became huge sucess. These sites typically start by a teen as teen drivel fodder, where almost 100% content is naked chicks or lurid pictures. Then, when they become big, either the luridness gets reduced or moved out, and or the site become more respectable as some digital age trend setter. For example: 4chan, Fark.com. In fact, facebook started that way. See: Facebook's Ethics. note that reddit was originally somewhat a site for programers, written in common lisp. For links, see: http://xahlee.blogspot.com/2010/09/reddit-porn-fodder.html Xah ? xahlee.org ? From aahz at pythoncraft.com Mon Sep 13 00:00:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Sep 2010 21:00:28 -0700 Subject: Anyone using python on Mint Linux ? References: Message-ID: In article , wrote: > >Just read that Mint is a fine version of Debian Linux. >Any comments about python on this ? Why would there be? Either it works or it's broken, and given that it's Debian, I'd certainly bet that Python works. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From debatem1 at gmail.com Mon Sep 13 00:41:13 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 12 Sep 2010 21:41:13 -0700 Subject: Anyone using python on Mint Linux ? In-Reply-To: References: Message-ID: On Sun, Sep 12, 2010 at 7:24 PM, wrote: > Just read that Mint is a fine version of Debian Linux. > Any comments about python on this ? > Thanks, ?Dave WB3DWE I used to do some of my development on Mint. Was happy with it then, and I suspect that the same would be true now. Geremy Condra From alf.p.steinbach+usenet at gmail.com Mon Sep 13 00:46:48 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 13 Sep 2010 06:46:48 +0200 Subject: Static typing, Python, D, DbC In-Reply-To: <7x39tenyq8.fsf@ruckus.brouhaha.com> References: <7x39tenyq8.fsf@ruckus.brouhaha.com> Message-ID: * Paul Rubin, on 13.09.2010 04:50: > Ed Keith writes: >>> I think DbC as envisioned by the Eiffel guy... >>> the term is that it's a static verification technique, >> >> Eiffel throws an exception when a contract is violated. That is run >> time behavior, not static verification. > > The runtime checks are for when static analysis hasn't been supplied > (that is usually a partly manual process). DBC is always intended to be > statically verified as I understand it. Doing it at runtime is just a > hackish fallback. DBC can't in generally be statically checked. E.g. a precondition of a routine might be that its argument is a sorted array. So regarding the nature of the checks it's not hopelessly incompatible with Python. Cheers, - Alf -- blog at From nagle at animats.com Mon Sep 13 00:47:26 2010 From: nagle at animats.com (John Nagle) Date: Sun, 12 Sep 2010 21:47:26 -0700 Subject: Static typing, Python, D, DbC In-Reply-To: <7x39tenyq8.fsf@ruckus.brouhaha.com> References: <7x39tenyq8.fsf@ruckus.brouhaha.com> Message-ID: <4c8dacea$0$1640$742ec2ed@news.sonic.net> On 9/12/2010 7:50 PM, Paul Rubin wrote: > Ed Keith writes: >>> I think DbC as envisioned by the Eiffel guy... >>> the term is that it's a static verification technique, >> >> Eiffel throws an exception when a contract is violated. That is run >> time behavior, not static verification. > > The runtime checks are for when static analysis hasn't been supplied > (that is usually a partly manual process). DBC is always intended to be > statically verified as I understand it. Doing it at runtime is just a > hackish fallback. Right. Static verification is finally a production technology. All signed Windows 7 drivers must pass Microsoft's static checker, which checks that they don't have bad pointers and call all the driver APIs correctly. That's real "design by contract". It's not that relevant to Python, where you can't crash the underlying system. But it really matters in languages where you can. John Nagle From cloudcontrollers at gmail.com Mon Sep 13 00:53:04 2010 From: cloudcontrollers at gmail.com (cloudcontrol) Date: Sun, 12 Sep 2010 21:53:04 -0700 (PDT) Subject: Python script for MySQL Passwords Unreliable on first boot (rc.local) Message-ID: The script below works great when logged in as root and run from the command line, but when run at first boot using /etc/rc.local in Ubuntu 10.04, it fails about 25% of the time- the system root, mysql root and some mysql user passwords are set correctly, but one will fail with console log reporting standard mysql login error: "ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: YES)" Is there something about running python scripts from init jobs that I should account for, such as an environment variable? #!/usr/bin/env python # Udates system & MySQL root passwords on first boot files = ['/home/ubuntu/passwords','/opt/data1/alfresco/extensions/ extension/alfresco-global.properties','/opt/data/etc/mysql/ debian.cnf','/home/ubuntu/duncil'] userpasswords = {'root':'ROOTPASSWORD'} mysqlpasswords = {'root':'MYSQLPASSWORD','alfresco':'alfrescoPASSWORD','debian-sys- maint':'debian-sys-maintPASSWORD'} otherpasswords = ['OTHERPASSWORD'] log = '/var/log/firstrun' import random, string import crypt import re from subprocess import PIPE, Popen def getsalt(chars = string.letters + string.digits): # generate a random 2-character 'salt' return random.choice(chars) + random.choice(chars) def getpwd(chars = string.letters + string.digits, len = 12): retval = ""; for i in range(0, len): # generate 12 character alphanumeric password retval += random.choice(chars) return retval def replace_pass(filename): handle = open(filename, 'r') hbuf = handle.read() handle.close() for placeholder, password in pdict.iteritems(): hbuf = re.sub(placeholder, password, hbuf) try: # Output file handle = open(filename, 'w') handle.write(hbuf) handle.close() except: pass #logh.write('failed to update ' + filename + "\n") #logh.write('maybe you don\'t have permision to write to it? \n') logh = open(log, "a") logh.write("Starting...\n") # Generate passwords pdict = {} for user, placeholder in userpasswords.iteritems(): syspass = getpwd() Popen(['usermod', '--password', crypt.crypt(syspass, getsalt()), user]) logh.write(placeholder + ": User " + user + " --> " + syspass + "\n") pdict[placeholder] = syspass # What's the MySQL Root password placeholder? mplace = mysqlpasswords['root'] for user, placeholder in mysqlpasswords.iteritems(): mpass = getpwd() if (("root" in mysqlpasswords) and (mysqlpasswords['root'] in pdict)): mrootpass = pdict[mysqlpasswords['root']] else: mrootpass = "" Popen(['mysql', '-uroot', "--password=" + mrootpass, "-e", "UPDATE user SET Password = PASSWORD('" + mpass + "') WHERE User = '" + user + "';FLUSH PRIVILEGES;","mysql"]) logh.write(placeholder + ": MySQL " + user + " --> " + mpass + "\n") pdict[placeholder] = mpass for placeholder in otherpasswords: opass = getpwd() logh.write(placeholder + ": " + opass + "\n") pdict[placeholder] = opass # Update passwords for file in files: logh.write("Replacing placeholders in " + file + "\n") replace_pass(file) logh.write("Finished\n") logh.close From darragh.ssa at gmail.com Mon Sep 13 01:42:17 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 12 Sep 2010 22:42:17 -0700 (PDT) Subject: Minimal-D References: <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19@n7g2000vbo.googlegroups.com> Message-ID: <798a0db8-0ef0-4f35-9427-b713fec45914@g10g2000vbc.googlegroups.com> On Sep 13, 3:23?am, Lawrence D'Oliveiro wrote: > In message > <383a7e4b-819f-4bdf-9b0c-e22baa9b6... at n7g2000vbo.googlegroups.com>, Kruptein > wrote: > > > Hey I'm creating a program called minimal-d which brings together many > > "things" you would otherwise use seperate to develop. ?These things > > are a file-manager,text-editor,ftp-client and sql-client. > > We have that already. It?s called a ?Linux distro?. Well I didn't know that although I use it perhaps daily? From esj at harvee.org Mon Sep 13 02:01:00 2010 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 13 Sep 2010 02:01:00 -0400 Subject: Static typing, Python, D, DbC In-Reply-To: <7x1v8y906i.fsf@ruckus.brouhaha.com> References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> <7x1v8y906i.fsf@ruckus.brouhaha.com> Message-ID: <4C8DBE1C.6040705@harvee.org> On 9/12/2010 4:28 PM, Paul Rubin wrote: > Bearophile writes: >> I see DbC for Python as a way to avoid or fix some of the bugs of the >> program, and not to perform proof of correctness of the code. Even if >> you can't be certain, you are able reduce the probabilities of some >> bugs to happen. > I think DbC as envisioned by the Eiffel guy who coined (and trademarked) > the term is that it's a static verification technique, marketing-speak > annotating subroutines with pre- and post- conditions that can be > checked with Hoare logic. Runtime checks wouldn't qualify as that. Programming by contract as popularized by Bertrand Meyer (that Eiffel guy) was designed for run-time checks because that's when errors show. Programming by contract is based on Dijkstra's weakest precondition work. http://www.scss.tcd.ie/Edsko.de.Vries/talks/weakest_precondition.pdf During the last five years before my hands went bad, I spent significant amount of time working with formal methods and simpler concepts such as design by contract. Design by contract made the last five years of my programming career the most rewarding it had ever been. It was nice to finally write code that was significantly, and measurably better than those coded using Brown 25 (another fine product from Uranus)[1]. one of the common mistakes have seen about programming by contract or design by contract is that people assume it's a proof of correctness. It's not, it's an experiential proof that the code is executing correctly to the extent that you've characterized the pre-and post-conditions. Formal proofs are considered a dead-end as far as I can tell but it's been a good number of years since I've really investigated that particular domain. If my opinion is worth anything to anyone, I would highly recommend adopting some form of programming by contract in everything you write. use the properties that Dijkstra taught us with the weakest precondition to test only what you need to test. If you are careless, assertions can build up to a significant percentage of the code base and Slow execution. the argument for dealing with this, last time I looked, was that you turn off assertions when your code is "running". This logic is flawed because bugs exist and will assert themselves at the worst possible time which usually means after you turned off the assertions. Personally, I see assertions as another form of defensive programming. If you can define preconditions as excluding bad data, then your mainline body becomes faster/smaller. Anyway, this debate was going on circa 1990 and possibly even earlier when Dykstra wrote his first papers. Consider me a double plus vote for strong programming by contract capability in Python. If I can ever get programming by voice working in a reasonable way, I might even be able to use it. :-) PS, to explain Brown 25 in case you weren't watching "those damn kids" comedy movies in the 1970s with a bunch of very stoned friends. Thank God for campus buses keeping us out of cars. [1] http://www.youtube.com/watch?v=008BPUdQ1XA From chris.mahan at gmail.com Mon Sep 13 02:18:13 2010 From: chris.mahan at gmail.com (Christopher Mahan) Date: Sun, 12 Sep 2010 23:18:13 -0700 Subject: Meeting in October Message-ID: Meeting in October? Chris Mahan (818) 671-1709 http://christophermahan.com/ chris.mahan at gmail.com http://twitter.com/chris_mahan From mientki at nonet.com Mon Sep 13 04:02:00 2010 From: mientki at nonet.com (Marc Mientki) Date: Mon, 13 Sep 2010 10:02:00 +0200 Subject: reddit = porn fodder In-Reply-To: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> References: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> Message-ID: Am 13.09.2010 05:14, schrieb Xah Lee: > note that reddit was originally somewhat a site for programers, > written in common lisp. It is still for Lisp programmers: http://www.reddit.com/r/lisp/ regards Marc From ldo at geek-central.gen.new_zealand Mon Sep 13 04:24:50 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 13 Sep 2010 20:24:50 +1200 Subject: Minimal-D References: <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19@n7g2000vbo.googlegroups.com> <798a0db8-0ef0-4f35-9427-b713fec45914@g10g2000vbc.googlegroups.com> Message-ID: In message <798a0db8-0ef0-4f35-9427- b713fec45914 at g10g2000vbc.googlegroups.com>, Kruptein wrote: > On Sep 13, 3:23 am, Lawrence D'Oliveiro > wrote: > >> In message >> <383a7e4b-819f-4bdf-9b0c-e22baa9b6... at n7g2000vbo.googlegroups.com>, >> Kruptein wrote: >> >> > Hey I'm creating a program called minimal-d which brings together many >> > "things" you would otherwise use seperate to develop. These things >> > are a file-manager,text-editor,ftp-client and sql-client. >> >> We have that already. It?s called a ?Linux distro?. > > Well I didn't know that although I use it perhaps daily? You didn?t know that all those features are just a checkbox in the package manager away? From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 13 05:39:09 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 13 Sep 2010 11:39:09 +0200 Subject: Refactoring similar subclasses In-Reply-To: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> References: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> Message-ID: <4c8df13d$0$23080$426a34cc@news.free.fr> Steven D'Aprano a ?crit : > I have some code that currently takes four different classes, A, B, C and > D, and subclasses each of them in the same way: > > class MyA(A): > def method(self, x): > result = super(MyA, self).method(x) > if result == "spam": > return "spam spam spam" > return result > # many more methods overloaded > > > class MyB(B): > def method(self, x): > result = super(MyB, self).method(x) > if result == "spam": > return "spam spam spam" > return result > # many more methods overloaded > If that's really what your code is doing - I mean, calling the super() implementation, checking the result and eventually returning something else instead - then a simple decorator might be enough... Could even be "applied" by the metaclass. From bearophileHUGS at lycos.com Mon Sep 13 06:03:16 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Mon, 13 Sep 2010 03:03:16 -0700 (PDT) Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> <7x1v8y906i.fsf@ruckus.brouhaha.com> Message-ID: <53f4134f-70c5-4b3c-bae6-46e94f9d7d0f@j19g2000vbh.googlegroups.com> John Nagle: > All signed Windows 7 drivers must pass Microsoft's static checker, > which checks that they don't have bad pointers and call all the > driver APIs correctly. I didn't know this, thank you. I'll read more about this topic. ---------------- Eric S. Johansson: > If you are careless, assertions can build up to a > significant percentage of the code base and Slow execution. the argument for > dealing with this, last time I looked, was that you turn off assertions when > your code is "running". This logic is flawed because bugs exist and will assert > themselves at the worst possible time which usually means after you turned off > the assertions. These are real problems. In some situations the code is "fast enough" even with those runtime tests, so in those situations it's better to keep them active even in release builds or when you use the program (this is often true for small script-like programs). But in some situations you want a faster final program. Running the run-time contracts only when you test the code and removing them when you run the program for real sounds silly or dangerous. But life is made of trade-offs, and running those contracts during testing is better than _never_ running them. In practice if your tests are done well enough (they are similar to the real usage of the program), the contracts are able to catch most of the bugs anyway before the release build. The run-time contracts may slow down the code, but there are few ways to reduce this problem. You have to write your contracts taking care of not changing the computational complexity of the routine/method they guard (so you usually don't want to perform a O(n) test for a routine with O(n ln n) worst-case complexity). You run your tests often, so if some tests are too much slow you see it soon and you may fix the problem (the same is true for slow unit tests). In D there are several ways to "layer" the work you perform at runtime, there is not just the release build and test build. You have the version and debug statements, you may use them inside DbC contracts too. So in normal test builds I use faster contracts, but if I spot a bug I lower the debug level and I recompile the D code, activating heavier tests, to better spot where the bug is. One good thing of DbC is that when the "density" of presence of contracts in your programs gets higher of some threshold, most of the bugs present in the code show themselves up as failed assertions/contracts. To me it seems related to percolation theory :-) (http://en.wikipedia.org/ wiki/Percolation_threshold ). In D you may also use enforce(), that's essentially a camouflaged throw/raise statement, if you use it outside DbC contracts, they are tests that run even in release builds when your contracts are disabled. Bye, bearophile From tartley at tartley.com Mon Sep 13 06:13:57 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Mon, 13 Sep 2010 03:13:57 -0700 (PDT) Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: <6b02e793-521c-4514-b8a1-ec9df1ecc43c@q26g2000vbn.googlegroups.com> On Sep 11, 11:32?am, Lawrence D'Oliveiro wrote: > In message , Peter Otten wrote: > > > Lawrence D'Oliveiro wrote: > > >> In message > >> <3a2d194c-9b34-4b84-8680-28bdfb53b... at y3g2000vbm.googlegroups.com>, Muddy > >> Coder wrote: > > >>> For a quick testing purpose, I deliver .pyc files to my customer. I > >>> don't want the black DOS console appearing behind my GUI, but I have > >>> no idea how to do it. Somebody can help? Thanks! > > >> Don?t run it on Windows. > > > If you switch the OS for every minor problem you'll run out of operating > > systems pretty soon... > > Not if you choose a suitably flexible and portable one to begin with. It isn't the OP choosing, it's his client. Now, I dislike aspects of Windows as much as anybody, but even I can see that dictating which OS your client is allowed to use if they want to run your program is sometimes not a viable option. From kinglabs.in at gmail.com Mon Sep 13 08:45:36 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Mon, 13 Sep 2010 05:45:36 -0700 (PDT) Subject: WMI in Python Message-ID: Hi All, I am new to programming and python, Being a system administrator I have chose Inventory (Software & Hardware ) as my first project. I would like to know experts advice on the best way to build the same using python. I would like to this tool to evolve into full fledge application. I would like to collect the complete information of system hardware & and also software installed from registry and add/remove program and feed this data into database. Regards, KINGLABS From ed at leafe.com Mon Sep 13 09:14:15 2010 From: ed at leafe.com (Ed Leafe) Date: Mon, 13 Sep 2010 09:14:15 -0400 Subject: ANN: Dabo 0.9.3 released Message-ID: It's been a while, but we've finally released version 0.9.3 of the Dabo framework! Since Dabo has a Web Update feature that lets developers receive regular updates between releases, the changes won't be too big for most current users of the framework, but compared to the 0.9.2 release, lots has been fixed and improved! Full release notes are at: http://svn.dabodev.com/dabo/tags/dabo-0.9.3/ChangeLog ...but here are the major changes since 0.9.2: - integration of the native Python logging module for all Dabo logging - support for DES3 cryptography in Dabo encryption - changed all pathing to be relative to the app's HomeDirectory - full parameterization of SQL calls - addition of the dRichTextBox control - improvement of unicode support with the dabo.lib.ustr() method You can grab the latest version, as always, from http://dabodev.com/download -- Ed Leafe From rodrick.brown at gmail.com Mon Sep 13 09:42:32 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Mon, 13 Sep 2010 09:42:32 -0400 Subject: WMI in Python In-Reply-To: References: Message-ID: <702BE5F2-EE8B-41BE-9BD4-847693CC20FC@gmail.com> The easiest way to do this is to use the native OS tools readily available to do the collection and log to a central location or if possible shared location accessible by all systems, once you have all the data you want to feed into your RDBMS you could easily parse these logs using python and the native db access module. I hope this give you a pointer. Sent from my iPhone 4. On Sep 13, 2010, at 8:45 AM, KING LABS wrote: > Hi All, > > I am new to programming and python, Being a system administrator I > have chose Inventory (Software & Hardware ) as my first project. > > I would like to know experts advice on the best way to build the same > using python. I would like to this tool to evolve into full fledge > application. > > I would like to collect the complete information of system hardware & > and also software installed from registry and add/remove program and > feed this data into database. > > Regards, > KINGLABS > -- > http://mail.python.org/mailman/listinfo/python-list From kinglabs.in at gmail.com Mon Sep 13 09:51:49 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Mon, 13 Sep 2010 06:51:49 -0700 (PDT) Subject: WMI in Python References: Message-ID: <90bf3587-941a-460b-ab48-9b02d6c830f4@x20g2000pro.googlegroups.com> On Sep 13, 6:42?pm, Rodrick Brown wrote: > The easiest way to do this is to use the native OS tools readily available to do the collection and log to a central location or if possible shared location accessible by all systems, once you have all the data you want to feed into your RDBMS you could easily parse these logs using python and the native db access module. > > I hope this give you a pointer. > > Sent from my iPhone 4. > > On Sep 13, 2010, at 8:45 AM, KING LABS wrote: > > > > > Hi All, > > > I am new to programming and python, Being a system administrator I > > have chose Inventory (Software & Hardware ) as my first project. > > > I would like to know experts advice on the best way to build the same > > using python. I would like to this tool to evolve into full fledge > > application. > > > I would like to collect the complete information of system hardware & > > and also software ?installed from registry and add/remove program and > > feed this data into database. > > > Regards, > > KINGLABS > > -- > >http://mail.python.org/mailman/listinfo/python-list I am trying to learn Python programming. Since I need a custom inventory management tool for my work place. I am considering it as a project in the process of learning Python. I am not looking for easiest way of doing things. I am considering using Python . Also I would need to build a setup of the tool for easy installation. Hope I am clear this time Regards, KINGLABS From ed at leafe.com Mon Sep 13 10:29:44 2010 From: ed at leafe.com (Ed Leafe) Date: Mon, 13 Sep 2010 10:29:44 -0400 Subject: WMI in Python In-Reply-To: <90bf3587-941a-460b-ab48-9b02d6c830f4@x20g2000pro.googlegroups.com> References: <90bf3587-941a-460b-ab48-9b02d6c830f4@x20g2000pro.googlegroups.com> Message-ID: <6F97D7E6-3109-446B-8C5B-9EC71B8F02D1@leafe.com> On Sep 13, 2010, at 9:51 AM, KING LABS wrote: > I am trying to learn Python programming. Since I need a custom > inventory management tool for my work place. I am considering it as a > project in the process of learning Python. > > I am not looking for easiest way of doing things. > I am considering using Python . Also I would need to build a setup of > the tool for easy installation. > > Hope I am clear this time If you're looking for a rich client (i.e., desktop) application, and not a web app, you should check out Dabo: http://dabodev.com. We have hundreds of developers around the world using Dabo to build many different kinds of business applications. -- Ed Leafe From no.email at nospam.invalid Mon Sep 13 11:05:43 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 13 Sep 2010 08:05:43 -0700 Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> <7x1v8y906i.fsf@ruckus.brouhaha.com> <53f4134f-70c5-4b3c-bae6-46e94f9d7d0f@j19g2000vbh.googlegroups.com> Message-ID: <7x4odt65vc.fsf@ruckus.brouhaha.com> Bearophile writes: > But in some situations you want a faster final program. Running the > run-time contracts only when you test the code and removing them when > you run the program for real sounds silly or dangerous. But life is > made of trade-offs, and running those contracts during testing is > better than _never_ running them. For some programs, having the contracts fail during running "for real" is intolerable, so if you're not ready to remove the runtime tests, then program is not ready to run for real. The Wikipedia article about DBC http://en.wikipedia.org/wiki/Design_by_contract makes it sound like what I thought, the preferred enforcement method is static, but runtime testing can be used as a fallback. I'm pretty sure Eiffel itself comes with static DBC tools. From aahz at pythoncraft.com Mon Sep 13 11:12:15 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Sep 2010 08:12:15 -0700 Subject: Looking for Python and Python/Django workplaces in Chicago References: <894aa094-70c8-4c0e-b2c6-f2b783f68929@l20g2000yqe.googlegroups.com> Message-ID: In article <894aa094-70c8-4c0e-b2c6-f2b783f68929 at l20g2000yqe.googlegroups.com>, Erik Reppen wrote: > >I'm a really strong front end web dev with an interest in becoming >more of a generalist web and app dev through Python. Anybody aware of >studios/agencies that actually prefer Python in Chicago I could keep >an eye on. Nobody else has responded, so I'll just refer you to the usual job boards, including http://www.python.org/community/jobs/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From aahz at pythoncraft.com Mon Sep 13 11:14:04 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Sep 2010 08:14:04 -0700 Subject: WMI in Python References: Message-ID: In article , KING LABS wrote: > >I would like to collect the complete information of system hardware & >and also software installed from registry and add/remove program and >feed this data into database. You should subscribe to the win32 mailing list: http://mail.python.org/mailman/listinfo/python-win32 Before you ask questions there, do a bit of searching first -- there are lots of examples. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From giacomo.boffi at polimi.it Mon Sep 13 11:18:06 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Mon, 13 Sep 2010 17:18:06 +0200 Subject: [Tutor] Arguments from the command line References: <8662yfklzu.fsf@aiuole.stru.polimi.it> <86wrqtsxo2.fsf@aiuole.stru.polimi.it> Message-ID: <86d3shlljl.fsf@aiuole.stru.polimi.it> Dennis Lee Bieber writes: > On Fri, 10 Sep 2010 12:25:17 +0200, Giacomo Boffi > declaimed the following in > gmane.comp.python.general: > >> Lawrence D'Oliveiro writes: >> >> > In message <8662yfklzu.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: >> > >> >> Dennis Lee Bieber writes: >> >> >> >>> FORTRAN just differentiates by having the main file start with >> >>> PROGRAM random_name >> >>> whereas subfiles are all either (or both) >> >>> SUBROUTINE another_name(args) >> >>> FUNCTION that_other_name(args) >> >> >> >> no BLOCKDATA? >> > >> > I think you mean COMMON. >> >> i meant BLOCKDATA > > It exists but I've only seen it used once... And I don't recall it > being "executable" in the same way as program/function/subroutine. i simply meant that the BLOCKDATA statement can begin a subfile as well as SUBROUTINE or FUNCTION -- Sar? un'ingenua ma continuo a pensarla come prima, anche se probabilmente i fatti mi smentiscono. -- Francy, in IHC From malaclypse2 at gmail.com Mon Sep 13 11:31:12 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 13 Sep 2010 11:31:12 -0400 Subject: WMI in Python In-Reply-To: References: Message-ID: On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > Hi All, > > I am new to programming and python, Being a system administrator I > have chose Inventory (Software & Hardware ) as my first project. You'll probably want to look at the python WMI module: http://timgolden.me.uk/python/wmi/index.html as well as the pywin32 module: http://sourceforge.net/projects/pywin32/ IIRC, there's been quite a bit of discussion about inventorying installed software on the pywin32 mailing list: http://mail.python.org/mailman/listinfo/python-win32 -- Jerry From thomas at jollybox.de Mon Sep 13 11:32:22 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Mon, 13 Sep 2010 17:32:22 +0200 Subject: Python script for MySQL Passwords Unreliable on first boot (rc.local) In-Reply-To: References: Message-ID: <201009131732.23506.thomas@jollybox.de> On Monday 13 September 2010, it occurred to cloudcontrol to exclaim: > The script below works great when logged in as root and run from the > command line, but when run at first boot using /etc/rc.local in Ubuntu > 10.04, it fails about 25% of the time- the system root, mysql root and > some mysql user passwords are set correctly, but one will fail with > console log reporting standard mysql login error: "ERROR 1045 (28000): > Access denied for user 'root' @ 'localhost' (using password: YES)" It looks like MySQL itself isn't properly set up (yet) in those cases. But why/how? Ubuntu uses upstart to boot up. I don't know much about how this works, but I understand it's dependency-based, and I expect it's parallel as well, where possible. This means that different init scripts could run in a different order sometimes, or even at the same time. However, rc.local should really always be run last. It does not, by and of itself, specify any dependencies, but it could require anything. It would be ludicrous for Ubuntu to run rc.local before or at the same time as other scripts, such as the MySQL one. The only plausible explanation for this strange behaviour I can think of right now would be that either a) Upstart/Ubuntu is just plain stupid, or b) The MySQL init script spawns MySQL in the background and doesn't wait for it to start up correctly. This seams highly unlikely and atypical of MySQL init scripts, but maybe that's what's happening. So this might be a bug in Ubuntu. The way to fix this might simply be to detect the login error and retry, say, 5 times with 1-second intervals. > > Is there something about running python scripts from init jobs that I > should account for, such as an environment variable? > > #!/usr/bin/env python > > # Udates system & MySQL root passwords on first boot > files = ['/home/ubuntu/passwords','/opt/data1/alfresco/extensions/ > extension/alfresco-global.properties','/opt/data/etc/mysql/ > debian.cnf','/home/ubuntu/duncil'] > userpasswords = {'root':'ROOTPASSWORD'} > mysqlpasswords = > {'root':'MYSQLPASSWORD','alfresco':'alfrescoPASSWORD','debian-sys- > maint':'debian-sys-maintPASSWORD'} > otherpasswords = ['OTHERPASSWORD'] > log = '/var/log/firstrun' > > import random, string > import crypt > import re > from subprocess import PIPE, Popen > > def getsalt(chars = string.letters + string.digits): > # generate a random 2-character 'salt' > return random.choice(chars) + random.choice(chars) > > def getpwd(chars = string.letters + string.digits, len = 12): > retval = ""; > for i in range(0, len): > # generate 12 character alphanumeric password > retval += random.choice(chars) > > return retval > > def replace_pass(filename): > handle = open(filename, 'r') > hbuf = handle.read() > handle.close() > for placeholder, password in pdict.iteritems(): > hbuf = re.sub(placeholder, password, hbuf) > > try: > # Output file > handle = open(filename, 'w') > handle.write(hbuf) > handle.close() > except: > pass > #logh.write('failed to update ' + filename + "\n") > #logh.write('maybe you don\'t have permision to write to it? > \n') > > logh = open(log, "a") > logh.write("Starting...\n") > # Generate passwords > pdict = {} > for user, placeholder in userpasswords.iteritems(): > syspass = getpwd() > Popen(['usermod', '--password', crypt.crypt(syspass, getsalt()), > user]) > logh.write(placeholder + ": User " + user + " --> " + syspass + > "\n") > pdict[placeholder] = syspass > > # What's the MySQL Root password placeholder? > mplace = mysqlpasswords['root'] > for user, placeholder in mysqlpasswords.iteritems(): > mpass = getpwd() > if (("root" in mysqlpasswords) and (mysqlpasswords['root'] in > pdict)): > mrootpass = pdict[mysqlpasswords['root']] > else: > mrootpass = "" > > Popen(['mysql', '-uroot', "--password=" + mrootpass, "-e", "UPDATE > user SET Password = PASSWORD('" + mpass + "') WHERE User = '" + user + > "';FLUSH PRIVILEGES;","mysql"]) > logh.write(placeholder + ": MySQL " + user + " --> " + mpass + > "\n") > pdict[placeholder] = mpass > > for placeholder in otherpasswords: > opass = getpwd() > logh.write(placeholder + ": " + opass + "\n") > pdict[placeholder] = opass > > # Update passwords > for file in files: > logh.write("Replacing placeholders in " + file + "\n") > replace_pass(file) > > logh.write("Finished\n") > logh.close From cousinstanley at gmail.com Mon Sep 13 11:52:57 2010 From: cousinstanley at gmail.com (Cousin Stanley) Date: Mon, 13 Sep 2010 15:52:57 +0000 (UTC) Subject: palindrome iteration References: <49c856c4-e6f4-4e4e-b1b4-694a50e56080@f6g2000yqa.googlegroups.com> <4c778ab6$0$4778$426a74cc@news.free.fr> Message-ID: > To deal with "real" palindromes such as, "Madam, I'm Adam," > you should probably strip all spaces and punctuation: > > # untested > pat = re.compile(r'[a-z]') > def is_palindrome(s): > letters = pat.findall(s.lower()) > return letters == reversed(letters) Using python 2.5 the above solution always returned False for me until the reversed( letters ) iterator was explicitly coerced into a list .... return letters == list( reversed( letters ) ) -- Stanley C. Kitching Human Being Phoenix, Arizona From chris.morisset at gmail.com Mon Sep 13 11:58:37 2010 From: chris.morisset at gmail.com (Chris) Date: Mon, 13 Sep 2010 08:58:37 -0700 (PDT) Subject: From IDL to Python Message-ID: <9029e94e-383c-42d9-b670-16f8e351ed04@b4g2000pra.googlegroups.com> Hi, I'm an IDL user since years and try now to learn Python since a few days. I'm blogging the various steps of this transition to: http://idl2python.blogspot.com/ I hope that other IDL switchers can help me by commenting on the blog and helping (me and others) to learn quickly the basics of Python. Cheers, Christophe From narkewoody at gmail.com Mon Sep 13 12:20:51 2010 From: narkewoody at gmail.com (narke) Date: Mon, 13 Sep 2010 16:20:51 GMT Subject: smtplib with Google Message-ID: Hi, Can anyone please show me a workable example that can let me use google's smtp server to send out a message? Thanks. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From namekuseijin at gmail.com Mon Sep 13 12:58:04 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 13 Sep 2010 13:58:04 -0300 Subject: reddit = porn fodder In-Reply-To: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> References: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> Message-ID: Xah Lee escreveu: > reddit = porn fodder > > Didn't realize, but Reddit is now a porn fodder. > > http://www.reddit.com/r/LegalTeens/ > http://www.reddit.com/r/highheels > http://www.reddit.com/r/gonewild/ > > Its traffic also seems to incleased 10 times since 2008. See: Computer > Language Websites Popularity. > > From my experience, if you just add one page that is remotely related > to sex, that page's traffic will eclipse your other hundred pages [snip] > note that reddit was originally somewhat a site for programers, > written in common lisp. guess the lesson here is that Python is more sexy than Lisp. :p -- a game sig: http://tinyurl.com/d3rxz9 --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From egrefen at gmail.com Mon Sep 13 13:05:38 2010 From: egrefen at gmail.com (Edward Grefenstette) Date: Mon, 13 Sep 2010 10:05:38 -0700 (PDT) Subject: Frustrating segfaults with Shelf Message-ID: Dear Pythonistas, Below is a simple script that reads relations from a generator (they're just tuples of strings) and attempts to write them to a database. It's simple as hell, and if I simply ignore the database and have it print to stdout by replacing the line "depsDB[str(index)] = rels" with "print rels" it works just fine. However every time I try to run it just inexplicably segfaults. Help, anyone? Best, Edward ======================================== from WNvectorBuilder import relBuilder import sys import cPickle as pickle import shelve def main(argv): ## read filenames from command line arguments depsFile = open(argv[1]) lemmaFile = open(argv[2]) depsDB = shelve.open(argv[3],"c") ## load lemma dictionary from lemma file lemmaDict = pickle.load(lemmaFile) ## index of database entries index = 0 ## read relations from relation generator, write each relation to database under new index for rels in relBuilder(depsFile,lemmaDict): index += 1 depsDB[str(index)] = rels del rels if __name__ == '__main__': main(sys.argv) ======================================== From chris at simplistix.co.uk Mon Sep 13 13:06:02 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 13 Sep 2010 18:06:02 +0100 Subject: business date and calendar libraries? Message-ID: <4C8E59FA.3060508@simplistix.co.uk> Hi All, I'm wondering what libraries people would use to answer the following questions relating to business days: - on a naive level; "what's give me the last business day" (ie: skipping weekends) - on a less-naive level; same question but taking into account public holidays - on a horrific level; same question, but taking into account business days of a particular market (NYSE, LSE, etc) cheers, Chris From thudfoo at opensuse.us Mon Sep 13 13:19:52 2010 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 13 Sep 2010 10:19:52 -0700 Subject: smtplib with Google In-Reply-To: References: Message-ID: On Mon, Sep 13, 2010 at 9:20 AM, narke wrote: > > Hi, > > Can anyone please show me a workable example that can let me use > google's smtp server to send out a message? ?Thanks. > Go here: http://code.activestate.com/recipes/langs/python/ and search for this gmail From aioe.org at technicalbloke.com Mon Sep 13 14:04:53 2010 From: aioe.org at technicalbloke.com (r0g) Date: Mon, 13 Sep 2010 19:04:53 +0100 Subject: Expected bahaviour of os.chroot and os.getcwd Message-ID: Hi CLP! Not been here for ages, I hope everyone is doing well :) I just want to check if this is the intended behaviour (2.2 to 2.7)... > import os > print os.getcwd() > os.chroot("/home/r0g/whatever/") > print os.getcwd() > os.chdir("/") > print os.getcwd() >>> /home/r0g/AAA_BACKED_UP/Code/py >>> /home/r0g/AAA_BACKED_UP/Code/py >>> / i.e. So do I always have to change directory after changing into a chroot? The reason I ask is because an app I was running inside the chrooted environment (specifically: apt-get) was trying to access files outside the chroot and erroring when it couldn't. I figured it must be doing a getcwd() and getting the cwd of the script that initialized the chroot. I just wanted to confirm that's how it's supposed to work so I'd appreciate it if anyone either knows or can point me to the docs that explain in more detail than http://docs.python.org/library/os.html Also, out of curiosity... If it does work (and should work) the way I think it does how come os.chroot doesn't set the cwd to "/" for you? It's not a costly operation and it could prevent errors of ignorance such as my own. Are there any good reasons why a person (who isn't a hacker / cracker / kludger) would want chrooted processes to be able to see the calling script's cwd anyway? Maybe I'm having a failure of imagination today but the only things I can think that info could be useful for are jailbreaking, nefarious reconnaissance and real ugly hacks. Maybe someone here can enlighten me :) Yours curiously, Roger Heathcote From emile at fenx.com Mon Sep 13 14:09:40 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 13 Sep 2010 11:09:40 -0700 Subject: Frustrating segfaults with Shelf In-Reply-To: References: Message-ID: On 9/13/2010 10:05 AM Edward Grefenstette said... > Dear Pythonistas, > > Below is a simple script that reads relations from a generator > (they're just tuples of strings) and attempts to write them to a > database. It's simple as hell, Ecept of course that no one else can test it due to the dependencies. > and if I simply ignore the database and > have it print to stdout by replacing the line "depsDB[str(index)] = > rels" with "print rels" it works just fine. However every time I try > to run it just inexplicably segfaults. Help, anyone? There are reported problems with the backend database in pre 2.3 python versions. There are also known problems with shelves being accessed by differing versions. So, I'd start by updating as needed, creating a new repository, then testing that. Once it works, migrate the data over if needed. If it doesn't work, it'll be tough to help out if narrowing things down to a specific reproducible test case is difficult. Describe the debugging techniques you're trying with the results you're getting, and we can help contribute with other things to try. HTH, Emile From python at rcn.com Mon Sep 13 14:28:46 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 13 Sep 2010 11:28:46 -0700 (PDT) Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: [Ben Finney] > I encourage anyone whose messages are munged like that to seek > correction from their mail service provider, and switch to a different > one until it's fixed. The post was typed on a mobile device into the text window on Google Groups. It's too bad that inane concerns with newline placement overwhelmed the substance of the post. Raymond From ian.g.kelly at gmail.com Mon Sep 13 14:38:55 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 13 Sep 2010 12:38:55 -0600 Subject: Expected bahaviour of os.chroot and os.getcwd In-Reply-To: References: Message-ID: On Mon, Sep 13, 2010 at 12:04 PM, r0g wrote: > i.e. So do I always have to change directory after changing into a chroot? > Yes, as documented in the man page for the chroot system call: This call changes an ingredient in the pathname resolution process and does > nothing else. > > This call does not change the current working directory, so that after the > call '.' can be outside the tree rooted at '/'. In particular, the superuser > can escape from a 'chroot jail' by doing 'mkdir foo; chroot foo; cd ..'. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon Sep 13 14:48:46 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 13 Sep 2010 20:48:46 +0200 Subject: PIL : "The _imaging C module is not installed" Message-ID: <4c8e720f$0$10204$ba4acef3@reader.news.orange.fr> Hello! (*** sorry for my bad english***) I have the message (title), but only with PIL 1.1.7 (Windows XP, Vista or 7 (32 bits or 64 bits)). I tried: _imaging.pyd exist in C:\Python26\Lib\site-packages\PIL OK python -v >>> import Image OK sys.path contain C:\Python26\Lib\site-packages\PIL OK python >>> import _imaging OK I tested on more than 6 computers, with new installations, or update installations. Same problem. Same problem, also, with Python 2.6 or Python 2.7 If I install again PIL 1.1.6, all scripts run OK. Then, I install again PIL 1.1.7, the problem returns. It is the only thing than I wait before update to Python 2.7 One idea? Thanks in advance. -- Michel Claveau From krdean at gmail.com Mon Sep 13 14:53:26 2010 From: krdean at gmail.com (kBob) Date: Mon, 13 Sep 2010 11:53:26 -0700 (PDT) Subject: From IDL to Python References: <9029e94e-383c-42d9-b670-16f8e351ed04@b4g2000pra.googlegroups.com> Message-ID: <692bd562-314f-41dc-82b4-538f56c2da1b@z30g2000prg.googlegroups.com> On Sep 13, 9:58?am, Chris wrote: > Hi, > > I'm an IDL user since years and try now to learn Python since a few > days. > I'm blogging the various steps of this transition to:http://idl2python.blogspot.com/ > I hope that other IDL switchers can help me by commenting on the blog > and helping (me and others) to learn quickly the basics of Python. > Cheers, > Christophe I have been using IDL and ENVI for years and started working with Python this summer. Mostly, as I find myself working with ArcGIS users and Python is popular among this group. I couldn't convinced them that IDL/ENVI was easier. Did my first "widget" with Python/Tkinter, which does require more work. Still can't get my Python version of the Widget/Hourglass to work correctly. However, you see, you may have to rebuild those IDL routines your so use to using in IDL. However, some areas are alot easier with Python like XML and Net URL stuff (working on OGC WMS and WFS project). There is plenty of examples to help you out. Maybe I should start my own blog spot, just to share my experiences. Kelly Dean Milliken, CO From stef.mientki at gmail.com Mon Sep 13 15:00:19 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 13 Sep 2010 21:00:19 +0200 Subject: is there a way to get the encoding of python file In-Reply-To: References: <4C8C99FA.2070405@gmail.com> Message-ID: <4C8E74C3.50602@gmail.com> On 12-09-2010 19:28, Robert Kern wrote: > On 9/12/10 4:14 AM, Stef Mientki wrote: >> hello, >> >> Is it possible to get the encoding of a python file from the first source line, >> (if there's any), >> after importing it ( with '__import__' ) >> >> # -*- coding: windows-1252 -*- > > The regular expression used to match the encoding declaration is given here: > > http://docs.python.org/reference/lexical_analysis.html#encoding-declarations > yes, but then I've to read the first line of the file myself. In the meanwhile I found another (better ?) solution, (I'm using Python 2.6) Place these 2 lines at the top of the file # -*- coding: windows-1252 -*- from __future__ import unicode_literals or these # -*- coding: utf-8 -*- from __future__ import unicode_literals then you always get the correct unicode string back. thanks, Stef From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon Sep 13 15:02:03 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 13 Sep 2010 21:02:03 +0200 Subject: SendKeys and Python 2.7 References: Message-ID: <4c8e752d$0$5432$ba4acef3@reader.news.orange.fr> Re! Sorry for time, but I am very busy... With Python + Pywin32, you can force the activation of a window (before send some keys...) See: win32gui.SetForegroundWindow(w_handle) or win32gui.SetActiveWindow(w_handle) For to find a windows (and his handle), see: win32gui.EnumWindows() win32gui.GetWindowTex() or win32gui.FindWindowEx() @-salutations -- Michel Claveau From drobinow at gmail.com Mon Sep 13 15:02:09 2010 From: drobinow at gmail.com (David Robinow) Date: Mon, 13 Sep 2010 15:02:09 -0400 Subject: business date and calendar libraries? In-Reply-To: <4C8E59FA.3060508@simplistix.co.uk> References: <4C8E59FA.3060508@simplistix.co.uk> Message-ID: On Mon, Sep 13, 2010 at 1:06 PM, Chris Withers wrote: > I'm wondering what libraries people would use to answer the following > questions relating to business days: > > - on a naive level; "what's give me the last business day" (ie: skipping > weekends) import datetime def is_weekend(year, month, day): return datetime.date(year, month, day).weekday() in (5,6) That should get you started. > - on a less-naive level; same question but taking into account public > holidays This depends on which government is oppressing you. > > - on a horrific level; same question, but taking into account business days > of a particular market (NYSE, LSE, etc) This is just an instance of the public holiday case. You need to define the holidays. If you read lisp you might want to look at the emacs calendar module for some hints on how they describe holidays, such as, for a US-biased example, Martin Luther King day is the third Monday in January, Memorial Day is the last Monday in May, Good Friday is not a public holiday but some markets are closed. From python at rcn.com Mon Sep 13 16:07:19 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 13 Sep 2010 13:07:19 -0700 (PDT) Subject: How Python works: What do you know about support for negative indices? References: Message-ID: <975f6488-09f4-4d80-8889-6e973fbf114e@h40g2000pro.googlegroups.com> On Sep 10, 2:13?pm, Terry Reedy wrote: > Reading the third paragraph out of context, one can miss the restriction > to built-in objects. I had assumed that the conversion using len(), when > available, happened prior to the __getitem__ call. Yes, that's a common misconception. It is probably based on the current wording of the docs and on the PySequence_GetItem() optimized fast-path for builtin and extension sequences. >From the users point-of-view, the important thing is that it (effectively) occurs in the __getitem__() code, that builtin sequences and extensions support it, and that else where it is optional. Another way of saying it is: if you are ever writing a __getitem__() method in Python (even for a subclass of a builtin sequence), then it is up to you to decide whether to add support for negative indices and slicing. Raymond From robert.kern at gmail.com Mon Sep 13 16:31:19 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 13 Sep 2010 15:31:19 -0500 Subject: is there a way to get the encoding of python file In-Reply-To: <4C8E74C3.50602@gmail.com> References: <4C8C99FA.2070405@gmail.com> <4C8E74C3.50602@gmail.com> Message-ID: On 9/13/10 2:00 PM, Stef Mientki wrote: > On 12-09-2010 19:28, Robert Kern wrote: >> On 9/12/10 4:14 AM, Stef Mientki wrote: >>> hello, >>> >>> Is it possible to get the encoding of a python file from the first source line, >>> (if there's any), >>> after importing it ( with '__import__' ) >>> >>> # -*- coding: windows-1252 -*- >> >> The regular expression used to match the encoding declaration is given here: >> >> http://docs.python.org/reference/lexical_analysis.html#encoding-declarations >> > yes, but then I've to read the first line of the file myself. > > In the meanwhile I found another (better ?) solution, (I'm using Python 2.6) > > > Place these 2 lines at the top of the file > # -*- coding: windows-1252 -*- > from __future__ import unicode_literals > > or these > # -*- coding: utf-8 -*- > from __future__ import unicode_literals > > then you always get the correct unicode string back. Ah. I see. You don't actually need to know the encoding; you just want to use literals with raw, unescaped characters embedded in them. This may interfere with the cases when you need a real str object. In Python 2.x, if you want a unicode literal, just use one like so: u'?'. As long as the encoding declaration is correct, this will work just fine. -- 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 thomas at jollybox.de Mon Sep 13 16:56:26 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Mon, 13 Sep 2010 22:56:26 +0200 Subject: is there a way to get the encoding of python file In-Reply-To: References: <4C8C99FA.2070405@gmail.com> <4C8E74C3.50602@gmail.com> Message-ID: <201009132256.26345.thomas@jollybox.de> On Monday 13 September 2010, it occurred to Robert Kern to exclaim: > On 9/13/10 2:00 PM, Stef Mientki wrote: > > On 12-09-2010 19:28, Robert Kern wrote: > >> On 9/12/10 4:14 AM, Stef Mientki wrote: > >>> hello, > >>> > >>> Is it possible to get the encoding of a python file from the first > >>> source line, (if there's any), > >>> after importing it ( with '__import__' ) > >>> > >>> # -*- coding: windows-1252 -*- > >> > >> The regular expression used to match the encoding declaration is given > >> here: > >> > >> http://docs.python.org/reference/lexical_analysis.html#encoding-declarat > >> ions > > > > yes, but then I've to read the first line of the file myself. > > > > In the meanwhile I found another (better ?) solution, (I'm using Python > > 2.6) > > > > > > Place these 2 lines at the top of the file > > # -*- coding: windows-1252 -*- > > from __future__ import unicode_literals > > > > or these > > # -*- coding: utf-8 -*- > > from __future__ import unicode_literals > > > > then you always get the correct unicode string back. > > Ah. I see. You don't actually need to know the encoding; you just want to > use literals with raw, unescaped characters embedded in them. > > This may interfere with the cases when you need a real str object. If you assume that unicode_literals from __future__ works, you can also assume that the b'bytestring' syntax works. > In > Python 2.x, if you want a unicode literal, just use one like so: u'?'. As > long as the encoding declaration is correct, this will work just fine. From modulus10 at yahoo.com Mon Sep 13 18:59:30 2010 From: modulus10 at yahoo.com (C3) Date: Mon, 13 Sep 2010 15:59:30 -0700 (PDT) Subject: Newbie question about Python + CouchDB Message-ID: <317194.60083.qm@web50801.mail.re2.yahoo.com> Total newbie here - have a quick question I have a script that takes data in a flat text file, breaks it up and builds a CouchDB with all my data - however during the loop in which the data is loaded into couchdb - I sometimes get crashes becuase of a duplicate Document ID (which in my case is the serial number of a product) i was wondering if it is possible to; 1. capture the HTTP status code for each post 2. write logic around that code (such as "skip post if error code was a 409") thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From AmFreak at web.de Mon Sep 13 19:07:48 2010 From: AmFreak at web.de (AmFreak at web.de) Date: Tue, 14 Sep 2010 01:07:48 +0200 Subject: Converting an ugly path to a shell path Message-ID: Hi, im using a QFileDialog to let the user select a path that is used later in a command send to the shell like this: retcode = Popen(command + " " + path, shell=True, stdout = PIPE, stderr = PIPE) The problem that occurs now is when the user selects an "ugly" path like this /home/user/!" ?$/. The shell don't understand the special chars so i have to escape them with "\" . Is there a function that does this ? If there isn't i would use a RegEx but I can't even seem to find a list containing all special chars :/ Greetings AmFreak From prologic at shortcircuit.net.au Mon Sep 13 19:33:15 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 14 Sep 2010 09:33:15 +1000 Subject: Newbie question about Python + CouchDB In-Reply-To: <317194.60083.qm@web50801.mail.re2.yahoo.com> References: <317194.60083.qm@web50801.mail.re2.yahoo.com> Message-ID: On Tue, Sep 14, 2010 at 8:59 AM, C3 wrote: > i was wondering if it is possible to; > > 1. capture the HTTP status code for each post > 2. write logic around that code (such as "skip post if error code was a > 409") An appropriate exception should by thrown when it "crashes". Use an appropriate try/except block to "catch" the exception(s). cheers James -- -- James Mills -- -- "Problems are solved by method" -------------- next part -------------- An HTML attachment was scrubbed... URL: From prakash.stack at gmail.com Mon Sep 13 19:36:33 2010 From: prakash.stack at gmail.com (prakash jp) Date: Tue, 14 Sep 2010 05:06:33 +0530 Subject: WMI in Python In-Reply-To: References: Message-ID: Very true most systems admins requirement range from : knoowing the Service tag for a given IP to knowing the system harware details such as RAM sizes etc. This is where Remote Inventory Management comes in handy. There is vault of already existing vb scripts/perl scripts and batch files. To me it looks fine if one can create a common interface and link the preexistant scripts. Else, wmi command line can be directly implemented in python through os.system("COMMAND WMI") so that redistributable python exe be created through py2exe Regards Prakash -------------- next part -------------- An HTML attachment was scrubbed... URL: From malaclypse2 at gmail.com Mon Sep 13 19:37:08 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 13 Sep 2010 19:37:08 -0400 Subject: Converting an ugly path to a shell path In-Reply-To: References: Message-ID: On Mon, Sep 13, 2010 at 7:07 PM, wrote: > The problem that occurs now is when the user selects an "ugly" path like > this /home/user/!" ?$/. > The shell don't understand the special chars so i have to escape them with > "\" . > Is there a function that does this ? http://stackoverflow.com/questions/35817/whats-the-best-way-to-escape-ossystem-calls-in-python seems to cover most of the possibilities. Particularly, do you really need shell=True? If not, you can just call Popen([command, path], stdout=PIPE, stderr=PIPE) and not worry about it. -- Jerry From jaksonaquino at gmail.com Mon Sep 13 19:57:37 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Mon, 13 Sep 2010 20:57:37 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: <4c8e752d$0$5432$ba4acef3@reader.news.orange.fr> References: <4c8e752d$0$5432$ba4acef3@reader.news.orange.fr> Message-ID: On Mon, Sep 13, 2010 at 4:02 PM, Michel Claveau - MVP wrote: > Re! > > Sorry for time, but I am very busy... > > > With Python + Pywin32, you can force the activation of a window (before > send some keys...) > See: > ?win32gui.SetForegroundWindow(w_handle) > > or > ?win32gui.SetActiveWindow(w_handle) > > > > For to find a windows (and his handle), see: > ?win32gui.EnumWindows() > ?win32gui.GetWindowTex() > or > ?win32gui.FindWindowEx() Thanks! I have found a simple workaround: sending Alt+Tab to R Console. Tomorrow I will test your solution. I can't do it right now because I don't have a real machine running Windows here. Best regards, Jakson From narkewoody at gmail.com Mon Sep 13 20:28:28 2010 From: narkewoody at gmail.com (narke) Date: Tue, 14 Sep 2010 00:28:28 GMT Subject: smtplib with Google References: Message-ID: On 2010-09-13, member thudfoo wrote: > On Mon, Sep 13, 2010 at 9:20 AM, narke wrote: >> >> Hi, >> >> Can anyone please show me a workable example that can let me use >> google's smtp server to send out a message? ?Thanks. >> > > Go here: > > http://code.activestate.com/recipes/langs/python/ > > and search for this > > gmail Thanks! -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From ldo at geek-central.gen.new_zealand Mon Sep 13 20:30:57 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 14 Sep 2010 12:30:57 +1200 Subject: Expected bahaviour of os.chroot and os.getcwd References: Message-ID: In message , r0g wrote: > i.e. So do I always have to change directory after changing into a chroot? When all else fails, read the man page . From egrefen at gmail.com Mon Sep 13 20:33:35 2010 From: egrefen at gmail.com (Edward Grefenstette) Date: Mon, 13 Sep 2010 17:33:35 -0700 (PDT) Subject: Frustrating segfaults with Shelf References: Message-ID: Dear Emile, Thank you for your response. Upgrading python and starting with a blank database somehow did the trick! Best, Edward On Sep 13, 7:09?pm, Emile van Sebille wrote: > On 9/13/2010 10:05 AM Edward Grefenstette said... > > > Dear Pythonistas, > > > Below is a simple script that reads relations from a generator > > (they're just tuples of strings) and attempts to write them to a > > database. It's simple as hell, > > Ecept of course that no one else can test it due to the dependencies. > > > and if I simply ignore the database and > > have it print to stdout by replacing the line "depsDB[str(index)] = > > rels" with "print rels" it works just fine. However every time I try > > to run it just inexplicably segfaults. Help, anyone? > > There are reported problems with the backend database in pre 2.3 python > versions. ?There are also known problems with shelves being accessed by > differing versions. > > So, I'd start by updating as needed, creating a new repository, then > testing that. ?Once it works, migrate the data over if needed. > > If it doesn't work, it'll be tough to help out if narrowing things down > to a specific reproducible test case is difficult. ?Describe the > debugging techniques you're trying with the results you're getting, and > we can help contribute with other things to try. > > HTH, > > Emile From kinglabs.in at gmail.com Tue Sep 14 01:39:57 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Mon, 13 Sep 2010 22:39:57 -0700 (PDT) Subject: WMI in Python References: Message-ID: On Sep 13, 8:31?pm, Jerry Hill wrote: > On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > > Hi All, > > > I am new to programming and python, Being a system administrator I > > have chose Inventory (Software & Hardware ) as my first project. > > You'll probably want to look at the python WMI module:http://timgolden.me.uk/python/wmi/index.html > > as well as the pywin32 module:http://sourceforge.net/projects/pywin32/ > > IIRC, there's been quite a bit of discussion about inventorying > installed software on the pywin32 mailing list:http://mail.python.org/mailman/listinfo/python-win32 > > -- > Jerry Thank you all, I will go through the links provided and suggestions. Shall get back to you on this soon. From kinglabs.in at gmail.com Tue Sep 14 01:46:32 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Mon, 13 Sep 2010 22:46:32 -0700 (PDT) Subject: WMI in Python References: Message-ID: On Sep 14, 10:39?am, KING LABS wrote: > On Sep 13, 8:31?pm, Jerry Hill wrote: > > > On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > > > Hi All, > > > > I am new to programming and python, Being a system administrator I > > > have chose Inventory (Software & Hardware ) as my first project. > > > You'll probably want to look at the python WMI module:http://timgolden.me.uk/python/wmi/index.html > > > as well as the pywin32 module:http://sourceforge.net/projects/pywin32/ > > > IIRC, there's been quite a bit of discussion about inventorying > > installed software on the pywin32 mailing list:http://mail.python.org/mailman/listinfo/python-win32 > > > -- > > Jerry > > Thank you all, I will go through the links provided and suggestions. > Shall get back to you on this soon. The following information is exactly what I am trying to collect for the inventory. I can find vb scripts with googling. I want to do the same with Python & Win32. Use Server/Client architecture . Client(agent) updates the information to server. ---------------------------------------------------------------------------------------- BIOS: System serial number, manufacturer, and model Bios manufacturer, version, and date Processors: Type, count (how many of them), manufacturer, speed, and cache Memory: Physical memory type, manufacturer, capacity, and slot number Total physical memory Total swap/paging memory Video: Video adapter: Chipset/model, manufacturer, memory size, speed, and screen resolution Display monitor: Manufacturer, description, refresh rate, type, serial number, and caption Storage/removable devices: Manufacturer, model, size, type, speed( all when applicable) Drive letter, filesystem type, partition/volume size, free space Network adapters/telephony: Manufacturer, model, type, speed, and description MAC and IP address, mask and IP gateway, DHCP server used Miscellaneous hardware: Input devices: Keyboard, mouse, and pointing device Sound devices: Manufacturer name, type, and description System slots: Name, type, and designation System ports: Type, name, caption, and description Software Information: ( from registry & add/remove program ) Operating system: Name, version, comments, and registration info Installed software: Name, publisher, version (from Add / Remove software or Programs and Features menu) Custom-specified registry queries (applicable to Windows OS) ------------------------------------------------------------------------------------------------------------------ From vontio at gmail.com Tue Sep 14 02:41:09 2010 From: vontio at gmail.com (Von) Date: Tue, 14 Sep 2010 14:41:09 +0800 Subject: python datetime Message-ID: Hi, How to determine a date is just the 7th day after today ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep the 7th day is 5 Oct,is there simple way to do this work? I wish I explained clear Bests, -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.ricordeau at gmail.com Tue Sep 14 03:50:40 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Tue, 14 Sep 2010 09:50:40 +0200 Subject: python datetime In-Reply-To: References: Message-ID: <20100914095040.6e26e15c@moriz.interne> # Determine diff days between two dates import datetime now = datetime.date(2010, 9, 28) next = datetime.date(2010, 10, 5) delta = next - now #delta is datetime.timedelta type. #(You can extract days diff) # Determine date in 7 days import datetime now = datetime.date(2010, 9, 28) delta = datetime.timedelta(days=7) next = now + delta Le Tue, 14 Sep 2010 14:41:09 +0800, Von a ?crit : > Hi, > How to determine a date is just the 7th day after today > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep the > 7th day is 5 Oct,is there simple way to do this work? > I wish I explained clear > > Bests, From __peter__ at web.de Tue Sep 14 03:51:37 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Sep 2010 09:51:37 +0200 Subject: python datetime References: Message-ID: Von wrote: > How to determine a date is just the 7th day after today > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep > the 7th day is 5 Oct,is there simple way to do this work? > I wish I explained clear The datetime module takes care of this >>> import datetime as dt >>> dt.date(2010, 9, 28) + dt.timedelta(days=7) datetime.date(2010, 10, 5) See http://docs.python.org/library/datetime.html Why didn't you find that yourself? It's the first match if you google for python datetime. Peter From vontio at gmail.com Tue Sep 14 04:43:25 2010 From: vontio at gmail.com (Von) Date: Tue, 14 Sep 2010 16:43:25 +0800 Subject: python datetime In-Reply-To: <20100914095040.6e26e15c@moriz.interne> References: <20100914095040.6e26e15c@moriz.interne> Message-ID: Thank you,the timedelta class is awesome. On Tue, Sep 14, 2010 at 3:50 PM, Michael Ricordeau < michael.ricordeau at gmail.com> wrote: > > # Determine diff days between two dates > import datetime > now = datetime.date(2010, 9, 28) > next = datetime.date(2010, 10, 5) > delta = next - now > > #delta is datetime.timedelta type. > #(You can extract days diff) > > # Determine date in 7 days > import datetime > now = datetime.date(2010, 9, 28) > delta = datetime.timedelta(days=7) > next = now + delta > > > > > > > > > > > Le Tue, 14 Sep 2010 14:41:09 +0800, > Von a ?crit : > > > Hi, > > How to determine a date is just the 7th day after today > > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep > the > > 7th day is 5 Oct,is there simple way to do this work? > > I wish I explained clear > > > > Bests, > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Tue Sep 14 05:23:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 14 Sep 2010 21:23:03 +1200 Subject: Converting an ugly path to a shell path References: Message-ID: In message , AmFreak at web.de wrote: > The shell don't understand the special chars so i have to escape them with > "\" . > Is there a function that does this ? You could get the shell (at least if it?s Bash) itself to do this. Try the following script: import sys import os import subprocess os.environ["ARG1"] = sys.argv[1] sys.stdout.write \ ( subprocess.Popen ( args = "printf $'%q\\n' \"$ARG1\"", stdout = subprocess.PIPE, shell = True ).communicate()[0] ) Sample output: ldo at theon:hack> ./escape_try '\ & # *' \\\\ \&\ #\ \* From nobody at nowhere.com Tue Sep 14 06:19:57 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 14 Sep 2010 11:19:57 +0100 Subject: Expected bahaviour of os.chroot and os.getcwd References: Message-ID: On Mon, 13 Sep 2010 19:04:53 +0100, r0g wrote: > i.e. So do I always have to change directory after changing into a chroot? You don't *have* to change the directory, but not doing so probably defeats the point of performing a chroot(). > The reason I ask is because an app I was running inside the chrooted > environment (specifically: apt-get) was trying to access files outside > the chroot and erroring when it couldn't. I figured it must be doing a > getcwd() and getting the cwd of the script that initialized the chroot. > I just wanted to confirm that's how it's supposed to work so I'd > appreciate it if anyone either knows or can point me to the docs that > explain in more detail than http://docs.python.org/library/os.html See the relevant manpages. os.chroot, os.chdir and os.getcwd are relatively thin interfaces to the underlying OS functions. > Also, out of curiosity... If it does work (and should work) the way I > think it does how come os.chroot doesn't set the cwd to "/" for you? Because os.chroot just calls the OS' chroot(), which doesn't perform an implicit chdir(). I don't know whether there is any deep reason for the behaviour (beyond the Unix philosophy of "do what I say, not what you think I mean"), but it's been that way forever and isn't likely to change. > It's not a costly operation and it could prevent errors of ignorance > such as my own. Are there any good reasons why a person (who isn't a > hacker / cracker / kludger) would want chrooted processes to be able to > see the calling script's cwd anyway? Maybe I'm having a failure of > imagination today but the only things I can think that info could be > useful for are jailbreaking, nefarious reconnaissance and real ugly > hacks. Maybe someone here can enlighten me :) chroot() wasn't designed as a security mechanism. It simply allows you to control a parameter of the filename resolution algorithm (i.e. the root directory). If you want to use it as a security mechanism, you have to perform additional work, i.e. ensuring that there are no other ways of escaping the chroot (cwd, descriptors, etc). Oh, and you need to lose the ability to perform a further chroot (root privilege or CAP_SYS_CHROOT), otherwise you can just do e.g.: os.chdir("/") os.mkdir("foo") os.chroot("foo") os.chdir("..") Making Python's os.chroot() call os.chdir() wouldn't help from a security standpoint, as the code can still achieve the "raw" behaviour with e.g. ctypes or os.system("chroot ..."). From nobody at nowhere.com Tue Sep 14 06:32:29 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 14 Sep 2010 11:32:29 +0100 Subject: Converting an ugly path to a shell path References: Message-ID: On Tue, 14 Sep 2010 01:07:48 +0200, AmFreak wrote: > im using a QFileDialog to let the user select a path that is used later in > a command send to the shell like this: > > retcode = Popen(command + " " + path, shell=True, stdout = PIPE, stderr = > PIPE) > > The problem that occurs now is when the user selects an "ugly" path like > this /home/user/!" ?$/. > The shell don't understand the special chars so i have to escape them with > "\" . Is there some fundamental reason why you're using a shell? Most of the time, you're better off executing the command directly, i.e.: process = Popen([command, path], shell=False, ...) If you must "unparse" the path for the benefit of the shell, the first question is: *which* shell? For a typical Bourne shell, quoting a string using: qstring = r"'" + string.replace(r"'", r"'\''") + r"'" should be reliable. This won't work for Windows, though; look at the source code for the subprocess module for the (rather bizarre) quoting rules used by Windows. From vontio at gmail.com Tue Sep 14 06:34:10 2010 From: vontio at gmail.com (Von) Date: Tue, 14 Sep 2010 18:34:10 +0800 Subject: python tkinter Listbox Message-ID: Hi all, I am building a simple tool using tkinter,and need multiselection checklist.I find that Listbox with option selectmode=tkinter.MULTIPLE could do this for me. But when I have two Listboxs,I do some selection with one,then do selection with another one,the previous listbox get cleared.I wonder how to keep the previous listbox selected. Wish I explained clear. Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From carlos.grohmann at gmail.com Tue Sep 14 07:02:26 2010 From: carlos.grohmann at gmail.com (Carlos Grohmann) Date: Tue, 14 Sep 2010 04:02:26 -0700 (PDT) Subject: help removing pyQt dll from dist created with py2exe Message-ID: Hello all, i've been trying to build an .exe with py2exe. After many tentatives, it worked, but the total space used by the app goes to 30Mb. It is a simple app, that uses wxpython, matplotlib and numpy. I checked the library.zip file and notived that there is a pyQt-related file there: Pyqt - QtGui.pyo - 8 Mb I'm not using Qt at all, so I assume it would be safe to not have this file, but I don't see how to do it. my setup.py file follows. many thanks Carlos #---------------------------------------------------------------------- from distutils.core import setup import py2exe from glob import glob # Remove the build folder, a bit slower but ensures that build contains the latest import shutil shutil.rmtree("build", ignore_errors=True) # my setup.py is based on one generated with gui2exe, so data_files is done a bit differently data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', 'scrolledpanel', 'customtreectrl', 'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', 'wx.lib.wordwrap', 'types', 'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', 'matplotlib.figure', 'matplotlib.backends.backend_wxagg', 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', 'matplotlib.patches', 'matplotlib.lines', 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', 'matplotlib.collections', 'matplotlib.font_manager', 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' ] excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', 'sqlite3', 'bsddb', 'curses', 'email','_fltkagg', '_gtk', '_gtkcairo', '_agg2', '_cairo', '_cocoaagg', 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' ] packages = ['encodings','pytz','scipy'] dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', 'libglib-2.0-0.dll', 'libcairo-2.dll', 'libpango-1.0-0.dll', 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', 'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', 'QtCore4.dll' ] icon_resources = [] bitmap_resources = [] other_resources = [] # add the mpl mpl-data folder and rc file import matplotlib as mpl data_files += mpl.get_py2exe_datafiles() setup( windows=['OpenStereo.py'], # compressed and optimize reduce the size options = {"py2exe": {"compressed": 2, "optimize": 2, "includes": includes, "excludes": excludes, "packages": packages, "dll_excludes": dll_excludes, # using 2 to reduce number of files in dist folder # using 1 is not recommended as it often does not work "bundle_files": 2, "dist_dir": 'dist', "xref": False, "skip_archive": False, "ascii": False, "custom_boot_script": '', } }, # using zipfile to reduce number of files in dist zipfile = r'lib\library.zip', data_files=data_files ) From almar.klein at gmail.com Tue Sep 14 08:21:07 2010 From: almar.klein at gmail.com (Almar Klein) Date: Tue, 14 Sep 2010 14:21:07 +0200 Subject: help removing pyQt dll from dist created with py2exe In-Reply-To: References: Message-ID: Hi, Have you tried adding "PyQt4", "PyQt4.QtGui" and "PyQt4.QtCore" to your list of excludes? (Maybe only "PyQt4.QtGui" is sufficient.) Almar On 14 September 2010 13:02, Carlos Grohmann wrote: > Hello all, > > i've been trying to build an .exe with py2exe. After many tentatives, > it worked, but the total space used by the app goes to 30Mb. It is a > simple app, that uses wxpython, matplotlib and numpy. I checked the > library.zip file and notived that there is a pyQt-related file there: > > Pyqt - QtGui.pyo - 8 Mb > > I'm not using Qt at all, so I assume it would be safe to not have this > file, but I don't see how to do it. > > my setup.py file follows. > > many thanks > > Carlos > > > #---------------------------------------------------------------------- > from distutils.core import setup > import py2exe > from glob import glob > > # Remove the build folder, a bit slower but ensures that build > contains the latest > import shutil > shutil.rmtree("build", ignore_errors=True) > > # my setup.py is based on one generated with gui2exe, so data_files is > done a bit differently > data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] > > includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', > 'scrolledpanel', 'customtreectrl', > 'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', > 'wx.lib.wordwrap', 'types', > 'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', > 'matplotlib.figure', > 'matplotlib.backends.backend_wxagg', > 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', > 'matplotlib.patches', 'matplotlib.lines', > 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', > 'matplotlib.collections', 'matplotlib.font_manager', > 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' > ] > > excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', > 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', > 'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', > 'sqlite3', > 'bsddb', 'curses', 'email','_fltkagg', '_gtk', > '_gtkcairo', > '_agg2', '_cairo', '_cocoaagg', > 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' > ] > > packages = ['encodings','pytz','scipy'] > > dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', > 'tcl84.dll', 'tk84.dll', > 'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', > 'libglib-2.0-0.dll', > 'libcairo-2.dll', 'libpango-1.0-0.dll', > 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', > 'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', > 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', > 'QtCore4.dll' > ] > > icon_resources = [] > bitmap_resources = [] > other_resources = [] > > # add the mpl mpl-data folder and rc file > import matplotlib as mpl > data_files += mpl.get_py2exe_datafiles() > > setup( > windows=['OpenStereo.py'], > # compressed and optimize reduce the size > options = {"py2exe": {"compressed": 2, > "optimize": 2, > "includes": includes, > "excludes": excludes, > "packages": packages, > "dll_excludes": dll_excludes, > # using 2 to reduce number of files in dist > folder > # using 1 is not recommended as it often > does not work > "bundle_files": 2, > "dist_dir": 'dist', > "xref": False, > "skip_archive": False, > "ascii": False, > "custom_boot_script": '', > } > }, > > # using zipfile to reduce number of files in dist > zipfile = r'lib\library.zip', > > data_files=data_files > ) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Tue Sep 14 09:11:31 2010 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 14 Sep 2010 14:11:31 +0100 Subject: Expected bahaviour of os.chroot and os.getcwd References: Message-ID: On 14/09/10 11:19, Nobody wrote: > On Mon, 13 Sep 2010 19:04:53 +0100, r0g wrote: > >> i.e. So do I always have to change directory after changing into a chroot? > > You don't *have* to change the directory, but not doing so probably > defeats the point of performing a chroot(). Thanks for the info 'Nobody', that was really clear and helpful :) It's kinda obvious once it's pointed out I suppose, the docs for the os module are primarily the os's own docs, should have thought to check the manpages eh, duh! Thanks very much for getting back to me, Roger. From lsolesen at gmail.com Tue Sep 14 10:14:51 2010 From: lsolesen at gmail.com (lsolesen) Date: Tue, 14 Sep 2010 07:14:51 -0700 (PDT) Subject: Install python-mcrypt on Ubuntu Message-ID: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> I am trying to install python-mcrypt (http://labix.org/python-mcrypt) on Ubuntu, but I cannot get it to work. I have the following python installed: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 I get the following message when trying to install. lsolesen at lsolesen-lenovo:~/Desktop/python-mcrypt-1.1$ python setup.py install running install running build running build_ext building 'mcrypt' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o mcrypt.c:24:20: error: Python.h: No such file or directory mcrypt.c:25:26: error: structmember.h: No such file or directory mcrypt.c:39: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:43: error: ?NULL? undeclared here (not in a function) mcrypt.c:54: error: expected specifier-qualifier-list before ?PyObject_HEAD? mcrypt.c:69: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?MCRYPT_members? mcrypt.c:75: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?PyTypeObject? mcrypt.c: In function ?catch_mcrypt_error?: mcrypt.c:89: warning: implicit declaration of function ?strdup? mcrypt.c:89: warning: incompatible implicit declaration of built-in function ?strdup? mcrypt.c:90: warning: implicit declaration of function ?strlen? mcrypt.c:90: warning: incompatible implicit declaration of built-in function ?strlen? mcrypt.c:92: warning: implicit declaration of function ?PyErr_SetString? mcrypt.c:92: error: ?MCRYPTError? undeclared (first use in this function) mcrypt.c:92: error: (Each undeclared identifier is reported only once mcrypt.c:92: error: for each function it appears in.) mcrypt.c:93: warning: implicit declaration of function ?free? mcrypt.c:93: warning: incompatible implicit declaration of built-in function ?free? mcrypt.c: At top level: mcrypt.c:103: error: expected declaration specifiers or ?...? before ?PyObject? mcrypt.c: In function ?get_iv_from_obj?: mcrypt.c:105: error: ?ivobj? undeclared (first use in this function) mcrypt.c:105: error: ?Py_None? undeclared (first use in this function) mcrypt.c:107: warning: implicit declaration of function ?PyString_Check? mcrypt.c:108: warning: implicit declaration of function ?PyString_Size? mcrypt.c:109: warning: implicit declaration of function ?PyString_AsString? mcrypt.c:110: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:111: warning: implicit declaration of function ?PyErr_Format? mcrypt.c:111: error: ?PyExc_ValueError? undeclared (first use in this function) mcrypt.c:113: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:117: error: ?PyExc_TypeError? undeclared (first use in this function) mcrypt.c: In function ?check_algorithm?: mcrypt.c:133: warning: implicit declaration of function ?strcmp? mcrypt.c: In function ?check_key?: mcrypt.c:167: error: ?PyExc_ValueError? undeclared (first use in this function) mcrypt.c:171: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:180: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?init_mcrypt?: mcrypt.c:208: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:225: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:230: error: ?MCRYPTError? undeclared (first use in this function) mcrypt.c:258: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:258: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:259: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:261: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:263: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:266: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:267: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:268: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:269: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:271: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:272: warning: implicit declaration of function ?PyMem_Free? mcrypt.c:272: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:273: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:274: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:275: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:276: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:279: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:282: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:283: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:284: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:285: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:286: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:287: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:290: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:297: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:297: warning: implicit declaration of function ?PyMem_Malloc? mcrypt.c:298: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:299: warning: implicit declaration of function ?PyErr_NoMemory? mcrypt.c:302: warning: implicit declaration of function ?memcpy? mcrypt.c:302: warning: incompatible implicit declaration of built-in function ?memcpy? mcrypt.c:302: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:303: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:303: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:304: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:309: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:309: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:311: warning: implicit declaration of function ?memset? mcrypt.c:311: warning: incompatible implicit declaration of built-in function ?memset? mcrypt.c:311: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:311: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:313: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:316: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:317: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:318: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:319: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:322: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:323: error: ?MCRYPTObject? has no member named ?init? mcrypt.c: In function ?MCRYPT_dealloc?: mcrypt.c:332: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:333: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:335: warning: implicit declaration of function ?PyErr_Clear? mcrypt.c:337: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:338: warning: incompatible implicit declaration of built-in function ?free? mcrypt.c:338: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:339: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:341: error: ?MCRYPTObject? has no member named ?ob_type? mcrypt.c:341: error: ?PyObject? undeclared (first use in this function) mcrypt.c:341: error: expected expression before ?)? token mcrypt.c: At top level: mcrypt.c:345: error: expected declaration specifiers or ?...? before ?PyObject? mcrypt.c:345: error: expected declaration specifiers or ?...? before ?PyObject? mcrypt.c: In function ?MCRYPT__init__?: mcrypt.c:351: error: ?PyObject? undeclared (first use in this function) mcrypt.c:351: error: ?aobj? undeclared (first use in this function) mcrypt.c:352: error: ?mobj? undeclared (first use in this function) mcrypt.c:357: warning: implicit declaration of function ?PyArg_ParseTupleAndKeywords? mcrypt.c:357: error: ?args? undeclared (first use in this function) mcrypt.c:357: error: ?kwargs? undeclared (first use in this function) mcrypt.c:363: error: ?Py_None? undeclared (first use in this function) mcrypt.c:368: error: ?PyExc_TypeError? undeclared (first use in this function) mcrypt.c:389: error: ?MCRYPTError? undeclared (first use in this function) mcrypt.c:411: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:413: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:418: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:418: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:419: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:420: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:423: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:423: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:424: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:425: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:428: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:428: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:429: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:430: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:434: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:434: warning: incompatible implicit declaration of built-in function ?strdup? mcrypt.c:435: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c: At top level: mcrypt.c:458: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:491: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:511: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:535: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:597: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:668: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:806: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:940: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:954: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:972: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1002: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1023: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1039: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1056: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1070: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1079: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?MCRYPT_methods? mcrypt.c:1164: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?PyTypeObject? mcrypt.c:1212: error: expected ?)? before ?*? token mcrypt.c:1236: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1266: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1300: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1348: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1397: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1430: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1463: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1496: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1531: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1567: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1605: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?mcrypt_methods? mcrypt.c:1705: warning: return type defaults to ?int? mcrypt.c: In function ?DL_EXPORT?: mcrypt.c:1705: error: expected declaration specifiers before ?initmcrypt? mcrypt.c:1768: error: expected ?{? at end of input error: command 'gcc' failed with exit status 1 From lsolesen at gmail.com Tue Sep 14 10:26:44 2010 From: lsolesen at gmail.com (lsolesen) Date: Tue, 14 Sep 2010 07:26:44 -0700 (PDT) Subject: Install python-mcrypt on Ubuntu References: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> Message-ID: Tried on another machine, but with this error: lsolesen at lsolesen-toshiba:~/Desktop/python-mcrypt-1.1$ python setup.py install running install running build running build_ext building 'mcrypt' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o mcrypt.c:23:20: error: mcrypt.h: No such file or directory mcrypt.c:55: error: expected specifier-qualifier-list before ?MCRYPT? mcrypt.c:70: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:71: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c: In function ?catch_mcrypt_error?: mcrypt.c:86: warning: implicit declaration of function ?mcrypt_strerror? mcrypt.c:86: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?get_iv_from_obj?: mcrypt.c:110: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:110: warning: comparison between pointer and integer mcrypt.c:113: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:113: warning: format ?%d? expects type ?int?, but argument 3 has type ?struct PyMemberDef *? mcrypt.c: In function ?check_algorithm?: mcrypt.c:130: warning: implicit declaration of function ?mcrypt_list_algorithms? mcrypt.c:130: warning: assignment makes pointer from integer without a cast mcrypt.c:134: warning: implicit declaration of function ?mcrypt_free_p? mcrypt.c: In function ?check_mode?: mcrypt.c:147: warning: implicit declaration of function ?mcrypt_list_modes? mcrypt.c:147: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?check_key?: mcrypt.c:171: warning: implicit declaration of function ?mcrypt_enc_get_key_size? mcrypt.c:171: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:180: warning: implicit declaration of function ?mcrypt_enc_get_supported_key_sizes? mcrypt.c:180: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:180: warning: assignment makes pointer from integer without a cast mcrypt.c:188: warning: implicit declaration of function ?mcrypt_free? mcrypt.c: In function ?init_mcrypt?: mcrypt.c:208: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:208: warning: initialization makes integer from pointer without a cast mcrypt.c:225: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:225: warning: statement with no effect mcrypt.c:258: warning: implicit declaration of function ?mcrypt_enc_set_state? mcrypt.c:258: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:258: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:259: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:261: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:261: warning: statement with no effect mcrypt.c:263: warning: implicit declaration of function ?mcrypt_generic_deinit? mcrypt.c:263: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:266: warning: implicit declaration of function ?mcrypt_generic_init? mcrypt.c:266: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:267: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:268: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:269: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:271: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:271: warning: statement with no effect mcrypt.c:272: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:273: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:274: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:274: warning: statement with no effect mcrypt.c:275: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:275: warning: statement with no effect mcrypt.c:276: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:276: warning: statement with no effect mcrypt.c:279: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:279: warning: statement with no effect mcrypt.c:282: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:282: warning: statement with no effect mcrypt.c:283: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:284: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:285: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:285: warning: statement with no effect mcrypt.c:286: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:286: warning: statement with no effect mcrypt.c:287: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:287: warning: statement with no effect mcrypt.c:290: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:297: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:297: warning: statement with no effect mcrypt.c:298: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:302: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:303: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:303: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:303: warning: passing argument 1 of ?PyMem_Malloc? makes integer from pointer without a cast /usr/include/python2.6/pymem.h:52: note: expected ?size_t? but argument is of type ?struct PyMemberDef *? mcrypt.c:303: warning: statement with no effect mcrypt.c:304: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:309: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:309: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:309: warning: passing argument 3 of ?memcpy? makes integer from pointer without a cast /usr/include/bits/string3.h:49: note: expected ?size_t? but argument is of type ?struct PyMemberDef *? mcrypt.c:311: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:311: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:311: warning: passing argument 3 of ?memset? makes integer from pointer without a cast /usr/include/bits/string3.h:78: note: expected ?size_t? but argument is of type ?struct PyMemberDef *? mcrypt.c:313: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:316: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:317: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:318: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:318: warning: statement with no effect mcrypt.c:319: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:319: warning: statement with no effect mcrypt.c:322: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:322: warning: statement with no effect mcrypt.c:323: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:323: warning: statement with no effect mcrypt.c: In function ?MCRYPT_dealloc?: mcrypt.c:332: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:333: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:337: warning: implicit declaration of function ?mcrypt_module_close? mcrypt.c:337: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:338: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:339: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c: In function ?MCRYPT__init__?: mcrypt.c:397: warning: implicit declaration of function ?mcrypt_module_is_block_algorithm? mcrypt.c:400: warning: implicit declaration of function ?mcrypt_module_is_block_algorithm_mode? mcrypt.c:411: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:411: warning: implicit declaration of function ?mcrypt_module_open? mcrypt.c:411: warning: statement with no effect mcrypt.c:413: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:413: error: ?MCRYPT_FAILED? undeclared (first use in this function) mcrypt.c:413: error: (Each undeclared identifier is reported only once mcrypt.c:413: error: for each function it appears in.) mcrypt.c:418: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:418: warning: implicit declaration of function ?mcrypt_enc_is_block_mode? mcrypt.c:418: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:418: warning: statement with no effect mcrypt.c:419: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:419: warning: passing argument 1 of ?catch_mcrypt_error? makes integer from pointer without a cast mcrypt.c:80: note: expected ?int? but argument is of type ?struct PyMemberDef *? mcrypt.c:420: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:423: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:423: warning: implicit declaration of function ?mcrypt_enc_get_block_size? mcrypt.c:423: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:423: warning: statement with no effect mcrypt.c:424: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:424: warning: passing argument 1 of ?catch_mcrypt_error? makes integer from pointer without a cast mcrypt.c:80: note: expected ?int? but argument is of type ?struct PyMemberDef *? mcrypt.c:425: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:428: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:428: warning: implicit declaration of function ?mcrypt_enc_get_iv_size? mcrypt.c:428: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:428: warning: statement with no effect mcrypt.c:429: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:429: warning: passing argument 1 of ?catch_mcrypt_error? makes integer from pointer without a cast mcrypt.c:80: note: expected ?int? but argument is of type ?struct PyMemberDef *? mcrypt.c:430: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:434: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:434: warning: statement with no effect mcrypt.c:435: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:435: warning: statement with no effect mcrypt.c: In function ?MCRYPT_encrypt?: mcrypt.c:551: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:552: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:552: warning: assignment makes integer from pointer without a cast mcrypt.c:575: warning: implicit declaration of function ?mcrypt_generic? mcrypt.c:575: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_decrypt?: mcrypt.c:614: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:615: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:615: warning: assignment makes integer from pointer without a cast mcrypt.c:632: warning: implicit declaration of function ?mdecrypt_generic? mcrypt.c:632: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_encrypt_file?: mcrypt.c:700: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:700: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:700: warning: assignment makes integer from pointer without a cast mcrypt.c:738: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:738: error: invalid operands to binary / (have ?int? and ?struct PyMemberDef *?) mcrypt.c:738: warning: assignment makes integer from pointer without a cast mcrypt.c:739: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:739: error: invalid operands to binary % (have ?int? and ?struct PyMemberDef *?) mcrypt.c:739: warning: assignment makes integer from pointer without a cast mcrypt.c:745: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:745: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:745: warning: assignment makes integer from pointer without a cast mcrypt.c:751: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:751: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:751: warning: assignment makes integer from pointer without a cast mcrypt.c:757: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_decrypt_file?: mcrypt.c:841: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:841: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:841: warning: assignment makes integer from pointer without a cast mcrypt.c:887: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:887: error: invalid operands to binary / (have ?int? and ?struct PyMemberDef *?) mcrypt.c:887: warning: assignment makes integer from pointer without a cast mcrypt.c:888: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:888: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:888: warning: assignment makes integer from pointer without a cast mcrypt.c:893: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:902: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:902: warning: assignment makes integer from pointer without a cast mcrypt.c:905: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:905: warning: comparison between pointer and integer mcrypt.c:907: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:907: warning: assignment makes integer from pointer without a cast mcrypt.c:913: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:913: error: invalid operands to binary - (have ?int? and ?struct PyMemberDef *?) mcrypt.c:919: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:919: warning: comparison between pointer and integer mcrypt.c: In function ?MCRYPT_get_block_size?: mcrypt.c:943: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:943: warning: passing argument 1 of ?PyInt_FromLong? makes integer from pointer without a cast /usr/include/python2.6/intobject.h:38: note: expected ?long int? but argument is of type ?struct PyMemberDef *? mcrypt.c: In function ?MCRYPT_get_key_size?: mcrypt.c:957: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_get_key_sizes?: mcrypt.c:979: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:979: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?MCRYPT_has_iv?: mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 1 of ?strlen? from incompatible pointer type /usr/include/string.h:397: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 2 of ?__builtin_strcmp? from incompatible pointer type mcrypt.c:1008: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 2 of ?__builtin_strcmp? from incompatible pointer type mcrypt.c:1008: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 1 of ?strlen? from incompatible pointer type /usr/include/string.h:397: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 2 of ?__builtin_strcmp? from incompatible pointer type mcrypt.c:1008: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 2 of ?__builtin_strcmp? from incompatible pointer type mcrypt.c:1008: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1010: warning: implicit declaration of function ?mcrypt_enc_mode_has_iv? mcrypt.c:1010: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_get_iv_size?: mcrypt.c:1026: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_is_block_algorithm?: mcrypt.c:1042: warning: implicit declaration of function ?mcrypt_enc_is_block_algorithm? mcrypt.c:1042: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_is_block_mode?: mcrypt.c:1059: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:1059: warning: passing argument 1 of ?PyInt_FromLong? makes integer from pointer without a cast /usr/include/python2.6/intobject.h:38: note: expected ?long int? but argument is of type ?struct PyMemberDef *? mcrypt.c: In function ?MCRYPT_is_block_algorithm_mode?: mcrypt.c:1073: warning: implicit declaration of function ?mcrypt_enc_is_block_algorithm_mode? mcrypt.c:1073: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?_mcrypt_list_algorithms?: mcrypt.c:1316: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?_mcrypt_list_modes?: mcrypt.c:1364: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?_mcrypt_is_block_mode?: mcrypt.c:1445: warning: implicit declaration of function ?mcrypt_module_is_block_mode? mcrypt.c: In function ?_mcrypt_get_block_size?: mcrypt.c:1512: warning: implicit declaration of function ?mcrypt_module_get_algo_block_size? mcrypt.c: In function ?_mcrypt_get_key_size?: mcrypt.c:1547: warning: implicit declaration of function ?mcrypt_module_get_algo_key_size? mcrypt.c: In function ?_mcrypt_get_key_sizes?: mcrypt.c:1585: warning: implicit declaration of function ?mcrypt_module_get_algo_supported_key_sizes? mcrypt.c:1586: warning: assignment makes pointer from integer without a cast error: command 'gcc' failed with exit status 1 From lists at cheimes.de Tue Sep 14 10:28:16 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 14 Sep 2010 16:28:16 +0200 Subject: Install python-mcrypt on Ubuntu In-Reply-To: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> References: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> Message-ID: Am 14.09.2010 16:14, schrieb lsolesen: > I am trying to install python-mcrypt (http://labix.org/python-mcrypt) > on Ubuntu, but I cannot get it to work. I have the following python > installed: sudo apt-get install python-dev Christian From lallous at lgwm.org Tue Sep 14 10:30:50 2010 From: lallous at lgwm.org (lallous) Date: Tue, 14 Sep 2010 07:30:50 -0700 (PDT) Subject: help with calling a static method in a private class Message-ID: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> How can I keep the class private and have the following work: [code] class __internal_class(object): @staticmethod def meth1(s): print "meth1:", s @staticmethod def meth2(s): print "meth2:", __internal_class.meth1(s) x = __internal_class() x.meth2('sdf') [/code] Thanks From deets at web.de Tue Sep 14 10:38:50 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 14 Sep 2010 16:38:50 +0200 Subject: help with calling a static method in a private class References: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> Message-ID: <87r5gwgzk5.fsf@web.de> lallous writes: > How can I keep the class private and have the following work: > > [code] > class __internal_class(object): > @staticmethod > def meth1(s): > print "meth1:", s > > @staticmethod > def meth2(s): > print "meth2:", > __internal_class.meth1(s) > > x = __internal_class() > > x.meth2('sdf') > [/code] By not using a double underscore. It is effectless on classes anyway (they are not hidden because of that). And additionally, but simply not using staticmethods at all. It's a rather obscure feature of python - usually, classmethods are what is considered a static method in other languages. And with that, even your double underscores work: class __internal_class(object): @classmethod def meth1(cls, s): print "meth1:", s @classmethod def meth2(cls, s): print "meth2:", cls.meth1(s) x = __internal_class() x.meth2('sdf') Diez From lists at cheimes.de Tue Sep 14 10:41:29 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 14 Sep 2010 16:41:29 +0200 Subject: Install python-mcrypt on Ubuntu In-Reply-To: References: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> Message-ID: Am 14.09.2010 16:26, schrieb lsolesen: > Tried on another machine, but with this error: > > lsolesen at lsolesen-toshiba:~/Desktop/python-mcrypt-1.1$ python setup.py > install > running install > running build > running build_ext > building 'mcrypt' extension > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - > Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c > mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o > mcrypt.c:23:20: error: mcrypt.h: No such file or directory You are missing the development headers for mcrypt, too. sudo apt-get install libmcrypt-dev Christian From benjamin.kaplan at case.edu Tue Sep 14 10:48:27 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Sep 2010 10:48:27 -0400 Subject: Install python-mcrypt on Ubuntu In-Reply-To: References: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> Message-ID: On Tue, Sep 14, 2010 at 10:26 AM, lsolesen wrote: > > mcrypt.c:23:20: error: mcrypt.h: No such file or directory Well, there's your problem. You don't have the mcrypt headers installed. sudo apt-get install libmcrypt-dev From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 14 11:34:11 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 14 Sep 2010 17:34:11 +0200 Subject: help with calling a static method in a private class In-Reply-To: <87r5gwgzk5.fsf@web.de> References: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> <87r5gwgzk5.fsf@web.de> Message-ID: <4c8f95eb$0$21752$426a74cc@news.free.fr> Diez B. Roggisch a ?crit : > lallous writes: > >> How can I keep the class private and have the following work: >> >> [code] >> class __internal_class(object): >> @staticmethod >> def meth1(s): >> print "meth1:", s >> >> @staticmethod >> def meth2(s): >> print "meth2:", >> __internal_class.meth1(s) >> >> x = __internal_class() >> >> x.meth2('sdf') >> [/code] > > By not using a double underscore. It is effectless on classes anyway > (they are not hidden because of that). FWIW, if what you want is to mark the class as being implementation (ie: not part of your module's API), just prefix it with a single underscore. > > And additionally, but simply not using staticmethods at all. +1 From nanothermite911fbibustards at gmail.com Tue Sep 14 11:37:34 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Tue, 14 Sep 2010 08:37:34 -0700 (PDT) Subject: The Brutal Truth About 911 MOSQUE - The JEWS and YANNKS themselves MAILED ANTHRAX and used NANO THERMITE to DEMOLISH the buildings Message-ID: Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA About me: The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From carlos.grohmann at gmail.com Tue Sep 14 11:45:21 2010 From: carlos.grohmann at gmail.com (Carlos Grohmann) Date: Tue, 14 Sep 2010 12:45:21 -0300 Subject: help removing pyQt dll from dist created with py2exe In-Reply-To: References: Message-ID: many thanks Almar. No more pyqt stuff in my dist. cheers carlos On Tue, Sep 14, 2010 at 09:21, Almar Klein wrote: > Hi, > > Have you tried adding "PyQt4", "PyQt4.QtGui" and "PyQt4.QtCore" to your list > of excludes? > (Maybe only "PyQt4.QtGui" is sufficient.) > > ? Almar > > > On 14 September 2010 13:02, Carlos Grohmann > wrote: >> >> Hello all, >> >> i've been trying to build an .exe with py2exe. After many tentatives, >> it worked, but the total space used by the app goes to 30Mb. It is a >> simple app, that uses wxpython, matplotlib and numpy. I checked the >> library.zip file and notived that there is a pyQt-related file there: >> >> Pyqt - QtGui.pyo - 8 Mb >> >> I'm not using Qt at all, so I assume it would be safe to not have this >> file, but I don't see how to do it. >> >> my setup.py file follows. >> >> many thanks >> >> Carlos >> >> >> #---------------------------------------------------------------------- >> from distutils.core import setup >> import py2exe >> from glob import glob >> >> # Remove the build folder, a bit slower but ensures that build >> contains the latest >> import shutil >> shutil.rmtree("build", ignore_errors=True) >> >> # my setup.py is based on one generated with gui2exe, so data_files is >> done a bit differently >> data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] >> >> includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', >> 'scrolledpanel', 'customtreectrl', >> ? ? ? ? ? ?'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', >> 'wx.lib.wordwrap', 'types', >> ? ? ? ? ? ?'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', >> 'matplotlib.figure', >> ? ? ? ? ? ?'matplotlib.backends.backend_wxagg', >> 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', >> ? ? ? ? ? ?'matplotlib.patches', 'matplotlib.lines', >> 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', >> ? ? ? ? ? ?'matplotlib.collections', 'matplotlib.font_manager', >> 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' >> ? ? ? ? ? ?] >> >> excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', >> ? ? ? ? ? ?'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', >> ? ? ? ? ? ?'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', >> 'sqlite3', >> ? ? ? ? ? ?'bsddb', 'curses', 'email','_fltkagg', '_gtk', >> '_gtkcairo', >> ? ? ? ? ? ?'_agg2', '_cairo', '_cocoaagg', >> 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' >> ? ? ? ? ? ?] >> >> packages = ['encodings','pytz','scipy'] >> >> dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', >> 'tcl84.dll', 'tk84.dll', >> ? ? ? ? ? ? ? ?'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', >> 'libglib-2.0-0.dll', >> ? ? ? ? ? ? ? ?'libcairo-2.dll', 'libpango-1.0-0.dll', >> 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', >> ? ? ? ? ? ? ? ?'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', >> 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', >> ? ? ? ? ? ? ? ?'QtCore4.dll' >> ? ? ? ? ? ? ? ?] >> >> icon_resources = [] >> bitmap_resources = [] >> other_resources = [] >> >> # add the mpl mpl-data folder and rc file >> import matplotlib as mpl >> data_files += mpl.get_py2exe_datafiles() >> >> setup( >> ? ?windows=['OpenStereo.py'], >> ? ? ? ? ? ? ? ? ? ? ? ? ?# compressed and optimize reduce the size >> ? ?options = {"py2exe": {"compressed": 2, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"optimize": 2, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"includes": includes, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"excludes": excludes, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"packages": packages, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"dll_excludes": dll_excludes, >> ? ? ? ? ? ? ? ? ? ? ? ? ?# using 2 to reduce number of files in dist >> folder >> ? ? ? ? ? ? ? ? ? ? ? ? ?# using 1 is not recommended as it often >> does not work >> ? ? ? ? ? ? ? ? ? ? ? ? ?"bundle_files": 2, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"dist_dir": 'dist', >> ? ? ? ? ? ? ? ? ? ? ? ? ?"xref": False, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"skip_archive": False, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"ascii": False, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"custom_boot_script": '', >> ? ? ? ? ? ? ? ? ? ? ? ? } >> ? ? ? ? ? ? ?}, >> >> ? ?# using zipfile to reduce number of files in dist >> ? ?zipfile = r'lib\library.zip', >> >> ? ?data_files=data_files >> ) >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- Prof. Carlos Henrique Grohmann - Geologist D.Sc. Institute of Geosciences - Univ. of S?o Paulo, Brazil http://www.igc.usp.br/pessoais/guano http://lattes.cnpq.br/5846052449613692 Linux User #89721 ________________ Can?t stop the signal. From post at andre-bell.de Tue Sep 14 12:59:48 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Tue, 14 Sep 2010 18:59:48 +0200 Subject: String formatting with the format string syntax Message-ID: <4C8FAA04.8000201@andre-bell.de> Hello, I'm used to write in Python something like >>> s = 'some text that says: %(hello)s' and then have a dictionary like >>> english = { 'hello': 'hello' } and get the formatted output like this: >>> s % english Occasionally I want to extract the field names from the template string. I was used to write a class like class Extractor(object): def __init__(self): self.keys = [] def __getitem__(self, key): self.keys.append(key) return '' and use it like this: >>> e = Extractor() >>> res = s % e >>> e.keys ['hello'] Now Python has the format method for string formatting with the more advanced handling. So I could as well write >>> s = 'some text that says: {hello!s}' >>> s.format(hello='hello') My question is, if I do have a string template which uses the newer format string syntax, how do I best extract the field information? I found the str._formatter_parser() method which I could use like this: keys = [] for (a, key, c, d) in s._formatter_parser(): if key: keys.append(key) Is there a more elegant solution? What are a, c, d? Where can I find additional information on this method? Should one use a method that actually starts with an _? Couldn't this one change any time soon? Thanks for any help Andre From miki.tebeka at gmail.com Tue Sep 14 14:20:18 2010 From: miki.tebeka at gmail.com (Miki) Date: Tue, 14 Sep 2010 11:20:18 -0700 (PDT) Subject: String formatting with the format string syntax References: Message-ID: You can use ** syntax: >>> english = {'hello':'hello'} >>> s.format(**english) On Sep 14, 9:59?am, Andre Alexander Bell wrote: > Hello, > > I'm used to write in Python something like > > ?>>> s = 'some text that says: %(hello)s' > > and then have a dictionary like > > ?>>> english = { 'hello': 'hello' } > > and get the formatted output like this: > > ?>>> s % english > > Occasionally I want to extract the field names from the template string. > I was used to write a class like > > class Extractor(object): > ? ? ?def __init__(self): > ? ? ? ? ?self.keys = [] > ? ? ?def __getitem__(self, key): > ? ? ? ? ?self.keys.append(key) > ? ? ? ? ?return '' > > and use it like this: > > ?>>> e = Extractor() > ?>>> res = s % e > ?>>> e.keys > ['hello'] > > Now Python has the format method for string formatting with the more > advanced handling. So I could as well write > > ?>>> s = 'some text that says: {hello!s}' > ?>>> s.format(hello='hello') > > My question is, if I do have a string template which uses the newer > format string syntax, how do I best extract the field information? > > I found the str._formatter_parser() method which I could use like this: > > keys = [] > for (a, key, c, d) in s._formatter_parser(): > ? ? ?if key: > ? ? ? ? ?keys.append(key) > > Is there a more elegant solution? > What are a, c, d? > Where can I find additional information on this method? > Should one use a method that actually starts with an _? > Couldn't this one change any time soon? > > Thanks for any help > > Andre From neil.benn at ziath.com Tue Sep 14 14:36:18 2010 From: neil.benn at ziath.com (Neil Benn) Date: Tue, 14 Sep 2010 11:36:18 -0700 Subject: Cross Compiling Python for ARM Message-ID: Hello, I've been working on an embedded ARM system which boots up quick (a beagleboard running a skinnied down version of Angstrom). For this I need to compile a lot of libraries from scratch. One of the things I need is Python; I've cross compiled Python and it works OK when I try to run it on an image on the same system which is more complete (the same hardware running Lucid Ubuntu). However when I try to run on the skinnied down image I get the following feedback: # ./python -sh: ./python: not found I'm guessing that Python is depending on some libraries which I don't have but as my situation is unusual I'm not sure what I am missing. So, I'm asking for help which is what libraries does python depend on on Linux? Thanks in advance. Cheers, Neil -- -- Neil Benn Msc Director Ziath Ltd Phone :+44 (0)7508 107942 Website - http://www.ziath.com IMPORTANT NOTICE: This message, including any attached documents, is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify Ziath Ltd immediately by email at info at ziath.com. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollybox.de Tue Sep 14 15:19:16 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Tue, 14 Sep 2010 21:19:16 +0200 Subject: Cross Compiling Python for ARM In-Reply-To: References: Message-ID: <201009142119.17639.thomas@jollybox.de> On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: > # > ./python > > -sh: ./python: not found I'm guessing either there is no file ./python, or /bin/sh is fundamentally broken. From thomas at jollybox.de Tue Sep 14 15:20:25 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Tue, 14 Sep 2010 21:20:25 +0200 Subject: String formatting with the format string syntax In-Reply-To: References: Message-ID: <201009142120.25442.thomas@jollybox.de> On Tuesday 14 September 2010, it occurred to Miki to exclaim: > You can use ** syntax: > >>> english = {'hello':'hello'} > >>> s.format(**english) No, you can't. This only works with dicts, not with arbitrary mappings, or dict subclasses that try to do some kind of funny stuff. > > On Sep 14, 9:59 am, Andre Alexander Bell wrote: > > Hello, > > > > I'm used to write in Python something like > > > > >>> s = 'some text that says: %(hello)s' > > > > and then have a dictionary like > > > > >>> english = { 'hello': 'hello' } > > > > and get the formatted output like this: > > > > >>> s % english > > > > Occasionally I want to extract the field names from the template string. > > I was used to write a class like > > > > class Extractor(object): > > def __init__(self): > > self.keys = [] > > def __getitem__(self, key): > > self.keys.append(key) > > return '' > > > > and use it like this: > > > > >>> e = Extractor() > > >>> res = s % e > > >>> e.keys > > ['hello'] > > > > Now Python has the format method for string formatting with the more > > advanced handling. So I could as well write > > > > >>> s = 'some text that says: {hello!s}' > > >>> s.format(hello='hello') > > > > My question is, if I do have a string template which uses the newer > > format string syntax, how do I best extract the field information? > > > > I found the str._formatter_parser() method which I could use like this: > > > > keys = [] > > for (a, key, c, d) in s._formatter_parser(): > > if key: > > keys.append(key) > > > > Is there a more elegant solution? > > What are a, c, d? > > Where can I find additional information on this method? > > Should one use a method that actually starts with an _? > > Couldn't this one change any time soon? > > > > Thanks for any help > > > > Andre From blye at telkomsa.net Tue Sep 14 15:20:28 2010 From: blye at telkomsa.net (bli) Date: Tue, 14 Sep 2010 12:20:28 -0700 (PDT) Subject: WMI in Python References: Message-ID: <26ea4ebe-d455-47d6-b637-4e8ecb895f2d@k9g2000vbo.googlegroups.com> On Sep 14, 7:46?am, KING LABS wrote: > On Sep 14, 10:39?am, KING LABS wrote: > > > > > > > > > > > On Sep 13, 8:31?pm, Jerry Hill wrote: > > > > On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > > > > Hi All, > > > > > I am new to programming and python, Being a system administrator I > > > > have chose Inventory (Software & Hardware ) as my first project. > > > > You'll probably want to look at the python WMI module:http://timgolden.me.uk/python/wmi/index.html > > > > as well as the pywin32 module:http://sourceforge.net/projects/pywin32/ > > > > IIRC, there's been quite a bit of discussion about inventorying > > > installed software on the pywin32 mailing list:http://mail.python.org/mailman/listinfo/python-win32 > > > > -- > > > Jerry > > > Thank you all, I will go through the links provided and suggestions. > > Shall get back to you on this soon. > > The following information is exactly what I am trying to collect for > the inventory. I can find vb scripts with googling. I want to do the > same with Python & Win32. Use Server/Client architecture . > Client(agent) updates the information to server. > > ---------------------------------------------------------------------------------------- > > BIOS: > > System serial number, manufacturer, and model > Bios manufacturer, version, and date > > Processors: > > Type, count (how many of them), manufacturer, speed, and cache > > Memory: > > Physical memory type, manufacturer, capacity, and slot number > Total physical memory > Total swap/paging memory > > Video: > > Video adapter: Chipset/model, manufacturer, memory size, speed, and > screen resolution > > Display monitor: Manufacturer, description, refresh rate, type, serial > number, and caption > > Storage/removable devices: > > Manufacturer, model, size, type, speed( all when applicable) > > Drive letter, filesystem type, partition/volume size, free space > > Network adapters/telephony: > > Manufacturer, model, type, speed, and description > MAC and IP address, mask and IP gateway, DHCP server used > > Miscellaneous hardware: > > Input devices: Keyboard, mouse, and pointing device > Sound devices: Manufacturer name, type, and description > System slots: Name, type, and designation > System ports: Type, name, caption, and description > > Software Information: ( from registry & add/remove program ) > > Operating system: Name, version, comments, and registration info > Installed software: Name, publisher, version (from Add / Remove > software or Programs and Features menu) > Custom-specified registry queries (applicable to Windows OS) > > ------------------------------------------------------------------------------------------------------------------ when I found Python :-) I downloaded from a Ms site many (+- 120) py programs for hardware and os stuff and collated them into one script. Astonishing amount of data in the innards of a computer, do not print some of these!@#! I meant to wrap it in a neat menu (any time now), but it is easy to use as is. A few of the options : 102 --- -List Terminal Services Terminals- 103 --- -List Terminal Services Permissions- 104 --- -List Terminal Services Session Settings- 105 --- - List Terminal Services Session Directory Settings- 106 --- - List Terminal Services Network Adapter- 107 --- -List Terminal Services Environment Settings- 108 --- -List Terminal Services Logon Settings- 109 --- -List Terminal Services General Settings- 110 --- -List Terminal Services Client Settings- 111 --- -List Terminal Services Terminal Settings- 112 --- -List Terminal Service Service Properties- 113 --- -List Info about Binary Files used on Computer- 114 --- -List Info about CODECS on this computer- 115 --- -List Installed Software- 116 --- -List Installed Software Features- Happy to send to you, will post it somewhere soon. From benjamin.kaplan at case.edu Tue Sep 14 15:57:32 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Sep 2010 15:57:32 -0400 Subject: String formatting with the format string syntax In-Reply-To: <201009142120.25442.thomas@jollybox.de> References: <201009142120.25442.thomas@jollybox.de> Message-ID: On Tue, Sep 14, 2010 at 3:20 PM, Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Miki to exclaim: >> You can use ** syntax: >> >>> english = {'hello':'hello'} >> >>> s.format(**english) > > No, you can't. This only works with dicts, not with arbitrary mappings, or > dict subclasses that try to do some kind of funny stuff. > That was changed in 2.6 http://docs.python.org/release/2.6.6/whatsnew/2.6.html#other-language-changes From david at boddie.org.uk Tue Sep 14 15:59:58 2010 From: david at boddie.org.uk (David Boddie) Date: Tue, 14 Sep 2010 21:59:58 +0200 Subject: Cross Compiling Python for ARM References: Message-ID: On Tuesday 14 September 2010 21:19, Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: >> # >> ./python >> >> -sh: ./python: not found > > > I'm guessing either there is no file ./python, or /bin/sh is fundamentally > broken. Yes, it may be instructive to use the file command to see what ./python actually is: file ./python David From nytrokiss at gmail.com Tue Sep 14 17:25:00 2010 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 14 Sep 2010 14:25:00 -0700 Subject: Default python compile options Message-ID: Hi, I am trying to compile Python 2.7 on Ubuntu and I am wondering what are the default compile options (i.e ./configure ..) for ubuntu. I just want the standard ones that are included with the python2.6 version on ubuntu. Can someone please shed some light? Thanks, James -- http://www.goldwatches.com -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From sridharr at activestate.com Tue Sep 14 17:25:24 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Tue, 14 Sep 2010 14:25:24 -0700 Subject: python27.exe vs python2.7.exe ... Message-ID: Hi, As you may already know, ActivePython provides versioned Python executables that makes it possible to invoke a particular X.Y version from the command line directly if you have multiple Python versions on PATH. Eg: C:\Python27\python26.exe C:\Python27\python27.exe C:\Python31\python31.exe In the upcoming releases, we are considering to change this format to match the unix executables (with a 'dot' in it). Eg: C:\Python27\python2.6.exe C:\Python27\python2.7.exe C:\Python31\python3.1.exe The idea is to be able to invoke "python2.7 myscript.py" on both Unix and Windows. Thoughts? Because there is bin/python3 on unix (to separate it from the default 2.x interpreter) - it is perhaps a good idea to have "C:\Python31\python3.exe" as well. -srid From xrgtn at yandex.ru Tue Sep 14 17:42:52 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Wed, 15 Sep 2010 00:42:52 +0300 Subject: scp with paramiko In-Reply-To: <8bfa00e7-2ae5-42a3-bb45-fcdb491d70e4@x18g2000pro.googlegroups.com> References: <8bfa00e7-2ae5-42a3-bb45-fcdb491d70e4@x18g2000pro.googlegroups.com> Message-ID: <20100914214252.GA6755@xrgtn-q40> Hello, On Wed, Sep 01, 2010 at 09:56:18AM -0700, cerr wrote: > I want to download a file from a client using > paramiko. I found plenty of ressources using > google on how to send a file but none that > would describe how to download files from a > client. Download files from remote to local? Get sftp object as usual, then e.g.: for f in sftp.listdir(rdir): lf = os.path.join(opts.tmpdir, f) sftp.get(rdir + "/" + f, lf) sftp.get() uses path + "/" + basename instead of os.path.join() because the latter uses local pathname conventions which may or may not be appropriate for remote system. -- With best regards, xrgtn From prologic at shortcircuit.net.au Tue Sep 14 17:50:29 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 15 Sep 2010 07:50:29 +1000 Subject: Default python compile options In-Reply-To: References: Message-ID: On Wed, Sep 15, 2010 at 7:25 AM, James Matthews wrote: > I am trying to compile Python 2.7 on Ubuntu and I am wondering what are the > default compile options (i.e ./configure ..) for ubuntu. I just want the > standard ones that are included with the python2.6 version on ubuntu. Can > someone please shed some light? You can easily find this out for yourself. Ubuntu is a Debian-based system. Use dpkg-source to get the source package of python-2.6 and have a look at how it builds. cheers James PS: There's nothing wrong with a plain old ./configure (no options). -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Tue Sep 14 17:52:29 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 15 Sep 2010 07:52:29 +1000 Subject: python27.exe vs python2.7.exe ... In-Reply-To: References: Message-ID: On Wed, Sep 15, 2010 at 7:25 AM, Sridhar Ratnakumar wrote: > Thoughts? I've never been a Windows developer (probably never will be), but I have one thought: Why has ActivePython not been doing this all along ? cheers James -- -- James Mills -- -- "Problems are solved by method" From trentm at activestate.com Tue Sep 14 18:31:47 2010 From: trentm at activestate.com (Trent Mick) Date: Tue, 14 Sep 2010 15:31:47 -0700 Subject: python27.exe vs python2.7.exe ... In-Reply-To: References: Message-ID: <4C8FF7D3.1010805@activestate.com> On 10-09-14 2:52 PM, James Mills wrote: > On Wed, Sep 15, 2010 at 7:25 AM, Sridhar Ratnakumar > wrote: >> Thoughts? > > I've never been a Windows developer (probably never will be), but I > have one thought: > > Why has ActivePython not been doing this all along ? Hind sight is 20/20 is all I can say. :) When I added support for "pythonXY.exe" instead of "pythonX.Y.exe" I was trying to add an out-of-the-box equivalent for what I saw some core developers doing with their own batch scripts: py20.bat, py21.bat, etc. I didn't think to provide equivalence to the Unix shortcuts. Also, this was a looong time ago (back when python 1.5, 1.6 and 2.0 were still relevant) so it could be there there *weren't* many of the typical (now) Linux "pythonX.Y" installed executables. Trent -- Trent Mick ActiveState From prologic at shortcircuit.net.au Tue Sep 14 18:36:12 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 15 Sep 2010 08:36:12 +1000 Subject: python27.exe vs python2.7.exe ... In-Reply-To: <4C8FF7D3.1010805@activestate.com> References: <4C8FF7D3.1010805@activestate.com> Message-ID: On Wed, Sep 15, 2010 at 8:31 AM, Trent Mick wrote: > Hind sight is 20/20 is all I can say. :) Perhaps having 1/60 sight is better ? :) > When I added support for "pythonXY.exe" instead of "pythonX.Y.exe" I was > trying to add an out-of-the-box equivalent for what I saw some core > developers doing with their own batch scripts: py20.bat, py21.bat, etc. ?I > didn't think to provide equivalence to the Unix shortcuts. Also, this was a > looong time ago (back when python 1.5, 1.6 and 2.0 were still relevant) so > it could be there there *weren't* many of the typical (now) Linux > "pythonX.Y" installed executables. Good point :) My comment was just a comment, nothing negative intended! cheers james -- -- James Mills -- -- "Problems are solved by method" From post at andre-bell.de Tue Sep 14 19:14:02 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Wed, 15 Sep 2010 01:14:02 +0200 Subject: String formatting with the format string syntax In-Reply-To: References: Message-ID: <4C9001BA.8010705@andre-bell.de> On 09/14/2010 08:20 PM, Miki wrote: > You can use ** syntax: >>>> english = {'hello':'hello'} >>>> s.format(**english) Thanks for your answer. Actually your answer tells me that my example was misleading. Consider the template s = 'A template with {variable1} and {variable2} placeholders.' I'm seeking a way to extract the named placesholders, i.e. the names 'variable1' and 'variable2' from the template. I'm not trying to put in values for them. I hope this is clearer. Thanks again Andre From astan.chee at al.com.au Tue Sep 14 19:32:24 2010 From: astan.chee at al.com.au (Astan Chee) Date: Wed, 15 Sep 2010 09:32:24 +1000 Subject: webcam in gtalk/xmpp Message-ID: <4C900608.1030409@al.com.au> Hi, I was wondering if there is an implementation in any of the xmpp python API (e.g. xmpppy, etc) that implements broadcasting webcam (as well as audio-chat). The documentation on xmpppy doesn't show me how this can be done. Is this even possible? Thanks Astan From greg.ewing at canterbury.ac.nz Tue Sep 14 19:54:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 15 Sep 2010 11:54:00 +1200 Subject: Numpy: Multiplying arrays of matrices Message-ID: <8fag9dF4mtU1@mid.individual.net> Suppose I have two N+2 dimensional arrays, representing N-d arrays of 2-d matrices. I want to perform matrix multiplication between corresponding matrices in these arrays. I had thought that dot() might do this, but it appears not, because e.g. applying it to two 3-d arrays gives a 4-d array, not another 3-d array. I'd also like to be able to find the inverse of each matrix in one of these arrays, but again, inv() doesn't do what I want -- it only works on 2-d arrays. Any thoughts on how to achieve these things using numpy functions? -- Greg From nytrokiss at gmail.com Tue Sep 14 20:20:48 2010 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 14 Sep 2010 17:20:48 -0700 Subject: Default python compile options In-Reply-To: References: Message-ID: Thanks James, I did try the plain old configure but I was missing compression zlib and I wanted to make sure that I wasn't going to be be running in circles having to run ./configure a bunch of times so I decided to ask) James On Tue, Sep 14, 2010 at 2:50 PM, James Mills wrote: > On Wed, Sep 15, 2010 at 7:25 AM, James Matthews > wrote: > > I am trying to compile Python 2.7 on Ubuntu and I am wondering what are > the > > default compile options (i.e ./configure ..) for ubuntu. I just want the > > standard ones that are included with the python2.6 version on ubuntu. Can > > someone please shed some light? > > You can easily find this out for yourself. > > Ubuntu is a Debian-based system. > > Use dpkg-source to get the source package of python-2.6 and have a > look at how it builds. > > cheers > James > > PS: There's nothing wrong with a plain old ./configure (no options). > > -- > -- James Mills > -- > -- "Problems are solved by method" > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue Sep 14 20:25:05 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 15 Sep 2010 10:25:05 +1000 Subject: Default python compile options In-Reply-To: References: Message-ID: On Wed, Sep 15, 2010 at 10:20 AM, James Matthews wrote: > Thanks James, > I did try the plain old configure but I was missing compression zlib and I > wanted to make sure that I wasn't going to be be running in circles having > to run ./configure a bunch of times so I decided to ask) You might need to installed some other packages from Ubuntu/Debian eg: zlib-dev Building python requires certain "development libraries" that Ubuntu/Debian systems do not install by default (they are separate packages). cheers James -- -- James Mills -- -- "Problems are solved by method" From bearophileHUGS at lycos.com Tue Sep 14 20:26:25 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Tue, 14 Sep 2010 17:26:25 -0700 (PDT) Subject: palindrome iteration References: <49c856c4-e6f4-4e4e-b1b4-694a50e56080@f6g2000yqa.googlegroups.com> Message-ID: <8affa77e-6d86-4d80-8e7a-55a28d2c3dd6@k11g2000vbf.googlegroups.com> Baba: > def i_palindrome(pal): > while len(pal)>1: > if pal[0] == pal[-1]: > pal=pal[1:-1] > return True > > print i_palindrome('annab') In normal programming a significant percentage of the time is spent debugging. Experience shows that even short functions may be buggy. If you don't want to waste too much time debugging your code you need to adopt a bit more rigorous approach to write programs. Learning to play piano requires a lot of self-discipline, programming too needs some. Ask yourself what are the exact purposes of your function/class/ program. And then define what are the correct outputs for all input corner cases you are able to find. This is TDD, Thought-driven development. For this program, what's the right output for mixed case strings, for empty strings, for input strings that contain many words with mixed white space and punctuation between them, for unicode strings that contain weird characters? Generally even simple functions may become very complex if you want to manage even complex input cases. You are free to ignore some of those inputs, to keep your code simple enough, but it's usually better for your function to not just ignore some inputs, but give some kind of error for the inputs you don't want to consider. Let's say you accept simple Unicode strings, you don't want to ignore white space, an empty string is palindrome, text cases need to be ignored. I don't like Test-Driven development a lot because your most powerful tool is your brain&mind and not your unit-tests, but I like tests a lot. So you need tests for this small function too. Here doctests are enough. Your first test is better to fail, to be sure your doctest is working: def is_palindrome(text): """ >>> is_palindrome("xy") False """ return True if __name__ == "__main__": import doctest doctest.testmod() print "Doctests done." Code formatting and function and argument names are important to keep code readable to yourself, improve its future maintenance, and reduce the total bug count. You may write this Python function in a high level style like this: def is_palidrome(text): ltext = text.lower() return ltext == ltext[::-1] But that doesn't teach you much programming, so for learning purposes you may try to create one function in lower-level style (that also doesn't stress the garbage collector, despite probably being overall slower in Python). So we use iterative loops and single char tests. But if you use a language as Scheme then a recursive solution too is a normal option. Now you need to invent the algorithm that solves your problem. Inventing algorithms that solve your problems is an art that requires training, experience and even ideas from this little book: http://en.wikipedia.org/wiki/How_to_Solve_It There are few ways to solve that problem, one possible way it to look at the first and last char of the string (ignoring their case), if they are different the given word is not palindrome, otherwise you look at the second and penultimate char, and you perform similar comparisons for all the char pairs. If your string length is odd there is no need to test the last char, but if you want to test it with itself because it keeps the code simpler it's not a problem. To avoid bugs like ones in your code you may think about the loop invariant and loop variant. This blog post shows an example to follow: http://reprog.wordpress.com/2010/04/25/writing-correct-code-part-1-invariants-binary-search-part-4a/ I use two indexes, i and j, that move forward and backwards in sync starting from the first and last char of the 'text' string. The program stops when they are on the same char or they cross. I have used an elaborate loop invariant, for this simple program it's overkill, but shows how you may do it. i ==> <== j +--+--+--+--+--+--+--+--+--+ text | | | | | | | | | | +--+--+--+--+--+--+--+--+--+ 0 1 2 3 4 5 6 7 8 def _is_palindrome_loop_invariant(i, j, length): assert i >= 0 assert i < length assert j >= 0 assert j < length assert i <= j assert i == length - 1 - j return True def is_palindrome(text): """ >>> is_palindrome("") True >>> is_palindrome("1") True >>> is_palindrome(u"x") True >>> is_palindrome("aa") True >>> is_palindrome("ab") False >>> is_palindrome("abc") False >>> [is_palindrome(s) for s in ["abA", "ABA", "ABA"]] [True, True, True] >>> is_palindrome("aibohphobia") True >>> is_palindrome("aibohphobia" * 1000) True >>> is_palindrome(list("aibohphobia")) True >>> is_palindrome([1, 2, 3]) Traceback (most recent call last): ... AttributeError: 'int' object has no attribute 'lower' """ n = len(text) i = 0 j = n - 1 while i < j: assert _is_palindrome_loop_invariant(i, j, n) if text[i].lower() != text[j].lower(): return False else: i += 1 j -= 1 return True if __name__ == "__main__": import doctest doctest.testmod() print "Doctests done." is_palindrome([1, 2, 3]) fails not because the input is a list, but because integers lack the lower() method. It's useful to add few failing doctests too, to show what are the limits of the duck typing of the function. As you see I have tried some corner cases, empty string, single char, two chars, three chars, and more. I have also added a 'stress test' with a larger input. In Python this code is not efficient because of the interpreter overhead and because I call a lower() method on each char (string of length 1), so this is not good Python code. But it's easy to translate to a lower level language, and I think Psyco does a good enough work on it. In C language (plus stdbool) the tolower() is more efficient, but strlen() wastes some time. Often it's better to keep around the length too of your strings, for example using a "fat pointer", as in D. // C code //#define NDEBUG #include "assert.h" #include "stdio.h" #include "string.h" #include "stdbool.h" #include "ctype.h" #include "stdlib.h" bool is_palindrome_loop_invariant(int i, int j, int length) { assert(i >= 0); assert(i < length); assert(j >= 0); assert(j < length); assert(i <= j); assert(i == length - 1 - j); return true; } bool is_palindrome(const char *text) { const int n = strlen(text); int i = 0; int j = n - 1; while (i < j) { assert(is_palindrome_loop_invariant(i, j, n)); if (tolower(text[i]) != tolower(text[j])) { return false; } else { i++; j--; } } return true; } void is_palindrome_test() { assert(is_palindrome("")); assert(is_palindrome("1")); assert(is_palindrome("aa")); assert(!is_palindrome("ab")); assert(!is_palindrome("abc")); assert(is_palindrome("aba")); assert(is_palindrome("abA")); assert(is_palindrome("AbA")); assert(is_palindrome("ABA")); assert(is_palindrome("aibohphobia")); assert(!is_palindrome("aaaaabaaaa")); const int n = 1000; const char *s = "aibohphobia"; const int len_s = strlen(s); char *text = malloc(n * len_s + 1); if (text == NULL) exit(EXIT_FAILURE); int i; char *p = text; for (i = 0; i < n; i++) { memcpy(p, s, len_s); p += len_s; } text[n * len_s] = '\0'; // puts(text); assert(is_palindrome(text)); } int main() { is_palindrome_test(); return EXIT_SUCCESS; } C experts (or good C lints) are probably able to find some loss of precision or loss of sign errors in the following lines: const int n = strlen(text); const int len_s = strlen(s); char *text = malloc(n * len_s + 1); memcpy(p, s, len_s); Writing perfect C code isn't an easy art. (I have used signed values because writing correct C code with unsigned values is a pain, despite avoids loss of precision or sign). Compiling the C code with GCC 4.5.1, and disabled assertions (NDEBUG defined): -O3 -Wall -fomit-frame-pointer -S The loop of is_palindrome() gets compiled to (x86, 32 bit): L10: addl $1, %esi subl $1, %ebx cmpl %ebx, %esi jge L9 L4: movsbl (%edi,%esi), %eax movl %eax, (%esp) call _tolower movl %eax, %ebp movsbl (%edi,%ebx), %eax movl %eax, (%esp) call _tolower cmpl %eax, %ebp je L10 Those two calls to _tolower inside the loop don't help performance, but if you know your strings contain only upper case and lower case chars, and you are able to assume few other things on your machine, it's easy to replace them with non-portable inlined code. The addl and subl are the i++ and j--, GCC has moved them at top as commonly done optimization. The first cmpl is the (i < j) test, and the jge is a jump that ends the loop when it's the right time to do so. The movsbl go read one char, and put them in eax. The movl are necessary to set arguments for the call to the tolower function. The last cmpl compares the results of the tolower, and je (jump equal) jumps to the start of the loop if they are equal. Bye, bearophile From paul.hermeneutic at gmail.com Tue Sep 14 22:50:04 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Tue, 14 Sep 2010 20:50:04 -0600 Subject: distutils, cygwin, 'not a regular file' Message-ID: <8faqj0FnoeU1@mid.individual.net> So, what is not a regular file about this? Is there any way to find out which files are being considered irregular? $ uname -a CYGWIN_NT-6.0-WOW64 pwatson 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin $ cat setup.py from distutils.core import setup setup( name='xlsexport', version='0.3', py_modules=['xlsexport'] ) 20:47 pwatson [ pwatson:/cygdrive/c/Users/pwatson/bin/xlsexport] 12 $ python setup.py sdist running sdist warning: sdist: missing required meta-data: url warning: sdist: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied reading manifest file 'MANIFEST' creating xlsexport-0.3 making hard links in xlsexport-0.3... ' not a regular file -- skipping ' not a regular file -- skipping ' not a regular file -- skipping tar -cf dist/xlsexport-0.3.tar xlsexport-0.3 gzip -f9 dist/xlsexport-0.3.tar removing 'xlsexport-0.3' (and everything under it) From justlooks at gmail.com Tue Sep 14 23:03:40 2010 From: justlooks at gmail.com (ch huang) Date: Wed, 15 Sep 2010 11:03:40 +0800 Subject: can not import hashlib Message-ID: i have a big problem,here is and any can help me? Python 2.6.5 (r265:79063, Apr 1 2010, 05:22:20) [GCC 4.4.3 20100316 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/hashlib.py", line 136, in md5 = __get_builtin_constructor('md5') File "/usr/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor import _md5 ImportError: No module named _md5 -------------- next part -------------- An HTML attachment was scrubbed... URL: From eliben at gmail.com Wed Sep 15 01:31:31 2010 From: eliben at gmail.com (Eli Bendersky) Date: Wed, 15 Sep 2010 07:31:31 +0200 Subject: Bit fields in python? In-Reply-To: <993B42015FA04D5D973F1870E384AAB5@cs0403293> References: <993B42015FA04D5D973F1870E384AAB5@cs0403293> Message-ID: > Hi, > > I'm trying to use the construct library, but encountered a problem. May I > know how do I implement the following using the construct library? > > typedef struct > { > unsigned short size; > . > . > }CodecInfo; > > typedef struct > { > unsigned short size; > CodecInfo mastercodec; > CodecInfo slavecodec; > }StatusInfo; > > StatusInfo t; > printf("%hu %hu\n", t.mastercodec.size,t.slavecodec.size); > > Not sure how to include 2 copies of the CodecInfo Struct into StatusInfo > Struct & be able to access CodecInfo's fields like the example above: > > CodecInfo = Struct("CodecInfo", > . > . > . > ) > > StatusInfo = Struct("StatusInfo", > CodecInfo, > CodecInfo > ) > > Status = StatusInfo.parse(buf) > > You can just nest Struct objects. Here's one implementation of what you're looking for: from construct import * def make_codec_info(name): return Struct(name, ULInt16('size')) StatusInfo = Struct('StatusInfo', ULInt16('size'), make_codec_info('mastercodec'), make_codec_info('slavecodec'), ) c = StatusInfo.parse('\x12\x13\x01\x02\x03\x04') print c P.S. It is covered in the first part of construct's tutorial ( http://construct.wikispaces.com/tut-basics). The tutorial is a pretty good starting point for using construct. Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From zhxia at njnet.edu.cn Wed Sep 15 01:36:40 2010 From: zhxia at njnet.edu.cn (Xia, Zhen) Date: Wed, 15 Sep 2010 13:36:40 +0800 Subject: can not import hashlib In-Reply-To: References: Message-ID: <20100915133640.759c0be0.zhxia@njnet.edu.cn> Your python is compiled without md5. Maybe your system misses some libraries and you have to re-compile the python. On Wed, 15 Sep 2010 11:03:40 +0800 ch huang wrote: > i have a big problem,here is > and any can help me? > > Python 2.6.5 (r265:79063, Apr 1 2010, 05:22:20) > [GCC 4.4.3 20100316 (prerelease)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import hashlib > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/hashlib.py", line 136, in > md5 = __get_builtin_constructor('md5') > File "/usr/lib/python2.6/hashlib.py", line 63, in > __get_builtin_constructor > import _md5 > ImportError: No module named _md5 > From vontio at gmail.com Wed Sep 15 02:13:42 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 14:13:42 +0800 Subject: python call a procedure at the specified time Message-ID: Hi, I have a python script running behind the scene,and I need it to call a method on sunday 9 o'clock. I get an idea,that I get the current time,and calculate the seconds to sunday 9 o'clock, then sleep these seconds and call my method,I think there could be an elegant way to resolve this. Regards, -------------- next part -------------- An HTML attachment was scrubbed... URL: From nitinpawar432 at gmail.com Wed Sep 15 02:15:15 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Wed, 15 Sep 2010 11:45:15 +0530 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: are you looking for something like cron? On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: > Hi, > I have a python script running behind the scene,and I need it to call a > method on sunday 9 o'clock. > I get an idea,that I get the current time,and calculate the seconds to > sunday 9 o'clock, > then sleep these seconds and call my method,I think there could be an > elegant way to resolve this. > > Regards, > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From vontio at gmail.com Wed Sep 15 02:24:39 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 14:24:39 +0800 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: Hi Nitin,I need a python solution for that. On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: > are you looking for something like cron? > > On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: > >> Hi, >> I have a python script running behind the scene,and I need it to call a >> method on sunday 9 o'clock. >> I get an idea,that I get the current time,and calculate the seconds to >> sunday 9 o'clock, >> then sleep these seconds and call my method,I think there could be an >> elegant way to resolve this. >> >> Regards, >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Nitin Pawar > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nitinpawar432 at gmail.com Wed Sep 15 02:35:29 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Wed, 15 Sep 2010 12:05:29 +0530 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: I think to do so either you will need to schedule a cron or write a daemon process which will run continuously. Assuming that its running only once a day or say timely manner daemon will be a costly affair for system resources To schedule crons for python, this might be useful (using yaml) http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml Thanks, Nitin On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: > Hi Nitin,I need a python solution for that. > > > On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: > >> are you looking for something like cron? >> >> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >> >>> Hi, >>> I have a python script running behind the scene,and I need it to call a >>> method on sunday 9 o'clock. >>> I get an idea,that I get the current time,and calculate the seconds to >>> sunday 9 o'clock, >>> then sleep these seconds and call my method,I think there could be an >>> elegant way to resolve this. >>> >>> Regards, >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> >> -- >> Nitin Pawar >> >> > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Sep 15 02:38:40 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Sep 2010 08:38:40 +0200 Subject: String formatting with the format string syntax References: Message-ID: Andre Alexander Bell wrote: > On 09/14/2010 08:20 PM, Miki wrote: >> You can use ** syntax: >>>>> english = {'hello':'hello'} >>>>> s.format(**english) > > Thanks for your answer. Actually your answer tells me that my example > was misleading. Consider the template > > s = 'A template with {variable1} and {variable2} placeholders.' > > I'm seeking a way to extract the named placesholders, i.e. the names > 'variable1' and 'variable2' from the template. I'm not trying to put in > values for them. > > I hope this is clearer. >>> s = 'A template with {variable1} and {variable2} placeholders.' >>> [name for _, name, _, _ in s._formatter_parser() if name is not None] ['variable1', 'variable2'] Peter From kristian.nissen at gmail.com Wed Sep 15 03:22:16 2010 From: kristian.nissen at gmail.com (kristiannissen) Date: Wed, 15 Sep 2010 00:22:16 -0700 (PDT) Subject: google app engine _method? put(self): Message-ID: <006e5cdb-5654-4073-b728-2be9d0cf7be3@u13g2000vbo.googlegroups.com> How can I get the request passed on to my views when using this middleware? class RestHTTPMiddleware(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): request = Request(environ) body = StringIO.StringIO(request.body) method = webapp.Request(environ).get('_method', None) if method: environ['REQUEST_METHOD'] = method.upper() environ['wsgi.input'] = body return self.app(environ, start_response) when i test : class Spot(webapp.RequestHandler): def put(self): logging.info("hello from put %s", self.request.get("author")) the following is logged: "spot put" but with no value. This is how it's implemented: def main(): app = webapp.WSGIApplication([ (r'/spot/new/$', Spot), ], debug=True) # run_wsgi_app(application) wsgiref.handlers.CGIHandler().run(RestHTTPMiddleware(app)) and this is the form:
From vontio at gmail.com Wed Sep 15 03:25:32 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 15:25:32 +0800 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: Thanks Nitin,I wonder how cron works,does it create a timer thread for each task? On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: > I think to do so either you will need to schedule a cron or write a daemon > process which will run continuously. > Assuming that its running only once a day or say timely manner daemon will > be a costly affair for system resources > > To schedule crons for python, this might be useful (using yaml) > > http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml > > Thanks, > Nitin > > > On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: > >> Hi Nitin,I need a python solution for that. >> >> >> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >> >>> are you looking for something like cron? >>> >>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>> >>>> Hi, >>>> I have a python script running behind the scene,and I need it to call a >>>> method on sunday 9 o'clock. >>>> I get an idea,that I get the current time,and calculate the seconds to >>>> sunday 9 o'clock, >>>> then sleep these seconds and call my method,I think there could be an >>>> elegant way to resolve this. >>>> >>>> Regards, >>>> >>>> -- >>>> http://mail.python.org/mailman/listinfo/python-list >>>> >>>> >>> >>> >>> -- >>> Nitin Pawar >>> >>> >> > > > -- > Nitin Pawar > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vontio at gmail.com Wed Sep 15 03:35:26 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 15:35:26 +0800 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: I have read the cron man page just now,It says that cron wakes up every minute to check task. I will try install/uninstall with cron. Cheers, On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: > Thanks Nitin,I wonder how cron works,does it create a timer thread for each > task? > > > On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: > >> I think to do so either you will need to schedule a cron or write a daemon >> process which will run continuously. >> Assuming that its running only once a day or say timely manner daemon will >> be a costly affair for system resources >> >> To schedule crons for python, this might be useful (using yaml) >> >> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >> >> Thanks, >> Nitin >> >> >> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >> >>> Hi Nitin,I need a python solution for that. >>> >>> >>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >>> >>>> are you looking for something like cron? >>>> >>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>> >>>>> Hi, >>>>> I have a python script running behind the scene,and I need it to call a >>>>> method on sunday 9 o'clock. >>>>> I get an idea,that I get the current time,and calculate the seconds to >>>>> sunday 9 o'clock, >>>>> then sleep these seconds and call my method,I think there could be an >>>>> elegant way to resolve this. >>>>> >>>>> Regards, >>>>> >>>>> -- >>>>> http://mail.python.org/mailman/listinfo/python-list >>>>> >>>>> >>>> >>>> >>>> -- >>>> Nitin Pawar >>>> >>>> >>> >> >> >> -- >> Nitin Pawar >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nitinpawar432 at gmail.com Wed Sep 15 03:44:08 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Wed, 15 Sep 2010 13:14:08 +0530 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: cron is daemon running which maps the tasks with the frequency if you want to run a task at a specific time, you can schedule it for the same if you need any help, ping on gtalk, can help you out Thanks, Nitin On Wed, Sep 15, 2010 at 1:05 PM, Von wrote: > I have read the cron man page just now,It says that cron wakes up every > minute to check task. > I will try install/uninstall with cron. > > Cheers, > > > On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: > >> Thanks Nitin,I wonder how cron works,does it create a timer thread for >> each task? >> >> >> On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: >> >>> I think to do so either you will need to schedule a cron or write a >>> daemon process which will run continuously. >>> Assuming that its running only once a day or say timely manner daemon >>> will be a costly affair for system resources >>> >>> To schedule crons for python, this might be useful (using yaml) >>> >>> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >>> >>> Thanks, >>> Nitin >>> >>> >>> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >>> >>>> Hi Nitin,I need a python solution for that. >>>> >>>> >>>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >>>> >>>>> are you looking for something like cron? >>>>> >>>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>>> >>>>>> Hi, >>>>>> I have a python script running behind the scene,and I need it to call >>>>>> a method on sunday 9 o'clock. >>>>>> I get an idea,that I get the current time,and calculate the seconds to >>>>>> sunday 9 o'clock, >>>>>> then sleep these seconds and call my method,I think there could be an >>>>>> elegant way to resolve this. >>>>>> >>>>>> Regards, >>>>>> >>>>>> -- >>>>>> http://mail.python.org/mailman/listinfo/python-list >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Nitin Pawar >>>>> >>>>> >>>> >>> >>> >>> -- >>> Nitin Pawar >>> >>> >> > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Sep 15 04:00:45 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Sep 2010 10:00:45 +0200 Subject: String formatting with the format string syntax References: Message-ID: Peter Otten wrote: > Andre Alexander Bell wrote: > >> On 09/14/2010 08:20 PM, Miki wrote: >>> You can use ** syntax: >>>>>> english = {'hello':'hello'} >>>>>> s.format(**english) >> >> Thanks for your answer. Actually your answer tells me that my example >> was misleading. Consider the template >> >> s = 'A template with {variable1} and {variable2} placeholders.' >> >> I'm seeking a way to extract the named placesholders, i.e. the names >> 'variable1' and 'variable2' from the template. I'm not trying to put in >> values for them. >> >> I hope this is clearer. > >>>> s = 'A template with {variable1} and {variable2} placeholders.' >>>> [name for _, name, _, _ in s._formatter_parser() if name is not None] > ['variable1', 'variable2'] Caveat: the format spec may contain names, too. Here's an attempt to take that into account: def extract_names(t, recurse=1): for _, name, fmt, _ in t._formatter_parser(): if name is not None: yield name if recurse and fmt is not None: for name in extract_names(fmt, recurse-1): yield name t = "before {one:{two}{three}} after" print(t) for name in extract_names(t): print(name) >>> list(extract_names("{one:{two}{three}}")) ['one', 'two', 'three'] Don't expect correct results for illegal formats: >>> list(extract_names("{one:{two:{three}}}")) ['one', 'two'] >>> "{one:{two:{three}}}".format(one=1, two=2, three=3) Traceback (most recent call last): File "", line 1, in ValueError: Max string recursion exceeded Duplicate names may occur: >>> list(extract_names("{one} {one} {one}")) ['one', 'one', 'one'] Positional arguments are treated like names: >>> list(extract_names("{0} {1} {0}")) ['0', '1', '0'] >>> list(extract_names("{} {} {}")) ['', '', ''] Peter From post at andre-bell.de Wed Sep 15 04:13:54 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Wed, 15 Sep 2010 10:13:54 +0200 Subject: String formatting with the format string syntax In-Reply-To: References: Message-ID: <4C908042.8020708@andre-bell.de> On 09/15/2010 10:00 AM, Peter Otten wrote: > def extract_names(t, recurse=1): > for _, name, fmt, _ in t._formatter_parser(): > if name is not None: > yield name > if recurse and fmt is not None: > for name in extract_names(fmt, recurse-1): > yield name Thanks Peter, I very much like this generator solution. It will work for all situations I can currently think of. However, one thing remains. It is based on the _format_parser method. And as I wrote in my original post this one - since it starts with _ - suggests to me to better not be used. So if using this method is completely ok, why does it start with _, why is it almost undocumented? Or did I miss something, some docs somewhere? Best regards Andre From __peter__ at web.de Wed Sep 15 04:48:35 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Sep 2010 10:48:35 +0200 Subject: String formatting with the format string syntax References: Message-ID: Andre Alexander Bell wrote: > On 09/15/2010 10:00 AM, Peter Otten wrote: >> def extract_names(t, recurse=1): >> for _, name, fmt, _ in t._formatter_parser(): >> if name is not None: >> yield name >> if recurse and fmt is not None: >> for name in extract_names(fmt, recurse-1): >> yield name > > Thanks Peter, I very much like this generator solution. It will work for > all situations I can currently think of. > > However, one thing remains. It is based on the _format_parser method. > And as I wrote in my original post this one - since it starts with _ - > suggests to me to better not be used. So if using this method is > completely ok, why does it start with _, why is it almost undocumented? > Or did I miss something, some docs somewhere? Sorry, I really should have read your original post carefully/completely. It would have spared me from finding _formatter_parser() independently... I personally would not be too concerned about the leading underscore, but you can use string.Formatter().parse(template) instead. Peter From mummerx at gmail.com Wed Sep 15 04:51:30 2010 From: mummerx at gmail.com (Douglas) Date: Wed, 15 Sep 2010 01:51:30 -0700 (PDT) Subject: Accessing windoze file attributes Message-ID: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Environment: X86, 1Gb RAM, Win XP, latest SP, Excel 2003. Hi, can anyone direct a relative newbie to the best source of info? I am writing my own backup app in Python 2.5.2 (all my company will allow me to use) using IDLE. I intend to run this app daily via the Task Scheduler to back up a mission-critical spreadsheet that only I use. It works well enough, but now I want to make it sensitive to the "A" attribute (only backup the file if it is set), and update it afterwards (unset it). This will help me avoid wasted disk due to needless backups. I have searched the inter-web and not found any info on how to do access/alter Windows file attributes. Please can someone direct me to a web page with suitable info (preferably with code snyppyts)? Many thanks, in advance. -- Douglas From dmitrey.kroshko at scipy.org Wed Sep 15 05:11:39 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Wed, 15 Sep 2010 02:11:39 -0700 (PDT) Subject: ANN: OpenOpt 0.31, FuncDesigner 0.21, DerApproximator 0.21 Message-ID: Hi all, I'm glad to inform you about new releases of our completely free (BSD license) cross-platform software, written using Python language and NumPy: OpenOpt 0.31 (numerical optimization), FuncDesigner 0.21 (automatic differentiation, modelling, interpolation, integration), DerApproximator 0.21 (finite-differences derivatives approximation). For release details see http://forum.openopt.org/viewtopic.php?id=299 or visit our homepage http://openopt.org Regards, Dmitrey From email at spam.la Wed Sep 15 05:40:58 2010 From: email at spam.la (http://thisisvegas.com/get/a/179639) Date: Wed, 15 Sep 2010 02:40:58 -0700 Subject: This is Vegas - Get $2400 Free Message-ID: This is Vegas - Get $2400 Free http://thisisvegas.com/get/a/179639 Click here to download over 400 Free Games http://thisisvegas.com/get/wd/206052 From vontio at gmail.com Wed Sep 15 06:22:23 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 18:22:23 +0800 Subject: python cxfreeze package pyqt app lost icon and tray icon Message-ID: Hi, Here is my command: cxfreeze --target-dir=AutoOrder gui.py --base-name=D:\Python31\Lib\site-packages\cx_Freeze\bases\Win32GUI.exe --include-path=. -z icon.jpg Both app icon and tray icon used icon.jpg Regards, -------------- next part -------------- An HTML attachment was scrubbed... URL: From post at andre-bell.de Wed Sep 15 06:35:23 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Wed, 15 Sep 2010 12:35:23 +0200 Subject: String formatting with the format string syntax In-Reply-To: References: Message-ID: <4C90A16B.8040804@andre-bell.de> On 09/15/2010 10:48 AM, Peter Otten wrote: > I personally would not be too concerned about the leading underscore, but > you can use > > string.Formatter().parse(template) > > instead. Thanks for this pointer. I like it this way. So if I now combine your generator with your suggestion, I end up with something like this: def extract_names(t, recurse=1): import string for _, name, fmt, _ in string.Formatter().parse(t): if name is not None: yield name if recurse and fmt is not None: for name in extract_names(fmt, recurse-1): yield name Pretty cool. Thanks a lot. Andre From k.sahithi2862 at gmail.com Wed Sep 15 06:37:51 2010 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 15 Sep 2010 03:37:51 -0700 (PDT) Subject: XXX HOT PHOTOS&VIDEOS Message-ID: <390e4289-ab6f-4851-ac72-aa46482099dc@b4g2000pra.googlegroups.com> FOR HOT SEXY PHOTOS&VIDEOS [EXPOSING PHOTO] http://hotheroinesphotos.blogspot.com/2010/09/exposing-photo.html FOR HOT VIDEOS WITH SEXY PHOTO http://hotheroinesphotos.blogspot.com/2010/09/kangana-in-sexy-feel.html HOT MALLU AUNTY http://hotheroinesphotos.blogspot.com/2010/09/mallu-aunty.html LASYA HOT SEXY PHOTO http://hotheroinesphotos.blogspot.com/2010/09/sexy-lasya.html CHARMI HOT BOOBS SHOW http://hotheroinesphotos.blogspot.com/2010/09/charmi-boobs-show.html HOT MALLU AUNTY http://hotheroinesphotos.blogspot.com/2010/09/mallu-special.html SNEHA IN A BIKINI http://hotheroinesphotos.blogspot.com/2010/09/sneha-in-bikini.html From lallous at lgwm.org Wed Sep 15 06:38:39 2010 From: lallous at lgwm.org (lallous) Date: Wed, 15 Sep 2010 03:38:39 -0700 (PDT) Subject: help with calling a static method in a private class References: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> <87r5gwgzk5.fsf@web.de> Message-ID: <293456d9-ecbe-4300-b938-725b11e299c2@q9g2000vbd.googlegroups.com> On Sep 14, 4:38?pm, de... at web.de (Diez B. Roggisch) wrote: > lallous writes: > > How can I keep the class private and have the following work: > > > [code] > > class __internal_class(object): > > ? ? @staticmethod > > ? ? def meth1(s): > > ? ? ? ? print "meth1:", s > > > ? ? @staticmethod > > ? ? def meth2(s): > > ? ? ? ? print "meth2:", > > ? ? ? ? __internal_class.meth1(s) > > > x = __internal_class() > > > x.meth2('sdf') > > [/code] > > By not using a double underscore. It is effectless on classes anyway > (they are not hidden because of that). > > And additionally, but simply not using staticmethods at all. It's a > rather obscure feature ofpython- usually, classmethods are what is > considered a static method in other languages. And with that, even your > double underscores work: > > class __internal_class(object): > ? ? @classmethod > ? ? def meth1(cls, s): > ? ? ? ? print "meth1:", s > > ? ? @classmethod > ? ? def meth2(cls, s): > ? ? ? ? print "meth2:", > ? ? ? ? cls.meth1(s) > > x = __internal_class() > > x.meth2('sdf') > > Diez Thanks, that does the trick. From vontio at gmail.com Wed Sep 15 06:53:57 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 18:53:57 +0800 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: I used timer way,and I found that threading.Timer didn't work with PyQt,so I used QTimer instead,and it did work. On Wed, Sep 15, 2010 at 3:44 PM, Nitin Pawar wrote: > cron is daemon running which maps the tasks with the frequency > > if you want to run a task at a specific time, you can schedule it for the > same > > if you need any help, ping on gtalk, can help you out > > Thanks, > Nitin > > On Wed, Sep 15, 2010 at 1:05 PM, Von wrote: > >> I have read the cron man page just now,It says that cron wakes up every >> minute to check task. >> I will try install/uninstall with cron. >> >> Cheers, >> >> >> On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: >> >>> Thanks Nitin,I wonder how cron works,does it create a timer thread for >>> each task? >>> >>> >>> On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: >>> >>>> I think to do so either you will need to schedule a cron or write a >>>> daemon process which will run continuously. >>>> Assuming that its running only once a day or say timely manner daemon >>>> will be a costly affair for system resources >>>> >>>> To schedule crons for python, this might be useful (using yaml) >>>> >>>> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >>>> >>>> Thanks, >>>> Nitin >>>> >>>> >>>> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >>>> >>>>> Hi Nitin,I need a python solution for that. >>>>> >>>>> >>>>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >>>>> >>>>>> are you looking for something like cron? >>>>>> >>>>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>>>> >>>>>>> Hi, >>>>>>> I have a python script running behind the scene,and I need it to call >>>>>>> a method on sunday 9 o'clock. >>>>>>> I get an idea,that I get the current time,and calculate the seconds >>>>>>> to sunday 9 o'clock, >>>>>>> then sleep these seconds and call my method,I think there could be >>>>>>> an elegant way to resolve this. >>>>>>> >>>>>>> Regards, >>>>>>> >>>>>>> -- >>>>>>> http://mail.python.org/mailman/listinfo/python-list >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Nitin Pawar >>>>>> >>>>>> >>>>> >>>> >>>> >>>> -- >>>> Nitin Pawar >>>> >>>> >>> >> > > > -- > Nitin Pawar > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at web.de Wed Sep 15 07:28:32 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 15 Sep 2010 13:28:32 +0200 Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: <87mxrjgs9r.fsf@web.de> Douglas writes: > Hi, can anyone direct a relative newbie to the best source of info? > I am writing my own backup app in Python 2.5.2 (all my company will > allow me to use) using IDLE. > I intend to run this app daily via the Task Scheduler to back up a > mission-critical spreadsheet that only I use. > It works well enough, but now I want to make it sensitive to the "A" > attribute (only backup the file if it is set), and update it > afterwards (unset it). This will help me avoid wasted disk due to > needless backups. > I have searched the inter-web and not found any info on how to do > access/alter Windows file attributes. > Please can someone direct me to a web page with suitable info > (preferably with code snyppyts)? No windows nowhere here, but os.stat should be your friend. Diez From drobinow at gmail.com Wed Sep 15 07:45:08 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 15 Sep 2010 07:45:08 -0400 Subject: Accessing windoze file attributes In-Reply-To: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: On Wed, Sep 15, 2010 at 4:51 AM, Douglas wrote: > Environment: X86, 1Gb RAM, Win XP, latest SP, Excel 2003. > > Hi, can anyone direct a relative newbie to the best source of info? > I am writing my own backup app in Python 2.5.2 (all my company will > allow me to use) using IDLE. > I intend to run this app daily via the Task Scheduler to back up a > mission-critical spreadsheet that only I use. > It works well enough, but now I want to make it sensitive to the "A" > attribute (only backup the file if it is set), and update it > afterwards (unset it). This will help me avoid wasted disk due to > needless backups. > I have searched the inter-web and not found any info on how to do > access/alter Windows file attributes. > Please can someone direct me to a web page with suitable info > (preferably with code snyppyts)? http://code.activestate.com/recipes/303343-changing-file-attributes-on-windows/ From ldo at geek-central.gen.new_zealand Wed Sep 15 08:32:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 16 Sep 2010 00:32:45 +1200 Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: In message <8dc0fa8e-f0e6-4603-9283-186551597e8d at a19g2000vbi.googlegroups.com>, Douglas wrote: > It works well enough, but now I want to make it sensitive to the "A" > attribute (only backup the file if it is set), and update it > afterwards (unset it). This will help me avoid wasted disk due to > needless backups. Why reinvent rsync? From lanyjie at yahoo.com Wed Sep 15 08:34:06 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 15 Sep 2010 05:34:06 -0700 (PDT) Subject: 3>0 is True Message-ID: <602031.32211.qm@web54205.mail.re2.yahoo.com> Hi, I am not sure how to interprete this, in the interactive mode: >>> 3>0 is True False >>> (3>0) is True True >>> 3> (0 is True) True Why did I get the first 'False'? I'm a little confused. Thanks in advance for anybody who shed some light on this. YL From ldo at geek-central.gen.new_zealand Wed Sep 15 08:34:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 16 Sep 2010 00:34:22 +1200 Subject: distutils, cygwin, 'not a regular file' References: <8faqj0FnoeU1@mid.individual.net> Message-ID: In message <8faqj0FnoeU1 at mid.individual.net>, Paul Watson wrote: > ' not a regular file -- skipping > ' not a regular file -- skipping > ' not a regular file -- skipping Just a guess, is the file it?s complaining about named ?'?? From __peter__ at web.de Wed Sep 15 08:46:07 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Sep 2010 14:46:07 +0200 Subject: 3>0 is True References: Message-ID: Yingjie Lan wrote: > I am not sure how to interprete this, in the interactive mode: > >>>> 3>0 is True > False >>>> (3>0) is True > True >>>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. http://docs.python.org/reference/expressions.html#notin """ Unlike C, all comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation. Also unlike C, expressions like a < b < c have the interpretation that is conventional in mathematics: comparison ::= or_expr ( comp_operator or_expr )* comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | "!=" | "is" ["not"] | ["not"] "in" Comparisons yield boolean values: True or False. Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false). """ Peter From jpiitula at ling.helsinki.fi Wed Sep 15 08:47:04 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 15 Sep 2010 15:47:04 +0300 Subject: 3>0 is True References: Message-ID: Yingjie Lan writes: > I am not sure how to interprete this, in the interactive mode: > > >>> 3>0 is True > False > >>> (3>0) is True > True > >>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. It is interpreted as equivalent to this: >>> 3 > 0 and 0 is True False >From the language reference at python.org (section 5.9 Comparisons): expressions like a < b < c have the interpretation that is conventional in mathematics ... Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false). From michael.ricordeau at gmail.com Wed Sep 15 08:47:11 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Wed, 15 Sep 2010 14:47:11 +0200 Subject: 3>0 is True In-Reply-To: <602031.32211.qm@web54205.mail.re2.yahoo.com> References: <602031.32211.qm@web54205.mail.re2.yahoo.com> Message-ID: <20100915144711.601e57da@moriz.interne> Because "is" operator take precedence on ">" operator . Le Wed, 15 Sep 2010 05:34:06 -0700 (PDT), Yingjie Lan a ?crit : > Hi, > > I am not sure how to interprete this, in the interactive mode: > > >>> 3>0 is True > False > >>> (3>0) is True > True > >>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. > > Thanks in advance for anybody who shed some light on this. > > YL > > > From mwilson at the-wire.com Wed Sep 15 08:57:13 2010 From: mwilson at the-wire.com (Mel) Date: Wed, 15 Sep 2010 08:57:13 -0400 Subject: 3>0 is True References: Message-ID: Yingjie Lan wrote: > I am not sure how to interprete this, in the interactive mode: > >>>> 3>0 is True > False >>>> (3>0) is True > True >>>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. > > Thanks in advance for anybody who shed some light on this. This looks like comparison chaining. `is` is a comparison operator, like `>`, and chains of comparisons are handled differently. `a < b < c` is equivalent to `(a < b) and (b < c)` Therefore the first expression is testing (3 > 0) and (0 is True) Mel. From michael.ricordeau at gmail.com Wed Sep 15 09:03:31 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Wed, 15 Sep 2010 15:03:31 +0200 Subject: 3>0 is True In-Reply-To: <20100915144711.601e57da@moriz.interne> References: <602031.32211.qm@web54205.mail.re2.yahoo.com> <20100915144711.601e57da@moriz.interne> Message-ID: <20100915150331.17a5b528@moriz.interne> Not really true for ">" and "is" : http://docs.python.org/reference/expressions.html#evaluation-order Operator ">" and operator "is" are in the same precedence but in group Comparisons : "Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right ? see section Comparisons" The important words here are : "all have the SAME PRECEDENCE and chain from left to right" See also : http://docs.python.org/reference/expressions.html#comparisons So for : >>> 3 > 0 is True #first evaluation is : >>> 3 > 0 ---> True #second evaluation is : >>> 0 is True ---> False (and second evaluation is not result of first one !) Le Wed, 15 Sep 2010 14:47:11 +0200, Michael Ricordeau a ?crit : > Because "is" operator take precedence on ">" operator . > > Le Wed, 15 Sep 2010 05:34:06 -0700 (PDT), > Yingjie Lan a ?crit : > > > Hi, > > > > I am not sure how to interprete this, in the interactive mode: > > > > >>> 3>0 is True > > False > > >>> (3>0) is True > > True > > >>> 3> (0 is True) > > True > > > > Why did I get the first 'False'? I'm a little confused. > > > > Thanks in advance for anybody who shed some light on this. > > > > YL > > > > > > From js at corefiling.co.uk Wed Sep 15 09:04:24 2010 From: js at corefiling.co.uk (Jon Siddle) Date: Wed, 15 Sep 2010 14:04:24 +0100 Subject: 3>0 is True In-Reply-To: <602031.32211.qm@web54205.mail.re2.yahoo.com> References: <602031.32211.qm@web54205.mail.re2.yahoo.com> Message-ID: <4C90C458.2080103@corefiling.co.uk> As others have said, it's not a matter of precendence. Using the compiler module you can see how python actually parses this: 3 > (0 is True) Compare(Const(3), [('>', Compare(Const(0), [('is', Name('True'))]))]) No great surprise there. 3 > 0 is True Compare(Const(3), [('>', Const(0)), ('is', Name('True'))]) As you can see, it's not the same. Two comparisons are being done "at once", not one comparison on the result of another. Hope this helps On 15/09/10 13:34, Yingjie Lan wrote: > Hi, > > I am not sure how to interprete this, in the interactive mode: > >>>> 3>0 is True > False >>>> (3>0) is True > True >>>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. > > Thanks in advance for anybody who shed some light on this. > > YL > > > -- Jon Siddle, CoreFiling Limited Software Tools Developer http://www.corefiling.com Phone: +44-1865-203192 From lanyjie at yahoo.com Wed Sep 15 09:33:57 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 15 Sep 2010 06:33:57 -0700 (PDT) Subject: 3>0 is True In-Reply-To: <4C90C458.2080103@corefiling.co.uk> Message-ID: <369612.86166.qm@web54203.mail.re2.yahoo.com> > From: Jon Siddle > Subject: Re: 3>0 is True > To: python-list at python.org > Date: Wednesday, September 15, 2010, 5:04 PM > ? As others have said, it's not > a matter of precendence. Using the > compiler module > you can see how python actually parses this: > > 3 > (0 is True) > Compare(Const(3), [('>', Compare(Const(0), [('is', > Name('True'))]))]) > > No great surprise there. > > 3 > 0 is True > Compare(Const(3), [('>', Const(0)), ('is', > Name('True'))]) > > As you can see, it's not the same. Two comparisons are > being done "at > once", not > one comparison on the result of another. > > Hope this helps Thank you all for nailing down this itching issue for me! All I can say is: Wow! You all have a teribly nice day! Yingjie From chris at simplistix.co.uk Wed Sep 15 09:49:09 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 15 Sep 2010 14:49:09 +0100 Subject: os.path.normcase rationale? Message-ID: <4C90CED5.8050005@simplistix.co.uk> Hi All, I'm curious as to why, with a file called "Foo.txt" os.path.normcase('FoO.txt') will return "foo.txt" rather than "Foo.txt"? Yes, I know the behaviour is documented, but I'm wondering if anyone can remember the rationale for that behaviour? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From pruebauno at latinmail.com Wed Sep 15 09:54:31 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 15 Sep 2010 06:54:31 -0700 (PDT) Subject: business date and calendar libraries? References: <4C8E59FA.3060508@simplistix.co.uk> Message-ID: <26d4ebce-33a6-4715-81ad-fb2a0422a8f8@g18g2000vbn.googlegroups.com> On Sep 13, 3:02?pm, David Robinow wrote: > On Mon, Sep 13, 2010 at 1:06 PM, Chris Withers wrote: > > I'm wondering what libraries people would use to answer the following > > questions relating to business days: > > > - on a less-naive level; same question but taking into account public > > holidays > > ?This depends on which government is oppressing you. > > > - on a horrific level; same question, but taking into account business days > > of a particular market (NYSE, LSE, etc) > > ?This is just an instance of the public holiday case. You need to > define the holidays. > ?If you read lisp you might want to look at the emacs calendar module > for some hints on how they describe holidays, such as, for a US-biased > example, ?Martin Luther King day is the third Monday in January, > Memorial Day is the last Monday in May, Good Friday is not a public > holiday but some markets are closed. A good way to do this IMHO is to keep a list of "holidays" for each year in your program and check if a day is in the list to do your calculations. The list could be automatically generated by an algorithm that figures out all the weird holiday dates or -as is done in many companies- some honcho adds them according to his preference to a database. From cjwilliams43 at gmail.com Wed Sep 15 12:36:16 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Wed, 15 Sep 2010 12:36:16 -0400 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: <8fag9dF4mtU1@mid.individual.net> References: <8fag9dF4mtU1@mid.individual.net> Message-ID: On 14-Sep-10 19:54 PM, Gregory Ewing wrote: > Suppose I have two N+2 dimensional arrays, representing > N-d arrays of 2-d matrices. I want to perform matrix > multiplication between corresponding matrices in these > arrays. > > I had thought that dot() might do this, but it appears > not, because e.g. applying it to two 3-d arrays gives > a 4-d array, not another 3-d array. > > I'd also like to be able to find the inverse of each > matrix in one of these arrays, but again, inv() doesn't > do what I want -- it only works on 2-d arrays. > > Any thoughts on how to achieve these things using numpy > functions? > There is a Matrix sub-class which permit you to do that sort of thimg. Colin W. From andrewt.herd at gmail.com Wed Sep 15 12:53:50 2010 From: andrewt.herd at gmail.com (Andrew) Date: Wed, 15 Sep 2010 09:53:50 -0700 (PDT) Subject: Deleting widgets from PyQt4 QFormWidget Message-ID: I'm trying to remove the widgets from the QFormLayout widget from PyQt4. According to the documentation I should be able to use the command .takeAt(int) which will delete the widget from the layout and then return to me the QLayoutWidget. It currently is giving me back the widget, but is not removing it from the layout. At the moment, I'm simply trying to clear out all the widgets on the layout with this: def clearForm(self): print ("Clearing") print self.dataForm.rowCount() for i in range(self.dataForm.rowCount()-1, -1, -1): print " .", tmp = self.dataForm.takeAt(i) print tmp.widget() tmp = "" print self.dataForm.rowCount() It goes through each widget on the layout, and prints out the classes .__repr__ on the tmp.widget() line since tmp is a QLayoutWidget. So it's doing the returning part, but they still exist instead of being deleted like the documentation explains. Am I missing a step or is this just broken? I haven't been able to find anything else on this issue yet. If it's broke, is there any potential workaround? I'm using python 2.6.4 and PyQt4 4.7.6 Thanks, Andrew From andrewt.herd at gmail.com Wed Sep 15 13:10:11 2010 From: andrewt.herd at gmail.com (Andrew) Date: Wed, 15 Sep 2010 10:10:11 -0700 (PDT) Subject: Deleting widgets from PyQt4 QFormWidget References: Message-ID: <25e05bac-f0b8-40d9-a632-1b471a210c10@h37g2000pro.googlegroups.com> On Sep 15, 9:53?am, Andrew wrote: > I'm trying to remove the widgets from the QFormLayout widget from > PyQt4. According to the documentation I should be able to use the > command .takeAt(int) which will delete the widget from the layout and > then return to me the QLayoutWidget. > It currently is giving me back the widget, but is not removing it from > the layout. > At the moment, I'm simply trying to clear out all the widgets on the > layout with this: > > def clearForm(self): > ? ? ? ? ? ? ? ? print ("Clearing") > ? ? ? ? ? ? ? ? print self.dataForm.rowCount() > ? ? ? ? ? ? ? ? for i in range(self.dataForm.rowCount()-1, -1, -1): > ? ? ? ? ? ? ? ? ? ? ? ? print " .", > ? ? ? ? ? ? ? ? ? ? ? ? tmp = self.dataForm.takeAt(i) > ? ? ? ? ? ? ? ? ? ? ? ? print tmp.widget() > ? ? ? ? ? ? ? ? ? ? ? ? tmp = "" > ? ? ? ? ? ? ? ? print self.dataForm.rowCount() > > It goes through each widget on the layout, and prints out the > classes .__repr__ on the tmp.widget() line since tmp is a > QLayoutWidget. So it's doing the returning part, but they still exist > instead of being deleted like the documentation explains. > > Am I missing a step or is this just broken? I haven't been able to > find anything else on this issue yet. If it's broke, is there any > potential workaround? > > I'm using python 2.6.4 and PyQt4 4.7.6 > > Thanks, > Andrew QLayoutWidget, I meant a QWidgetItem. From anand.shashwat at gmail.com Wed Sep 15 13:25:11 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 15 Sep 2010 13:25:11 -0400 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: <8fag9dF4mtU1@mid.individual.net> References: <8fag9dF4mtU1@mid.individual.net> Message-ID: On Tue, Sep 14, 2010 at 7:54 PM, Gregory Ewing wrote: > Suppose I have two N+2 dimensional arrays, representing > N-d arrays of 2-d matrices. I want to perform matrix > multiplication between corresponding matrices in these > arrays. > > I had thought that dot() might do this, but it appears > not, because e.g. applying it to two 3-d arrays gives > a 4-d array, not another 3-d array. > > I'd also like to be able to find the inverse of each > matrix in one of these arrays, but again, inv() doesn't > do what I want -- it only works on 2-d arrays. > > Any thoughts on how to achieve these things using numpy > functions? > Unrelated to numpy, but you can apply the basics of dynamic programming to optimize the stuff. > -- > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From edg at greenberg.org Wed Sep 15 13:38:16 2010 From: edg at greenberg.org (Ed Greenberg) Date: Wed, 15 Sep 2010 12:38:16 -0500 Subject: Debugger - fails to "continue" with breakpoint set Message-ID: <4C910488.8020203@greenberg.org> I'm pretty new to Python, but I am really enjoying it as an alternative to Perl and PHP. When I run the debugger [import pdb; pdb.set_trace()] and then do next and step, and evaluate variables, etc, when I hit 'c' for continue, we go to the end, just fine. As soon as I set a breakpoint down the line, [b ] the behavior of 'c' changes. Instead of continuing until the breakpoint, or until the end, if the breakpoint is hidden by a conditional, the debugger starts to treat 'c' as a step (or a next, I'm not sure which.) This behavior is repeatable and consistent. I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu 8.04 (Hardy), both using the installed packages. I must be missing something. Assistance will be welcome. Thanks, Ed Greenberg From mummerx at gmail.com Wed Sep 15 13:38:47 2010 From: mummerx at gmail.com (Douglas) Date: Wed, 15 Sep 2010 10:38:47 -0700 (PDT) Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: @Diez and @David Thanks guys. Both excellent leads. Colour me happy. I can now make progress and meet some deadlines. :) @Lawrence > Why reinvent rsync? In what way is rsync relevant to the stated problem? Did you actually READ the question? Note: I use Linux at home (yes, even rsync) and very much prefer it to Windows. However, at work I have no choice but to use the resources the company provides - which is Windows; have you got that straight now? If you have something more helpful and mature to say, relevant to the actual question, then I will gladly hear it, and even apologise. Otherwise, don't bother. I already enough from respondents who were far more adult, knowledgeable and helpful ... and all the more impressive in comparison. Sincerely, -- Douglas From ron.eggler at gmail.com Wed Sep 15 14:32:43 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 15 Sep 2010 11:32:43 -0700 (PDT) Subject: socket.error: [Errno 98] Address already in use Message-ID: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Hi There, I get a socket error "[Errno 98] Address already in use" when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() Shouldn't that clean it all up properly? Thanks for hints & suggestions! Ron From thomas at jollybox.de Wed Sep 15 14:49:04 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 15 Sep 2010 20:49:04 +0200 Subject: socket.error: [Errno 98] Address already in use In-Reply-To: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: <201009152049.04891.thomas@jollybox.de> On Wednesday 15 September 2010, it occurred to cerr to exclaim: > Hi There, > > I get a socket error "[Errno 98] Address already in use" when i try to > open a socket that got closed before with close(). How come close() > doesn't close the socket properly? > My socket code : > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((host, port)) > s.listen(1) > ... > ... > ... > while loop: > conn, addr = s.accept() > while conn and loop: > ... > ... > ... > conn.close() > > Shouldn't that clean it all up properly? `s` is still listening? From hansmu at xs4all.nl Wed Sep 15 14:54:13 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 15 Sep 2010 20:54:13 +0200 Subject: Cross Compiling Python for ARM In-Reply-To: References: Message-ID: <4c911670$0$41115$e4fe514c@news.xs4all.nl> Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: >> # >> ./python >> >> -sh: ./python: not found > > > I'm guessing either there is no file ./python, or /bin/sh is fundamentally > broken. .... or ./python is a symlink to a file that does not exist, or ./python is a script and the shebang line points to an interpreter that does not exist. The most popular way to get the latter problem is to write the script on a Windows box and then upload it to Unix box using FTP in binary mode (or some other transport that doesn't adjust the line endings). Try the command "file ./python". If it reports something like: ./python: a /usr/bin/python\015 script text executable , then the \015 tells you that you need to use dos2unix. It may be the case that /bin/sh is fundamentally broken if it reports "./python: file not found" if the problem is really the shebang line. Unfortunately, some shells are fundamentally broken this way. Hope this helps, -- HansM From thomas at jollybox.de Wed Sep 15 14:54:58 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 15 Sep 2010 20:54:58 +0200 Subject: distutils, cygwin, 'not a regular file' In-Reply-To: <8faqj0FnoeU1@mid.individual.net> References: <8faqj0FnoeU1@mid.individual.net> Message-ID: <201009152054.58285.thomas@jollybox.de> On Wednesday 15 September 2010, it occurred to Paul Watson to exclaim: > So, what is not a regular file about this? Is there any way to find out > which files are being considered irregular? Regular files are the kind of files used to store bytes. Other kinds of files you might find in a file system include: directories symbolic links pipes (FIFOs) sockets (UNIX/LOCAL domain) character devices block devices Also, for help on interpreting the message at hand, see Lawrence d'Oliveiro's response. > > $ uname -a > CYGWIN_NT-6.0-WOW64 pwatson 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin > > $ cat setup.py > > from distutils.core import setup > > setup( > name='xlsexport', > version='0.3', > > py_modules=['xlsexport'] > ) > 20:47 pwatson [ pwatson:/cygdrive/c/Users/pwatson/bin/xlsexport] 12 > $ python setup.py sdist > running sdist > warning: sdist: missing required meta-data: url > warning: sdist: missing meta-data: either (author and author_email) or > (maintainer and maintainer_email) must be supplied > reading manifest file 'MANIFEST' > creating xlsexport-0.3 > making hard links in xlsexport-0.3... > ' not a regular file -- skipping > ' not a regular file -- skipping > ' not a regular file -- skipping > tar -cf dist/xlsexport-0.3.tar xlsexport-0.3 > gzip -f9 dist/xlsexport-0.3.tar > removing 'xlsexport-0.3' (and everything under it) From invalid at invalid.invalid Wed Sep 15 14:58:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 15 Sep 2010 18:58:32 +0000 (UTC) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On 2010-09-15, cerr wrote: > I get a socket error "[Errno 98] Address already in use" when i try to > open a socket that got closed before with close(). How come close() > doesn't close the socket properly? > My socket code : > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((host, port)) > s.listen(1) > ... > ... > ... > while loop: > conn, addr = s.accept() > while conn and loop: > ... > ... > ... > conn.close() At what line does the error occur? To what does the phrase "open a socket" refer? Have you tried the usual solution of setting the SO_REUSEADDR option on the socket before calling bind? http://www.google.com/search?q=socket+%27address+already+in+use%27 -- Grant Edwards grant.b.edwards Yow! I own seven-eighths of at all the artists in downtown gmail.com Burbank! From thomas at jollybox.de Wed Sep 15 15:04:28 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 15 Sep 2010 21:04:28 +0200 Subject: Debugger - fails to "continue" with breakpoint set In-Reply-To: <4C910488.8020203@greenberg.org> References: <4C910488.8020203@greenberg.org> Message-ID: <201009152104.28899.thomas@jollybox.de> On Wednesday 15 September 2010, it occurred to Ed Greenberg to exclaim: > I'm pretty new to Python, but I am really enjoying it as an alternative > to Perl and PHP. > > When I run the debugger [import pdb; pdb.set_trace()] and then do next > and step, and evaluate variables, etc, when I hit 'c' for continue, we > go to the end, just fine. > > As soon as I set a breakpoint down the line, [b ] the > behavior of 'c' changes. Instead of continuing until the breakpoint, or > until the end, if the breakpoint is hidden by a conditional, the > debugger starts to treat 'c' as a step (or a next, I'm not sure which.) > > This behavior is repeatable and consistent. > > I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu > 8.04 (Hardy), both using the installed packages. > > I must be missing something. Assistance will be welcome. I can't reproduce this. Please post a small script and debugger session transcript that illustrate the problem clearly. Maybe, on the way, you'll discover something you'd been missing. Maybe someone here will be able to help you then (maybe someone is now, but not me...). Maybe it's a bug (which it would be, if it behaves as you describe, but as I said, it appears to work for me). From nicoddemus at gmail.com Wed Sep 15 16:10:59 2010 From: nicoddemus at gmail.com (Bruno Oliveira) Date: Wed, 15 Sep 2010 17:10:59 -0300 Subject: Multiprocessing Queue strange behavior Message-ID: Hi list, I recently found a bug in my company's code because of a strange behavior using multiprocessing.Queue. The following code snippet: from multiprocessing import Queue queue = Queue() queue.put('x') print queue.get_nowait() Fails with: ... File "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", line 153, in getNoWait return self.get(False) File "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", line 129, in get raise Empty Queue.Empty Strangely, changing this to: queue = Queue() queue.put('x') time.sleep(0.1) # <<< print queue.get_nowait() Works as expected. Using the original snippet changing the import to threading's Queue also works. It seems like there's a bug in multiprocessing's Queue implementation. Opinions? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Sep 15 16:47:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Sep 2010 21:47:46 +0100 Subject: Multiprocessing Queue strange behavior In-Reply-To: References: Message-ID: <4C9130F2.80000@mrabarnett.plus.com> On 15/09/2010 21:10, Bruno Oliveira wrote: > Hi list, > > I recently found a bug in my company's code because of a strange > behavior using multiprocessing.Queue. The following code snippet: > > from multiprocessing import Queue > > queue = Queue() > queue.put('x') > print queue.get_nowait() > Fails with: > > ... > File > "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", > line 153, in getNoWait > return self.get(False) > File > "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", > line 129, in get > raise Empty > Queue.Empty > > Strangely, changing this to: > > queue = Queue() > queue.put('x') > time.sleep(0.1) # <<< > print queue.get_nowait() > Works as expected. Using the original snippet changing the import to > threading's Queue also works. > > It seems like there's a bug in multiprocessing's Queue implementation. > Opinions? > I don't think it's a bug as such. The purpose of the multiprocessing queue is to transfer data between different processes, which don't have a shared address space (unlike threads, which do). The transfer involves passing the data between the processes via a pipe. This is done in a background thread and takes some time to complete, so the data won't appear immediately. It looks like it doesn't matter that the putter and the getter happen to be in the same process, possibly because no-one expected that someone would use a multiprocessing queue within the same process like that, so it doesn't check for a shortcut. From mariakirsan at hotmail.com Wed Sep 15 16:51:19 2010 From: mariakirsan at hotmail.com (Maria) Date: Wed, 15 Sep 2010 13:51:19 -0700 (PDT) Subject: Please I need help! Message-ID: <5581bb73-66b3-4d8c-a0b4-b04f8d6956c7@a11g2000vbn.googlegroups.com> I urgently need money help!https://siteheart.com/js/chat/chat.html? ent=9228&hash=97b8aa4b4eec4801f941b0aa97cd2587&ipcsid=842e10a5515ee7299638a546b6b2997f Maria From ben+python at benfinney.id.au Wed Sep 15 17:12:16 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 16 Sep 2010 07:12:16 +1000 Subject: os.path.normcase rationale? References: Message-ID: <87lj727lu7.fsf@benfinney.id.au> Chris Withers writes: > I'm curious as to why, with a file called "Foo.txt" > os.path.normcase('FoO.txt') will return "foo.txt" rather than > "Foo.txt"? What kind of answer are you looking for? A direct answer would be: it does that because on case-insensitive filesystems, it doesn't matter what the case is, so there's no need for anything more complex than all lowercase. > Yes, I know the behaviour is documented The docstring is fairly poor, IMO. You might want to submit a bug report to improve it. > but I'm wondering if anyone can remember the rationale for that > behaviour? I can't speak to that. Does the above answer seem sufficient? -- \ ?I think there is a world market for maybe five computers.? | `\ ?Thomas Watson, chairman of IBM, 1943 | _o__) | Ben Finney From robert.kern at gmail.com Wed Sep 15 17:46:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 15 Sep 2010 16:46:22 -0500 Subject: business date and calendar libraries? In-Reply-To: <4C8E59FA.3060508@simplistix.co.uk> References: <4C8E59FA.3060508@simplistix.co.uk> Message-ID: On 9/13/10 12:06 PM, Chris Withers wrote: > Hi All, > > I'm wondering what libraries people would use to answer the following questions > relating to business days: > > - on a naive level; "what's give me the last business day" (ie: skipping weekends) > > - on a less-naive level; same question but taking into account public holidays > > - on a horrific level; same question, but taking into account business days of a > particular market (NYSE, LSE, etc) Quantlib has a fairly good (by which I mean, horrific) collection of these implemented in C++: http://quantlib.svn.sourceforge.net/viewvc/quantlib/trunk/QuantLib/ql/time/calendars/ If you only need a few of these, it can be more straightforward to look at them and recode them rather than trying to build Quantlib and its wrappers. Most of them have some algorithmic component (e.g. weekends, "easy" recurring holidays) and some exceptional cases (e.g. the days NYSE was closed after 2001-09-11). -- 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 Sep 15 17:47:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 15 Sep 2010 16:47:02 -0500 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: References: <8fag9dF4mtU1@mid.individual.net> Message-ID: On 9/15/10 11:36 AM, Colin J. Williams wrote: > On 14-Sep-10 19:54 PM, Gregory Ewing wrote: >> Suppose I have two N+2 dimensional arrays, representing >> N-d arrays of 2-d matrices. I want to perform matrix >> multiplication between corresponding matrices in these >> arrays. >> >> I had thought that dot() might do this, but it appears >> not, because e.g. applying it to two 3-d arrays gives >> a 4-d array, not another 3-d array. >> >> I'd also like to be able to find the inverse of each >> matrix in one of these arrays, but again, inv() doesn't >> do what I want -- it only works on 2-d arrays. >> >> Any thoughts on how to achieve these things using numpy >> functions? > > There is a Matrix sub-class which permit you to do that sort of thimg. No, it doesn'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 edg at greenberg.org Wed Sep 15 18:17:52 2010 From: edg at greenberg.org (Ed Greenberg) Date: Wed, 15 Sep 2010 17:17:52 -0500 Subject: Debugger - fails to "continue" with breakpoint set In-Reply-To: <201009152104.28899.thomas@jollybox.de> References: <4C910488.8020203@greenberg.org> <201009152104.28899.thomas@jollybox.de> Message-ID: <4C914610.5060904@greenberg.org> On 09/15/2010 02:04 PM, Thomas Jollans wrote: > On Wednesday 15 September 2010, it occurred to Ed Greenberg to exclaim: > >> I'm pretty new to Python, but I am really enjoying it as an alternative >> to Perl and PHP. >> >> When I run the debugger [import pdb; pdb.set_trace()] and then do next >> and step, and evaluate variables, etc, when I hit 'c' for continue, we >> go to the end, just fine. >> >> As soon as I set a breakpoint down the line, [b] the >> behavior of 'c' changes. Instead of continuing until the breakpoint, or >> until the end, if the breakpoint is hidden by a conditional, the >> debugger starts to treat 'c' as a step (or a next, I'm not sure which.) >> >> This behavior is repeatable and consistent. >> >> I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu >> 8.04 (Hardy), both using the installed packages. >> >> I must be missing something. Assistance will be welcome. >> > I can't reproduce this. Please post a small script and debugger session > transcript that illustrate the problem clearly. > > Maybe, on the way, you'll discover something you'd been missing. Maybe someone > here will be able to help you then (maybe someone is now, but not me...). > Maybe it's a bug (which it would be, if it behaves as you describe, but as I > said, it appears to work for me). > Here is my debugger session as requested. Note that I set a breakpoint at line 7, but c still stops at lines 4, 5 and 6. I hope somebody can explain this. ------------------------------------------------- root at cloud4:~# python --version Python 2.6.4 root at cloud4:~# python test.py > /root/test.py(3)() -> a=1 (Pdb) l 1 #!/usr/bin/python 2 import pdb;pdb.set_trace() 3 -> a=1 4 b=2 5 c=3 6 d=4 7 print a,b,c,d 8 [EOF] (Pdb) b 7 Breakpoint 1 at /root/test.py:7 (Pdb) c > /root/test.py(4)() -> b=2 (Pdb) c > /root/test.py(5)() -> c=3 (Pdb) c > /root/test.py(6)() -> d=4 (Pdb) c > /root/test.py(7)() -> print a,b,c,d (Pdb) c 1 2 3 4 --Return-- > /root/test.py(7)()->None -> print a,b,c,d (Pdb) c root at cloud4:~# From greg.ewing at canterbury.ac.nz Wed Sep 15 19:14:55 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 16 Sep 2010 11:14:55 +1200 Subject: os.path.normcase rationale? In-Reply-To: <87lj727lu7.fsf@benfinney.id.au> References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <8fd2c1FvvhU1@mid.individual.net> Ben Finney wrote: > it doesn't matter what the case is, so there's no need for > anything more complex than all lowercase. Also doing what was suggested would require looking at what's in the file system, which would be a lot of bother to go to for no good reason, and would fail for paths that don't correspond to an existing file. -- Greg From ethan at stoneleaf.us Wed Sep 15 19:23:20 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Sep 2010 16:23:20 -0700 Subject: it doesn't work ;) [class recursive function] Message-ID: <4C915568.3080007@stoneleaf.us> I need some fresh eyes, or better brains, or both! The expected debugging output is a list of names in alphabetical order from each node (there are about 90 of them); what I am getting is this: --> dbf.tables.Index.from_file('', r'aad13658_last_name_for_state.idx') starting next_item call for root ----- 512 30 ----- more nodes CARNAHAN 1536 ENGLUND 1024 HOLSTEIN 2048 MATTHEWS 2560 ROSENFELD 3072 TERWILLIGER 3584 YAZZOLINO 4096 and then it stops. I should get about nine of these sections, and I'm only getting one. class Index(object): @classmethod def from_file(cls, table, index_file): def get_idx_records(data, length, howmany): print "get_idx_records: keylen - %d; howmany - %d" %\ (length, howmany) ptr = 0 current = 0 while current < howmany: key = data[ptr:ptr+length].replace('\x00','') rec = io.unpackLongInt(data[ptr+length:ptr+length+4],\ bigendian=True) yield key, rec ptr += length + 4 current += 1 def next_item(idx_file, node_loc, keylen): print idx_file, node_loc, keylen, '\n','-----' idx_file.seek(node_loc) data_chunk = idx_file.read(512) attributes = io.unpackShortInt(data_chunk[:2]) howmany = io.unpackShortInt(data_chunk[2:4]) if attributes in (2, 3): print "actual records" for key, rec in get_idx_records(data_chunk[12:512],\ keylen, howmany): yield key, rec else: print "more nodes" for ignore, next_node in \ get_idx_records(data_chunk[12:512],\ keylen, howmany): print ignore, next_node next_item(idx_file, next_node, keylen) idx = object.__new__(cls) #- idx.key = lambda rec: DoNotIndex data = open(index_file, 'rb') header = data.read(512) rootnode = io.unpackLongInt(header[:4]) keylen = io.unpackShortInt(header[12:14]) idx.__doc__ = header[16:236].replace('\x00','') for_expr = header[236:456].replace('\x00','') if for_expr: idx.__doc__ += ' for ' + for_expr.replace('=','==') print "starting next_item call for root" for rec in next_item(data, rootnode, keylen): print rec Any ideas appreciated! ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: aad13658_last_name_for_state.idx Type: application/octet-stream Size: 4608 bytes Desc: not available URL: From gavcomedy at gmail.com Wed Sep 15 19:58:00 2010 From: gavcomedy at gmail.com (gavino) Date: Wed, 15 Sep 2010 16:58:00 -0700 (PDT) Subject: compiling python 3.1.2 with local readline fails to get readline - help! Message-ID: I compiled readline 6.1 myself. # ./configure --prefix=/home/apps/python --disable-shared --with- pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6 --enable-readline --with-readline=/home/apps/readline/lib/ # make -j14 .... .... modules not installed: ........ readline ......... Python starts but no readline. What is the proper configure flag to use a locally compiled readline? I tried with and without --with-readline and with readline/ and readline/lib as shown above. thx for help From python at mrabarnett.plus.com Wed Sep 15 20:01:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Sep 2010 01:01:40 +0100 Subject: it doesn't work ;) [class recursive function] In-Reply-To: <4C915568.3080007@stoneleaf.us> References: <4C915568.3080007@stoneleaf.us> Message-ID: <4C915E64.50308@mrabarnett.plus.com> On 16/09/2010 00:23, Ethan Furman wrote: > I need some fresh eyes, or better brains, or both! > > The expected debugging output is a list of names in alphabetical order > from each node (there are about 90 of them); what I am getting is this: > > --> dbf.tables.Index.from_file('', r'aad13658_last_name_for_state.idx') > > starting next_item call for root > ----- > > 512 30 > ----- > more nodes > CARNAHAN 1536 > ENGLUND 1024 > HOLSTEIN 2048 > MATTHEWS 2560 > ROSENFELD 3072 > TERWILLIGER 3584 > YAZZOLINO 4096 > > and then it stops. I should get about nine of these sections, and I'm > only getting one. > > > [snip code] > > > > Any ideas appreciated! > 'next_item' is a generator, but it's just calling itself and discarding the result. I think it should be yielding the results to its caller. That fix gives me 7 sections in total. From prologic at shortcircuit.net.au Wed Sep 15 20:12:08 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 10:12:08 +1000 Subject: compiling python 3.1.2 with local readline fails to get readline - help! In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 9:58 AM, gavino wrote: > I compiled readline 6.1 myself. > > # ?./configure --prefix=/home/apps/python --disable-shared --with- > pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6 > --enable-readline --with-readline=/home/apps/readline/lib/ > # ?make -j14 > .... > .... > modules not installed: > ........ ? ?readline ? ......... > > Python starts but no readline. > > What is the proper configure flag to use a locally compiled readline? > I tried with and without --with-readline and with readline/ and > readline/lib as shown above. > thx for help AFAIK, there are no "readline" specific options in python 2.x's ./configure options: # pwd /usr/ports/opt/python/Python-2.6.5 # ./configure --help | grep readline -i # I could be wrong... Are you sure you've configured and compile readline correctly and that you've set the appropriate environment variables and paths for C/C++ compilers (eg: GCC) to pick it up ? cheers James -- -- James Mills -- -- "Problems are solved by method" From jason.swails at gmail.com Wed Sep 15 20:13:04 2010 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 15 Sep 2010 20:13:04 -0400 Subject: classes and dictionaries Message-ID: Hello everyone, I'm encountering an issue in one of my Python classes that makes extensive use of dictionaries. I was under the impression that each time an object was instantiated, all of its variables were created in a new section of memory, so that if you change the value of the variable in one instance, it left that variable's value in another instance alone. In the object that I wrote, I have 3 different dictionaries: parm_data, pointers, and formats, all defined in the same place. When I load 2 instances of this object, parm_data and formats each take on different values between the two objects (as they should), but for some reason pointers does not. I've seen this problem with python2.6.4 and 2.6.1 (and I believe earlier versions as well, but I'm not sure). I've attached a tarball with the relevant code and a sample script that shows what I mean. If anyone can tell me why the dictionary from 2 different objects are exactly the same for pointers, but are different for, e.g. parm_data and formats, that would be greatly appreciated. Thanks! Jason -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: prmtop_test.tgz Type: application/x-gzip Size: 10749 bytes Desc: not available URL: From hansyin at gmail.com Wed Sep 15 20:14:14 2010 From: hansyin at gmail.com (Hans) Date: Wed, 15 Sep 2010 17:14:14 -0700 (PDT) Subject: program organization question for web development with python Message-ID: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> Hi, I'm new to this area. Please allow me to ask some (maybe stupid) questions. I'm planning to write a web application which used for searching my mysql database. 1. files organization I have this in my main.py: print """%s""" % (record[0],table_name,cursor_name,record1) it kind of works but not comfortable to me. Do I have to use two files(main.py and display_tb.py)? does that means each hyper-link needs a single file? Can I put those files together and then they can share variables,classes, modules, etc? 2. database cursor as parameter? I created database cursor in my main.py and then I have to use it in another file(display_tb.py), Can I? I put cursor as a parameter and try to send it through hyper-link. but it somehow does not work. error log listed below: /usr/lib/cgi-bin/display_tb.py in () 20 sql_str = "SELECT * FROM %s " % search_str_list 21 print "

%s

" % sql_str 22 cursor_ptr.execute(sql_str) 23 result = cursor_ptr.fetchall() 24 cursor_ptr = '', cursor_ptr.execute undefined, sql_str = 'SELECT * FROM env_test where id=20 ' : 'str' object has no attribute 'execute' args = ("'str' object has no attribute 'execute'",) message = "'str' object has no attribute 'execute'" From share.it.usa at gmail.com Wed Sep 15 20:19:05 2010 From: share.it.usa at gmail.com (Health Coach) Date: Wed, 15 Sep 2010 17:19:05 -0700 (PDT) Subject: work opportunity Message-ID: <3b890b18-657d-45ad-bc9d-a09f4118c4b4@l32g2000prn.googlegroups.com> FREE to Join ! You get up to 35% cashback for every qualified purchase you make on the site. On any personal referrals, you'll also make 1/2% on their qualifying purchases! ********************************************* www.ma360eMall.com Everything you need and want Get paid to shop with Cashback up to 35% Many more hot deals.... ma360emall at gmail.com ********************************************** http://w.mawebcenters.com/ma360emall/ http://motivescosmetics.marketamerica.com/MA360EMALL/ http://isotonix.marketamerica.com/MA360EMALL/USA From prologic at shortcircuit.net.au Wed Sep 15 20:30:46 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 10:30:46 +1000 Subject: classes and dictionaries In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 10:13 AM, Jason Swails wrote: > Hello everyone, > > I'm encountering an issue in one of my Python classes that makes extensive > use of dictionaries.? I was under the impression that each time an object > was instantiated, all of its variables were created in a new section of > memory, so that if you change the value of the variable in one instance, it > left that variable's value in another instance alone.? In the object that I > wrote, I have 3 different dictionaries: parm_data, pointers, and formats, > all defined in the same place.? When I load 2 instances of this object, > parm_data and formats each take on different values between the two objects > (as they should), but for some reason pointers does not.? I've seen this > problem with python2.6.4 and 2.6.1 (and I believe earlier versions as well, > but I'm not sure).? I've attached a tarball with the relevant code and a > sample script that shows what I mean. > > If anyone can tell me why the dictionary from 2 different objects are > exactly the same for pointers, but are different for, e.g. parm_data and > formats, that would be greatly appreciated. In short (without creating a huge thread of unnecessary chatter), if you reference an object in 2 different dictionaries, the values (dictionary values) will be identical. The following example might help you understand this. >>> class Foo(object): ... def __init__(self, data=None): ... self.data = {"params": data} ... >>> a = b = object() >>> id(a), id(b) (3075279112L, 3075279112L) >>> foo = Foo(a) >>> bar = Foo(b) >>> foo.data, bar.data ({'params': }, {'params': }) >>> id(foo.data["params"]), id(bar.data["params"]) (3075279112L, 3075279112L) >>> cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Sep 15 20:33:05 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 10:33:05 +1000 Subject: program organization question for web development with python In-Reply-To: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> Message-ID: On Thu, Sep 16, 2010 at 10:14 AM, Hans wrote: > I'm new to this area. Please allow me to ask some (maybe stupid) > questions. Without reading the rest of your post too much. Designs are up to you, I can't comment. I can only share in a fairly common view, and that is, we'd encourage you to use a web framework as opposed to plain old CGI. cheers james -- -- James Mills -- -- "Problems are solved by method" From python at mrabarnett.plus.com Wed Sep 15 20:36:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Sep 2010 01:36:41 +0100 Subject: classes and dictionaries In-Reply-To: References: Message-ID: <4C916699.2040202@mrabarnett.plus.com> On 16/09/2010 01:13, Jason Swails wrote: > Hello everyone, > > I'm encountering an issue in one of my Python classes that makes > extensive use of dictionaries. I was under the impression that each > time an object was instantiated, all of its variables were created in a > new section of memory, so that if you change the value of the variable > in one instance, it left that variable's value in another instance > alone. In the object that I wrote, I have 3 different dictionaries: > parm_data, pointers, and formats, all defined in the same place. When I > load 2 instances of this object, parm_data and formats each take on > different values between the two objects (as they should), but for some > reason pointers does not. I've seen this problem with python2.6.4 and > 2.6.1 (and I believe earlier versions as well, but I'm not sure). I've > attached a tarball with the relevant code and a sample script that shows > what I mean. > > If anyone can tell me why the dictionary from 2 different objects are > exactly the same for pointers, but are different for, e.g. parm_data and > formats, that would be greatly appreciated. > When you bind to a name in the class namespace: class Example: foo = "class attribute" the name is an attribute of the class. If you want a name to be an attribute of an instance then you should refer to the instance explicitly: class Example: def __init__(self): self.bar = "instance attribute" From jipalaciosortega at gmail.com Wed Sep 15 20:51:04 2010 From: jipalaciosortega at gmail.com (jipalaciosortega at gmail.com) Date: Thu, 16 Sep 2010 02:51:04 +0200 Subject: socket.error: [Errno 98] Address already in use In-Reply-To: References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: <4C9169F8.4020906@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 El 15/09/2010 20:58, Grant Edwards escribi?: > On 2010-09-15, cerr wrote: > >> I get a socket error "[Errno 98] Address already in use" when i >> try to open a socket that got closed before with close(). How >> come close() doesn't close the socket properly? My socket code : >> >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >> s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, >> addr = s.accept() while conn and loop: ... ... ... conn.close() > > At what line does the error occur? > > To what does the phrase "open a socket" refer? > > Have you tried the usual solution of setting the SO_REUSEADDR > option on the socket before calling bind? > > http://www.google.com/search?q=socket+%27address+already+in+use%27 > Maybe, you have any other proccess in your system using your listen port, for example apache... - -- _ _ _ _ _ _ _ _ _ _ _ Jose Ignacio Palacios Ortega /_ _/ / / / _ / / _ / Telf: +34 637 058 813 / / / / / /_ / / / / / / Correo-e: jipalaciosortega at gmail.com _ / / / / / _ _ _/ / / / / Msn: jipalaciosortega at gmail.com / /_ / / / / / / / /_/ / ID firma PGP: 0x0EB87E48 \ _ _ / /_/ /_/ /_ _ _/ Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ 4cgAniOoR70hu7UylkpgAr3JI5hxNXYP =MoYK -----END PGP SIGNATURE----- From gavcomedy at gmail.com Wed Sep 15 21:10:39 2010 From: gavcomedy at gmail.com (gavino) Date: Wed, 15 Sep 2010 18:10:39 -0700 (PDT) Subject: compiling python 3.1.2 with local readline fails to get readline - help! References: Message-ID: On Sep 15, 5:12?pm, James Mills wrote: > On Thu, Sep 16, 2010 at 9:58 AM, gavino wrote: > > I compiled readline 6.1 myself. > > > # ?./configure --prefix=/home/apps/python --disable-shared --with- > > pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6 > > --enable-readline --with-readline=/home/apps/readline/lib/ > > # ?make -j14 > > .... > > .... > > modules not installed: > > ........ ? ?readline ? ......... > > > Python starts but no readline. > > > What is the proper configure flag to use a locally compiled readline? > > I tried with and without --with-readline and with readline/ and > > readline/lib as shown above. > > thx for help > > AFAIK, there are no "readline" specific options in python 2.x's > ./configure options: > > # pwd > /usr/ports/opt/python/Python-2.6.5 > # ./configure --help | grep readline -i > # > > I could be wrong... Are you sure you've configured and compile > readline correctly and that you've set the appropriate environment > variables and paths for C/C++ compilers (eg: GCC) to pick it up ? > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" I am comiling 3.1.2. I am not root but a user. I compiled readline and it did not complain. gdb and zlib and some other modules also were not found. From prologic at shortcircuit.net.au Wed Sep 15 21:39:30 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 11:39:30 +1000 Subject: [Python-Dev] problem with python 3.1 In-Reply-To: References: Message-ID: (Posting to python general discussion). On Thu, Sep 16, 2010 at 10:17 AM, Jo?o Vitor wrote: > I made a program that, according to my teacher, is correct but is not > running properly. > The program is really simple: > import math > x = input ("Coloque o valor do primeiro cateto:") > y = input ("Coloque o valor do segundo cateto:") > z = x**2 > w = y**2 > soma = z + w > h = math.sqrt (soma) > print = "O valor da hipotenusa ?:", h > But after I put the value of x and y this error appears: > Traceback (most recent call last): > ??File "C:/lista03.py", line 4, in > ?? ?z = x**2 > TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' > My teacher said the program ran normally in his computer, but in my it > doesn't! > why? You're teacher has clearly overlooked that you must convert the values of x and y to int's using either: x = int(input(...)) or x = int(x) You cannot perform (most) mathematical operators where the operands are of different types (in Python) eg: str and int cheers James PS: Please post questions like this to either the tutor or general python mailing list(s). -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Sep 15 21:41:35 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 11:41:35 +1000 Subject: compiling python 3.1.2 with local readline fails to get readline - help! In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 11:10 AM, gavino wrote: > I am comiling 3.1.2. > I am not root but a user. > I compiled readline and it did not complain. > gdb and zlib ?and some other modules also were not found. Like I said earlier in my previous post, is the readline line that you compiled and installed to your home directory actually working and can you actually compile any C programs that use this custom readline ? cheers James -- -- James Mills -- -- "Problems are solved by method" From wuwei23 at gmail.com Wed Sep 15 22:01:07 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 15 Sep 2010 19:01:07 -0700 (PDT) Subject: WMI in Python References: Message-ID: KING LABS wrote: > The following information is exactly what I am trying to collect for > the inventory. I can find vb scripts with googling. I want to do the > same with Python & Win32. Use Server/Client architecture . > Client(agent) updates the information to server. I highly agree with the recommendations for Tim Golden's WMI library. I once used it during an MS VBScript course for sys admins to produce python equivalents of the VBS code; it was far, _far_ easier to componentise & reuse python code than VBS. However, for a quick & ready solution, have you looked at Microsoft's Scriptomatic?[2] It's a handy little tool that lets you specify the WMI query you want and produces code for you, with Python being one of the targets. It _should_ be able to handle most of everything you're after, with the exception of Software Information (from memory that's not something WMI covers?). Once Scriptomatic has generated the bulk of the WMI code, that's the payload of your client-side script. There are many many many ways of doing simple client/server set ups in python, just google and pick one that works at a suitable abstraction level for you. Here's a straightforward sockets-based approach[3] (that I've never used but looks okay). 1: http://timgolden.me.uk/python/wmi/index.html 2: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&displaylang=en 3: http://wdvl.internet.com/Authoring/python/client/watts06152009.html From ldo at geek-central.gen.new_zealand Wed Sep 15 22:19:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 16 Sep 2010 14:19:53 +1200 Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: In message , Douglas wrote: >> Why reinvent rsync? > In what way is rsync relevant to the stated problem? Did you actually > READ the question? Yes. > Note: I use Linux at home (yes, even rsync) and very much prefer it to > Windows. However, at work I have no choice but to use the resources > the company provides - which is Windows; have you got that straight > now? Doesn?t change the fact that you?re reinventing rsync. From ldo at geek-central.gen.new_zealand Wed Sep 15 22:23:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 16 Sep 2010 14:23:44 +1200 Subject: WMI in Python References: Message-ID: In message , alex23 wrote: > However, for a quick & ready solution, have you looked at Microsoft's > Scriptomatic?[2] It's a handy little tool that lets you specify the > WMI query you want and produces code for you, with Python being one of > the targets. Why not just call Scriptomatic directly from within the Python script, then? Machine-generated code has no place in a source file to be maintained by a human. From rodrick.brown at gmail.com Wed Sep 15 22:31:14 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 15 Sep 2010 22:31:14 -0400 Subject: How do you preserve time values with date.datefromtimestamp() Message-ID: I'm doing something like >>> today = datetime.date.fromtimestamp(1284584357.241863) >>> today.ctime() 'Wed Sep 15 00:00:00 2010' Why isn't the time field being populated what I expect is to see something like Wed Sep 15 2010 16:59:17:241863 -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -------------- next part -------------- An HTML attachment was scrubbed... URL: From research at johnohagan.com Wed Sep 15 23:18:56 2010 From: research at johnohagan.com (John O'Hagan) Date: Thu, 16 Sep 2010 03:18:56 +0000 Subject: Argparse: add_argument with action=append appends to default Message-ID: <201009160318.57152.research@johnohagan.com> I find this surprising: >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--test', action='append', default=['default']) [...] >>> parser.parse_args(['--test', 'arg']) Namespace(test=['default', 'arg']) As an argument is provided, I didn't expect to see the default in there as well. From the argparse docs: "the default value is used when the option string was not present at the command line". While it doesn't say "_only_ when...", that's what I would have expected. Is there a reason for this behaviour? Is there a way to do what I want, to get a list of appended options _or_ a default list (apart from setting defaults outside the parser, a good way to lose track of things)? Thanks, John From cs at zip.com.au Wed Sep 15 23:33:50 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 16 Sep 2010 13:33:50 +1000 Subject: How do you preserve time values with date.datefromtimestamp() In-Reply-To: References: Message-ID: <20100916033350.GA10543@cskk.homeip.net> On 15Sep2010 22:31, Rodrick Brown wrote: | I'm doing something like | | >>> today = datetime.date.fromtimestamp(1284584357.241863) | >>> today.ctime() | 'Wed Sep 15 00:00:00 2010' | | Why isn't the time field being populated what I expect is to see something | like Wed Sep 15 2010 16:59:17:241863 Because you asked for a "date". A "date" only has day resolution. It's like going: i = int(1.234) which quite legitimately results in "1" (the interger, not a string). You want a datetime, thus: >>> today = datetime.datetime.fromtimestamp(1284584357.241863) >>> today datetime.datetime(2010, 9, 16, 6, 59, 17, 241863) >>> today.ctime() 'Thu Sep 16 06:59:17 2010' Note that .ctime() is a specific historic time reporting format of very limited utility - you're a lot better off not considering it as a storage value or as a value to print, unless you actually need to work in the domains where it is used. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Tiggers don't like honey. - A.A.Milne, The House at Pooh Corner From sumerc at gmail.com Thu Sep 16 00:05:49 2010 From: sumerc at gmail.com (k3xji) Date: Wed, 15 Sep 2010 21:05:49 -0700 (PDT) Subject: select() call and filedescriptor out of range in select error Message-ID: Hi all, We have a select-based server written in Python. Occasionally, maybe twice a month there occurs a weird problem, select() returns with filedescriptor out of range in select() error. This is of course a normal error and handled gracefully. Our policy is to take down few users for select() to handle the next cycle. However, once this error occurs, this also fails too: self.__Sockets.remove(socket) self.__Socket's is the very basic list of sockets we use in our IO loop. The call fails with: remove(x): x not in list First of all, in our entire application there is no line of code like remove(x), meaning there is no x variable. Second, the Exception shows the line number containing above code. So self.__Sockets.remove(socket) this fails with remove(x): x not in list.... I cannot understand the problem. It happens in sporadic manner and it feels that the ValueError of select() call somehow corrupts the List structure itself in Python? Not sure if something like that is possible. Thanks in advance, From pavlovevidence at gmail.com Thu Sep 16 00:13:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 15 Sep 2010 21:13:33 -0700 (PDT) Subject: Numpy: Multiplying arrays of matrices References: <8fag9dF4mtU1@mid.individual.net> Message-ID: <701b305b-a684-4b79-b147-420d27f78b41@q40g2000prg.googlegroups.com> On Sep 14, 4:54?pm, Gregory Ewing wrote: > Suppose I have two N+2 dimensional arrays, representing > N-d arrays of 2-d matrices. I want to perform matrix > multiplication between corresponding matrices in these > arrays. > > I had thought that dot() might do this, but it appears > not, because e.g. applying it to two 3-d arrays gives > a 4-d array, not another 3-d array. > > I'd also like to be able to find the inverse of each > matrix in one of these arrays, but again, inv() doesn't > do what I want -- it only works on 2-d arrays. > > Any thoughts on how to achieve these things using numpy > functions? I find for situations like this the best thing I can do is hand code the bounded operation and use the slicing to handle the arbitrarily large stuff with slicing. So, r[:,:,1,1] = a[:,:,1,1]*b[:,:,1,1] + a[:,:,2,1]*b[:,:,1,2] r[:,:,1,2] = a[:,:,1,2]*b[:,:,1,1] + a[:,:,2,2]*b[:,:,1,2] etc. Carl Banks From steve-REMOVE-THIS at cybersource.com.au Thu Sep 16 00:29:39 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Sep 2010 04:29:39 GMT Subject: help with calling a static method in a private class References: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> <87r5gwgzk5.fsf@web.de> Message-ID: <4c919d33$0$11127$c3e8da3@news.astraweb.com> On Tue, 14 Sep 2010 16:38:50 +0200, Diez B. Roggisch wrote: > And additionally, but simply not using staticmethods at all. It's a > rather obscure feature of python - usually, classmethods are what is > considered a static method in other languages. Are you sure about that? I know Java isn't necessarily "other languages", but my understanding is that static methods in Java are the same as static methods in Python -- they're essentially ordinary functions glued to a class, and they don't receive either the instance or the class as an argument. http://leepoint.net/notes-java/flow/methods/50static-methods.html (Aside: I don't know about others, but I find that article *incredibly* hard to read. E.g. Static methods typically take all they data from parameters and compute something from those parameters, with no reference to variables. What, parameters aren't variables? What about local variables? I know what they *mean*, but it causes a double-take every time I read it. And when they distinguish between *classes* and *objects*, that's another double-take, because of course in Python classes are objects.) C# seems to be the same: http://dotnetperls.com/static-method as is C++ (I believe), except I'm too lazy to find a good reference. -- Steven From nad at acm.org Thu Sep 16 00:49:14 2010 From: nad at acm.org (Ned Deily) Date: Wed, 15 Sep 2010 21:49:14 -0700 Subject: select() call and filedescriptor out of range in select error References: Message-ID: In article , k3xji wrote: > We have a select-based server written in Python. Occasionally, maybe > twice a month there occurs a weird problem, select() returns with > filedescriptor out of range in select() error. This is of course a > normal error and handled gracefully. Our policy is to take down few > users for select() to handle the next cycle. However, once this error > occurs, this also fails too: > > self.__Sockets.remove(socket) > > self.__Socket's is the very basic list of sockets we use in our IO > loop. The call fails with: > remove(x): x not in list > > First of all, in our entire application there is no line of code like > remove(x), meaning there is no x variable. Second, the Exception shows > the line number containing above code. So > self.__Sockets.remove(socket) this fails with remove(x): x not in > list.... > > I cannot understand the problem. It happens in sporadic manner and it > feels that the ValueError of select() call somehow corrupts the List > structure itself in Python? Not sure if something like that is > possible. That error message is a generic exception message. It just means the object to be removed is not in the list. For example: >>> l = [a, b] >>> a, b = 1, 2 >>> l = [a, b] >>> l.remove(a) >>> l.remove(a) Traceback (most recent call last): File "", line 1, in ValueError: list.remove(x): x not in list If the problem is that the socket object in question no longer exists, you can protect your code there by enclosing the remove operation in a try block, like: try: self.__Sockets.remove(socket) except ValueError: pass -- Ned Deily, nad at acm.org From steve-REMOVE-THIS at cybersource.com.au Thu Sep 16 01:00:50 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Sep 2010 05:00:50 GMT Subject: select() call and filedescriptor out of range in select error References: Message-ID: <4c91a482$0$11127$c3e8da3@news.astraweb.com> On Wed, 15 Sep 2010 21:05:49 -0700, k3xji wrote: > Hi all, > > We have a select-based server written in Python. Occasionally, maybe > twice a month there occurs a weird problem, select() returns with > filedescriptor out of range in select() error. This is of course a > normal error and handled gracefully. Our policy is to take down few > users for select() to handle the next cycle. However, once this error > occurs, this also fails too: > > self.__Sockets.remove(socket) > > self.__Socket's is the very basic list of sockets we use in our IO loop. > The call fails with: > remove(x): x not in list Please show the *exact* error message, including the traceback, by copying and pasting it. Do not retype it by hand, or summarize it, or put it into your own words. > First of all, in our entire application there is no line of code like > remove(x), meaning there is no x variable. Look at this example: >>> sockets = [] >>> sockets.remove("Hello world") Traceback (most recent call last): File "", line 1, in ValueError: list.remove(x): x not in list "x" is just a placeholder. It doesn't refer to an actual variable x. > Second, the Exception shows > the line number containing above code. So self.__Sockets.remove(socket) > this fails with remove(x): x not in list.... Exactly. > I cannot understand the problem. It happens in sporadic manner and it > feels that the ValueError of select() call somehow corrupts the List > structure itself in Python? Not sure if something like that is possible. Anything is possible, but it's not likely. What's far more likely is that you have a bug in your code, and that somehow, under rare circumstances, it tries to remove something from a list that was never inserted into the list. Or it tries to remove it twice. My guess is something like this: try: socket = get_socket() self._sockets.append(socket) except SomeError: pass # later on self._sockets.remove(socket) -- Steven From prologic at shortcircuit.net.au Thu Sep 16 01:51:38 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 15:51:38 +1000 Subject: select() call and filedescriptor out of range in select error In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 2:49 PM, Ned Deily wrote: > If the problem is that the socket object in question no longer exists, > you can protect your code there by enclosing the remove operation in a > try block, like: The question that remains to be seen however is: Why does your list contain dirty data ? Your code has likely removed the socket object from the list before, why is it attempting to remove it again ? I would consider you re-look at your code's logic rather than patch up the code with a "band-aid-solution". cheers James -- -- James Mills -- -- "Problems are solved by method" From post at andre-bell.de Thu Sep 16 02:24:03 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Thu, 16 Sep 2010 08:24:03 +0200 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: <8fag9dF4mtU1@mid.individual.net> References: <8fag9dF4mtU1@mid.individual.net> Message-ID: <4C91B803.4080005@andre-bell.de> Hi, I assume you have arrays like these: >>> import numpy as np >>> m1 = np.random.rand(size=(4,3,3)) >>> m2 = np.random.rand(size=(4,3,3)) So that m1[0] is a 3x3 Matrix and m1[1] is another one, i.e. you have four matrices. On 09/15/2010 01:54 AM, Gregory Ewing wrote: > I had thought that dot() might do this, but it appears > not, because e.g. applying it to two 3-d arrays gives > a 4-d array, not another 3-d array. You now want to compute the matrixproducts like this >>> np.dot(m1[0], m2[0]) and most likely you want to do this for all of the pairs >>> m1m2 = np.array(map(lambda (a,b): np.dot(a,b), zip(m1,m2))) or you could write the loop >>> m1m2 = np.empty_like(m1) >>> for i in range(m1m2.shape[0]): ... m1m2[i] = np.dot(m1, m2) which might scale better > I'd also like to be able to find the inverse of each > matrix in one of these arrays, but again, inv() doesn't > do what I want -- it only works on 2-d arrays. Same as before >>> m1inv = np.array(map(np.linalg.inv, m1)) or writing the loop >>> m1inv = np.empty_like(m1) >>> for i in range(m1inv.shape[0]): ... m1inv[i] = np.linalg.inv(m1[i]) Once again, I'm not sure whether or not it is acceptable to have the overhead of treating the array as a list. Andre From nagle at animats.com Thu Sep 16 02:25:38 2010 From: nagle at animats.com (John Nagle) Date: Wed, 15 Sep 2010 23:25:38 -0700 Subject: python27.exe vs python2.7.exe ... In-Reply-To: References: Message-ID: <4c91b86f$0$1660$742ec2ed@news.sonic.net> On 9/14/2010 2:25 PM, Sridhar Ratnakumar wrote: > Hi, > > As you may already know, ActivePython provides versioned Python executables that makes it possible to invoke a particular X.Y version from the command line directly if you have multiple Python versions on PATH. Eg: > > C:\Python27\python26.exe > C:\Python27\python27.exe > C:\Python31\python31.exe > > In the upcoming releases, we are considering to change this format to match the unix executables (with a 'dot' in it). Eg: > > C:\Python27\python2.6.exe > C:\Python27\python2.7.exe > C:\Python31\python3.1.exe > > The idea is to be able to invoke "python2.7 myscript.py" on both Unix and Windows. > > Thoughts? > > Because there is bin/python3 on unix (to separate it from the default 2.x interpreter) - it is perhaps a good idea to have "C:\Python31\python3.exe" as well. > > -srid > Take a look at Debian's Python policy. http://www.debian.org/doc/packaging-manuals/python-policy/ch-python.html at "Interpreter Name". They've addressed this. Consistency would be appreciated. Thank you. John Nagle From post at andre-bell.de Thu Sep 16 02:48:23 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Thu, 16 Sep 2010 08:48:23 +0200 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: <4C91B803.4080005@andre-bell.de> References: <8fag9dF4mtU1@mid.individual.net> <4C91B803.4080005@andre-bell.de> Message-ID: <4C91BDB7.7030602@andre-bell.de> On 09/16/2010 08:24 AM, Andre Alexander Bell wrote: > or you could write the loop > > >>> m1m2 = np.empty_like(m1) > >>> for i in range(m1m2.shape[0]): > ... m1m2[i] = np.dot(m1, m2) This should have been ... m1m2[i] = np.dot(m1[i], m2[i]) Sorry for the typo. Andre From sumerc at gmail.com Thu Sep 16 02:51:34 2010 From: sumerc at gmail.com (k3xji) Date: Wed, 15 Sep 2010 23:51:34 -0700 (PDT) Subject: select() call and filedescriptor out of range in select error References: <4c91a482$0$11127$c3e8da3@news.astraweb.com> Message-ID: <0119c83d-c43e-44c0-a874-a758248e9ca6@y3g2000vbm.googlegroups.com> > Please show the *exact* error message, including the traceback, by > copying and pasting it. Do not retype it by hand, or summarize it, or put > it into your own words. Unfortunately this is not possible. The logging system I designed only gives the following information, as we have millions of logs per-day of custom exceptions I didnot include the full traceback.Here is only what I have: 1448) 15/09/10 20:02:08 - [*] ERROR: Physical max client limit reached. Please contact maintenance.filedescriptor out of range in select()[scSocketServer.py:215:][Port:515] The code generating the error is: try: self.__ReadersInCycle, self.__WritersInCycle, e = \ select( self.__Sockets, self.__WritersInCycle, [], base.scOptions.scOPT_SELECT_TIMEOUT) except ValueError, e: LogError('Physical max client limit reached.' \ ' Please contact maintenance.'+ str(e)) self.scSvr_OnClientPhysicalLimitReached() #define a policy here continue > > First of all, in our entire application there is no line of code like > > remove(x), meaning there is no x variable. > > Look at this example: > > >>> sockets = [] > >>> sockets.remove("Hello world") > > Traceback (most recent call last): > ? File "", line 1, in > ValueError: list.remove(x): x not in list > Ok. Thanks. > Anything is possible, but it's not likely. What's far more likely is that > you have a bug in your code, and that somehow, under rare circumstances, > it tries to remove something from a list that was never inserted into the > list. Or it tries to remove it twice. > > My guess is something like this: > > try: > ? ? socket = get_socket() > ? ? self._sockets.append(socket) > except SomeError: > ? ? pass > # later on > self._sockets.remove(socket) > Hmm.. Might be, but inside the self.__Sockets list there is the ListenSocket() which is the real listening socket. Naturally, I am using it in the read list of select() on every server cycle. The weird thing is that the ListenSocket itself is throwing the "not in list" exception, too! And one thing I am sure is that I have not written any kind of code that removes the Listen socket from the List, that is just impossible. Additionaly, there are very few places that I traverse the __Sockets list for optimization. The only places I delete something from the __Sockets list: 1) a user disconnects (normal disconnect, authentication or ping timeout) 3) server is being stopped or restarted Other than that there is not access to that variable from outside objects, as can be seen it is also private. And please keep in mind that this bug is there for about a year, so many code reviews have passed successfully without noticing the type of error you are suggesting. And more information on system: I am running Python 2.4 on CentOS. By the way, through digging the logs and system, it turns out select(..) is hitting the per-process FD limit. Although the system wide ulimit is unlimited, I think Python "selectmodule.c" enforces the rule to 1024. I am getting the error after hitting that limit and somehow as I just explained the __ListenSocket is being removed from the read list which causes it to be lost and Server instance is just lost forever. Putting a try..except to that code and re-init server port is a solution but I guess a bad one, because I will have not found the root cause. Thanks in advance, From steve-REMOVE-THIS at cybersource.com.au Thu Sep 16 03:14:47 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Sep 2010 07:14:47 GMT Subject: select() call and filedescriptor out of range in select error References: Message-ID: <4c91c3e7$0$11127$c3e8da3@news.astraweb.com> On Thu, 16 Sep 2010 15:51:38 +1000, James Mills wrote: > On Thu, Sep 16, 2010 at 2:49 PM, Ned Deily wrote: >> If the problem is that the socket object in question no longer exists, >> you can protect your code there by enclosing the remove operation in a >> try block, like: > > > The question that remains to be seen however is: > > Why does your list contain dirty data ? Your code has likely removed the > socket object from the list before, why is it attempting to remove it > again ? > > I would consider you re-look at your code's logic rather than patch up > the code with a "band-aid-solution". Well said. -- Steven From __peter__ at web.de Thu Sep 16 03:26:32 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Sep 2010 09:26:32 +0200 Subject: Argparse: add_argument with action=append appends to default References: Message-ID: John O'Hagan wrote: > I find this surprising: > >>>> import argparse >>>> parser = argparse.ArgumentParser() >>>> parser.add_argument('--test', action='append', default=['default']) > [...] >>>> parser.parse_args(['--test', 'arg']) > Namespace(test=['default', 'arg']) > > As an argument is provided, I didn't expect to see the default in there as > well. From the argparse docs: "the default value is used when the option > string was not present at the command line". While it doesn't say "_only_ > when...", that's what I would have expected. > > Is there a reason for this behaviour? Is there a way to do what I want, to > get a list of appended options _or_ a default list (apart from setting > defaults outside the parser, a good way to lose track of things)? You could either tweak the default value or the action: $ cat append.py import argparse class DefaultList(list): def __copy__(self): return [] if __name__ == "__main__": p = argparse.ArgumentParser() p.add_argument("-t", "--test", action="append", default=DefaultList(["default"])) print p.parse_args() $ python append.py -t one -t two Namespace(test=['one', 'two']) $ python append.py -t one Namespace(test=['one']) $ python append.py Namespace(test=['default']) $ cat append1.py import argparse class DefaultAppend(argparse._AppendAction): def __call__(self, parser, namespace, values, option_string=None): items = argparse._copy.copy(argparse._ensure_value(namespace, self.dest, [])) try: self._not_first except AttributeError: self._not_first = True del items[:] items.append(values) setattr(namespace, self.dest, items) if __name__ == "__main__": p = argparse.ArgumentParser() p.add_argument("-t", "--test", action=DefaultAppend, default=["default"]) print p.parse_args() $ python append1.py -t one -t two Namespace(test=['one', 'two']) $ python append1.py -t one Namespace(test=['one']) $ python append1.py Namespace(test=['default']) Peter From wuwei23 at gmail.com Thu Sep 16 03:39:41 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 16 Sep 2010 00:39:41 -0700 (PDT) Subject: WMI in Python References: Message-ID: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> Lawrence D'Oliveiro wrote: > Why not just call Scriptomatic directly from within the Python script, then? Because Scriptomatic _generates scripts to access WMI_, that's what it _does_. Are you _seriously_ advocating writing Python code to fire up a Windows application, programmatically manipulating a GUI to generate more Python code for your original script to import or exec? For your question to make any real sense, you'd want to ask "Why not access WMI directly...", which you might notice was the first recommendation I made. > Machine-generated code has no place in a source file to be maintained by a > human. As you've made your disdain for Windows _perfectly_ clear through your incessant sniping on this list, I think I'm pretty safe in saying you have no idea of the quality of Scriptomatic's output. I don't understand what possibly makes you believe you're qualified to make such a statement. From jeeva235 at hotmail.com Thu Sep 16 03:39:58 2010 From: jeeva235 at hotmail.com (superman) Date: Thu, 16 Sep 2010 00:39:58 -0700 (PDT) Subject: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INVESTMENT Message-ID: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INVESTMENT Generate $50 to $100 whenever you have a couple of hours free time to spare. You could make $50 or more in the next 2 hours. Starting right Now!Today! http://snipurl.com/11i6lw GET PAID TO: Take online surveys and make from $5 to $75, or more Participate in focus groups and make up to $150 an hour Take phone surveys and you can earn as much as $120 an hour Try new products (and keep the free products too) Preview new movie trailers for $4 to $25 an hour http://snipurl.com/11i6lw Earn from your free website Awesome earnings get paid for your honest work Join as a free member and get paid to your bank account To join the Network follow the link http://snipurl.com/11i6lw From k.sahithi2862 at gmail.com Thu Sep 16 04:44:34 2010 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 16 Sep 2010 01:44:34 -0700 (PDT) Subject: HOT PHOTOS&VIDEOS Message-ID: FOR HOT SEXY PHOTOS&VIDEOS [EXPOSING PHOTO] http://hotheroinesphotos.blogspot.com/2010/09/exposing-photo.html FOR HOT VIDEOS WITH SEXY PHOTO http://hotheroinesphotos.blogspot.com/2010/09/kangana-in-sexy-feel.html HOT MALLU AUNTY http://hotheroinesphotos.blogspot.com/2010/09/mallu-aunty.html LASYA HOT SEXY PHOTO http://hotheroinesphotos.blogspot.com/2010/09/sexy-lasya.html CHARMI HOT BOOBS SHOW http://hotheroinesphotos.blogspot.com/2010/09/charmi-boobs-show.html HOT MALLU AUNTY http://hotheroinesphotos.blogspot.com/2010/09/mallu-special.html SNEHA IN A BIKINI http://hotheroinesphotos.blogspot.com/2010/09/sneha-in-bikini.html From davea at ieee.org Thu Sep 16 05:46:36 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 16 Sep 2010 05:46:36 -0400 Subject: Accessing windoze file attributes In-Reply-To: References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: <4C91E77C.1050808@ieee.org> On 2:59 PM, Douglas wrote: > @Diez and @David > Thanks guys. Both excellent leads. Colour me happy. I can now make > progress and meet some deadlines. :) > > @Lawrence >> Why reinvent rsync? > In what way is rsync relevant to the stated problem? Did you actually > READ the question? > Note: I use Linux at home (yes, even rsync) and very much prefer it to > Windows. However, at work I have no choice but to use the resources > the company provides - which is Windows; have you got that straight > now? > If you have something more helpful and mature to say, relevant to the > actual question, then I will gladly hear it, and even apologise. > Otherwise, don't bother. I already enough from respondents who were > far more adult, knowledgeable and helpful ... and all the more > impressive in comparison. > > Sincerely, > -- Douglas > Let's see. You're a first-time poster on this forum, and you choose to attack Lawrence, who was giving you a succinct reference to a possible solution to your problem. So how does mentioning a program that could directly solve your problem constitute immature and unhelpful response? Have you checked out any of the several rsync implementations on Windows? Some require cygwin, but there are a couple that would seem not to. Maybe try http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp or http://www.itefix.no/i2/node/10650 There are several reasons why any particular one of these may not be appropriate for your needs, but being stuck on Windows isn't really one of them. DaveA From hobson42 at gmaiil.com Thu Sep 16 06:06:15 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 16 Sep 2010 11:06:15 +0100 Subject: business date and calendar libraries? In-Reply-To: <4C8E59FA.3060508@simplistix.co.uk> References: <4C8E59FA.3060508@simplistix.co.uk> Message-ID: <4C91EC17.9010000@gmaiil.com> On 13/09/2010 18:06, Chris Withers wrote: > Hi All, > > I'm wondering what libraries people would use to answer the following > questions relating to business days: > > - on a naive level; "what's give me the last business day" (ie: > skipping weekends) > > - on a less-naive level; same question but taking into account public > holidays > > - on a horrific level; same question, but taking into account business > days of a particular market (NYSE, LSE, etc) Hi Chris, Having written one of these for UK holidays, it was easy once I obtained a routine to calculate the date of Easter :) We decided that editing a list of holidays each year was "too hard" and so they would always be calculated so.. I had a "isWorkday()" routine that returned false for everything below, and true otherwise: Every Sat and Sun Jan 1st, and the first Monday in Jan The day after Easter day The first Monday in May (Month = May and day <= 7 and dow = Monday) The last Monday in May (day >= 25 .... The last Monday in August (day >= 25 .... Every day from 23rd Dec to the end of the year. (unique to company). I believe that officially, Christmas holiday is the first week-day on or after 25th Dec. Boxing Day/St Stephens holiday is the week-day after the Christmas holiday date above. Hope this helps. Ian From raoulbia at gmail.com Thu Sep 16 06:36:10 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 16 Sep 2010 03:36:10 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <32c15d1d-5785-488e-b957-18f486476363@l17g2000vbf.googlegroups.com> On Sep 9, 10:09?pm, Nobody wrote: > On Wed, 08 Sep 2010 03:30:00 -0700, Baba wrote: > > Who is licensed to judge what can and cannot be posted as a question? > > Exactly the same set of people who are licensed to judge what can and > cannot be posted as an answer. > > If you don't like the responses you get here, you could try posting your > questions on 4chan. If nothing else, that will give you a whole new > perspective on what an "unfriendly" response really looks like. I would to apologise to anyone who might have been upset or offended by my reaction. I am new to forums (as i am new to programming) so i hope i might be forgiven for not appreciating the true value of the support one can receive on this forum. I wish to reiterate that i underatand that experts provide help free of charge and in their spare time so there's no point for me to like or dislike the style of an answer. Baba From mummerx at gmail.com Thu Sep 16 07:50:23 2010 From: mummerx at gmail.com (Douglas) Date: Thu, 16 Sep 2010 04:50:23 -0700 (PDT) Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: @Dave Grateful thanks for your web site suggestions, and I will look them up. @Lawrence Pleasee accept my apologies. I mistook your brevity for a superior snotty attitude. From dusan.smitran at gmail.com Thu Sep 16 08:04:56 2010 From: dusan.smitran at gmail.com (dusans) Date: Thu, 16 Sep 2010 05:04:56 -0700 (PDT) Subject: Python autocomplete module Message-ID: Is there a python module to make autocomplete suggestion easy. I would build an api reference as a string: CATALOG1.SCHEME1.TABLE1.column1 CATALOG1.SCHEME1.TABLE1.column2 CATALOG1.SCHEME1.TABLE1.column3 . . CATALOG10.SCHEME10.TABLE100.column1 CATALOG10.SCHEME10.TABLE100.column2 CATALOG10.SCHEME10.TABLE100.column3 And when the user types and want suggestions he would get a nice list. Example: I trype "CATALOG10.SCHEME10." then i request autocomplete and it would return the tables in the specified scheme. Tnx From anand.shashwat at gmail.com Thu Sep 16 08:18:43 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 16 Sep 2010 17:48:43 +0530 Subject: Python autocomplete module In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 5:34 PM, dusans wrote: > Is there a python module to make autocomplete suggestion easy. > Try 'rlcompleter' module. Though I haven't tried it myself, just used it in .pythonrc for auto-completion in intepretor mode. http://docs.python.org/library/rlcompleter.html -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicoddemus at gmail.com Thu Sep 16 08:32:31 2010 From: nicoddemus at gmail.com (Bruno Oliveira) Date: Thu, 16 Sep 2010 09:32:31 -0300 Subject: Multiprocessing Queue strange behavior In-Reply-To: <4C9130F2.80000@mrabarnett.plus.com> References: <4C9130F2.80000@mrabarnett.plus.com> Message-ID: Hi, thanks for the answer. I thought about that, but the problem is that I found the problem in code that *was* using the Queue between processes. This code for example fails around 60% of the time in one of our linux machines (raising an Empty exception): from processing import Queue, Process import time def Consume(queue): print queue.get_nowait() if __name__ == '__main__': queue = Queue() queue.put('x') p = Process(target=Consume, args=(queue,)) p.start() p.join() Again, putting a sleep call before starting the consumer process makes the code work all time. That is the main reason I believe there is a problem in the Queue code somewhere. Cheers, On Wed, Sep 15, 2010 at 5:47 PM, MRAB wrote: > On 15/09/2010 21:10, Bruno Oliveira wrote: > >> Hi list, >> >> I recently found a bug in my company's code because of a strange >> behavior using multiprocessing.Queue. The following code snippet: >> >> from multiprocessing import Queue >> >> queue = Queue() >> queue.put('x') >> print queue.get_nowait() >> Fails with: >> >> ... >> File >> >> "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", >> line 153, in getNoWait >> return self.get(False) >> File >> >> "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", >> line 129, in get >> raise Empty >> Queue.Empty >> >> Strangely, changing this to: >> >> queue = Queue() >> queue.put('x') >> time.sleep(0.1) # <<< >> print queue.get_nowait() >> Works as expected. Using the original snippet changing the import to >> threading's Queue also works. >> >> It seems like there's a bug in multiprocessing's Queue implementation. >> Opinions? >> >> I don't think it's a bug as such. > > The purpose of the multiprocessing queue is to transfer data between > different processes, which don't have a shared address space (unlike > threads, which do). > > The transfer involves passing the data between the processes via a > pipe. This is done in a background thread and takes some time to > complete, so the data won't appear immediately. It looks like it > doesn't matter that the putter and the getter happen to be in the same > process, possibly because no-one expected that someone would use a > multiprocessing queue within the same process like that, so it doesn't > check for a shortcut. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kinglabs.in at gmail.com Thu Sep 16 08:41:54 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Thu, 16 Sep 2010 05:41:54 -0700 (PDT) Subject: WMI in Python References: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> Message-ID: On Sep 16, 12:39?pm, alex23 wrote: > Lawrence D'Oliveiro wrote: > > Why not just call Scriptomatic directly from within the Python script, then? > > Because Scriptomatic _generates scripts to access WMI_, that's what it > _does_. Are you _seriously_ advocating writing Python code to fire up > a Windows application, programmatically manipulating a GUI to generate > more Python code for your original script to import or exec? > > For your question to make any real sense, you'd want to ask "Why not > access WMI directly...", which you might notice was the first > recommendation I made. > > > Machine-generated code has no place in a source file to be maintained by a > > human. > > As you've made your disdain for Windows _perfectly_ clear through your > incessant sniping on this list, I think I'm pretty safe in saying you > have no idea of the quality of Scriptomatic's output. I don't > understand what possibly makes you believe you're qualified to make > such a statement. Thank you all .... looks I got lot of reading to be done now based on all your suggestions. From coolaj86 at gmail.com Thu Sep 16 09:17:58 2010 From: coolaj86 at gmail.com (AJ ONeal) Date: Thu, 16 Sep 2010 07:17:58 -0600 Subject: Stream Audio to Web Clients Message-ID: I'm looking for an example (perhaps with red5) for this scenario: 1. I install some server tools on my ubuntu box 2. I place an mp3 and an m4a in a special location 3. I click a play button on a web page and both songs play in random order AJ ONeal -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreadpiratejeff at gmail.com Thu Sep 16 11:25:06 2010 From: dreadpiratejeff at gmail.com (J) Date: Thu, 16 Sep 2010 11:25:06 -0400 Subject: Very stupid question about a % symbol Message-ID: OK, this is a very stupid question about a very simple topic, but Google is failing me this morning... I'm trying to print a string that looks like this: Reported memory amounts are within 10% tolerance and the print line looks (for now) like this: print "Reported memory amounts are within %s%s tolerance" % (self.mem_tolerance,'%') Is there a better way to print a '%' in the string when also using formating? That works, but I've been looking for a way that looks... less kludgey. I've tried things like this: print "blahblahblah %s \%" % variable but the first %s forces every other % to be interpreted as additional format markers. So while what I'm doing works, I was hoping someone could either confirm that that's the right way, or show me a better way. Cheers Jeff From googler.1.webmaster at spamgourmet.com Thu Sep 16 11:34:51 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 16 Sep 2010 08:34:51 -0700 (PDT) Subject: compile Py2.6 on SL Message-ID: Hi, I have some trouble with Python on Snow Leopard (10.6.3). I compile Python as a framework(for 32/64bit) without any problems. But implementing the lib in my C app, I get the following error on linking: Undefined symbols: "_Py_InitModule4_64", referenced from: RegisterModule_BPY(char const*, PyMethodDef*, char const*, _object*, int)in i_moduleobject.o ld: symbol(s) not found I read a lot of stuff about this problem, but nothing helped me. My app is in 64-bit and I compiled Python for 32/64bit. When I compile exactly the same package with the same configure flags under Leopard (10.5.8) it works fine. Any ideas? Thanks a lot! Bye, moerchendiser2k3 From contact at xavierho.com Thu Sep 16 12:04:42 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 17 Sep 2010 02:04:42 +1000 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: On 17 September 2010 01:25, J wrote: > Is there a better way to print a '%' in the string when also using > formating? > I believe %% will escape the % and prints it straight out. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Thu Sep 16 12:09:14 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 16 Sep 2010 16:09:14 +0000 (UTC) Subject: Very stupid question about a % symbol References: Message-ID: On 2010-09-16, J wrote: > Reported memory amounts are within 10% tolerance >>> "Reported memory amounts are within %d%% tolerance" % 10 'Reported memory amounts are within 10% tolerance' -- Grant Edwards grant.b.edwards Yow! It's the RINSE CYCLE!! at They've ALL IGNORED the gmail.com RINSE CYCLE!! From python.list at tim.thechases.com Thu Sep 16 12:14:19 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 16 Sep 2010 11:14:19 -0500 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: <4C92425B.8040301@tim.thechases.com> On 09/16/10 10:25, J wrote: > OK, this is a very stupid question about a very simple topic, but > print "Reported memory amounts are within %s%s tolerance" % > (self.mem_tolerance,'%') > > Is there a better way to print a '%' in the string when also using formating? > > I've tried things like this: > > print "blahblahblah %s \%" % variable So close print "blah %s %%" % variable -tkc From dreadpiratejeff at gmail.com Thu Sep 16 12:23:08 2010 From: dreadpiratejeff at gmail.com (J) Date: Thu, 16 Sep 2010 12:23:08 -0400 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 12:09, Grant Edwards wrote: > On 2010-09-16, J wrote: > >> Reported memory amounts are within 10% tolerance > >>>> "Reported memory amounts are within %d%% tolerance" % 10 > 'Reported memory amounts are within 10% tolerance' Thanks for the replies... I KNEW there was a simple way to escape the % but I had no idea what it was (I just had conviction). I was thrown when the \ didn't escape it... never knew about %%. But now I do! Thanks for the replies! From jason.swails at gmail.com Thu Sep 16 12:24:00 2010 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 16 Sep 2010 12:24:00 -0400 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: Ha, I had this same problem, but I was trying to do dynamic formatting: ("%%%s" % format) % number where "format" is a python-ized fortran format string (i.e. "9.4E"). Looks kinda weird and less elegant than the {0:{1}}-type .format() syntax, but at least it preserves backwards compatibility to pythons older than 2.6. Before I found out how to cancel the %, the statement looked like ("%"+"%s" % format) % number. Not much of a change, but still a nice thing to know since I play with %s a lot. Thanks! (even though I'm not the original asker) Jason On Thu, Sep 16, 2010 at 12:09 PM, Grant Edwards wrote: > On 2010-09-16, J wrote: > > > Reported memory amounts are within 10% tolerance > > >>> "Reported memory amounts are within %d%% tolerance" % 10 > 'Reported memory amounts are within 10% tolerance' > > -- > Grant Edwards grant.b.edwards Yow! It's the RINSE > CYCLE!! > at They've ALL IGNORED the > gmail.com RINSE CYCLE!! > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ron.eggler at gmail.com Thu Sep 16 12:33:06 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 16 Sep 2010 09:33:06 -0700 (PDT) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: <4138d49d-5681-40d8-8d52-761143ce645b@p22g2000pre.googlegroups.com> On Sep 15, 5:51?pm, "jipalaciosort... at gmail.com" wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > El 15/09/2010 20:58, Grant Edwards escribi?: > > > > > On 2010-09-15, cerr wrote: > > >> I get a socket error "[Errno 98] Address already in use" when i > >> try to open a socket that got closed before with close(). How > >> come close() doesn't close the socket properly? My socket code : > > >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > >> s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, > >> addr = s.accept() while conn and loop: ... ... ... conn.close() > > > At what line does the error occur? > > > To what does the phrase "open a socket" refer? > > > Have you tried the usual solution of setting the SO_REUSEADDR > > option on the socket before calling bind? > > >http://www.google.com/search?q=socket+%27address+already+in+use%27 > > Maybe, you have any other proccess in your system using your listen > port, for example apache... Nope negative, I have one process on my system only that occupies port 1514. > > - -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?_ _ _ ? _ ? _ _ _ _ ? _ _ _ > Jose Ignacio Palacios Ortega ? ? ? ? ? ? ?/_ ? _/ / / / ?_ ? / / _ ? / > Telf: +34 637 058 813 ? ? ? ? ? ? ? ? ? ? ? / / ?/ / / /_ / / / / / / > Correo-e: jipalaciosort... at gmail.com ?_ ? ?/ / ?/ / / _ _ _/ / / / / > Msn: jipalaciosort... at gmail.com ? ? ?/ /_ / / ?/ / / / ? ? ?/ /_/ / > ID firma PGP: 0x0EB87E48 ? ? ? ? ? ? \ _ _ / ?/_/ /_/ ? ? ?/_ _ _/ > Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48 > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (MingW32) > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ > > iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ > 4cgAniOoR70hu7UylkpgAr3JI5hxNXYP > =MoYK > -----END PGP SIGNATURE----- From tom.browder at gmail.com Thu Sep 16 12:33:25 2010 From: tom.browder at gmail.com (Tom Browder) Date: Thu, 16 Sep 2010 11:33:25 -0500 Subject: Python 2.7 Won't Build Message-ID: I am trying to rebujild the 2.7 maintenance branch and get this error on Ubuntu 10.04.1 LTS: XXX lineno: 743, opcode: 0 Traceback (most recent call last): File "/usr/local/src/python-2.7-maint-svn/Lib/site.py", line 62, in import os File "/usr/local/src/python-2.7-maint-svn/Lib/os.py", line 743, in def urandom(n): SystemError: unknown opcode I installed it successfully once so I may be getting conflicts, but I can't figure it out. There were some similar bugs reported in previous versions but I didn't see a clear solution. I have unset my PYTHONPATH and LD_LIBRARY_PATH, but python2.7 is my default python. I guess my next step will be to manually remove python 2.7 unless I hear some solutions soon. Thanks, -Tom Thomas M. Browder, Jr. Niceville, Florida USA From ron.eggler at gmail.com Thu Sep 16 12:43:45 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 16 Sep 2010 09:43:45 -0700 (PDT) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Sep 15, 11:58?am, Grant Edwards wrote: > On 2010-09-15, cerr wrote: > > > > > > > I get a socket error "[Errno 98] Address already in use" when i try to > > open a socket that got closed before with close(). How come close() > > doesn't close the socket properly? > > My socket code : > > > ? s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > ? s.bind((host, port)) > > ? s.listen(1) > > ... > > ... > > ... > > ? while loop: > > ? ? conn, addr = s.accept() > > ? ? while conn and loop: > > ... > > ... > > ... > > ? ? ?conn.close() > > At what line does the error occur? The whole message I get looks like: Traceback (most recent call last): File "./checkGPIO.py", line 148, in main() File "./checkGPIO.py", line 75, in main s.bind((host, port)) File "", line 1, in bind socket.error: [Errno 98] Address already in use Where line 75 contains following: s.bind((host, port)) > > To what does the phrase "open a socket" refer? create a listening socket...? > Have you tried the usual solution of setting the SO_REUSEADDR option > on the socket before calling bind? yep, that did it for me, thanks a lot! :) > http://www.google.com/search?q=socket+%27address+already+in+use%27 Google's your friend if you can read ;) > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! I own seven-eighths of > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? all the artists in downtown > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ?Burbank! From mark.pelletier at asrcms.com Thu Sep 16 12:55:51 2010 From: mark.pelletier at asrcms.com (mark.pelletier at asrcms.com) Date: Thu, 16 Sep 2010 09:55:51 -0700 (PDT) Subject: Too many threads Message-ID: <716be5f9-79b9-43c7-9c04-0454d015086d@j30g2000vbr.googlegroups.com> For some reason, the tasks I put into my thread pool occasionally get run more than once. Here's the code: # ------------------------------------------------------------------------------------------------------------------- from threading import Thread from queue import Queue import subprocess class ThreadPool(object): def __init__(self, thread_count): ''' Argument thread_count is the maximum number of theads. ''' self.thread_count = thread_count self.queue = Queue() # create and start the threads for i in range(self.thread_count): t = Thread(target=self._worker) t.daemon = True t.start() def _worker(self): ''' A "private" method that pulls tasks off the queue and does something with them. ''' while True: item = self.queue.get() print(item) self.queue.task_done() def run(self, tasklist): ''' Put tasks in the queue. ''' for item in tasklist: self.queue.put(item) # block until all threads are done. self.queue.join() # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - tasklist = [ 'task1', 'task2', 'task3', 'task4', 'task5', 'task6', 'task7', 'task8', 'task9', 'task10', 'task11', 'task12', 'task13', 'task14', 'task15', 'task16'] if __name__ == '__main__': t = ThreadPool(3) t.run(tasklist) #--------------------------------------------------------------------------------------------------- And here's some typical output: task1 task2 task2 task3 task4 task5 task5 task6 task7 task8 task8 task9 task8 task9 task10 task11 task11 task12 task13 task13 task14 task15 task15 task16 I only want a task to get fired off once. What am I doing wrong? Thanks! From hansyin at gmail.com Thu Sep 16 13:19:32 2010 From: hansyin at gmail.com (Hans) Date: Thu, 16 Sep 2010 10:19:32 -0700 (PDT) Subject: program organization question for web development with python References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> Message-ID: <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> On Sep 15, 5:33?pm, James Mills wrote: > On Thu, Sep 16, 2010 at 10:14 AM, Hans wrote: > > I'm new to this area. Please allow me to ask some (maybe stupid) > > questions. > > Without reading the rest of your post too much. Designs are up to you, > I can't comment. > > I can only share in a fairly common view, and that is, we'd encourage > you to use a web framework > as opposed to plain old CGI. > > cheers > james > > -- > -- James Mills > -- > -- "Problems are solved by method" Hi James, Thanks for response. Maybe I did not make my question clear. I never tried python web programing before, so I want to start from CGI. I read something about web framework like django, but seems it's a little bit complicated. my task is actually very simple: get search string from input, and then search database, print search result. I thought CGI should be good enough to do this. I don't have any idea about how to organize those cgi codes, so what I'm asking is: 1. do I have to have each single file for each hyper-link? Can I put them together? how? 2. how can I pass a db_cursor to another file? can I use db_cursor as a parameter? Thanks again! Hans From lehmannmapson at cnm.de Thu Sep 16 13:40:02 2010 From: lehmannmapson at cnm.de (Marten Lehmann) Date: Thu, 16 Sep 2010 19:40:02 +0200 Subject: Problem building python 2.7 with --enable-shared Message-ID: <8ff33iFi97U1@mid.individual.net> Hello, I've build python 2.7 successfully by just calling configure, make and make install. But to use python within PostgreSQL, I need to built python with --enable-shared. I tried to do so (configure --enable-shared), but I see these lines several times in the log (but compiling continues): /usr/bin/ld: /test/python/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /test/python/lib/libpython2.7.a: could not read symbols: Bad value collect2: ld returned 1 exit status Later, the compiling process ends completely: PYTHONPATH=/var/tmp/vrmd-python2-root/test/python/lib/python2.7 LD_LIBRARY_PATH=/usr/src/redhat/BUILD/Python-2.7: \ ./python -Wi -tt /var/tmp/vrmd-python2-root/test/python/lib/python2.7/compileall.py \ -d /test/python/lib/python2.7 -f \ -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ /var/tmp/vrmd-python2-root/test/python/lib/python2.7 Traceback (most recent call last): File "/var/tmp/vrmd-python2-root/test/python/lib/python2.7/compileall.py", line 17, in import struct File "/var/tmp/vrmd-python2-root/test/python/lib/python2.7/struct.py", line 1, in from _struct import * ImportError: No module named _struct make: *** [libinstall] Error 1 Any ideas, what I have done wrong? Kind regards Marten From python at mrabarnett.plus.com Thu Sep 16 14:01:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Sep 2010 19:01:58 +0100 Subject: program organization question for web development with python In-Reply-To: <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> Message-ID: <4C925B96.60000@mrabarnett.plus.com> On 16/09/2010 18:19, Hans wrote: > On Sep 15, 5:33 pm, James Mills wrote: >> On Thu, Sep 16, 2010 at 10:14 AM, Hans wrote: >>> I'm new to this area. Please allow me to ask some (maybe stupid) >>> questions. >> >> Without reading the rest of your post too much. Designs are up to you, >> I can't comment. >> >> I can only share in a fairly common view, and that is, we'd encourage >> you to use a web framework >> as opposed to plain old CGI. >> >> cheers >> james >> >> -- >> -- James Mills >> -- >> -- "Problems are solved by method" > > Hi James, > > Thanks for response. > Maybe I did not make my question clear. I never tried python web > programing before, so I want to start from CGI. > > I read something about web framework like django, but seems it's a > little bit complicated. my task is actually very simple: get search > string from input, and then search database, print search result. I > thought CGI should be good enough to do this. > > I don't have any idea about how to organize those cgi codes, so what > I'm asking is: > > 1. do I have to have each single file for each hyper-link? Can I put > them together? how? > 2. how can I pass a db_cursor to another file? can I use db_cursor as > a parameter? > I recently wrote a web-based program using CherryPy, which was very straightforward. That might suit your needs. From iurisilvio at gmail.com Thu Sep 16 14:09:02 2010 From: iurisilvio at gmail.com (Iuri) Date: Thu, 16 Sep 2010 15:09:02 -0300 Subject: program organization question for web development with python In-Reply-To: <4C925B96.60000@mrabarnett.plus.com> References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> <4C925B96.60000@mrabarnett.plus.com> Message-ID: Another pretty web framework is Bottle (http://bottle.paws.de). It is very easy to setup and use. I use it to tasks like this one you want. []s iuri On Thu, Sep 16, 2010 at 3:01 PM, MRAB wrote: > On 16/09/2010 18:19, Hans wrote: > >> On Sep 15, 5:33 pm, James Mills wrote: >> >>> On Thu, Sep 16, 2010 at 10:14 AM, Hans wrote: >>> >>>> I'm new to this area. Please allow me to ask some (maybe stupid) >>>> questions. >>>> >>> >>> Without reading the rest of your post too much. Designs are up to you, >>> I can't comment. >>> >>> I can only share in a fairly common view, and that is, we'd encourage >>> you to use a web framework >>> as opposed to plain old CGI. >>> >>> cheers >>> james >>> >>> -- >>> -- James Mills >>> -- >>> -- "Problems are solved by method" >>> >> >> Hi James, >> >> Thanks for response. >> Maybe I did not make my question clear. I never tried python web >> programing before, so I want to start from CGI. >> >> I read something about web framework like django, but seems it's a >> little bit complicated. my task is actually very simple: get search >> string from input, and then search database, print search result. I >> thought CGI should be good enough to do this. >> >> I don't have any idea about how to organize those cgi codes, so what >> I'm asking is: >> >> 1. do I have to have each single file for each hyper-link? Can I put >> them together? how? >> 2. how can I pass a db_cursor to another file? can I use db_cursor as >> a parameter? >> >> I recently wrote a web-based program using CherryPy, which was very > straightforward. That might suit your needs. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lehmannmapson at cnm.de Thu Sep 16 14:11:23 2010 From: lehmannmapson at cnm.de (Marten Lehmann) Date: Thu, 16 Sep 2010 20:11:23 +0200 Subject: Problem building python 2.7 with --enable-shared In-Reply-To: <8ff33iFi97U1@mid.individual.net> References: <8ff33iFi97U1@mid.individual.net> Message-ID: <8ff4ubFt5tU1@mid.individual.net> The strange thing is: This only happens when I'm compiling through rpmbuild. Issuing the same commands (configure --enable-shared, make, make install) directly on the shell works fine... From thomas at jollybox.de Thu Sep 16 14:12:38 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 16 Sep 2010 20:12:38 +0200 Subject: Problem building python 2.7 with --enable-shared In-Reply-To: <8ff33iFi97U1@mid.individual.net> References: <8ff33iFi97U1@mid.individual.net> Message-ID: <201009162012.39459.thomas@jollybox.de> On Thursday 16 September 2010, it occurred to Marten Lehmann to exclaim: > Hello, > > I've build python 2.7 successfully by just calling configure, make and > make install. But to use python within PostgreSQL, I need to built > python with --enable-shared. > > I tried to do so (configure --enable-shared), but I see these lines > several times in the log (but compiling continues): Did you start with a clean source tree? If you just reconfigured and called make again in the source tree where you already had built Python, make will just re-use the old object files, which would be built without -fPIC and whatever other options are required for the shared library linking to work. > > /usr/bin/ld: /test/python/lib/libpython2.7.a(abstract.o): relocation > R_X86_64_32 against `a local symbol' can not be used when making a > shared object; recompile with -fPIC > /test/python/lib/libpython2.7.a: could not read symbols: Bad value > collect2: ld returned 1 exit status If you get this when building from a fresh source tree, I can't explain why this might happen, but, again, starting afresh, this time adding -fPIC to the CFLAGS, may work. But I expect that the configure script, or makefile, or libtool, or whatever, should do this, hence my guess that maybe you're using leftover object files. (hint: make clean) > > Later, the compiling process ends completely: > > PYTHONPATH=/var/tmp/vrmd-python2-root/test/python/lib/python2.7 > LD_LIBRARY_PATH=/usr/src/redhat/BUILD/Python-2.7: \ > ./python -Wi -tt > /var/tmp/vrmd-python2-root/test/python/lib/python2.7/compileall.py \ > -d /test/python/lib/python2.7 -f \ > -x > 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ > /var/tmp/vrmd-python2-root/test/python/lib/python2.7 > Traceback (most recent call last): > File > "/var/tmp/vrmd-python2-root/test/python/lib/python2.7/compileall.py", > line 17, in > import struct > File > "/var/tmp/vrmd-python2-root/test/python/lib/python2.7/struct.py", line > 1, in > from _struct import * > ImportError: No module named _struct > make: *** [libinstall] Error 1 > > Any ideas, what I have done wrong? > > Kind regards > Marten From lehmannmapson at cnm.de Thu Sep 16 15:02:53 2010 From: lehmannmapson at cnm.de (Marten Lehmann) Date: Thu, 16 Sep 2010 21:02:53 +0200 Subject: Problem building python 2.7 with --enable-shared In-Reply-To: References: <8ff33iFi97U1@mid.individual.net> Message-ID: <8ff7utFh63U1@mid.individual.net> I digged into this one step further: I compared the output of configure and make. For configure, there is no change. But for make, I found out something, that I didn't expected: When configure is called with a prefix to a location, where a valid python installation already exists, it uses these locations for gcc, although it shouldn't (we are about to compile a clean, brandnew python version, so why should it include parts of an existing python installation?). Additionally to the default include paths gcc [...] -I. -IInclude -I./Include -I/usr/local/include -I/usr/src/redhat/BUILD/Python-2.7/Include -I/usr/src/redhat/BUILD/Python-2.7 [...] the path of the existing Python installation is added: -I/test/python2/include And additionally the default library paths and libs gcc [...] -L/usr/local/lib -L. -lpython2.7 [...] the path of the existing Python libs is added: gcc [...9 -L/vrmd/python2/lib So linking to python2.7 during make doesn't link to the freshly build library, but to the existing in the system. And at least in my case, where I'm switching from a python installation without --enabled-shared to a new version including --enable-shared, this causes serious problems: /usr/bin/ld: /vrmd/python2/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC -/vrmd/python2/lib/libpython2.7.a: could not read symbols: Bad value -collect2: ld returned 1 exit status Is there any option I missed in configure or any variable that I might set to correct this? Or should a file a bug to the python developers? Deinstalling python before compiling or renaming the python directory is not a good solution. Kind regards Marten From rdh at new.rr.com Thu Sep 16 15:35:46 2010 From: rdh at new.rr.com (DataSmash) Date: Thu, 16 Sep 2010 12:35:46 -0700 (PDT) Subject: Too much code - slicing Message-ID: I need to create a simple utility to remove characters from either the right or left side of directories. This works, but there has to be a better way. I tried to use a variable inside the brackets but I can't get that to work. Can anyone think of a way to do this with less code? Thanks! import os dirs = filter(os.path.isdir, os.listdir('')) for dir in dirs: # Left side if num == '1' and side == "l": code = dir[1:] if num == '2' and side == "l": code = dir[2:] if num == '3' and side == "l": code = dir[3:] if num == '4' and side == "l": code = dir[4:] if num == '5' and side == "l": code = dir[5:] if num == '6' and side == "l": code = dir[6:] if num == '7' and side == "l": code = dir[7:] if num == '8' and side == "l": code = dir[8:] if num == '9' and side == "l": code = dir[9:] if num == '10' and side == "l": code = dir[10:] # Right side if num == '1' and side == "r": code = dir[:-1] if num == '2' and side == "r": code = dir[:-2] if num == '3' and side == "r": code = dir[:-3] if num == '4' and side == "r": code = dir[:-4] if num == '5' and side == "r": code = dir[:-5] if num == '6' and side == "r": code = dir[:-6] if num == '7' and side == "r": code = dir[:-7] if num == '8' and side == "r": code = dir[:-8] if num == '9' and side == "r": code = dir[:-9] if num == '10' and side == "r": code = dir[:-10] print " Renaming "+dir+" to "+code os.rename(dir, code) From benjamin.kaplan at case.edu Thu Sep 16 15:47:49 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 16 Sep 2010 15:47:49 -0400 Subject: Too much code - slicing In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 3:35 PM, DataSmash wrote: > I need to create a simple utility to remove characters from either the > right or left side of directories. > This works, but there has to be a better way. ?I tried to use a > variable inside the brackets but I can't get > that to work. ?Can anyone think of a way to do this with less code? > Thanks! > > import os > > dirs = filter(os.path.isdir, os.listdir('')) > for dir in dirs: > > ? ?# Left side The int() type will convert a string to an int for you. So all you need to do is check the side and slice accordingly. if side=='l': code = dir[int(num):] else : code = dir[:-1*int(num)] From andrei.avk at gmail.com Thu Sep 16 16:20:33 2010 From: andrei.avk at gmail.com (AK) Date: Thu, 16 Sep 2010 16:20:33 -0400 Subject: Too much code - slicing In-Reply-To: References: Message-ID: <4C927C11.8050805@gmail.com> On 09/16/2010 03:47 PM, Benjamin Kaplan wrote: > On Thu, Sep 16, 2010 at 3:35 PM, DataSmash wrote: >> I need to create a simple utility to remove characters from either the >> right or left side of directories. >> This works, but there has to be a better way. I tried to use a >> variable inside the brackets but I can't get >> that to work. Can anyone think of a way to do this with less code? >> Thanks! >> >> import os >> >> dirs = filter(os.path.isdir, os.listdir('')) >> for dir in dirs: >> >> # Left side > > > The int() type will convert a string to an int for you. So all you > need to do is check the side and slice accordingly. > > if side=='l': > code = dir[int(num):] > else : > code = dir[:-1*int(num)] I also like this construct that works, I think, since 2.6: code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] -ak From rdh at new.rr.com Thu Sep 16 16:40:14 2010 From: rdh at new.rr.com (DataSmash) Date: Thu, 16 Sep 2010 13:40:14 -0700 (PDT) Subject: Too much code - slicing References: Message-ID: <74f71197-f6a7-42ab-93e6-7af1de8e646f@j2g2000vbo.googlegroups.com> On Sep 16, 2:47?pm, Benjamin Kaplan wrote: > On Thu, Sep 16, 2010 at 3:35 PM, DataSmash wrote: > > I need to create a simple utility to remove characters from either the > > right or left side of directories. > > This works, but there has to be a better way. ?I tried to use a > > variable inside the brackets but I can't get > > that to work. ?Can anyone think of a way to do this with less code? > > Thanks! > > > import os > > > dirs = filter(os.path.isdir, os.listdir('')) > > for dir in dirs: > > > ? ?# Left side > > > > The int() type will convert a string to an int for you. So all you > need to do is check the side and slice accordingly. > > if side=='l': > ? ? code = dir[int(num):] > else : > ? ? code = dir[:-1*int(num)] Much appreciated! I thought I tried every combination, guess I didn't try this as it works great. Thanks again. From b.f.lundin at gmail.com Thu Sep 16 17:40:25 2010 From: b.f.lundin at gmail.com (=?ISO-8859-1?Q?bj=F6rn_lundin?=) Date: Thu, 16 Sep 2010 14:40:25 -0700 (PDT) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: <9e71eee4-ccfa-439f-905b-47351ef06197@e20g2000vbn.googlegroups.com> > Where line 75 contains following: > s.bind((host, port)) As Tomas pointed out, you close conn, but you do not close the server socket 's' /Bj?rn From nagle at animats.com Thu Sep 16 17:46:45 2010 From: nagle at animats.com (John Nagle) Date: Thu, 16 Sep 2010 14:46:45 -0700 Subject: The trouble with "dynamic attributes". In-Reply-To: References: Message-ID: <4c929052$0$1601$742ec2ed@news.sonic.net> There's a tendency to use "dynamic attributes" in Python when trying to encapsulate objects from other systems. It almost works. But it's usually a headache in the end, and should be discouraged. Here's why. Some parsers, like BeautifulSoup, try to encapsulate HTML tag fields as Python attributes. This gives trouble for several reasons. First, the syntax for Python attributes and Python tags is different. Some strings won't convert to attributes. You can crash BeautifulSoup (which is supposed to be robust against bad HTML) by using a non-ASCII character in a tag in an HTML document it is parsing. Then there's the reserved word problem. "class" is a valid field name in HTML, and a reserved word in Python. So there has to be a workaround for reserved words. There's also the problem that user-created attributes go into the same namespace as other object attributes. This creates a vulnerability comparable to MySQL injection. If an attacker controls the input being parsed, they may be able to induce a store into something they shouldn't be able to access. This problem shows up again in "suds", the module for writing SOAP RPC clients. This module tries to use attributes for XML structures, and it almost works. It tends to founder when the XML data model has strings that aren't valid attributes. ("-" appears frequently in XML fields, but is not valid in an attribute name.) Using a dictionary, or inheriting an object from "dict", doesn't create these problems. The data items live in their own dictionary, and can't clash with anything else. Of course, you have to write tag['a'] instead of tag.a but then, at least you know what to do when you need tag['class'] "suds", incidentally, tries to do both. They accept both item.fieldname and item['fieldname'] But they are faking a dictionary, and it doesn't quite work right. 'fieldname' in item works correctly, but the form to get None when the field is missing, item.get('fieldname',None) isn't implemented. Much of the code that uses objects as dictionaries either predates the days when you couldn't inherit from "dict", or was written by Javascript programmers. (In Javascript, an object and a dictionary are the same thing. In Python, they're not.) In new code, it's better to inherit from "dict". It eliminates the special cases. John Nagle From prologic at shortcircuit.net.au Thu Sep 16 18:06:03 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 08:06:03 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c929052$0$1601$742ec2ed@news.sonic.net> References: <4c929052$0$1601$742ec2ed@news.sonic.net> Message-ID: On Fri, Sep 17, 2010 at 7:46 AM, John Nagle wrote: > There's a tendency to use "dynamic attributes" in Python when > trying to encapsulate objects from other systems. ?It almost > works. ?But it's usually a headache in the end, and should be > discouraged. ?Here's why. What do you mean by "dynamic attributes " ? Can you show a simple code example ? cheers James -- -- James Mills -- -- "Problems are solved by method" From vlastimil.brom at gmail.com Thu Sep 16 18:11:25 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 17 Sep 2010 00:11:25 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) Message-ID: Hi all, I'd like to ask for suggestions regarding suitable datastracture for storing textual metadata along with a plain text string. The input format I have is simply text with custom tags like ; I'd prefer to have this human readable format the original data source. For the application, the tags are extracted and stored in a custom datastructure along with the plain text.The queries should either return the tagset for a given text position (index) or reversely the text indices for a given tag-value combination.. (I posted some more detailed remarks earlier, as I was beginning with this topic http://mail.python.org/pipermail/python-list/2007-December/1130275.html http://mail.python.org/pipermail/python-list/2008-May/1141958.html Meanwhile I managed to get working code using python native datastructures (nested defaultdicts and sets); however after some time I am now planning to adapt this code for a web-based program and am considering alternative datastructures, for simplicity I started with sqlite (which should actually suffice for the data volume and traffic in question). I put together some code, which works as expected, but I suspect somehow, that there must be better ways of doing it. Two things I am not quite clear about are using the placeholders for the data identifiers and "chaining" the SELECT parameters. I Couldn't find a way to use "?" placeholder for table or column names, hence I ended up using string interpolation for them and placeholders for the data values, like. curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, index_col), (text_index,)) is there a better way or is it not supposed to supply these identifiers programatically? For getting the matching text indices given the tags, tag_values combination I ended up with a clumsy query: combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % (index_col, text_name, tag) for tag in tags] sql_query = " INTERSECT ".join(combined_query_list) curs.execute(sql_query, tag_values) which produces e.g.: SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" WHERE "VN"==? or alternatively: select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) sql_query = select_begin + where_subquery with the resulting query string like: SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') (BTW, are these queries equivalent, as the outputs suggest, or are there some distinctions to be aware of?) Anyway, I can't really believe, this would be the expected way ... (I only marginally looked into sqlalchemy, which might simplify this a bit, is this true? - Currently I only use the standard lib, depending on the available server setup (python 2.6)). Thanks in advance for any suggestions or pointers on both the sql usage as well as the general datatype question. regards, Vlastimil Brom From david at boddie.org.uk Thu Sep 16 18:23:26 2010 From: david at boddie.org.uk (David Boddie) Date: Fri, 17 Sep 2010 00:23:26 +0200 Subject: Deleting widgets from PyQt4 QFormWidget References: Message-ID: On Wednesday 15 September 2010 18:53, Andrew wrote: > I'm trying to remove the widgets from the QFormLayout widget from > PyQt4. According to the documentation I should be able to use the > command .takeAt(int) which will delete the widget from the layout and > then return to me the QLayoutWidget. It will remove the widget from the layout but it won't delete it because it doesn't own it. The widget will still remain within its parent widget. You have to either reparent it to another widget, or delete it manually. [...] > Am I missing a step or is this just broken? I haven't been able to > find anything else on this issue yet. If it's broke, is there any > potential workaround? Try calling deleteLater() on each widget when you take it from the layout. Does that work? David From python at mrabarnett.plus.com Thu Sep 16 19:17:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 00:17:24 +0100 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: Message-ID: <4C92A584.8060303@mrabarnett.plus.com> On 16/09/2010 23:11, Vlastimil Brom wrote: > Hi all, > I'd like to ask for suggestions regarding suitable datastracture for > storing textual metadata along with a plain text string. > The input format I have is simply text with custom tags like tag_value>; I'd prefer to have this human readable format the original > data source. > For the application, the tags are extracted and stored in a custom > datastructure along with the plain text.The queries should either > return the tagset for a given text position (index) or reversely the > text indices for a given tag-value combination.. > (I posted some more detailed remarks earlier, as I was beginning with this topic > http://mail.python.org/pipermail/python-list/2007-December/1130275.html > http://mail.python.org/pipermail/python-list/2008-May/1141958.html > > Meanwhile I managed to get working code using python native > datastructures (nested defaultdicts and sets); however after some time > I am now planning to adapt this code for a web-based program and am > considering alternative datastructures, for simplicity I started with > sqlite (which should actually suffice for the data volume and traffic > in question). > > I put together some code, which works as expected, but I suspect > somehow, that there must be better ways of doing it. > > Two things I am not quite clear about are using the placeholders for > the data identifiers and "chaining" the SELECT parameters. > > I Couldn't find a way to use "?" placeholder for table or column > names, hence I ended up using string interpolation for them and > placeholders for the data values, like. > curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, > index_col), (text_index,)) > is there a better way or is it not supposed to supply these > identifiers programatically? > You would normally expect the structure of the database to be fixed and only the contents to vary. > For getting the matching text indices given the tags, tag_values > combination I ended up with a clumsy query: > > combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % > (index_col, text_name, tag) for tag in tags] > sql_query = " INTERSECT ".join(combined_query_list) > curs.execute(sql_query, tag_values) > > which produces e.g.: > SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" > WHERE "VN"==? > > or alternatively: > > select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) > where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) > sql_query = select_begin + where_subquery > > with the resulting query string like: > SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') > > (BTW, are these queries equivalent, as the outputs suggest, or are > there some distinctions to be aware of?) > > Anyway, I can't really believe, this would be the expected way ... > If you're selecting rows of a table then using 'AND' would seem the obvious way. > (I only marginally looked into sqlalchemy, which might simplify this a > bit, is this true? - Currently I only use the standard lib, depending > on the available server setup (python 2.6)). > > Thanks in advance for any suggestions or pointers on both the sql > usage as well as the general datatype question. > > regards, > Vlastimil Brom From python at mrabarnett.plus.com Thu Sep 16 19:27:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 00:27:08 +0100 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c929052$0$1601$742ec2ed@news.sonic.net> References: <4c929052$0$1601$742ec2ed@news.sonic.net> Message-ID: <4C92A7CC.8000505@mrabarnett.plus.com> On 16/09/2010 22:46, John Nagle wrote: > There's a tendency to use "dynamic attributes" in Python when > trying to encapsulate objects from other systems. It almost > works. But it's usually a headache in the end, and should be > discouraged. Here's why. > > Some parsers, like BeautifulSoup, try to encapsulate HTML tag > fields as Python attributes. This gives trouble for several reasons. > First, the syntax for Python attributes and Python tags is different. > Some strings won't convert to attributes. You can crash BeautifulSoup > (which is supposed to be robust against bad HTML) by using a non-ASCII > character in a tag in an HTML document it is parsing. > > Then there's the reserved word problem. "class" is a valid field > name in HTML, and a reserved word in Python. So there has to be a > workaround for reserved words. > > There's also the problem that user-created attributes go into the > same namespace as other object attributes. This creates a vulnerability > comparable to MySQL injection. If an attacker controls the input > being parsed, they may be able to induce a store into something > they shouldn't be able to access. > > This problem shows up again in "suds", the module for writing > SOAP RPC clients. This module tries to use attributes for > XML structures, and it almost works. It tends to founder when > the XML data model has strings that aren't valid attributes. > ("-" appears frequently in XML fields, but is not valid in an > attribute name.) > > Using a dictionary, or inheriting an object from "dict", doesn't > create these problems. The data items live in their own dictionary, > and can't clash with anything else. Of course, you have to write > > tag['a'] > > instead of > > tag.a > > but then, at least you know what to do when you need > > tag['class'] > > "suds", incidentally, tries to do both. They accept both > > item.fieldname > > and > > item['fieldname'] > > But they are faking a dictionary, and it doesn't quite work right. > > 'fieldname' in item > > works correctly, but the form to get None when the field is missing, > > item.get('fieldname',None) > > isn't implemented. > > Much of the code that uses objects as dictionaries either predates > the days when you couldn't inherit from "dict", or was written by > Javascript programmers. (In Javascript, an object and a dictionary > are the same thing. In Python, they're not.) In new code, it's > better to inherit from "dict". It eliminates the special cases. > For the work on updating the re module there was a discussion about whether named capture groups should be available as attributes of the match object or via subscripting (or both?). Subscripting seemed preferable to me because: 1. Adding attributes looks too much like 'magic'. 2. What should happen if a group name conflicts with a normal attribute? 3. What should happen if a group name conflicts with a reserved word? For those reasons the new regex module uses subscripting. It's more Pythonic, IMHO. From prologic at shortcircuit.net.au Thu Sep 16 19:36:15 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 09:36:15 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <4C92A7CC.8000505@mrabarnett.plus.com> References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4C92A7CC.8000505@mrabarnett.plus.com> Message-ID: On Fri, Sep 17, 2010 at 9:27 AM, MRAB wrote: > For the work on updating the re module there was a discussion about > whether named capture groups should be available as attributes of the > match object or via subscripting (or both?). Subscripting seemed > preferable to me because: > > 1. Adding attributes looks too much like 'magic'. > > 2. What should happen if a group name conflicts with a normal attribute? > > 3. What should happen if a group name conflicts with a reserved word? > > For those reasons the new regex module uses subscripting. It's more > Pythonic, IMHO. I agree with 2) and 3) and in general this is probably a "good approach". cheers James -- -- James Mills -- -- "Problems are solved by method" From jeanluc434 at gmail.com Thu Sep 16 19:36:55 2010 From: jeanluc434 at gmail.com (Jean Luc Truchtersheim) Date: Thu, 16 Sep 2010 16:36:55 -0700 (PDT) Subject: File read from stdin and printed to temp file are not identicial? Message-ID: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Hello, I am trying to read from stdin and dump what's read to a temporary file. My code works for small files but as soon as I have a file that has, e.g., more than 300 lines, there is always one and only one line that is truncated compared to the input. Here is my code: #--------------------------------------------------------------------------------- #! /usr/bin/env python import sys from tempfile import * if __name__ == "__main__": data = [] f_in = NamedTemporaryFile(suffix=".txt", delete=False) for line in sys.stdin: f_in.write(line) data.append(line) f_in.close f = open(f_in.name, 'rb') i=0 for line in f: if data[i] != line: print >>sys.stderr, "line %d:\nfile(%d):\"%s\"\narray(%d):\"%s\"" % (i+1, len(line), line, len(data[i]), data[i]) i += 1 sys.exit() #------------------------------------------------------------------------------------------------- I feel that I must be doing something very stupid, but I don't really know what. Any idea? Can anybody reproduce this behavior. Thanks a bunch for any help. Jean Luc. From vlastimil.brom at gmail.com Thu Sep 16 19:56:49 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 17 Sep 2010 01:56:49 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: <4C92A584.8060303@mrabarnett.plus.com> References: <4C92A584.8060303@mrabarnett.plus.com> Message-ID: 2010/9/17 MRAB : > On 16/09/2010 23:11, Vlastimil Brom wrote: >> >>... >> I put together some code, which works as expected, but I suspect >> somehow, that there must be better ways of doing it. >> >> Two things I am not quite clear about are using the placeholders for >> the data identifiers and "chaining" the SELECT parameters. >> >> I Couldn't find a way to use "?" placeholder for table or column >> names, hence I ended up using string interpolation for them and >> placeholders for the data values, like. >> curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, >> index_col), (text_index,)) >> is there a better way or is it not supposed to supply these >> identifiers programatically? >> > You would normally expect the structure of the database to be fixed and > only the contents to vary. > >> For getting the matching text indices given the tags, tag_values >> combination I ended up with a clumsy query: >> >> combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % >> (index_col, text_name, tag) for tag in tags] >> sql_query = " INTERSECT ".join(combined_query_list) >> curs.execute(sql_query, tag_values) >> >> which produces e.g.: >> SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" >> WHERE "VN"==? >> >> or alternatively: >> >> select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) >> where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) >> sql_query = select_begin + where_subquery >> >> with the resulting query string like: >> SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') >> >> (BTW, are these queries equivalent, as the outputs suggest, or are >> there some distinctions to be aware of?) >> >> Anyway, I can't really believe, this would be the expected way ... >> > If you're selecting rows of a table then using 'AND' would seem the > obvious way. > > Thanks for the answer, Well, that may be a part of the problem, the database structure is going to be fixed once I'll have the text sources complete, but I was trying to keep it more general, also allowing the identifiers to be passed programmatically (based on the tagged text in question). yes, I am just selecting rows - based on the combination of the column values (which, I guess, might be an usual database approach(?). However, I was unsure, whether it is usual to construct the query string this way - partly using string interpolation or sequence joining. Or should there normally be no need for construct like the above and I am doing something wrong in a more general sense? Thanks again, Vlastimil Brom From jason.swails at gmail.com Thu Sep 16 19:57:09 2010 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 16 Sep 2010 19:57:09 -0400 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Message-ID: On Thu, Sep 16, 2010 at 7:36 PM, Jean Luc Truchtersheim < jeanluc434 at gmail.com> wrote: > Hello, > > I am trying to read from stdin and dump what's read to a temporary > file. My code works for small files but as soon as I have a file that > has, e.g., more than 300 lines, there is always one and only one line > that is truncated compared to the input. > > Here is my code: > > #--------------------------------------------------------------------------------- > #! /usr/bin/env python > > import sys > from tempfile import * > > if __name__ == "__main__": > data = [] > f_in = NamedTemporaryFile(suffix=".txt", delete=False) > for line in sys.stdin: > f_in.write(line) > data.append(line) > f_in.close > Does this need to be f_in.close() ? > f = open(f_in.name, 'rb') > i=0 > for line in f: > if data[i] != line: > print >>sys.stderr, "line > %d:\nfile(%d):\"%s\"\narray(%d):\"%s\"" % > (i+1, len(line), line, len(data[i]), data[i]) > i += 1 > sys.exit() > > #------------------------------------------------------------------------------------------------- > > I feel that I must be doing something very stupid, but I don't really > know what. > > Any idea? > > Can anybody reproduce this behavior. > > Thanks a bunch for any help. > > Jean Luc. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Sep 16 20:06:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 01:06:08 +0100 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Message-ID: <4C92B0F0.3010600@mrabarnett.plus.com> On 17/09/2010 00:36, Jean Luc Truchtersheim wrote: > Hello, > > I am trying to read from stdin and dump what's read to a temporary > file. My code works for small files but as soon as I have a file that > has, e.g., more than 300 lines, there is always one and only one line > that is truncated compared to the input. > > Here is my code: > #--------------------------------------------------------------------------------- > #! /usr/bin/env python > > import sys > from tempfile import * > > if __name__ == "__main__": > data = [] > f_in = NamedTemporaryFile(suffix=".txt", delete=False) > for line in sys.stdin: > f_in.write(line) > data.append(line) > f_in.close > f = open(f_in.name, 'rb') > i=0 > for line in f: > if data[i] != line: > print>>sys.stderr, "line %d:\nfile(%d):\"%s\"\narray(%d):\"%s\"" % > (i+1, len(line), line, len(data[i]), data[i]) > i += 1 > sys.exit() > #------------------------------------------------------------------------------------------------- > > I feel that I must be doing something very stupid, but I don't really > know what. > > Any idea? > > Can anybody reproduce this behavior. > > Thanks a bunch for any help. > > Jean Luc. You're not closing f_in. That line should be: f_in.close() From prologic at shortcircuit.net.au Thu Sep 16 20:08:03 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 10:08:03 +1000 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Message-ID: On Fri, Sep 17, 2010 at 9:36 AM, Jean Luc Truchtersheim wrote: > Can anybody reproduce this behavior. Jean it would help if you could provide samples of your input and output files. I'm pretty sure I might have a clue as to what your problem might be, but I can't be sure until I see the input and resulting output files. cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Thu Sep 16 20:10:34 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 10:10:34 +1000 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <4C92B0F0.3010600@mrabarnett.plus.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> <4C92B0F0.3010600@mrabarnett.plus.com> Message-ID: On Fri, Sep 17, 2010 at 10:06 AM, MRAB wrote: > You're not closing f_in. That line should be: Although this _could_ be the problem (buffers not being flushed and the file being properly closed, etc) it could be something else... --James -- -- James Mills -- -- "Problems are solved by method" From python at mrabarnett.plus.com Thu Sep 16 20:18:04 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 01:18:04 +0100 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: <4C92A584.8060303@mrabarnett.plus.com> Message-ID: <4C92B3BC.6090901@mrabarnett.plus.com> On 17/09/2010 00:56, Vlastimil Brom wrote: > 2010/9/17 MRAB: >> On 16/09/2010 23:11, Vlastimil Brom wrote: >>> >>> ... >>> I put together some code, which works as expected, but I suspect >>> somehow, that there must be better ways of doing it. >>> >>> Two things I am not quite clear about are using the placeholders for >>> the data identifiers and "chaining" the SELECT parameters. >>> >>> I Couldn't find a way to use "?" placeholder for table or column >>> names, hence I ended up using string interpolation for them and >>> placeholders for the data values, like. >>> curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, >>> index_col), (text_index,)) >>> is there a better way or is it not supposed to supply these >>> identifiers programatically? >>> >> You would normally expect the structure of the database to be fixed and >> only the contents to vary. >> >>> For getting the matching text indices given the tags, tag_values >>> combination I ended up with a clumsy query: >>> >>> combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % >>> (index_col, text_name, tag) for tag in tags] >>> sql_query = " INTERSECT ".join(combined_query_list) >>> curs.execute(sql_query, tag_values) >>> >>> which produces e.g.: >>> SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" >>> WHERE "VN"==? >>> >>> or alternatively: >>> >>> select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) >>> where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) >>> sql_query = select_begin + where_subquery >>> >>> with the resulting query string like: >>> SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') >>> >>> (BTW, are these queries equivalent, as the outputs suggest, or are >>> there some distinctions to be aware of?) >>> >>> Anyway, I can't really believe, this would be the expected way ... >>> >> If you're selecting rows of a table then using 'AND' would seem the >> obvious way. >> >> > Thanks for the answer, > Well, that may be a part of the problem, the database structure is > going to be fixed once I'll have the text sources complete, but I was > trying to keep it more general, also allowing the identifiers to be > passed programmatically (based on the tagged text in question). > > yes, I am just selecting rows - based on the combination of the column > values (which, I guess, might be an usual database approach(?). > However, I was unsure, whether it is usual to construct the query > string this way - partly using string interpolation or sequence > joining. > Or should there normally be no need for construct like the above and I > am doing something wrong in a more general sense? > In general you'd have a fixed database structure and fixed queries. You'd design it so that you wouldn't have different columns for different tagged texts, forcing you to change the database structure when texts were added or removed, but no-one will come around to your house to stop you creating queries dynamically. :-) From jeanluc434 at gmail.com Thu Sep 16 20:25:54 2010 From: jeanluc434 at gmail.com (Jean Luc Truchtersheim) Date: Thu, 16 Sep 2010 17:25:54 -0700 (PDT) Subject: File read from stdin and printed to temp file are not identicial? References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Message-ID: <03679b87-ab47-4316-a755-176d2fce07de@v23g2000vbi.googlegroups.com> Dear Fellow python users, Many thanks for your help. Those missing brackets were the cause of my problem. Now my program works as expected. Many, many heartfelt thanks. From prologic at shortcircuit.net.au Thu Sep 16 20:35:40 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 10:35:40 +1000 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <03679b87-ab47-4316-a755-176d2fce07de@v23g2000vbi.googlegroups.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> <03679b87-ab47-4316-a755-176d2fce07de@v23g2000vbi.googlegroups.com> Message-ID: On Fri, Sep 17, 2010 at 10:25 AM, Jean Luc Truchtersheim wrote: > Dear Fellow python users, > > Many thanks for your help. > > Those missing brackets were the cause of my problem. > > Now my program works as expected. > > Many, many heartfelt thanks. Glad to hear it! Do you understand why ? cheers James -- -- James Mills -- -- "Problems are solved by method" From googler.1.webmaster at spamgourmet.com Thu Sep 16 21:33:27 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 16 Sep 2010 18:33:27 -0700 (PDT) Subject: The trouble with "dynamic attributes". References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4C92A7CC.8000505@mrabarnett.plus.com> Message-ID: <2e749113-5c9f-475e-85e5-f6c787559572@a30g2000vbt.googlegroups.com> I am really sorry, but what are you talking about ? Hmmm, ...I have problems to compile Python on SL, I did not ask anything about "dynamic attribute". I don't get it... From ldo at geek-central.gen.new_zealand Thu Sep 16 21:47:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 17 Sep 2010 13:47:22 +1200 Subject: WMI in Python References: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> Message-ID: In message <257b2d99-03d4-491b-8f8b-dccd2bc102a7 at p22g2000pre.googlegroups.com>, alex23 wrote: > Lawrence D'Oliveiro wrote: > >> Why not just call Scriptomatic directly from within the Python script, >> then? > > Because Scriptomatic _generates scripts to access WMI_, that's what it > _does_. Precisely why I suggested running it on the fly. Because machine-generated code has no place in a source file to be maintained by a human. > Are you _seriously_ advocating writing Python code to fire up > a Windows application, programmatically manipulating a GUI to generate > more Python code for your original script to import or exec? If that?s the only way you can use Scriptomatic, then the stupidity lies with the one who suggested using such a brain-dead tool in the first place. > As you've made your disdain for Windows _perfectly_ clear through your > incessant sniping on this list, I think I'm pretty safe in saying you > have no idea of the quality of Scriptomatic's output. The quality of the output is not at issue here. The point is that it is machine-generated from an input command, therefore it makes sense from a maintenance viewpoint to keep the input command, not the machine-generated output, in the source file, and simply generate the latter from the former as part of the build process. Unfortunately, as you have made abundantly clear above, Scriptomatic is a GUI-only tool, totally unsuited to this sort of use. From prologic at shortcircuit.net.au Thu Sep 16 22:12:28 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 12:12:28 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <2e749113-5c9f-475e-85e5-f6c787559572@a30g2000vbt.googlegroups.com> References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4C92A7CC.8000505@mrabarnett.plus.com> <2e749113-5c9f-475e-85e5-f6c787559572@a30g2000vbt.googlegroups.com> Message-ID: On Fri, Sep 17, 2010 at 11:33 AM, moerchendiser2k3 wrote: > I am really sorry, but what are you talking about ? Hmmm, ...I have > problems to compile Python on SL, I did not ask anything about > "dynamic attribute". I don't get it... You are subscribed to the python mailing list. Check your subscription status with the link below. cheers James -- -- James Mills -- -- "Problems are solved by method" From nobody at nowhere.com Thu Sep 16 22:17:50 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 17 Sep 2010 03:17:50 +0100 Subject: os.path.normcase rationale? References: Message-ID: On Wed, 15 Sep 2010 14:49:09 +0100, Chris Withers wrote: > I'm curious as to why, with a file called "Foo.txt" > os.path.normcase('FoO.txt') will return "foo.txt" rather than "Foo.txt"? normcase() doesn't look at the filesystem; it's just string manipulation. From nobody at nowhere.com Thu Sep 16 22:35:41 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 17 Sep 2010 03:35:41 +0100 Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: On Thu, 16 Sep 2010 07:12:16 +1000, Ben Finney wrote: >> Yes, I know the behaviour is documented > > The docstring is fairly poor, IMO. You might want to submit a bug report > to improve it. The description in the library documentation is misleading: os.path.normcase(path) Normalize the case of a pathname. On Unix and Mac OS X, this returns the path unchanged; on case-insensitive filesystems, it converts the path to lowercase. On Windows, it also converts forward slashes to backward slashes. It implies that the behaviour depends upon the actual filesystem, which isn't the case. It only depends upon the platform, i.e. it assumes that all filenames are case-sensitive on Unix systems and case-insensitive on Windows. But Unix systems can access FAT/SMBFS/etc filesystems which are case-insensitive. From tjreedy at udel.edu Thu Sep 16 22:41:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Sep 2010 22:41:42 -0400 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c929052$0$1601$742ec2ed@news.sonic.net> References: <4c929052$0$1601$742ec2ed@news.sonic.net> Message-ID: On 9/16/2010 5:46 PM, John Nagle wrote: By mistakenly posted this as a response to "compile Py2.6 on SL", you 1) confused the OP and 2) limited it audience -- I agree with your points, but would have missed this if I had had threads collapsed, as I usually do, since I have no interest in 2.6 compilation. -- Terry Jan Reedy From tjreedy at udel.edu Thu Sep 16 22:48:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Sep 2010 22:48:21 -0400 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: On 9/16/2010 12:23 PM, J wrote: > Thanks for the replies... I KNEW there was a simple way to escape the > % but I had no idea what it was (I just had conviction). > > I was thrown when the \ didn't escape it... never knew about %%. But > now I do! Thanks for the replies! Doubling an escape char, whatever it is, is a common convention: >>> print("Print a {{}} format string line this: {{{}}}".format(2)) Print a {} format string line this: {2} -- Terry Jan Reedy From cs at zip.com.au Fri Sep 17 00:38:26 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 17 Sep 2010 14:38:26 +1000 Subject: Too many threads In-Reply-To: <716be5f9-79b9-43c7-9c04-0454d015086d@j30g2000vbr.googlegroups.com> References: <716be5f9-79b9-43c7-9c04-0454d015086d@j30g2000vbr.googlegroups.com> Message-ID: <20100917043826.GA21464@cskk.homeip.net> On 16Sep2010 09:55, mark.pelletier at asrcms.com wrote: | For some reason, the tasks I put into my thread pool occasionally get | run more than once. | | Here's the code: You need to post your _exact_ code. I had to change: from queue import Queue into from Queue import Queue So: _do_ you have a "queue" (lowercase) module? Is it buggy? Let's pretend not. Using the standard Queue module I can't reproduce your problem and your code looks correct to my eye. However, it is possible that the output stream used by print() is not thread safe. In which case your multiple outputs may stem from output buffer mishandling and not from your thread pool. Make another Queue to receice items, change _worker() to .put(item) onto it and collect form the queue and print in the program's main code. That way only one thread (the main one) will be trying to print(), removing the possibility of mismanagement of the output if print() is not thread safe. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Rules of Optimization: Rule 1: Don't do it. Rule 2 (for experts only): Don't do it yet. - M.A. Jackson From nad at acm.org Fri Sep 17 01:14:46 2010 From: nad at acm.org (Ned Deily) Date: Thu, 16 Sep 2010 22:14:46 -0700 Subject: Too many threads References: <716be5f9-79b9-43c7-9c04-0454d015086d@j30g2000vbr.googlegroups.com> <20100917043826.GA21464@cskk.homeip.net> Message-ID: In article <20100917043826.GA21464 at cskk.homeip.net>, Cameron Simpson wrote: > On 16Sep2010 09:55, mark.pelletier at asrcms.com > wrote: > | For some reason, the tasks I put into my thread pool occasionally get > | run more than once. > | > | Here's the code: > > You need to post your _exact_ code. I had to change: > from queue import Queue > into > from Queue import Queue > So: _do_ you have a "queue" (lowercase) module? Is it buggy? The OP is probably using Python 3. -- Ned Deily, nad at acm.org From cs at zip.com.au Fri Sep 17 01:22:59 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 17 Sep 2010 15:22:59 +1000 Subject: Too many threads In-Reply-To: References: Message-ID: <20100917052259.GA28454@cskk.homeip.net> On 16Sep2010 22:14, Ned Deily wrote: | In article <20100917043826.GA21464 at cskk.homeip.net>, | Cameron Simpson wrote: | | > On 16Sep2010 09:55, mark.pelletier at asrcms.com | > wrote: | > | For some reason, the tasks I put into my thread pool occasionally get | > | run more than once. | > | | > | Here's the code: | > | > You need to post your _exact_ code. I had to change: | > from queue import Queue | > into | > from Queue import Queue | > So: _do_ you have a "queue" (lowercase) module? Is it buggy? | | The OP is probably using Python 3. Ah, that explains the print(). Anyone know if print() is thread safe in python 3? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If I repent anything, it is very likely to be my good behavior. What demon possessed me that I behaved so well? - Henry David Thoreau From nad at acm.org Fri Sep 17 01:38:41 2010 From: nad at acm.org (Ned Deily) Date: Thu, 16 Sep 2010 22:38:41 -0700 Subject: Too many threads References: <20100917052259.GA28454@cskk.homeip.net> Message-ID: In article <20100917052259.GA28454 at cskk.homeip.net>, Cameron Simpson wrote: > On 16Sep2010 22:14, Ned Deily wrote: > | In article <20100917043826.GA21464 at cskk.homeip.net>, > | Cameron Simpson wrote: > | > | > On 16Sep2010 09:55, mark.pelletier at asrcms.com > | > wrote: > | > | For some reason, the tasks I put into my thread pool occasionally get > | > | run more than once. > | > | > | > | Here's the code: > | > > | > You need to post your _exact_ code. I had to change: > | > from queue import Queue > | > into > | > from Queue import Queue > | > So: _do_ you have a "queue" (lowercase) module? Is it buggy? > | > | The OP is probably using Python 3. > > Ah, that explains the print(). Anyone know if print() is thread safe in > python 3? I vaguely recalled a similar problem and, on the second try, found it: http://bugs.python.org/issue6750 Looks like that fix should have been in Python 3.1.2. -- Ned Deily, nad at acm.org From justin.mailinglists at gmail.com Fri Sep 17 02:59:43 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Thu, 16 Sep 2010 23:59:43 -0700 (PDT) Subject: SimpleHTTPServer, external CSS, and Google Chrome Message-ID: <057af264-995d-4e60-9887-d053b93bd988@m17g2000prl.googlegroups.com> I am running "python -m SimpleHTTPServer 80" on Windows XP Pro SP 3 (Python 2.5.4) browsing http://localhost/ using IE8 and FireFox 3.6, I get blue text on red background on Google Chrome 6.0 however, I get blue text on white background placing index.htm and styles.css (see below) under IIS, I get blue text on red background for all browsers, including Google Chrome 6.0. I get exactly the same results when browsing from another machine. what's wrong? what do I need to change in SimpleHTTPServer? index.htm -------------- your title

foo bar

-------------- styles.css -------------- body { background-color: red; } -------------- From vlastimil.brom at gmail.com Fri Sep 17 04:44:43 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 17 Sep 2010 10:44:43 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: <4C92B3BC.6090901@mrabarnett.plus.com> References: <4C92A584.8060303@mrabarnett.plus.com> <4C92B3BC.6090901@mrabarnett.plus.com> Message-ID: 2010/9/17 MRAB : > On 17/09/2010 00:56, Vlastimil Brom wrote: >> >> 2010/9/17 MRAB: >>> >>> On 16/09/2010 23:11, Vlastimil Brom wrote: >>>> >>>> ... >>>> I put together some code, which works as expected, but I suspect >>>> somehow, that there must be better ways of doing it. >>>> >>>> Two things I am not quite clear about are using the placeholders for >>>> the data identifiers and "chaining" the SELECT parameters. >>>> >>>> I Couldn't find a way to use "?" placeholder for table or column >>>> names, hence I ended up using string interpolation for them and >>>> placeholders for the data values, like. >>>> curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, >>>> index_col), (text_index,)) >>>> is there a better way or is it not supposed to supply these >>>> identifiers programatically? >>>> >>> You would normally expect the structure of the database to be fixed and >>> only the contents to vary. >>> >>>> For getting the matching text indices given the tags, tag_values >>>> combination I ended up with a clumsy query: >>>> >>>> combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % >>>> (index_col, text_name, tag) for tag in tags] >>>> sql_query = " INTERSECT ".join(combined_query_list) >>>> curs.execute(sql_query, tag_values) >>>> >>>> which produces e.g.: >>>> SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" >>>> WHERE "VN"==? >>>> >>>> or alternatively: >>>> >>>> select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) >>>> where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) >>>> sql_query = select_begin + where_subquery >>>> >>>> with the resulting query string like: >>>> SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') >>>> >>>> (BTW, are these queries equivalent, as the outputs suggest, or are >>>> there some distinctions to be aware of?) >>>> >>>> Anyway, I can't really believe, this would be the expected way ... >>>> >>> If you're selecting rows of a table then using 'AND' would seem the >>> obvious way. >>> >>> >> Thanks for the answer, >> Well, that may be a part of the problem, the database structure is >> going to be fixed once I'll have the text sources complete, but I was >> trying to keep it more general, also allowing the identifiers to be >> passed programmatically (based on the tagged text in question). >> >> yes, I am just selecting rows - based on the combination of the column >> values (which, I guess, might be an usual database approach(?). >> However, I was unsure, whether it is usual to construct the query >> string this way - partly using string interpolation or sequence >> joining. >> Or should there normally be no need for construct like the above and I >> am doing something wrong in a more general sense? >> > In general you'd have a fixed database structure and fixed queries. > You'd design it so that you wouldn't have different columns for > different tagged texts, forcing you to change the database structure > when texts were added or removed, but no-one will come around to your > house to stop you creating queries dynamically. :-) > -- > http://mail.python.org/mailman/listinfo/python-list > Ok, thanks for confirming my suspicion :-), Now I have to decide whether I shall use my custom data structure, where I am on my own, or whether using an sql database in such a non-standard way has some advantages... The main problem indeed seems to be the fact, that I consider the tagged texts to be the primary storage format, whereas the database is only means for accessing it more conveniently. Thanks again, vbr From vgnulinux at gmail.com Fri Sep 17 05:31:39 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Fri, 17 Sep 2010 15:01:39 +0530 Subject: Embedded Systems development using Python In-Reply-To: References: Message-ID: Hi All, Appreciate your response. Now I am going to use Telit Module GE865-QUAD with support for GPS and GPRS capabilities. It also has built-in python interpreter for developing application for the module. But still I have no idea which microprocessor/microcontroller to use. Can anyone help me out here ? Is there any microprocessor/microcontroller which I could use with Python and Telit module? Any help here will be appreciated. Regards, VGNU On Mon, Sep 6, 2010 at 8:54 PM, Grant Edwards wrote: > On 2010-09-06, Stefan Behnel wrote: > > VGNU Linux, 06.09.2010 13:02: > >> Can Python be used for embedded systems development ? > > > > It can and has been. > > > > What kind of embedded system with what set of capabilities are you > thinking > > about? TV sets? Mobile phones? Smart dust? > > [The OP never showed up on my sever for some reason] > > If you google for "deeply embedded python", you'll find some raterh > old links: > > http://tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy > > http://groups.google.com/group/python-on-a-chip/web/list-of-small-python-implementations > > http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html > > A few years ago I used Python on a prototype for a bicycle computer > with GPS, four buttons, and a small LCD screen. It was more or less > comparable to a PDA with Linux running on an 200MHz XScale with > something like 16MB of flash and 32MB of SDRAM. > > IIRC, that project used OpenEmbedded, and all I had to do was build > the Python package that's already there in OE. I don't remember if I > was using PySDL or PyQt for the UI -- I remember experimenting with > both on desktop hosts at the time. > > I don't think that product ever saw daylight. There was just now way > they could have competed with Garmin. > > -- > Grant > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Fri Sep 17 05:36:43 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 17 Sep 2010 11:36:43 +0200 Subject: program organization question for web development with python In-Reply-To: <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> Message-ID: <4c933693$0$4439$426a34cc@news.free.fr> Hans a ?crit : (snip) > Maybe I did not make my question clear. I never tried python web > programing before, so I want to start from CGI. You can indeed learn quite a few things doing raw CGI - the most important one being why frameworks are a good idea !-) > I read something about web framework like django, but seems it's a > little bit complicated. Not that much IMHO, but being an early django user I'm probably a bit biased. Now Python is known as "the language with more web frameworks than keywords", so you could probably check some lighter framework like web.py (http://webpy.org/) or flask (http://flask.pocoo.org/). > my task is actually very simple: get search > string from input, and then search database, print search result. I > thought CGI should be good enough to do this. CGI is "good enough" to do any web stuff - just like assembler is "good enough" to write any application !-) > I don't have any idea about how to organize those cgi codes, so what > I'm asking is: > > 1. do I have to have each single file for each hyper-link? Can I put > them together? how? > > 2. how can I pass a db_cursor to another file? can I use db_cursor as > a parameter? Obviously not. FWIW, both questions show a lack of understanding of the HTTP protocol, and you can't hope to do anything good in web programming if you don't understand at least the basics of the HTTP protocol, specially the request/response cycle. Now for a couple more practical answers: There are basically two ways to organize your url => code mapping: 1/ have only one cgi script and use querystring params to tell which action should be executed. 2/ have one cgi script per action. The choice is up to you. For a simple app like yours, the first solution is probably the most obvious : always display the seach form, if the user submitted the form also display the result list. That's how google works (wrt/ user interface I mean). Now if you still need / want to have distinct scripts and want to factor out some common code, you just put the common code in a module that you import from each script. From steve at REMOVE-THIS-cybersource.com.au Fri Sep 17 06:55:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Sep 2010 10:55:44 GMT Subject: Very stupid question about a % symbol References: Message-ID: <4c934930$0$28657$c3e8da3@news.astraweb.com> On Thu, 16 Sep 2010 11:25:06 -0400, J wrote: > OK, this is a very stupid question about a very simple topic, but Google > is failing me this morning... [...] Others have already answered your question, but for future reference, many people won't bother to read posts with a meaningless subject line like "Very stupid question about ...". Very stupid questions invite very stupid answers. I guess you can be grateful that this Python group is more friendly than the average tech group, otherwise you might have got no answers at all, or a sarcastic one. Besides, your actual question isn't stupid at all. It is a sensible, although basic, question. A better subject line would have been: "How to insert percent sign in % format strings?" or some variation thereof. This will also be of benefit to others, who some day may be Googling for the answer to the same question. Regards, -- Steven From enleverLesX_XXmcX at XmclavXeauX.com.invalid Fri Sep 17 07:21:17 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 17 Sep 2010 13:21:17 +0200 Subject: compile Py2.6 on SL References: Message-ID: <4c934f3c$0$5417$ba4acef3@reader.news.orange.fr> Hello! SL (SilverLight) is a library/techno who give functions. You cannot compile Python on SL (SilverLight). @-salutations -- Michel Claveau From contact at xavierho.com Fri Sep 17 07:23:13 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 17 Sep 2010 21:23:13 +1000 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: On 17 September 2010 12:48, Terry Reedy wrote: > Doubling an escape char, whatever it is, is a common convention: > >>> print("Print a {{}} format string line this: {{{}}}".format(2)) > Print a {} format string line this: {2} > Wow. That's convoluted. Took me a minute to process. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Fri Sep 17 08:14:39 2010 From: jason.swails at gmail.com (Jason Swails) Date: Fri, 17 Sep 2010 08:14:39 -0400 Subject: compile Py2.6 on SL In-Reply-To: <4c934f3c$0$5417$ba4acef3@reader.news.orange.fr> References: <4c934f3c$0$5417$ba4acef3@reader.news.orange.fr> Message-ID: On Fri, Sep 17, 2010 at 7:21 AM, Michel Claveau - MVP wrote: > Hello! > > SL (SilverLight) is a library/techno who give functions. > You cannot compile Python on SL (SilverLight). > I think the original thread meant Snow Leopard (the latest Mac OS X) > > @-salutations > -- > Michel Claveau > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Sep 17 08:51:31 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 17 Sep 2010 08:51:31 -0400 Subject: MySQL Query Problem Message-ID: Hi; I have this code: cursor.execute('insert into Passengers values (Null, %s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, curr_sex, curr_weight, price, curr_rt, curr_confirmation)) Now, when I print it out, add quotes where necessary and enter it in at a mysql prompt, all goes well. But when I do it this way, it enters null values for curr_customer and curr_weight! Same darn thing printed out works at the prompt. What gives? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.pelletier at asrcms.com Fri Sep 17 09:25:47 2010 From: mark.pelletier at asrcms.com (mark.pelletier at asrcms.com) Date: Fri, 17 Sep 2010 06:25:47 -0700 (PDT) Subject: Too many threads References: <20100917052259.GA28454@cskk.homeip.net> Message-ID: <3ce61e43-75fd-4091-9dae-161d119fa9f5@e20g2000vbn.googlegroups.com> On Sep 17, 1:38?am, Ned Deily wrote: > In article <20100917052259.GA28... at cskk.homeip.net>, > ?Cameron Simpson wrote: > > > > > > > On 16Sep2010 22:14, Ned Deily wrote: > > | In article <20100917043826.GA21... at cskk.homeip.net>, > > | ?Cameron Simpson wrote: > > | > > | > On 16Sep2010 09:55, mark.pellet... at asrcms.com > > | > wrote: > > | > | For some reason, the tasks I put into my thread pool occasionally get > > | > | run more than once. > > | > | > > | > | Here's the code: > > | > > > | > You need to post your _exact_ code. I had to change: > > | > ? from queue import Queue > > | > into > > | > ? from Queue import Queue > > | > So: _do_ you have a "queue" (lowercase) module? Is it buggy? > > | > > | The OP is probably using Python 3. > > > Ah, that explains the print(). Anyone know if print() is thread safe in > > python 3? > > I vaguely recalled a similar problem and, on the second try, found it: > > http://bugs.python.org/issue6750 > > Looks like that fix should have been in Python 3.1.2. > > -- > ?Ned Deily, > ?n... at acm.org- Hide quoted text - > > - Show quoted text - I was a little surprised at my problems, as I cribbed the code from http://docs.python.org/py3k/library/queue.html?highlight=queue#queue.Queue.put But in the end, yeah it does look like a thread-safe problem with print. I tried replacing the print statement by using another queue, and it worked just fine. Glad to know that it's fixed in 3.1.2; of course, I am running 3.1.1. Doesn't matter, the print statement was just for demonstration purposes. I'm actually going to put a subprocess.getoutput() there. Wonder if that's thread safe? Thanks, Cameron and Ned From victorsubervi at gmail.com Fri Sep 17 09:26:48 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 17 Sep 2010 09:26:48 -0400 Subject: MySQL Query Problem In-Reply-To: References: Message-ID: Here's some more data: print 'insert into Passengers values (Null, %s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")' % (curr_flight, curr_customer, name, curr_sex, curr_weight, price, curr_rt, curr_confirmation) cursor.execute('insert into Passengers values (Null, %s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, curr_sex, curr_weight, price, curr_rt, curr_confirmation)) database.commit() cursor.execute('select last_insert_id() from Passengers') last_insert_id = cursor.fetchone()[0] print 'update Passengers set name=%s, weight=%s where id=%s' % (name, curr_weight, last_insert_id) cursor.execute('update Passengers set name=%s, weight=%s where id=%s', (name, curr_weight, last_insert_id)) database.commit() This prints out: insert into Passengers values (Null, 1, 1, Dr. Mengela, Male, 155, 100, 100, 654, "no", "n/a") update Passengers set name=Dr. Mengela, weight=155 where id=15 Here's what's in the database: mysql> select * from Passengers; +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ | id | flights_id | customer_id | name | sex | weight | price | round_trip | confirmation | late_fee | late_fee_paid | +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ | 1 | 1 | 1 | '' | NULL | NULL | 0.00 | 0 | 12345 | NULL | NULL | | 15 | 1 | 1 | '' | Male | NULL | 0.00 | 100 | 654 | no | n/a | +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ 2 rows in set (0.00 sec) mysql> describe Passengers; +---------------+-------------------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------------------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | flights_id | int(11) | NO | MUL | NULL | | | customer_id | int(11) | NO | MUL | NULL | | | name | varchar(40) | YES | | NULL | | | sex | enum('Male','Female') | YES | | NULL | | | weight | int(11) | YES | | NULL | | | price | float(6,2) | NO | | NULL | | | round_trip | tinyint(1) | NO | | 1 | | | confirmation | varchar(20) | YES | | NULL | | | late_fee | enum('no','yes') | YES | | no | | | late_fee_paid | enum('n/a','paid','not paid') | YES | | n/a | | +---------------+-------------------------------+------+-----+---------+----------------+ 11 rows in set (0.00 sec) and when I run the update: mysql> select * from Passengers; +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ | id | flights_id | customer_id | name | sex | weight | price | round_trip | confirmation | late_fee | late_fee_paid | +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ | 1 | 1 | 1 | '' | NULL | NULL | 0.00 | 0 | 12345 | NULL | NULL | | 15 | 1 | 1 | Dr. Mengela | Male | 155 | 0.00 | 100 | 654 | no | n/a | +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ 2 rows in set (0.00 sec) Please explain why it does that! TIA, beno On Fri, Sep 17, 2010 at 8:51 AM, Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('insert into Passengers values (Null, %s, %s, %s, > %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, > curr_sex, curr_weight, price, curr_rt, curr_confirmation)) > > Now, when I print it out, add quotes where necessary and enter it in at a > mysql prompt, all goes well. But when I do it this way, it enters null > values for curr_customer and curr_weight! Same darn thing printed out works > at the prompt. What gives? > TIA, > beno > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Fri Sep 17 10:32:36 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 17 Sep 2010 07:32:36 -0700 (PDT) Subject: WMI in Python References: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> Message-ID: <210f30c4-22da-405f-ad4b-cc46841ca686@p22g2000pre.googlegroups.com> Lawrence D'Oliveiro wrote: > Because machine-generated > code has no place in a source file to be maintained by a human. Endlessly repeating your bigotry doesn't make it any more true. From lo.maximo73 at gmail.com Fri Sep 17 10:56:19 2010 From: lo.maximo73 at gmail.com (ElMariachi) Date: Fri, 17 Sep 2010 07:56:19 -0700 (PDT) Subject: Compiling SWIG Extensions With VC2008 and VC2010 Both Installed Message-ID: <29739343.post@talk.nabble.com> I am attempting to compile a SWIG extension library for QuantLib (www.quantlib.org) on Windows 7 running Python 2.6. 2.6 needs VC2008 to compile extensions yet distutils cannot find this version, is there a way I can specify that this version be used? Currently, when I attempt a build, I get a lot of the following errors: python setup.py build running build running build_py running build_ext building 'QuantLib._QuantLib' extension C:\Python26\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include -IC:\Python26\PC -c QuantLib/quantlib_wrap.cpp -o build QuantLib/quantlib_wrap.cpp:3423:26: ql/version.hpp: No such file or directory QuantLib/quantlib_wrap.cpp:3424: error: `QL_HEX_VERSION' was not declared in this scope QuantLib/quantlib_wrap.cpp:3425: error: `QL_VERSION' was not declared in this scope QuantLib/quantlib_wrap.cpp:3484:27: ql/quantlib.hpp: No such file or directory QuantLib/quantlib_wrap.cpp:3487:6: #error using an old version of QuantLib, please update QuantLib/quantlib_wrap.cpp:3874:48: boost/algorithm/string/case_conv.hpp: No such file or directory QuantLib/quantlib_wrap.cpp:3878: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3878: error: expected nested-name-specifier before "Error" QuantLib/quantlib_wrap.cpp:3878: error: `Error' has not been declared QuantLib/quantlib_wrap.cpp:3879: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3879: error: expected nested-name-specifier before "Handle" QuantLib/quantlib_wrap.cpp:3879: error: `Handle' has not been declared QuantLib/quantlib_wrap.cpp:3880: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3880: error: expected nested-name-specifier before "RelinkableHandle" QuantLib/quantlib_wrap.cpp:3880: error: `RelinkableHandle' has not been declared QuantLib/quantlib_wrap.cpp:3883: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3883: error: expected nested-name-specifier before "Integer" QuantLib/quantlib_wrap.cpp:3883: error: `Integer' has not been declared QuantLib/quantlib_wrap.cpp:3884: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3884: error: expected nested-name-specifier before "BigInteger" QuantLib/quantlib_wrap.cpp:3884: error: `BigInteger' has not been declared -- View this message in context: http://old.nabble.com/Compiling-SWIG-Extensions-With-VC2008-and-VC2010-Both-Installed-tp29739343p29739343.html Sent from the Python - python-list mailing list archive at Nabble.com. From victorsubervi at gmail.com Fri Sep 17 10:59:32 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 17 Sep 2010 10:59:32 -0400 Subject: MySQL Query Problem In-Reply-To: References: Message-ID: I rebooted MySQL and it now works fine ;) On Fri, Sep 17, 2010 at 9:26 AM, Victor Subervi wrote: > Here's some more data: > > print 'insert into Passengers values (Null, %s, %s, %s, %s, %s, %s, > %s, %s, "no", "n/a")' % (curr_flight, curr_customer, name, curr_sex, > curr_weight, price, curr_rt, curr_confirmation) > > cursor.execute('insert into Passengers values (Null, %s, %s, %s, > %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, > curr_sex, curr_weight, price, curr_rt, curr_confirmation)) > database.commit() > cursor.execute('select last_insert_id() from Passengers') > last_insert_id = cursor.fetchone()[0] > print 'update Passengers set name=%s, weight=%s where id=%s' % > (name, curr_weight, last_insert_id) > cursor.execute('update Passengers set name=%s, weight=%s where > id=%s', (name, curr_weight, last_insert_id)) > database.commit() > > This prints out: > > insert into Passengers values (Null, 1, 1, Dr. Mengela, Male, 155, 100, > 100, 654, "no", "n/a") > update Passengers set name=Dr. Mengela, weight=155 where id=15 > > Here's what's in the database: > > mysql> select * from Passengers; > > +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ > | id | flights_id | customer_id | name | sex | weight | price | round_trip > | confirmation | late_fee | late_fee_paid | > > +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ > | 1 | 1 | 1 | '' | NULL | NULL | 0.00 | 0 > | 12345 | NULL | NULL | > | 15 | 1 | 1 | '' | Male | NULL | 0.00 | 100 > | 654 | no | n/a | > > +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ > 2 rows in set (0.00 sec) > > mysql> describe Passengers; > > +---------------+-------------------------------+------+-----+---------+----------------+ > | Field | Type | Null | Key | Default | > Extra | > > +---------------+-------------------------------+------+-----+---------+----------------+ > | id | int(11) | NO | PRI | NULL | > auto_increment | > | flights_id | int(11) | NO | MUL | NULL > | | > | customer_id | int(11) | NO | MUL | NULL > | | > | name | varchar(40) | YES | | NULL > | | > | sex | enum('Male','Female') | YES | | NULL > | | > | weight | int(11) | YES | | NULL > | | > | price | float(6,2) | NO | | NULL > | | > | round_trip | tinyint(1) | NO | | 1 > | | > | confirmation | varchar(20) | YES | | NULL > | | > | late_fee | enum('no','yes') | YES | | no > | | > | late_fee_paid | enum('n/a','paid','not paid') | YES | | n/a > | | > > +---------------+-------------------------------+------+-----+---------+----------------+ > 11 rows in set (0.00 sec) > > and when I run the update: > > mysql> select * from Passengers; > > +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ > | id | flights_id | customer_id | name | sex | weight | price | > round_trip | confirmation | late_fee | late_fee_paid | > > +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ > | 1 | 1 | 1 | '' | NULL | NULL | 0.00 > | 0 | 12345 | NULL | NULL | > | 15 | 1 | 1 | Dr. Mengela | Male | 155 | 0.00 > | 100 | 654 | no | n/a | > > +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ > 2 rows in set (0.00 sec) > > Please explain why it does that! > TIA, > beno > > > On Fri, Sep 17, 2010 at 8:51 AM, Victor Subervi wrote: > >> Hi; >> I have this code: >> >> cursor.execute('insert into Passengers values (Null, %s, %s, %s, >> %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, >> curr_sex, curr_weight, price, curr_rt, curr_confirmation)) >> >> Now, when I print it out, add quotes where necessary and enter it in at a >> mysql prompt, all goes well. But when I do it this way, it enters null >> values for curr_customer and curr_weight! Same darn thing printed out works >> at the prompt. What gives? >> TIA, >> beno >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Fri Sep 17 11:11:43 2010 From: aahz at pythoncraft.com (Aahz) Date: 17 Sep 2010 08:11:43 -0700 Subject: compile Py2.6 on SL References: <4c934f3c$0$5417$ba4acef3@reader.news.orange.fr> Message-ID: In article <4c934f3c$0$5417$ba4acef3 at reader.news.orange.fr>, Michel Claveau - MVP wrote: > >SL (SilverLight) is a library/techno who give functions. >You cannot compile Python on SL (SilverLight). SL (Snow Leopard) is a popular platform for Python development. I suppose this is another argument against TLAs. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From python at mrabarnett.plus.com Fri Sep 17 12:03:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 17:03:14 +0100 Subject: MySQL Query Problem In-Reply-To: References: Message-ID: <4C939142.5020407@mrabarnett.plus.com> On 17/09/2010 15:59, Victor Subervi wrote: > I rebooted MySQL and it now works fine ;) > I recommend that you always list the column names explicitly to be on the safe side: cursor.execute('insert into Passengers (flights_id, customer_id, name, sex , weight, price, round_trip, confirmation, late_fee, late_fee_paid) values (%s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, curr_sex, curr_weight, price, curr_rt, curr_confirmation)) [snip code] From jabba.laci at gmail.com Fri Sep 17 12:05:18 2010 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 17 Sep 2010 12:05:18 -0400 Subject: self-closing window with wxPython Message-ID: Hi, I'd like to create a simple alarm application that shows an alarm window. The application should shut down automatically after 5 seconds. The problem is the following: * If I keep the mouse outside of the window, the application keeps running. Somehow self.Destroy() is not taken into account. * If the mouse is over the window and I keep moving it, the window closes. I'm using Ubuntu Linux with wxPython 2.8. Below you can find what I have so far. Thanks, Laszlo ========== class MyThread(threading.Thread): def __init__(self, parent): self.parent = parent threading.Thread.__init__(self) def run(self): print time.time() # appears on stdout time.sleep(5) print time.time() # appears on stdout self.parent.Destroy() # ??? doesn't work if the mouse is outside of the application window class Alarm(wx.Frame): def __init__(self, title, *args): wx.Frame.__init__(self, None, -1, title, pos=(0, 0), size=(800, 600), *args) self.sleepThread = MyThread(self) self.sleepThread.start() self.Bind(wx.EVT_CLOSE, self.on_close) def on_close(self, event): self.Destroy() ========== To call it: class Main(wx.PySimpleApp): def OnInit(self): self.frame = alarm.Alarm("Alarm 0.1") self.SetTopWindow(self.frame) self.SetExitOnFrameDelete(True) self.frame.Show() return True a = Main() a.MainLoop() ===== From vinay_sajip at yahoo.co.uk Fri Sep 17 12:34:23 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 17 Sep 2010 09:34:23 -0700 (PDT) Subject: Configuring logging for Web applications Message-ID: <71ec0bf9-b480-4272-aa57-743ca5d53244@g10g2000vbc.googlegroups.com> For those of you writing web applications and having multiple web applications in the same Python process, if you are interesting in using Python logging to write to web-application-specific logs, you may be interested in this link: http://plumberjack.blogspot.com/2010/09/configuring-logging-for-web.html If you have any feedback on that post, please comment on that post itself rather than here ;-) Thanks and regards, Vinay Sajip From lie.1296 at gmail.com Fri Sep 17 12:58:29 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 18 Sep 2010 02:58:29 +1000 Subject: Debugger - fails to "continue" with breakpoint set In-Reply-To: References: Message-ID: <4c939dfa$1@dnews.tpgi.com.au> On 09/16/10 03:38, Ed Greenberg wrote: > I'm pretty new to Python, but I am really enjoying it as an alternative > to Perl and PHP. > > When I run the debugger [import pdb; pdb.set_trace()] and then do next > and step, and evaluate variables, etc, when I hit 'c' for continue, we > go to the end, just fine. > > As soon as I set a breakpoint down the line, [b ] the > behavior of 'c' changes. Instead of continuing until the breakpoint, or > until the end, if the breakpoint is hidden by a conditional, the > debugger starts to treat 'c' as a step (or a next, I'm not sure which.) > > This behavior is repeatable and consistent. > can you write a test script and post its corresponding gdb session that demonstrates what you meant? From lie.1296 at gmail.com Fri Sep 17 13:08:54 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 18 Sep 2010 03:08:54 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c929052$0$1601$742ec2ed@news.sonic.net> References: <4c929052$0$1601$742ec2ed@news.sonic.net> Message-ID: <4c93a06c$1@dnews.tpgi.com.au> On 09/17/10 07:46, John Nagle wrote: > There's a tendency to use "dynamic attributes" in Python when > trying to encapsulate objects from other systems. It almost > works. But it's usually a headache in the end, and should be > discouraged. Here's why. I personally love them, they makes XML files looks more like python objects. foo bar being able to say: if a.b == 'foo': print a.c is very convenient. Yes, it doesn't work if the attribute contains special characters that python doesn't recognize; but you shouldn't use these syntax if that's the case. And even dict-syntax is not perfect for accessing XML file, e.g.: foo bar should a['b'] be 'foo' or 'bar'? So, personally I think both attribute-syntax and dict-syntax should continue; it should be up to the programmer to determine whether the limitations imposed by these syntaxes are suitable for their need (e.g. if the programmer knows he would only use alphabet tag name, then attr-style syntax is fine; and if he knows that there is no duplicate, then dict-style syntax is fine as well; and if he can't rely on both, then and only then, he'd be forced to do it the long way) From python at mrabarnett.plus.com Fri Sep 17 13:28:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 18:28:13 +0100 Subject: it doesn't work ;) [class recursive function] In-Reply-To: <4C939D6F.4040606@stoneleaf.us> References: <4C915568.3080007@stoneleaf.us> <4C915E64.50308@mrabarnett.plus.com> <4C939D6F.4040606@stoneleaf.us> Message-ID: <4C93A52D.5060008@mrabarnett.plus.com> On 17/09/2010 17:55, Ethan Furman wrote: > MRAB wrote: >> On 16/09/2010 00:23, Ethan Furman wrote: >> >>> I need some fresh eyes, or better brains, or both! >>> >> 'next_item' is a generator, but it's just calling itself and discarding >> the result. I think it should be yielding the results to its caller. >> That fix gives me 7 sections in total. > > Thanks, M! > > Some further reading on generators has helped clarify the issue for me. > I had forgotten that the initial call to a generator only sets it up, > and then returns the generator function itself, which then needs to be > iterated through. > > Thanks for the reminder! > > -- > ~Ethan~ > > Still early in the morning for me, so just in case I didn't phrase it > well, my thanks are sincere. > > PS > My apologies if this shows up twice, I haven't seen my other post yet > and it's been 27 hours. > That's probably because you sent it directly to me. From ethan at stoneleaf.us Fri Sep 17 13:49:37 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 10:49:37 -0700 Subject: it doesn't work ;) [class recursive function] In-Reply-To: <4C93A52D.5060008@mrabarnett.plus.com> References: <4C915568.3080007@stoneleaf.us> <4C915E64.50308@mrabarnett.plus.com> <4C939D6F.4040606@stoneleaf.us> <4C93A52D.5060008@mrabarnett.plus.com> Message-ID: <4C93AA31.6010009@stoneleaf.us> MRAB wrote: > On 17/09/2010 17:55, Ethan Furman wrote: >> MRAB wrote: >>> On 16/09/2010 00:23, Ethan Furman wrote: >> >> PS >> My apologies if this shows up twice, I haven't seen my other post yet >> and it's been 27 hours. >> > That's probably because you sent it directly to me. That would explain it -- like I said, it was still early for me! :) -- ~Ethan~ From ethan at stoneleaf.us Fri Sep 17 13:53:28 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 10:53:28 -0700 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c93a06c$1@dnews.tpgi.com.au> References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4c93a06c$1@dnews.tpgi.com.au> Message-ID: <4C93AB18.2080500@stoneleaf.us> Lie Ryan wrote: [snip] > And even dict-syntax is not perfect for accessing XML file, e.g.: > > > foo > bar > > > should a['b'] be 'foo' or 'bar'? Attribute style access would also fail in this instance -- how is this worked-around? -- ~Ethan~ From joncle at googlemail.com Fri Sep 17 14:21:30 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 17 Sep 2010 11:21:30 -0700 (PDT) Subject: re.sub: escaping capture group followed by numeric(s) Message-ID: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> Hi All, (I reckon this is probably a question for MRAB and is not really Python specific, but anyhow...) Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1') I've been searching around and I'm sure it'll be obvious when it's pointed out, but how do I use the above to replace 1 with 11? Obviously I can't use r'\11' because there is no group 11. I know I can use a function to do it, but it seems to me there must be a way without. Can I escape r'\11' somehow so that it's group 1 with a '1' after it (not group 11). Cheers, Jon. From jojo.mwebaze at gmail.com Fri Sep 17 14:48:36 2010 From: jojo.mwebaze at gmail.com (Jojo Mwe) Date: Fri, 17 Sep 2010 11:48:36 -0700 (PDT) Subject: recording input/outputs, attributes and parameters of modules Message-ID: i would like to track all inputs/output to modules/functions -if a module retrieved and used files and run some analysis on them and produced other files in return, i would like to take not of this. i.e what i want is to record all input sand outputs to a module. and also to record all parameters, attribute vaules used by the same module and also would like to know how one module calls another whether it instantiates classes from one module etc Any help will be highly appreciated.. Jojo From mrjean1 at gmail.com Fri Sep 17 14:54:41 2010 From: mrjean1 at gmail.com (MrJean1) Date: Fri, 17 Sep 2010 11:54:41 -0700 (PDT) Subject: SimpleHTTPServer, external CSS, and Google Chrome References: <057af264-995d-4e60-9887-d053b93bd988@m17g2000prl.googlegroups.com> Message-ID: <2079bf56-6c19-4233-97d9-418b7e9d0190@a4g2000prm.googlegroups.com> FWIW, There is a blue text on a red background in all 4 browsers Google Chrome 6.0.472.59, Safari 5.0.1 (7533.17.8), FireFox 3.6.9 and IE 6.0.2900.5512.... with Python 2.7 serving that page on my Windows XP SP 3 machine. /Jean On Sep 16, 11:59?pm, Justin Ezequiel wrote: > I am running "python -m SimpleHTTPServer 80" on Windows XP Pro SP 3 > (Python 2.5.4) > > browsinghttp://localhost/using IE8 and FireFox 3.6, I get blue text > on red background > on Google Chrome 6.0 however, I get blue text on white background > placing index.htm and styles.css (see below) under IIS, I get blue > text on red background for all browsers, > including Google Chrome 6.0. > > I get exactly the same results when browsing from another machine. > what's wrong? what do I need to change in SimpleHTTPServer? > > index.htm > -------------- > ? ?"http://www.w3.org/TR/html4/strict.dtd"> > > > your title > > > > >

foo bar

> > > -------------- > > styles.css > -------------- > body { > ? ? background-color: red;} > > -------------- From python at mrabarnett.plus.com Fri Sep 17 14:56:37 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 19:56:37 +0100 Subject: re.sub: escaping capture group followed by numeric(s) In-Reply-To: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> References: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> Message-ID: <4C93B9E5.4050000@mrabarnett.plus.com> On 17/09/2010 19:21, Jon Clements wrote: > Hi All, > > (I reckon this is probably a question for MRAB and is not really > Python specific, but anyhow...) > > Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1') > > I've been searching around and I'm sure it'll be obvious when it's > pointed out, but how do I use the above to replace 1 with 11? > Obviously I can't use r'\11' because there is no group 11. I know I > can use a function to do it, but it seems to me there must be a way > without. Can I escape r'\11' somehow so that it's group 1 with a '1' > after it (not group 11). > re.sub(r'(\d+)', r'\g<1>', 'string1') From __peter__ at web.de Fri Sep 17 14:59:13 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 17 Sep 2010 20:59:13 +0200 Subject: re.sub: escaping capture group followed by numeric(s) References: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> Message-ID: Jon Clements wrote: > (I reckon this is probably a question for MRAB and is not really > Python specific, but anyhow...) > > Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1') > > I've been searching around and I'm sure it'll be obvious when it's > pointed out, but how do I use the above to replace 1 with 11? > Obviously I can't use r'\11' because there is no group 11. I know I > can use a function to do it, but it seems to me there must be a way > without. Can I escape r'\11' somehow so that it's group 1 with a '1' > after it (not group 11). Quoting http://docs.python.org/library/re.html#re.sub """ In addition to character escapes and backreferences as described above, \g will use the substring matched by the group named name, as defined by the (?P...) syntax. \g uses the corresponding group number; \g<2> is therefore equivalent to \2, but isn?t ambiguous in a replacement such as \g<2>0. \20 would be interpreted as a reference to group 20, not a reference to group 2 followed by the literal character '0'. The backreference \g<0> substitutes in the entire substring matched by the RE. """ Peter From joncle at googlemail.com Fri Sep 17 15:00:58 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 17 Sep 2010 12:00:58 -0700 (PDT) Subject: re.sub: escaping capture group followed by numeric(s) References: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> Message-ID: <516ef370-7b28-40eb-a0c6-2c176cbc85c5@t3g2000vbb.googlegroups.com> On 17 Sep, 19:59, Peter Otten <__pete... at web.de> wrote: > Jon Clements wrote: > > (I reckon this is probably a question for MRAB and is not really > > Python specific, but anyhow...) > > > Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1') > > > I've been searching around and I'm sure it'll be obvious when it's > > pointed out, but how do I use the above to replace 1 with 11? > > Obviously I can't use r'\11' because there is no group 11. I know I > > can use a function to do it, but it seems to me there must be a way > > without. Can I escape r'\11' somehow so that it's group 1 with a '1' > > after it (not group 11). > > Quoting > > http://docs.python.org/library/re.html#re.sub > > """ > In addition to character escapes and backreferences as described above, > \g will use the substring matched by the group named name, as defined > by the (?P...) syntax. \g uses the corresponding group number; > \g<2> is therefore equivalent to \2, but isn?t ambiguous in a replacement > such as \g<2>0. \20 would be interpreted as a reference to group 20, not a > reference to group 2 followed by the literal character '0'. The > backreference \g<0> substitutes in the entire substring matched by the RE. > """ > > Peter Thanks Peter and MRAB. I must have been through the docs half a dozen times and missed that - what a muppet! One of those days I guess... Cheers, Jon. From philip at semanchuk.com Fri Sep 17 15:08:16 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 17 Sep 2010 15:08:16 -0400 Subject: self-closing window with wxPython In-Reply-To: References: Message-ID: <05E2E665-4777-4F72-B1BC-852887260D22@semanchuk.com> On Sep 17, 2010, at 12:05 PM, Jabba Laci wrote: > Hi, > > I'd like to create a simple alarm application that shows an alarm > window. The application should shut down automatically after 5 > seconds. The problem is the following: > * If I keep the mouse outside of the window, the application keeps > running. Somehow self.Destroy() is not taken into account. > * If the mouse is over the window and I keep moving it, the window closes. > > I'm using Ubuntu Linux with wxPython 2.8. Below you can find what I have so far. Hi Laszlo, It's difficult to help without a complete working example. But I have a few suggestions. 1) Why not call self.parent.Close()? It seems a bit more polite than .Destroy(). 2) I saw this in the documentation for Destroy() -- "Frames and dialogs are not destroyed immediately when this function is called -- they are added to a list of windows to be deleted on idle time, when all the window's events have been processed." That might be consistent with what you're seeing. The window you're trying to destroy has no events in its queue. WHen you move the mouse over it, the window processes those mouse events and then wx realizes, "Hey, this window has processed all of its events, and it's on the list of windows to be destroyed. I'd better get rid of it." If you're interested in experimenting, find a non-mouse way to force that window to process an event and I'll bet that would have the same effect as moving the mouse over it. 3) Both the wxPython and wxWidgets mailing lists are probably better places to ask for help on wxPython. Good luck Philip > > ========== > > class MyThread(threading.Thread): > def __init__(self, parent): > self.parent = parent > threading.Thread.__init__(self) > > def run(self): > print time.time() # appears on stdout > time.sleep(5) > print time.time() # appears on stdout > > self.parent.Destroy() # ??? doesn't work if the mouse is > outside of the application window > > class Alarm(wx.Frame): > def __init__(self, title, *args): > wx.Frame.__init__(self, None, -1, title, pos=(0, 0), > size=(800, 600), *args) > > self.sleepThread = MyThread(self) > self.sleepThread.start() > > self.Bind(wx.EVT_CLOSE, self.on_close) > > def on_close(self, event): > self.Destroy() > > ========== > > To call it: > > class Main(wx.PySimpleApp): > def OnInit(self): > self.frame = alarm.Alarm("Alarm 0.1") > self.SetTopWindow(self.frame) > self.SetExitOnFrameDelete(True) > self.frame.Show() > return True > > a = Main() > a.MainLoop() > > ===== > -- > http://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Fri Sep 17 15:16:15 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 12:16:15 -0700 Subject: parsing compact index files (*.cdx) Message-ID: <4C93BE7F.3050203@stoneleaf.us> Greetings! Does anybody have any pointers, tips, web-pages, already written routines, etc, on parsing *.cdx files? I have found the pages on MS's sight for Foxpro, but they neglect to describe the compaction algorithm used, and my Google-fu has failed to find any sites with that information. Any and all help greatly appreciated! -- ~Ethan~ From ethan at stoneleaf.us Fri Sep 17 15:34:42 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 12:34:42 -0700 Subject: parsing compact index files (*.cdx) In-Reply-To: <4C93BE7F.3050203@stoneleaf.us> References: <4C93BE7F.3050203@stoneleaf.us> Message-ID: <4C93C2D2.3020608@stoneleaf.us> Ethan Furman wrote: > Greetings! > > Does anybody have any pointers, tips, web-pages, already written > routines, etc, on parsing *.cdx files? I have found the pages on MS's > sight for Foxpro, but they neglect to describe the compaction algorithm > used, and my Google-fu has failed to find any sites with that information. > > Any and all help greatly appreciated! > > -- > ~Ethan~ Oops -- compact index files are *.idx; compound index files are *.cdx; I believe they use the same algorithm, though, at least for Foxpro. -- ~Ethan~ From python at mrabarnett.plus.com Fri Sep 17 15:37:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 20:37:34 +0100 Subject: parsing compact index files (*.cdx) In-Reply-To: <4C93BE7F.3050203@stoneleaf.us> References: <4C93BE7F.3050203@stoneleaf.us> Message-ID: <4C93C37E.30803@mrabarnett.plus.com> On 17/09/2010 20:16, Ethan Furman wrote: > Greetings! > > Does anybody have any pointers, tips, web-pages, already written > routines, etc, on parsing *.cdx files? I have found the pages on MS's > sight for Foxpro, but they neglect to describe the compaction algorithm > used, and my Google-fu has failed to find any sites with that information. > > Any and all help greatly appreciated! > Have you seen this: http://www.archive.org/web/researcher/cdx_file_format.php From ethan at stoneleaf.us Fri Sep 17 16:00:48 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 13:00:48 -0700 Subject: parsing compact index files (*.cdx) In-Reply-To: <4C93C37E.30803@mrabarnett.plus.com> References: <4C93BE7F.3050203@stoneleaf.us> <4C93C37E.30803@mrabarnett.plus.com> Message-ID: <4C93C8F0.6050205@stoneleaf.us> MRAB wrote: > On 17/09/2010 20:16, Ethan Furman wrote: >> Greetings! >> >> Does anybody have any pointers, tips, web-pages, already written >> routines, etc, on parsing *.cdx files? I have found the pages on MS's >> sight for Foxpro, but they neglect to describe the compaction algorithm >> used, and my Google-fu has failed to find any sites with that >> information. >> >> Any and all help greatly appreciated! >> > Have you seen this: > > http://www.archive.org/web/researcher/cdx_file_format.php I had not. Unfortunately what I need are cdx files that are for dbf files. Thanks anyway! -- ~Ethan~ From usenot at geekmail.INVALID Fri Sep 17 16:01:54 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 17 Sep 2010 16:01:54 -0400 Subject: Too much code - slicing References: Message-ID: <20100917160154.570ce164@geekmail.INVALID> On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > I also like this construct that works, I think, since 2.6: > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > I wonder when this construct will finally start to look good. /W -- INVALID? DE! From isaacrc82 at gmail.com Fri Sep 17 16:07:15 2010 From: isaacrc82 at gmail.com (Ariel) Date: Fri, 17 Sep 2010 16:07:15 -0400 Subject: How to make a web services in python ??? Message-ID: Hi everybody, I need some help to find documentation about how to implements web services in python, could you help me please ??? Regards Thanks in advance Ariel -------------- next part -------------- An HTML attachment was scrubbed... URL: From jabba.laci at gmail.com Fri Sep 17 17:00:54 2010 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 17 Sep 2010 17:00:54 -0400 Subject: self-closing window with wxPython In-Reply-To: <05E2E665-4777-4F72-B1BC-852887260D22@semanchuk.com> References: <05E2E665-4777-4F72-B1BC-852887260D22@semanchuk.com> Message-ID: Hi, > 2) I saw this in the documentation for Destroy() -- "Frames and dialogs are not destroyed immediately when this function is called -- they are added to a list of windows to be deleted on idle time, when all the window's events have been processed." That might be consistent with what you're seeing. The window you're trying to destroy has no events in its queue. WHen you move the mouse over it, the window processes those mouse events and then wx realizes, "Hey, this window has processed all of its events, and it's on the list of windows to be destroyed. I'd better get rid of it." > > If you're interested in experimenting, find a non-mouse way to force that window to process an event and I'll bet that would have the same effect as moving the mouse over it. Thanks for the hint, I could solve the problem. After Destroy() I added an extra event: self.parent.Destroy() self.parent.dc.SetFocus() As you suggested, the extra event triggers the queue processing and when it becomes empty the window gets destroyed. Thanks, Laszlo From cs at zip.com.au Fri Sep 17 17:07:41 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 18 Sep 2010 07:07:41 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <4C93AB18.2080500@stoneleaf.us> References: <4C93AB18.2080500@stoneleaf.us> Message-ID: <20100917210741.GA1674@cskk.homeip.net> On 17Sep2010 10:53, Ethan Furman wrote: | Lie Ryan wrote: | [snip] | >And even dict-syntax is not perfect for accessing XML file, e.g.: | > | > | > foo | > bar | > | > | >should a['b'] be 'foo' or 'bar'? | | Attribute style access would also fail in this instance -- how is | this worked-around? I'd be inclined to go for ('foo', 'bar'), though that makes all the single occurence nodes into sequences too, a bit cumbersome:-( -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ alt.skunks A newsgroup for enthusiasts of skunks and other mustelidae. From ian.g.kelly at gmail.com Fri Sep 17 17:15:04 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 17 Sep 2010 15:15:04 -0600 Subject: self-closing window with wxPython In-Reply-To: References: <05E2E665-4777-4F72-B1BC-852887260D22@semanchuk.com> Message-ID: On Fri, Sep 17, 2010 at 3:00 PM, Jabba Laci wrote: > Hi, > > > 2) I saw this in the documentation for Destroy() -- "Frames and dialogs > are not destroyed immediately when this function is called -- they are added > to a list of windows to be deleted on idle time, when all the window's > events have been processed." That might be consistent with what you're > seeing. The window you're trying to destroy has no events in its queue. WHen > you move the mouse over it, the window processes those mouse events and then > wx realizes, "Hey, this window has processed all of its events, and it's on > the list of windows to be destroyed. I'd better get rid of it." > > > > If you're interested in experimenting, find a non-mouse way to force that > window to process an event and I'll bet that would have the same effect as > moving the mouse over it. > > Thanks for the hint, I could solve the problem. After Destroy() I > added an extra event: > > self.parent.Destroy() > self.parent.dc.SetFocus() > > As you suggested, the extra event triggers the queue processing and > when it becomes empty the window gets destroyed. > You could also implement the alarm with a wxTimer instance that triggers a wxTimerEvent, rather than creating a new thread for no good reason. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hidura at gmail.com Fri Sep 17 17:35:56 2010 From: hidura at gmail.com (Hidura) Date: Fri, 17 Sep 2010 18:35:56 -0300 Subject: How to make a web services in python ??? In-Reply-To: References: Message-ID: What kind of web-service you have in mind???? 2010/9/17, Ariel : > Hi everybody, I need some help to find documentation about how to implements > web services in python, could you help me please ??? > Regards > Thanks in advance > Ariel > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From jaksonaquino at gmail.com Fri Sep 17 19:04:51 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Fri, 17 Sep 2010 20:04:51 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: <4c8e752d$0$5432$ba4acef3@reader.news.orange.fr> Message-ID: > On Mon, Sep 13, 2010 at 4:02 PM, Michel Claveau - MVP > wrote: >> Sorry for time, but I am very busy... >> >> With Python + Pywin32, you can force the activation of a window (before >> send some keys...) >> See: >> ?win32gui.SetForegroundWindow(w_handle) >> >> or >> ?win32gui.SetActiveWindow(w_handle) >> >> >> >> For to find a windows (and his handle), see: >> ?win32gui.EnumWindows() >> ?win32gui.GetWindowTex() >> or >> ?win32gui.FindWindowEx() I ended up using Dispatch("WScript.Shell") and AppActivate("R Console") of the win32com.client module because they are higher level functions. I guess that your code runs faster, but I don't have an old machine to compare the performance of the two codes. I still may switch to your code in the future, when I have easy access to a real machine running Windows to make some tests. The released version of the plugin is here: http://www.vim.org/scripts/script.php?script_id=2628 Thanks for your help! Jakson Aquino From nkrumm at gmail.com Fri Sep 17 19:10:39 2010 From: nkrumm at gmail.com (Nik Krumm) Date: Fri, 17 Sep 2010 16:10:39 -0700 (PDT) Subject: [OS X 10.5] hitting TAB inserts ./ in interactive mode ? Message-ID: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Hi all, Thanks for your help. I installed python 2.7 on my Mac OS X 10.5.8 machine: nik$ python Python 2.7 (r27:82508, Jul 3 2010, 21:12:11) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. and now, when I hit TAB or paste in a code snippet with tabs in them, the interpreter tries to autocomplete a path, or inserts "./" if the line is blank (just as readline would in the shell environment). It does *not* try to autocomplete function (as readline would in python-- importing readline does turn on this functionality). And it does *not* insert a tab, as I would like it to! If i start my old python 2.5 which came with the OS, this is not a problem. I've tried setting a PYTHONIOENCODING, but that doesn't seem to be doing the job. Any ideas? Thanks in advance. ~Nik From wegwerp at gmail.com Fri Sep 17 19:30:56 2010 From: wegwerp at gmail.com (Bas) Date: Fri, 17 Sep 2010 16:30:56 -0700 (PDT) Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> Message-ID: <96057530-3d0d-4e78-b7a3-12425a7c7f83@i17g2000vbq.googlegroups.com> On Sep 17, 10:01?pm, Andreas Waldenburger wrote: > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > > > I also like this construct that works, I think, since 2.6: > > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > I wonder when this construct will finally start to look good. Using IFs is just plain ugly. Why not go for the much more pythonic code = (lambda s:dir[slice(*(s*int(num),None)[::s])])(cmp('o',side)) Much easier on the eyes and no code duplication ... ;) Bas From sumerc at gmail.com Fri Sep 17 19:57:15 2010 From: sumerc at gmail.com (k3xji) Date: Fri, 17 Sep 2010 16:57:15 -0700 (PDT) Subject: Porting PEP 3148 to 2.x series Message-ID: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> Hi, Is there any work on porting PEP 3148 back to 2.x series. That is a wonderful PEP, any many long-running applications are really in need of some stable library for handling stuff in async way just as proposed in this PEP. Thanks, From ben+python at benfinney.id.au Fri Sep 17 21:21:10 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 18 Sep 2010 11:21:10 +1000 Subject: Porting PEP 3148 to 2.x series References: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> Message-ID: <8762y37sop.fsf@benfinney.id.au> k3xji writes: > Is there any work on porting PEP 3148 back to 2.x series. That is a > wonderful PEP, any many long-running applications are really in need > of some stable library for handling stuff in async way just as > proposed in this PEP. Better would be to port those applications that would benefit to Python 3.x. -- \ ?To stay young requires unceasing cultivation of the ability to | `\ unlearn old falsehoods.? ?Robert Anson Heinlein | _o__) | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Fri Sep 17 21:50:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Sep 2010 01:50:59 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> Message-ID: <4c941b03$0$28657$c3e8da3@news.astraweb.com> On Fri, 17 Sep 2010 16:01:54 -0400, Andreas Waldenburger wrote: > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > >> I also like this construct that works, I think, since 2.6: >> >> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] >> > I wonder when this construct will finally start to look good. It looks good to me. It follows a common English idiom: "What are you doing tonight?" "I'll be going to the movies, if I finish work early, otherwise I'll stay home and watch a DVD." -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Sep 17 23:12:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Sep 2010 03:12:15 GMT Subject: Why IterableUserDict? Message-ID: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> I was writing some tests for a mapping class I have made, and I decided to run those same tests over dict and UserDict. The built-in dict passed all the tests, but UserDict failed one: class SimpleMappingTest(unittest.TestCase): type2test = UserDict.UserDict def test_iter(self): k, v = [0, 1, 2, 3], 'abcd' m = self.type2test(zip(k, v)) it = iter(m) self.assert_(iter(it) is it) self.assertEquals(sorted(it), k) # This line fails. # many more tests To cut a long story short, the problem is that UserDict doesn't support the modern iteration protocol. Python falls back on the old-fashioned __getitem__ iteration protocol, but since it expects IndexError rather than KeyError, iteration fails for UserDict once it hits key=4. If I look at the source code for the UserDict module, I discover that there's a second mapping class, IterableUserDict, specifically to make UserDict iterable. To do this requires a single one-line method: class IterableUserDict(UserDict): def __iter__(self): return iter(self.data) This class was apparently added to the module in 2.2 -- it doesn't exist in 2.1. Now that boggles my brain. Why was support for iteration added as a subclass, instead of simply adding the __iter__ method to UserDict? UserDict is supposed to be a drop-in replacement for dict (although the use-cases for it are much fewer now that we can inherit from dict), so it doesn't make sense to me to have a non-iterable UserDict plus a subclass which is iterable. Can anyone shed any light on this apparently bizarre design decision? -- Steven From nad at acm.org Sat Sep 18 00:01:47 2010 From: nad at acm.org (Ned Deily) Date: Fri, 17 Sep 2010 21:01:47 -0700 Subject: [OS X 10.5] hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Message-ID: In article <431250b2-391e-4a1f-ba72-08afb7159d65 at l25g2000prn.googlegroups.com>, Nik Krumm wrote: > Thanks for your help. I installed python 2.7 on my Mac OS X 10.5.8 > machine: > > > nik$ python > Python 2.7 (r27:82508, Jul 3 2010, 21:12:11) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > > and now, when I hit TAB or paste in a code snippet with tabs in them, > the interpreter tries to autocomplete a path, or inserts "./" if the > line is blank (just as readline would in the shell environment). It > does *not* try to autocomplete function (as readline would in python-- > importing readline does turn on this functionality). And it does *not* > insert a tab, as I would like it to! See the rlcompleter module in the standard library: http://docs.python.org/library/rlcompleter.html In my .bashrc file, I have a line: [ -f ~/.pythonrc ] && export PYTHONSTARTUP=~/.pythonrc and in the .pythonrc file, I include: try: import readline except ImportError: print("Module readline not available.") else: import rlcompleter readline.parse_and_bind("tab: complete") Note the print() form which works with either Python 2 or 3. -- Ned Deily, nad at acm.org From ldo at geek-central.gen.new_zealand Sat Sep 18 01:03:23 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 18 Sep 2010 17:03:23 +1200 Subject: WMI in Python References: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> <210f30c4-22da-405f-ad4b-cc46841ca686@p22g2000pre.googlegroups.com> Message-ID: In message <210f30c4-22da-405f-ad4b-cc46841ca686 at p22g2000pre.googlegroups.com>, alex23 wrote: > Lawrence D'Oliveiro wrote: > >> Because machine-generated >> code has no place in a source file to be maintained by a human. > > Endlessly repeating your bigotry doesn't make it any more true. The point is that it is machine-generated from an input command, therefore it makes sense from a maintenance viewpoint to keep the input command, not the machine-generated output, in the source file, and simply generate the latter from the former as part of the build process. From ldo at geek-central.gen.new_zealand Sat Sep 18 01:07:09 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 18 Sep 2010 17:07:09 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message <2f830099-4264-47bc-98ee-31950412ad43 at q21g2000prm.googlegroups.com>, cerr wrote: > I get a socket error "[Errno 98] Address already in use" when i try to > open a socket that got closed before with close(). How come close() > doesn't close the socket properly? The usual case this happens is you have a client connection open at the time, that was not properly terminated. Then the TCP stack goes through a holdoff period (2 minutes, I believe it is), to make absolutely sure all packets destined for the old connection have completely disappeared off the entire Internet, before it will let you open a socket on the same port again. From brian at sweetapp.com Sat Sep 18 01:53:20 2010 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 18 Sep 2010 15:53:20 +1000 Subject: Porting PEP 3148 to 2.x series In-Reply-To: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> References: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> Message-ID: <3BD26867-EDDE-442B-948A-A8FBB636904E@sweetapp.com> On 18 Sep 2010, at 09:57, k3xji wrote: > Hi, > > Is there any work on porting PEP 3148 back to 2.x series. That is a > wonderful PEP, any many long-running applications are really in need > of some stable library for handling stuff in async way just as > proposed in this PEP. I'll probably port 3148 to Python 2.x after its running happily in Python 3.2. But there is no chance that it will be included with the standard library in the 2.x series. Cheers, Brian From __peter__ at web.de Sat Sep 18 03:42:14 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Sep 2010 09:42:14 +0200 Subject: Why IterableUserDict? References: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I was writing some tests for a mapping class I have made, and I decided > to run those same tests over dict and UserDict. The built-in dict passed > all the tests, but UserDict failed one: > > class SimpleMappingTest(unittest.TestCase): > type2test = UserDict.UserDict > def test_iter(self): > k, v = [0, 1, 2, 3], 'abcd' > m = self.type2test(zip(k, v)) > it = iter(m) > self.assert_(iter(it) is it) > self.assertEquals(sorted(it), k) # This line fails. > # many more tests > > To cut a long story short, the problem is that UserDict doesn't support > the modern iteration protocol. Python falls back on the old-fashioned > __getitem__ iteration protocol, but since it expects IndexError rather > than KeyError, iteration fails for UserDict once it hits key=4. > > If I look at the source code for the UserDict module, I discover that > there's a second mapping class, IterableUserDict, specifically to make > UserDict iterable. To do this requires a single one-line method: > > class IterableUserDict(UserDict): > def __iter__(self): > return iter(self.data) > > This class was apparently added to the module in 2.2 -- it doesn't exist > in 2.1. > > Now that boggles my brain. Why was support for iteration added as a > subclass, instead of simply adding the __iter__ method to UserDict? > UserDict is supposed to be a drop-in replacement for dict (although the > use-cases for it are much fewer now that we can inherit from dict), so it > doesn't make sense to me to have a non-iterable UserDict plus a subclass > which is iterable. > > Can anyone shed any light on this apparently bizarre design decision? I looked it up for you: http://svn.python.org/view/python/trunk/Lib/UserDict.py?view=log """ Revision 22248 - (view) (download) (as text) (annotate) - [select for diffs] Modified Tue Aug 7 17:40:42 2001 UTC (9 years, 1 month ago) by gvanrossum File length: 1913 byte(s) Diff to previous 21167 Remove the __iter__ method from the UserDict class -- it can silently break old code (in extreme cases). See SF bug #448153. Add a new subclass IterableUserDict that has the __iter__ method. Note that for new projects, unless backwards compatibility with pre-2.2 Python is required, subclassing 'dictionary' is recommended; UserDict might become deprecated. """ The bug report is also interesting: http://bugs.python.org/issue448153 Peter From ldo at geek-central.gen.new_zealand Sat Sep 18 04:04:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 18 Sep 2010 20:04:21 +1200 Subject: [OS X 10.5] hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Message-ID: In message , Ned Deily wrote: > try: > import readline > except ImportError: > print("Module readline not available.") > else: > import rlcompleter > readline.parse_and_bind("tab: complete") > > Note the print() form which works with either Python 2 or 3. You should be writing diagnostics to stderr, not stdout. From vlastimil.brom at gmail.com Sat Sep 18 04:48:44 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 18 Sep 2010 10:48:44 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: <4C92A584.8060303@mrabarnett.plus.com> <4C92B3BC.6090901@mrabarnett.plus.com> Message-ID: 2010/9/18 Dennis Lee Bieber : > On Fri, 17 Sep 2010 10:44:43 +0200, Vlastimil Brom > declaimed the following in > gmane.comp.python.general: > > >> Ok, thanks for confirming my suspicion :-), >> Now I have to decide whether I shall use my custom data structure, >> where I am on my own, or whether using an sql database in such a >> non-standard way has some advantages... >> The main problem indeed seems to be the fact, that I consider the >> tagged texts to be the primary storage format, whereas the database is >> only means for accessing it more conveniently. >> > > ? ? ? ?I suspect part of your difficulty is in trying to fit everything > into a single relation (table). > > ? ? ? ?Looking back at your ancient "format for storing textual data (for > an edition) - formatting and additional info" post, I'd probably move > your so-called tags into one relation -- where the tag type is, itself, > data... > > ? ? ? ?Without seeing an actual data sample (and pseudo-DDL): > > create table texts > ? ? ? ?( > ? ? ? ? ? ? ? ?ID autoincrement primary key, > ? ? ? ? ? ? ? ?text varchar > ? ? ? ?); > > create table tags > ? ? ? ?( > ? ? ? ? ? ? ? ?ID autoincrement primary key, > ? ? ? ? ? ? ? ?textID integer foreign key references texts(ID), > ? ? ? ? ? ? ? ?tagtype char, > ? ? ? ? ? ? ? ?start integer, > ? ? ? ? ? ? ? ?end integer, > ? ? ? ? ? ? ? ?supplement varchar > ? ? ? ?); > > ? ? ? ?I'd really have to see samples (more than one line) of the raw > input, and the desired information... > > -- > ? ? ? ?Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ?wlfraed at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the elaboration, I am sure, I am missing some more advanced features of SQL (would the above also work in sqlite, as there (probably?) are no real type restrictions on data? The "markup" format as well as the requirements haven't change since those old posts, one sample of the tagged text is in one of the follow-up post of that: http://mail.python.org/pipermail/python-list/2008-May/540773.html in principle in the tags are in the form , from that text index on this tag-value combination is assigned - until or arbitrary combinations of the tags including overlapping are possible (nesting of the same tags is not possible in favor of the direct replacement). Different texts may have (partly) differing tags, which I'd prefer to handle generally, without having to adapt the queries directly. After the tagged text is parsed, the plain text and the corresponding "database" are created, which maps the text indices to the tag names with their values. Querying the data should be able to get the "tagset" for the given text index and conversely to find the indices matching the given tag-value combinations. (actually the text ranges matching those criteria would be even better, but these are easily done with bisect) (from the specification, mxTextTools looks similar, but it seemed rather low-level and quite heavyweight for the given task) Thanks in advance for any suggestions, Vlastimil Brom From greg.ewing at canterbury.ac.nz Sat Sep 18 04:54:54 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 18 Sep 2010 20:54:54 +1200 Subject: self-closing window with wxPython In-Reply-To: References: Message-ID: <8fjd3iFhckU1@mid.individual.net> Jabba Laci wrote: > I'd like to create a simple alarm application that shows an alarm > window. The application should shut down automatically after 5 > seconds. Are you sure that's a good idea? What happens if the user gets distracted for 6 seconds and misses the alarm? -- Greg From sumerc at gmail.com Sat Sep 18 06:59:19 2010 From: sumerc at gmail.com (k3xji) Date: Sat, 18 Sep 2010 03:59:19 -0700 (PDT) Subject: Porting PEP 3148 to 2.x series References: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> Message-ID: <5917be2a-7f4d-4776-89b9-063f6247c9be@a11g2000vbn.googlegroups.com> > I'll probably port 3148 to Python 2.x after its running happily in ? > Python 3.2. Very good news. One idea: Once library becomes reliable enough- of course there are various use cases - but IMHO it perfectly fits the problem domain of implementing an async DB library on top of it. I suppose that will get attention from Web Community. That is why I am asking for the port because various Web applications written in frameworks (e.g Django) that does not have been ported to 3.x series yet. Thanks, From invalid at invalid.invalid Sat Sep 18 08:10:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 18 Sep 2010 12:10:18 +0000 (UTC) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On 2010-09-18, Lawrence D'Oliveiro wrote: > In message ><2f830099-4264-47bc-98ee-31950412ad43 at q21g2000prm.googlegroups.com>, cerr > wrote: > >> I get a socket error "[Errno 98] Address already in use" when i try to >> open a socket that got closed before with close(). How come close() >> doesn't close the socket properly? > > The usual case this happens is you have a client connection open at the > time, that was not properly terminated. Then the TCP stack goes through a > holdoff period (2 minutes, I believe it is), to make absolutely sure all > packets destined for the old connection have completely disappeared off the > entire Internet, before it will let you open a socket on the same port > again. Even when the connection was properly terminated (from an application's POV), there's a TIME_WAIT period before the TCP stack considered the connection completely gone and will allow re-use of the port. IOW, the TIME_WAIT is actually part of the connection termination (from the TCP stack's POV), and it can takes place after the application considers the connection closed (and may have even exited): http://www.developerweb.net/forum/showthread.php?t=2941 -- Grant From ldo at geek-central.gen.new_zealand Sat Sep 18 08:23:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 00:23:29 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message , Grant Edwards wrote: > Even when the connection was properly terminated (from an > application's POV), there's a TIME_WAIT period before the TCP stack > considered the connection completely gone and will allow re-use of the > port. I?m not so sure about that. I?ve done a bunch of development on a system recently which had a server process written in Python running on a Linux box, accepting connections from a client running under old MacOS 9 (don?t ask) which was, of course, prone to crash. If the client had shut down cleanly, then I could stop and restart the server process without any problems reopening the socket. But if I forgot to close the client, then the server would hit the ?already in use? error. To deal with it, I simply put in an automatic retry at 60-second intervals until it succeeded in reopening the socket. From niklasro at gmail.com Sat Sep 18 11:25:31 2010 From: niklasro at gmail.com (Niklasro) Date: Sat, 18 Sep 2010 08:25:31 -0700 (PDT) Subject: Learning inheritance Message-ID: Hi How can I make the visibility of a variable across many methods or files? To avoid repeating the same line eg url = os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else os.environ['SERVER_NAME'] I repeat for many methods. So declaring it to a super class and inheriting it is my plan. Do you agree or propose otherwise? Thanks Niklas From bruno.desthuilliers at gmail.com Sat Sep 18 12:13:01 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Sat, 18 Sep 2010 09:13:01 -0700 (PDT) Subject: Learning inheritance References: Message-ID: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> On 18 sep, 17:25, Niklasro wrote: > Hi > How can I make the visibility of a variable across many methods or > files? To avoid repeating the same line eg ? ? url = > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > os.environ['SERVER_NAME'] First learn to use Python correctly: url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) => dict.get(key, default=None) Also and FWIW, neither HTTP_HOST not SERVER_NAME are really urls... > I repeat for many methods. So declaring it > to a super class and inheriting it is my plan. Do you agree or propose > otherwise? Not enough background to answer. From ethan at stoneleaf.us Sat Sep 18 12:16:12 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 09:16:12 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> Message-ID: <4C94E5CC.7060809@stoneleaf.us> Carl Karsten wrote: > On Sat, Sep 18, 2010 at 1:11 AM, Ethan Furman wrote: > >>Does anybody have any pointers, tips, web-pages, already written routines, >>etc, on parsing *.cdx files? I have found the pages on MS's sight for >>Foxpro, but they neglect to describe the compaction algorithm used, and my >>Google-fu has failed to find any sites with that information. >> >>Any and all help greatly appreciated! >> > > > "Compound Index File Structure (.cdx)" > > http://msdn.microsoft.com/en-us/library/k35b9hs2%28v=VS.80%29.aspx > > which basiclly links to: > http://msdn.microsoft.com/en-us/library/s8tb8f47%28v=VS.80%29.aspx > > Is that what you need? Thanks for the link, unfortunately I am already familiar with the page. What I need help with is the first sentence of the note at the bottom: Each entry consists of the record number, duplicate byte count and trailing byte count, all compacted. The key text is placed at the logical end of the node, working backwards, allowing for previous key entries. Here's a dump of the last interior node: ----- node type: 2 number of keys: 57 free space: 1 (or 256) (and is this bits, bytes, keys, what?) -- record number mask: c8 0e 40 b0 duplicate byte count mask: 28 trailing byte count mask: 00 -- bits used for record number: 178 bits used for duplicate count: 29 bits used for trail count: 64 bytes used for rec num, dup count, trail count: 192 ----- 12 00 ff 3f 00 00 1f 1f 0e 05 05 03 01 00 c8 0e 40 b0 28 00 b2 1d 40 c0 29 00 d0 42 40 d0 54 80 c0 43 40 a8 14 40 b8 40 40 c8 02 40 d0 08 00 b0 4c 80 b0 3a 40 a0 50 80 d0 3b 40 a8 09 40 b8 0a 80 88 3c 80 c0 2a 00 d8 21 c0 c0 3d 40 c0 4a 80 b0 26 40 b8 2b 40 c0 2c 00 c0 41 40 b8 4d 80 c8 37 00 c0 04 40 c8 44 80 c0 1b 40 c8 15 80 c8 27 40 c8 16 00 a8 2d c0 c8 51 80 b8 2e 40 c0 1e 00 b0 17 40 b8 46 40 b0 2f 80 c8 4f 80 a8 13 00 c8 59 00 c8 31 00 c8 1f 00 a8 3e 40 c0 22 40 a8 07 00 c8 23 80 d0 32 80 b0 52 80 c0 34 80 b0 20 40 b0 24 40 c0 47 80 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4e 44 45 4e 49 44 53 4f 4e 43 43 41 4d 4d 4f 4e 54 54 48 45 57 53 53 4c 45 4e 52 54 49 4e 45 5a 4e 4e 4d 41 47 45 45 49 45 42 45 52 4d 41 4e 45 57 49 4e 53 4c 41 56 45 4e 42 45 52 47 4b 41 56 41 4e 4a 4f 4e 45 53 49 52 49 53 48 53 54 45 54 4c 45 52 52 41 4e 4f 4c 53 54 45 49 4e 45 41 44 4c 45 59 48 41 54 48 41 57 41 59 52 49 4d 45 53 45 41 53 4f 4e 53 53 47 4c 41 44 53 54 4f 4e 45 55 52 52 59 4f 53 54 52 49 4e 4b 52 42 45 53 4f 4c 45 59 46 49 4c 45 4e 45 4e 49 53 4e 47 4c 55 4e 44 45 42 45 52 4c 45 4f 44 53 4f 4e 49 4e 47 4c 45 52 4d 41 52 45 53 54 45 43 4b 45 52 54 4f 4e 44 41 59 57 47 45 52 52 4e 45 49 4c 2d 53 55 4e 44 54 4f 4f 4b 53 45 59 4c 45 4e 44 45 4e 49 4e 55 4e 48 49 41 50 50 45 54 54 41 52 4e 41 48 41 4e 43 41 4c 44 57 45 4c 4c 55 54 54 52 55 43 45 4f 43 41 52 44 45 4c 4f 4f 4d 42 45 52 47 4e 53 45 4c 45 45 52 42 41 43 48 55 47 55 53 54 4e 44 45 52 53 4f 4e 41 4c 4c 41 4e ----- The last half (roughly) consists of last names compressed together, while the first half consists of 57 (in this case) entries of the record number, duplicate byte count and trailing byte count, all compacted -- how do I uncompact them? -- ~Ethan~ From lie.1296 at gmail.com Sat Sep 18 12:35:15 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 19 Sep 2010 02:35:15 +1000 Subject: Making logging.getLogger() simpler Message-ID: <4c94ea0d$1@dnews.tpgi.com.au> I was expecting this to work: import logging logger = logging.getLogger(__name__) logger.warn('this is a warning') instead it produced the error: No handlers could be found for logger "__main__" However, if instead I do: import logging logging.warn('creating logger') logger = logging.getLogger(__name__) logger.warn('this is a warning') then it does work. Is there any reason why getLogger()-created logger shouldn't automatically create a default handler? From carl at personnelware.com Sat Sep 18 13:15:22 2010 From: carl at personnelware.com (Carl Karsten) Date: Sat, 18 Sep 2010 12:15:22 -0500 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: <4C94E5CC.7060809@stoneleaf.us> References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> Message-ID: On Sat, Sep 18, 2010 at 11:16 AM, Ethan Furman wrote: > Carl Karsten wrote: >> >> On Sat, Sep 18, 2010 at 1:11 AM, Ethan Furman wrote: >> >>> Does anybody have any pointers, tips, web-pages, already written >>> routines, >>> etc, on parsing *.cdx files? ?I have found the pages on MS's sight for >>> Foxpro, but they neglect to describe the compaction algorithm used, and >>> my >>> Google-fu has failed to find any sites with that information. >>> >>> Any and all help greatly appreciated! >>> >> >> >> "Compound Index File Structure (.cdx)" >> >> http://msdn.microsoft.com/en-us/library/k35b9hs2%28v=VS.80%29.aspx >> >> which basiclly links to: >> http://msdn.microsoft.com/en-us/library/s8tb8f47%28v=VS.80%29.aspx >> >> Is that what you need? > > Thanks for the link, unfortunately I am already familiar with the page. > ?What I need help with is the first sentence of the note at the bottom: > > Each entry consists of the record number, duplicate byte count and > trailing byte count, all compacted. The key text is placed at the > logical end of the node, working backwards, allowing for previous key > entries. > > Here's a dump of the last interior node: > > ----- > node type: 2 > number of keys: 57 > free space: 1 (or 256) (and is this bits, bytes, keys, what?) > -- > record number mask: c8 0e 40 b0 > duplicate byte count mask: 28 > trailing byte count mask: 00 > -- > bits used for record number: 178 > bits used for duplicate count: 29 > bits used for trail count: 64 > bytes used for rec num, dup count, trail count: 192 > ----- > 12 00 ff 3f 00 00 1f 1f 0e 05 05 03 01 00 c8 0e 40 b0 28 00 > b2 1d 40 c0 29 00 d0 42 40 d0 54 80 c0 43 40 a8 14 40 b8 40 > 40 c8 02 40 d0 08 00 b0 4c 80 b0 3a 40 a0 50 80 d0 3b 40 a8 > 09 40 b8 0a 80 88 3c 80 c0 2a 00 d8 21 c0 c0 3d 40 c0 4a 80 > b0 26 40 b8 2b 40 c0 2c 00 c0 41 40 b8 4d 80 c8 37 00 c0 04 > 40 c8 44 80 c0 1b 40 c8 15 80 c8 27 40 c8 16 00 a8 2d c0 c8 > 51 80 b8 2e 40 c0 1e 00 b0 17 40 b8 46 40 b0 2f 80 c8 4f 80 > a8 13 00 c8 59 00 c8 31 00 c8 1f 00 a8 3e 40 c0 22 40 a8 07 > 00 c8 23 80 d0 32 80 b0 52 80 c0 34 80 b0 20 40 b0 24 40 c0 > 47 80 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 00 4e 44 45 4e 49 44 53 4f 4e 43 43 41 4d 4d 4f 4e 54 54 48 > 45 57 53 53 4c 45 4e 52 54 49 4e 45 5a 4e 4e 4d 41 47 45 45 > 49 45 42 45 52 4d 41 4e 45 57 49 4e 53 4c 41 56 45 4e 42 45 > 52 47 4b 41 56 41 4e 4a 4f 4e 45 53 49 52 49 53 48 53 54 45 > 54 4c 45 52 52 41 4e 4f 4c 53 54 45 49 4e 45 41 44 4c 45 59 > 48 41 54 48 41 57 41 59 52 49 4d 45 53 45 41 53 4f 4e 53 53 > 47 4c 41 44 53 54 4f 4e 45 55 52 52 59 4f 53 54 52 49 4e 4b > 52 42 45 53 4f 4c 45 59 46 49 4c 45 4e 45 4e 49 53 4e 47 4c > 55 4e 44 45 42 45 52 4c 45 4f 44 53 4f 4e 49 4e 47 4c 45 52 > 4d 41 52 45 53 54 45 43 4b 45 52 54 4f 4e 44 41 59 57 47 45 > 52 52 4e 45 49 4c 2d 53 55 4e 44 54 4f 4f 4b 53 45 59 4c 45 > 4e 44 45 4e 49 4e 55 4e 48 49 41 50 50 45 54 54 41 52 4e 41 > 48 41 4e 43 41 4c 44 57 45 4c 4c 55 54 54 52 55 43 45 4f 43 > 41 52 44 45 4c 4f 4f 4d 42 45 52 47 4e 53 45 4c 45 45 52 42 > 41 43 48 55 47 55 53 54 4e 44 45 52 53 4f 4e 41 4c 4c 41 4e > ----- > > The last half (roughly) consists of last names compressed together, > while the first half consists of 57 (in this case) entries of the record > number, duplicate byte count and trailing byte count, all compacted -- > how do I uncompact them? > huh, I see what you mean. What are you working on? I know a few people that may have the answer, but it would help to explain why it is being worked on. -- Carl K From ethan at stoneleaf.us Sat Sep 18 13:44:06 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 10:44:06 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> Message-ID: <4C94FA66.80008@stoneleaf.us> Carl Karsten wrote: > On Sat, Sep 18, 2010 at 11:16 AM, Ethan Furman wrote: > >>Carl Karsten wrote: >> >>>On Sat, Sep 18, 2010 at 1:11 AM, Ethan Furman wrote: >>> >>> >>>>Does anybody have any pointers, tips, web-pages, already written >>>>routines, >>>>etc, on parsing *.cdx files? I have found the pages on MS's sight for >>>>Foxpro, but they neglect to describe the compaction algorithm used, and >>>>my >>>>Google-fu has failed to find any sites with that information. >>>> >>>>Any and all help greatly appreciated! >>>> >>> >>> >>>"Compound Index File Structure (.cdx)" >>> >>>http://msdn.microsoft.com/en-us/library/k35b9hs2%28v=VS.80%29.aspx >>> >>>which basiclly links to: >>>http://msdn.microsoft.com/en-us/library/s8tb8f47%28v=VS.80%29.aspx >>> >>>Is that what you need? >> >>Thanks for the link, unfortunately I am already familiar with the page. >> What I need help with is the first sentence of the note at the bottom: >> >>Each entry consists of the record number, duplicate byte count and >>trailing byte count, all compacted. The key text is placed at the >>logical end of the node, working backwards, allowing for previous key >>entries. >> >>Here's a dump of the last interior node: >> >>----- >>node type: 2 >>number of keys: 57 >>free space: 1 (or 256) (and is this bits, bytes, keys, what?) >>-- >>record number mask: c8 0e 40 b0 >>duplicate byte count mask: 28 >>trailing byte count mask: 00 >>-- >>bits used for record number: 178 >>bits used for duplicate count: 29 >>bits used for trail count: 64 >>bytes used for rec num, dup count, trail count: 192 >>----- >>12 00 ff 3f 00 00 1f 1f 0e 05 05 03 01 00 c8 0e 40 b0 28 00 >>b2 1d 40 c0 29 00 d0 42 40 d0 54 80 c0 43 40 a8 14 40 b8 40 >>40 c8 02 40 d0 08 00 b0 4c 80 b0 3a 40 a0 50 80 d0 3b 40 a8 >>09 40 b8 0a 80 88 3c 80 c0 2a 00 d8 21 c0 c0 3d 40 c0 4a 80 >>b0 26 40 b8 2b 40 c0 2c 00 c0 41 40 b8 4d 80 c8 37 00 c0 04 >>40 c8 44 80 c0 1b 40 c8 15 80 c8 27 40 c8 16 00 a8 2d c0 c8 >>51 80 b8 2e 40 c0 1e 00 b0 17 40 b8 46 40 b0 2f 80 c8 4f 80 >>a8 13 00 c8 59 00 c8 31 00 c8 1f 00 a8 3e 40 c0 22 40 a8 07 >>00 c8 23 80 d0 32 80 b0 52 80 c0 34 80 b0 20 40 b0 24 40 c0 >>47 80 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >>00 4e 44 45 4e 49 44 53 4f 4e 43 43 41 4d 4d 4f 4e 54 54 48 >>45 57 53 53 4c 45 4e 52 54 49 4e 45 5a 4e 4e 4d 41 47 45 45 >>49 45 42 45 52 4d 41 4e 45 57 49 4e 53 4c 41 56 45 4e 42 45 >>52 47 4b 41 56 41 4e 4a 4f 4e 45 53 49 52 49 53 48 53 54 45 >>54 4c 45 52 52 41 4e 4f 4c 53 54 45 49 4e 45 41 44 4c 45 59 >>48 41 54 48 41 57 41 59 52 49 4d 45 53 45 41 53 4f 4e 53 53 >>47 4c 41 44 53 54 4f 4e 45 55 52 52 59 4f 53 54 52 49 4e 4b >>52 42 45 53 4f 4c 45 59 46 49 4c 45 4e 45 4e 49 53 4e 47 4c >>55 4e 44 45 42 45 52 4c 45 4f 44 53 4f 4e 49 4e 47 4c 45 52 >>4d 41 52 45 53 54 45 43 4b 45 52 54 4f 4e 44 41 59 57 47 45 >>52 52 4e 45 49 4c 2d 53 55 4e 44 54 4f 4f 4b 53 45 59 4c 45 >>4e 44 45 4e 49 4e 55 4e 48 49 41 50 50 45 54 54 41 52 4e 41 >>48 41 4e 43 41 4c 44 57 45 4c 4c 55 54 54 52 55 43 45 4f 43 >>41 52 44 45 4c 4f 4f 4d 42 45 52 47 4e 53 45 4c 45 45 52 42 >>41 43 48 55 47 55 53 54 4e 44 45 52 53 4f 4e 41 4c 4c 41 4e >>----- >> >>The last half (roughly) consists of last names compressed together, >>while the first half consists of 57 (in this case) entries of the record >>number, duplicate byte count and trailing byte count, all compacted -- >>how do I uncompact them? >> > > > huh, I see what you mean. > > What are you working on? > > I know a few people that may have the answer, but it would help to > explain why it is being worked on. > > I have a pure-python module to read db3 and vfp 6 dbf files, and I find that I need to read (and write) the idx and cdx index files that foxpro generates. We are in the process of switching from homegrown foxpro apps to homegrown python apps, but I have to support the foxpro file formats until the switch is complete. Once I have the index files down, I'll publish another release of it (an older version can be found on PyPI). Thanks for your help! -- ~Ethan~ From nad at acm.org Sat Sep 18 14:28:57 2010 From: nad at acm.org (Ned Deily) Date: Sat, 18 Sep 2010 11:28:57 -0700 Subject: [OS X 10.5] hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Ned Deily > wrote: > > try: > > import readline > > except ImportError: > > print("Module readline not available.") > > else: > > import rlcompleter > > readline.parse_and_bind("tab: complete") > > > > Note the print() form which works with either Python 2 or 3. > You should be writing diagnostics to stderr, not stdout. In general, sure. Statements in a PYTHONSTARTUP file, like here, are only executed in interactive mode and it isn't likely that someone is going to be redirecting stdout or stderr; that would kind of defeat the purpose of readline completion functions which is what this is all about. But, if you feel strongly about it, I'm sure a contributed patch to improve the rlcompleter documentation would be welcome. -- Ned Deily, nad at acm.org From vlastimil.brom at gmail.com Sat Sep 18 17:00:25 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 18 Sep 2010 23:00:25 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: <4C92A584.8060303@mrabarnett.plus.com> <4C92B3BC.6090901@mrabarnett.plus.com> Message-ID: 2010/9/18 Dennis Lee Bieber : > On Sat, 18 Sep 2010 10:48:44 +0200, Vlastimil Brom > declaimed the following in > gmane.comp.python.general: > >> >> http://mail.python.org/pipermail/python-list/2008-May/540773.html >> > ? ? ? ?Ah, based on that listing you are not worried about embedded tags; > your tags all come at the start of the line (and I presume are > terminated by the end of line). I'd thought you needed actual positions > /in/ the line... You can drop the start/end fields and stuff the tag > attribute into supplement (on SQLite this becomes even simpler since > even if you define supplement to be integer, SQLite will happily store a > text value -- a full type checking RDBM would require either making it a > text field and storing numeric values as text, or using a pair of fields > for numeric vs text). > > ? ? ? ?Tricky part may be how you handle the display markup -- you seem to > have a split over two lines... Is that significant? > >... > ? ? ? ?Of course, all the search terms can be parameterized when > programming... > > cur.execute("""select t.ID, tg.supplement, t.text from texts as t > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?inner join tags as tg > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?on tg.textID = t.ID > ? ? ? ? ? ? ? ? ? ? ? ?where t.text like ? and tg.type = ?""", > ? ? ? ? ? ? ? ? ? ? ? ?("%den%", "VN")) > > results = cur.fetchall() > > should return (a Python list of one tuple, in this case): > > [(1, "rn_1_vers_1", "wi den L...n")] > -- > ? ? ? ?Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ?wlfraed at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ > Thank you very much for detailed hints, I see, I should have mention the specification with my initial post... It is true, that nested tags of the same name aren't supported, but tags may appear anywhere in the text and aren't terminated with newline. The tag-value association is valid from the tag position until the next tag replacing the value or closing tag (like ) or to the end of the text file. Tags beginning at line beginnings are rather frequent, but they can appear anywhere else too. I actually only store the metadata in the database - i.e. the tag-value combinations for the corresponding text indices of the plain text. The database doesn't currently contain the text itself; plain text is used for fulltext regexp search, and it should be possible to find the relevant tags for the matches. I'll have a closer look on joins in sql and maybe redesign the data structure - now the tags data are copied for each text position with some tag change - in order to simplify queries; with multiple tables it could be more efficient to store the tags separately and look it up individually (probably using bisect (unless there is an SQL equivalent ?) Well, I still have many areas to investigate in this context ... regards, Vlastimil Brom From python at bdurham.com Sat Sep 18 17:24:32 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 18 Sep 2010 17:24:32 -0400 Subject: Standard library function to remove folder with files and subfolders? Message-ID: <1284845072.7300.1395698357@webmail.messagingengine.com> Is there a standard library function to remove a folder that may contain files and subfolders? Or must I write a function that walks my folder's children and deletes all files/subfolders first, and then call os.removedirs()? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sat Sep 18 17:36:49 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 18 Sep 2010 17:36:49 -0400 Subject: Standard library function to remove folder with files and subfolders? In-Reply-To: <1284845072.7300.1395698357@webmail.messagingengine.com> References: <1284845072.7300.1395698357@webmail.messagingengine.com> Message-ID: <950D062E-08C7-4190-A67F-241FDEE10EF3@semanchuk.com> On Sep 18, 2010, at 5:24 PM, python at bdurham.com wrote: > Is there a standard library function to remove a folder that may > contain files and subfolders? Or must I write a function that > walks my folder's children and deletes all files/subfolders > first, and then call os.removedirs()? In Python 2.x: shutil.rmtree() Might have moved in Python 3.x. HTH Philip From usenet-nospam at seebs.net Sat Sep 18 18:56:51 2010 From: usenet-nospam at seebs.net (Seebs) Date: 18 Sep 2010 22:56:51 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-18, Steven D'Aprano wrote: > On Fri, 17 Sep 2010 16:01:54 -0400, Andreas Waldenburger wrote: >> On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: >>> I also like this construct that works, I think, since 2.6: >>> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] >> I wonder when this construct will finally start to look good. > It looks good to me. It follows a common English idiom: > "What are you doing tonight?" > "I'll be going to the movies, if I finish work early, otherwise I'll stay > home and watch a DVD." I hate that idiom in English, too. If you're going to give me a forking conditional, I want to know about it early. Basically, I can handle do x if y pretty well, but do x if y else z always breaks my parser. So in English, I might say "I'll go to the store if I have time", but I'd rarely use "I'll go to the store if I have time, otherwise I'll send the house elf"; instead, I'd say "If I have time, I'll go to the store, otherwise I'll send the house elf." -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 Sat Sep 18 19:08:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Sep 2010 19:08:57 -0400 Subject: Why IterableUserDict? In-Reply-To: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> References: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 9/17/2010 11:12 PM, Steven D'Aprano wrote: > I was writing some tests for a mapping class I have made, and I decided > to run those same tests over dict and UserDict. The built-in dict passed > all the tests, but UserDict failed one: You forgot to specify Python version ;-). > > class SimpleMappingTest(unittest.TestCase): > type2test = UserDict.UserDict In 3.x, collections.UserDict > def test_iter(self): > k, v = [0, 1, 2, 3], 'abcd' > m = self.type2test(zip(k, v)) > it = iter(m) > self.assert_(iter(it) is it) > self.assertEquals(sorted(it), k) # This line fails. Not in 3.x import collections k, v = [0, 1, 2, 3], 'abcd' m = collections.UserDict(zip(k, v)) it = iter(m) assert iter(it) is it assert sorted(it) == k runs clean. > If I look at the source code for the UserDict module, I discover that > there's a second mapping class, IterableUserDict, Not any more. One of numerous 3.x cleanups made possible by dropping obsessive back compatibility, which, as Peter explained, wan the reason for the hack. -- Terry Jan Reedy From grahn+nntp at snipabacken.se Sat Sep 18 19:15:05 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 18 Sep 2010 23:15:05 GMT Subject: Learning inheritance References: Message-ID: On Sat, 2010-09-18, Niklasro wrote: > Hi > How can I make the visibility of a variable across many methods or > files? To avoid repeating the same line eg url = > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > os.environ['SERVER_NAME'] I repeat for many methods. So declaring it > to a super class and inheriting it is my plan. Do you agree or propose > otherwise? Inheritance is not the main tool for sharing code. Just make it a function and place it in one of your modules (files): def get_host(): """Return the environment's $HTTP_HOST if it exists, otherwise $SERVER_NAME or (if that doesn't exist either) None. """ ... Perhaps you are focusing too much on inheritance in general. I personally almost never use it in Python -- it has much fewer uses here than in staticaly typed languages. /Jorgen -- // Jorgen Grahn O o . From niklasro at gmail.com Sat Sep 18 19:19:56 2010 From: niklasro at gmail.com (Niklasro) Date: Sat, 18 Sep 2010 16:19:56 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> Message-ID: <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> On Sep 18, 4:13?pm, "bruno.desthuilli... at gmail.com" wrote: > On 18 sep, 17:25, Niklasro wrote: > > > Hi > > How can I make the visibility of a variable across many methods or > > files? To avoid repeating the same line eg ? ? url = > > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > > os.environ['SERVER_NAME'] > > First learn to use Python correctly: > > url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) > > => dict.get(key, default=None) > > Also and FWIW, neither HTTP_HOST not SERVER_NAME are really urls... > > > I repeat for many methods. So declaring it > > to a super class and inheriting it is my plan. Do you agree or propose > > otherwise? > > Not enough background to answer. Thanks for replying and informing correctness. More background is the variable I want accessible for many functions and files either is HTTP_HOST or SERVER_NAME used as beginning of url or resource locator indicated where the software is used. Instead of declaring the variable many times feasibility study is how to minify number of times I declare the same variable. I got 2 files main.py and i18n both with webapp request handlers which I would like access the variable. Thanks Niklas R From grahn+nntp at snipabacken.se Sat Sep 18 19:29:33 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 18 Sep 2010 23:29:33 GMT Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Sat, 2010-09-18, Lawrence D'Oliveiro wrote: > In message > <2f830099-4264-47bc-98ee-31950412ad43 at q21g2000prm.googlegroups.com>, cerr > wrote: > >> I get a socket error "[Errno 98] Address already in use" when i try to >> open a socket that got closed before with close(). How come close() >> doesn't close the socket properly? > > The usual case this happens is you have a client connection open at the > time, that was not properly terminated. Then the TCP stack goes through a > holdoff period (2 minutes, I believe it is), to make absolutely sure all > packets destined for the old connection have completely disappeared off the > entire Internet, before it will let you open a socket on the same port > again. That's why Stevens recommends that all TCP servers use the SO_REUSEADDR socket option. He also noted in his book: "This scenario is one of the most frequently asked questions on Usenet." Possibly I missed something in the question, but it's worth googling for. /Jorgen -- // Jorgen Grahn O o . From andrei.avk at gmail.com Sat Sep 18 19:31:44 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 19:31:44 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C954BE0.700@gmail.com> On 09/18/2010 06:56 PM, Seebs wrote: > On 2010-09-18, Steven D'Aprano wrote: >> On Fri, 17 Sep 2010 16:01:54 -0400, Andreas Waldenburger wrote: >>> On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: >>>> I also like this construct that works, I think, since 2.6: > >>>> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > >>> I wonder when this construct will finally start to look good. > >> It looks good to me. It follows a common English idiom: > >> "What are you doing tonight?" >> "I'll be going to the movies, if I finish work early, otherwise I'll stay >> home and watch a DVD." > > I hate that idiom in English, too. If you're going to give me a forking > conditional, I want to know about it early. > > Basically, I can handle > do x if y > pretty well, but > do x if y else z > always breaks my parser. > > So in English, I might say "I'll go to the store if I have time", but > I'd rarely use "I'll go to the store if I have time, otherwise I'll send > the house elf"; instead, I'd say "If I have time, I'll go to the store, > otherwise I'll send the house elf." > > -s I actually find the shorter version slightly more readable than full version. I think in English you'd say it in one sentence and that to me feels like it should vaguely correspond to one line in code (perhaps split over more than one line but that'd be due to long var names or complex operations, not inherently). The longer version may be like saying "I'll go to the store. If I have time. If I don't have time. I will send the house elf." It's a bit more readable to me because I can tell at a glance that a single variable gets assigned a value based on a condition. With a longer version it looks like something more complicated it going on, and the eye has to look at all four lines and jump to another ident level. By the way, it also looks far more readable in an editor where if and else would be highlighted vs. all in plain colour. -ak From grahn+nntp at snipabacken.se Sat Sep 18 19:33:58 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 18 Sep 2010 23:33:58 GMT Subject: The trouble with "dynamic attributes". References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4C92A7CC.8000505@mrabarnett.plus.com> <2e749113-5c9f-475e-85e5-f6c787559572@a30g2000vbt.googlegroups.com> Message-ID: On Fri, 2010-09-17, James Mills wrote: > On Fri, Sep 17, 2010 at 11:33 AM, moerchendiser2k3 > wrote: >> I am really sorry, but what are you talking about ? Hmmm, ...I have >> problems to compile Python on SL, I did not ask anything about >> "dynamic attribute". I don't get it... > > You are subscribed to the python mailing list. > > Check your subscription status with the link below. JN's posting was technically a reply to JM's SL question -- a References: header led back to it. That's why he was confused. /Jorgen -- // Jorgen Grahn O o . From usenet-nospam at seebs.net Sat Sep 18 19:38:19 2010 From: usenet-nospam at seebs.net (Seebs) Date: 18 Sep 2010 23:38:19 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-18, AK wrote: > On 09/18/2010 06:56 PM, Seebs wrote: >> Basically, I can handle >> do x if y >> pretty well, but >> do x if y else z >> always breaks my parser. >> So in English, I might say "I'll go to the store if I have time", but >> I'd rarely use "I'll go to the store if I have time, otherwise I'll send >> the house elf"; instead, I'd say "If I have time, I'll go to the store, >> otherwise I'll send the house elf." > I actually find the shorter version slightly more readable than full > version. I think in English you'd say it in one sentence and that to me > feels like it should vaguely correspond to one line in code (perhaps > split over more than one line but that'd be due to long var names or > complex operations, not inherently). I dunno, it always breaks my parser. The condition ends up between the two dependents, and that doesn't work for me. I can have conditions which are leading or trailing, but not infix. > It's a bit more readable to me because I can tell at a glance that a > single variable gets assigned a value based on a condition. With a > longer version it looks like something more complicated it going on, and > the eye has to look at all four lines and jump to another ident level. Ahh! I see. There's several variants that could be discussed. if condition: x = y else: x = z x = y if condition else z And then the one I'm used to from other languages: x = if condition then y else z The other thing, from my point of view, is an ambiguity with a common idiom I'm used to, again from other languages: x = y if condition If !condition, then nothing happens to x. So far as I can tell, that's a syntax error in Python -- I can't use postfix if to modify a sentence, because it's an expression thing. > By the way, it also looks far more readable in an editor where if and > else would be highlighted vs. all in plain colour. I use syntax coloring in programming languages precisely as often, and for precisely the same reasons, that I use it when writing in English. Which is to say, if such a feature exists, I turn it off immediately because it consistently distracts me from following the actual meaning of code. Syntax is the least part of the meaning of code; giving extra weight to syntax is pretty disruptive, IMHO. -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 andrei.avk at gmail.com Sat Sep 18 20:00:32 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 20:00:32 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C9552A0.1060406@gmail.com> On 09/18/2010 07:38 PM, Seebs wrote: > On 2010-09-18, AK wrote: >> On 09/18/2010 06:56 PM, Seebs wrote: >>> Basically, I can handle >>> do x if y >>> pretty well, but >>> do x if y else z >>> always breaks my parser. > >>> So in English, I might say "I'll go to the store if I have time", but >>> I'd rarely use "I'll go to the store if I have time, otherwise I'll send >>> the house elf"; instead, I'd say "If I have time, I'll go to the store, >>> otherwise I'll send the house elf." > >> I actually find the shorter version slightly more readable than full >> version. I think in English you'd say it in one sentence and that to me >> feels like it should vaguely correspond to one line in code (perhaps >> split over more than one line but that'd be due to long var names or >> complex operations, not inherently). > > I dunno, it always breaks my parser. The condition ends up between > the two dependents, and that doesn't work for me. I can have conditions > which are leading or trailing, but not infix. > >> It's a bit more readable to me because I can tell at a glance that a >> single variable gets assigned a value based on a condition. With a >> longer version it looks like something more complicated it going on, and >> the eye has to look at all four lines and jump to another ident level. > > Ahh! I see. There's several variants that could be discussed. > > if condition: > x = y > else: > x = z > > x = y if condition else z > > And then the one I'm used to from other languages: > > x = if condition then y else z > > The other thing, from my point of view, is an ambiguity with a common > idiom I'm used to, again from other languages: > > x = y if condition > > If !condition, then nothing happens to x. So far as I can tell, that's > a syntax error in Python -- I can't use postfix if to modify a sentence, > because it's an expression thing. > >> By the way, it also looks far more readable in an editor where if and >> else would be highlighted vs. all in plain colour. > > I use syntax coloring in programming languages precisely as often, and > for precisely the same reasons, that I use it when writing in English. > Which is to say, if such a feature exists, I turn it off immediately > because it consistently distracts me from following the actual meaning > of code. Syntax is the least part of the meaning of code; giving extra > weight to syntax is pretty disruptive, IMHO. Funny that you should say that, because I thought quite a few times that it would be really awesome if some texts in English had syntax highlighting. Obviously, not Brothers Karamazov, but something like a tutorial, or a manual, or an online article. If key words were highlighted, I'd be able to quickly glance over parts that are not useful to me at the time, and find the interesting bits. For instance, in the above paragraph I'd highlight 'awesome', 'English', 'syntax highlighting', 'tutorial', 'manual', 'online article', 'quickly glance over', 'not useful', 'find', 'interesting bits'. It'd be like speed reading, except real! -ak From ldo at geek-central.gen.new_zealand Sat Sep 18 20:27:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 12:27:08 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message , Jorgen Grahn wrote: > That's why Stevens recommends that all TCP servers use the > SO_REUSEADDR socket option. I don?t think I?ve ever used that. It seems to defeat a safety mechanism which was put in for a reason. From usenet-nospam at seebs.net Sat Sep 18 20:35:14 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 00:35:14 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, AK wrote: > Funny that you should say that, because I thought quite a few times that > it would be really awesome if some texts in English had syntax > highlighting. Obviously, not Brothers Karamazov, but something like a > tutorial, or a manual, or an online article. If key words were > highlighted, I'd be able to quickly glance over parts that are not > useful to me at the time, and find the interesting bits. That wouldn't be *syntax* highlighting, that'd be *semantic* highlighting. Which people often do -- notice that I did it twice in that paragraph. But that's the point -- you need to know what it *means* to make sensible decisions about what to highlight. Syntax highlighting is precisely the opposite, highlighting things for reasons that have nothing to do with their semantic content. It distracts from the actual meaning of the code. In short, syntax highlighting would be like writing: FUNNY *that* _you_ *should* /say/ *that*. > It'd be like speed reading, except real! I don't understand this. So far as I know, the phrase "speed reading" refers to various methods of reading much faster than most people read, and is real but not exceptionally interesting. -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 pavlovevidence at gmail.com Sat Sep 18 20:35:14 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 18 Sep 2010 17:35:14 -0700 (PDT) Subject: Learning inheritance References: Message-ID: <77705adb-48d5-4b3d-9398-feb27dee16b7@y32g2000prc.googlegroups.com> On Sep 18, 4:15?pm, Jorgen Grahn wrote: > On Sat, 2010-09-18, Niklasro wrote: > > Hi > > How can I make the visibility of a variable across many methods or > > files? To avoid repeating the same line eg ? ? url = > > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > > os.environ['SERVER_NAME'] I repeat for many methods. So declaring it > > to a super class and inheriting it is my plan. Do you agree or propose > > otherwise? > > Inheritance is not the main tool for sharing code. That statement might be a little too general to be true. Inheritance is a (or the) main tool for different objects to share behavior, which is implemented by code. So when your program is organized around objects, it is the (or a) main tool. You are right that you shouldn't rework your code into an OO style simply because you want to share code. I think that's what you meant. > Just make it a > function and place it in one of your modules (files): Or even just make it a global variable in the module (which would work in this case, unless you plan to update the environment within the program). Carl Banks From andrei.avk at gmail.com Sat Sep 18 21:58:58 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 21:58:58 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C956E62.4070001@gmail.com> On 09/18/2010 08:35 PM, Seebs wrote: > On 2010-09-19, AK wrote: >> Funny that you should say that, because I thought quite a few times that >> it would be really awesome if some texts in English had syntax >> highlighting. Obviously, not Brothers Karamazov, but something like a >> tutorial, or a manual, or an online article. If key words were >> highlighted, I'd be able to quickly glance over parts that are not >> useful to me at the time, and find the interesting bits. > > That wouldn't be *syntax* highlighting, that'd be *semantic* highlighting. In case of programming, the effect is similar. I find that it allows me to look quickly through code, scanning for something specific, e.g. the next function, the next if/else block. If I'm looking for a print statement, for example, I can quickly scan a whole screenful, looking for a first highlighted long word (all the other highlighted keywords will usually be if, else, and for). On the other hand, if I know I'm looking for a variable, my eyes will filter out all the highlighted text - strings and keywords. English is of course much less formal so you have to understand the text to do useful highlighting. Anyway, I find it very odd that anyone would not find it extremely useful (in code)! > > Which people often do -- notice that I did it twice in that paragraph. But > that's the point -- you need to know what it *means* to make sensible > decisions about what to highlight. Syntax highlighting is precisely the > opposite, highlighting things for reasons that have nothing to do with > their semantic content. It distracts from the actual meaning of the > code. I'm not always looking for meaning *immediately*. If I know there's a single print statement in a function, I don't need to understand its meaning to know that's the one print statement I need. (Or, if there's two, I might know that I need the first one or at least I'll have 2 lines to look at instead of 75). > > In short, syntax highlighting would be like writing: > > FUNNY *that* _you_ *should* /say/ *that*. > >> It'd be like speed reading, except real! > > I don't understand this. So far as I know, the phrase "speed reading" > refers to various methods of reading much faster than most people read, > and is real but not exceptionally interesting. Afaik the idea is that you can read a novel at the speed of half a page a second or so and understand it to the same extent as people who'd read at a normal rate. Woody Allen joke: "I learned speed reading and read War&Peace"; - it involves Russia. -ak From pavlovevidence at gmail.com Sat Sep 18 22:00:09 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 18 Sep 2010 19:00:09 -0700 (PDT) Subject: ctypes and buffers Message-ID: I am creating a ctypes buffer from an existing non-ctypes object that supports buffer protocol using the following code: from ctypes import * PyObject_AsReadBuffer = pythonapi.PyObject_AsReadBuffer PyObject_AsReadBuffer.argtypes = [py_object,POINTER(c_void_p),POINTER(c_size_t)] PyObject_AsReadBuffer.restype = None def ctypes_buffer_from_buffer(buf): cbuf = c_void_p() size = c_size_t() PyObject_AsReadBuffer(buf,byref(cbuf),byref(size)) return cbuf It works, but is there a standard way to do this in ctypes? I couldn't find anything in the documentation. Python 2.6 for now. Thanks. Carl Banks From andrei.avk at gmail.com Sat Sep 18 22:04:26 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 22:04:26 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4C9552A0.1060406@gmail.com> Message-ID: <4C956FAA.2020401@gmail.com> On 09/18/2010 09:08 PM, Dennis Lee Bieber wrote: > On Sat, 18 Sep 2010 20:00:32 -0400, AK declaimed > the following in gmane.comp.python.general: > > >> Funny that you should say that, because I thought quite a few times that >> it would be really awesome if some texts in English had syntax >> highlighting. Obviously, not Brothers Karamazov, but something like a >> tutorial, or a manual, or an online article. If key words were >> highlighted, I'd be able to quickly glance over parts that are not >> useful to me at the time, and find the interesting bits. >> >> For instance, in the above paragraph I'd highlight 'awesome', 'English', >> 'syntax highlighting', 'tutorial', 'manual', 'online article', >> 'quickly glance over', 'not useful', 'find', 'interesting bits'. >> > > Syntax highlighting is more likely to identify: be, if, had, but, > like, or, were, are, not, and. That is, the (relatively) fixed > connectors between arbitrary nouns and concepts. > > be if had. > not, but like, or. If > were are not, and Yes, I didn't mean that it's exactly the same, of course. Python being much more formal than English means automatic syntax highlight can be useful, as obviously many people find it; although this gave me an interesting idea: if you had a long text that you wished to read quickly, it might be more efficient to do syntax highlight of all verbs, quickly scan through the text, then syntax highlight of all nouns, do another quick scan, and then turn off syntax highlight and concentrate on the parts that you did not understand while scanning. Is there a program that'd do something like that? -ak From pavlovevidence at gmail.com Sat Sep 18 22:09:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> Message-ID: <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> On Sep 17, 1:01?pm, Andreas Waldenburger wrote: > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > > > I also like this construct that works, I think, since 2.6: > > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > I wonder when this construct will finally start to look good. I don't know if it'll ever look good, per se, but it looks better when it's used in rule-exception sort of case: something = rule if condition else exception Then the "tacked-on" feel the "if condition else exception" part works because it is actually tacked on. Apart from occasions like this and throwaway one-liners I use regular if-then statements. If Python had added the C-like a ? b : c, then I'd use it a lot more, since that version is not inherently unbalanced. Carl Banks From usenet-nospam at seebs.net Sat Sep 18 22:12:58 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 02:12:58 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, AK wrote: > On 09/18/2010 08:35 PM, Seebs wrote: >> That wouldn't be *syntax* highlighting, that'd be *semantic* highlighting. > In case of programming, the effect is similar. I have not found that to be the case. It's been exactly the same as syntax highlighting in English would be -- it's wasting bandwidth telling me things I already know, which slows down my perception of the things I'm trying to find out. Hmm. Actually, one thing -- I think I sometimes find it useful for a couple of days on a new language I don't know yet. It's helpful then, but once I've got my parser trained, it's a distraction. > Anyway, I find it > very odd that anyone would not find it extremely useful (in code)! Yes, and I find it inexplicable that people find it useful. News flash: Not all people think the same way. Film at 11. :) I've tried to use syntax coloring editors, and I've always found that they end up making me slower and less accurate at reading things, because what they're highlighting isn't waht what I need to know. >> I don't understand this. So far as I know, the phrase "speed reading" >> refers to various methods of reading much faster than most people read, >> and is real but not exceptionally interesting. > Afaik the idea is that you can read a novel at the speed of half a page > a second or so and understand it to the same extent as people who'd read > at a normal rate. Woody Allen joke: "I learned speed reading and > read War&Peace"; - it involves Russia. I dunno about that speed, but as I recall, my default reading speed for English is about the range that people advertise in "speed reading" courses, and I end up understanding text about as well as other people do. -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 fridge at micro.com Sat Sep 18 22:23:15 2010 From: fridge at micro.com (fridge) Date: Sun, 19 Sep 2010 12:23:15 +1000 Subject: Plz comment on this code Message-ID: <4c957412$0$3036$afc38c87@news.optusnet.com.au> # bigdigits2.py import sys zero=["***", "* *", "***"] one=["***", " * ", "***"] digits=[zero,one,zero,one,zero,one,zero,one,zero,one] inputted_digit=sys.argv[1] column_max=len(inputted_digit) row_max=3 r=0 while r<3: line="" c=0 while c From wuwei23 at gmail.com Sat Sep 18 22:31:39 2010 From: wuwei23 at gmail.com (alex23) Date: Sat, 18 Sep 2010 19:31:39 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> Message-ID: Niklasro wrote: > I got 2 files main.py and i18n both with > webapp request handlers which I would like access the variable. I'd probably use a module for this. Create a third file, called something like shared.py, containing the line that bruno gave above: url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) Then from within both main & i18n you can 'import shared' and access the variable as 'shared.url'. Python only actually executes a module the first time it's imported, every other import will be given a reference to the same module object. This also lets you share temporary data between modules. Any module that imports 'shared' can add an attribute to it ('shared.foo = "barbaz"') that will be visible to all other modules that have (or will have) imported it. From andrei.avk at gmail.com Sat Sep 18 22:49:29 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 22:49:29 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C957A39.6070105@gmail.com> On 09/18/2010 10:12 PM, Seebs wrote: > On 2010-09-19, AK wrote: >> On 09/18/2010 08:35 PM, Seebs wrote: News flash: Not all people think the same way. Film at 11. :) > > I've tried to use syntax coloring editors, and I've always found that > they end up making me slower and less accurate at reading things, > because what they're highlighting isn't waht what I need to know. The way I see it, it's not meant to tell you something, it's punctuation, it's as if you'd argue against periods and spaces at the end of sentencesBecause the next sentence is capitalized anyway, so you already know the last sentence ended. In the same way, in many cases other punctuation is not absolutely necessary for understanding. The other thing is of course that it helps you not to name your variables using keywords and spot misspelled keywords. -ak From jason.swails at gmail.com Sat Sep 18 22:52:05 2010 From: jason.swails at gmail.com (Jason Swails) Date: Sat, 18 Sep 2010 22:52:05 -0400 Subject: Plz comment on this code In-Reply-To: <4c957412$0$3036$afc38c87@news.optusnet.com.au> References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: On Sat, Sep 18, 2010 at 10:23 PM, fridge wrote: > # bigdigits2.py > ^ Here is the comment > > import sys > > zero=["***", > "* *", > "***"] > one=["***", > " * ", > "***"] > digits=[zero,one,zero,one,zero,one,zero,one,zero,one] > > inputted_digit=sys.argv[1] > column_max=len(inputted_digit) > row_max=3 > > r=0 > while r<3: > line="" > c=0 > while c digit_i=int(inputted_digit[c]) > digit=digits[digit_i] > line+=digit[r] > line+=" " > c+=1 > print(line) > r+=1 > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Sep 18 23:01:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 03:01:59 GMT Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: <4c957d27$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 12:23:15 +1000, fridge wrote: > # bigdigits2.py [snip code] It looks like Python. Did you have a specific question? P.S. Please don't send HTML to non-binary news groups, it's very annoying. And if you're sending it by email, your mail client appears to be broken, because it's just dumping the HTML code after the plain text. > > > [and much more HTML junk] P.P.S. If you can't even be bothered to spell "Please" in full, you probably shouldn't expect many people to be bothered to read your code in detail and comment extensively. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Sep 18 23:20:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 03:20:38 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> Message-ID: <4c958185$0$11113$c3e8da3@news.astraweb.com> On Sat, 18 Sep 2010 19:09:33 -0700, Carl Banks wrote: > Apart from occasions like this and throwaway one-liners I use regular > if-then statements. If Python had added the C-like a ? b : c, then I'd > use it a lot more, since that version is not inherently unbalanced. Define "unbalanced". Putting aside the over-use of punctuation, The C syntax feels unbalanced to me. You have: condition IF true-clause ELSE false-clause so both clauses follow the test, that is, they're on the same side: ?-- This looks unbalanced to me. And it reads like something Yoda would say, or Forth code. But the Python syntax looks balanced to me: true-clause IF condition ELSE false-clause which is not only plain English, but perfectly balanced, with a clause on either side of the test: -?- Python's ternary-if puts the emphasis on the true-clause, while C's ternary-if puts the emphasis on the test. I'm not convinced that this is necessarily a better choice than Python's. It's a *valid* choice, but better? I don't think so, but I accept that at least partially boils down to subjective factors. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Sep 18 23:28:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 03:28:48 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c958370$0$11113$c3e8da3@news.astraweb.com> On Sat, 18 Sep 2010 21:58:58 -0400, AK wrote: >> I don't understand this. So far as I know, the phrase "speed reading" >> refers to various methods of reading much faster than most people read, >> and is real but not exceptionally interesting. > > Afaik the idea is that you can read a novel at the speed of half a page > a second or so and understand it to the same extent as people who'd read > at a normal rate. Woody Allen joke: "I learned speed reading and read > War&Peace"; - it involves Russia. My wife can read scarily fast. It's very something to watch her reading pages as fast as she can turn them, and a few years ago she read the entire Harry Potter series (to date) in one afternoon, and could gives a blow-by-blow account of the plots, including a detailed critique of the writing style and characters. But then, she feels that reading the Potter series is a chore to be completed as fast as possible, rather than a pleasure to be savored. She'll sometimes drag a new Terry Pratchett or Stephen King novel out for as much as two days. -- Steven From ethan at stoneleaf.us Sun Sep 19 00:23:21 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 21:23:21 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> Message-ID: <4C959039.5070700@stoneleaf.us> Vernon Cole wrote: > Ethan: > I cannot see where you mentioned your operating system, I am assuming > Windows. > > Perhaps you have already investigated this ... I have no way to test it > ... but you might try: > ADO can access almost any data source, and a quick look seems to show > that .dbf is supported using the JET driver or a FoxPro driver. > > 1) upload pywin32 > 2) import adodbapi > 3) find an appropriate connection string for your data source > http://connectionstrings.com suggests that perhaps: > Driver={Microsoft Visual FoxPro > Driver};SourceType=DBF;SourceDB=c:\myvfpdbfolder;Exclusive=No; > Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO; > may be a good sample to start with -- there are other variations, check > their site. > 4) do your data input/output using standard Python db-api calls. > > see python\lib\site-packages\adodbapi\test\ for usage examples > > You can get pywin32 from http://sourceforge.net/projects/pywin32 Thanks for the suggestion, but I don't want to be tied to Foxpro, which means I need to be able to parse these files directly. I have the dbf files, now I need the idx and cdx files. -- ~Ethan~ From carl at personnelware.com Sun Sep 19 00:36:54 2010 From: carl at personnelware.com (Carl Karsten) Date: Sat, 18 Sep 2010 23:36:54 -0500 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: <4C959039.5070700@stoneleaf.us> References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> <4C959039.5070700@stoneleaf.us> Message-ID: On Sat, Sep 18, 2010 at 11:23 PM, Ethan Furman wrote: > Vernon Cole wrote: >> >> Ethan: >> I cannot see where you mentioned your operating system, I am assuming >> Windows. >> >> Perhaps you have already investigated this ... I have no way to test it >> ... but you might try: >> ADO can access almost any data source, and a quick look seems to show that >> .dbf is supported using the JET driver or a FoxPro driver. >> >> 1) upload pywin32 >> 2) import adodbapi >> 3) find an appropriate connection string for your data source >> http://connectionstrings.com suggests that perhaps: >> Driver={Microsoft Visual FoxPro >> Driver};SourceType=DBF;SourceDB=c:\myvfpdbfolder;Exclusive=No; >> Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO; >> may be a good sample to start with -- there are other variations, check >> their site. >> 4) do your data input/output using standard Python db-api calls. >> >> see python\lib\site-packages\adodbapi\test\ for usage examples >> >> You can get pywin32 from http://sourceforge.net/projects/pywin32 > > Thanks for the suggestion, but I don't want to be tied to Foxpro, which > means I need to be able to parse these files directly. ?I have the dbf > files, now I need the idx and cdx files. What do you mean "tied" ? -- Carl K From ldo at geek-central.gen.new_zealand Sun Sep 19 00:46:33 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 16:46:33 +1200 Subject: This Is International =?UTF-8?B?RG9u4oCZdC1TcXVhd2stTGlrZS1BLVBhcnJvdA==?= Day Message-ID: Do your bit to help stamp out parrocy. Thank you. From ethan at stoneleaf.us Sun Sep 19 00:51:56 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 21:51:56 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> Message-ID: <4C9596EC.40906@stoneleaf.us> Dennis Lee Bieber wrote: > On Sat, 18 Sep 2010 10:44:06 -0700, Ethan Furman > declaimed the following in gmane.comp.python.general: > > >>I have a pure-python module to read db3 and vfp 6 dbf files, and I find >>that I need to read (and write) the idx and cdx index files that foxpro >>generates. We are in the process of switching from homegrown foxpro >>apps to homegrown python apps, but I have to support the foxpro file >>formats until the switch is complete. Once I have the index files down, >>I'll publish another release of it (an older version can be found on PyPI). >> > > Seems odd that you'd have to do all that low-level processing... Do > you have the VFP ODBC driver on the systems? That would permit just > using ODBC queries to operate on the data. Hmmm. I may look at that. When I first started this project, I was brand new to Python and unaware of all the cool stuff out there. It was a great learning project -- iterators, magic methods, emulating sequences and attributes, properties, class methods, inheritence, packages... it has been quite an adventure! It's probably a safe bet that I don't /need/ to, but I certainly /want/ to. It would be a finished project, and a sense of accomplishment. Thanks for the suggestion. -- ~Ethan~ From ethan at stoneleaf.us Sun Sep 19 01:10:16 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 22:10:16 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> <4C959039.5070700@stoneleaf.us> Message-ID: <4C959B38.3040108@stoneleaf.us> Carl Karsten wrote: > On Sat, Sep 18, 2010 at 11:23 PM, Ethan Furman wrote: >>Thanks for the suggestion, but I don't want to be tied to Foxpro, which >>means I need to be able to parse these files directly. I have the dbf >>files, now I need the idx and cdx files. > > > > What do you mean "tied" ? I meant having to have Foxpro installed. I just learned from another reply that I may not have to have Foxpro installed as long as I have the Foxpro ODBC driver, because then I could use odbc instead of fiddling with the files directly. While I may switch over to odbc in the future, I would still like to have the idx/cdx components. -- ~Ethan~ From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 01:25:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 05:25:48 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c959edc$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 00:35:14 +0000, Seebs wrote: > On 2010-09-19, AK wrote: >> Funny that you should say that, because I thought quite a few times >> that it would be really awesome if some texts in English had syntax >> highlighting. Obviously, not Brothers Karamazov, but something like a >> tutorial, or a manual, or an online article. If key words were >> highlighted, I'd be able to quickly glance over parts that are not >> useful to me at the time, and find the interesting bits. > > That wouldn't be *syntax* highlighting, that'd be *semantic* > highlighting. > > Which people often do -- notice that I did it twice in that paragraph. > But that's the point -- you need to know what it *means* to make > sensible decisions about what to highlight. Syntax highlighting is > precisely the opposite, highlighting things for reasons that have > nothing to do with their semantic content. It distracts from the actual > meaning of the code. I'm not entirely sure I agree with you here... you can't ignore syntax in order to understand the meaning of code. Unless you understand the syntax, even a simple line like: x = y is impossible to understand. Is it an assignment? If so, which way (does it assign the value of x to the variable y, or y to x)? Or is it a comparison? The term "syntax highlighting" for what editors I've seen do is actually misleading -- they don't highlight *syntax*, they try to highlight *semantics*. When your editor highlights the function len() in the expression "x = len(y) + spam(z)" but not the function spam(), you know it has nothing to do with syntax. len() is singled out because of its semantics, namely the fact that it's a built-in. In English, the meaning of the some sentences do benefit by syntax highlighting, and in fact that's partly what punctuation is for: English partly uses punctuation marks as tags to break the sentence structure into sub-sentences, clauses and terms (particularly when the sentence would otherwise be ambiguous). An extreme example is the infamous "buffalo" sentence, which is grammatically valid and semantically meaningful but rather difficult to decipher: http://en.wikipedia.org/wiki/Buffalo_buffalo_Buffalo_buffalo_buffalo_buffalo_Buffalo_buffalo Of course this is an extreme example, but English is often ambiguous, and some sort of syntax highlighting could potentially be useful: "Woman shoots man with crossbow" Was it the man armed with a crossbow, or the woman? If we could somehow group the clause "with crossbow" with "woman" or "man" by something *other* than proximity, we could remove the ambiguity. In ordinary English, not only does punctuation sometimes play the role of syntax highlighting, but so do otherwise meaningless words like "the", "a", "which", "that", "also", and so forth. Bringing it back to Python, that's why punctuation like : are useful. They're syntax highlighting. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 01:26:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 05:26:58 GMT Subject: Why IterableUserDict? References: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c959f21$0$11113$c3e8da3@news.astraweb.com> On Sat, 18 Sep 2010 09:42:14 +0200, Peter Otten wrote: [...] >> Now that boggles my brain. Why was support for iteration added as a >> subclass, instead of simply adding the __iter__ method to UserDict? >> UserDict is supposed to be a drop-in replacement for dict (although the >> use-cases for it are much fewer now that we can inherit from dict), so >> it doesn't make sense to me to have a non-iterable UserDict plus a >> subclass which is iterable. >> >> Can anyone shed any light on this apparently bizarre design decision? > > I looked it up for you: > > http://svn.python.org/view/python/trunk/Lib/UserDict.py?view=log [...] > The bug report is also interesting: > > http://bugs.python.org/issue448153 Oh my. Guido is more forgiving than me. I would have left __iter__ in UserDict and treated the bug report as a "will not fix". Thanks for that. -- Steven From nobody at nowhere.com Sun Sep 19 01:36:19 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 19 Sep 2010 06:36:19 +0100 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Sun, 19 Sep 2010 12:27:08 +1200, Lawrence D'Oliveiro wrote: >> That's why Stevens recommends that all TCP servers use the >> SO_REUSEADDR socket option. > > I don?t think I?ve ever used that. It seems to defeat a safety mechanism > which was put in for a reason. It was put in for the benefit of clients, to prevent them from selecting a port which they won't be able to use. At the point that the program calls bind(), the kernel doesn't know whether the program will call connect() or listen() next (i.e. whether it's a client or a server). Even if you set SO_REUSEADDR, you cannot create a connection which could be confused with an existing connection, i.e. one with the same source and destination address and port (BSD allows this provided that the previous connection is closed and the initial sequence number of the new connection exceeds the final sequence number of the previous connection). For a client, re-using the port would mean that any attempt to connect to the same port and address as an existing TIME_WAIT connection will fail with EADDRINUSE, so it should choose another port. This scenario is quite likely, as a client for a particular protocol will tend to connect to a specific remote port, and often to a small set of servers. But a server often has to use a specific port, and its clients will typically connect from ephemeral ports. Even if some clients insist on trying to use a specific source port (which will fail so long as the TIME_WAIT connections exist), the server can still serve other clients. From ldo at geek-central.gen.new_zealand Sun Sep 19 02:42:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 18:42:51 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message , Nobody wrote: > On Sun, 19 Sep 2010 12:27:08 +1200, Lawrence D'Oliveiro wrote: > >>> That's why Stevens recommends that all TCP servers use the >>> SO_REUSEADDR socket option. >> >> I don?t think I?ve ever used that. It seems to defeat a safety mechanism >> which was put in for a reason. > > It was put in for the benefit of clients, to prevent them from selecting > a port which they won't be able to use. But clients typically don?t care what port they use?they let the system pick a port for them, so this kind of option is unnecessary. From lie.1296 at gmail.com Sun Sep 19 02:47:26 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 19 Sep 2010 16:47:26 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4c93a06c$1@dnews.tpgi.com.au> Message-ID: <4c95b1c3$1@dnews.tpgi.com.au> On 09/18/10 03:53, Ethan Furman wrote: > Lie Ryan wrote: > [snip] >> And even dict-syntax is not perfect for accessing XML file, e.g.: >> >> >> foo >> bar >> >> >> should a['b'] be 'foo' or 'bar'? > > Attribute style access would also fail in this instance -- how is this > worked-around? By not having multiple b in the first place! However, if you cannot avoid having duplicates, then you would have to use a different approach: SAX (Simple API for XML; Java has a weird sense of simplicity): import xml.sax as sax from xml.sax.handler import ContentHandler class MyHandler(ContentHandler): def __init__(self): self.inB = False def startElement(self, name, attrs): if name == 'b': self.inB = True def characters(self, ch): if self.inB: print ch def endElement(self, name): if name == 'b': self.inB = False data = 'FooEvilBar' sax.parseString(data, MyHandler()) or in ElementTree: import xml.etree.ElementTree as et data = 'FooEvilBar' a = et.fromstring(data) for elem in a.findall('b'): print elem.text From martin at v.loewis.de Sun Sep 19 03:09:04 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 19 Sep 2010 09:09:04 +0200 Subject: compile Py2.6 on SL In-Reply-To: References: Message-ID: <4C95B710.8060605@v.loewis.de> Am 16.09.2010 17:34, schrieb moerchendiser2k3: > Hi, > > I have some trouble with Python on Snow Leopard (10.6.3). I compile > Python as a framework(for 32/64bit) without any problems. > But implementing the lib in my C app, I get the following error on > linking: > > Undefined symbols: > "_Py_InitModule4_64", referenced from: > RegisterModule_BPY(char const*, PyMethodDef*, char const*, > _object*, int)in i_moduleobject.o > ld: symbol(s) not found > > I read a lot of stuff about this problem, but nothing helped me. My > app is in 64-bit and I compiled Python for 32/64bit. I'm skeptical that you did - if you really *had* compiled Python for AMD64, this error would not have occured. Please use file/lipo to verify that the Python library really is available as 64-bit code. Regards, Martin From niklasro at gmail.com Sun Sep 19 03:13:04 2010 From: niklasro at gmail.com (Niklasro) Date: Sun, 19 Sep 2010 00:13:04 -0700 (PDT) Subject: Learning inheritance References: Message-ID: On Sep 18, 11:15?pm, Jorgen Grahn wrote: > On Sat, 2010-09-18, Niklasro wrote: > > Hi > > How can I make the visibility of a variable across many methods or > > files? To avoid repeating the same line eg ? ? url = > > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > > os.environ['SERVER_NAME'] I repeat for many methods. So declaring it > > to a super class and inheriting it is my plan. Do you agree or propose > > otherwise? > > Inheritance is not the main tool for sharing code. Just make it a > function and place it in one of your modules (files): > > def get_host(): > ? ?"""Return the environment's $HTTP_HOST if > ? ?it exists, otherwise $SERVER_NAME or (if that > ? ?doesn't exist either) None. > ? ?""" > ? ?... > > Perhaps you are focusing too much on inheritance in general. > I personally almost never use it in Python -- it has much fewer > uses here than in staticaly typed languages. > > /Jorgen > > -- > ? // Jorgen Grahn \X/ ? ? snipabacken.se> ? O ?o ? . Thanks for sharing the knowledge. I alternatively think about declaring the variable in a setting.py file and import it. It doesn't create many objects but I want to learn more professional code conventions than same test repeated. Sincerely, Niklas R From niklasro at gmail.com Sun Sep 19 03:14:42 2010 From: niklasro at gmail.com (Niklasro) Date: Sun, 19 Sep 2010 00:14:42 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> Message-ID: On Sep 19, 2:31?am, alex23 wrote: > Niklasro wrote: > > I got 2 files main.py and i18n both with > > webapp request handlers which I would like access the variable. > > I'd probably use a module for this. Create a third file, called > something like shared.py, containing the line that bruno gave above: > > url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) > > Then from within both main & i18n you can 'import shared' and access > the variable as 'shared.url'. > > Python only actually executes a module the first time it's imported, > every other import will be given a reference to the same module > object. This also lets you share temporary data between modules. Any > module that imports 'shared' can add an attribute to it ('shared.foo = > "barbaz"') that will be visible to all other modules that have (or > will have) imported it. I try a file setting.py declaring it like this just loose in the file not knowing much theory about it thinking it's easy and intuitive. Thanks Niklas From __peter__ at web.de Sun Sep 19 03:22:41 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 19 Sep 2010 09:22:41 +0200 Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: fridge wrote: > # bigdigits2.py > > import sys > > zero=["***", > "* *", > "***"] > one=["***", > " * ", > "***"] > digits=[zero,one,zero,one,zero,one,zero,one,zero,one] > > inputted_digit=sys.argv[1] > column_max=len(inputted_digit) > row_max=3 > > r=0 > while r<3: > line="" > c=0 > while c digit_i=int(inputted_digit[c]) > digit=digits[digit_i] > line+=digit[r] > line+=" " > c+=1 > print(line) > r+=1 - Add a docstring at the beginning of the script explaining what it is meant to do. - Use four-space indent; add a space between names and operators. - Replace the while-loops with for-loops. You can iterate over numbers and characters: >>> for i in range(3): ... print(i) ... 0 1 2 >>> for c in "abc": ... print(c) ... a b c Peter From niklasro at gmail.com Sun Sep 19 03:22:49 2010 From: niklasro at gmail.com (Niklasro) Date: Sun, 19 Sep 2010 00:22:49 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> Message-ID: <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> It works but I don't know whether it's formally inheritance or class variable. Before code was url = os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else os.environ['SERVER_NAME'] if url.find('niklas') > 0: and now the change saves me from repeating myself! util.py: url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) #declared as class variable(?) And viola just test if util.url.find('niklas') > 0: Exactly what I wanted to do with your experienced guidance. Many thanks Happy refactored From usenet-nospam at seebs.net Sun Sep 19 03:31:18 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 07:31:18 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, Steven D'Aprano wrote: > Define "unbalanced". I'm not sure that's the word I'd use. I'm not even sure what it would mean here. > Putting aside the over-use of punctuation, The C syntax feels unbalanced > to me. You have: > condition IF true-clause ELSE false-clause > so both clauses follow the test, that is, they're on the same side: ?-- Yes. Just like: if condition: foo else: bar The condition is the primary, the clauses are secondary to it. So I like that form because it matches what I'd write if I were writing things out more verbosely for some reason. > But the Python syntax looks balanced to me: > true-clause IF condition ELSE false-clause > which is not only plain English, but perfectly balanced, with a clause on > either side of the test: -?- It may be balanced, but it requires you to reevaluate what you're reading after you've already read something that seemed to have a clear meaning. Basically, think of what happens as I read each symbol: x = x + 1 if condition else x - 1 Up through the '1', I have a perfectly ordinary assignment of a value. The, suddenly, it retroactively turns out that I have misunderstood everything I've been reading. I am actually reading a conditional, and the things I've been seeing which looked like they were definitely part of the flow of evaluation may in fact be completely skipped. It's even more confusing if I'm familiar with the postfix-if as seen in, say, perl or ruby. > Python's ternary-if puts the emphasis on the true-clause, while C's > ternary-if puts the emphasis on the test. I'm not convinced that this is > necessarily a better choice than Python's. It's a *valid* choice, but > better? I don't think so, but I accept that at least partially boils down > to subjective factors. I would usually think it better, just because most often, the *fact* of there being a test is the first thing you have to know about the expression to make sense of it. If I am given the right framework first, and the information to fill into it second, I don't have to throw away parsing I'd already done. If I'm given information, then later retroactively told to move it into a slot in a framework I didn't even know I was going to need, I have to do a lot of reworking. Consider the following lovely hypothetical syntax: foo bar baz if condition else: blah blah blah And there, at least you have some cue that you're about to see something happen. -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 Sep 19 03:36:11 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 07:36:11 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, Steven D'Aprano wrote: > I'm not entirely sure I agree with you here... you can't ignore syntax in > order to understand the meaning of code. No, but the syntax should be invisible. When I read English, I don't have to think about nouns and verbs and such unless something is very badly written. The syntax is handled automatically at a lower level without conscious intervention, as it should be. Calling my conscious attention to it is disruptive. > The term "syntax highlighting" for what editors I've seen do is actually > misleading -- they don't highlight *syntax*, they try to highlight > *semantics*. I've never seen this. I've seen things highlight comments and keywords and operators and constants and identifiers differently. > When your editor highlights the function len() in the > expression "x = len(y) + spam(z)" but not the function spam(), you know > it has nothing to do with syntax. len() is singled out because of its > semantics, namely the fact that it's a built-in. Eww. (I had not yet gotten to the point of finding out that whether something was "built-in" or not substantially affected its semantics.) > In English, the meaning of the some sentences do benefit by syntax > highlighting, and in fact that's partly what punctuation is for: English > partly uses punctuation marks as tags to break the sentence structure > into sub-sentences, clauses and terms (particularly when the sentence > would otherwise be ambiguous). Punctuation is very different from highlighting, IMHO. That said, I find punctuation very effective at being small and discrete, clearly not words, and easy to pick out. Color cues are not nearly as good at being inobtrusive but automatically parsed. > "Woman shoots man with crossbow" > Was it the man armed with a crossbow, or the woman? If we could somehow group the > clause "with crossbow" with "woman" or "man" by something *other* than > proximity, we could remove the ambiguity. Yes. But syntax highlighting won't help you here -- at least, I've never yet seen any editor that showed precedence relations or anything similar in its coloring. > Bringing it back to Python, that's why punctuation like : are useful. > They're syntax highlighting. I don't think they are, though. I think punctuation is fundamentally different in intent and purpose from colorizing things based on whether they're, say, constants or identifiers or comments or keywords. The punctuation is *itself* part of the syntax -- it's not being highlighted. Syntax highlighting is putting all the punctuation in green so you know it's punctuation. -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 thomas at jollans.com Sun Sep 19 04:12:52 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 19 Sep 2010 10:12:52 +0200 Subject: Learning inheritance In-Reply-To: <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> Message-ID: <4C95C604.4020801@jollans.com> On 2010-09-19 09:22, Niklasro wrote: > util.py: > url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) #declared > as class variable(?) > There is no class here, so this is no class variable, and you're not inheriting anything. You're simply using a module. > And viola just test if util.url.find('niklas') > 0: > > Exactly what I wanted to do with your experienced guidance. > > Many thanks > Happy refactored > From niklasro at gmail.com Sun Sep 19 04:18:44 2010 From: niklasro at gmail.com (Niklasro) Date: Sun, 19 Sep 2010 01:18:44 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> Message-ID: <8632bf75-3963-4e85-99f3-684dcde99589@i17g2000vbq.googlegroups.com> On Sep 19, 8:12?am, Thomas Jollans wrote: > On 2010-09-19 09:22, Niklasro wrote:> util.py: > > url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) #declared > > as class variable(?) > > There is no class here, so this is no class variable, and you're not > inheriting anything. You're simply using a module. > > > And viola just test if util.url.find('niklas') > 0: > > > Exactly what I wanted to do with your experienced guidance. > > > Many thanks > > Happy refactored > > Good to learn what I'm doing :-) since important being able to explain choices taken farther than "doing it because it works". I understand the concept of modules may not correspond to java programming where I come from. Sincerely with thanks for the help, Niklas From alex at moreati.org.uk Sun Sep 19 06:54:18 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Sun, 19 Sep 2010 03:54:18 -0700 (PDT) Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: Your code works (assuming digits gets populated fully), but it's the absolute bare minimum that would. To be brutally honest it's: - unpythonic - you've not used the core features of Python at all, such as for loops over a sequence - poorly formatted - Please read the python style guide and follow it - not reusable - Your code can only be called from the command line, it should be usable as a module - not documented - There is no indication what this code does, other than mentally running it - Fragile - There is no error checking on user input There are other ways to write what you have more concisely (e.g. list comprehensions, iterators) but those can wait for another time. Here is a start at improving your code wrt to the above points: #!/usr/bin/env python3 # bigdigits2.py ZERO = ["***", # NB Constants are by convention ALL_CAPS "* *", "***"] ONE = ["** ", " * ", "***"] # TODO Define and populate digits 2-9 DIGITS = [ZERO, ONE, ZERO, ONE, ZERO, ONE, ZERO, ONE, ZERO, ONE] def big_digits(str_of_digits): """Return a list of lines representing the digits using 3x3 blocks of "*" """ banner = [] # Accumulate results in this # Loop over the rows/lines of the result # TODO Replace hard coded block size with global constant or measured size for row in range(3): line_parts = [] # Assemble the current line from the current row of each big digit for digit in str_of_digits: big_digit = DIGITS[int(digit)] line_parts.append(big_digit[row]) # Create a string for the current row and add it to the result line = " ".join(line_parts) banner.append(line) return banner def usage(): print("Usage: bigdigit.py ", file=sys.stderr) sys.exit(1) if __name__ == "__main__": import sys # Check that an argument was passed # NB This will ignore additional arguments if len(sys.argv) >= 2: input_string = sys.argv[1] else: usage() # Check that only digits were passed if not input_string.isnumeric(): usage() # All is well, print the output for line in big_digits(input_string): print(line) Here are some suggested further improvements: - Map directly from a digit to it's big digit with a dictionary, rather than indexing into a list: BIG_DIGITS = { "1": ["** ", " * ", "***"], # ... } - Is input_string.isnumeric() the right test? Can you find a character it would not correctly flag as invalid input? - What if I wanted to use my own 4x4 big digits? Could the big_digits() function accept it as an argument? From mal at egenix.com Sun Sep 19 07:04:40 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Sun, 19 Sep 2010 13:04:40 +0200 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: <4C959B38.3040108@stoneleaf.us> References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> <4C959039.5070700@stoneleaf.us> <4C959B38.3040108@stoneleaf.us> Message-ID: <4C95EE48.2030303@egenix.com> Ethan Furman wrote: > Carl Karsten wrote: >> On Sat, Sep 18, 2010 at 11:23 PM, Ethan Furman >> wrote: >>> Thanks for the suggestion, but I don't want to be tied to Foxpro, which >>> means I need to be able to parse these files directly. I have the dbf >>> files, now I need the idx and cdx files. >> >> >> >> What do you mean "tied" ? > > I meant having to have Foxpro installed. I just learned from another > reply that I may not have to have Foxpro installed as long as I have the > Foxpro ODBC driver, because then I could use odbc instead of fiddling > with the files directly. > > While I may switch over to odbc in the future, I would still like to > have the idx/cdx components. If you are working on Windows, you can install the MS MDAC package to get a hold of the MS FoxPro ODBC drivers. They are usually already installed in Vista and 7, in XP they comes with MS SQL Server and MS Office as well. mxODBC can then provide Python access on Windows, mxODBC Connect on other platforms. If you want direct files access on other platforms, you can use http://pypi.python.org/pypi/dbf/ or http://dbfpy.sourceforge.net/. If you want to add support for index files (which the above two don't support), you could also have a look at this recipe for some inspiration: http://code.activestate.com/recipes/362715-dbf-reader-and-writer/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 19 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 ldo at geek-central.gen.new_zealand Sun Sep 19 07:20:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 23:20:13 +1200 Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: In message , Alex Willmer wrote: > # NB Constants are by convention ALL_CAPS SAYS_WHO? From ldo at geek-central.gen.new_zealand Sun Sep 19 07:23:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 23:23:21 +1200 Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: In message <4c957412$0$3036$afc38c87 at news.optusnet.com.au>, fridge wrote: > digits=[zero,one,zero,one,zero,one,zero,one,zero,one] digits = [zero, one] * 5 > row_max=3 Defined but never used. > digit_i=int(inputted_digit[c]) > digit=digits[digit_i] > line+=digit[r] > line+=" " Too many intermediate variables only defined and used once. Do this all on one line. From ldo at geek-central.gen.new_zealand Sun Sep 19 07:26:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 23:26:26 +1200 Subject: Cross Compiling Python for ARM References: <4c911670$0$41115$e4fe514c@news.xs4all.nl> Message-ID: In message <4c911670$0$41115$e4fe514c at news.xs4all.nl>, Hans Mulder wrote: > The most popular way to get the latter problem is to write the script > on a Windows box and then upload it to Unix box using FTP in binary > mode (or some other transport that doesn't adjust the line endings). I always thought it was a misfeature that the Linux kernel doesn?t recognize all the common conventions for ending the shebang line. All reading of text files should be similarly tolerant. From ldo at geek-central.gen.new_zealand Sun Sep 19 07:29:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 23:29:44 +1200 Subject: program organization question for web development with python References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> Message-ID: In message <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29 at w15g2000pro.googlegroups.com>, Hans wrote: > print """%s""" % > (record[0],table_name,cursor_name,record1) I would recommend avoiding filename extensions in your URLs wherever possible. For executables, in particular, leaving out the ?.py? or ?.pl? or whatever makes it easier to switch languages, should you need to in future. From alex at moreati.org.uk Sun Sep 19 07:34:17 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Sun, 19 Sep 2010 04:34:17 -0700 (PDT) Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: On Sep 19, 12:20?pm, Lawrence D'Oliveiro wrote: > In message > , Alex > > Willmer wrote: > > # NB Constants are by convention ALL_CAPS > > SAYS_WHO? Says PEP 8: Constants Constants are usually declared on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL. -- http://www.python.org/dev/peps/pep-0008/ From python.list at tim.thechases.com Sun Sep 19 07:37:23 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 19 Sep 2010 06:37:23 -0500 Subject: This Is International =?windows-1252?Q?Don=92t-Squawk-Like-A?= =?windows-1252?Q?-Parrot_Day?= In-Reply-To: References: Message-ID: <4C95F5F3.7050408@tim.thechases.com> On 09/18/10 23:46, Lawrence D'Oliveiro wrote: > Do your bit to help stamp out parrocy. Did you send this by mistake? It looks like a parroty-error. I think it's a bit off... -tkc From thomas at jollybox.de Sun Sep 19 08:10:39 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 19 Sep 2010 14:10:39 +0200 Subject: ctypes and buffers In-Reply-To: References: Message-ID: <201009191410.40186.thomas@jollybox.de> On Sunday 19 September 2010, it occurred to Carl Banks to exclaim: > I am creating a ctypes buffer from an existing non-ctypes object that > supports buffer protocol using the following code: > > > from ctypes import * > > PyObject_AsReadBuffer = pythonapi.PyObject_AsReadBuffer > PyObject_AsReadBuffer.argtypes = > [py_object,POINTER(c_void_p),POINTER(c_size_t)] > PyObject_AsReadBuffer.restype = None > > def ctypes_buffer_from_buffer(buf): > cbuf = c_void_p() > size = c_size_t() > PyObject_AsReadBuffer(buf,byref(cbuf),byref(size)) > return cbuf > If I understand what you are doing correctly, you're referencing a Python buffer object and returning a pointer wrapped in some ctypes thingy. hmm. I see some problems in your code: * You're not passing the size along. In the name of sanity, why on earth not?! The pointer cannot be safely used without knowing how long the area of memory referenced is! * You're using the old buffer protocol. You might rather implement this with the one introduced with Python 3.0, and supported in 2.6 as well. > > It works, but is there a standard way to do this in ctypes? I > couldn't find anything in the documentation. Python 2.6 for now. > Thanks. > > > Carl Banks From aahz at pythoncraft.com Sun Sep 19 09:11:20 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 06:11:20 -0700 Subject: C++ - Python API References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: In article , Thomas Jollans wrote: >On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: >> >> So the feature overview: > >First, the obligatory things you don't want to hear: Have you had >a look at similar efforts? A while ago, Aahz posted something very >similar on this very list. You should be able to find it in any of the >archives without too much trouble. You almost certainly have me confused with someone else -- I wouldn't touch C++ with a ten-meter pole if I could possibly help it. (The last time I dealt with C++ code, about a decade ago, I just rewrote it in C.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From philip at semanchuk.com Sun Sep 19 09:11:50 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 19 Sep 2010 09:11:50 -0400 Subject: =?windows-1252?Q?Re:_This_Is_International_Don=92t-Squawk-Like-A?= =?windows-1252?Q?-Parrot_Day?= In-Reply-To: <4C95F5F3.7050408@tim.thechases.com> References: <4C95F5F3.7050408@tim.thechases.com> Message-ID: <302A823C-C163-4FF2-B492-1398B2B1BDE5@semanchuk.com> On Sep 19, 2010, at 7:37 AM, Tim Chase wrote: > On 09/18/10 23:46, Lawrence D'Oliveiro wrote: >> Do your bit to help stamp out parrocy. > > Did you send this by mistake? It looks like a parroty-error. I think it's a bit off... What an aaaawkward thing to say. Are you crackers? From aahz at pythoncraft.com Sun Sep 19 09:11:55 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 06:11:55 -0700 Subject: This Is International =?windows-1252?Q?Don=92t-Squawk-Like-A?= =?windows-1252?Q?-Parrot_Day?= References: Message-ID: In article , Tim Chase wrote: >On 09/18/10 23:46, Lawrence D'Oliveiro wrote: >> >> Do your bit to help stamp out parrocy. > >Did you send this by mistake? It looks like a parroty-error. I >think it's a bit off... Arrrrgh! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From aahz at pythoncraft.com Sun Sep 19 09:16:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 06:16:49 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: In article , geremy condra wrote: >On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking > wrote: >> >> I've been working with Python now for about a year using it primarily for >> scripting in the Puredata graphical programming environment. I'm working on >> a project where I have been given a 1000 by 1000 cell excel spreadsheet and >> I would like to be able to access the data using Python. Does anyone know >> of a way that I can do this? > >http://tinyurl.com/2eqqjxv Please don't use tinyurl -- it's opaque and provides zero help to anyone who might later want to look it up (and also no accessibility if tinyurl ever goes down). At the very least, include the original URL for reference. (Yes, I realize this is probably a joke given the smiley I excised, but too many people do just post tinyurl.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From thomas at jollybox.de Sun Sep 19 10:28:41 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 19 Sep 2010 16:28:41 +0200 Subject: C++ - Python API In-Reply-To: References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: <201009191628.42036.thomas@jollybox.de> On Sunday 19 September 2010, it occurred to Aahz to exclaim: > In article , > > Thomas Jollans wrote: > >On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: > >> So the feature overview: > >First, the obligatory things you don't want to hear: Have you had > >a look at similar efforts? A while ago, Aahz posted something very > >similar on this very list. You should be able to find it in any of the > >archives without too much trouble. > > You almost certainly have me confused with someone else -- I wouldn't > touch C++ with a ten-meter pole if I could possibly help it. (The last > time I dealt with C++ code, about a decade ago, I just rewrote it in C.) Sorry about that. From andrei.avk at gmail.com Sun Sep 19 10:29:10 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 10:29:10 -0400 Subject: Too much code - slicing In-Reply-To: <4c958370$0$11113$c3e8da3@news.astraweb.com> References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C961E36.5010606@gmail.com> On 09/18/2010 11:28 PM, Steven D'Aprano wrote: > On Sat, 18 Sep 2010 21:58:58 -0400, AK wrote: > >>> I don't understand this. So far as I know, the phrase "speed reading" >>> refers to various methods of reading much faster than most people read, >>> and is real but not exceptionally interesting. >> >> Afaik the idea is that you can read a novel at the speed of half a page >> a second or so and understand it to the same extent as people who'd read >> at a normal rate. Woody Allen joke: "I learned speed reading and read >> War&Peace"; - it involves Russia. > > My wife can read scarily fast. It's very something to watch her reading > pages as fast as she can turn them, and a few years ago she read the > entire Harry Potter series (to date) in one afternoon, and could gives a > blow-by-blow account of the plots, including a detailed critique of the > writing style and characters. But then, she feels that reading the Potter > series is a chore to be completed as fast as possible, rather than a > pleasure to be savored. She'll sometimes drag a new Terry Pratchett or > Stephen King novel out for as much as two days. > > That's pretty impressive. I used to get somewhat close to that speed when, years ago, I'd read a lot of trashy scifi. The way it would work is that I'd sense in advance that there's a passage where the hero with his team is going through a desert area and I'd know that a 30-40 page section will be punctuated by two battles and one friendly encounter. I would be able to read at different speeds depending on what's going on, slowing down a bit where a twist is presented or a crucial plot point is revealed, both would be telegraphed well in advance. In other spots, I'd be able to scan a few words at the top of page, a few in the middle and at the bottom and I'd know what's going on, generally. I would also be able to give a detailed account of the plot and writing style and characters but this would be entirely due to predictability of writing and following tropes. Interestingly, I've also read LoTR in the same way when I was younger because I was interested in battles and skipped the dull parts. I tried a few times to read Potter book 3 but couldn't bear it.. spoiled too much by Barrie and Grahame. When I was reading The book of the new sun, though, I could stop and read a single sentence a few times over and reflect on it for a minute. -ak From andrei.avk at gmail.com Sun Sep 19 10:44:59 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 10:44:59 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C9621EB.6040304@gmail.com> On 09/19/2010 03:31 AM, Seebs wrote: > On 2010-09-19, Steven D'Aprano wrote: >> Define "unbalanced". > > I'm not sure that's the word I'd use. I'm not even sure what it would mean > here. > >> Putting aside the over-use of punctuation, The C syntax feels unbalanced >> to me. You have: > >> condition IF true-clause ELSE false-clause > >> so both clauses follow the test, that is, they're on the same side: ?-- > > Yes. > > Just like: > if condition: > foo > else: > bar > > The condition is the primary, the clauses are secondary to it. To me, the problem with C ternary is, why is true condition first and false second? It could just as well be the other way around. With if and else, the meaning is direct, x if y else z, or if y: x; else: z. > > It may be balanced, but it requires you to reevaluate what you're reading > after you've already read something that seemed to have a clear meaning. > > Basically, think of what happens as I read each symbol: > > x = x + 1 if condition else x - 1 > > Up through the '1', I have a perfectly ordinary assignment of a value. > The, suddenly, it retroactively turns out that I have misunderstood > everything I've been reading. I am actually reading a conditional, and > the things I've been seeing which looked like they were definitely > part of the flow of evaluation may in fact be completely skipped. That's absolutely not how I read code. For example, if you have a line like: x = x + 1 ASF!@#$!@$ASFASF!@#$!@$#ADFASDF!@# Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is this?". I would read it like "there's something wrong at the end of line", before I even see it as an assignment. That's where syntax highlighting comes in, as well. What I see, at the same time (i.e. not in sequence): .. = .. if .. else .. The second thing I see is what variable is being assigned to. Of couse, this might change if I'm looking for that particular variable, then I might see: x ................ or x = ................ > > > Consider the following lovely hypothetical syntax: > > foo > bar > baz > if condition else: > blah > blah > blah > > And there, at least you have some cue that you're about to see something > happen. After some time getting used to it, I'd end up seeing this as: . . . if .. else: . . . at first and then processing everything else. Again, syntax highlighting would help here. The only issue is that it'd be hard to separate the beginning from other code, for me that'd be the primary reason why this is not a good construct. -ak From andrei.avk at gmail.com Sun Sep 19 10:56:06 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 10:56:06 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C962486.3020901@gmail.com> On 09/19/2010 03:36 AM, Seebs wrote: > On 2010-09-19, Steven D'Aprano wrote: >> I'm not entirely sure I agree with you here... you can't ignore syntax in >> order to understand the meaning of code. > > No, but the syntax should be invisible. When I read English, I don't have > to think about nouns and verbs and such unless something is very badly > written. The syntax is handled automatically at a lower level without > conscious intervention, as it should be. Calling my conscious attention > to it is disruptive. The interesting thing is that syntax highlight for me *is* handled at a lower level. What you're describing is exactly the same as when I try a highlight scheme with colours that are too strong, or have a background. I would rather use no highlighting at all than a theme with garish colours. When I read code, I filter out colours when I don't need them and filter out non-coloured text when I'm looking for a particular structure. So, with x = y if a else z, I might see . = . if . else . and then immediately see x . y . a . z, already with knowledge of what is the structure surrounding vars. > Punctuation is very different from highlighting, IMHO. That said, I > find punctuation very effective at being small and discrete, clearly not > words, and easy to pick out. Color cues are not nearly as good at > being inobtrusive but automatically parsed. Seems like the difference of how you process colours vs. how I do, for me they work precisely in the same way as punctuation might, but adding an additional layer which may be used but never gets in the way. -ak From mahaboobnisha at gmail.com Sun Sep 19 11:49:41 2010 From: mahaboobnisha at gmail.com (roshini begum) Date: Sun, 19 Sep 2010 08:49:41 -0700 (PDT) Subject: comp.lang.python Message-ID: <3d6e88f4-13ed-4c8d-bce0-79350d60b7a8@n7g2000vbo.googlegroups.com> http://127760.blogspot.com From kevin.p.dwyer at gmail.com Sun Sep 19 12:35:10 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 19 Sep 2010 16:35:10 +0000 (UTC) Subject: Making logging.getLogger() simpler References: <4c94ea0d$1@dnews.tpgi.com.au> Message-ID: On Sun, 19 Sep 2010 02:35:15 +1000, Lie Ryan wrote: > I was expecting this to work: > > import logging > logger = logging.getLogger(__name__) > logger.warn('this is a warning') > > instead it produced the error: > > No handlers could be found for logger "__main__" > > > However, if instead I do: > > import logging > logging.warn('creating logger') > logger = logging.getLogger(__name__) > logger.warn('this is a warning') > > then it does work. > > Is there any reason why getLogger()-created logger shouldn't > automatically create a default handler? Hello Lie, Calling logging.warn(), or logging.debug() etc. before handlers have been assigned to the root logger will result in logging.basicConfig() being called automatically. By default a StreamHandler will be created on the root logger and your logger inherits the StreamHandler. So you can avoid the "No handlers..." warning by calling logging.basicConfig() before your program does any logging. I don't know why getLogger() doesn't so something similar when it's called. Perhaps so that the logger is explicitly initialised with basic, file or dictConfig? Cheers, Kev From nobody at nowhere.com Sun Sep 19 13:19:19 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 19 Sep 2010 18:19:19 +0100 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Sun, 19 Sep 2010 18:42:51 +1200, Lawrence D'Oliveiro wrote: >>>> That's why Stevens recommends that all TCP servers use the >>>> SO_REUSEADDR socket option. >>> >>> I don?t think I?ve ever used that. It seems to defeat a safety mechanism >>> which was put in for a reason. >> >> It was put in for the benefit of clients, to prevent them from selecting >> a port which they won't be able to use. > > But clients typically don?t care what port they use?they let the > system pick a port for them, so this kind of option is unnecessary. If they use an ephemeral port, the kernel won't pick a port which has any connections in the TIME_WAIT state. However, some clients choose their own source ports. E.g. rlogin/rsh use privileged (low-numbered) ports, and you can't get the kernel to choose a random privileged port for you. If you're writing a server which listens on a known port, you *should* be using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel will automatically reject packets relating to stale connections, and your server should be accepting any new connections ASAP. From mafeusek at gmail.com Sun Sep 19 13:37:47 2010 From: mafeusek at gmail.com (mafeusek at gmail.com) Date: Sun, 19 Sep 2010 19:37:47 +0200 Subject: newbie: class and __dict__ variable. Message-ID: Hallo Group Members. From time to time I see in python code following notation that (as I believe) extends namespace of MyClass. class MyClass: def __init__(self): self.__dict__["maci"]=45 myCl2 = MyClass2() print myCl2.maci I am guessing that there must be some difference between the one above and the one below, because otherwise no one would probably use the one above. Do YOu know that difference? class MyClass2: def __init__(self): self.maci=45 myCl = MyClass() print myCl.maci best regards, Pawel From hunguponcontent at gmail.com Sun Sep 19 13:55:43 2010 From: hunguponcontent at gmail.com (Default User) Date: Sun, 19 Sep 2010 12:55:43 -0500 Subject: develop for Windows on GNU/Linux, using Python Message-ID: Consider: Can someone do development of programs for use on Windows systems, but developed totally on a GNU/Linux system, using standard, contemporary 32 and / or 64-bit PC hardware? This would be for someone who can not or will not use Windows, but wants to create software for those who do. This might not include the use of VM for developing on GNU/Linux, as that would seem to require a Windows installation disk, which the developer may not be able or willing to obtain and use. Is the correct answer: 1) no. 2) yes. 3) yes, a "Hello World" program will run just fine on the Windows Python interpreter. 4) other. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sebastianthegreatful at gmail.com Sun Sep 19 14:08:22 2010 From: sebastianthegreatful at gmail.com (Seb) Date: Sun, 19 Sep 2010 11:08:22 -0700 (PDT) Subject: http2https proxy Message-ID: I'd like to open a ssl connection to a https server, done Create a socket and bind it to a local port, done Connect the two in such a way that everything read or written to the local port is actually read or written to the https server. In other words I want a http2https proxy. ideas? best regards, Seb From usenet-nospam at seebs.net Sun Sep 19 14:21:12 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 18:21:12 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, AK wrote: > On 09/19/2010 03:31 AM, Seebs wrote: >> Just like: >> if condition: >> foo >> else: >> bar >> The condition is the primary, the clauses are secondary to it. > To me, the problem with C ternary is, why is true condition first and > false second? It could just as well be the other way around. Again, look at the long-form "if/else" above; it's always "if a then b otherwise c". > With if and > else, the meaning is direct, x if y else z, or if y: x; else: z. The latter still has condition, true, false. >> Basically, think of what happens as I read each symbol: >> >> x = x + 1 if condition else x - 1 >> >> Up through the '1', I have a perfectly ordinary assignment of a value. >> The, suddenly, it retroactively turns out that I have misunderstood >> everything I've been reading. I am actually reading a conditional, and >> the things I've been seeing which looked like they were definitely >> part of the flow of evaluation may in fact be completely skipped. > That's absolutely not how I read code. For example, if you have a line > like: > x = x + 1 ASF!@#$!@$ASFASF!@#$!@$#ADFASDF!@# > Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is > this?". Not for something that big and visible. But the if/else stuff is just ordinary blocks of text. > That's where syntax highlighting comes in, as well. So basically, if we use syntax highlighting to make up for the legibility problems of a given syntax, then the syntax is okay, but people who don't use syntax highlighting to make up for its legibility problems are wrong. I see. This does seem self-contained; you like syntax highlighting because you like constructs which are hard to read without it. You like those constructs because they let you show off syntax highlighting. > After some time getting used to it, I'd end up seeing this as: > . > . > . > if .. else: > . > . > . > at first and then processing everything else. Assuming that the if/else was on the same page. :) > Again, syntax highlighting > would help here. The only issue is that it'd be hard to separate the > beginning from other code, for me that'd be the primary reason why this > is not a good construct. No matter how long I'd been using that construct, I'd still have the problem that, mechanically, I'm going to see the opening few lines first, and that means that those lines are going to get parsed first. I read largely in order. I do have some lookahead, but no matter how much I use the lookahead, I'm already parsing the first things I see, and that's top-down-left-right. -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 kevin.p.dwyer at gmail.com Sun Sep 19 14:36:04 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 19 Sep 2010 18:36:04 +0000 (UTC) Subject: develop for Windows on GNU/Linux, using Python References: Message-ID: On Sun, 19 Sep 2010 12:55:43 -0500, Default User wrote: > Consider: > > Can someone do development of programs for use on Windows systems, but > developed totally on a GNU/Linux system, using standard, contemporary 32 > and / or 64-bit PC hardware? > > This would be for someone who can not or will not use Windows, but wants > to create software for those who do. > > This might not include the use of VM for developing on GNU/Linux, as > that would seem to require a Windows installation disk, which the > developer may not be able or willing to obtain and use. > > Is the correct answer: > 1) no. > 2) yes. > 3) yes, a "Hello World" program will run just fine on the Windows Python > interpreter. > 4) other. Hello, The answer is "it depends", or 4 on your list of responses. You can write pure python on a Linux machine and it will run fine on Windows as long as you've taken care to program in a portable fashion. However, writing the code isn't everything. To be confident that your code is good you need to test it on a Windows box (we all test, right?). If you want to distribute your application to non-developers you'll need to wrap it in a Windows installer; if you have C-extensions in your code you'll need to compile them over Windows. If you want to program against the Windows API you'll need access to a Windows box. So, if you really want to develop code for Windows (or cross-platform code) I think you need to bite the bullet and get access to a Windows (virtual) machine. Cheers, Kev PS - You might be able to get away with using an emulator like WINE, but given the ubiquity of Windows in business/home computing I think you're better of testing on the real thing. From ethan at stoneleaf.us Sun Sep 19 14:45:54 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 19 Sep 2010 11:45:54 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: <4C95EE48.2030303@egenix.com> References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> <4C959039.5070700@stoneleaf.us> <4C959B38.3040108@stoneleaf.us> <4C95EE48.2030303@egenix.com> Message-ID: <4C965A62.3040804@stoneleaf.us> M.-A. Lemburg wrote: > If you are working on Windows, you can install the MS MDAC package to > get a hold of the MS FoxPro ODBC drivers. They are usually already installed > in Vista and 7, in XP they comes with MS SQL Server and MS Office as > well. mxODBC can then provide Python access on Windows, mxODBC Connect > on other platforms. > > If you want direct files access on other platforms, you can use > http://pypi.python.org/pypi/dbf/ ^--- I'm the author if this package :) > or http://dbfpy.sourceforge.net/. ^--- from the quick skim of the code, I think mine does more at this point (memos, adding/deleting/renaming fields in existing tables, in-memory indexes, unicode support, export to csv,tab,fixed formats, field access via attribute/dictionary/index style (e.g. table.fullname or table['fullname'] or table[0] if fullname is the first field), very rudimentary sql support, etc.) > If you want to add support for index files (which the above two don't > support), you could also have a look at this recipe for some > inspiration: > > http://code.activestate.com/recipes/362715-dbf-reader-and-writer/ I didn't see anything regarding the .idx or .cdx files in this recipe. :( Thanks for your time, though! -- ~Ethan~ From vinay_sajip at yahoo.co.uk Sun Sep 19 14:52:59 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 19 Sep 2010 11:52:59 -0700 (PDT) Subject: Making logging.getLogger() simpler References: <4c94ea0d$1@dnews.tpgi.com.au> Message-ID: <19a4cbe4-d0df-4e85-886b-7ef2feedde03@s19g2000vbr.googlegroups.com> On Sep 18, 5:35?pm, Lie Ryan wrote: > I was expecting this to work: > > ? importlogging > ? logger =logging.getLogger(__name__) > ? logger.warn('this is a warning') > > instead it produced the error: > > ? No handlers could be found for logger "__main__" > > However, if instead I do: > > ? importlogging > ?logging.warn('creating logger') > ? logger =logging.getLogger(__name__) > ? logger.warn('this is a warning') > > then it does work. > > Is there any reason why getLogger()-created logger shouldn't > automatically create a default handler? There is a good reason why a getLogger()-created logger doesn't add a default handler. Imagine if it did, and the code you were writing was a library module that was used in an application being written by another developer. Imagine if there were several other libraries which also declared loggers (and therefore several default handlers). Then the result of running the application would be to get a whole bunch of unexpected messages from those libraries, including yours. This would annoy the application developer no end, and rightly so. For simple uses of logging (where you are writing a utility script, for example, when you are the application developer) you can call logging.warning() etc. which will (for your convenience) add a handler to write to the console for you, if there isn't a handler already. If you are doing something more involved, you will need to configure logging to do whatever it is you want, and when you run your program your log will contain messages from your application as well as third- party libraries you use, all playing well together and with no unpleasant surprises. If you are writing a library, you will typically: 1. Add a NullHandler to your top-level logger. 2. If you want to force your users (application developers) to add handlers explicitly to their loggers, set your top-level logger's propagate flag to False. 3. If you want to have a specific verbosity on your loggers, which is different from the default (WARNING), you need to set that level on your top-level logger, or on individual loggers for which you want that specific, non-default verbosity. I hope that helps, Vinay Sajip From vinay_sajip at yahoo.co.uk Sun Sep 19 14:55:34 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 19 Sep 2010 11:55:34 -0700 (PDT) Subject: Making logging.getLogger() simpler References: <4c94ea0d$1@dnews.tpgi.com.au> <19a4cbe4-d0df-4e85-886b-7ef2feedde03@s19g2000vbr.googlegroups.com> Message-ID: On Sep 19, 7:52?pm, Vinay Sajip wrote: > If you are writing a library, you will typically: > 2. If you want to force your users (application developers) to add > handlers explicitly to their loggers, set your top-level logger's > propagate flag to False. Sorry, in the above text, where it says "their loggers" it should say "your loggers" Regards, Vinay Sajip From user at example.net Sun Sep 19 15:31:30 2010 From: user at example.net (J.O. Aho) Date: Sun, 19 Sep 2010 21:31:30 +0200 Subject: develop for Windows on GNU/Linux, using Python In-Reply-To: References: Message-ID: <8fn6ojF783U1@mid.individual.net> Kev Dwyer wrote: > On Sun, 19 Sep 2010 12:55:43 -0500, Default User wrote: > >> Consider: >> >> Can someone do development of programs for use on Windows systems, but >> developed totally on a GNU/Linux system, using standard, contemporary 32 >> and / or 64-bit PC hardware? >> >> This would be for someone who can not or will not use Windows, but wants >> to create software for those who do. >> >> This might not include the use of VM for developing on GNU/Linux, as >> that would seem to require a Windows installation disk, which the >> developer may not be able or willing to obtain and use. >> >> Is the correct answer: >> 1) no. >> 2) yes. >> 3) yes, a "Hello World" program will run just fine on the Windows Python >> interpreter. >> 4) other. > > Hello, > > The answer is "it depends", or 4 on your list of responses. > > You can write pure python on a Linux machine and it will run fine on > Windows as long as you've taken care to program in a portable fashion. And not use modules not yet converted to microsoft, seems to happen from time to time. > if you have C-extensions in > your code you'll need to compile them over Windows. If you want to > program against the Windows API you'll need access to a Windows box. You can always cross compile, not only over OS but even CPU architecture, but of course testing will be more difficult, on x86 based Linux you can use wine or similar to test, but can give you some differences to run on a native or virtualized instance. -- //Aho From goran.novosel at gmail.com Sun Sep 19 15:43:28 2010 From: goran.novosel at gmail.com (Goran Novosel) Date: Sun, 19 Sep 2010 12:43:28 -0700 (PDT) Subject: Python and unicode Message-ID: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> Hi everybody. I've played for few hours with encoding in py, but it's still somewhat confusing to me. So I've written a test file (encoded as utf-8). I've put everything I think is true in comment at the beginning of script. Could you check if it's correct (on side note, script does what I intended it to do). One more thing, is there some mechanism to avoid writing all the time 'something'.decode('utf-8')? Some sort of function call to tell py interpreter that id like to do implicit decoding with specified encoding for all string constants in script? Here's my script: ------------------- # vim: set encoding=utf-8 : """ ----- encoding and py ----- - 1st (or 2nd) line tells py interpreter encoding of file - if this line is missing, interpreter assumes 'ascii' - it's possible to use variations of first line - the first or second line must match the regular expression "coding[:=]\s*([-\w.]+)" (PEP-0263) - some variations: ''' # coding= ''' ''' #!/usr/bin/python # -*- coding: -*- ''' ''' #!/usr/bin/python # vim: set fileencoding= : ''' - this version works for my vim: ''' # vim: set encoding=utf-8 : ''' - constants can be given via str.decode() method or via unicode constructor - if locale is used, it shouldn't be set to 'LC_ALL' as it changes encoding """ import datetime, locale #locale.setlocale(locale.LC_ALL,'croatian') # changes encoding locale.setlocale(locale.LC_TIME,'croatian') # sets correct date format, but encoding is left alone print 'default locale:', locale.getdefaultlocale() s='abcdef ??????????'.decode('utf-8') ss=unicode('ab ?????','utf-8') # date part of string is decoded as cp1250, because it's default locale all=datetime.date(2000,1,6).strftime("'%d.%m.%Y.', %x, %A, %B, ").decode('cp1250')+'%s, %s' % (s, ss) print all ------------------- From martin at v.loewis.de Sun Sep 19 16:01:00 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 19 Sep 2010 22:01:00 +0200 Subject: Python and unicode In-Reply-To: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> Message-ID: <4C966BFC.3070806@v.loewis.de> > One more thing, is there some mechanism to avoid writing all the time > 'something'.decode('utf-8')? Yes, use u'something' instead (i.e. put the letter u before the literal, to make it a unicode literal). Since Python 2.6, you can also put from __future__ import unicode_literals at the top of the file to make all string literals Unicode objects. Since Python 3.0, this is the default (i.e. all string literals *are* unicode objects). Regards, Martin From andrei.avk at gmail.com Sun Sep 19 16:29:52 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 16:29:52 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C9672C0.4080202@gmail.com> On 09/19/2010 02:21 PM, Seebs wrote: > On 2010-09-19, AK wrote: >> On 09/19/2010 03:31 AM, Seebs wrote: >>> Just like: >>> if condition: >>> foo >>> else: >>> bar > >>> The condition is the primary, the clauses are secondary to it. > >> To me, the problem with C ternary is, why is true condition first and >> false second? It could just as well be the other way around. > > Again, look at the long-form "if/else" above; it's always "if a then b > otherwise c". Because that's what 'if' and 'else' mean. I have no problem with '?' separating condition from possible outcomes.. The most natural reading of that construct is that depending on condition, there are two possible outcomes, separated by a ':' and you have to remember that first outcome corresponds to true condition. x = y if a else z is much more pythonic because 'else' is explicitly saying what happens on false condition. Explicit is better than implicit. > >> That's absolutely not how I read code. For example, if you have a line >> like: > >> x = x + 1 ASF!@#$!@$ASFASF!@#$!@$#ADFASDF!@# > >> Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is >> this?". > > Not for something that big and visible. But the if/else stuff is > just ordinary blocks of text. Not with syntax highlighting they're not ;) Seriously though, my guess is even without syntax highlighting I'd still prefer it because I do enough look-ahead and in 95% of cases the first 'if' is close enough to the beginning of the line. In fact, most often plain assignments will be much shorter than this construct so you can figure it out by combination of line length and the 'if' keyword. It still has the advantage over the more verbose version that I mentioned before: you can see immediately that there's an assignment to a single variable, and the logic flows like a single sentence in a natural language. > >> That's where syntax highlighting comes in, as well. > > So basically, if we use syntax highlighting to make up for the legibility > problems of a given syntax, then the syntax is okay, but people who don't > use syntax highlighting to make up for its legibility problems are wrong. That's not really true, it merely makes a given syntax easier to read even when it's already a preferable syntax. It's like this, if someone gives you five dollars for nothing, and then later gives you three dollars, you don't complain that the latter amount is less than former :). > > I see. > > This does seem self-contained; you like syntax highlighting because you > like constructs which are hard to read without it. You like those constructs > because they let you show off syntax highlighting. Well, you're exaggerating this out of all proportion just to prove a point. I like syntax highlighting in all of python and, in fact, in all languages I've used. Even in crontab files! This is a single construct I can think of, which, being already very readable, explicit, and succinct, *on top of that*, gains even more in readability due to syntax highlight. So, as you can see, I'd like syntax highlight just fine if this construct was not present in Python, and in fact I did. Conversely, I'd prefer it to the longer version if there was no syntax highlight at all. > >> After some time getting used to it, I'd end up seeing this as: > >> . >> . >> . >> if .. else: >> . >> . >> . > >> at first and then processing everything else. > > Assuming that the if/else was on the same page. :) I'll concede you one point in this case: if the statement 'x = .. if .. else .. ' is split over two pages, I would at least seriously consider the 'if: .. else: ' version. ;) -ak From usenet-nospam at seebs.net Sun Sep 19 17:32:29 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 21:32:29 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, AK wrote: > Because that's what 'if' and 'else' mean. My point is, I don't want the order of the clauses in if/else to change. If it is sometimes "if else ", then it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, then false clause. If it's sometimes "if condition true-clause else false-clause", and sometimes "true-clause if condition else false-clause", that's a source of extra complexity. > I have no problem with '?' > separating condition from possible outcomes.. The most natural reading > of that construct is that depending on condition, there are two possible > outcomes, separated by a ':' and you have to remember that first outcome > corresponds to true condition. Exactly as it ALWAYS does. That's the point. > x = y if a else z is much more pythonic > because 'else' is explicitly saying what happens on false condition. > Explicit is better than implicit. Is it "more pythonic" to shuffle the orders of clauses in precisely analagous constructs? I'm not arguing against the use of the *words* "if" and "else". I'm arguing that the shuffling of the orders of the clauses creates confusion. > It still has the advantage over the more verbose version that I > mentioned before: you can see immediately that there's an assignment to > a single variable, and the logic flows like a single sentence in a > natural language. I'm getting frustrated here because I really felt my point was pretty clearly expressed, and yet, every time you respond, you respond to things TOTALLY DIFFERENT from what I am saying. The syntax I like for this kind of thing is: x = if condition then true-clause else false-clause This is because it follows the same *ordering* as the multi-line if/else, so it preserves the logical flow. Condition, then true clause, then false clause. Always. The only way in which this is more verbose than the inverted one is the "then", and you don't even need that if you stick with a python-style colon: x = if condition: true-clause else false-clause But this is *always* easier to follow because it follows the same logical structure. Leave poetic inversion to the poets. > That's not really true, it merely makes a given syntax easier to read > even when it's already a preferable syntax. Except that it's *NOT PREFERABLE* to me, because it is BACKWARDS. Have I somehow failed to express this? Is there some magical rule that it is not pythonic for you to react in any way to the actual comparison I'm making, rather than to totally unrelated comparisons? I gave the example of what an if/else statement looks like, not because I think it is always better to use statements and blocks instead of expressions, but to point out the LOGICAL ORDER. You were asking why I preferred the condition to come first. My answer is, because the condition comes first in an if/else statement normally, and I like to preserve the logical flow. Instead, you're off ranting about how that's too long. But that's not my point. My point was *only* that the logical flow is consistent between if/else and the way various languages have done if/else expressions: Condition first, then true clause, then false clause. Doesn't matter whether it's ruby or C or lua or even bourne shell, in every other language I use that lets me use an if/else as part of an expression, it follows the SAME logical flow as the regular if/else statement. In Python, it's inverted. You were arguing that this inversion is better and more intuitive, and that there is no reason to expect the condition to come first. But there is! The condition comes first in regular if/else statements. This establishes a pattern -- if/else things are introduced by their condition, then you get the true clause and then you get the false clause. > Well, you're exaggerating this out of all proportion just to prove a > point. No, I'm not. > This is a single construct I > can think of, which, being already very readable, explicit, and > succinct, *on top of that*, gains even more in readability due to syntax > highlight. But it's *not readable to me*. Because it's backwards. > So, as you can see, I'd like syntax highlight just fine if this > construct was not present in Python, and in fact I did. Conversely, I'd > prefer it to the longer version if there was no syntax highlight at all. And again, NO ONE HAS SUGGESTED THE LONGER VERSION. AT ALL. EVER. I don't understand why you keep contrasting this with the longer version when the only reason that was brought up was to COMPARE it in terms of *logical flow*. I pointed out the *PARALLELS* between conditional expressions and conditional statements. I did not suggest that the longer version should be preferred in all cases, or even in all that many. > I'll concede you one point in this case: if the statement 'x = .. if .. > else .. ' is split over two pages, I would at least seriously consider > the 'if: .. else: ' version. ;) Okay, one more time: I am not proposing the use of multi-line statements as superior to conditional expressions. I am *ONLY* stating that I find the "true-clause if condition else false-clause" form confusing because it inverts the LOGICAL FLOW of multi-line if/else statements. By the nature of programming, I'm going to have to use if/else statements a lot. So I'm going to be used to the way they flow -- condition, true, false. Condition, true, false. Condition, true, false. It goes in that order every time, in every language I use, both when working with statements and when working with expressions. EXCEPT. That in one specific language, when doing expressions (but not statements), it is "True, condition, false." That's all I'm talking about. I am not arguing whether conditional expressions are better or worse than conditional statements. I am not arguing whether conditional expressions should exist at all. I am only pointing out that I find it much clearer when conditional expressions follow the same pattern as other conditional things. Condition, true, false. Is there something horribly unusual about wanting to take advantage of the fact that my brain has a much easier time processing things when they follow consistent patterns? -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 python at mrabarnett.plus.com Sun Sep 19 17:46:38 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 19 Sep 2010 22:46:38 +0100 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C9684BE.1040002@mrabarnett.plus.com> On 19/09/2010 22:32, Seebs wrote: > On 2010-09-19, AK wrote: >> Because that's what 'if' and 'else' mean. > > My point is, I don't want the order of the clauses in if/else to change. > If it is sometimes "if else", then > it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, > then false clause. If it's sometimes "if condition true-clause else > false-clause", and sometimes "true-clause if condition else false-clause", > that's a source of extra complexity. > [snip] Have you read PEP 308? There was a lot of discussion about it. From kwatford+python at gmail.com Sun Sep 19 17:59:38 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Sun, 19 Sep 2010 17:59:38 -0400 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) In-Reply-To: References: Message-ID: On Sun, Sep 19, 2010 at 9:16 AM, Aahz wrote: > In article , > geremy condra ? wrote: >>On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking >> wrote: >>> >>> I've been working with Python now for about a year using it primarily for >>> scripting in the Puredata graphical programming environment. I'm working on >>> a project where I have been given a 1000 by 1000 cell excel spreadsheet and >>> I would like to be able to access the data using Python. Does anyone know >>> of a way that I can do this? >> >>http://tinyurl.com/2eqqjxv > > Please don't use tinyurl -- it's opaque and provides zero help to anyone > who might later want to look it up (and also no accessibility if tinyurl > ever goes down). ?At the very least, include the original URL for > reference. > > (Yes, I realize this is probably a joke given the smiley I excised, but > too many people do just post tinyurl.) Not that I disagree with you, but you might find this helpful: http://tinyurl.com/preview.php From contact at xavierho.com Sun Sep 19 18:05:07 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 08:05:07 +1000 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) In-Reply-To: References: Message-ID: On 20 September 2010 07:59, Ken Watford > wrote: > > Not that I disagree with you, but you might find this helpful: > http://tinyurl.com/preview.php > -- > http://mail.python.org/mailman/listinfo/python-list > I don't think the OP wants a preview feature. The fact that you still have to go through tinyurl (which by the way, the short link itself in the email has no information on where it is whatsoever), and it makes searching through the archives difficult, too. We don't have a 140 character limit like Twitter. There's no reason we can't post the full link for reference purposes. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sun Sep 19 18:35:43 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 19 Sep 2010 15:35:43 -0700 (PDT) Subject: ctypes and buffers References: Message-ID: On Sep 19, 5:10?am, Thomas Jollans wrote: > On Sunday 19 September 2010, it occurred to Carl Banks to exclaim: > > I am creating a ctypes buffer from an existing non-ctypes object that > > supports buffer protocol using the following code: > > > from ctypes import * > > > PyObject_AsReadBuffer = pythonapi.PyObject_AsReadBuffer > > PyObject_AsReadBuffer.argtypes = > > [py_object,POINTER(c_void_p),POINTER(c_size_t)] > > PyObject_AsReadBuffer.restype = None > > > def ctypes_buffer_from_buffer(buf): > > ? ? cbuf = c_void_p() > > ? ? size = c_size_t() > > ? ? PyObject_AsReadBuffer(buf,byref(cbuf),byref(size)) > > ? ? return cbuf > > If I understand what you are doing correctly, you're referencing a Python > buffer object and returning a pointer wrapped in some ctypes thingy. hmm. I > see some problems in your code: > > ?* You're not passing the size along. In the name of sanity, why on earth > ? ?not?! The pointer cannot be safely used without knowing how long the area > ? ?of memory referenced is! How D'Olivero of you to overreact this way. A. No, and B. I already know the size of the object > ?* You're using the old buffer protocol. You might rather implement this with > ? ?the one introduced with Python 3.0, and supported in 2.6 as well. Hmm, I didn't know they got that into 2.6. Maybe I'll do that, thanks. Carl Banks From ben+python at benfinney.id.au Sun Sep 19 19:09:31 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Sep 2010 09:09:31 +1000 Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> Message-ID: <87k4mh5o0k.fsf@benfinney.id.au> Goran Novosel writes: > # vim: set encoding=utf-8 : This will help Vim, but won't help Python. Use the PEP 263 encoding declaration to let Python know the encoding of the program source file. # -*- coding: utf-8 -*- You can use the bottom of the file for editor hints. > s='abcdef ??????????'.decode('utf-8') > ss=unicode('ab ?????','utf-8') In Python 2.x, those string literals are created as byte strings, which is why you're having to decode them. Instead, tell Python explicitly that you want a string literal to be a Unicode text string: s = u'abcdef ??????????' ss = u'ab ?????' Learn more from the documentation . -- \ ?He that would make his own liberty secure must guard even his | `\ enemy from oppression.? ?Thomas Paine | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Sun Sep 19 19:18:57 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 20 Sep 2010 11:18:57 +1200 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <8fnk3qFk0bU1@mid.individual.net> AK wrote: > Afaik the idea is that you can read a novel at the speed of half a page > a second or so and understand it to the same extent as people who'd read > at a normal rate. I've never understood why anyone would *want* to read a novel that fast, though. For me at least, reading a novel is something done for pleasure, so reading it at ten times normal speed would waste 90% of the benefit. -- Greg From usenet-nospam at seebs.net Sun Sep 19 19:30:32 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 23:30:32 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, MRAB wrote: > On 19/09/2010 22:32, Seebs wrote: >> On 2010-09-19, AK wrote: >>> Because that's what 'if' and 'else' mean. >> My point is, I don't want the order of the clauses in if/else to change. >> If it is sometimes "if else", then >> it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, >> then false clause. If it's sometimes "if condition true-clause else >> false-clause", and sometimes "true-clause if condition else false-clause", >> that's a source of extra complexity. > > [snip] > Have you read PEP 308? There was a lot of discussion about it. Interesting, in the historical section we see: The original version of this PEP proposed the following syntax: if else The out-of-order arrangement was found to be too uncomfortable for many of participants in the discussion; especially when is long, it's easy to miss the conditional while skimming. But apparently those objections were either unknown or disregarded when the syntax was later adopted. -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 Sep 19 19:32:09 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 23:32:09 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: On 2010-09-19, Gregory Ewing wrote: > AK wrote: >> Afaik the idea is that you can read a novel at the speed of half a page >> a second or so and understand it to the same extent as people who'd read >> at a normal rate. > I've never understood why anyone would *want* to read a > novel that fast, though. For me at least, reading a novel > is something done for pleasure, so reading it at ten times > normal speed would waste 90% of the benefit. I get pleasure from the story, not from the time spent. Reading faster means I get more stories. Same thing, to some extent, with programming. I could easily spend much more time writing some programs by switching to a language ill-suited to them (say, using C for heavy string manipulation, or PHP for anything), but that wouldn't mean I had more fun, it would mean my fun was spread out over a longer period of time, and might well cross over to no-longer-fun. -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 Sun Sep 19 20:00:41 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 12:00:41 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message , Nobody wrote: > However, some clients choose their own source ports. E.g. rlogin/rsh use > privileged (low-numbered) ports, and you can't get the kernel to choose a > random privileged port for you. But nobody uses rlogin/rsh any more, and who would attach any trustworthy meaning to a connection coming from a remote low-numbered source port? > If you're writing a server which listens on a known port, you *should* be > using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel > will automatically reject packets relating to stale connections, and your > server should be accepting any new connections ASAP. That makes it sound like SO_REUSEADDR should really be a superfluous option. But it?s not. From ldo at geek-central.gen.new_zealand Sun Sep 19 20:02:28 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 12:02:28 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: In message , Aahz wrote: > Please don't use tinyurl -- it's opaque and provides zero help to anyone > who might later want to look it up (and also no accessibility if tinyurl > ever goes down). At the very least, include the original URL for > reference. +1 from someone who has seen URL-shortening used even in reader comments on websites which allow HTML links. From wuwei23 at gmail.com Sun Sep 19 20:33:53 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 19 Sep 2010 17:33:53 -0700 (PDT) Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> Message-ID: <46c489ec-2028-4a53-a184-f9f0afeb2ee6@h40g2000pro.googlegroups.com> AK wrote: > When I was reading The book of the new sun, though, I could stop and > read a single sentence a few times over and reflect on it for a minute. Totally understandable, Wolfe is a far, far greater writer than Rowling :) From andrei.avk at gmail.com Sun Sep 19 20:38:16 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 20:38:16 -0400 Subject: Too much code - slicing In-Reply-To: <8fnk3qFk0bU1@mid.individual.net> References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: <4C96ACF8.5000104@gmail.com> On 09/19/2010 07:18 PM, Gregory Ewing wrote: > AK wrote: > >> Afaik the idea is that you can read a novel at the speed of half a page >> a second or so and understand it to the same extent as people who'd read >> at a normal rate. > > I've never understood why anyone would *want* to read a > novel that fast, though. For me at least, reading a novel > is something done for pleasure, so reading it at ten times > normal speed would waste 90% of the benefit. > One definite advantage would be that if, say, it takes you 70 pages of a given novel to figure out whether you like it enough to continue, you'd want to read those pages in 2 minutes rather than an hour. Unfortunately, beginning of a novel is where I have to read at the slowest rate because I'm not used to author's style and pacing yet and I don't want to miss something crucial. -ak From tjreedy at udel.edu Sun Sep 19 20:38:49 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Sep 2010 20:38:49 -0400 Subject: newbie: class and __dict__ variable. In-Reply-To: References: Message-ID: On 9/19/2010 1:37 PM, mafeusek at gmail.com wrote: > > Hallo Group Members. From time to time I see in python code following > notation that (as I believe) extends namespace of MyClass. No, it does not affect MyClass, just the instance dict. > class MyClass: > def __init__(self): > self.__dict__["maci"]=45 Have you seen exactly this usage? > > myCl2 = MyClass2() > print myCl2.maci > > > I am guessing that there must be some difference between the one above > and the one below, because otherwise no one would probably use the one > above. Do YOu know that difference? > > class MyClass2: > def __init__(self): > self.maci=45 If the class has a .__setattr__ method, the first bypasses that method, the second results in it being called. The direct __dict__ access is most useful within a .__setattr__ method to avoid infinite recursion. > myCl = MyClass() > print myCl.maci -- Terry Jan Reedy From philip at semanchuk.com Sun Sep 19 20:54:35 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 19 Sep 2010 20:54:35 -0400 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) In-Reply-To: References: Message-ID: On Sep 19, 2010, at 6:05 PM, Xavier Ho wrote: > On 20 September 2010 07:59, Ken Watford > >> wrote: > >> >> Not that I disagree with you, but you might find this helpful: >> http://tinyurl.com/preview.php >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > I don't think the OP wants a preview feature. The fact that you still have > to go through tinyurl (which by the way, the short link itself in the email > has no information on where it is whatsoever), and it makes searching > through the archives difficult, too. > > We don't have a 140 character limit like Twitter. There's no reason we can't > post the full link for reference purposes. Some email systems still insert hard line breaks around the 72 or 80 column mark and as a result long URLs get broken. I hope anyone on this list would be able to surgically repair a broken URL, but I email plenty of people who can't and tinyurl & friends are really helpful in that context. bye P From usenet-nospam at seebs.net Sun Sep 19 21:36:14 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 01:36:14 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> <46c489ec-2028-4a53-a184-f9f0afeb2ee6@h40g2000pro.googlegroups.com> Message-ID: On 2010-09-20, alex23 wrote: > AK wrote: >> When I was reading The book of the new sun, though, I could stop and >> read a single sentence a few times over and reflect on it for a minute. > Totally understandable, Wolfe is a far, far greater writer than > Rowling :) Certainly true. On the other hand, I found it frustrating when I *had* to re-read a passage a couple of times to figure out what had just happened. :) ... Not that rereading books is necessarily a bad thing. -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 john at castleamber.com Sun Sep 19 22:32:17 2010 From: john at castleamber.com (John Bokma) Date: Sun, 19 Sep 2010 21:32:17 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: <87vd6116xa.fsf@castleamber.com> AK writes: > On 09/19/2010 07:18 PM, Gregory Ewing wrote: >> AK wrote: >> >>> Afaik the idea is that you can read a novel at the speed of half a page >>> a second or so and understand it to the same extent as people who'd read >>> at a normal rate. >> >> I've never understood why anyone would *want* to read a >> novel that fast, though. For me at least, reading a novel >> is something done for pleasure, so reading it at ten times >> normal speed would waste 90% of the benefit. >> > > One definite advantage would be that if, say, it takes you 70 pages of a > given novel to figure out whether you like it enough to continue, you'd > want to read those pages in 2 minutes rather than an hour. Heh, to me speed reading those 70 pages in a very short while, concluding that it's a good book, and start over again would be quite the spoiler. Do you fast forward movies as well? I do speed read but not the books I read for pleasure. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From pavlovevidence at gmail.com Sun Sep 19 22:32:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 19 Sep 2010 19:32:33 -0700 (PDT) Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> Message-ID: On Sep 19, 4:09?pm, Ben Finney wrote: > Goran Novosel writes: > > # vim: set encoding=utf-8 : > > This will help Vim, but won't help Python. Use the PEP 263 encoding > declaration to let Python > know the encoding of the program source file. That's funny because I went to PEP 263 and the line he used was listed there. Apparently, you're the one that needs to read PEP 263. Carl Banks From usenet-nospam at seebs.net Sun Sep 19 22:50:21 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 02:50:21 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> Message-ID: On 2010-09-20, John Bokma wrote: > Heh, to me speed reading those 70 pages in a very short while, > concluding that it's a good book, and start over again would be quite > the spoiler. I rarely encounter substantive spoilers in the first 70 pages or so of a book. That said, I'm pretty much immune to spoilers; while I'm reading, I'm usually ignoring anything I might have previously known about a story, so it all works even if I've read it before. > Do you fast forward movies as well? Amusingly, I can't generally watch movies at normal speed. They're too boring. Luckily, computers are finally advancing to a point where "1.2x faster, but no chipmunks" is an available setting in some software. -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 Sun Sep 19 22:57:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 19:57:16 -0700 Subject: C++ - Python API References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: In article , Thomas Jollans wrote: >On Sunday 19 September 2010, it occurred to Aahz to exclaim: >> In article , >> Thomas Jollans wrote: >>>On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: >>>> >>>> So the feature overview: >>> >>>First, the obligatory things you don't want to hear: Have you had >>>a look at similar efforts? A while ago, Aahz posted something very >>>similar on this very list. You should be able to find it in any of the >>>archives without too much trouble. >> >> You almost certainly have me confused with someone else -- I wouldn't >> touch C++ with a ten-meter pole if I could possibly help it. (The last >> time I dealt with C++ code, about a decade ago, I just rewrote it in C.) > >Sorry about that. No biggie, just wanted to prevent further confusion. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From aahz at pythoncraft.com Sun Sep 19 23:00:39 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 20:00:39 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: In article , Philip Semanchuk wrote: > >Some email systems still insert hard line breaks around the 72 or 80 >column mark and as a result long URLs get broken. I hope anyone on this >list would be able to surgically repair a broken URL, but I email plenty >of people who can't and tinyurl & friends are really helpful in that >context. There's no reason you can't cater to that problem by using tinyurl *in* *addition* to the full regular URL. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 23:36:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 03:36:42 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: <4c96d6ca$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 11:18:57 +1200, Gregory Ewing wrote: > AK wrote: > >> Afaik the idea is that you can read a novel at the speed of half a page >> a second or so and understand it to the same extent as people who'd >> read at a normal rate. > > I've never understood why anyone would *want* to read a novel that fast, > though. For me at least, reading a novel is something done for pleasure, > so reading it at ten times normal speed would waste 90% of the benefit. Or reduce the pain by 90%, depending on the book... -- Steven From justin.mailinglists at gmail.com Sun Sep 19 23:38:46 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Sun, 19 Sep 2010 20:38:46 -0700 (PDT) Subject: SimpleHTTPServer, external CSS, and Google Chrome References: <057af264-995d-4e60-9887-d053b93bd988@m17g2000prl.googlegroups.com> <2079bf56-6c19-4233-97d9-418b7e9d0190@a4g2000prm.googlegroups.com> Message-ID: <66c6c94a-9022-494d-8cce-04086f7106fb@v35g2000prn.googlegroups.com> On Sep 18, 2:54?am, MrJean1 wrote: > FWIW, > > There is a blue text on a red background in all 4 browsers Google > Chrome 6.0.472.59, Safari 5.0.1 (7533.17.8), FireFox 3.6.9 and IE > 6.0.2900.5512.... with Python 2.7 serving that page on my Windows XP > SP 3 machine. > > /Jean > Hmm. Will download and install newer python versions to re-check then. Thanks. From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 23:42:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 03:42:30 GMT Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> Message-ID: <4c96d826$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 09:09:31 +1000, Ben Finney wrote: > Goran Novosel writes: > >> # vim: set encoding=utf-8 : > > This will help Vim, but won't help Python. It will actually -- the regex Python uses to detect encoding lines is documented, and Vim-style declarations are allowed as are Emacs style. In fact, something as minimal as: # coding=utf-8 will do the job. > Use the PEP 263 encoding > declaration to let Python > know the encoding of the program source file. While PEPs are valuable, once accepted or rejected they become historical documents. They don't necessarily document the current behaviour of the language. See here for documentation on encoding declarations: http://docs.python.org/reference/lexical_analysis.html#encoding-declarations -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 23:43:01 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 03:43:01 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: <4c96d845$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 06:16:49 -0700, Aahz wrote: > Please don't use tinyurl -- it's opaque and provides zero help to anyone > who might later want to look it up (and also no accessibility if tinyurl > ever goes down). At the very least, include the original URL for > reference. Do you have something against tinyurl in particular, or would any URL shortener service also get your ire? -- Steven From usenet-nospam at seebs.net Sun Sep 19 23:53:06 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 03:53:06 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Steven D'Aprano wrote: > On Sun, 19 Sep 2010 06:16:49 -0700, Aahz wrote: >> Please don't use tinyurl -- it's opaque and provides zero help to anyone >> who might later want to look it up (and also no accessibility if tinyurl >> ever goes down). At the very least, include the original URL for >> reference. > Do you have something against tinyurl in particular, or would any URL > shortener service also get your ire? I'd assume all of them have the same essential problems: * No hint as to what site you'll be getting redirected to. * No cues from URL as to what the link is to. * If the service ever goes away, the links become pure noise. -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 andrei.avk at gmail.com Mon Sep 20 00:03:48 2010 From: andrei.avk at gmail.com (AK) Date: Mon, 20 Sep 2010 00:03:48 -0400 Subject: Too much code - slicing In-Reply-To: <87vd6116xa.fsf@castleamber.com> References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> Message-ID: <4C96DD24.3020400@gmail.com> On 09/19/2010 10:32 PM, John Bokma wrote: > AK writes: > >> On 09/19/2010 07:18 PM, Gregory Ewing wrote: >>> AK wrote: >>> >>>> Afaik the idea is that you can read a novel at the speed of half a page >>>> a second or so and understand it to the same extent as people who'd read >>>> at a normal rate. >>> >>> I've never understood why anyone would *want* to read a >>> novel that fast, though. For me at least, reading a novel >>> is something done for pleasure, so reading it at ten times >>> normal speed would waste 90% of the benefit. >>> >> >> One definite advantage would be that if, say, it takes you 70 pages of a >> given novel to figure out whether you like it enough to continue, you'd >> want to read those pages in 2 minutes rather than an hour. > > Heh, to me speed reading those 70 pages in a very short while, > concluding that it's a good book, and start over again would be quite > the spoiler. Do you fast forward movies as well? I honestly doubt it would be a spoiler if it's a good book. Generally I find that poor books rely on twists and turns while better ones rely on the fabric of story-telling. Aside from that, though, it's a very interesting question - I'll try to think of good books and see if they'd be spoiled by peeking in the first 70 pages.. Starting with children's books, Peter Pan and Wind in the Willows, I think, would not be. Don quixote would not be. Crime and punishment - maybe if you get as far as the murder? Same author's the Devils, I would say you can read the last 70 pages and it'd be just as good :). -ak From mahaboobnisha at gmail.com Mon Sep 20 00:15:40 2010 From: mahaboobnisha at gmail.com (roshini begum) Date: Sun, 19 Sep 2010 21:15:40 -0700 (PDT) Subject: www.127760.blogspot.com Message-ID: <22f15036-d560-4bac-bc09-ef3f5fe5e721@g21g2000prn.googlegroups.com> www.127760.blogspot.com From john at castleamber.com Mon Sep 20 01:04:22 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 00:04:22 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> Message-ID: <87vd613t0p.fsf@castleamber.com> AK writes: > On 09/19/2010 10:32 PM, John Bokma wrote: >> AK writes: >> >>> On 09/19/2010 07:18 PM, Gregory Ewing wrote: >>>> AK wrote: >>>> >>>>> Afaik the idea is that you can read a novel at the speed of half a page >>>>> a second or so and understand it to the same extent as people who'd read >>>>> at a normal rate. >>>> >>>> I've never understood why anyone would *want* to read a >>>> novel that fast, though. For me at least, reading a novel >>>> is something done for pleasure, so reading it at ten times >>>> normal speed would waste 90% of the benefit. >>>> >>> >>> One definite advantage would be that if, say, it takes you 70 pages of a >>> given novel to figure out whether you like it enough to continue, you'd >>> want to read those pages in 2 minutes rather than an hour. >> >> Heh, to me speed reading those 70 pages in a very short while, >> concluding that it's a good book, and start over again would be quite >> the spoiler. Do you fast forward movies as well? > > I honestly doubt it would be a spoiler if it's a good book. Generally I > find that poor books rely on twists and turns while better ones rely on > the fabric of story-telling. Aside from that, though, it's a very > interesting question - I'll try to think of good books and see if they'd > be spoiled by peeking in the first 70 pages.. Starting with children's > books, Peter Pan and Wind in the Willows, I think, would not be. Don > quixote would not be. Crime and punishment - maybe if you get as far as > the murder? Same author's the Devils, I would say you can read the last > 70 pages and it'd be just as good :). -ak I didn't mean that there are spoilers in the first 70 pages, just that to me the excercise would spoil the book, so, I wouldn't do it. I consider a book like a meal, I wouldn't gobble down food, regurgitate it, and eat it again at a slower pace. Books, movies, family, walks are the things I prefer to do at a normal mudane pace, or even slower, if I can bring myself to it. My favourite books I try to read slow, and enjoy. ;-). Too much of my life is already in overdrive. -- 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 Sep 20 01:06:03 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 05:06:03 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Seebs wrote: > On 2010-09-20, Steven D'Aprano wrote: >> On Sun, 19 Sep 2010 06:16:49 -0700, Aahz wrote: >>> Please don't use tinyurl -- it's opaque and provides zero help to anyone >>> who might later want to look it up (and also no accessibility if tinyurl >>> ever goes down). At the very least, include the original URL for >>> reference. > >> Do you have something against tinyurl in particular, or would any URL >> shortener service also get your ire? > > I'd assume all of them have the same essential problems: > > * No hint as to what site you'll be getting redirected to. Tinyurl, in particular, allows you to preview the url if you choose to do so. Other URL shortning services have a similar feature. > * No cues from URL as to what the link is to. Same point as above. Same solution. > * If the service ever goes away, the links become pure noise. This happens a lot on the web anyway. Do you have any idea how many pieces of free software are first hosted on university servers to disappear when the author graduates/moves to another school or free shared host servers that have to be moved due to lack of scalability? Sourceforge solved much of this problem; but, then if sourceforge should ever disappear, all of its links will be pure noise as well. The simple fact is that the Internet changes. It changed before URL shortening services came into the mainstream and it will be true long after they have left. From usenet-nospam at seebs.net Mon Sep 20 01:06:47 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 05:06:47 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> <87vd613t0p.fsf@castleamber.com> Message-ID: On 2010-09-20, John Bokma wrote: > I didn't mean that there are spoilers in the first 70 pages, just that > to me the excercise would spoil the book, so, I wouldn't do it. I > consider a book like a meal, I wouldn't gobble down food, regurgitate > it, and eat it again at a slower pace. Books, movies, family, walks are > the things I prefer to do at a normal mudane pace, or even slower, if I > can bring myself to it. My favourite books I try to read slow, and > enjoy. ;-). Too much of my life is already in overdrive. Now that you explain it like this, that makes a fair bit of sense. I often wonder whether reading slowly would be more pleasant. I have no idea how to do it, so the question remains theoretical. -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 Sep 20 01:10:05 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 05:10:05 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Tim Harig wrote: > On 2010-09-20, Seebs wrote: >> * No hint as to what site you'll be getting redirected to. > Tinyurl, in particular, allows you to preview the url if you choose to do > so. Other URL shortning services have a similar feature. I have no idea how. If I see a "tinyurl" URL, and I paste it into a browser, last I tried it, I ended up on whatever page it redirected to. >> * No cues from URL as to what the link is to. > Same point as above. Same solution. I'm not reading news in a web browser. I don't want to have to cut and paste and go look at a page in order to determine whether I want to switch to my browser. >> * If the service ever goes away, the links become pure noise. > This happens a lot on the web anyway. True. > Do you have any idea how many > pieces of free software are first hosted on university servers to > disappear when the author graduates/moves to another school or free > shared host servers that have to be moved due to lack of scalability? > Sourceforge solved much of this problem; but, then if sourceforge should > ever disappear, all of its links will be pure noise as well. This is true. But two points of failure strikes me as worse than one. :) > The simple fact is that the Internet changes. It changed before URL > shortening services came into the mainstream and it will be true long > after they have left. Oh, certainly. I'm not particularly convinced that these are *significant* complaints about URL-shorteners. But I will say, of the last couple hundred links I've followed from Usenet posts, precisely zero of them were through URL redirectors. If I can't at least look at the URL to get some initial impression of what it's a link to, I'm not going to the trouble of swapping to a web browser to find out. -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 gavcomedy at gmail.com Mon Sep 20 01:17:45 2010 From: gavcomedy at gmail.com (gavino) Date: Sun, 19 Sep 2010 22:17:45 -0700 (PDT) Subject: compiling python 3.1.2 with local readline fails to get readline - help! References: Message-ID: On Sep 15, 6:41?pm, James Mills wrote: > On Thu, Sep 16, 2010 at 11:10 AM, gavino wrote: > > I am comiling 3.1.2. > > I am not root but a user. > > I compiled readline and it did not complain. > > gdb and zlib ?and some other modules also were not found. > > Like I said earlier in my previous post, is the readline line that > you compiled and installed to your home directory actually > working and can you actually compile any C programs that > use this custom readline ? > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" I don't know how to test readline. It compiled without complaint. I guess my questions boils down to how to point the python compile to the readline lib? I don't have root. From jeblanton at crimson.ua.edu Mon Sep 20 01:46:34 2010 From: jeblanton at crimson.ua.edu (Jordan Blanton) Date: Mon, 20 Sep 2010 00:46:34 -0500 Subject: programming Message-ID: I am in a computer science class in which I am supposed to be creating a program involving a sine wave and some other functions. I understand the concept of the problem, but I don't understand any of the "lingo" being used. The directions might as well be written in a different language. Is there anyone on here that might be able to help me in understanding what certain things mean? -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Mon Sep 20 01:46:38 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 05:46:38 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Seebs wrote: > On 2010-09-20, Tim Harig wrote: >> On 2010-09-20, Seebs wrote: >>> * No hint as to what site you'll be getting redirected to. > >> Tinyurl, in particular, allows you to preview the url if you choose to do >> so. Other URL shortning services have a similar feature. > > I have no idea how. If I see a "tinyurl" URL, and I paste it into > a browser, last I tried it, I ended up on whatever page it redirected > to. 1. Don't bother to manually paste when you can use something like urlview to lauch directly. 2. tinyurl addresses can be previewed by adding the "preview" subdomain to the tinyurl. For example, the address that started this subthread would become: http://preview.tinyurl.com/2eqqjxv If you want this behavior by default, you can easily wrap urlview to automatically add the prefix. >>> * If the service ever goes away, the links become pure noise. > >> This happens a lot on the web anyway. > > True. > >> Do you have any idea how many >> pieces of free software are first hosted on university servers to >> disappear when the author graduates/moves to another school or free >> shared host servers that have to be moved due to lack of scalability? >> Sourceforge solved much of this problem; but, then if sourceforge should >> ever disappear, all of its links will be pure noise as well. > > This is true. > > But two points of failure strikes me as worse than one. :) I question first whether most tinyurl links are really of such an intransient nature that they need to be long lasting. I personally use them most when writing paper notes. They only need to last long enough for me, or whoever I made the note for, to get back to them. In theory, something like this adds the possibilty of adding another level of indirection; which could make the system more robust if used properly. Just think of how much resiliency is gained by using DNS, which can be redirected, as opposed to IP addresses which you cannot take with you if you move. This is academic as tinyurl addresses cannot be changed; but, it does point out that simple logic such as two points of failure must be worse then one isn't always correct. >> The simple fact is that the Internet changes. It changed before URL >> shortening services came into the mainstream and it will be true long >> after they have left. > > I'm not particularly convinced that these are *significant* complaints > about URL-shorteners. But I will say, of the last couple hundred links > I've followed from Usenet posts, precisely zero of them were through > URL redirectors. If I can't at least look at the URL to get some > initial impression of what it's a link to, I'm not going to the trouble > of swapping to a web browser to find out. But why should the rest of us be penalized because you make the choice not to use (or not take full advantage of) all of the tools that are available to you? From debatem1 at gmail.com Mon Sep 20 01:50:34 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 19 Sep 2010 22:50:34 -0700 Subject: programming In-Reply-To: References: Message-ID: On Sun, Sep 19, 2010 at 10:46 PM, Jordan Blanton wrote: > I am in a computer science class in which I am supposed to be creating a > program involving a sine wave and some other functions. I understand the > concept of the problem, but I don't understand any of the "lingo" being > used. The directions might as well be written in a different language. Is > there anyone on here that might be able to help me in understanding what > certain things mean? Yes. Geremy Condra From haring at preypacer.com Mon Sep 20 02:08:09 2010 From: haring at preypacer.com (Ralf Haring) Date: Sun, 19 Sep 2010 23:08:09 -0700 (PDT) Subject: visual studio 2010 question Message-ID: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> After running into the error "Setup script exited with error: Unable to find vcvarsall.bat" when trying to use easy_install / setuptools a little digging showed that the MS compiler files in distutils only support up to Studio 2008. Does anyone know if there is a timetable for when Studio 2010 will be supported? I am using python 2.6.5, but web searching seemed to show that 2.7 or 3.X didn't support it yet either. -Ralf Haring From contact at xavierho.com Mon Sep 20 02:18:03 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 16:18:03 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 15:46, Jordan Blanton wrote: > I am in a computer science class in which I am supposed to be creating a > program involving a sine wave and some other functions. I understand the > concept of the problem, but I don't understand any of the "lingo" being > used. The directions might as well be written in a different language. Is > there anyone on here that might be able to help me in understanding what > certain things mean? > If you can tell us what terms you don't understand, we may be able to provide you some explanations. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Mon Sep 20 02:22:18 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 06:22:18 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Tim Harig wrote: > 1. Don't bother to manually paste when you can use something like urlview > to lauch directly. I don't know that this would actually be better than what I currently do, which is grab text and middle-click in another window. > If you want this behavior by default, you can easily wrap urlview > to automatically add the prefix. True, but since my news reading is not on the machine my web browser is on, it seems like it might get annoying. > I question first whether most tinyurl links are really of such an > intransient nature that they need to be long lasting. I personally use > them most when writing paper notes. They only need to last long enough > for me, or whoever I made the note for, to get back to them. By default, I assume that Usenet posts are for the longer term, and a Usenet post which relies for its content on tinyurl is thus somewhat more vulnerable than one which doesn't. In particular, consider things like archive.org; they may well be able to find a long-dead web page, but not a long-dead tinyurl link. > This is academic as tinyurl addresses cannot be changed; but, it > does point out that simple logic such as two points of failure must be > worse then one isn't always correct. Not always correct, but I think it is in this case. > But why should the rest of us be penalized because you make the choice > not to use (or not take full advantage of) all of the tools that are > available to you? For about the same reason that I should be penalized because someone else wanted things done differently. Which is to say, it's a tradeoff, the right choice to make depends on what your goals are. If you want a piece of information to have maximal longevity, something like tinyurl is probably a bad way to transmit it. If you want something small that survives line wrapping, it's probably a good way. FWIW, the browsers I use automatically Do The Right Thing if you paste in a multiline URL. -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 Mon Sep 20 02:22:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 06:22:41 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 05:46:38 +0000, Tim Harig wrote: >> I'm not particularly convinced that these are *significant* complaints >> about URL-shorteners. But I will say, of the last couple hundred links >> I've followed from Usenet posts, precisely zero of them were through >> URL redirectors. If I can't at least look at the URL to get some >> initial impression of what it's a link to, I'm not going to the trouble >> of swapping to a web browser to find out. > > But why should the rest of us be penalized because you make the choice > not to use (or not take full advantage of) all of the tools that are > available to you? I'm with Aahz... best practice is to post both the full and shortened URL, unless the URL is less that 78 characters, in which case just post the full version. Similarly, if I'm posting a link to some URL that looks like this: http://blah blah blah/link=useful-bit&noise&rubbish&crap&crap&crap&more- crap&lots-more-crap-for-three-more-lines I try editing the URL to http://blah blah blah/link=useful-bit and if the link still works, I just post that. Google search results, I'm looking at you. (Although they're not even *close* to the worst.) Personally, I think that any professional business or government site that exposes URLs filled with parameters, without giving a shortened "permalink" version, is full of Fail. -- Steven From justin.mailinglists at gmail.com Mon Sep 20 02:26:11 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Sun, 19 Sep 2010 23:26:11 -0700 (PDT) Subject: SimpleHTTPServer, external CSS, and Google Chrome References: <057af264-995d-4e60-9887-d053b93bd988@m17g2000prl.googlegroups.com> <2079bf56-6c19-4233-97d9-418b7e9d0190@a4g2000prm.googlegroups.com> <66c6c94a-9022-494d-8cce-04086f7106fb@v35g2000prn.googlegroups.com> Message-ID: LOL. twas http://bugs.python.org/issue839496 From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 02:26:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 06:26:20 GMT Subject: [OT] Speed-reading [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c96fe8b$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 10:29:10 -0400, AK wrote: > On 09/18/2010 11:28 PM, Steven D'Aprano wrote: [...] >> My wife can read scarily fast. It's very something to watch her reading >> pages as fast as she can turn them, and a few years ago she read the >> entire Harry Potter series (to date) in one afternoon, and could gives >> a blow-by-blow account of the plots, including a detailed critique of >> the writing style and characters. But then, she feels that reading the >> Potter series is a chore to be completed as fast as possible, rather >> than a pleasure to be savored. She'll sometimes drag a new Terry >> Pratchett or Stephen King novel out for as much as two days. >> >> >> > That's pretty impressive. I used to get somewhat close to that speed > when, years ago, I'd read a lot of trashy scifi. [...] > In other spots, I'd > be able to scan a few words at the top of page, a few in the middle and > at the bottom and I'd know what's going on, generally. I don't know about how other people speed-read, but I can assure you that when my wife speed-reads, she's not just scanning a few words and interpolating between them. She can give you a detailed summary of what *actually* happened, not just a good guess. Including pointing out any spelling or grammatical errors and clumsy writing. *Especially* the spelling errors, they have about the same effect on her reading speed as a tree trunk lying across a Formula 1 race track. -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 02:29:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 06:29:57 GMT Subject: [OT] Syntax highlighting [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c96ff65$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 07:36:11 +0000, Seebs wrote: > On 2010-09-19, Steven D'Aprano > wrote: >> I'm not entirely sure I agree with you here... you can't ignore syntax >> in order to understand the meaning of code. > > No, but the syntax should be invisible. When I read English, I don't > have to think about nouns and verbs and such unless something is very > badly written. That's almost certainly because you've been listening to, speaking, reading and writing English since you were a small child, and the syntax and grammar of English is buried deep in your brain. And you certainly do think about nouns and verbs, you just don't *consciously* think about them. If I write: "Susan blooged the mobblet." you will probably recognise "bloog" as the verb and "mobblet" as the noun, even though you've almost certainly never seen those words before and have no idea what they mean. But if I write this: "Susan is mobblet the blooged." you'll probably give a double-take. The words don't look right for English grammar and syntax. I've been reading, writing and thinking in Python for well over a decade. The syntax and grammar is almost entirely invisible to me too. No surprise there -- they are relatively close to that of the human languages I'm used to (English). But if I were a native Chinese or Arabic speaker, I'd probably find Python much less "natural" and *would* need to explicitly think about the syntax more. [...] >> The term "syntax highlighting" for what editors I've seen do is >> actually misleading -- they don't highlight *syntax*, they try to >> highlight *semantics*. > > I've never seen this. I've seen things highlight comments and keywords > and operators and constants and identifiers differently. Exactly. Things are highlighted because of *what* they are, not because of the syntax they use or because of the grammatical role they play. In a Python expression like: y = none or None an editor might colour "None" green because it's a known keyword, but "none" black because it's a variable. If you change the syntax: y = None if [none][0] is None else {None: none}[None] the colours remain the same. None is coloured green not because of *where* it is in the syntax tree, but because of *what* it is. Calling this "syntax highlighting" is misleading, or at least incomplete. >> When your editor highlights the function len() in the expression "x = >> len(y) + spam(z)" but not the function spam(), you know it has nothing >> to do with syntax. len() is singled out because of its semantics, >> namely the fact that it's a built-in. > > Eww. (I had not yet gotten to the point of finding out that whether > something was "built-in" or not substantially affected its semantics.) In some languages, built-in functions truly are special, e.g. they are reserved words. That's not the case for Python. Nevertheless, the editors I've used treat built-ins as "pseudo-reserved words" and colourise them. >> In English, the meaning of the some sentences do benefit by syntax >> highlighting, and in fact that's partly what punctuation is for: >> English partly uses punctuation marks as tags to break the sentence >> structure into sub-sentences, clauses and terms (particularly when the >> sentence would otherwise be ambiguous). > > Punctuation is very different from highlighting, IMHO. That said, I > find punctuation very effective at being small and discrete, clearly not > words, and easy to pick out. Color cues are not nearly as good at being > inobtrusive but automatically parsed. Well that surely depends on the colour scheme you have. My editor is fairly restrained -- it uses a handful of colours (although of course you can customize it and go nuts), and I've made it even more subtle. To my eyes, the feature of syntax highlighting that alone makes it worthwhile, its killer feature, is that I can set comments and docstrings to grey. When I'm scanning code, being able to slide my eyes over greyed- out comments and docstrings and ignore them with essentially zero effort is a huge help. That's the thing I most miss, more than anything else, when using a dumb editor. >> "Woman shoots man with crossbow" > >> Was it the man armed with a crossbow, or the woman? If we could somehow >> group the clause "with crossbow" with "woman" or "man" by something >> *other* than proximity, we could remove the ambiguity. > > Yes. But syntax highlighting won't help you here -- at least, I've > never yet seen any editor that showed precedence relations or anything > similar in its coloring. Just because nobody has done it yet doesn't mean that some sufficiently intelligent software in the future couldn't do it :) -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 02:30:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 06:30:30 GMT Subject: The trouble with "dynamic attributes". References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4c93a06c$1@dnews.tpgi.com.au> <4c95b1c3$1@dnews.tpgi.com.au> Message-ID: <4c96ff85$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 16:47:26 +1000, Lie Ryan wrote: > On 09/18/10 03:53, Ethan Furman wrote: >> Lie Ryan wrote: >> [snip] >>> And even dict-syntax is not perfect for accessing XML file, e.g.: >>> >>> >>> foo >>> bar >>> >>> >>> should a['b'] be 'foo' or 'bar'? >> >> Attribute style access would also fail in this instance -- how is this >> worked-around? > > By not having multiple b in the first place! Which works just as well for dict access. Given that attribute access is nothing but syntactic sugar for dict access, there is nothing you can do with attribute access that can't be done with dict access. However, the same does not apply in reverse -- there are many things you can't do with attribute access that work fine with dict access. -- Steven From contact at xavierho.com Mon Sep 20 02:34:16 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 16:34:16 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 16:25, Jordan Blanton wrote: > its not specific terms that i dont understand. its general directions. but > when i dont understand one or two key points in a sentence, its hard to > understand what the directions are telling me to do. Is it possible for you to share the sentence / description with us? My psychic powers have its limits. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From contact at xavierho.com Mon Sep 20 02:34:16 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 16:34:16 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 16:25, Jordan Blanton wrote: > its not specific terms that i dont understand. its general directions. but > when i dont understand one or two key points in a sentence, its hard to > understand what the directions are telling me to do. Is it possible for you to share the sentence / description with us? My psychic powers have its limits. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From cournape at gmail.com Mon Sep 20 02:39:34 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 20 Sep 2010 15:39:34 +0900 Subject: visual studio 2010 question In-Reply-To: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> References: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> Message-ID: On Mon, Sep 20, 2010 at 3:08 PM, Ralf Haring wrote: > > After running into the error "Setup script exited with error: Unable > to find vcvarsall.bat" when trying to use easy_install / setuptools a > little digging showed that the MS compiler files in distutils only > support up to Studio 2008. Does anyone know if there is a timetable > for when Studio 2010 will be supported? > > I am using python 2.6.5, but web searching seemed to show that 2.7 or > 3.X didn't support it yet either. You should use VS 2008 - the lack of distutils support is only the first of a long list of issues if you want to use another compiler to build python extensions. Unless you really know what you are doing, you are better off with VS 2008, cheers, David From contact at xavierho.com Mon Sep 20 02:39:57 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 16:39:57 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 16:38, Jordan Blanton wrote: > Honestly, if I knew what was being said, then yes. I posted the directions > to the project and what I've done so far but I have no idea if what I'm > doing is right at all. > > Jordan, correct me if I'm mistaken, but you didn't post the directions to the project, nor what you've done so far - at least not on Python-list. Double check your emails that you didn't just reply to specifically someone, and not the whole list? Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From mafeusek at gmail.com Mon Sep 20 02:42:30 2010 From: mafeusek at gmail.com (mafeusek at gmail.com) Date: Mon, 20 Sep 2010 08:42:30 +0200 Subject: newbie: class and __dict__ variable. In-Reply-To: (Terry Reedy's message of "Sun, 19 Sep 2010 20:38:49 -0400") References: Message-ID: Terry, thank You very much for Your answer. Very helpfull! > Have you seen exactly this usage? NO, i just wrote an example, but the trick is quite frequent, thus it will be easy to check out the existence of .__setattr__ in such a case. best regards, Pawel From usenet-nospam at seebs.net Mon Sep 20 02:51:52 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 06:51:52 GMT Subject: [OT] Speed-reading [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> <4c96fe8b$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Steven D'Aprano wrote: > I don't know about how other people speed-read, but I can assure you that > when my wife speed-reads, she's not just scanning a few words and > interpolating between them. She can give you a detailed summary of what > *actually* happened, not just a good guess. Including pointing out any > spelling or grammatical errors and clumsy writing. *Especially* the > spelling errors, they have about the same effect on her reading speed as > a tree trunk lying across a Formula 1 race track. Yeah. I think it's because the entire trick is to have a nice smooth pipeline, and the error-checking mechanism has to be pretty alert for that to work -- you have to know if something went wrong. And a spelling error in the text is initially indistinguishable from a reading error in the eye... -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 Sep 20 03:02:23 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 07:02:23 GMT Subject: [OT] Syntax highlighting [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> <4c96ff65$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Steven D'Aprano wrote: > On Sun, 19 Sep 2010 07:36:11 +0000, Seebs wrote: >> No, but the syntax should be invisible. When I read English, I don't >> have to think about nouns and verbs and such unless something is very >> badly written. > That's almost certainly because you've been listening to, speaking, > reading and writing English since you were a small child, and the syntax > and grammar of English is buried deep in your brain. Yes. But I've been programming long enough that I seem to get similar results in most languages pretty quickly. > And you certainly do think about nouns and verbs, you just don't > *consciously* think about them. Well, yes. But it's conscious think time that's the limiting resource for the most part -- so if I can avoid things that require conscious thought, that frees up more for thinking about the problem. > you will probably recognise "bloog" as the verb and "mobblet" as the > noun, even though you've almost certainly never seen those words before > and have no idea what they mean. But if I write this: > "Susan is mobblet the blooged." > you'll probably give a double-take. The words don't look right for > English grammar and syntax. Well, actually, at that point I just assume you missed the capital m on what is apparently a proper noun. :) > I've been reading, writing and thinking in Python for well over a decade. > The syntax and grammar is almost entirely invisible to me too. No > surprise there -- they are relatively close to that of the human > languages I'm used to (English). But if I were a native Chinese or Arabic > speaker, I'd probably find Python much less "natural" and *would* need to > explicitly think about the syntax more. That's a fascinating question. I don't think that would be the case, though. Or at least. If you've used more than a couple of programming languages that much, I wouldn't expect it to be the case. I'm not a native speaker of Chinese, but after a year in China, I stopped perceiving grammar and just heard sentences. (Sadly, I've mostly since lost the vocabulary, leaving me with the annoyance of a language I can think in grammatically but can't express much of anything in.) >> I've never seen this. I've seen things highlight comments and keywords >> and operators and constants and identifiers differently. > Exactly. Things are highlighted because of *what* they are, not because > of the syntax they use or because of the grammatical role they play. Hmm, interesting point. e.g., a function name is likely to be highlighted the same whether I'm calling it or referring to it as an object. (I'm very new to Python, so I'm not 100% sure functions are a kind of an object, but I seem to recall they were.) I guess that's a point; "syntax coloring" is perhaps not the right word either for what they do. > In a Python expression like: > y = none or None > an editor might colour "None" green because it's a known keyword, but > "none" black because it's a variable. If you change the syntax: > y = None if [none][0] is None else {None: none}[None] > the colours remain the same. None is coloured green not because of > *where* it is in the syntax tree, but because of *what* it is. Calling > this "syntax highlighting" is misleading, or at least incomplete. This strikes me as correct. But it's not exactly semantics, either. It's... I dunno what to call it. >> Eww. (I had not yet gotten to the point of finding out that whether >> something was "built-in" or not substantially affected its semantics.) > In some languages, built-in functions truly are special, e.g. they are > reserved words. That's not the case for Python. Nevertheless, the editors > I've used treat built-ins as "pseudo-reserved words" and colourise them. Interesting. I wonder why. I guess just because if you meant to name a variable with one of those words, maybe you'd want the reminder. >> Punctuation is very different from highlighting, IMHO. That said, I >> find punctuation very effective at being small and discrete, clearly not >> words, and easy to pick out. Color cues are not nearly as good at being >> inobtrusive but automatically parsed. > Well that surely depends on the colour scheme you have. Only partially. The big thing, I think, is that punctuation is separate things next to words, not attributes of words. Come to think of it, that may be why I sometimes like to see keywords and other times punctuation. I like {} better than do/end, for the same reason I prefer parentheticals in English to something like: And this is a digression contrived end digression example. I much prefer: And this is a (contrived) example. > To my eyes, the feature of syntax highlighting that alone makes it > worthwhile, its killer feature, is that I can set comments and docstrings > to grey. When I'm scanning code, being able to slide my eyes over greyed- > out comments and docstrings and ignore them with essentially zero effort > is a huge help. That's the thing I most miss, more than anything else, > when using a dumb editor. That makes some sense. In sh/python/Ruby/lua, I don't have any troubles with it because the comment mechanism is fairly unambiguous. I'm fine in C as long as people remember the * on the left hand side of long comments. Omit that, and I get fussy. :) > Just because nobody has done it yet doesn't mean that some sufficiently > intelligent software in the future couldn't do it :) True. It raises a curious question. Imagine that you had the option of having color highlighting to show precedence and/or grouping in complicated expressions. Would that be better or worse than parentheses? For instance, consider the classic: x + y * z In many programming languages, this is equivalent to: x + (y * z) But would it be clearer to just have the unpunctuated text, with the "y * z" in, say, a slightly lighter or darker shade? I don't *think* so, but I'm honestly not totally sure. -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 contact at xavierho.com Mon Sep 20 03:13:33 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 17:13:33 +1000 Subject: programming In-Reply-To: References: Message-ID: Thanks Jordan. My reply will be in Blue. I apologise if this ever gets hard to read, but it's beginning to. On 20 September 2010 16:51, Jordan Blanton wrote: > "And so he started on a module that estimated the length of a sine wave. > Here is what he wrote: " > ok. what is a module? A Python module is a .py file. Nothing more. > Create a *project0* directory off of your *cs150* directory and move into > *project0*. > > Name your main python file *stopping.py*. Provide one more file named * > support.py* Dr. Lusth's code should go into the *support.py* file. The > main function in *stopping.py* should call a function that prompts the > user of your program for the following information, in the order given. > > - amplitude of the sine wave (in feet) > - period of the sine wave (in feet) > - distance to the stop sign (in feet) > - distance needed to stop without using hand brakes (in feet) > > Ok. is there a difference between my main file and the "one more file"? Yeah, they are two different files. > Do I create these by going into the project0 directory and typing "touch > support.py" and "touch stopping.py"? Well, I generally just open up a text editor and save it as (for example) support.py. If you're on Linux, gedit will do the trick. They're just plain text files. > What does is mean when is says that the main function in stopping.py should > *call* a function that prompts the user of your program......? > It means the main function in stopping.py should ask for user input in the terminal. In other words, your program need to be able to read from console input (stdin in C, or use the input() function in Python) and save them for calculation. > "Your main function should call at least one of the functions in the > support file. You will need to import these functions into your main program > by placing this line at the top of *stopping.py*. > Also, your *stopping.py* file should have two function definitions in it, > the definition of *main* and the definition of a function that obtains > information from the user. " > ok. how do i import functions into my main program? what exactly is my main > program? stopping.py? and how do i define my main program? > Ironically, Python doesn't have a "main" function. But it's a generally accepted practice that you would define something like this: def main(): # Do something here if __name__ == '__main__': main() The first bit is the main function definition, in which you should program what it is supposed to do. The second bit tells Python to run main() when the module is run directly (like calling "python stopping.py" without the quotes to run your program in the terminal.) > > Here is part of what is given in the directions: These are codes > provided... > > import math > # > # A module for approximating the length of the path traced out > > # by a sine wave. > # > # written by John C. Lusth > # > > # > # compute the length of the wavy line traced out by a sine wave > > # via approximation. The value of 'step' controls the accuracy of > # the approximation > > > # > > def sineLength(amplitude,period,xDistance,step): > x = 0.0 > total = 0.0 > lastx = 0 > lasty = 0 > > while x <= xDistance + (step / 2): > y = amplitude * math.sin(2 * math.pi / period * x) > > > d = distance(lastx,lasty,x,y) > #print(" distance from (",lastx,",",lasty,") to (",x,",",y,") is",d) > > total = total + d > lastx = x > > > lasty = y > x = x + step > return total > > # > # compute the distance between point (a,b) and point (b,c) > # > > def distance(a,b,c,d): > > return > > What do all the #'s mean? > > You really should start by doing some Python tutorials. How to Think Like a Computer Scientistis a good one. I'm not sure if you're prepared enough to do this project on your own. In short, # is a commet in the file. Same as // in C or Java, if you have done them before. They're ignored by the compiler, so you can put notes in there. > Why are all the values set at 0? > > Because that's how you initialise (and declare) variables in Python. This way, you can use them later. The initial value in your case is not very relevant, except for the total. > What should follow "return" at the very end? > > The function calculates the distance between Point (a, b) and Point (c, d). I think that's a typo in the comment for that function. Besides, it should have been a proper doc comment. Tell your instructor to code like Python, not like C. You'll want something like: def distance(a, b, c, d): '''Returns the distance between point(a, b) and point(c, d).''' # Use Pythagorean Theoremhere # return the distance you calculated ' Note how I commented the function. This is the standard Python convention, and you can later on use help(distance) to extract that documentation if needed. Seriously, though, do yourself a favour and do some Python tutorial first. You seem pretty new to Python. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From goran.novosel at gmail.com Mon Sep 20 03:23:48 2010 From: goran.novosel at gmail.com (Goran Novosel) Date: Mon, 20 Sep 2010 00:23:48 -0700 (PDT) Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <4C966BFC.3070806@v.loewis.de> Message-ID: <8910136c-04f0-4d65-9b52-82318c83ccd3@k11g2000vbf.googlegroups.com> Can't believe I missed something as simple as u'smt', and I even saw that on many occasions... Thank you. From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 03:27:25 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 09:27:25 +0200 Subject: newbie: class and __dict__ variable. In-Reply-To: References: Message-ID: <4c970cdd$0$21775$426a74cc@news.free.fr> Terry Reedy a ?crit : > On 9/19/2010 1:37 PM, mafeusek at gmail.com wrote: >> >> Hallo Group Members. From time to time I see in python code following >> notation that (as I believe) extends namespace of MyClass. > > No, it does not affect MyClass, just the instance dict. > >> class MyClass: >> def __init__(self): >> self.__dict__["maci"]=45 > > Have you seen exactly this usage? > >> >> myCl2 = MyClass2() >> print myCl2.maci >> >> >> I am guessing that there must be some difference between the one above >> and the one below, because otherwise no one would probably use the one >> above. Do YOu know that difference? >> >> class MyClass2: >> def __init__(self): >> self.maci=45 > > If the class has a .__setattr__ method, the first bypasses that method, It also bypasses object.__setattribute__ and - as a consequence - any binding descriptor by the same name as the attribute being set. >> myCl = MyClass() >> print myCl.maci > From contact at xavierho.com Mon Sep 20 03:29:30 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 17:29:30 +1000 Subject: programming In-Reply-To: References: Message-ID: Okay, it looks like you're doing well. I'm just going through your second email now, and it seems many of my comments in the first email is irrelavent to you anymore, because you already knew how to do it. =] Let's have a look. Again, my reply is in Blue. . *And what I've attempted to do so far.... *so far, i have gone into the cs150 directory as instructed and created a project0 directory. in that directory i typed in touch support.py and touch stopping.py to create the support and stopping files. is that correct so far? then i typed in vim support.py to edit the support.py file. I believe in vim you can save your file, too, anyway, so the touch part is probably unnecessary, but won't hurt. def distance(a,b,c,d): return sqrt(a**2+b**2), sqrt(c**2+d**2) That won't do. You're returning the distance between the origin and (a, b), and another distance between the origin and (c, d). Think about this again. If I understand this correctly, you should be only returning one value (not two, which is what you're doing now), that is the distance between (a, b) and (c, d). from support import* from support import * Note the space before *. It makes things more pleasant, even when your version compiles. def main(): def getinfo(): amplitude=eval(input(" Amplitude of the sine wave (in feet): ")) period=eval(input("Period of the sine wave (in feet): ")) xDistance=eval(input("Distance to the stop sign (in feet): ")) distance2=eval(input("Distance needed to stop without using brakes (in feet): ")) return amplitude,period,xDistance,distance2 amplitude,period,xDistance,distance2=getinfo() s=sineLength(amplitude,period,xDistance,1) print(xDistance,distance2,s) I'm almost 100% certain your instructor wanted you to have getinfo() outside of main(). It's valid to have a function inside a function, but there's not much point to it. Secondly, that doesn't even compile. Nor does xDistance=eval(input("Distance to the stop sign (in feet): ")) by itself. Without going into how slobby the use of eval() is in your case, you can fix it and make it syntax-legal by adding another quotes around your input function. xDistance = eval('input("Distance to the stop sign (in feet): ")') main() It's okay to run your main() method that way, as long as you're sure stopping.py isn't going to be imported by anyone else. I realize this is probably elementary, but I've never done anything like this, and kind of got thrown into it. It's very much a teach-yourself-course, so I guess if you don't really understand the lingo, it's easy to fall behind. You're doing well as far as I can tell. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From contact at xavierho.com Mon Sep 20 03:32:49 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 17:32:49 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 17:29, Xavier Ho wrote: > Secondly, that doesn't even compile. Nor does > > xDistance=eval(input("Distance to the stop sign (in feet): ")) > Just correcting myself here. It compiles, but generates an error when you give it a number, which still fails. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Mon Sep 20 03:33:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 19:33:45 +1200 Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: In message , Alex Willmer wrote: > On Sep 19, 12:20 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message >> , Alex >> >> Willmer wrote: >> > # NB Constants are by convention ALL_CAPS >> >> SAYS_WHO? > > Says PEP 8: > > Constants > > Constants are usually declared on a module level and written in all > capital letters with underscores separating words. Examples include > MAX_OVERFLOW and TOTAL. > > -- http://www.python.org/dev/peps/pep-0008/ WHAT_IF_SOMETHING_IS_INITIALLY_CONSTANT,_BUT_LATER_BECOMES_A_CONFIG_VARIABLE,_OR_VICE_VERSA,_DOES_IT_NEED_TO_CHANGE_ITS_NAME? From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 03:34:23 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 09:34:23 +0200 Subject: Learning inheritance In-Reply-To: References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> Message-ID: <4c970e7f$0$21775$426a74cc@news.free.fr> alex23 a ?crit : > > Python only actually executes a module the first time it's imported, Beware of multithreading and modules imported under different names... There can be issues with both in some web frameowrks. From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 03:39:14 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 09:39:14 +0200 Subject: Learning inheritance In-Reply-To: <8632bf75-3963-4e85-99f3-684dcde99589@i17g2000vbq.googlegroups.com> References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> <8632bf75-3963-4e85-99f3-684dcde99589@i17g2000vbq.googlegroups.com> Message-ID: <4c970fa2$0$7946$426a74cc@news.free.fr> Niklasro a ?crit : > Good to learn what I'm doing :-) since important being able to explain > choices taken farther than "doing it because it works". > I understand the concept of modules may not correspond to java > programming where I come from. Coming from Java - and specially if you only have experience with Java -, you'll have to unlearn quite a few things. Python is 100% object - in that everything you can bind to a name is an object, including classes, functions, methods, and even modules - but it doesn't try to force you into using classes when you don't need them. From zooko at zooko.com Mon Sep 20 03:49:34 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Mon, 20 Sep 2010 01:49:34 -0600 Subject: announcing pycryptopp-0.5.20 Message-ID: Folks: pycryptopp is a Python crypto library, so it could be considered an alternative to PyCrypto. However, pycryptopp offers very few algorithms. In fact, it only offers RSA, AES, and SHA-256. So if that's all you need, then great. I just released a new version of pycryptopp. http://tahoe-lafs.org/trac/pycryptopp 2010-09-18 -- pycryptopp v0.5.20 The following things are new in this release: * fix bugs in assembly implementation of SHA-256 from Crypto++ * fix it to compile on *BSD (#39) * improve doc strings * add a quick start-up-self-test of SHA256 (#43) * execute the quick start-up-self-tests of AES and SHA256 on module import Regards, Zooko From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 03:58:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 07:58:09 GMT Subject: Back on topic [was [OT] Syntax highlighting] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> <4c96ff65$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c971411$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 07:02:23 +0000, Seebs wrote: > I'm > very new to Python, so I'm not 100% sure functions are a kind of an > object, but I seem to recall they were. Yes, functions are objects. *Everything* in Python is an object (apart from statements, but they're not actually *things* in Python). >>> def f(): ... return f.x ... >>> f.x = 2 >>> f() 2 >>> f.x = -1 >>> f() -1 For some interesting glimpse at how Python works, create a function f and then look at dir(f). -- Steven From gh at gregor-horvath.com Mon Sep 20 04:45:46 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Mon, 20 Sep 2010 10:45:46 +0200 Subject: Encode HTML CDATA name token Message-ID: <20100920104546.3699e919@valun> Hi, ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). [1] Is there a encoder / decoder in Python that can convert arbitrary text to and from this encoding in an readable manner? base64 is not readable: In [31]: base64.encodestring("/TEST") Out[31]: 'L1RFU1Q=\n' quopri does not encode for example "/". In [25]: quopri.encodestring("/test") Out[25]: '/test' Anything else? -- Greg [1] http://www.w3.org/TR/html4/types.html#type-cdata From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 04:50:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 08:50:46 GMT Subject: newbie: class and __dict__ variable. References: <4c970cdd$0$21775$426a74cc@news.free.fr> Message-ID: <4c972065$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 09:27:25 +0200, Bruno Desthuilliers wrote: >> If the class has a .__setattr__ method, the first bypasses that method, > > It also bypasses object.__setattribute__ and - as a consequence - any > binding descriptor by the same name as the attribute being set. __setattribute__ ? >>> object.__setattribute__ Traceback (most recent call last): File "", line 1, in AttributeError: type object 'object' has no attribute '__setattribute__' -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 04:52:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 08:52:19 GMT Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: <4c9720c3$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 19:33:45 +1200, Lawrence D'Oliveiro wrote: > WHAT_IF_SOMETHING_IS_INITIALLY_CONSTANT,_BUT_LATER_BECOMES_A > _CONFIG_VARIABLE,_OR_VICE_VERSA,_DOES_IT_NEED_TO_CHANGE_ITS_NAME? If you want to be compliant with PEP 8, then yes. -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 05:02:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 09:02:40 GMT Subject: Encode HTML CDATA name token References: <20100920104546.3699e919@valun> Message-ID: <4c972330$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 10:45:46 +0200, Gregor Horvath wrote: > Hi, > > ID and NAME tokens must begin with a letter ([A-Za-z]) and may be > followed by any number of letters, digits ([0-9]), hyphens ("-"), > underscores ("_"), colons (":"), and periods ("."). [1] > > Is there a encoder / decoder in Python that can convert arbitrary text > to and from this encoding in an readable manner? What is "this encoding" called? The article you link to describes a specification, not an encoding. What makes you think that you should be able to convert arbitrary text to strings suitable for use as ID or NAME tokens? What would you expect this encoding to do with these strings? "1234" "?*(#@!+{})" " " -- Steven From rihad at mail.ru Mon Sep 20 05:10:06 2010 From: rihad at mail.ru (rihad) Date: Mon, 20 Sep 2010 02:10:06 -0700 (PDT) Subject: Is "python -W ignore" the default? Message-ID: $ mkdir foo $ python Python 2.7 (r27:82500, Sep 1 2010, 22:10:47) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 Type "help", "copyright", "credits" or "license" for more information. >>> dir() ['__builtins__', '__doc__', '__name__', '__package__'] >>> import foo Traceback (most recent call last): File "", line 1, in ImportError: No module named foo >>> dir() ['__builtins__', '__doc__', '__name__', '__package__', '__warningregistry__'] >>> __warningregistry__.items() [(("Not importing directory 'foo': missing __init__.py", , 1), True)] >>> $ (...went to read some "man python"...) $ python -W default Python 2.7 (r27:82500, Sep 1 2010, 22:10:47) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 Type "help", "copyright", "credits" or "license" for more information. >>> import foo __main__:1: ImportWarning: Not importing directory 'foo': missing __init__.py Traceback (most recent call last): File "", line 1, in ImportError: No module named foo >>> $ The problem isn't easily spotted unless run with -W default. How come "default" is not on by default? :) From ldo at geek-central.gen.new_zealand Mon Sep 20 05:33:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 21:33:47 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: In message , Philip Semanchuk wrote: > Some email systems still insert hard line breaks around the 72 or 80 > column mark and as a result long URLs get broken. That?s why content transfer encodings (quoted-printable, base64) are a standard part of MIME. From dotancohen at gmail.com Mon Sep 20 05:35:03 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Mon, 20 Sep 2010 11:35:03 +0200 Subject: Python and unicode In-Reply-To: <4c96d826$0$11113$c3e8da3@news.astraweb.com> References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> <4c96d826$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Mon, Sep 20, 2010 at 05:42, Steven D'Aprano wrote: >> Use the PEP 263 encoding >> declaration to let Python >> know the encoding of the program source file. > > While PEPs are valuable, once accepted or rejected they become historical > documents. They don't necessarily document the current behaviour of the > language. > > See here for documentation on encoding declarations: > > http://docs.python.org/reference/lexical_analysis.html#encoding-declarations > > This is the first time that I've read the PEP document regarding Unicode / UTF-8. I see that it mentions that the declaration must be on the second or first line of the file. Is this still true in Python 3? I have been putting it further down (still before all python code, but after some comments) in code that I write (for my own use, not commercial code). -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ldo at geek-central.gen.new_zealand Mon Sep 20 05:36:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 21:36:46 +1200 Subject: Encode HTML CDATA name token References: <20100920104546.3699e919@valun> Message-ID: In message <20100920104546.3699e919 at valun>, Gregor Horvath wrote: > Is there a encoder / decoder in Python that can convert arbitrary text > to and from this encoding in an readable manner? Not sure if this is already in Python, but . From usernet at ilthio.net Mon Sep 20 05:48:41 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 09:48:41 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Seebs wrote: > On 2010-09-20, Tim Harig wrote: >> 1. Don't bother to manually paste when you can use something like urlview >> to lauch directly. > > I don't know that this would actually be better than what I currently do, > which is grab text and middle-click in another window. I don't know. Personally, I almost never use a mouse, so if I take my hands off of my keyboard, it really annoys me. >> If you want this behavior by default, you can easily wrap urlview >> to automatically add the prefix. > > True, but since my news reading is not on the machine my web browser is > on, it seems like it might get annoying. You could simply place the filter in slrn; then, any urls that you see in your reader would already be shown with the preview prefix suitable for cut and paste mechanisms. If you wanted, you can even have your script download the preview and automatically convert it back to the full origional URL. >> I question first whether most tinyurl links are really of such an >> intransient nature that they need to be long lasting. I personally use >> them most when writing paper notes. They only need to last long enough >> for me, or whoever I made the note for, to get back to them. > > By default, I assume that Usenet posts are for the longer term, and a > Usenet post which relies for its content on tinyurl is thus somewhat > more vulnerable than one which doesn't. In particular, consider things > like archive.org; they may well be able to find a long-dead web page, > but not a long-dead tinyurl link. I assume just the opposite. Once the post has been removed from the server, it is gone to me. I am not fond of the various archives that are otherwise available on the web. Those who should be using them never do and when I searching for the answer to a serious problem, I find myself inundated with thousands of posts that never would have been asked had the poster simply RTFM from mailing lists, web forums, and usernet that are difficult to filter out because they happen to contain the same basic subject matter that I am looking for. Google is particulary bad about this. Often the top posts have high ranks because they have been around so long that they are considered the definitive source; however the information in them is no longer accurate or even relevant. No, I tend to think is is much better that posts simply expire by their use by date. >> But why should the rest of us be penalized because you make the choice >> not to use (or not take full advantage of) all of the tools that are >> available to you? > > For about the same reason that I should be penalized because someone else > wanted things done differently. Which is to say, it's a tradeoff, the > right choice to make depends on what your goals are. If you want a > piece of information to have maximal longevity, something like tinyurl > is probably a bad way to transmit it. If you want something small that > survives line wrapping, it's probably a good way. I don't personally any problem with either mechanism -- especially in usernet where I have full control over how my client displays posts. Other media are less flexible. Nevertheless, I do have a problem with the constant nagging sentiment that tinyurl and kin are totally immoral to use. If this was something that was forced upon you, then I might have some sympathy; however, I see it as the poster's right to do what he thinks will make his post more effective. If that turns out to by tinyurl, then so be it. If you don't like tinyurls then you are free to filter them out in your newsreader or simply ignore the post. From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 05:51:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 11:51:53 +0200 Subject: newbie: class and __dict__ variable. In-Reply-To: <4c972065$0$11113$c3e8da3@news.astraweb.com> References: <4c970cdd$0$21775$426a74cc@news.free.fr> <4c972065$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c972eb9$0$12598$426a34cc@news.free.fr> Steven D'Aprano a ?crit : > On Mon, 20 Sep 2010 09:27:25 +0200, Bruno Desthuilliers wrote: > >>> If the class has a .__setattr__ method, the first bypasses that method, >> It also bypasses object.__setattribute__ and - as a consequence - any >> binding descriptor by the same name as the attribute being set. > > __setattribute__ ? > > >>>> object.__setattribute__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: type object 'object' has no attribute '__setattribute__' > Duh... Brain fart, sorry, shouldn't post before I get my dose of coffee :( Let's do it again: Terry Reedy a ?crit : > If the class has a .__setattr__ method, the first bypasses that > method, All new-style classes have a __setattr__ method - whether inherited from object or overridden. object.__setattr__ implements the support for binding descriptors, so bypassing it will also bypass all binding descriptors. The right way to avoid infinite recursion when overriding __setattr__ is to call on the superclass __setattr__, unless of course you *really* know what you're doing... class BarDescriptor(object): def __init__(self): self.val = None def __set__(self, instance, value): print "stores value elsewhere and trigger some required behaviour" self.val = value * 2 def __get__(self, instance, cls=None): if instance is None: return self print "retrieve value from elsewhere and trigger some required behaviour" return self.val # well behaved class Foo(object): bar = BarDescriptor() def __init__(self): self.bar = 42 def __setattr__(self, name, value): print "override __setattr_ for some reason" super(Foo, self).__setattr__(name, value) # ugly mess class Baaz(Foo): bar = BarDescriptor() def __init__(self): self.__dict__['bar'] = 42 def __setattr__(self, name, value): print "override __setattr_ for some reason" self.__dict__[name] == value >>> f = Foo() override __setattr_ for some reason stores value elsewhere and trigger some required behaviour >>> f.bar retrieve value from elsewhere and trigger some required behaviour 84 >>> f.__dict__ {} >>> f.bar = 33 override __setattr_ for some reason stores value elsewhere and trigger some required behaviour >>> f.bar retrieve value from elsewhere and trigger some required behaviour 66 >>> f.__dict__ {} >>> b = Baaz() >>> b.__dict__ {'bar': 42} >>> b.bar retrieve value from elsewhere and trigger some required behaviour >>> b.bar = 33 override __setattr_ for some reason >>> b.bar retrieve value from elsewhere and trigger some required behaviour >>> b.__dict__ {'bar': 42} >>> From usernet at ilthio.net Mon Sep 20 05:59:20 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 09:59:20 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Steven D'Aprano wrote: > On Mon, 20 Sep 2010 05:46:38 +0000, Tim Harig wrote: > >>> I'm not particularly convinced that these are *significant* complaints >>> about URL-shorteners. But I will say, of the last couple hundred links >>> I've followed from Usenet posts, precisely zero of them were through >>> URL redirectors. If I can't at least look at the URL to get some >>> initial impression of what it's a link to, I'm not going to the trouble >>> of swapping to a web browser to find out. >> >> But why should the rest of us be penalized because you make the choice >> not to use (or not take full advantage of) all of the tools that are >> available to you? > > I'm with Aahz... best practice is to post both the full and shortened > URL, unless the URL is less that 78 characters, in which case just post > the full version. Posting two URLs rather defeats the purpose of using a URL shortening service in the first place; but, if that is what you feel is effective, then by all means, do so. You are the master of your posts and you have the right to post them using whatever methods and formating that you feel is most effect; but, other people should have the same priviledge. Many people find tinyurl and kin to be useful tools. If you do not, then are free to rewrite them in your reader, ignore posts using these services, or even add a rule blocking them to your score/kill file so that you do not have to view their ugliness. From usernet at ilthio.net Mon Sep 20 06:01:07 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 10:01:07 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Tim Harig wrote: > On 2010-09-20, Seebs wrote: >> On 2010-09-20, Tim Harig wrote: >>> If you want this behavior by default, you can easily wrap urlview >>> to automatically add the prefix. >> >> True, but since my news reading is not on the machine my web browser is >> on, it seems like it might get annoying. > > You could simply place the filter in slrn; then, any urls that you see in > your reader would already be shown with the preview prefix suitable for cut > and paste mechanisms. If you wanted, you can even have your script > download the preview and automatically convert it back to the full > origional URL. I should add that there are browser extensions that do just this. From __peter__ at web.de Mon Sep 20 06:20:34 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 20 Sep 2010 12:20:34 +0200 Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> <4c96d826$0$11113$c3e8da3@news.astraweb.com> Message-ID: Dotan Cohen wrote: > On Mon, Sep 20, 2010 at 05:42, Steven D'Aprano > wrote: >>> Use the PEP 263 encoding >>> declaration to let Python >>> know the encoding of the program source file. >> >> While PEPs are valuable, once accepted or rejected they become historical >> documents. They don't necessarily document the current behaviour of the >> language. >> >> See here for documentation on encoding declarations: >> >> http://docs.python.org/reference/lexical_analysis.html#encoding- declarations >> >> > > This is the first time that I've read the PEP document regarding > Unicode / UTF-8. I see that it mentions that the declaration must be > on the second or first line of the file. Is this still true in Python > 3? Yes > I have been putting it further down (still before all python code, > but after some comments) in code that I write (for my own use, not > commercial code). It may work by accident, if you declare it as UTF-8, because that is also the default in Python 3. Peter From gh at gregor-horvath.com Mon Sep 20 06:37:48 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Mon, 20 Sep 2010 12:37:48 +0200 Subject: Encode HTML CDATA name token References: <20100920104546.3699e919@valun> Message-ID: <20100920123748.6f3a5264@valun> Am Mon, 20 Sep 2010 21:36:46 +1200 schrieb Lawrence D'Oliveiro : > In message <20100920104546.3699e919 at valun>, Gregor Horvath wrote: > > > Is there a encoder / decoder in Python that can convert arbitrary > > text to and from this encoding in an readable manner? > > Not sure if this is already in Python, but > . Thanks for the suggestion. Yes it is in Python: base64.b32encode 2 Problems: a) "=" is used as padding char b) The special case of a base32 encoding with a leading digit is not handled. c) It's not readbale But I can easly work around this. Thanks. -- Greg From dotancohen at gmail.com Mon Sep 20 06:57:35 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Mon, 20 Sep 2010 12:57:35 +0200 Subject: Python and unicode In-Reply-To: References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> <4c96d826$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Mon, Sep 20, 2010 at 12:20, Peter Otten <__peter__ at web.de> wrote: > It may work by accident, if you declare it as UTF-8, because that is also > the default in Python 3. > That does seem to be the case. Thank you for the enlightenment and information. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 07:11:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 11:11:51 GMT Subject: Overriding dict constructor Message-ID: <4c974177$0$11113$c3e8da3@news.astraweb.com> I have a dict subclass that associates extra data with each value of the key/value items: class MyDict(dict): def __setitem__(self, key, value): super(MyDict, self).__setitem__(key, (value, "extra_data")) def __getitem__(self, key): return super(MyDict, self).__getitem__(key)[0] # plus extra methods This works fine for item access, updates, etc: >>> d = MyDict() >>> d[0] = 'a'; d[1] = 'b' >>> d[1] 'b' But if I try to create a regular dict from this, dict() doesn't call my __getitem__ method: >>> dict(d) {0: ('a', 'extra_data'), 1: ('b', 'extra_data')} instead of {0: 'a', 1: 'b'} as I expected. How can I fix this? -- Steven From yoavglazner at gmail.com Mon Sep 20 07:17:53 2010 From: yoavglazner at gmail.com (Glazner) Date: Mon, 20 Sep 2010 04:17:53 -0700 (PDT) Subject: Python Monitoring Message-ID: <4d1cbff7-af15-4ec8-bb24-0cbd616ca594@q9g2000vbd.googlegroups.com> Hi, I'm will be writing a distributed program with parallel python and i would like to if there are any good monitoring utilities for python. I would like each remote server to post messages and to see the messages in a web-broweser or such. I googled python monitoring and found pymon but it seems a bit outdated. any tips will be great! Many Thanks, Yoav Glazner From dirknbr at gmail.com Mon Sep 20 07:36:42 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Mon, 20 Sep 2010 04:36:42 -0700 (PDT) Subject: Numpy on 2.7 Message-ID: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> I am trying to install Numpy on Python 2.7 but it only looks for 2.6 folder, how can I change that? Dirk From duncan.booth at invalid.invalid Mon Sep 20 07:53:48 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Sep 2010 11:53:48 GMT Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I have a dict subclass that associates extra data with each value of the > key/value items: > > class MyDict(dict): > def __setitem__(self, key, value): > super(MyDict, self).__setitem__(key, (value, "extra_data")) > def __getitem__(self, key): > return super(MyDict, self).__getitem__(key)[0] > # plus extra methods > > > This works fine for item access, updates, etc: > >>>> d = MyDict() >>>> d[0] = 'a'; d[1] = 'b' >>>> d[1] > 'b' > > > But if I try to create a regular dict from this, dict() doesn't call my > __getitem__ method: > >>>> dict(d) > {0: ('a', 'extra_data'), 1: ('b', 'extra_data')} > > > instead of {0: 'a', 1: 'b'} as I expected. > > How can I fix this? > > I was going to suggest overriding items() (or iteritems() for Python 2.x), but while that is another hole that your values leak out it isn't the hole used by the dict constructor. It might be simpler to duck the issue entirely and store the extra data in another dict alongside the main one: class MyDict(dict): def __init__(self, *args, **kw): self._extra = {} super(MyDict, self).__init__(*args, **kw) for k in self: self._extra[k] = "extra_data" def __setitem__(self, key, value): super(MyDict, self).__setitem__(key, value) self._extra[key] = "extra_data" # plus extra methods then you only have to worry about catching all the mutators but not the accessors. -- Duncan Booth http://kupuguy.blogspot.com From john at castleamber.com Mon Sep 20 08:00:09 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 07:00:09 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: <878w2wsjzq.fsf@castleamber.com> Tim Harig writes: > I question first whether most tinyurl links are really of such an > intransient nature that they need to be long lasting. I personally use > them most when writing paper notes. They only need to last long enough > for me, or whoever I made the note for, to get back to them. As an additional note: tinyurl allows one to enter a postfix to use, so instead of /xc4ax7 you can have /something-more-readable. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From lists at cheimes.de Mon Sep 20 08:00:58 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 20 Sep 2010 14:00:58 +0200 Subject: Overriding dict constructor In-Reply-To: <4c974177$0$11113$c3e8da3@news.astraweb.com> References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: Am 20.09.2010 13:11, schrieb Steven D'Aprano: > I have a dict subclass that associates extra data with each value of the > key/value items: [...] > How can I fix this? Since the dict class is crucial to the overall performance of Python, the dict class behaves bit different than other classes. I don't know if this is documented somewhere. Dict methods call the PyDict_GetItem function directly instead of going through the type's struct. You have two options to get the desired behavior. Either implement all functions that call the methods you want to overwrite, or subclass from something like DictMixin or the appropriate ABC. Christian From john at castleamber.com Mon Sep 20 08:04:47 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 07:04:47 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> <87vd613t0p.fsf@castleamber.com> Message-ID: <874odksjs0.fsf@castleamber.com> Seebs writes: > On 2010-09-20, John Bokma wrote: >> I didn't mean that there are spoilers in the first 70 pages, just that >> to me the excercise would spoil the book, so, I wouldn't do it. I >> consider a book like a meal, I wouldn't gobble down food, regurgitate >> it, and eat it again at a slower pace. Books, movies, family, walks are >> the things I prefer to do at a normal mudane pace, or even slower, if I >> can bring myself to it. My favourite books I try to read slow, and >> enjoy. ;-). Too much of my life is already in overdrive. > > Now that you explain it like this, that makes a fair bit of sense. I > often wonder whether reading slowly would be more pleasant. I have no > idea how to do it, so the question remains theoretical. By practicing ;-). I have it worse with movies, but in my case, for several reasons, it's really important (to me) that I watch the movie at it's normal pace and try to enjoy it at that speed. Talking about reading: if you have any suggestions, feel free to email me (since this is already way off topic). I read mostly in my second language, English, and live in a country where English books are hard to find, so browsing in bookshops is not much of an option :-(. And most of my (online) friends don't read much, if at all. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 08:15:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 12:15:02 GMT Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c975046$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 11:53:48 +0000, Duncan Booth wrote: > I was going to suggest overriding items() (or iteritems() for Python > 2.x), but while that is another hole that your values leak out it isn't > the hole used by the dict constructor. Yes, I already override items(), keys(), values(), their iter... versions, and just about every damn method that dicts have :/ I suspect that the dict() constructor is just grabbing the key/value pairs directly from the underlying hash table. If that's the case, my choices are to not inherit from dict at all, or take your suggestion and keep an auxiliary dict alongside the main one. -- Steven From john at castleamber.com Mon Sep 20 08:31:05 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 07:31:05 -0500 Subject: [OT] Speed-reading References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> <4c96fe8b$0$11113$c3e8da3@news.astraweb.com> Message-ID: <87wrqgr3zq.fsf@castleamber.com> Steven D'Aprano writes: > spelling or grammatical errors and clumsy writing. *Especially* the > spelling errors, they have about the same effect on her reading speed as > a tree trunk lying across a Formula 1 race track. Spelling errors are a disaster, somehow they stand out like they use Comic Sans Bold and red ink. Most likely because they break the pattern. I seem to find them more and more often in the books I read, maybe because I use English (my second language) more and more. As for speed reading, there are many levels to do this: one can call scanning a page really fast left-right, moving as fast to the bottom as possible speed-reading, or reading each and every sentence just as fast as possible speed reading. The faster one goes, the more is lost. The total # of pages in Harry Potter seems to be just over 4000 [1]. If an afternoon is 4 hrs, this means 1000 pages an hour, or 17 pages/minute. One has to do skimming to read that fast. With 250 words/page the reading speed would be over 4K words/minute, which would make your wife a serious competitor for Anna Jones (4.7K words/minute, 67% comprehension, see [2]) In my native language I read just above 1 page a minute, if the pages are not too dense I can do sometimes 2. In English I can often get close to 1 page a minute, except with books that are quite dense (think fantasy). So I guess around 300-350 wpm in Dutch, 250 wpm in English (normal pace). [1] http://wiki.answers.com/Q/What_is_the_total_number_of_pages_in_the_%27Harry_Potter%27_series [2] http://en.wikipedia.org/wiki/Speed_reading#Claims_of_speed_readers -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From pekka.niiranen at pp5.inet.fi Mon Sep 20 08:46:34 2010 From: pekka.niiranen at pp5.inet.fi (Pekka Niiranen) Date: Mon, 20 Sep 2010 15:46:34 +0300 Subject: Numpy on 2.7 In-Reply-To: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> References: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> Message-ID: On 9/20/10 2:36 PM, Dirk Nachbar wrote: > I am trying to install Numpy on Python 2.7 but it only looks for 2.6 > folder, how can I change that? > > Dirk http://sourceforge.net/projects/numpy/files/NumPy/1.5.0/numpy-1.5.0-win32-superpack-python2.7.exe/download From ian at ianhobson.co.uk Mon Sep 20 09:00:19 2010 From: ian at ianhobson.co.uk (Ian Hobson) Date: Mon, 20 Sep 2010 14:00:19 +0100 Subject: Encoding problem - or bug in couchdb-0.8-py2.7.egg?? Message-ID: <4C975AE3.6070703@ianhobson.co.uk> Hi all, I have hit a problem and I don't know enough about python to diagnose things further. Trying to use couchDB from Python. This script:- # coding=utf8 import couchdb from couchdb.client import Server server = Server() dbName = 'python-tests' try: db = server.create(dbName) except couchdb.PreconditionFailed: del server[dbName] db = server.create(dbName) doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) Gives this traceback:- D:\work\C-U-B>python tes1.py Traceback (most recent call last): File "tes1.py", line 11, in doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\client.py", line 407, in save _, _, data = func(body=doc, **options) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", line 399, in post_json status, headers, data = self.post(*a, **k) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", line 381, in post **params) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", line 419, in _request credentials=self.credentials) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", line 310, in request raise ServerError((status, error)) couchdb.http.ServerError: (400, ('bad_request', 'invalid UTF-8 JSON')) D:\work\C-U-B> Why? I've tried adding u to the strings, and removing the # coding line, and I still get the same error. Thanks for any help. Ian From oswald.harry at gmail.com Mon Sep 20 10:02:27 2010 From: oswald.harry at gmail.com (harryos) Date: Mon, 20 Sep 2010 07:02:27 -0700 (PDT) Subject: elementwise multiplication of 2 lists of numbers Message-ID: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> hi I have 2 lists of numbers,say x=[2,4,3,1] y=[5,9,10,6] I need to create another list containing z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] I did not want to use numpy or any Array types.I tried to implement this in python .I tried the following z=[] for a,b in zip(x,y): z.append(a*b) This gives me the correct result.Still,Is this the correct way? Or can this be done in a better way? Any pointers most welcome, harry From hniksic at xemacs.org Mon Sep 20 10:15:22 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 20 Sep 2010 16:15:22 +0200 Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: <87ocbsbix1.fsf@xemacs.org> Christian Heimes writes: > Am 20.09.2010 13:11, schrieb Steven D'Aprano: >> I have a dict subclass that associates extra data with each value of the >> key/value items: > [...] >> How can I fix this? > > Since the dict class is crucial to the overall performance of Python, > the dict class behaves bit different than other classes. I don't know if > this is documented somewhere. Dict methods call the PyDict_GetItem > function directly instead of going through the type's struct. Normally where this kind of optimization is necessary Python is careful to use PyFoo_CheckExact to find out if it is dealing with an instance of the class or a subclass, and only goes through the fast path for the former case. That PyDict_Merge (called by dict_init) doesn't do this could be considered a bug because it constrains dict subclass in a way that is hard to work around, and without a clear gain in performance compared to using an exact check. dict_fromkeys is an example in the same file that uses PyDict_CheckExact. From hunguponcontent at gmail.com Mon Sep 20 10:16:56 2010 From: hunguponcontent at gmail.com (Default User) Date: Mon, 20 Sep 2010 09:16:56 -0500 Subject: develop for Windows on GNU/Linux, using Python In-Reply-To: <8fn6ojF783U1@mid.individual.net> References: <8fn6ojF783U1@mid.individual.net> Message-ID: On Sun, Sep 19, 2010 at 14:31, J.O. Aho wrote: > Kev Dwyer wrote: > > On Sun, 19 Sep 2010 12:55:43 -0500, Default User wrote: > > > >> Consider: > >> > >> Can someone do development of programs for use on Windows systems, but > >> developed totally on a GNU/Linux system, using standard, contemporary 32 > >> and / or 64-bit PC hardware? > >> > >> This would be for someone who can not or will not use Windows, but wants > >> to create software for those who do. > >> > >> This might not include the use of VM for developing on GNU/Linux, as > >> that would seem to require a Windows installation disk, which the > >> developer may not be able or willing to obtain and use. > >> > >> Is the correct answer: > >> 1) no. > >> 2) yes. > >> 3) yes, a "Hello World" program will run just fine on the Windows Python > >> interpreter. > >> 4) other. > > > > Hello, > > > > The answer is "it depends", or 4 on your list of responses. > > > > You can write pure python on a Linux machine and it will run fine on > > Windows as long as you've taken care to program in a portable fashion. > > And not use modules not yet converted to microsoft, seems to happen from > time > to time. > > > > if you have C-extensions in > > your code you'll need to compile them over Windows. If you want to > > program against the Windows API you'll need access to a Windows box. > > You can always cross compile, not only over OS but even CPU architecture, > but > of course testing will be more difficult, on x86 based Linux you can use > wine > or similar to test, but can give you some differences to run on a native or > virtualized instance. > > > < sigh > . . . Well, that's about what I expected, unfortunately. But thanks for the honest replies. [OT] So what's the alternative -- use the end user's browser as an interpreter for JavaScript or HTML5? [/OT] -- > > //Aho > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Mon Sep 20 10:26:36 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 20 Sep 2010 07:26:36 -0700 Subject: elementwise multiplication of 2 lists of numbers In-Reply-To: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: <4C976F1C.6020008@islandtraining.com> On 09/20/2010 07:02 AM, harryos wrote: > hi > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > z.append(a*b) > This gives me the correct result.Still,Is this the correct way? > Or can this be done in a better way? > > Any pointers most welcome, > harry > List comprehension might be considered better by some, but that's a subjective judgment. (One with which I agree.) List comprehension may also be faster, but you'd have to test to know for sure. >>> x=[2,4,3,1] >>> y=[5,9,10,6] >>> z = [a*b for a,b in zip(x,y)] >>> print z [10, 36, 30, 6] Gary Herron From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 10:28:12 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 16:28:12 +0200 Subject: elementwise multiplication of 2 lists of numbers In-Reply-To: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: <4c976f7b$0$23949$426a74cc@news.free.fr> harryos a ?crit : > hi > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > z.append(a*b) > This gives me the correct result.Still,Is this the correct way? If it gives the expected results then it's at least *a* correct way !-) > Or can this be done in a better way? A list comp comes to mind, as well as using itertools.izip if your lists are a bit on the huge side. from itertools import izip z = [a * b for a, b in izip(x, y)] From giacomo.boffi at polimi.it Mon Sep 20 10:39:34 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Mon, 20 Sep 2010 16:39:34 +0200 Subject: elementwise multiplication of 2 lists of numbers References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: <86iq20fpi1.fsf@aiuole.stru.polimi.it> harryos writes: > hi > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > z.append(a*b) > This gives me the correct result.Still,Is this the correct way? > Or can this be done in a better way? what you've done is correct, rather than in better ways this can be done in different ways first, there is list comprehension >>> [x*y for x,y in zip([2,4,3,1],[5,9,10,6])] [10, 36, 30, 6] >>> if you feel that "zip" looks like an artifact, python has some functional bit >>> map(lambda x,y: x*y, [2,4,3,1],[5,9,10,6]) [10, 36, 30, 6] >>> if you feel that "lambda" looks like an artifact, >>> from operator import mul >>> map(mul, [2,4,3,1],[5,9,10,6]) [10, 36, 30, 6] >>> hth, -- > In tutti noi c'? un lato interista Lato perlopi? nascosto dalle mutande. --- Basil Fawlty, a reti unificate (IFQ+ISC) From oswald.harry at gmail.com Mon Sep 20 10:40:04 2010 From: oswald.harry at gmail.com (harryos) Date: Mon, 20 Sep 2010 07:40:04 -0700 (PDT) Subject: elementwise multiplication of 2 lists of numbers References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> <4c976f7b$0$23949$426a74cc@news.free.fr> Message-ID: <1a1339ca-5925-4b8e-a438-9f582d1d38a4@k1g2000prl.googlegroups.com> On Sep 20, 7:28?pm, Bruno wrote: >> A list comp comes to mind, as well as using itertools.izip thanks Bruno,thanks Gary.. Should have thought of list comprehension.. Thanks for the pointer about izip harry From robert.kern at gmail.com Mon Sep 20 10:58:18 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 20 Sep 2010 09:58:18 -0500 Subject: Numpy on 2.7 In-Reply-To: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> References: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> Message-ID: On 9/20/10 6:36 AM, Dirk Nachbar wrote: > I am trying to install Numpy on Python 2.7 but it only looks for 2.6 > folder, how can I change that? You should ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists -- 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 isaacrc82 at gmail.com Mon Sep 20 11:09:13 2010 From: isaacrc82 at gmail.com (Ariel) Date: Mon, 20 Sep 2010 11:09:13 -0400 Subject: How to make a web services in python ??? In-Reply-To: References: Message-ID: Soap web services I think. On Fri, Sep 17, 2010 at 5:35 PM, Hidura wrote: > What kind of web-service you have in mind???? > > 2010/9/17, Ariel : > > Hi everybody, I need some help to find documentation about how to > implements > > web services in python, could you help me please ??? > > Regards > > Thanks in advance > > Ariel > > > > -- > Enviado desde mi dispositivo m?vil > > Diego I. Hidalgo D. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From et1ssgmiller at gmail.com Mon Sep 20 11:15:00 2010 From: et1ssgmiller at gmail.com (Greg Miller) Date: Mon, 20 Sep 2010 08:15:00 -0700 (PDT) Subject: catching WM_TIMER message Message-ID: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> I'm trying to get the following code converted to Python.......and am stuck if(GetMessage(&msg.NULL,NULL,NULL)) { if(msg.message == WM_TIMER) { TranslateMEssage(&msg); DispatchMessage(&msg); } } I think GetMessage is a canned C or C++ function, and I'm not sure how to catch a message from WM_TIMER. Anyone who could help me get this loop converted to Python I would really appreciate it!!!! From mail at timgolden.me.uk Mon Sep 20 11:30:32 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 20 Sep 2010 16:30:32 +0100 Subject: catching WM_TIMER message In-Reply-To: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> References: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> Message-ID: <4C977E18.7090802@timgolden.me.uk> On 20/09/2010 16:15, Greg Miller wrote: > I'm trying to get the following code converted to Python.......and am > stuck > > if(GetMessage(&msg.NULL,NULL,NULL)) > { > if(msg.message == WM_TIMER) > { > TranslateMEssage(&msg); > DispatchMessage(&msg); > } > } > > I think GetMessage is a canned C or C++ function, and I'm not sure how > to catch a message from WM_TIMER. Anyone who could help me get this > loop converted to Python I would really appreciate it!!!! Goodness. You're going in at the deep end, slightly. What you're seeing there is a typical part of the standard Windows message loop which retrieves messages from the message queue of a Window (or thread) and then dispatches as your code does above. You *can* do this in Python, either using core Python only and making use of the ctypes module, or by employing the pywin32 packages which wrap the functions above. There's a thread-based example here which uses ctypes: http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html It should be readily adaptable to a WM_TIMER situation. Or you can see a (more complex) window-based example here which uses the pywin32 package: http://timgolden.me.uk/python/win32_how_do_i/detect-device-insertion.html If all you needed was the simplest code to catch a WM_TIMER message then the earlier example is probably a better fit. If this is part of a wider setup involving windows and other messages then you'll need (something like) the latter. TJG From homeusenet4 at brianhv.org Mon Sep 20 11:49:15 2010 From: homeusenet4 at brianhv.org (Brian Victor) Date: Mon, 20 Sep 2010 15:49:15 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: Tim Harig wrote: > Posting two URLs rather defeats the purpose of using a URL shortening > service in the first place; but, if that is what you feel is effective, > then by all means, do so. You are the master of your posts and you have > the right to post them using whatever methods and formating that you > feel is most effect; but, other people should have the same priviledge. The thing I haven't seen anyone make explicit in this conversation is that URL shorteners remove all the information from a URL. When someone posts a URL, I very frequently find one of the following is true: * I've already read the article or doc page being linked to * I haven't read it, but I recognize the domain name and can guess what it says based on what I know about the author. * I haven't read it, but the title (which is often a slug in the URL) tells me that it's not relevant to my problem. In any of those cases, I don't even have to click the link, much less copy and paste and add "preview" to the URL to see if it's something I care to read. Given this, I concur that URL shortening makes sense as an addition to a full URL if you're concerned about line-breaking, but feels like a needless obstacle when presented alone. And as a datapoint on the topic of archiving, I search usenet archives regularly when faced with a problem. -- Brian From deets at web.de Mon Sep 20 12:00:17 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 18:00:17 +0200 Subject: Encoding problem - or bug in couchdb-0.8-py2.7.egg?? References: Message-ID: <87iq201k32.fsf@web.de> Ian Hobson writes: > Hi all, > > I have hit a problem and I don't know enough about python to diagnose > things further. Trying to use couchDB from Python. This script:- > > # coding=utf8 > import couchdb > from couchdb.client import Server > server = Server() > dbName = 'python-tests' > try: > db = server.create(dbName) > except couchdb.PreconditionFailed: > del server[dbName] > db = server.create(dbName) > doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) > > Gives this traceback:- > > D:\work\C-U-B>python tes1.py > Traceback (most recent call last): > File "tes1.py", line 11, in > doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\client.py", > line 407, in save > _, _, data = func(body=doc, **options) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", > line 399, in post_json > status, headers, data = self.post(*a, **k) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", > line 381, in post > **params) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", > line 419, in _request > credentials=self.credentials) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", > line 310, in request > raise ServerError((status, error)) > couchdb.http.ServerError: (400, ('bad_request', 'invalid UTF-8 JSON')) > > D:\work\C-U-B> > > Why? I've tried adding u to the strings, and removing the # coding > line, and I still get the same error. Sounds cargo-cultish. I suggest you read the python introduction on unicode. http://docs.python.org/howto/unicode.html For your actual problem, I have difficulties seeing how it can happen with the above data - frankly because there is nothing outside the ascii-range of data, so there is no reason why anything could be wrong encoded. But googling the error-message reveals that there seem to be totally unrelated reasons for this: http://sindro.me/2010/4/3/couchdb-invalid-utf8-json Maybe using something like tcpmon or ethereal to capture the actual HTTP-request helps to see where the issue comes from. Diez From deets at web.de Mon Sep 20 12:03:10 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 18:03:10 +0200 Subject: Python Monitoring References: <4d1cbff7-af15-4ec8-bb24-0cbd616ca594@q9g2000vbd.googlegroups.com> Message-ID: <87eico1jy9.fsf@web.de> Glazner writes: > Hi, > > I'm will be writing a distributed program with parallel python and i > would like to if there are any good monitoring utilities for python. > I would like each remote server to post messages and to see the > messages in a web-broweser or such. > > I googled python monitoring and found pymon but it seems a bit > outdated. It's not exactly what you asked for, but the supervisord written in Python is not only capable of watching a process (admittedly always on the machine it is supposed to run), but can also be configured to have XMLRPC based (and I think even other) interfaces that a central server could poll & see the status of specific processes. I admit though that it needs more configuration. Just wanted to mention it, because process management might be on your list as well. Diez From arnodel at gmail.com Mon Sep 20 12:17:40 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 20 Sep 2010 09:17:40 -0700 (PDT) Subject: elementwise multiplication of 2 lists of numbers References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: On Sep 20, 3:02?pm, harryos wrote: > hi > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ?ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > ? ? ? ? z.append(a*b) > This gives me the correct result.Still,Is this the correct way? > Or can this be done in a better way? > > Any pointers most welcome, > harry In addition to what others have said, you can use the map builtin as follows: In Python 2.x: >>> map(int.__mul__, [2, 4, 3, 1], [5, 9, 10, 6]) [10, 36, 30, 6] If you don't know the list only contain ints use operator.mul. In Python 3.x you need to wrap it in list() as map returns an iterator. HTH -- Arnaud From __peter__ at web.de Mon Sep 20 12:33:30 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 20 Sep 2010 18:33:30 +0200 Subject: elementwise multiplication of 2 lists of numbers References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: harryos wrote: > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > z.append(a*b) > This gives me the correct result.Still,Is this the correct way? > Or can this be done in a better way? > > Any pointers most welcome, Finally, if you have a lot of data that you want to process efficiently consider using numpy arrays instead of lists: >>> import numpy >>> x = numpy.array([2,4,3,1]) >>> y = numpy.array([5,9,10,6]) >>> x*y array([10, 36, 30, 6]) Peter From et1ssgmiller at gmail.com Mon Sep 20 12:41:33 2010 From: et1ssgmiller at gmail.com (Greg Miller) Date: Mon, 20 Sep 2010 09:41:33 -0700 (PDT) Subject: catching WM_TIMER message References: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> Message-ID: <0f445259-11e5-410b-bdab-2cdb26919d83@c16g2000vbp.googlegroups.com> On Sep 20, 11:30?am, Tim Golden wrote: > On 20/09/2010 16:15, Greg Miller wrote: > > > I'm trying to get the following code converted to Python.......and am > > stuck > > > if(GetMessage(&msg.NULL,NULL,NULL)) > > { > > ? ? ? if(msg.message == WM_TIMER) > > ? ? ? { > > ? ? ? ? ? ?TranslateMEssage(&msg); > > ? ? ? ? ? ?DispatchMessage(&msg); > > ? ? ? } > > } > > > I think GetMessage is a canned C or C++ function, and I'm not sure how > > to catch a message from WM_TIMER. ?Anyone who could help me get this > > loop converted to Python I would really appreciate it!!!! > > Goodness. You're going in at the deep end, slightly. > > What you're seeing there is a typical part of the standard > Windows message loop which retrieves messages from the > message queue of a Window (or thread) and then dispatches > as your code does above. You *can* do this in Python, either > using core Python only and making use of the ctypes module, > or by employing the pywin32 packages which wrap the functions > above. > > There's a thread-based example here which uses ctypes: > > http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkey... > > It should be readily adaptable to a WM_TIMER situation. > > Or you can see a (more complex) window-based example here which > uses the pywin32 package: > > ? ?http://timgolden.me.uk/python/win32_how_do_i/detect-device-insertion.... > > If all you needed was the simplest code to catch a WM_TIMER > message then the earlier example is probably a better fit. > If this is part of a wider setup involving windows and other > messages then you'll need (something like) the latter. > > TJG Thank you for the assist! Quick question though, using the first example is there any need to register for WM_TIMER, ( instead of registering for WM_HOTKEY ), or is extracting the "home grown Windows message loop" enough and just run with that? et1ssgmiller From thomas at jollybox.de Mon Sep 20 12:46:07 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Mon, 20 Sep 2010 18:46:07 +0200 Subject: develop for Windows on GNU/Linux, using Python In-Reply-To: References: <8fn6ojF783U1@mid.individual.net> Message-ID: <201009201846.08296.thomas@jollybox.de> On Monday 20 September 2010, it occurred to Default User to exclaim: > On Sun, Sep 19, 2010 at 14:31, J.O. Aho wrote: > > Kev Dwyer wrote: > > > if you have C-extensions in > > > your code you'll need to compile them over Windows. If you want to > > > program against the Windows API you'll need access to a Windows box. > > > > You can always cross compile, not only over OS but even CPU architecture, > > but > > of course testing will be more difficult, on x86 based Linux you can use > > wine > > or similar to test, but can give you some differences to run on a native > > or virtualized instance. > > < sigh > . . . > > Well, that's about what I expected, unfortunately. But thanks for the > honest replies. > > [OT] > So what's the alternative -- use the end user's browser as an interpreter > for JavaScript or HTML5? > [/OT] Umn, what? Python makes it rather easy to write portable code. But you still need to test it properly on all platforms you want to support, because maybe there's some platform-specific glitch you weren't aware of. If you use web technologies, then you really have to test against browsers such as Opera, Safari, and Microsoft IE. Same difference, really. If you're doing something that requires C extensions to Python, things get more complicated, and probably impossible with web technologies. From simon at brunningonline.net Mon Sep 20 12:46:22 2010 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 20 Sep 2010 17:46:22 +0100 Subject: How to make a web services in python ??? In-Reply-To: References: Message-ID: On 20 September 2010 16:09, Ariel wrote: > Soap web services I think. I think the cool kids would be using , but for the fact that the cool kids all build REST () rather than SOAP these days. -- Cheers, Simon B. From usernet at ilthio.net Mon Sep 20 13:25:09 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 17:25:09 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Brian Victor wrote: > Tim Harig wrote: >> Posting two URLs rather defeats the purpose of using a URL shortening >> service in the first place; but, if that is what you feel is effective, >> then by all means, do so. You are the master of your posts and you have >> the right to post them using whatever methods and formating that you >> feel is most effect; but, other people should have the same priviledge. > > The thing I haven't seen anyone make explicit in this conversation is > that URL shorteners remove all the information from a URL. When someone > posts a URL, I very frequently find one of the following is true: Actually, its been a central point in this conversation. > In any of those cases, I don't even have to click the link, much less > copy and paste and add "preview" to the URL to see if it's something I > care to read. I have already stated in my thread with Seebs that all of this can be done automatically including converting the tinyurl back to a full url if you choose to do so. If you really wanted to, you could bring back the and other meta headers that would give you even more information about the page tinyurl redirects to. > Given this, I concur that URL shortening makes sense as an addition to a > full URL if you're concerned about line-breaking, but feels like a > needless obstacle when presented alone. Yes, it makes sense for you to do so and I support your right to do so. Personally, I would find two urls annoying. I also support the grandparent's right to post just the tinyurl. I don't make use of it much when posting myself; but, I do understand why some people find it useful. Its his post and he can do it how he wants. You have the right to do the same for your posts. > And as a datapoint on the topic of archiving, I search usenet archives > regularly when faced with a problem. Usernet users also have the right to use the X-No-Archive header field. Does the fact that *you* happen to search usenet archives make using this field immoral? Shouldn't the poster have to right to determine for themselves whether they care about the long term persistance of their posts and be able to balance that against other factors? From nkrumm at gmail.com Mon Sep 20 13:26:18 2010 From: nkrumm at gmail.com (Nik Krumm) Date: Mon, 20 Sep 2010 10:26:18 -0700 (PDT) Subject: hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Message-ID: <7b7f018e-b429-448b-94c1-2a812c5f3436@h37g2000pro.googlegroups.com> On Sep 18, 11:28?am, Ned Deily wrote: > In article , > ?Lawrence D'Oliveiro wrote: > > > In message , Ned Deily > > wrote: > > > ? ? try: > > > ? ? ? ? importreadline > > > ? ? except ImportError: > > > ? ? ? ? print("Modulereadlinenot available.") > > > ? ? else: > > > ? ? ? ? import rlcompleter > > > ? ? ? ?readline.parse_and_bind("tab: complete") > > > > Note the print() form which works with either Python 2 or 3. > > You should be writing diagnostics to stderr, not stdout. > > In general, sure. ? Statements in a PYTHONSTARTUP file, like here, are > only executed in interactive mode and it isn't likely that someone is > going to be redirecting stdout or stderr; that would kind of defeat the > purpose ofreadlinecompletion functions which is what this is all > about. ?But, if you feel strongly about it, I'm sure a contributed patch > to improve the rlcompleter documentation would be welcome. > > -- > ?Ned Deily, > ?n... at acm.org Hi, Thanks for the replies. The issue isn't with readline. The readline module or rlcompleter module are both available, and loading them has no effect on the behavior of tab: >>> import readline [Now i hit tab...] >>> ./ File "", line 1 ./ ^ SyntaxError: invalid syntax [Hit tab twice...] >>> ./ ./.bash_history ./.bash_profile ./.bash_profile.pysave ./.CFUserTextEncoding ./.cups ./.dropbox ./.DS_Store ./.fontconfig ./.ipython ./.lesshst ./.ssh ./.subversion ./.Trash ./.Xauthority ./ Desktop ./Documents ./ Downloads ./inputrc ./Library ./Movies ./ Music ./Pictures ./ Public ./python ./Sites >>> ./ >>> import rlcompleter >>> pri[TAB]--> completes >>> if testvar: ... [one TAB: nothing], [two TABs: "Display all 179 possibilities y/ n?"] (Note: here i need it to insert a tab, just as it should!) So this ostensibly makes it very hard to write or paste any code into the command line! any further ideas? Thanks again ~N From Antoon.Pardon at rece.vub.ac.be Mon Sep 20 13:28:49 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 20 Sep 2010 19:28:49 +0200 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <20100920172849.GA3388@rcpc42.vub.ac.be> On Sun, Sep 19, 2010 at 11:30:32PM +0000, Seebs wrote: > On 2010-09-19, MRAB wrote: > > On 19/09/2010 22:32, Seebs wrote: > >> On 2010-09-19, AK wrote: > >>> Because that's what 'if' and 'else' mean. > > >> My point is, I don't want the order of the clauses in if/else to change. > >> If it is sometimes "if else", then > >> it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, > >> then false clause. If it's sometimes "if condition true-clause else > >> false-clause", and sometimes "true-clause if condition else false-clause", > >> that's a source of extra complexity. > > > > [snip] > > Have you read PEP 308? There was a lot of discussion about it. > > Interesting, in the historical section we see: > > The original version of this PEP proposed the following syntax: > > if else > > The out-of-order arrangement was found to be too uncomfortable > for many of participants in the discussion; especially when > is long, it's easy to miss the conditional while > skimming. > > But apparently those objections were either unknown or disregarded when > the syntax was later adopted. Not necessarily. Some of us have the impression that Guido deliberatly chose an ugly format for the ternary operator. Guido has alwasys been against a ternary operator but the requests kept coming. So eventually he introduced one. But the impression is that he chose an ugly format in the hope of discouraging people to use it. -- Antoon Pardon From hobson42 at gmaiil.com Mon Sep 20 13:30:22 2010 From: hobson42 at gmaiil.com (Ian) Date: Mon, 20 Sep 2010 18:30:22 +0100 Subject: Encoding problem - or bug in couchdb-0.8-py2.7.egg?? In-Reply-To: <87iq201k32.fsf@web.de> References: <87iq201k32.fsf@web.de> Message-ID: <4C979A2E.5050505@gmaiil.com> Thanks Diez, Removing, rebooting and installing the latest version solved the problem. :) Your google-foo is better than mine. Google had not turned that up for me. Thanks again Regards Ian On 20/09/2010 17:00, Diez B. Roggisch wrote: > Ian Hobson writes: > >> Hi all, >> >> I have hit a problem and I don't know enough about python to diagnose >> things further. Trying to use couchDB from Python. This script:- >> >> # coding=utf8 >> import couchdb >> from couchdb.client import Server >> server = Server() >> dbName = 'python-tests' >> try: >> db = server.create(dbName) >> except couchdb.PreconditionFailed: >> del server[dbName] >> db = server.create(dbName) >> doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) >> >> Gives this traceback:- >> >> D:\work\C-U-B>python tes1.py >> Traceback (most recent call last): >> File "tes1.py", line 11, in >> doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\client.py", >> line 407, in save >> _, _, data = func(body=doc, **options) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", >> line 399, in post_json >> status, headers, data = self.post(*a, **k) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", >> line 381, in post >> **params) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", >> line 419, in _request >> credentials=self.credentials) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", >> line 310, in request >> raise ServerError((status, error)) >> couchdb.http.ServerError: (400, ('bad_request', 'invalid UTF-8 JSON')) >> >> D:\work\C-U-B> >> >> Why? I've tried adding u to the strings, and removing the # coding >> line, and I still get the same error. > Sounds cargo-cultish. I suggest you read the python introduction on > unicode. > > http://docs.python.org/howto/unicode.html > > For your actual problem, I have difficulties seeing how it can happen > with the above data - frankly because there is nothing outside the > ascii-range of data, so there is no reason why anything could be wrong > encoded. I came to the same conclusion. > But googling the error-message reveals that there seem to be totally > unrelated reasons for this: > > http://sindro.me/2010/4/3/couchdb-invalid-utf8-json > > Maybe using something like tcpmon or ethereal to capture the actual > HTTP-request helps to see where the issue comes from. > > Diez From mail at timgolden.me.uk Mon Sep 20 13:35:54 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 20 Sep 2010 18:35:54 +0100 Subject: catching WM_TIMER message In-Reply-To: <0f445259-11e5-410b-bdab-2cdb26919d83@c16g2000vbp.googlegroups.com> References: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> <0f445259-11e5-410b-bdab-2cdb26919d83@c16g2000vbp.googlegroups.com> Message-ID: <4C979B7A.1090500@timgolden.me.uk> On 20/09/2010 5:41 PM, Greg Miller wrote: > Thank you for the assist! Quick question though, using the first > example is there any need to register for WM_TIMER, ( instead of > registering for WM_HOTKEY ), or is extracting the "home grown Windows > message loop" enough and just run with that? In short: no need to register (although the WM_TIMER will have to come from somewhere, ie your process will have to initiated a SetTimer call. If you aren't familiar with this area, it's worth your reading up on the way in which Windows message queues and timers work. There are oodles of examples /tutorials. This is pretty much the canonical starting point: http://msdn.microsoft.com/en-us/library/ms644928%28VS.85%29.aspx but obviously YMMV. TJG From hobson42 at gmaiil.com Mon Sep 20 13:36:50 2010 From: hobson42 at gmaiil.com (Ian) Date: Mon, 20 Sep 2010 18:36:50 +0100 Subject: How to make a web services in python ??? In-Reply-To: References: Message-ID: <4C979BB2.4020809@gmaiil.com> On 20/09/2010 16:09, Ariel wrote: > Soap web services I think. > > On Fri, Sep 17, 2010 at 5:35 PM, Hidura > wrote: > > What kind of web-service you have in mind???? > > 2010/9/17, Ariel >: > > Hi everybody, I need some help to find documentation about how > to implements > > web services in python, could you help me please ??? > > Regards > > Thanks in advance > > Ariel > > > > Hi Ariel, There are a few pages on creating a TCP server and a Threaded server in Chapters 18 and 19 of "Rapid GUI Programming with Python and Qt" by Mark Summerfield. It shows you how to handle sockets, threading , and the locking of shared data constructs. Regards Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From yoavglazner at gmail.com Mon Sep 20 14:10:58 2010 From: yoavglazner at gmail.com (Glazner) Date: Mon, 20 Sep 2010 11:10:58 -0700 (PDT) Subject: Python Monitoring References: <4d1cbff7-af15-4ec8-bb24-0cbd616ca594@q9g2000vbd.googlegroups.com> <87eico1jy9.fsf@web.de> Message-ID: <0c2c9d7f-9c5b-40d8-8eef-53c5842d09dd@u13g2000vbo.googlegroups.com> On Sep 20, 6:03?pm, de... at web.de (Diez B. Roggisch) wrote: > Glazner writes: > > Hi, > > > I'm will be writing a distributed program with parallel python and i > > would like to if there are any good monitoring utilities for python. > > I would like each remote server to post messages and to see the > > messages in a web-broweser or such. > > > I googled python monitoring and found pymon but it seems a bit > > outdated. > > It's not exactly what you asked for, but the supervisord written in > Python is not only capable of watching a process (admittedly always on > the machine it is supposed to run), but can also be configured to have > XMLRPC based (and I think even other) interfaces that a central server > could poll & see the status of specific processes. I admit though that > it needs more configuration. Just wanted to mention it, because process > management might be on your list as well. > > Diez mmm... , windows not supported :( I need windows (cross platform is important) From usenet-nospam at seebs.net Mon Sep 20 14:14:34 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 18:14:34 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Tim Harig wrote: > You could simply place the filter in slrn; then, any urls that you see in > your reader would already be shown with the preview prefix suitable for cut > and paste mechanisms. If you wanted, you can even have your script > download the preview and automatically convert it back to the full > origional URL. This would require me to do a lot more work. :) > I assume just the opposite. Once the post has been removed from the > server, it is gone to me. I am not fond of the various archives that are > otherwise available on the web. Huh. I find the old usenet archives amusing, at the very least, and often very informative. > No, I tend to think is is much better that posts simply expire by > their use by date. I prefer data to be around as long as possible, since it at least potentially reduces effort. > If this was something that was forced upon you, then I might have some > sympathy; however, I see it as the poster's right to do what he thinks will > make his post more effective. I agree. On the other hand, many people are simply unaware of some of the reasons for which tinyurl and the like can make their message less effective to at least some users, so mentioning this to them may be useful. In theory, you have the right to indent your Python code however you want. In practice, if you don't use four spaces, you'll run into various problems interoperating with other people. Telling people this if they don't know it or are ignoring it is probably useful, even though ultimately the decision remains up to 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 tjreedy at udel.edu Mon Sep 20 14:23:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Sep 2010 14:23:45 -0400 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) In-Reply-To: <4c96d845$0$11113$c3e8da3@news.astraweb.com> References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 9/19/2010 11:43 PM, Steven D'Aprano wrote: > On Sun, 19 Sep 2010 06:16:49 -0700, Aahz wrote: > >> Please don't use tinyurl -- it's opaque and provides zero help to anyone >> who might later want to look it up (and also no accessibility if tinyurl >> ever goes down). At the very least, include the original URL for >> reference. > > Do you have something against tinyurl in particular, or would any URL > shortener service also get your ire? All of them. For mail/news without a 140 char limit, read with a mail/news reader, there is usually no point to using them. All pain, no gain. I almost never click on them. (This is quite different from ephemeral photo storage sites, where the short url is *the* one and only url.) Most long urls have a bunch of unneeded garbage at the end. When I create or search for a tracker issue, resulting url in the browser bar is about 2/3rds unnecessary stuff. When posting such links, I only cut and paste the needed part: http://bugs.python.org/issue#### and leave off the rest. I may also include the title separately. Anyone reading that can know just what they will find. -- Terry Jan Reedy From chris at simplistix.co.uk Mon Sep 20 14:29:44 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 20 Sep 2010 19:29:44 +0100 Subject: sqlalchemy: how to define association object with declarative style? In-Reply-To: References: Message-ID: <4C97A818.5070409@simplistix.co.uk> Hi Jerry, For SQLAlchemy questions, you're better off asking on sqlalchemy at googlegroups.com. On 07/09/2010 10:39, Jerry Fleming wrote: > class GroupUser(DeclarativeBase, Tablename, TimestampMixin): > id = Column(Integer, Sequence('group_user_id_seq'), primary_key=True) > user = Column(Integer, ForeignKey('user.id'), index=True), > group = Column(Integer, ForeignKey('group.id'), index=True) > > I was wondering how to associate User and Group with GroupUser with > GroupUser as the association object/proxy? The sqlalchemy docs only > mention only mention association tables, or non-declarative manual mapping. Yes, declarative doesn't currently work like this. The functionality could probably be added, but Michael Bayer would be the man to decide how to do that :-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From tjreedy at udel.edu Mon Sep 20 14:30:08 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Sep 2010 14:30:08 -0400 Subject: newbie: class and __dict__ variable. In-Reply-To: <4c972eb9$0$12598$426a34cc@news.free.fr> References: <4c970cdd$0$21775$426a74cc@news.free.fr> <4c972065$0$11113$c3e8da3@news.astraweb.com> <4c972eb9$0$12598$426a34cc@news.free.fr> Message-ID: On 9/20/2010 5:51 AM, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : >> On Mon, 20 Sep 2010 09:27:25 +0200, Bruno Desthuilliers wrote: >> >>>> If the class has a .__setattr__ method, the first bypasses that method, >>> It also bypasses object.__setattribute__ and - as a consequence - any >>> binding descriptor by the same name as the attribute being set. >> >> __setattribute__ ? >> >> >>>>> object.__setattribute__ >> Traceback (most recent call last): >> File "", line 1, in >> AttributeError: type object 'object' has no attribute '__setattribute__' >> > > Duh... > Brain fart, sorry, shouldn't post before I get my dose of coffee :( > > Let's do it again: > > Terry Reedy a ?crit : > > If the class has a .__setattr__ method, the first bypasses that > > method, > > All new-style classes have a __setattr__ method - whether inherited from > object or overridden. object.__setattr__ implements the support for > binding descriptors, so bypassing it will also bypass all binding > descriptors. > > The right way to avoid infinite recursion when overriding __setattr__ is > to call on the superclass __setattr__, unless of course you *really* > know what you're doing... In the 3.x doc, this is now the recommended method. The self.__dict__ idiom predates new-style classes, object, and super. To the OP. It is possible that you have seem bad (useless, redundant) uses as well as uses that were necessary with old-style user classes. > class BarDescriptor(object): > def __init__(self): > self.val = None > > def __set__(self, instance, value): > print "stores value elsewhere and trigger some required behaviour" > self.val = value * 2 > > def __get__(self, instance, cls=None): > if instance is None: > return self > print "retrieve value from elsewhere and trigger some required behaviour" > return self.val > > # well behaved > class Foo(object): > bar = BarDescriptor() > > def __init__(self): > self.bar = 42 > > def __setattr__(self, name, value): > print "override __setattr_ for some reason" > super(Foo, self).__setattr__(name, value) > > > # ugly mess > class Baaz(Foo): > bar = BarDescriptor() > > def __init__(self): > self.__dict__['bar'] = 42 > > def __setattr__(self, name, value): > print "override __setattr_ for some reason" > self.__dict__[name] == value > > >>> f = Foo() > override __setattr_ for some reason > stores value elsewhere and trigger some required behaviour > >>> f.bar > retrieve value from elsewhere and trigger some required behaviour > 84 > >>> f.__dict__ > {} > >>> f.bar = 33 > override __setattr_ for some reason > stores value elsewhere and trigger some required behaviour > >>> f.bar > retrieve value from elsewhere and trigger some required behaviour > 66 > >>> f.__dict__ > {} > >>> b = Baaz() > >>> b.__dict__ > {'bar': 42} > >>> b.bar > retrieve value from elsewhere and trigger some required behaviour > >>> b.bar = 33 > override __setattr_ for some reason > >>> b.bar > retrieve value from elsewhere and trigger some required behaviour > >>> b.__dict__ > {'bar': 42} -- Terry Jan Reedy From tjreedy at udel.edu Mon Sep 20 14:43:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Sep 2010 14:43:31 -0400 Subject: Too much code - slicing In-Reply-To: <4C96DD24.3020400@gmail.com> References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> <4C96DD24.3020400@gmail.com> Message-ID: > On 09/19/2010 10:32 PM, John Bokma wrote: >> the spoiler. Do you fast forward movies as well? I sometimes watch movies (or parts thereof) on 1.5x, especially if it has a lot of 'filler' scenes. But only when my wife is not watching, as she hates it. -- Terry Jan Reedy From chris at simplistix.co.uk Mon Sep 20 14:45:37 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 20 Sep 2010 19:45:37 +0100 Subject: os.path.normcase rationale? In-Reply-To: <87lj727lu7.fsf@benfinney.id.au> References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <4C97ABD1.5090506@simplistix.co.uk> On 15/09/2010 22:12, Ben Finney wrote: > Chris Withers writes: > >> I'm curious as to why, with a file called "Foo.txt" >> os.path.normcase('FoO.txt') will return "foo.txt" rather than >> "Foo.txt"? > > What kind of answer are you looking for? > > A direct answer would be: it does that because on case-insensitive > filesystems, it doesn't matter what the case is, so there's no need for > anything more complex than all lowercase. Well, no, that doesn't feel right. Normalisation of case, for me, means "give me the case as the filesystem thinks it should be", not "just lowercase it all". This makes a difference; I hit it by way of version pinning in buildout, the culprit being setuptools calling normcase on distributions found on the filesystem on Windows. Buildout's version pinning is case sensitive (arguably a bug) and so doesn't work when setuptools's use of normcase ends up with he distribution name being lowercased, even though the case is correct on the file system... >> Yes, I know the behaviour is documented > > The docstring is fairly poor, IMO. You might want to submit a bug report > to improve it. I think it would have been a lot more confusing had it not been mentioned that it was just lowercasing everything... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Mon Sep 20 14:46:39 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 20 Sep 2010 19:46:39 +0100 Subject: os.path.normcase rationale? In-Reply-To: <8fd2c1FvvhU1@mid.individual.net> References: <87lj727lu7.fsf@benfinney.id.au> <8fd2c1FvvhU1@mid.individual.net> Message-ID: <4C97AC0F.9090108@simplistix.co.uk> On 16/09/2010 00:14, Gregory Ewing wrote: > Ben Finney wrote: >> it doesn't matter what the case is, so there's no need for >> anything more complex than all lowercase. > > Also doing what was suggested would require looking at > what's in the file system, which would be a lot of bother > to go to for no good reason, and would fail for paths > that don't correspond to an existing file. .lower() is shorter to type, if that's what you want... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From usenet-nospam at seebs.net Mon Sep 20 14:47:50 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 18:47:50 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Antoon Pardon wrote: > Not necessarily. Some of us have the impression that Guido deliberatly > chose an ugly format for the ternary operator. Guido has alwasys been > against a ternary operator but the requests kept coming. So eventually > he introduced one. But the impression is that he chose an ugly format > in the hope of discouraging people to use it. If true, that is an *awesome* etymology for a hunk of a programming 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 chris at simplistix.co.uk Mon Sep 20 14:48:40 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 20 Sep 2010 19:48:40 +0100 Subject: os.path.normcase rationale? In-Reply-To: References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <4C97AC88.5080207@simplistix.co.uk> On 17/09/2010 03:35, Nobody wrote: > os.path.normcase(path) > Normalize the case of a pathname. On Unix and Mac OS X, this returns > the path unchanged; on case-insensitive filesystems, it converts the > path to lowercase. On Windows, it also converts forward slashes to > backward slashes. > > It implies that the behaviour depends upon the actual filesystem, which > isn't the case. It only depends upon the platform, i.e. it assumes that > all filenames are case-sensitive on Unix systems and case-insensitive on > Windows. But Unix systems can access FAT/SMBFS/etc filesystems which are > case-insensitive. Right, so in its current form it seems pretty useless ;-) What I expected it to mean was "give me what the filesystem thinks this file path is", which doesn't seem unreasonable and would be a lot more useful, no matter the platform... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rudikk99 at yahoo.com Mon Sep 20 14:58:09 2010 From: rudikk99 at yahoo.com (rudikk00) Date: Mon, 20 Sep 2010 11:58:09 -0700 (PDT) Subject: match pattern Message-ID: Hi all, I remember perl has a match function =~/H/ --> which searches if there is "H" pattern in line. Is there a reasonable analog of it in python? thanks! Alex From ian.g.kelly at gmail.com Mon Sep 20 15:15:30 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 13:15:30 -0600 Subject: match pattern In-Reply-To: References: Message-ID: On Mon, Sep 20, 2010 at 12:58 PM, rudikk00 wrote: > Hi all, > > I remember perl has a match function =~/H/ --> which searches if there > is "H" pattern in line. Is there a reasonable analog of it in python? > Yes, have a look at the re module in the standard library. If all you're interested in is exact matches and not regular expressions, you can also use the "in" operator: if "H" in my_string: do_something() Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Sep 20 15:22:47 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 13:22:47 -0600 Subject: Too much code - slicing In-Reply-To: <20100920172849.GA3388@rcpc42.vub.ac.be> References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <20100920172849.GA3388@rcpc42.vub.ac.be> Message-ID: On Mon, Sep 20, 2010 at 11:28 AM, Antoon Pardon < Antoon.Pardon at rece.vub.ac.be> wrote: > > Not necessarily. Some of us have the impression that Guido deliberatly > chose an ugly format for the ternary operator. Guido has alwasys been > against a ternary operator but the requests kept coming. So eventually > he introduced one. But the impression is that he chose an ugly format > in the hope of discouraging people to use it. > If that was indeed the intention, then it worked, at least in my case. Hmm, perhaps we should also add goto to the language, but we'll call it something cumbersome like "slitherto" and give it the side effect of reformatting the hard drive. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Mon Sep 20 16:19:37 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 20 Sep 2010 22:19:37 +0200 Subject: Python and unicode In-Reply-To: References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> <4c96d826$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C97C1D9.6070202@v.loewis.de> Am 20.09.2010 12:57, schrieb Dotan Cohen: > On Mon, Sep 20, 2010 at 12:20, Peter Otten <__peter__ at web.de> wrote: >> It may work by accident, if you declare it as UTF-8, because that is also >> the default in Python 3. >> > > That does seem to be the case. > > Thank you for the enlightenment and information. It's as Peter says. Python really will ignore any encoding declaration on the third or later line. This was added to the spec on explicit request from Guido van Rossum. It's still the case today. However, in Python 3, in the absence of an encoding declaration, the file encoding is assumed to be UTF-8 (producing an error if it actually is not). So it worked for you by accident. Regards, Martin From deets at web.de Mon Sep 20 16:40:58 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 22:40:58 +0200 Subject: match pattern References: Message-ID: rudikk00 writes: > I remember perl has a match function =~/H/ --> which searches if there > is "H" pattern in line. Is there a reasonable analog of it in python? It's called a regular expression, which can be matched or searched in a string. Take a look at the module "re" in python. http://docs.python.org/library/re.html Diez From deets at web.de Mon Sep 20 16:45:20 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 22:45:20 +0200 Subject: Python Monitoring References: <4d1cbff7-af15-4ec8-bb24-0cbd616ca594@q9g2000vbd.googlegroups.com> <87eico1jy9.fsf@web.de> <0c2c9d7f-9c5b-40d8-8eef-53c5842d09dd@u13g2000vbo.googlegroups.com> Message-ID: Glazner writes: > On Sep 20, 6:03?pm, de... at web.de (Diez B. Roggisch) wrote: >> Glazner writes: >> > Hi, >> >> > I'm will be writing a distributed program with parallel python and i >> > would like to if there are any good monitoring utilities for python. >> > I would like each remote server to post messages and to see the >> > messages in a web-broweser or such. >> >> > I googled python monitoring and found pymon but it seems a bit >> > outdated. >> >> It's not exactly what you asked for, but the supervisord written in >> Python is not only capable of watching a process (admittedly always on >> the machine it is supposed to run), but can also be configured to have >> XMLRPC based (and I think even other) interfaces that a central server >> could poll & see the status of specific processes. I admit though that >> it needs more configuration. Just wanted to mention it, because process >> management might be on your list as well. >> >> Diez > > mmm... , windows not supported :( > I need windows (cross platform is important) Ah. Poor you. Well, there is also pyro. It should run on all OS, and it comes with a name-service. With this, it's actually possible and probably quite easy to have all your respective clients/workers/agents connect themselves to central monitoring instance, and posting more or less accurately their state. The configuration needed should be minimal, and depending on your network setup even trivial because there is some broadcasting detection ala bonjour available. The worst that can happen is that you have to spread knowledge of a specific pyro server through a string like pyro:/// or some such. Diez From fazzitron at gmail.com Mon Sep 20 16:54:56 2010 From: fazzitron at gmail.com (Seth Leija) Date: Mon, 20 Sep 2010 13:54:56 -0700 (PDT) Subject: Combinations or Permutations Message-ID: I need to know how to generate a list of combinations/permutations (can't remember which it is). Say I have a list of variables: [a,b,c,d,...,x,y,z] I am curious if there is an optimized way to generate this: [[a,b],[a,c],[a,d],...,[x,z],[y,z]] I currently have an iteration that does this: #list.py from math import * list1=['a','b','c','d','e'] list2=[] length=len(list1) for it1 in range(0 ,length): for it2 in range(it1+1, length): list2.append([list1[it1],list1[it2]]) print list2 However, this is one of the slowest parts of my function (beaten only by variable instantiation). I posted this on another forum looking to see if there was a different method completely. They said that my method was about as simple as it could get, but I might be able to find out how to optimize my code here. Thanks in advance. From deets at web.de Mon Sep 20 16:54:59 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 22:54:59 +0200 Subject: visual studio 2010 question References: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> Message-ID: David Cournapeau writes: > On Mon, Sep 20, 2010 at 3:08 PM, Ralf Haring wrote: >> >> After running into the error "Setup script exited with error: Unable >> to find vcvarsall.bat" when trying to use easy_install / setuptools a >> little digging showed that the MS compiler files in distutils only >> support up to Studio 2008. Does anyone know if there is a timetable >> for when Studio 2010 will be supported? >> >> I am using python 2.6.5, but web searching seemed to show that 2.7 or >> 3.X didn't support it yet either. > > You should use VS 2008 - the lack of distutils support is only the > first of a long list of issues if you want to use another compiler to > build python extensions. Unless you really know what you are doing, > you are better off with VS 2008, Forgive my ignorance, but AFAIK mingw can be used to build extensions for standard python distributions. After all, it's C we're talking here, not C++. So I have difficulties imagining VS2010 is that much of a problem. So - which problems you expect? Diez From ckaynor at zindagigames.com Mon Sep 20 17:00:35 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 20 Sep 2010 14:00:35 -0700 Subject: Combinations or Permutations In-Reply-To: References: Message-ID: The itertools module (http://docs.python.org/library/itertools.html) has both permutations and combinations functionality. Chris On Mon, Sep 20, 2010 at 1:54 PM, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > I currently have an iteration that does this: > > #list.py > > from math import * > > list1=['a','b','c','d','e'] > list2=[] > length=len(list1) > > for it1 in range(0 ,length): > for it2 in range(it1+1, length): > list2.append([list1[it1],list1[it2]]) > > print list2 > > However, this is one of the slowest parts of my function (beaten only > by variable instantiation). I posted this on another forum looking to > see if there was a different method completely. They said that my > method was about as simple as it could get, but I might be able to > find out how to optimize my code here. > > Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Sep 20 17:02:33 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 15:02:33 -0600 Subject: Combinations or Permutations In-Reply-To: References: Message-ID: On Mon, Sep 20, 2010 at 2:54 PM, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > In Python 2.6 or newer: >>> from itertools import combinations >>> import string >>> print list(combinations(string.lowercase, 2)) Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Sep 20 17:07:03 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Sep 2010 22:07:03 +0100 Subject: Too much code - slicing In-Reply-To: <20100920172849.GA3388@rcpc42.vub.ac.be> References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <20100920172849.GA3388@rcpc42.vub.ac.be> Message-ID: On 20/09/2010 18:28, Antoon Pardon wrote: > On Sun, Sep 19, 2010 at 11:30:32PM +0000, Seebs wrote: >> On 2010-09-19, MRAB wrote: >>> On 19/09/2010 22:32, Seebs wrote: >>>> On 2010-09-19, AK wrote: >>>>> Because that's what 'if' and 'else' mean. >> >>>> My point is, I don't want the order of the clauses in if/else to change. >>>> If it is sometimes "if else", then >>>> it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, >>>> then false clause. If it's sometimes "if condition true-clause else >>>> false-clause", and sometimes "true-clause if condition else false-clause", >>>> that's a source of extra complexity. >>> >>> [snip] >>> Have you read PEP 308? There was a lot of discussion about it. >> >> Interesting, in the historical section we see: >> >> The original version of this PEP proposed the following syntax: >> >> if else >> >> The out-of-order arrangement was found to be too uncomfortable >> for many of participants in the discussion; especially when >> is long, it's easy to miss the conditional while >> skimming. >> >> But apparently those objections were either unknown or disregarded when >> the syntax was later adopted. > > Not necessarily. Some of us have the impression that Guido deliberatly > chose an ugly format for the ternary operator. Guido has alwasys been > against a ternary operator but the requests kept coming. So eventually > he introduced one. But the impression is that he chose an ugly format > in the hope of discouraging people to use it. > I very much like the format of the Python ternary operator, but I've never actually used it myself :) Cheers Mark Lawrence. From breamoreboy at yahoo.co.uk Mon Sep 20 17:08:53 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Sep 2010 22:08:53 +0100 Subject: Combinations or Permutations In-Reply-To: References: Message-ID: On 20/09/2010 21:54, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > I currently have an iteration that does this: > > #list.py > > from math import * > > list1=['a','b','c','d','e'] > list2=[] > length=len(list1) > > for it1 in range(0 ,length): > for it2 in range(it1+1, length): > list2.append([list1[it1],list1[it2]]) > > print list2 > > However, this is one of the slowest parts of my function (beaten only > by variable instantiation). I posted this on another forum looking to > see if there was a different method completely. They said that my > method was about as simple as it could get, but I might be able to > find out how to optimize my code here. > > Thanks in advance. Check the docs for the itertools module. Cheers. Mark Lawrence. From robert.kern at gmail.com Mon Sep 20 17:11:01 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 20 Sep 2010 16:11:01 -0500 Subject: visual studio 2010 question In-Reply-To: References: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> Message-ID: On 9/20/10 3:54 PM, Diez B. Roggisch wrote: > David Cournapeau writes: > >> On Mon, Sep 20, 2010 at 3:08 PM, Ralf Haring wrote: >>> >>> After running into the error "Setup script exited with error: Unable >>> to find vcvarsall.bat" when trying to use easy_install / setuptools a >>> little digging showed that the MS compiler files in distutils only >>> support up to Studio 2008. Does anyone know if there is a timetable >>> for when Studio 2010 will be supported? >>> >>> I am using python 2.6.5, but web searching seemed to show that 2.7 or >>> 3.X didn't support it yet either. >> >> You should use VS 2008 - the lack of distutils support is only the >> first of a long list of issues if you want to use another compiler to >> build python extensions. Unless you really know what you are doing, >> you are better off with VS 2008, > > Forgive my ignorance, but AFAIK mingw can be used to build extensions > for standard python distributions. After all, it's C we're talking here, > not C++. So I have difficulties imagining VS2010 is that much of a > problem. So - which problems you expect? VS2010 uses a different C runtime DLL than VS2008 and Python 2.6, and I believe this cannot be changed. This will cause errors for a variety of Python extension modules. mingw can be retargeted to link against one of several different C runtimes, including the one VS2008 uses. -- 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 astley.lejasper at gmail.com Mon Sep 20 17:42:26 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Mon, 20 Sep 2010 14:42:26 -0700 (PDT) Subject: Grouping pairs - suggested tools Message-ID: I have a list of tuples that indicate a relationship, ie a is related to b, b is related to c etc etc. What I want to do is cluster these relationships into groups. An item will only be associated with a single cluster. Before I started, I wondered if there was any particular tool within Python I should be looking at. I don't expect anyone to code this for me, just say ... "you need to look at using x". I was going to use populate a dictionary and Sorry for being so vague. Example Data: [(a,b) (a,c) (a,d) (b,c) (b,d) (c,d) (e,f) (e,g) (f,g) (h,i)] Output (grouping id, item ref) (1,a), (1,b), (1,c), (1,d), (2,e), (2,f), (2,g), (3,h), (3,i) From nad at acm.org Mon Sep 20 17:49:47 2010 From: nad at acm.org (Ned Deily) Date: Mon, 20 Sep 2010 14:49:47 -0700 Subject: hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> <7b7f018e-b429-448b-94c1-2a812c5f3436@h37g2000pro.googlegroups.com> Message-ID: In article <7b7f018e-b429-448b-94c1-2a812c5f3436 at h37g2000pro.googlegroups.com>, Nik Krumm wrote: > The issue isn't with readline. The readline module or rlcompleter > module are both available, and loading them has no effect on the > behavior of tab: > > >>> import readline > [Now i hit tab...] > >>> ./ > File "", line 1 > ./ > ^ > SyntaxError: invalid syntax > > [Hit tab twice...] > >>> ./ > ./.bash_history ./.bash_profile ./.bash_profile.pysave [...] > So this ostensibly makes it very hard to write or paste any code into > the command line! Ah, thanks, I get it now. It turns out this is a bug seen for the first time with the new-style (32-/64-, 10.5+) python.org 2.7 installer build because it links with the Apple-supplied editline library rather than the GNU readline library as in other installers. I've opened an issue for this: http://bugs.python.org/issue9907 As noted there, two workarounds come to mind. Either switch to using the old-style (32-only, 10.3+) 2.7 installer; or, add or modify a PYTHONSTARTUP file to force the desired TAB behavior, so something like this: $ cat > $HOME/.pystartup import readline if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I ed-insert") ^D $ export PYTHONSTARTUP=$HOME/.pystartup Thanks for reporting this! -- Ned Deily, nad at acm.org From fazzitron at gmail.com Mon Sep 20 17:57:48 2010 From: fazzitron at gmail.com (Seth Leija) Date: Mon, 20 Sep 2010 14:57:48 -0700 (PDT) Subject: Combinations or Permutations References: Message-ID: <044f3958-d3e6-4ad8-b60b-67fb363cc542@a4g2000prm.googlegroups.com> On Sep 20, 3:08?pm, Mark Lawrence wrote: > On 20/09/2010 21:54, Seth Leija wrote: > > > > > > > I need to know how to generate a list of combinations/permutations > > (can't remember which it is). Say I have a list of variables: > > > [a,b,c,d,...,x,y,z] > > > I am curious if there is an optimized way to generate this: > > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > > I currently have an iteration that does this: > > > #list.py > > > from math import * > > > list1=['a','b','c','d','e'] > > list2=[] > > length=len(list1) > > > for it1 in range(0 ,length): > > ? ? ?for it2 in range(it1+1, length): > > ? ? ? ? ?list2.append([list1[it1],list1[it2]]) > > > print list2 > > > However, this is one of the slowest parts of my function (beaten only > > by variable instantiation). I posted this on another forum looking to > > see if there was a different method completely. They said that my > > method was about as simple as it could get, but I might be able to > > find out how to optimize my code here. > > > Thanks in advance. > > Check the docs for the itertools module. > > Cheers. > > Mark Lawrence. That works! That made my function significantly faster! It's still slower than I would like it, but this is enough for now. Thank you so much! From glenn.pringle at gmail.com Mon Sep 20 18:47:32 2010 From: glenn.pringle at gmail.com (Glenn Pringle) Date: Mon, 20 Sep 2010 15:47:32 -0700 (PDT) Subject: Arrays and CTYPE Message-ID: <824d1ec2-93ee-4a81-ad95-19560fabe9e4@r10g2000vbc.googlegroups.com> Ok. I ran into a problem here. I have been dabbling with Python and I thought that this would be a good exercise but I got stuck. I have a DLL and one of the functions(getState) in that DLL returns an array. I'm having a hard time getting access to the contents of that array. Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import ctypes >>> hold = ctypes.CDLL('Dinamap.dll') >>> print hold.checkReadiness() 1 >>> print hold.getBufferLength() 1400 >>> print hold.resetMonitor() 1 >>> print hold.getState() 42607516 >>> Would greatly appreciate if somebody points me in the right direction. Thanks, Glenn From clp2 at rebertia.com Mon Sep 20 18:59:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 20 Sep 2010 15:59:31 -0700 Subject: Arrays and CTYPE In-Reply-To: <824d1ec2-93ee-4a81-ad95-19560fabe9e4@r10g2000vbc.googlegroups.com> References: <824d1ec2-93ee-4a81-ad95-19560fabe9e4@r10g2000vbc.googlegroups.com> Message-ID: On Mon, Sep 20, 2010 at 3:47 PM, Glenn Pringle wrote: > Ok. I ran into a problem here. I have been dabbling with Python and I > thought that this would be a good exercise but I got stuck. > > I have a DLL and one of the functions(getState) in that DLL returns an > array. I'm having a hard time getting access to the contents of that > array. > > Python 2.7 (r27:82525, Jul ?4 2010, 09:01:59) [MSC v.1500 32 bit > (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> import ctypes >>>> hold = ctypes.CDLL('Dinamap.dll') >>>> print hold.checkReadiness() > 1 >>>> print hold.getBufferLength() > 1400 >>>> print hold.resetMonitor() > 1 >>>> print hold.getState() > 42607516 >>>> > > Would greatly appreciate if somebody points me in the right direction. Set hold.getState.restype appropriately. Read the fine docs: http://docs.python.org/library/ctypes.html#return-types http://docs.python.org/library/ctypes.html#fundamental-data-types Cheers, Chris -- http://blog.rebertia.com From alf.p.steinbach+usenet at gmail.com Mon Sep 20 19:09:09 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 21 Sep 2010 01:09:09 +0200 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: * Astley Le Jasper, on 20.09.2010 23:42: > I have a list of tuples that indicate a relationship, ie a is related > to b, b is related to c etc etc. What I want to do is cluster these > relationships into groups. An item will only be associated with a > single cluster. > > Before I started, I wondered if there was any particular tool within > Python I should be looking at. I don't expect anyone to code this for > me, just say ... "you need to look at using x". I was going to use > populate a dictionary and > > Sorry for being so vague. > > Example Data: > [(a,b) > (a,c) > (a,d) > (b,c) > (b,d) > (c,d) > (e,f) > (e,g) > (f,g) > (h,i)] > > Output (grouping id, item ref) > (1,a), > (1,b), > (1,c), > (1,d), > (2,e), > (2,f), > (2,g), > (3,h), > (3,i) It seems to be the same problem as "equivalence sets". This problem was solved early on because e.g. Fortran compilers had to construct such sets (equivalence partitions of a set). I though I'd just say "Google it!", because I know there's a standard algorithm but I can't recall the name. However, googling it I found no mention of that algorithm. Not even in the Wikipedia articles on equivalence sets. A number of approaches spring to mind: Approach 1: Multi-pass. Originally you assign a distinct set number to each symbol. In each pass through the symbols you replace one number with another as per one of the equivalence specs. Stop when no replacements are done. Approach 2: Merging. For each new equivalence A=B you check whether A has been assigned to a set, if not you create a new one, call that S1, and ditto for B, S2. Merge S1 and S2, e.g. move all elements of S2 to S1. Approach 3: In a first pass convert the data to more explicit form, linking each symbol to the symbols it's directly equivalent to. Then in second pass simply drag out each equivalence group (recurse on each symbol's list of equivalences). Approaches 1 and 2 seem to be pretty inefficient for a large number of symbols, but I think approach 1 may be a practical option for a small number of symbols. Cheers & hth., - Alf -- blog at From cmpython at gmail.com Mon Sep 20 19:10:13 2010 From: cmpython at gmail.com (CM) Date: Mon, 20 Sep 2010 16:10:13 -0700 (PDT) Subject: develop for Windows on GNU/Linux, using Python References: <8fn6ojF783U1@mid.individual.net> Message-ID: On Sep 20, 12:46?pm, Thomas Jollans wrote: > On Monday 20 September 2010, it occurred to Default User to exclaim: > > > > > On Sun, Sep 19, 2010 at 14:31, J.O. Aho wrote: > > > Kev Dwyer wrote: > > > > if you have C-extensions in > > > > your code you'll need to compile them over Windows. ?If you want to > > > > program against the Windows API you'll need access to a Windows box. > > > > You can always cross compile, not only over OS but even CPU architecture, > > > but > > > of course testing will be more difficult, on x86 based Linux you can use > > > wine > > > or similar to test, but can give you some differences to run on a native > > > or virtualized instance. > > > < sigh > . . . > > > Well, that's about what I expected, unfortunately. ? But thanks for the > > honest replies. > > > [OT] > > So what's the alternative -- use the end user's browser as an interpreter > > for JavaScript or HTML5? > > [/OT] > > Umn, what? > > Python makes it rather easy to write portable code. But you still need to test > it properly on all platforms you want to support, because maybe there's some > platform-specific glitch you weren't aware of. My guess is, if the application the person is writing uses basic features of Python and is more like a utility that one runs from the command line, there will not be that many concerns--maybe none. He might get lucky and it will just work on Windows. But if it is a GUI app and he uses, say, wxPython, I know there can be fairly significant differences in appearance between the two platforms, sometimes deal- breakingly so (but definitely able to be worked around). A lot depends on how complex/fancy the GUI is. From davea at ieee.org Mon Sep 20 19:21:05 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 20 Sep 2010 19:21:05 -0400 Subject: Combinations or Permutations In-Reply-To: References: Message-ID: <4C97EC61.2030005@ieee.org> On 2:59 PM, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > I currently have an iteration that does this: > > #list.py > > from math import * > > list1=['a','b','c','d','e'] > list2=[] > length=len(list1) > > for it1 in range(0 ,length): > for it2 in range(it1+1, length): > list2.append([list1[it1],list1[it2]]) > > print list2 > > However, this is one of the slowest parts of my function (beaten only > by variable instantiation). I posted this on another forum looking to > see if there was a different method completely. They said that my > method was about as simple as it could get, but I might be able to > find out how to optimize my code here. > > Thanks in advance. > You're apparently looking for combinations. You're asking for all the combinations of items from the original list, taken two at a time. Permutations would also include the reverse of each item, so it would be exactly twice the size. For the specific case of two, your approach is about as simple as it can get. However, generalizing the code to handle 'r' at a time is pretty tricky. There's a library function for it in Python 2.6 and later, as mentioned by others, and the docs show a sample implementation. Clearly making a single function call is optimized in one sense. However, if you're looking for speed, chances are you could improve on your own function by changing the two loops. (tested in python 2.6) Consider: list1=['a','b','c','d','e'] list2=[] for it1, val1 in enumerate(list1): for val2 in list1[it1+1:]: list2.append([val1, val2]) print list2 DaveA From peter.milliken at gmail.com Mon Sep 20 19:44:31 2010 From: peter.milliken at gmail.com (Peter) Date: Mon, 20 Sep 2010 16:44:31 -0700 (PDT) Subject: Customising Tk widgets Message-ID: <805f1248-9217-4688-9731-4a1868cf06c3@x20g2000pro.googlegroups.com> I am using Windoze, I suspect the appearance attributes I am asking about here are platform dependent? Using Tkinter, I would like to generate a Checkbutton that is filled in with a solid colour rather than a tick mark when selected. Could somebody provide some pointers as to how I could achieve this? Also, John Shipman's Tkinter reference shows the Radiobutton drawn as a diamond and yet when I create one in Windows I get a circle - again, how and where do I need to look to change this behaviour? Thanks Peter From ian.g.kelly at gmail.com Mon Sep 20 20:00:26 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 18:00:26 -0600 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: On Mon, Sep 20, 2010 at 5:09 PM, Alf P. Steinbach /Usenet < alf.p.steinbach+usenet at gmail.com >wrote: > It seems to be the same problem as "equivalence sets". > > This problem was solved early on because e.g. Fortran compilers had to > construct such sets (equivalence partitions of a set). > > I though I'd just say "Google it!", because I know there's a standard > algorithm but I can't recall the name. However, googling it I found no > mention of that algorithm. Not even in the Wikipedia articles on equivalence > sets. > I don't recall the name either, but the standard algorithm represents the equivalence sets as trees, with the canonical name of each set being whatever happens to be at the root of tree. To find the set containing any given node, you just recurse up to the root of its tree (and then repoint the links to the root on the way back down, to optimize for the next lookup). Merging two sets is then just a matter of hanging the root of one set from the root of the other. If memory serves, this algorithm is amortized O(n) if the optimization is performed, where n is the total number of merge and lookup operations. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Sep 20 20:00:26 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 18:00:26 -0600 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: On Mon, Sep 20, 2010 at 5:09 PM, Alf P. Steinbach /Usenet < alf.p.steinbach+usenet at gmail.com >wrote: > It seems to be the same problem as "equivalence sets". > > This problem was solved early on because e.g. Fortran compilers had to > construct such sets (equivalence partitions of a set). > > I though I'd just say "Google it!", because I know there's a standard > algorithm but I can't recall the name. However, googling it I found no > mention of that algorithm. Not even in the Wikipedia articles on equivalence > sets. > I don't recall the name either, but the standard algorithm represents the equivalence sets as trees, with the canonical name of each set being whatever happens to be at the root of tree. To find the set containing any given node, you just recurse up to the root of its tree (and then repoint the links to the root on the way back down, to optimize for the next lookup). Merging two sets is then just a matter of hanging the root of one set from the root of the other. If memory serves, this algorithm is amortized O(n) if the optimization is performed, where n is the total number of merge and lookup operations. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 20:02:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 00:02:49 GMT Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <4c97f629$0$28658$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 19:45:37 +0100, Chris Withers wrote: > Well, no, that doesn't feel right. Normalisation of case, for me, means > "give me the case as the filesystem thinks it should be", What do you mean "the filesystem"? If I look at the available devices on my system now, I see: 2 x FAT-32 filesystems 1 x ext2 filesystem 3 x ext3 filesystems 1 x NTFS filesystem 1 x UDF filesystem and if I ever get my act together to install Basilisk II, as I've been threatening to do for the last five years, there will also be at least one 1 x HFS filesystem. Which one is "the" filesystem? If you are suggesting that os.path.normcase(filename) should determine which filesystem actually applies to filename at runtime, and hence work out what rules apply, what do you suggest should happen if the given path doesn't actually exist? What if it's a filesystem that the normpath developers haven't seen or considered before? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 20:07:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 00:07:07 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c97f72b$0$28658$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: > Not necessarily. Some of us have the impression that Guido deliberatly > chose an ugly format for the ternary operator. If he did, then he must have changed his mind, because there is nothing ugly about the ternary operator we ended up with. > Guido has alwasys been > against a ternary operator but the requests kept coming. So eventually > he introduced one. But the impression is that he chose an ugly format in > the hope of discouraging people to use it. That's sheer and unadulterated nonsense. The fact is that Guido changed his mind about ternary if after discovering that the work-around true-clause and condition or false-clause is buggy -- it gives the wrong answer if true-clause happens to be a false value like [], 0 or None. If I recall correctly, the bug bit Guido himself. The and-or hack, which was *very* common in Python code for many years and many versions, follows the same pattern as ternary if: true-clause if condition else false-clause It astounds me how the Python community changed it's collective mind from admiration of the elegance and simplicity of the expression when it was a buggy hack, to despising it when it became a bug-free language feature. Go figure. -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 20:09:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 00:09:51 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 17:25:09 +0000, Tim Harig wrote: >> And as a datapoint on the topic of archiving, I search usenet archives >> regularly when faced with a problem. > > Usernet users also have the right to use the X-No-Archive header field. They do? Is that right enshrined by law somewhere? Can I go to jail for human rights abuses if I archive X-No-Archive posts? > Does the fact that *you* happen to search usenet archives make using > this field immoral? Immoral and ineffective. > Shouldn't the poster have to right to determine for > themselves whether they care about the long term persistance of their > posts and be able to balance that against other factors? If you don't want your post to be read by people in six months, don't post it. It may be that news posts are, in the long term, ephemeral. But in the long term, the sun will expand and destroy the earth. In the meantime, X-No-Archive is an attempt to revise history by covering up what the poster said publicly. -- Steven From ben+python at benfinney.id.au Mon Sep 20 20:12:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 21 Sep 2010 10:12:27 +1000 Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <87bp7s5504.fsf@benfinney.id.au> Chris Withers writes: > What I expected it to mean was "give me what the filesystem thinks > this file path is", which doesn't seem unreasonable and would be a lot > more useful, no matter the platform... Two problems with that. One is that the entry specified by the path may not exist on the filesystem, but the function shouldn't care about that. It's for ?normalising? a path, whether the entry referred to exists or not. Another is that filesystems don't have a standard way of determining whether they are case-sensitive. The operating system's driver for that particular filesystem knows, but Python doesn't. So in this case you'll simply have to adjust your expectations. -- \ ?I prayed for twenty years but received no answer until I | `\ prayed with my legs.? ?Frederick Douglass, escaped slave | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Mon Sep 20 20:16:19 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 21 Sep 2010 12:16:19 +1200 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: <8fqbrdF7t7U1@mid.individual.net> AK wrote: > One definite advantage would be that if, say, it takes you 70 pages of a > given novel to figure out whether you like it enough to continue, If there was that much doubt, I would give up long before reaching the 70 page mark, regardless of reading speed. If I'm not hooked by the first page, things are unlikely to get better later. -- Greg From usenet-nospam at seebs.net Mon Sep 20 20:41:31 2010 From: usenet-nospam at seebs.net (Seebs) Date: 21 Sep 2010 00:41:31 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-21, Steven D'Aprano wrote: > On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: >> Not necessarily. Some of us have the impression that Guido deliberatly >> chose an ugly format for the ternary operator. > If he did, then he must have changed his mind, because there is nothing > ugly about the ternary operator we ended up with. Empirically, looking at the commentary on the PEP, there is something about it which a large number of participants found awkward or dislikeable. I'm not sure I'd say "ugly", but I would say that the net result is that it is likely more error-prone than an arrangement which put the conditions and clauses in the order they're in for other conditionals. > It astounds me how the Python community changed it's collective mind from > admiration of the elegance and simplicity of the expression when it was a > buggy hack, to despising it when it became a bug-free language feature. > Go figure. Well, if I had to point at an explanation, I'd guess it's the inversion. That, and things of the general form "x or y" are found in several other scripting languages, so it's a more familiar idiom. But I suspect some of it is just that, well, a number of people as of the original PEP discussion on the conditional operator disliked the "new" proposal of "x if y else z", and if they still dislike it, they'll find the conditional operator unpleasant even if it's bug-free. This may come as a total shock, but in modern scripting languages, people are often substantially concerned with style, not just with whether or not something works. :) I would probably tend to avoid the Python conditional as it currently exists because I know that a fair number of people will find it mildly confusing. Not that they won't be able to parse it, but... It's like phrasing tests negatively. It adds one chunk to the cognitive load of reading something. It increases the likelihood of the user making mistakes -- and no amount of polish and debugging of the engine can prevent users from making mistakes. The implementation in the language engine may be bug-free, but I'd be less optimistic about code which used the construct. -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 john at castleamber.com Mon Sep 20 21:03:58 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 20:03:58 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> <4C96DD24.3020400@gmail.com> Message-ID: <87eicnx5z5.fsf@castleamber.com> Terry Reedy writes: >> On 09/19/2010 10:32 PM, John Bokma wrote: > >>> the spoiler. Do you fast forward movies as well? > > I sometimes watch movies (or parts thereof) on 1.5x, especially if it > has a lot of 'filler' scenes. But only when my wife is not watching, > as she hates it. Heh, my question was somewhat rhetorical. I watch movies to slow myself down, so 1.5x is not an option. Same reason I read books slow (well, at a normal pace). If I don't I end up not being able to sleep and things go downhill from there. Also, I notice that if I want to run everything on 1.5x (or more) that I become quite annoying to the rest of my family and I want to enjoy them now, when I can. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From ckaynor at zindagigames.com Mon Sep 20 21:06:34 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 20 Sep 2010 18:06:34 -0700 Subject: Combinations or Permutations In-Reply-To: <4C97EC61.2030005@ieee.org> References: <4C97EC61.2030005@ieee.org> Message-ID: One of the advantages of using itertools is that it is written in C rather than Python (at least for CPython) and thus should run significantly faster than a pure Python implementation. Chris On Mon, Sep 20, 2010 at 4:21 PM, Dave Angel wrote: > On 2:59 PM, Seth Leija wrote: > >> I need to know how to generate a list of combinations/permutations >> (can't remember which it is). Say I have a list of variables: >> >> [a,b,c,d,...,x,y,z] >> >> I am curious if there is an optimized way to generate this: >> >> [[a,b],[a,c],[a,d],...,[x,z],[y,z]] >> >> I currently have an iteration that does this: >> >> #list.py >> >> from math import * >> >> list1=['a','b','c','d','e'] >> list2=[] >> length=len(list1) >> >> for it1 in range(0 ,length): >> for it2 in range(it1+1, length): >> list2.append([list1[it1],list1[it2]]) >> >> print list2 >> >> However, this is one of the slowest parts of my function (beaten only >> by variable instantiation). I posted this on another forum looking to >> see if there was a different method completely. They said that my >> method was about as simple as it could get, but I might be able to >> find out how to optimize my code here. >> >> Thanks in advance. >> >> You're apparently looking for combinations. You're asking for all the > combinations of items from the original list, taken two at a time. > > Permutations would also include the reverse of each item, so it would be > exactly twice the size. > > For the specific case of two, your approach is about as simple as it can > get. However, generalizing the code to handle 'r' at a time is pretty > tricky. There's a library function for it in Python 2.6 and later, as > mentioned by others, and the docs show a sample implementation. > > Clearly making a single function call is optimized in one sense. However, > if you're looking for speed, chances are you could improve on your own > function by changing the two loops. (tested in python 2.6) > > Consider: > > > list1=['a','b','c','d','e'] > list2=[] > > for it1, val1 in enumerate(list1): > for val2 in list1[it1+1:]: > list2.append([val1, val2]) > > print list2 > > > DaveA > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Sep 20 21:12:01 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 20:12:01 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> Message-ID: <87aanbx5lq.fsf@castleamber.com> Steven D'Aprano writes: > On Mon, 20 Sep 2010 17:25:09 +0000, Tim Harig wrote: > >>> And as a datapoint on the topic of archiving, I search usenet archives >>> regularly when faced with a problem. >> >> Usernet users also have the right to use the X-No-Archive header field. > > They do? Is that right enshrined by law somewhere? Can I go to jail for > human rights abuses if I archive X-No-Archive posts? I think they do have the right to use it as you have the right to ignore it ;-) I never saw the point of the whole X-No-Archive: Yes thing. What happens if I quote such a message? It's archived, right? -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From wuwei23 at gmail.com Mon Sep 20 21:30:41 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 20 Sep 2010 18:30:41 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <4c970e7f$0$21775$426a74cc@news.free.fr> Message-ID: <65e3f364-3b47-407e-a0d4-326c5a3b2f6b@k17g2000prf.googlegroups.com> Bruno Desthuilliers wrote: > alex23 a ?crit : > > Python only actually executes a module the first time it's imported, > > Beware of multithreading and modules imported under different names... > There can be issues with both in some web frameowrks. Good points, Bruno, thank you. Niklasro, a good example of Bruno's second point: running a module as a script and then importing it elsewhere later will execute the module in the second import, creating two module objects - '__main__' and ''. The issue with threading is the more important one of which to be aware. From nandytemp at gmail.com Mon Sep 20 21:36:12 2010 From: nandytemp at gmail.com (Nandy) Date: Mon, 20 Sep 2010 18:36:12 -0700 (PDT) Subject: Executing wctp script in python 2.7 for windows. Message-ID: Ok, it could be that im exhausted but I cant figure out how to execute this script in python2.7 for windows. The short: I got the file from here: http://sourceforge.net/projects/wctpxml-python/files/ and I want to execute it to send a text to my att pager using wctp via port 80. I have a commercial application that does just that but it is on demo mode and once the demo expires im not using it anymore. Any help will be greatly appreciated. The long: I have a need to get a page every time I get a notice from a system. I have work on this application and it is working great using a commercial application that uses wctp to send messages to my pager taking the unit number and the message via a command line. It goes like wctp.bat 1231234567 "you are needed". I cant use snpp or email as those ports are close but wctp is wide open. I do a bit of tcl but I have not found a viable script for this. I have only found scripts in perl and python so im going for python and if I can get this to work maybe I will have to start writing my little projects on python. So for now all I need is to learn how to execute the above script on my windows xp os, then I will edit what I need to make it work for my pager. After that is done I will try to convert that script to a windows execute so I can use it in other pc's. Last stop will be to do some html parsing to get some information off the notification. But that is at the end, for now I will be happy if someone can help me with getting the script to work and send the page... Thanks, many thanks!!!! From lie.1296 at gmail.com Mon Sep 20 21:41:42 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 21 Sep 2010 11:41:42 +1000 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c980cdb$1@dnews.tpgi.com.au> On 09/19/10 17:31, Seebs wrote: > Basically, think of what happens as I read each symbol: > > x = x + 1 if condition else x - 1 > > Up through the '1', I have a perfectly ordinary assignment of a value. > The, suddenly, it retroactively turns out that I have misunderstood > everything I've been reading. I am actually reading a conditional, and > the things I've been seeing which looked like they were definitely > part of the flow of evaluation may in fact be completely skipped. Seems like you've got a much more complicated parser than I do. You can read code from top-down, bottom-left; doing that would require keeping a mental stack of the contexts of code all the time; that's something I can't do. What I normally do when reading code is to first scan the overall structure first, then zoom in to the interesting parts until I get to an atomic structure (something I can understand in a quick glance). I'd then agglutinate some of the atoms into bigger chunks that I don't read in detail anymore. Reading code left-right is too difficult for me since then, you'd have to keep a stack that tracks how many logical parentheses (i.e. how deep in the code structure) you've seen and their types. From python.list at tim.thechases.com Mon Sep 20 21:52:24 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 20 Sep 2010 20:52:24 -0500 Subject: Down with tinyurl! In-Reply-To: <87aanbx5lq.fsf@castleamber.com> References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <4C980FD8.7070804@tim.thechases.com> On 09/20/10 20:12, John Bokma wrote: > Steven D'Aprano writes: >> On Mon, 20 Sep 2010 17:25:09 +0000, Tim Harig wrote: >>> Usernet users also have the right to use the X-No-Archive header field. >> >> They do? Is that right enshrined by law somewhere? Can I go to jail for >> human rights abuses if I archive X-No-Archive posts? > > I think they do have the right to use it as you have the right to ignore > it ;-) > > I never saw the point of the whole X-No-Archive: Yes thing. What happens > if I quote such a message? It's archived, right? The point? It's much shorter than "X-Stick-your-fingers-in-your-ears-close-your-eyes-and-yell-la-la-la-ignorantly-hoping-people-will-delete-this-message-after-some-arbitrary-period-of-time: Yes". -tkc From lie.1296 at gmail.com Mon Sep 20 21:55:23 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 21 Sep 2010 11:55:23 +1000 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c98100d$1@dnews.tpgi.com.au> On 09/20/10 19:59, Tim Harig wrote: > On 2010-09-20, Steven D'Aprano wrote: >> On Mon, 20 Sep 2010 05:46:38 +0000, Tim Harig wrote: >> >>>> I'm not particularly convinced that these are *significant* complaints >>>> about URL-shorteners. But I will say, of the last couple hundred links >>>> I've followed from Usenet posts, precisely zero of them were through >>>> URL redirectors. If I can't at least look at the URL to get some >>>> initial impression of what it's a link to, I'm not going to the trouble >>>> of swapping to a web browser to find out. >>> >>> But why should the rest of us be penalized because you make the choice >>> not to use (or not take full advantage of) all of the tools that are >>> available to you? >> >> I'm with Aahz... best practice is to post both the full and shortened >> URL, unless the URL is less that 78 characters, in which case just post >> the full version. > > Posting two URLs rather defeats the purpose of using a URL shortening > service in the first place; but, if that is what you feel is effective, > then by all means, do so. You are the master of your posts and you have > the right to post them using whatever methods and formating that you > feel is most effect; but, other people should have the same priviledge. > > Many people find tinyurl and kin to be useful tools. If you do not, > then are free to rewrite them in your reader, ignore posts using these > services, or even add a rule blocking them to your score/kill file so > that you do not have to view their ugliness. IMO, url-shortener are most (only?) useful in presentations or printed materials. When you instead have a full-fledged computer, using which you can just click on the link or copy paste; they're unnecessary and counter-productive. From debatem1 at gmail.com Mon Sep 20 22:35:03 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 20 Sep 2010 19:35:03 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: <4c98100d$1@dnews.tpgi.com.au> References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On Mon, Sep 20, 2010 at 6:55 PM, Lie Ryan wrote: > On 09/20/10 19:59, Tim Harig wrote: >> On 2010-09-20, Steven D'Aprano wrote: >>> On Mon, 20 Sep 2010 05:46:38 +0000, Tim Harig wrote: >>> >>>>> I'm not particularly convinced that these are *significant* complaints >>>>> about URL-shorteners. ?But I will say, of the last couple hundred links >>>>> I've followed from Usenet posts, precisely zero of them were through >>>>> URL redirectors. ?If I can't at least look at the URL to get some >>>>> initial impression of what it's a link to, I'm not going to the trouble >>>>> of swapping to a web browser to find out. >>>> >>>> But why should the rest of us be penalized because you make the choice >>>> not to use (or not take full advantage of) all of the tools that are >>>> available to you? >>> >>> I'm with Aahz... best practice is to post both the full and shortened >>> URL, unless the URL is less that 78 characters, in which case just post >>> the full version. >> >> Posting two URLs rather defeats the purpose of using a URL shortening >> service in the first place; but, if that is what you feel is effective, >> then by all means, do so. ?You are the master of your posts and you have >> the right to post them using whatever methods and formating that you >> feel is most effect; but, other people should have the same priviledge. >> >> Many people find tinyurl and kin to be useful tools. ?If you do not, >> then are free to rewrite them in your reader, ignore posts using these >> services, or even add a rule blocking them to your score/kill file so >> that you do not have to view their ugliness. > > IMO, url-shortener are most (only?) useful in presentations or printed > materials. When you instead have a full-fledged computer, using which > you can just click on the link or copy paste; they're unnecessary and > counter-productive. I use them when I want to conceal the target of the link. Usually here that just means its a letmegooglethatforyou.com link, which I find more amusing than is probably healthy. Geremy Condra From ethan at stoneleaf.us Mon Sep 20 22:39:21 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 20 Sep 2010 19:39:21 -0700 Subject: os.path.normcase rationale? In-Reply-To: <4c97f629$0$28658$c3e8da3@news.astraweb.com> References: <87lj727lu7.fsf@benfinney.id.au> <4c97f629$0$28658$c3e8da3@news.astraweb.com> Message-ID: <4C981AD9.3060102@stoneleaf.us> Steven D'Aprano wrote: > On Mon, 20 Sep 2010 19:45:37 +0100, Chris Withers wrote: > > >>Well, no, that doesn't feel right. Normalisation of case, for me, means >>"give me the case as the filesystem thinks it should be", > > > What do you mean "the filesystem"? Well, if it were me, it would be either the filesystem in the path that's being norm'ed, or if no path is explicity stated, the filesystem that is hosting the current directory. > If I look at the available devices on my system now, I see: > > 2 x FAT-32 filesystems > 1 x ext2 filesystem > 3 x ext3 filesystems > 1 x NTFS filesystem > 1 x UDF filesystem > > and if I ever get my act together to install Basilisk II, as I've been > threatening to do for the last five years, there will also be at least > one 1 x HFS filesystem. Which one is "the" filesystem? > > If you are suggesting that os.path.normcase(filename) should determine > which filesystem actually applies to filename at runtime, and hence work > out what rules apply, what do you suggest should happen if the given path > doesn't actually exist? What if it's a filesystem that the normpath > developers haven't seen or considered before? Something along those lines seems to be happening now. Observe what happens on my XP machine with an NTFS drive. --> import foo Traceback (most recent call last): File "", line 1, in ImportError: No module named foo --> import FOO Traceback (most recent call last): File "", line 1, in ImportError: No module named FOO --> import fOo Traceback (most recent call last): File "", line 1, in ImportError: No module named fOo --> import Foo Foo has been imported! ~Ethan~ From ldo at geek-central.gen.new_zealand Mon Sep 20 22:55:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 14:55:49 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: In message , geremy condra wrote: > Usually here that just means its a letmegooglethatforyou.com link, which I > find more amusing than is probably healthy. Why hold back, I also use fuckinggoogleit.com. :) From john at castleamber.com Mon Sep 20 23:00:27 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 22:00:27 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <87r5gn3ino.fsf@castleamber.com> Tim Chase writes: > On 09/20/10 20:12, John Bokma wrote: >> Steven D'Aprano writes: >>> On Mon, 20 Sep 2010 17:25:09 +0000, Tim Harig wrote: >>>> Usernet users also have the right to use the X-No-Archive header field. >>> >>> They do? Is that right enshrined by law somewhere? Can I go to jail for >>> human rights abuses if I archive X-No-Archive posts? >> >> I think they do have the right to use it as you have the right to ignore >> it ;-) >> >> I never saw the point of the whole X-No-Archive: Yes thing. What happens >> if I quote such a message? It's archived, right? > > The point? It's much shorter than > "X-Stick-your-fingers-in-your-ears-close-your-eyes-and-yell-la-la-la-ignorantly-hoping-people-will-delete-this-message-after-some-arbitrary-period-of-time: > Yes". Well, X-Archive: No is even shorter ;-). What I mean is, it's just a request, nothing more and nothing less. DejaNews honored it, and Google still does. But it doesn't stop other people from archiving posts. I can imagine that for some automatic generated messages someone might think XNA is a good thing. But for human written messages, I just don't see the point. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From usenet-nospam at seebs.net Mon Sep 20 23:01:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 21 Sep 2010 03:01:53 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On 2010-09-21, geremy condra wrote: > I use them when I want to conceal the target of the link. Usually here > that just means its a letmegooglethatforyou.com link, which I find > more amusing than is probably healthy. I thought the idea was funny at first. Then I posted a question on an IRC channel. I had done a ton of searching already, and I started by explaining the top three near-solutions I'd found and why each of them wasn't actually a solution to my problem. And someone handed me a URL... which was to lmgtfy on the first search terms I tried. And this caused me to realize just how amazingly insulting that can be when done to someone who *did* already do the research. While certainly there's plenty of people who didn't do their own searching, there's also a fair number who are asking a question because they DID try searching and there was some problem with one or more of the answers. -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 jerry.fleming at saybot.com Mon Sep 20 23:21:55 2010 From: jerry.fleming at saybot.com (Jerry Fleming) Date: Tue, 21 Sep 2010 11:21:55 +0800 Subject: re and locale/unicode Message-ID: Hi, Having the following python code: import locale import re locale.setlocale(locale.LC_ALL, 'zh_CN.utf8') re.findall('(?uL)\s+', u'\u2001\u3000\x20', re.U|re.L) re.findall('\s+', u'\u2001\u3000\x20', re.U|re.L) re.findall('(?uL)\s+', u'\u2001\u3000\x20') I was wondering why doesn't it find the unicode space chars \u2001 and \u3000? The python docs for re module says: When the LOCALE and UNICODE flags are not specified, matches any whitespace character; this is equivalent to the set [ \t\n\r\f\v]. With LOCALE, it will match this set plus whatever characters are defined as space for the current locale. If UNICODE is set, this will match the characters [ \t\n\r\f\v] plus whatever is classified as space in the Unicode character properties database. which doesn't seem to work. Any ideas? From john at castleamber.com Mon Sep 20 23:25:18 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 22:25:18 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: <87mxrb3hi9.fsf@castleamber.com> Seebs writes: > And this caused me to realize just how amazingly insulting that can be when > done to someone who *did* already do the research. Exactly. I hate lmgtfy links hidden in a tiny url. It's not only insulting to the OP but also to people who try to learn something and end up on a google search page they could've come up with themselves. > While certainly there's plenty of people who didn't do their own searching, > there's also a fair number who are asking a question because they DID try > searching and there was some problem with one or more of the answers. Yup, exactly. Or people who did a lot of searching but somehow were not able to compile a good query. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From debatem1 at gmail.com Mon Sep 20 23:26:18 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 20 Sep 2010 20:26:18 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On Mon, Sep 20, 2010 at 7:55 PM, Lawrence D'Oliveiro wrote: > In message , geremy > condra wrote: > >> Usually here that just means its a letmegooglethatforyou.com link, which I >> find more amusing than is probably healthy. > > Why hold back, I also use fuckinggoogleit.com. :) Yeah, I need to start using that- a shocking number of people don't seem to realize that lmgtfy is a joke. I had a person a few months ago seriously thank me for giving them a link that did the typing for them. Light a man a fire and he'll be warm for an hour, light a man *on* fire and he'll be warm for the rest of his life... Geremy Condra From debatem1 at gmail.com Mon Sep 20 23:55:57 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 20 Sep 2010 20:55:57 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On Mon, Sep 20, 2010 at 8:01 PM, Seebs wrote: > On 2010-09-21, geremy condra wrote: >> I use them when I want to conceal the target of the link. Usually here >> that just means its a letmegooglethatforyou.com link, which I find >> more amusing than is probably healthy. > > I thought the idea was funny at first. > > Then I posted a question on an IRC channel. ?I had done a ton of searching > already, and I started by explaining the top three near-solutions I'd found > and why each of them wasn't actually a solution to my problem. ?And someone > handed me a URL... which was to lmgtfy on the first search terms I tried. > > And this caused me to realize just how amazingly insulting that can be when > done to someone who *did* already do the research. > > While certainly there's plenty of people who didn't do their own searching, > there's also a fair number who are asking a question because they DID try > searching and there was some problem with one or more of the answers. It's a joke. Admittedly it's a bit pointed, but it's a joke nonetheless, and it does at least provide what I consider to be two valuable pieces of information: that you should have googled this before asking, and what you should have googled for. If I miss and you've done your homework already, well, at least you get the smug satisfaction of knowing that I was too stupid to understand your question. Geremy Condra From python at mrabarnett.plus.com Mon Sep 20 23:57:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 21 Sep 2010 04:57:21 +0100 Subject: re and locale/unicode In-Reply-To: References: Message-ID: <4C982D21.2070406@mrabarnett.plus.com> On 21/09/2010 04:21, Jerry Fleming wrote: > Hi, > > Having the following python code: > > > import locale > import re > > locale.setlocale(locale.LC_ALL, 'zh_CN.utf8') > re.findall('(?uL)\s+', u'\u2001\u3000\x20', re.U|re.L) > re.findall('\s+', u'\u2001\u3000\x20', re.U|re.L) > re.findall('(?uL)\s+', u'\u2001\u3000\x20') > > > I was wondering why doesn't it find the unicode space chars \u2001 and > \u3000? The python docs for re module says: > > When the LOCALE and UNICODE flags are not specified, matches any > whitespace character; this is equivalent to the set [ \t\n\r\f\v]. With > LOCALE, it will match this set plus whatever characters are defined as > space for the current locale. If UNICODE is set, this will match the > characters [ \t\n\r\f\v] plus whatever is classified as space in the > Unicode character properties database. > > which doesn't seem to work. Any ideas? Use the regex module? ;-) http://pypi.python.org/pypi/regex BTW, LOCALE is for locale-specific bytestrings. Basically the choice is between ASCII (bytestring) (default in Python 2), LOCALE (bytestring) and UNICODE (Unicode string), so don't bother combining them. From steve-REMOVE-THIS at cybersource.com.au Tue Sep 21 01:01:45 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 05:01:45 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: <4c983c38$0$11089$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 03:01:53 +0000, Seebs wrote: > On 2010-09-21, geremy condra wrote: >> I use them when I want to conceal the target of the link. Usually here >> that just means its a letmegooglethatforyou.com link, which I find more >> amusing than is probably healthy. > > I thought the idea was funny at first. > > Then I posted a question on an IRC channel. I had done a ton of > searching already, and I started by explaining the top three > near-solutions I'd found and why each of them wasn't actually a solution > to my problem. And someone handed me a URL... which was to lmgtfy on > the first search terms I tried. Yeah, some people are just self-righteous dicks. Hey, that would be an *awesome* google bombing project... to get lmgtfy to come up as the first link for "self-righteous dicks". 4chan, where are you when we need you??? > And this caused me to realize just how amazingly insulting that can be > when done to someone who *did* already do the research. Yes, although in fairness people aren't mind readers. If you (generic you) don't give any indication of doing the research, you can expect to be ignored or told to RTFM. Google is just the new FM. Personally, I found LMGTFY to be amusing for about 1.3 microseconds, followed by annoying. The joke also falls flat when you send somebody there, and they have Javascript turned off. I prefer the old fashioned version: "Google Is Your Friend" followed by a URL to the appropriate google's search results page. Or even more to the point: "Did you bother to google for the answer first? Because the very first page that comes up gives exactly the answer you want." Although sometimes people genuinely don't know what search terms they should be using, or if they're too generic. -- Steven From usenet-nospam at seebs.net Tue Sep 21 01:11:37 2010 From: usenet-nospam at seebs.net (Seebs) Date: 21 Sep 2010 05:11:37 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-21, Steven D'Aprano wrote: > On Tue, 21 Sep 2010 03:01:53 +0000, Seebs wrote: >> On 2010-09-21, geremy condra wrote: >> Then I posted a question on an IRC channel. I had done a ton of >> searching already, and I started by explaining the top three >> near-solutions I'd found and why each of them wasn't actually a solution >> to my problem. And someone handed me a URL... which was to lmgtfy on >> the first search terms I tried. > Yes, although in fairness people aren't mind readers. If you (generic > you) don't give any indication of doing the research, you can expect to > be ignored or told to RTFM. Google is just the new FM. See above -- "I started by explaining..." > Although sometimes people genuinely don't know what search terms they > should be using, or if they're too generic. Yes. A few of my friends periodically ask me to search for something because somehow my pick of search terms tends to work better than theirs. We're not actually sure why. -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-REMOVE-THIS at cybersource.com.au Tue Sep 21 01:43:09 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 05:43:09 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: <4c9845ed$0$11089$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 05:11:37 +0000, Seebs wrote: > On 2010-09-21, Steven D'Aprano > wrote: >> On Tue, 21 Sep 2010 03:01:53 +0000, Seebs wrote: >>> On 2010-09-21, geremy condra wrote: Then I posted >>> a question on an IRC channel. I had done a ton of searching already, >>> and I started by explaining the top three near-solutions I'd found and >>> why each of them wasn't actually a solution to my problem. And >>> someone handed me a URL... which was to lmgtfy on the first search >>> terms I tried. > >> Yes, although in fairness people aren't mind readers. If you (generic >> you) don't give any indication of doing the research, you can expect to >> be ignored or told to RTFM. Google is just the new FM. > > See above -- "I started by explaining..." Yes, I know that. I sympathized with your experience and explicitly said I was talking about "generic you". -- Steven From usenet-nospam at seebs.net Tue Sep 21 01:49:03 2010 From: usenet-nospam at seebs.net (Seebs) Date: 21 Sep 2010 05:49:03 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> <4c9845ed$0$11089$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-21, Steven D'Aprano wrote: > Yes, I know that. I sympathized with your experience and explicitly said > I was talking about "generic you". Hah! Then it was *I* who wasn't reading carefully enough! I bet you didn't expect *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 alf.p.steinbach+usenet at gmail.com Tue Sep 21 02:19:48 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 21 Sep 2010 08:19:48 +0200 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: * Alf P. Steinbach /Usenet, on 21.09.2010 01:09: > * Astley Le Jasper, on 20.09.2010 23:42: >> I have a list of tuples that indicate a relationship, ie a is related >> to b, b is related to c etc etc. What I want to do is cluster these >> relationships into groups. An item will only be associated with a >> single cluster. >> >> Before I started, I wondered if there was any particular tool within >> Python I should be looking at. I don't expect anyone to code this for >> me, just say ... "you need to look at using x". I was going to use >> populate a dictionary and >> >> Sorry for being so vague. >> >> Example Data: >> [(a,b) >> (a,c) >> (a,d) >> (b,c) >> (b,d) >> (c,d) >> (e,f) >> (e,g) >> (f,g) >> (h,i)] >> >> Output (grouping id, item ref) >> (1,a), >> (1,b), >> (1,c), >> (1,d), >> (2,e), >> (2,f), >> (2,g), >> (3,h), >> (3,i) > > It seems to be the same problem as "equivalence sets". > > This problem was solved early on because e.g. Fortran compilers had to construct > such sets (equivalence partitions of a set). > > I though I'd just say "Google it!", because I know there's a standard algorithm > but I can't recall the name. However, googling it I found no mention of that > algorithm. Not even in the Wikipedia articles on equivalence sets. > > A number of approaches spring to mind: > > Approach 1: > Multi-pass. Originally you assign a distinct set number to each symbol. > In each pass through the symbols you replace one number with another as > per one of the equivalence specs. Stop when no replacements are done. > > Approach 2: > Merging. For each new equivalence A=B you check whether A has been assigned > to a set, if not you create a new one, call that S1, and ditto for B, S2. > Merge S1 and S2, e.g. move all elements of S2 to S1. > > Approach 3: > In a first pass convert the data to more explicit form, linking each symbol > to the symbols it's directly equivalent to. Then in second pass simply drag > out each equivalence group (recurse on each symbol's list of equivalences). > > Approaches 1 and 2 seem to be pretty inefficient for a large number of symbols, > but I think approach 1 may be a practical option for a small number of symbols. Uhm, thinking about it (it must have been my unconscious mind doing the work, it just popped into my head), if you first sort each individual equivalence relation so that you never have e.g. C=A but only A=C and so on, and then sort the list of equivalences, then it should reduce to walking the list and just starting a new set whenever a symbol is encountered that isn't yet in a set. class Attributes: pass sym = Attributes() for name in ("a", "b", "c", "d", "e", "f", "g", "h", "i"): setattr( sym, name, name ) eq_specs = [ (sym.a, sym.d), (sym.b, sym.a), (sym.b, sym.c), (sym.b, sym.d), (sym.c, sym.d), (sym.c, sym.a), (sym.e, sym.f), (sym.e, sym.g), (sym.f, sym.g), (sym.h, sym.i), ] equalities = [] for eq in eq_specs: sorted_eq = eq if eq[0] <= eq[1] else (eq[1], eq[0]) equalities.append( sorted_eq ) equalities.sort() eq_sets = {} eq_set_ids = {} current_eq_set_id = 0 for eq in equalities: if eq_set_ids.get( eq[0] ) is None: current_eq_set_id += 1 eq_set_ids[eq[0]] = current_eq_set_id eq_sets[current_eq_set_id] = set( eq[0] ) eq_set_id = eq_set_ids[eq[0]] eq_set_ids[eq[1]] = eq_set_id eq_sets[eq_set_id].add( eq[1] ) for eq_set_id in eq_sets.keys(): for sym_name in eq_sets[eq_set_id]: print( "{}, {}".format( eq_set_id, sym_name ) ) 1, a 1, c 1, b 1, d 2, e 2, g 2, f 3, i 3, h Disclaimer: for me it's pretty late in day/night. Cheers & hth., - Alf -- blog at From ian.g.kelly at gmail.com Tue Sep 21 02:49:48 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Sep 2010 00:49:48 -0600 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: On Tue, Sep 21, 2010 at 12:19 AM, Alf P. Steinbach /Usenet < alf.p.steinbach+usenet at gmail.com >wrote: > Uhm, thinking about it (it must have been my unconscious mind doing the > work, it just popped into my head), if you first sort each individual > equivalence relation so that you never have e.g. C=A but only A=C and so on, > and then sort the list of equivalences, then it should reduce to walking the > list and just starting a new set whenever a symbol is encountered that isn't > yet in a set. > This won't work for all inputs. Consider the input: [('a', 'd'), ('b', 'c'), ('c', 'd')] Expected Output: 1, a 1, b 1, c 1, d Actual Output: 1, a 1, d 2, c 2, b 2, d Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Sep 21 03:01:07 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 21 Sep 2010 00:01:07 -0700 (PDT) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Sep 20, 12:25?pm, Tim Harig wrote: > On 2010-09-20, Brian Victor wrote: > Usernet users also have the right to use the X-No-Archive header field. > Does the fact that *you* happen to search usenet archives make using this > field immoral? ?Shouldn't the poster have to right to determine for > themselves whether they care about the long term persistance of their posts > and be able to balance that against other factors? X No Archive should have never been allowed and should be removed immediately and forever. What is the point of posting when your words will be gone form memory in a short time? Why not save your fingers an painful and early demise and go watch wheel of fortune instead? Heck, i can't tell you how much enjoyment i get from reading over some of my old posts. Actually i think i get more enjoyment reading over them then when creating them. Besides, when people X-No_Archive it makes me a bit suspicious of their true intentions. Are they just trolling or maybe blowing hot air from an alter ego? Or, are they paranoid nitwits with twenty-two bolt locks on their front door who sleep with wads of cotton balls crammed in their ear canals for fear of carnivorous ear wigs? Do they carefully craft tin foil hats in agonizing 3d detail using solid works to maximize the defecting efficiency of each and every facet in an effort to ward off the ever present mind altering signals emanating from cell phone towers in an overly ambitious attempt to rebel against the interplanetary borg-ish assimilation's ever increasing empirical expansion? 8-O ...Or, who knows, maybe they just shy? From rantingrick at gmail.com Tue Sep 21 03:12:48 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 21 Sep 2010 00:12:48 -0700 (PDT) Subject: Customising Tk widgets References: <805f1248-9217-4688-9731-4a1868cf06c3@x20g2000pro.googlegroups.com> Message-ID: <8716f5a1-b5b5-4c34-9962-94bd49e97ef7@w4g2000vbh.googlegroups.com> On Sep 20, 6:44?pm, Peter wrote: > I am using Windoze, I suspect the appearance attributes I am asking > about here are platform dependent? not really. > Using Tkinter, I would like to generate a Checkbutton that is filled > in with a solid colour rather than a tick mark when selected. Why, who cares if it's a check or solid box. > Could somebody provide some pointers as to how I could achieve this? Ok, Ok, if you *really* need to see this just create a custom widget using either the canvas or a couple of Label widgets. (psst: i would use the canvas) For extra credit you could create a custom "ChoiceBox" widget. Which is a scrollable box containing an unlimited number of check buttons. > Also, John Shipman's Tkinter reference shows the Radiobutton drawn as > a diamond and yet when I create one in Windows I get a circle - again, > how and where do I need to look to change this behaviour? Hmm, me thinks John ist using Linistz, at least me thinks? From duncan.booth at invalid.invalid Tue Sep 21 03:37:33 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Sep 2010 07:37:33 GMT Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> <4c975046$0$11113$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Mon, 20 Sep 2010 11:53:48 +0000, Duncan Booth wrote: > >> I was going to suggest overriding items() (or iteritems() for Python >> 2.x), but while that is another hole that your values leak out it isn't >> the hole used by the dict constructor. > > Yes, I already override items(), keys(), values(), their iter... > versions, and just about every damn method that dicts have :/ > > I suspect that the dict() constructor is just grabbing the key/value > pairs directly from the underlying hash table. If that's the case, my > choices are to not inherit from dict at all, or take your suggestion and > keep an auxiliary dict alongside the main one. > >From Python 2.x sources that I have lying around (sorry I have no idea if the code for 3.x has changed much): dict_init calls dict_update_common which does: if (PyObject_HasAttrString(arg, "keys")) result = PyDict_Merge(self, arg, 1); else result = PyDict_MergeFromSeq2(self, arg, 1); PyDict_Merge says: /* We accept for the argument either a concrete dictionary object, * or an abstract "mapping" object. For the former, we can do * things quite efficiently. For the latter, we only require that * PyMapping_Keys() and PyObject_GetItem() be supported. */ which basically boils down to "if PyDict_Check() is true then iterate directly over the structure and use the existing key, hash and value fields to insert into the new dict". If PyDict_Check() is false then it iterates over the keys and calls PyObject_GetItem(). -- Duncan Booth http://kupuguy.blogspot.com From rantingrick at gmail.com Tue Sep 21 03:37:58 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 21 Sep 2010 00:37:58 -0700 (PDT) Subject: Syntax highlighting [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> <4c96ff65$0$11113$c3e8da3@news.astraweb.com> Message-ID: <74717128-54ef-4de3-a18e-f7e921a2aa97@q26g2000vbn.googlegroups.com> On Sep 20, 1:29?am, Steven D'Aprano wrote: > To my eyes, the feature of syntax highlighting that alone makes it > worthwhile, its killer feature, is that I can set comments and docstrings > to grey. When I'm scanning code, being able to slide my eyes over greyed- > out comments and docstrings and ignore them with essentially zero effort > is a huge help. That's the thing I most miss, more than anything else, > when using a dumb editor. Well dumb editors use syntax highlighting also... specifically the ones that default to bright (attention grabbing!) colors for comments and/or docstrings... like the color RED! Gawd i hate that! Never should a comment be a bright color, and RED is the worst choice of all! Grey for comments, orange for keywords, purple for builtins, and green for strings is pure bliss. Save red for scary things like global variables and such. That way you know where the hemorrhaging is coming from! From duncan.booth at invalid.invalid Tue Sep 21 04:17:00 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Sep 2010 08:17:00 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > That's sheer and unadulterated nonsense. The fact is that Guido changed > his mind about ternary if after discovering that the work-around > > true-clause and condition or false-clause > > is buggy -- it gives the wrong answer if true-clause happens to be a > false value like [], 0 or None. If I recall correctly, the bug bit Guido > himself. > > The and-or hack, which was *very* common in Python code for many years > and many versions, follows the same pattern as ternary if: > > true-clause if condition else false-clause > I guess you have worked hard to forget the and-or hack. It was actually: condition and true-clause or false-clause so its not quite the same pattern. Of course there's also the bug fixed version which I suspect was so ugly it was the real trigger for getting a real ternary operator: (condition and [true-clause] or [false-clause])[0] -- Duncan Booth http://kupuguy.blogspot.com From ldo at geek-central.gen.new_zealand Tue Sep 21 04:32:32 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:32:32 +1200 Subject: This Is International =?UTF-8?B?RG9u4oCZdC1TcXVhd2stTGlrZS1BLVBhcnJvdA==?= Day References: Message-ID: Next we need an International Surfin? Bird day, a day to go around and tell everybody that the bird bird bird, the bird is the word. (Yes, *that* FG episode was just on earlier.) From ldo at geek-central.gen.new_zealand Tue Sep 21 04:36:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:36:05 +1200 Subject: develop for Windows on GNU/Linux, using Python References: Message-ID: In message , Kev Dwyer wrote: > To be confident that your code is good you need to test it on a Windows > box (we all test, right?). Preferably more than one. Test with Seven as well as Vista (yes, there are still some Vista users out there). What about the difference between Starter versus Home Basic versus Home Premium versus Professional versus Ultimate versus whatever? To be 100% safe, you probably need to test with all those as well. Test on machines running the various major antivirus packages, because you have no idea how they might screw things up. In other words, with Windows the guideline is: test till it hurts. Then test some more. From arndt.roger at addcom.de Tue Sep 21 04:37:11 2010 From: arndt.roger at addcom.de (Arndt Roger Schneider) Date: Tue, 21 Sep 2010 10:37:11 +0200 Subject: Customising Tk widgets References: <805f1248-9217-4688-9731-4a1868cf06c3@x20g2000pro.googlegroups.com> Message-ID: Peter schrieb: > I am using Windoze, I suspect the appearance attributes I am asking > about here are platform dependent? > > Using Tkinter, I would like to generate a Checkbutton that is filled > in with a solid colour rather than a tick mark when selected. > tk = Tk() tk.option_add("*Checkbutton.inidcatorOn", 0) > Could somebody provide some pointers as to how I could achieve this? > > Also, John Shipman's Tkinter reference shows the Radiobutton drawn as > a diamond and yet when I create one in Windows I get a circle - again, > how and where do I need to look to change this behaviour? > > Thanks > Peter Shipman's screenshots are made under Tk 8.4/X11, featureing the motif look-a-like. Tk 8.4 follows the windows user style guide (windows95) under windows. You could still get the motif look under windows: Tk 8.5 is bundled with a theming engine ttk, this engine uses the built-in theming engine under windows xp and later, but also allows you to supplant this engine. The related ttk theme is called "classic". -roger From ldo at geek-central.gen.new_zealand Tue Sep 21 04:46:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:46:53 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: In message , geremy condra wrote: > ... a shocking number of people don't seem to realize that lmgtfy is a > joke. I had a person a few months ago seriously thank me for giving them a > link that did the typing for them. Tell them to tell all their friends about it. :) From ldo at geek-central.gen.new_zealand Tue Sep 21 04:49:25 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:49:25 +1200 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> <87r5gn3ino.fsf@castleamber.com> Message-ID: In message <87r5gn3ino.fsf at castleamber.com>, John Bokma wrote: > Well, X-Archive: No is even shorter ;-). X-No-Bananas: Yes From ldo at geek-central.gen.new_zealand Tue Sep 21 04:50:33 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:50:33 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: In message , rantingrick wrote: > X No Archive should have never been allowed and should be removed > immediately and forever. What is the point of posting when your words > will be gone form memory in a short time? My words are for now. All I think are fleeting thoughts; Tomorrow I am dust. From arnodel at gmail.com Tue Sep 21 04:51:38 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 21 Sep 2010 01:51:38 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: On Sep 20, 10:42?pm, Astley Le Jasper wrote: > I have a list of tuples that indicate a relationship, ie a is related > to b, b is related to c etc etc. What I want to do is cluster these > relationships into groups. ?An item will only be associated with a > single cluster. > > Before I started, I wondered if there was any particular tool within > Python I should be looking at. I don't expect anyone to code this for > me, just say ... "you need to look at using x". I was going to use > populate a dictionary and > > Sorry for being so vague. > > Example Data: > [(a,b) > (a,c) > (a,d) > (b,c) > (b,d) > (c,d) > (e,f) > (e,g) > (f,g) > (h,i)] > > Output (grouping id, item ref) > (1,a), > (1,b), > (1,c), > (1,d), > (2,e), > (2,f), > (2,g), > (3,h), > (3,i) What you are doing is finding the connected components of a graph. There aren't any tools in the standard library to do this. But for example python-graph [1] has a connected_components function. Probably other packages will. If you don't want a dependency, it is not too hard to implement if you think about it. [1] http://code.google.com/p/python-graph/ -- Arnaud From ldo at geek-central.gen.new_zealand Tue Sep 21 04:53:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:53:46 +1200 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: In message , Dennis Lee Bieber wrote: > On Mon, 20 Sep 2010 20:12:01 -0500, John Bokma > declaimed the following in gmane.comp.python.general: > > >> I never saw the point of the whole X-No-Archive: Yes thing. What happens >> if I quote such a message? It's archived, right? > > Compliant clients (like Agent) will echo the X-No-Archive: Yes in > YOUR reply -- so it too will be deleted at some point in time. Words said once, and then Never to be heard again. Fuck posterity! From ldo at geek-central.gen.new_zealand Tue Sep 21 04:54:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:54:20 +1200 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: In message <87aanbx5lq.fsf at castleamber.com>, John Bokma wrote: > I never saw the point of the whole X-No-Archive: Yes thing. What happens > if I quote such a message? It's archived, right? Where did they come from? Posting fragments, followed up-- Originals? No more. From bob.aalsma at aalsmacons.nl Tue Sep 21 04:56:27 2010 From: bob.aalsma at aalsmacons.nl (BobAalsma) Date: Tue, 21 Sep 2010 01:56:27 -0700 (PDT) Subject: Newbie: plist & control characters? Message-ID: <9082a271-5f9c-49e4-8f83-3957184e7b92@j2g2000vbo.googlegroups.com> I'm trying to modify a plist file. The modification works properly, but I'm having difficulties in finding the proper way to restore. The file contains HTML strings like "$#226;" and either this gets replaced by "?" (which I don't want) but the programme completes or the program fails when I try to use the data wrapper. I must be doing something wrong, but can't find what (and this includes Google searches). Please help. Failing text: def omkattenAgents(AANGRIJPINGSPUNT, KLANTNAAM_OUT, KLANTNAAM_IN, ZOEKSET1_OUT, ZOEKSET1_IN, ZOEKSET2_OUT, ZOEKSET2_IN): tussentekst = plistlib.Data(plistlib.readPlist(os.path.join(root,bestandsnaam))) tussenblok = tussentekst.data ding = tussenblok['RepresentedObject'] tekststring = ding.get('Name') tekststring_0 = tekststring.replace(KLANTNAAM_OUT,KLANTNAAM_IN) tekststring_1 = tekststring_0.replace(ZOEKSET1_OUT,ZOEKSET1_IN) tekststring_2 = tekststring_1.replace(ZOEKSET2_OUT,ZOEKSET2_IN) tekststring_3 = tekststring_2.replace(ZOEKSET1_OUT_LOWER,ZOEKSET1_IN_LOWER) tekststring_4 = tekststring_3.replace(ZOEKSET2_OUT_LOWER,ZOEKSET2_IN_LOWER) ding['Name'] = tekststring_4 tussenblok['RepresentedObject'] = ding tussentekst.data = tussenblok plistlib.Data(plistlib.writePlist(tussentekst, os.path.join(root,bestandsnaam))) Text in Terminal: File "LeadDevice_klant_nieuw_aanmaken.py", line 66, in omkattenAgents(AANGRIJPINGSPUNT, KLANTNAAM_OUT, KLANTNAAM_IN, ZOEKSET1_OUT, ZOEKSET1_IN, ZOEKSET2_OUT, ZOEKSET2_IN) File "/Volumes/LeadDevice-2/LeadDevice/Programmatuur/Python/ LeadDeviceProductie/LeadDevice_klant_nieuw_naamcorrectie_intern.py", line 162, in omkattenAgents plistlib.Data(plistlib.writePlist(tussentekst, os.path.join(root,bestandsnaam))) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 94, in writePlist writer.writeValue(rootObject) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 254, in writeValue self.writeData(value) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 267, in writeData for line in data.asBase64(maxlinelength).split("\n"): File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 379, in asBase64 return _encodeBase64(self.data, maxlinelength) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 361, in _encodeBase64 chunk = s[i : i + maxbinsize] TypeError: unhashable type The difference between failure and completion with replacing HTML is the statement tussentekst.data = tussenblok (failure) tussentekst = tussenblok (completion with replacing) Regards, Bob From astley.lejasper at gmail.com Tue Sep 21 05:07:59 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Tue, 21 Sep 2010 02:07:59 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: Thanks for the feedback both. I'll have a look at these. One of the frustrating things I find about python is that there are so many modules. There have been times when I've spend ages doing something and then some has said, "Oh yeah, there is a module for that". Anyway. Nearly finished. Cheers ALJ From stef.mientki at gmail.com Tue Sep 21 05:08:27 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 21 Sep 2010 11:08:27 +0200 Subject: utf-8 coding sometimes it works, most of the time it don't work. Message-ID: <4C98760B.8070400@gmail.com> hello, I've a pyjamas application (python to javascript translator), that can be run (as pure python) in MSHTML (IE Com interface) . When running this python application from the command line ( or launched from another Python program), the wrong character encoding (probably windows-1252) is used. When I run this program from PyScripter ( either internal engine or remote engine), MSHTML shows the correct character encoding, perfect! In the main file, and in the major files that constains strings I've added the following 2 lines: # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals >From the Pyjamas and PyScripter group I've no answer untill now. any clues where to look for the problem ? thanks, Stef Mientki From arnodel at gmail.com Tue Sep 21 05:13:06 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 21 Sep 2010 02:13:06 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: <3463624f-405e-483f-9c21-52989d9a874f@k9g2000vbo.googlegroups.com> On Sep 21, 7:19?am, "Alf P. Steinbach /Usenet" wrote: > * Alf P. Steinbach /Usenet, on 21.09.2010 01:09: > > > > > > > * Astley Le Jasper, on 20.09.2010 23:42: > >> I have a list of tuples that indicate a relationship, ie a is related > >> to b, b is related to c etc etc. What I want to do is cluster these > >> relationships into groups. An item will only be associated with a > >> single cluster. > > >> Before I started, I wondered if there was any particular tool within > >> Python I should be looking at. I don't expect anyone to code this for > >> me, just say ... "you need to look at using x". I was going to use > >> populate a dictionary and > > >> Sorry for being so vague. > > >> Example Data: > >> [(a,b) > >> (a,c) > >> (a,d) > >> (b,c) > >> (b,d) > >> (c,d) > >> (e,f) > >> (e,g) > >> (f,g) ? > >> (h,i)] > > >> Output (grouping id, item ref) > >> (1,a), > >> (1,b), > >> (1,c), > >> (1,d), > >> (2,e), > >> (2,f), > >> (2,g), > >> (3,h), > >> (3,i) > > > It seems to be the same problem as "equivalence sets". > > > This problem was solved early on because e.g. Fortran compilers had to construct > > such sets (equivalence partitions of a set). > > > I though I'd just say "Google it!", because I know there's a standard algorithm > > but I can't recall the name. However, googling it I found no mention of that > > algorithm. Not even in the Wikipedia articles on equivalence sets. > > > A number of approaches spring to mind: > > > Approach 1: > > Multi-pass. Originally you assign a distinct set number to each symbol. > > In each pass through the symbols you replace one number with another as > > per one of the equivalence specs. Stop when no replacements are done. > > > Approach 2: > > Merging. For each new equivalence A=B you check whether A has been assigned > > to a set, if not you create a new one, call that S1, and ditto for B, S2. > > Merge S1 and S2, e.g. move all elements of S2 to S1. > > > Approach 3: > > In a first pass convert the data to more explicit form, linking each symbol > > to the symbols it's directly equivalent to. Then in second pass simply drag > > out each equivalence group (recurse on each symbol's list of equivalences). > > > Approaches 1 and 2 seem to be pretty inefficient for a large number of symbols, > > but I think approach 1 may be a practical option for a small number of symbols. > > Uhm, thinking about it (it must have been my unconscious mind doing the work, it > just popped into my head), if you first sort each individual equivalence > relation so that you never have e.g. C=A but only A=C and so on, and then sort > the list of equivalences, then it should reduce to walking the list and just > starting a new set whenever a symbol is encountered that isn't yet in a set. > > > class Attributes: pass > > sym = Attributes() > for name in ("a", "b", "c", "d", "e", "f", "g", "h", "i"): > ? ? ?setattr( sym, name, name ) > > eq_specs = [ > ? ? ?(sym.a, sym.d), > ? ? ?(sym.b, sym.a), > ? ? ?(sym.b, sym.c), > ? ? ?(sym.b, sym.d), > ? ? ?(sym.c, sym.d), > ? ? ?(sym.c, sym.a), > ? ? ?(sym.e, sym.f), > ? ? ?(sym.e, sym.g), > ? ? ?(sym.f, sym.g), > ? ? ?(sym.h, sym.i), > ? ? ?] > > equalities = [] > for eq in eq_specs: > ? ? ?sorted_eq = eq if eq[0] <= eq[1] else (eq[1], eq[0]) > ? ? ?equalities.append( sorted_eq ) > equalities.sort() > > eq_sets = {} > eq_set_ids = {} > current_eq_set_id = 0 > for eq in equalities: This would make the body of the loop easier to read: for x, y in equalities: > ? ? ?if eq_set_ids.get( eq[0] ) is None: Why not simply: if eq[0] in eq_set_ids: > ? ? ? ? ?current_eq_set_id += 1 > ? ? ? ? ?eq_set_ids[eq[0]] = current_eq_set_id > ? ? ? ? ?eq_sets[current_eq_set_id] = set( eq[0] ) > ? ? ?eq_set_id = eq_set_ids[eq[0]] > ? ? ?eq_set_ids[eq[1]] = eq_set_id > ? ? ?eq_sets[eq_set_id].add( eq[1] ) > > for eq_set_id in eq_sets.keys(): > ? ? ?for sym_name in eq_sets[eq_set_id]: > ? ? ? ? ?print( "{}, {}".format( eq_set_id, sym_name ) ) > > > > 1, a > 1, c > 1, b > 1, d > 2, e > 2, g > 2, f > 3, i > 3, h > > > Disclaimer: for me it's pretty late in day/night. > > Cheers & hth., > > - Alf > > -- > blog at I think this won't work with the following graph: eq_specs = [('a', 'c'), ('b', 'd'), ('c', 'd')] Note that it is already sorted according to your sorting method. I don't have a Python machine to check this but I believe it will output: 1, a 1, c 1, d 2, b The flaw is that you fail to consider that the two vertices in the current pair may already be part of a (partial) connected component. -- Arnaud From alf.p.steinbach+usenet at gmail.com Tue Sep 21 05:41:46 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 21 Sep 2010 11:41:46 +0200 Subject: Grouping pairs - suggested tools In-Reply-To: <3463624f-405e-483f-9c21-52989d9a874f@k9g2000vbo.googlegroups.com> References: <3463624f-405e-483f-9c21-52989d9a874f@k9g2000vbo.googlegroups.com> Message-ID: * Arnaud Delobelle, on 21.09.2010 11:13: > On Sep 21, 7:19 am, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: >> * Alf P. Steinbach /Usenet, on 21.09.2010 01:09: >> >> >> >> >> >>> * Astley Le Jasper, on 20.09.2010 23:42: >>>> I have a list of tuples that indicate a relationship, ie a is related >>>> to b, b is related to c etc etc. What I want to do is cluster these >>>> relationships into groups. An item will only be associated with a >>>> single cluster. >> >>>> Before I started, I wondered if there was any particular tool within >>>> Python I should be looking at. I don't expect anyone to code this for >>>> me, just say ... "you need to look at using x". I was going to use >>>> populate a dictionary and >> >>>> Sorry for being so vague. >> >>>> Example Data: >>>> [(a,b) >>>> (a,c) >>>> (a,d) >>>> (b,c) >>>> (b,d) >>>> (c,d) >>>> (e,f) >>>> (e,g) >>>> (f,g) >>>> (h,i)] >> >>>> Output (grouping id, item ref) >>>> (1,a), >>>> (1,b), >>>> (1,c), >>>> (1,d), >>>> (2,e), >>>> (2,f), >>>> (2,g), >>>> (3,h), >>>> (3,i) >> >>> It seems to be the same problem as "equivalence sets". >> >>> This problem was solved early on because e.g. Fortran compilers had to construct >>> such sets (equivalence partitions of a set). >> >>> I though I'd just say "Google it!", because I know there's a standard algorithm >>> but I can't recall the name. However, googling it I found no mention of that >>> algorithm. Not even in the Wikipedia articles on equivalence sets. >> >>> A number of approaches spring to mind: >> >>> Approach 1: >>> Multi-pass. Originally you assign a distinct set number to each symbol. >>> In each pass through the symbols you replace one number with another as >>> per one of the equivalence specs. Stop when no replacements are done. >> >>> Approach 2: >>> Merging. For each new equivalence A=B you check whether A has been assigned >>> to a set, if not you create a new one, call that S1, and ditto for B, S2. >>> Merge S1 and S2, e.g. move all elements of S2 to S1. >> >>> Approach 3: >>> In a first pass convert the data to more explicit form, linking each symbol >>> to the symbols it's directly equivalent to. Then in second pass simply drag >>> out each equivalence group (recurse on each symbol's list of equivalences). >> >>> Approaches 1 and 2 seem to be pretty inefficient for a large number of symbols, >>> but I think approach 1 may be a practical option for a small number of symbols. >> >> Uhm, thinking about it (it must have been my unconscious mind doing the work, it >> just popped into my head), if you first sort each individual equivalence >> relation so that you never have e.g. C=A but only A=C and so on, and then sort >> the list of equivalences, then it should reduce to walking the list and just >> starting a new set whenever a symbol is encountered that isn't yet in a set. >> >> >> class Attributes: pass >> >> sym = Attributes() >> for name in ("a", "b", "c", "d", "e", "f", "g", "h", "i"): >> setattr( sym, name, name ) >> >> eq_specs = [ >> (sym.a, sym.d), >> (sym.b, sym.a), >> (sym.b, sym.c), >> (sym.b, sym.d), >> (sym.c, sym.d), >> (sym.c, sym.a), >> (sym.e, sym.f), >> (sym.e, sym.g), >> (sym.f, sym.g), >> (sym.h, sym.i), >> ] >> >> equalities = [] >> for eq in eq_specs: >> sorted_eq = eq if eq[0]<= eq[1] else (eq[1], eq[0]) >> equalities.append( sorted_eq ) >> equalities.sort() >> >> eq_sets = {} >> eq_set_ids = {} >> current_eq_set_id = 0 >> for eq in equalities: > > This would make the body of the loop easier to read: > > for x, y in equalities: > >> if eq_set_ids.get( eq[0] ) is None: > > Why not simply: > > if eq[0] in eq_set_ids: > >> current_eq_set_id += 1 >> eq_set_ids[eq[0]] = current_eq_set_id >> eq_sets[current_eq_set_id] = set( eq[0] ) >> eq_set_id = eq_set_ids[eq[0]] >> eq_set_ids[eq[1]] = eq_set_id >> eq_sets[eq_set_id].add( eq[1] ) >> >> for eq_set_id in eq_sets.keys(): >> for sym_name in eq_sets[eq_set_id]: >> print( "{}, {}".format( eq_set_id, sym_name ) ) >> >> >> >> 1, a >> 1, c >> 1, b >> 1, d >> 2, e >> 2, g >> 2, f >> 3, i >> 3, h >> >> >> Disclaimer: for me it's pretty late in day/night. >> >> Cheers& hth., >> >> - Alf >> >> -- >> blog at > > I think this won't work with the following graph: > > eq_specs = [('a', 'c'), ('b', 'd'), ('c', 'd')] > > Note that it is already sorted according to your sorting method. I > don't have a Python machine to check this but I believe it will > output: > > 1, a > 1, c > 1, d > 2, b > > The flaw is that you fail to consider that the two vertices in the > current pair may already be part of a (partial) connected component. Yeah, thanks. I think the three general methods I listed will nicely work, though. Moral: don't post insights from dream-world... ;-) Cheers, - Alf -- blog at From __peter__ at web.de Tue Sep 21 06:13:56 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Sep 2010 12:13:56 +0200 Subject: Grouping pairs - suggested tools References: Message-ID: Astley Le Jasper wrote: > I have a list of tuples that indicate a relationship, ie a is related > to b, b is related to c etc etc. What I want to do is cluster these > relationships into groups. An item will only be associated with a > single cluster. > > Before I started, I wondered if there was any particular tool within > Python I should be looking at. I don't expect anyone to code this for > me, just say ... "you need to look at using x". I was going to use > populate a dictionary and > > Sorry for being so vague. > > Example Data: > [(a,b) > (a,c) > (a,d) > (b,c) > (b,d) > (c,d) > (e,f) > (e,g) > (f,g) > (h,i)] > > Output (grouping id, item ref) > (1,a), > (1,b), > (1,c), > (1,d), > (2,e), > (2,f), > (2,g), > (3,h), > (3,i) A straightforward implementation: $ cat group_edges.py def find_groups(edges): lookup = {} # node --> group groups = {} # id(group) --> group for a, b in edges: if a in lookup: if b in lookup: ga = lookup[a] gb = lookup[b] if ga is not gb: # merge groups if len(ga) < len(gb): # always update the smaller group ga, gb = gb, ga del groups[id(gb)] ga.update(gb) for k in gb: lookup[k] = ga else: # add b to a's group ga = lookup[a] ga.add(b) lookup[b] = ga elif b in lookup: # add a to b's group gb = lookup[b] gb.add(a) lookup[a] = gb else: # create new group g = set((a, b)) groups[id(g)] = g lookup[a] = lookup[b] = g return groups.values() def show_groups(edges): groups = sorted(sorted(g) for g in find_groups(edges)) for i, group in enumerate(groups, 1): for node in sorted(group): print i, node if __name__ == "__main__": edges = [ ('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'), ('c', 'd'), ('e', 'f'), ('e', 'g'), ('f', 'g'), ('h', 'i'), ("lonesome john", "lonesome john")] show_groups(edges) print show_groups([('a', 'c'), ('b', 'd'), ('c', 'd')]) $ python group_edges.py 1 a 1 b 1 c 1 d 2 e 2 f 2 g 3 h 3 i 4 lonesome john 1 a 1 b 1 c 1 d Untested. Peter From raoulbia at gmail.com Tue Sep 21 06:25:14 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 21 Sep 2010 03:25:14 -0700 (PDT) Subject: basic 2 player wordgame Message-ID: <0f3ae081-cab9-43d9-9ddd-2f3f6926dc9d@a11g2000vbn.googlegroups.com> Hi I am working on a simple wordgame exercise: 2 players form a word by alternating turns saying a letter, which is added on to the end of the word fragment. I am familiar with loops, iterations etc but i need a hint as to how to approach alternating turns when writing this code? exercise source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset5.pdf thanks Baba From cournape at gmail.com Tue Sep 21 07:17:46 2010 From: cournape at gmail.com (David Cournapeau) Date: Tue, 21 Sep 2010 20:17:46 +0900 Subject: visual studio 2010 question In-Reply-To: References: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> Message-ID: On Tue, Sep 21, 2010 at 5:54 AM, Diez B. Roggisch wrote: > David Cournapeau writes: > >> On Mon, Sep 20, 2010 at 3:08 PM, Ralf Haring wrote: >>> >>> After running into the error "Setup script exited with error: Unable >>> to find vcvarsall.bat" when trying to use easy_install / setuptools a >>> little digging showed that the MS compiler files in distutils only >>> support up to Studio 2008. Does anyone know if there is a timetable >>> for when Studio 2010 will be supported? >>> >>> I am using python 2.6.5, but web searching seemed to show that 2.7 or >>> 3.X didn't support it yet either. >> >> You should use VS 2008 - the lack of distutils support is only the >> first of a long list of issues if you want to use another compiler to >> build python extensions. Unless you really know what you are doing, >> you are better off with VS 2008, > > Forgive my ignorance, but AFAIK mingw can be used to build extensions > for standard python distributions. Yes, mingw may be used - I assumed that the OP was interesting in MS compilers. > After all, it's C we're talking here, > not C++. So I have difficulties imagining VS2010 is that much of a > problem. So - which problems you expect? The ones described by Robert, David From nobody at nowhere.com Tue Sep 21 08:02:01 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 21 Sep 2010 13:02:01 +0100 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Mon, 20 Sep 2010 12:00:41 +1200, Lawrence D'Oliveiro wrote: >> However, some clients choose their own source ports. E.g. rlogin/rsh use >> privileged (low-numbered) ports, and you can't get the kernel to choose a >> random privileged port for you. > > But nobody uses rlogin/rsh any more, They did when the bind() and SO_REUSEADDR semantics were developed. If they were doing it now, chances are that SO_REUSEADDR would be enabled by default. > and who would attach any trustworthy > meaning to a connection coming from a remote low-numbered source port? If you receive a connection with a low-numbered source port and it *isn't* legitimate, then someone has got root (in which case any other authentication mechanism isn't safe either) or someone has hijacked the IP address (you do know that low-numbered ports are only meaningful for systems under your control, right?). Using a firewall rule which only allows connections from a low port on specific IP addresses certainly isn't any worse than a rule which only allows connections from any port on specific IP addresses. That's true regardless of whether the protocol includes other authentication mechanisms. >> If you're writing a server which listens on a known port, you *should* be >> using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel >> will automatically reject packets relating to stale connections, and your >> server should be accepting any new connections ASAP. > > That makes it sound like SO_REUSEADDR should really be a superfluous option. > But it?s not. Well it is mostly superfluous. It should always be enabled for a server listening on a known port, and doesn't matter for a client which uses ephemeral ports. From nobody at nowhere.com Tue Sep 21 08:10:08 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 21 Sep 2010 13:10:08 +0100 Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> <87bp7s5504.fsf@benfinney.id.au> Message-ID: On Tue, 21 Sep 2010 10:12:27 +1000, Ben Finney wrote: > Another is that filesystems don't have a standard way of determining > whether they are case-sensitive. The operating system's driver for that > particular filesystem knows, I'm not even sure that's true; with a networked filesytem, some parts of it may be case-sensitive and others case-insensitve (e.g. if you export a Linux filesystem which includes Windows filesystems mounted beneath the root of the export). From nobody at nowhere.com Tue Sep 21 08:29:04 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 21 Sep 2010 13:29:04 +0100 Subject: Arrays and CTYPE References: <824d1ec2-93ee-4a81-ad95-19560fabe9e4@r10g2000vbc.googlegroups.com> Message-ID: On Mon, 20 Sep 2010 15:47:32 -0700, Glenn Pringle wrote: > Ok. I ran into a problem here. I have been dabbling with Python and I > thought that this would be a good exercise but I got stuck. > > I have a DLL and one of the functions(getState) in that DLL returns an > array. If the DLL was written in C (or C++), it can't return an array; it will return a pointer instead. > I'm having a hard time getting access to the contents of that > array. Set getState.restype to a pointer type, e.g.: hold.getState.restype = POINTER(c_int) Pointer types can be indexed with [], as in C. From antroy at gmail.com Tue Sep 21 08:29:30 2010 From: antroy at gmail.com (Ant) Date: Tue, 21 Sep 2010 05:29:30 -0700 (PDT) Subject: Python in Linux - barrier to Python 3.x Message-ID: Hi all, I've just seen this: http://sheddingbikes.com/posts/1285063820.html Whatever you think of Zed Shaw (author of the Mongrel Ruby server and relatively recent Python convert), he has a very good point in this. I run Fedora 12 on my home computers, and find it far too much hassle to try to get Python 3 installed. Even the 2.x's are behind - IIRC think it currently uses 2.5. So I really think this is a barrier to entry to Python 3 that we could do without - it's the only reason I do all of my Python work in 2.x, I would jump at migrating to Python 3 if it was easily available on Fedora. Is there a solution to this that anyone knows of? Has Zed jumped to conclusions? Have I? From mwilson at the-wire.com Tue Sep 21 08:39:00 2010 From: mwilson at the-wire.com (Mel) Date: Tue, 21 Sep 2010 08:39 -0400 Subject: basic 2 player wordgame References: <0f3ae081-cab9-43d9-9ddd-2f3f6926dc9d@a11g2000vbn.googlegroups.com> Message-ID: Baba wrote: > I am working on a simple wordgame exercise: 2 players form a word by > alternating turns saying a letter, which is added on to the end of the > word fragment. > > I am familiar with loops, iterations etc but i need a hint as to how > to approach alternating turns when writing this code? One way (not tested): thisplayer = Player() otherplayer = Player() while not_won: thisplayer.take_turn() thisplayer, otherplayer = otherplayer, thisplayer Mel. From vineetdaniel at gmail.com Tue Sep 21 08:49:38 2010 From: vineetdaniel at gmail.com (vineet daniel) Date: Tue, 21 Sep 2010 05:49:38 -0700 (PDT) Subject: creating python daemon ? Message-ID: Hi I have succesfully created daemon with python script and as next step I am trying to give input to that python script daemon from Apache Logs....here I have got stuck and I have even checked IRC python channel for solution. Apache is able to call the file but fails to execute it properly and I get this error continuosly : piped log program '/var/www/html/test.py' failed unexpectedly How do I rectify the above error and make adjustment to the code so that it takes input from apache. code that I am using is as follows : #! /usr/bin/env python import sys,os pid = os.fork() os.chdir("/var/www/html/") os.setsid() os.umask(0) #this line will read apache log in real time as redirected from the CustomLog directive of Apache. log = sys.stdin.readlines() f = open('/var/www/logmongo.txt','a') # append log to this text file f.write(log) I'd appreciate if anybody could share the code that they used for daemon or used with Apache CustomLog directive. From __peter__ at web.de Tue Sep 21 09:03:35 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Sep 2010 15:03:35 +0200 Subject: Python in Linux - barrier to Python 3.x References: Message-ID: Ant wrote: > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. Once you remove the Zedshawisms the article's claim boils down to - If you want to install and run a python script on a wide range of Linux distributions you have to stay compatible with Python 2.4. - Users of languages competing with Python tend to avoid applications that use Python, even if that usage is mostly under the hood -- but they don't mind using a program written in C. > So I really think this is a barrier to entry to Python 3 that we could > do without - it's the only reason I do all of my Python work in 2.x, I > would jump at migrating to Python 3 if it was easily available on > Fedora. > > Is there a solution to this that anyone knows of? More practical people than Zed (or his online persona) don't see it as a problem. > Has Zed jumped to conclusions? He jumped indeed, to another language, and he will do it again, but not without telling the world. > Have I? I think migration from 2.x to 3.x will be hard for large infrastructures but that doesn't seem to be your concern. Peter PS: Is the Paul Graham quote real? From philip at semanchuk.com Tue Sep 21 09:04:03 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 21 Sep 2010 09:04:03 -0400 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: References: Message-ID: <01306838-6ACB-4566-8931-7D469F319CEA@semanchuk.com> On Sep 21, 2010, at 8:29 AM, Ant wrote: > Hi all, > > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. Don't know about Python 3 on Fedora (I use a Mac), but distrowatch.org reports that Fedora has been using Python >= 2.6 since Fedora 11 which was released in June of 2009. http://distrowatch.com/table.php?distribution=fedora bye Philip From philip at semanchuk.com Tue Sep 21 09:10:51 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 21 Sep 2010 09:10:51 -0400 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: References: Message-ID: <5074C910-3249-413E-A1CA-A1192ABD9425@semanchuk.com> On Sep 21, 2010, at 8:29 AM, Ant wrote: > Hi all, > > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. Don't know about Python 3 on Fedora (I use a Mac), but distrowatch.org reports that Fedora has been using Python >= 2.6 since Fedora 11 which was released in June of 2009. http://distrowatch.com/table.php?distribution=fedora bye Philip From deets at web.de Tue Sep 21 09:23:42 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 15:23:42 +0200 Subject: Python in Linux - barrier to Python 3.x References: Message-ID: <874odj1b8h.fsf@web.de> Ant writes: > Hi all, > > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. > > So I really think this is a barrier to entry to Python 3 that we could > do without - it's the only reason I do all of my Python work in 2.x, I > would jump at migrating to Python 3 if it was easily available on > Fedora. > > Is there a solution to this that anyone knows of? Has Zed jumped to > conclusions? Have I? I think he has a very valid point. I've been arguing quite a few times here that e.g. the stupid splitting up of python and python-dev packages that a great deal of people trip over should go away. But usually people here seem to think that other package management systems are the way to go, and python itself must integrate with them. E.g. providing dependency information compatible to them and their policies. I think that's bonkers. You can't support every new kid on the block claiming to be the shizzle in package management. Or the next distro with it's own packaging policies. And of course the overall release planning that says "we use that ancient stable version not supported for years anymore, because it's true & tested for us". IMHO the solution to this is the way Apple does it: they have a System Python. Don't mess with it. Seriously. Don't. But you can install as many other Python versions as you want, or even bundle one with your own app that depends on it. People object to this usually for two reasons: - additional waste of disk-space. Seriously? A thorough visit of youporn.com most probably fills your browser cache with more data than all possibly python installations ever can. - security issues through aged libraries. Certainly a valid point, but then this problem is not limited to Python and needs a more universal solution: Meta-information gathering about binary versions of libraries, and (safe) upgrades for these. Maybe. I haven't given much thought to this, but I think it's an OS thing more than a package distro thing. So, in summary, I think if anything, Python should liberate itself from the reigns of distro package management, and fix whatever issues there are with setuptools (or distutils or pip or distribute or whatever the cool kids use these days). And then make people use that to work with Python-packages, potentially even in individual, isolated VirtualEnvs because of package version conflicts. Diez From icanbob at gmail.com Tue Sep 21 10:02:23 2010 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 21 Sep 2010 07:02:23 -0700 (PDT) Subject: basic 2 player wordgame References: <0f3ae081-cab9-43d9-9ddd-2f3f6926dc9d@a11g2000vbn.googlegroups.com> Message-ID: On Sep 21, 6:25 am, Baba wrote: > Hi > > I am working on a simple wordgame exercise: 2 players form a word by > alternating turns saying a letter, which is added on to the end of the > word fragment. > > I am familiar with loops, iterations etc but i need a hint as to how > to approach alternating turns when writing this code? > > exercise source:http://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > thanks > Baba Have a look at the SIMPL toolkit (http://www.icanprogram.com/06py/ lesson1/lesson1.html). This would allow your two players to be split into two separate Python modules. It has the "advantage" that once completed those two players could be deployed across a network, likely without any code changes. bob From michele.simionato at gmail.com Tue Sep 21 10:10:59 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 21 Sep 2010 07:10:59 -0700 (PDT) Subject: Python in Linux - barrier to Python 3.x References: Message-ID: On Sep 21, 2:29?pm, Ant wrote: > Hi all, > > I've just seen this:http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. > > So I really think this is a barrier to entry to Python 3 that we could > do without - it's the only reason I do all of my Python work in 2.x, I > would jump at migrating to Python 3 if it was easily available on > Fedora. > > Is there a solution to this that anyone knows of? Has Zed jumped to > conclusions? Have I? Zed's approach (removing Python when it could just have downgraded to Python 2.4) does not look very smart to me. The post itself is pretty much bullshit. Yes, there are Linux distributions with old Python versions out there. Yes, if you don't want to install a newer Python on such distributions you need to take in account this fact and not to use modern features of Python. But the situation is not different for other languages such as Perl or Ruby. C is free from this problem because it is a very old and stable language. There is no more content in that post and everybody should already know such basic facts. Michele Simionato From Antoon.Pardon at rece.vub.ac.be Tue Sep 21 10:17:48 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 21 Sep 2010 16:17:48 +0200 Subject: Too much code - slicing In-Reply-To: <4c97f72b$0$28658$c3e8da3@news.astraweb.com> References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: <20100921141748.GA8814@rcpc42.vub.ac.be> On Tue, Sep 21, 2010 at 12:07:07AM +0000, Steven D'Aprano wrote: > On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: > > > Not necessarily. Some of us have the impression that Guido deliberatly > > chose an ugly format for the ternary operator. > > If he did, then he must have changed his mind, because there is nothing > ugly about the ternary operator we ended up with. That is a question of taste and the poll and discussion earlier made it clear that this was not the preferred way to have a ternary operator. This form only ranked fourth (or maybe third), with the first three all wanting ar structure with the elelement is this order: condition, true case, false case > > Guido has alwasys been > > against a ternary operator but the requests kept coming. So eventually > > he introduced one. But the impression is that he chose an ugly format in > > the hope of discouraging people to use it. > > That's sheer and unadulterated nonsense. The fact is that Guido changed > his mind about ternary if after discovering that the work-around > > true-clause and condition or false-clause > > is buggy -- it gives the wrong answer if true-clause happens to be a > false value like [], 0 or None. If I recall correctly, the bug bit Guido > himself. Nonsense. That the work around was buggy was known years before the ternary operator was finally introduced. The introduction of list comprehension made a ternary operator that more usefull but every time it came up the supporters of Guido, told us we just had to define a function if we wanted the items to depend on a condition. And we knew about the problem, that is why we discussed bug-free alternatives like: condition and [true-expr] or [false-expr][0] or condition and (lambda: true-expr) or (lambda: false-expr)() > The and-or hack, which was *very* common in Python code for many years > and many versions, follows the same pattern as ternary if: > > true-clause if condition else false-clause No it doesn't. the and-or-hack follows the same pattern as the if statement. condition, true clause, else clause > It astounds me how the Python community changed it's collective mind from > admiration of the elegance and simplicity of the expression when it was a > buggy hack, to despising it when it became a bug-free language feature. It seems that what changed is your memory and not the collective mind of the python community. We had an if statement and a (buggy) hack that followed the same pattern. An earlier discussion and poll had revealed that people n general preferredr to keep that pattern in a conditional expression. So why should you be surprised when people express that they would have preferred a conditional expression with a different pattern than we have now. -- Antoon Pardon From darcy at druid.net Tue Sep 21 10:47:18 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 21 Sep 2010 10:47:18 -0400 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <874odj1b8h.fsf@web.de> References: <874odj1b8h.fsf@web.de> Message-ID: <20100921104718.601a0504.darcy@druid.net> On Tue, 21 Sep 2010 15:23:42 +0200 deets at web.de (Diez B. Roggisch) wrote: > So, in summary, I think if anything, Python should liberate itself from > the reigns of distro package management, and fix whatever issues there > are with setuptools (or distutils or pip or distribute or whatever the > cool kids use these days). And then make people use that to work with > Python-packages, potentially even in individual, isolated VirtualEnvs > because of package version conflicts. Install NetBSD package tools (http://pkgsrc.org/) and install as many versions as you like. A symlink takes care of your default and you can use .pth files to have separate local libraries. Pkgsrc is designed to run on all OSs including Linux distros. -- 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 astley.lejasper at gmail.com Tue Sep 21 11:07:48 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Tue, 21 Sep 2010 08:07:48 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: <79047d2d-4d9a-4e74-b44b-1010cf033525@t11g2000vbc.googlegroups.com> Thanks all. I was playing around with this and came up with another solution using dictionaries (... comfort zone ...!!) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Code >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> from operator import itemgetter def group_stuff(data): group_dic = {} group_id = 0 for line in data: i = 0 for ref in line: if group_dic.get(ref) is None: if group_dic.get(line[1-i]) is not None: group_id = group_dic[line[1-i]] else: group_id +=1 group_dic[ref] = group_id i+=1 group_list = [] for id, group in sorted(group_dic.items(), key=itemgetter(1,0)): group_list.append((group, id)) return group_list if __name__ == '__main__': data = [('a','b'),('a','c'),('a','d'),('b','c'),('b','d'), ('c','d'),('e','f'),('e','g'),('f','g'),('h','i')] grouped = group_stuff(data) print grouped <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Code >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Output: [(1, 'a'), (1, 'b'), (1, 'c'), (1, 'd'), (2, 'e'), (2, 'f'), (2, 'g'), (3, 'h'), (3, 'i')] From cournape at gmail.com Tue Sep 21 11:18:06 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 22 Sep 2010 00:18:06 +0900 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <874odj1b8h.fsf@web.de> References: <874odj1b8h.fsf@web.de> Message-ID: On Tue, Sep 21, 2010 at 10:23 PM, Diez B. Roggisch wrote: > Ant writes: > >> Hi all, >> >> I've just seen this: http://sheddingbikes.com/posts/1285063820.html >> >> Whatever you think of Zed Shaw (author of the Mongrel Ruby server and >> relatively recent Python convert), he has a very good point in this. I >> run Fedora 12 on my home computers, and find it far too much hassle to >> try to get Python 3 installed. Even the 2.x's are behind - IIRC think >> it currently uses 2.5. >> >> So I really think this is a barrier to entry to Python 3 that we could >> do without - it's the only reason I do all of my Python work in 2.x, I >> would jump at migrating to Python 3 if it was easily available on >> Fedora. >> >> Is there a solution to this that anyone knows of? Has Zed jumped to >> conclusions? Have I? > > I think he has a very valid point. I've been arguing quite a few times > here that e.g. the stupid splitting up of python and python-dev packages > that a great deal of people trip over should go away. It is not stupid, it makes a lot of sense when you know the distributions in question. It means you have a consistent behavior independently of the language. So of course if you don't care about the rest of the ecosystem, you will think it is useless overhead. Also, I doubt that the issue is python vs python-dev - of course, given that the exact issues are not explained, we can only play guess games. > > But usually people here seem to think that other package management > systems are the way to go, and python itself must integrate with > them. E.g. providing dependency information compatible to them and their policies. > > I think that's bonkers. You can't support every new kid on the block > claiming to be the shizzle in package management. Or the next distro > with it's own packaging policies. And of course the overall release > planning that says "we use that ancient stable version not supported for > years anymore, because it's true & tested for us". > > IMHO the solution to this is the way Apple does it: they have a System > Python. Don't mess with it. Seriously. Don't. Apple's python have caused more issues than all distributions altogether for Numpy and scipy, at least as far as python itself is concerned. It is very confusing for many end-users. > So, in summary, I think if anything, Python should liberate itself from > the reigns of distro package management, and fix whatever issues there > are with setuptools (or distutils or pip or distribute or whatever the > cool kids use these days). And then make people use that to work with > Python-packages, potentially even in individual, isolated VirtualEnvs > because of package version conflicts. This kind of thinking mostly shows a poor understanding of complex deployment scenario. If everybody worked like that, you would quickly be unable to build anything stable. True, conflicts are sometimes unavoidable, but if every library keeps changing your only solution is isolated environments, you quickly have a mess of a system where many combinations of libraries are not possible. The fact is that if you need to assemble softwares from many sources, you need proper engineering. Isolated environments do not help you much with that. Maybe you should consider that distros have an experience that you don't, cheers, David From __peter__ at web.de Tue Sep 21 11:31:32 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Sep 2010 17:31:32 +0200 Subject: Grouping pairs - suggested tools References: <79047d2d-4d9a-4e74-b44b-1010cf033525@t11g2000vbc.googlegroups.com> Message-ID: Astley Le Jasper wrote: > Thanks all. I was playing around with this and came up with another > solution using dictionaries (... comfort zone ...!!) > from operator import itemgetter > > def group_stuff(data): > > group_dic = {} > group_id = 0 > > for line in data: > i = 0 > for ref in line: > if group_dic.get(ref) is None: > if group_dic.get(line[1-i]) is not None: > group_id = group_dic[line[1-i]] > else: > group_id +=1 > group_dic[ref] = group_id > i+=1 > > group_list = [] > for id, group in sorted(group_dic.items(), key=itemgetter(1,0)): > group_list.append((group, id)) > > return group_list > > if __name__ == '__main__': > data = [('a','b'),('a','c'),('a','d'),('b','c'),('b','d'), > ('c','d'),('e','f'),('e','g'),('f','g'),('h','i')] > grouped = group_stuff(data) > print grouped > Output: [(1, 'a'), (1, 'b'), (1, 'c'), (1, 'd'), (2, 'e'), (2, 'f'), > (2, 'g'), (3, 'h'), (3, 'i')] I think you have the same bug as Alf's code, you never merge existing groups. Have you tried Arnaud's counterexample? By the way, are ('a', 'b') and ('b', 'a') to be considered equivalent for your problem? Peter From ndbecker2 at gmail.com Tue Sep 21 11:32:16 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 21 Sep 2010 11:32:16 -0400 Subject: Python in Linux - barrier to Python 3.x References: Message-ID: Ant wrote: > Hi all, > > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. > > So I really think this is a barrier to entry to Python 3 that we could > do without - it's the only reason I do all of my Python work in 2.x, I > would jump at migrating to Python 3 if it was easily available on > Fedora. > > Is there a solution to this that anyone knows of? Has Zed jumped to > conclusions? Have I? Current fedora release (13) has python3 available. From deets at web.de Tue Sep 21 11:59:27 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 17:59:27 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> Message-ID: <87zkvbytnk.fsf@web.de> David Cournapeau writes: > On Tue, Sep 21, 2010 at 10:23 PM, Diez B. Roggisch wrote: >> Ant writes: >> >>> Hi all, >>> >>> I've just seen this: http://sheddingbikes.com/posts/1285063820.html >>> >>> Whatever you think of Zed Shaw (author of the Mongrel Ruby server and >>> relatively recent Python convert), he has a very good point in this. I >>> run Fedora 12 on my home computers, and find it far too much hassle to >>> try to get Python 3 installed. Even the 2.x's are behind - IIRC think >>> it currently uses 2.5. >>> >>> So I really think this is a barrier to entry to Python 3 that we could >>> do without - it's the only reason I do all of my Python work in 2.x, I >>> would jump at migrating to Python 3 if it was easily available on >>> Fedora. >>> >>> Is there a solution to this that anyone knows of? Has Zed jumped to >>> conclusions? Have I? >> >> I think he has a very valid point. I've been arguing quite a few times >> here that e.g. the stupid splitting up of python and python-dev packages >> that a great deal of people trip over should go away. > > It is not stupid, it makes a lot of sense when you know the > distributions in question. It means you have a consistent behavior > independently of the language. So of course if you don't care about > the rest of the ecosystem, you will think it is useless overhead. The point is that the distro doesn't care about the python eco system. Which is what I care about, and a lot of people who want to ship software. Don't get me wrong: I'm a Linux user for way over a decade, I enjoy the package management in providing a consistent distribution. What I'm talking about here are 3rd-party developers/companies/whatever, and people who want to install software that requires recent versions of packages *not* provided by their distros. I should have made that point clearer I guess. > > Also, I doubt that the issue is python vs python-dev - of course, > given that the exact issues are not explained, we can only play guess > games. The problems explained are simply outdated and crippled python versions. And to me, a python version installed that has not the distutils module is *crippled*. You can rationalize that as much as you want through some package philosophy saying "we don't ship development related files", but to me a simple installation instruction that says "run 'python setup.py install'" which fails because of such a (debatable) decision sucks. Yes, there are corner-cases when you need GCC to compile an extension. But that's still catering to the 80% or even more (I'm guessing here) of pure-python packages. Of course, in a ideal world, distutils would hook into the distros dependency system + simply say "please install python-dev first". But I'm not convinced that putting the weight here on the shoulders of the python-communtiy to deal with arbirtray decisions of the dozen or how many distros + packaging schemes out there is possible - and helpful. >> But usually people here seem to think that other package management >> systems are the way to go, and python itself must integrate with >> them. E.g. providing dependency information compatible to them and their policies. >> >> I think that's bonkers. You can't support every new kid on the block >> claiming to be the shizzle in package management. Or the next distro >> with it's own packaging policies. And of course the overall release >> planning that says "we use that ancient stable version not supported for >> years anymore, because it's true & tested for us". >> >> IMHO the solution to this is the way Apple does it: they have a System >> Python. Don't mess with it. Seriously. Don't. > > Apple's python have caused more issues than all distributions > altogether for Numpy and scipy, at least as far as python itself is > concerned. It is very confusing for many end-users. Exactly. My point is that I can safely install a second version besides it, and don't use the system's python that is there and kept stable for the system's own belongings. >> So, in summary, I think if anything, Python should liberate itself from >> the reigns of distro package management, and fix whatever issues there >> are with setuptools (or distutils or pip or distribute or whatever the >> cool kids use these days). And then make people use that to work with >> Python-packages, potentially even in individual, isolated VirtualEnvs >> because of package version conflicts. > > This kind of thinking mostly shows a poor understanding of complex > deployment scenario. If everybody worked like that, you would quickly > be unable to build anything stable. True, conflicts are sometimes > unavoidable, but if every library keeps changing your only solution is > isolated environments, you quickly have a mess of a system where many > combinations of libraries are not possible. And now you are already in a mess of a system where many combinations of libraries are not possible. And the thinking of "one version set to rule them all" shows a poor understanding of the need for legacy code's specific version requirements, as well as the need for fluctuating, (sometimes cutting edge) libraries. Does that suck? Sure. But the answer can't be a system that ties you in with *outdated* software for *years*. And it can't be Python's or it's communities burden to provide the solutions for the mass of distro providers. I *am* in the situation to need to deploy a TurboGears2 application every day on a debian lenny machine. Guess what that means: root at web01 / 15:55:43 # aptitude install python-turbogears -Vs Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done Reading task descriptions... Done The following NEW packages will be installed: python-cheetah{a} [2.0.1-2] python-cherrypy{a} [2.3.0-1] python-configobj{a} [4.5.2-1] python-crypto{a} [2.0.1+dfsg1-2.3+lenny0] python-decoratortools{a} [1.7-1] python-dispatch{a} [0.5a.svn20080510-1] python-dns{a} [2.3.3-2] python-elementtree{a} [1.2.6-12] python-elixir{a} [0.6.0-1] python-flup{a} [1.0-1] python-formencode{a} [1.0.1-1] python-kid{a} [0.9.6-1] python-mysqldb{a} [1.2.2-7] python-nose{a} [0.10.3-1] python-openid{a} [2.2.1-2] python-openssl{a} [0.7-2] python-paste{a} [1.7.1-1] python-pastedeploy{a} [1.3.2-1] python-pastescript{a} [1.6.3-1] python-pkg-resources{a} [0.6c8-4] python-protocols{a} [1.0a.svn20070625-2] python-pysqlite2{a} [2.4.1-1] python-scgi{a} [1.12-0.2] python-setuptools{a} [0.6c8-4] python-simplejson{a} [1.9.2-1] python-sqlalchemy{a} [0.4.7p1-2] python-sqlobject{a} [0.10.2-3] python-turbogears [1.0.4.4-1] python-turbojson{a} [1.1.2-1] python-turbokid{a} [1.0.4-2] python-webpy{a} [0.230-1] 0 packages upgraded, 31 newly installed, 0 to remove and 0 not upgraded. Need to get 4936kB/5188kB of archives. After unpacking 29.3MB will be used. Turbogears 1.0.4? Thank you - can't use that. > The fact is that if you need to assemble softwares from many sources, > you need proper engineering. Isolated environments do not help you > much with that. Maybe you should consider that distros have an > experience that you don't, I don't deny them their experience. Do you deny the experience of other people with *other* needs? As I already said: I don't propose to ditch the package management. I'm all fine with a distro that carefully selects it's packages and dependencies. I'm proposing that it should be able to have "system_python" and "current_python" or whatever you call it on one machine, and then let them live as happy co-existing eco-systems. This is not a well planned out thing. And it would certainly help to have a central meta-information registry to know exactly *where* and *which* version of all dependend libraries are installed. And thus make it possible to say "ok, we upgrade all system copies of openssl, and btw. you have these additional locations where you should do that as well." Or something like this. But the current state of affairs forces me to use customized versions of python on my machines, with virtualenvs including specific versions of libraries, bypassing the distro anyway. Why not try and make this more standardized & thus manageable? Diez From garyr at fidalgo.net Tue Sep 21 12:04:55 2010 From: garyr at fidalgo.net (garyr) Date: Tue, 21 Sep 2010 09:04:55 -0700 Subject: Python 2.6 & bsddb Message-ID: I recently installed ActivePython 2.6.6 and my programs that use anydbm or shelve generate import errors because bsddb is missing. I installed bsddb3 (bsddb3-5.0.0.win32-py2.6.exe) but that didn't change anything. What more do I need to do? From solipsis at pitrou.net Tue Sep 21 12:13:19 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 21 Sep 2010 18:13:19 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: <20100921181319.1f8d73ef@pitrou.net> On Tue, 21 Sep 2010 17:59:27 +0200 deets at web.de (Diez B. Roggisch) wrote: > > The problems explained are simply outdated and crippled python > versions. > > And to me, a python version installed that has not the > distutils module is *crippled*. You can rationalize that as much as you > want through some package philosophy saying "we don't ship development > related files", but to me a simple installation instruction that says comp.lang.python doesn't handle Linux packaging, so why don't you complain to your distro instead? Ranting on this group has zero chance of fixing the problem. Thank you Antoine. From robin at reportlab.com Tue Sep 21 12:18:40 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 21 Sep 2010 17:18:40 +0100 Subject: weird error with python 2.7 installer under windows 7 Message-ID: <4C98DAE0.2010100@chamonix.reportlab.co.uk> A colleague gets this error while testing a bdist wininst installer under windows 7 professional. This is on the page where the Post install script output appears. In the upper part I see "Postinstall script finished. Click the Finish button to exit the setup wizard." In the bottom panel where we normally see output about the created scripts I see this "close failed in file object destructor: Error in sys.excepthook: Original exception was:" I have tried the same installer with a Win XP Sp3 machine and it doesn't cause any problems. Any ideas? -- Robin Becker From usenot at geekmail.INVALID Tue Sep 21 12:26:29 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 21 Sep 2010 12:26:29 -0400 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> Message-ID: <20100921122629.4a1ff844@geekmail.INVALID> On Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Carl Banks wrote: > On Sep 17, 1:01?pm, Andreas Waldenburger > wrote: > > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > > > > > I also like this construct that works, I think, since 2.6: > > > > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > > > I wonder when this construct will finally start to look good. > > I don't know if it'll ever look good, per se, but it looks better when > it's used in rule-exception sort of case: > > something = rule if condition else exception > Spot on. I (more or less) like it when used that way, too. But it seems to invite crackers like the example above, and that irks me. /W -- INVALID? DE! From cournape at gmail.com Tue Sep 21 12:38:21 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 22 Sep 2010 01:38:21 +0900 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <87zkvbytnk.fsf@web.de> References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: On Wed, Sep 22, 2010 at 12:59 AM, Diez B. Roggisch wrote: > David Cournapeau writes: > >> On Tue, Sep 21, 2010 at 10:23 PM, Diez B. Roggisch wrote: >>> Ant writes: >>> >>>> Hi all, >>>> >>>> I've just seen this: http://sheddingbikes.com/posts/1285063820.html >>>> >>>> Whatever you think of Zed Shaw (author of the Mongrel Ruby server and >>>> relatively recent Python convert), he has a very good point in this. I >>>> run Fedora 12 on my home computers, and find it far too much hassle to >>>> try to get Python 3 installed. Even the 2.x's are behind - IIRC think >>>> it currently uses 2.5. >>>> >>>> So I really think this is a barrier to entry to Python 3 that we could >>>> do without - it's the only reason I do all of my Python work in 2.x, I >>>> would jump at migrating to Python 3 if it was easily available on >>>> Fedora. >>>> >>>> Is there a solution to this that anyone knows of? Has Zed jumped to >>>> conclusions? Have I? >>> >>> I think he has a very valid point. I've been arguing quite a few times >>> here that e.g. the stupid splitting up of python and python-dev packages >>> that a great deal of people trip over should go away. >> >> It is not stupid, it makes a lot of sense when you know the >> distributions in question. It means you have a consistent behavior >> independently of the language. So of course if you don't care about >> the rest of the ecosystem, you will think it is useless overhead. > > The point is that the distro doesn't care about the python eco > system. Which is what I care about, and a lot of people who want to ship > software. > > Don't get me wrong: I'm a Linux user for way over a decade, I enjoy the > package management in providing a consistent distribution. > > What I'm talking about here are 3rd-party > developers/companies/whatever, and people who want to install software > that requires recent versions of packages *not* provided by their > distros. I should have made that point clearer I guess. > >> >> Also, I doubt that the issue is python vs python-dev - of course, >> given that the exact issues are not explained, we can only play guess >> games. > > The problems explained are simply outdated and crippled python > versions. > > And to me, a python version installed that has not the > distutils module is *crippled*. You can rationalize that as much as you > want through some package philosophy saying "we don't ship development > related files", but to me a simple installation instruction that says > > "run 'python setup.py install'" > > which fails because of such a (debatable) decision sucks. Yes, there are > corner-cases when you need GCC to compile an extension. But that's still > catering to the 80% or even more (I'm guessing here) of pure-python packages. > > Of course, in a ideal world, distutils would hook into the distros > dependency system + simply say "please install python-dev first". > > But I'm not convinced that putting the weight here on the shoulders of > the python-communtiy to deal with arbirtray decisions of the dozen or > how many distros + packaging schemes out there is possible - and helpful. > >>> But usually people here seem to think that other package management >>> systems are the way to go, and python itself must integrate with >>> them. E.g. providing dependency information compatible to them and their policies. >>> >>> I think that's bonkers. You can't support every new kid on the block >>> claiming to be the shizzle in package management. Or the next distro >>> with it's own packaging policies. And of course the overall release >>> planning that says "we use that ancient stable version not supported for >>> years anymore, because it's true & tested for us". >>> >>> IMHO the solution to this is the way Apple does it: they have a System >>> Python. Don't mess with it. Seriously. Don't. >> >> Apple's python have caused more issues than all distributions >> altogether for Numpy and scipy, at least as far as python itself is >> concerned. It is very confusing for many end-users. > > Exactly. My point is that I can safely install a second version besides > it, and don't use the system's python that is there and kept stable for > the system's own belongings. > >>> So, in summary, I think if anything, Python should liberate itself from >>> the reigns of distro package management, and fix whatever issues there >>> are with setuptools (or distutils or pip or distribute or whatever the >>> cool kids use these days). And then make people use that to work with >>> Python-packages, potentially even in individual, isolated VirtualEnvs >>> because of package version conflicts. >> >> This kind of thinking mostly shows a poor understanding of complex >> deployment scenario. If everybody worked like that, you would quickly >> be unable to build anything stable. True, conflicts are sometimes >> unavoidable, but if every library keeps changing your only solution is >> isolated environments, you quickly have a mess of a system where many >> combinations of libraries are not possible. > > And now you are already in a mess of a system where many combinations of > libraries are not possible. And the thinking of "one version set to rule > them all" shows a poor understanding of the need for legacy code's > specific version requirements, as well as the need for fluctuating, > (sometimes cutting edge) libraries. > > Does that suck? Sure. But the answer can't be a system that ties you in > with *outdated* software for *years*. And it can't be Python's or it's > communities burden to provide the solutions for the mass of distro providers. > > I *am* in the situation to need to deploy > a TurboGears2 application every day on a debian lenny machine. Guess > what that means: > > root at web01 / 15:55:43 # aptitude install python-turbogears -Vs > Reading package lists... Done > Building dependency tree > Reading state information... Done > Reading extended state information > Initializing package states... Done > Reading task descriptions... Done > The following NEW packages will be installed: > ?python-cheetah{a} [2.0.1-2] ?python-cherrypy{a} [2.3.0-1] ?python-configobj{a} [4.5.2-1] ?python-crypto{a} [2.0.1+dfsg1-2.3+lenny0] ?python-decoratortools{a} [1.7-1] > ?python-dispatch{a} [0.5a.svn20080510-1] ?python-dns{a} [2.3.3-2] ?python-elementtree{a} [1.2.6-12] ?python-elixir{a} [0.6.0-1] ?python-flup{a} [1.0-1] ?python-formencode{a} [1.0.1-1] > ?python-kid{a} [0.9.6-1] ?python-mysqldb{a} [1.2.2-7] ?python-nose{a} [0.10.3-1] ?python-openid{a} [2.2.1-2] ?python-openssl{a} [0.7-2] ?python-paste{a} [1.7.1-1] ?python-pastedeploy{a} [1.3.2-1] > ?python-pastescript{a} [1.6.3-1] ?python-pkg-resources{a} [0.6c8-4] ?python-protocols{a} [1.0a.svn20070625-2] ?python-pysqlite2{a} [2.4.1-1] ?python-scgi{a} [1.12-0.2] > ?python-setuptools{a} [0.6c8-4] ?python-simplejson{a} [1.9.2-1] ?python-sqlalchemy{a} [0.4.7p1-2] ?python-sqlobject{a} [0.10.2-3] ?python-turbogears [1.0.4.4-1] ?python-turbojson{a} [1.1.2-1] > ?python-turbokid{a} [1.0.4-2] ?python-webpy{a} [0.230-1] > 0 packages upgraded, 31 newly installed, 0 to remove and 0 not upgraded. > Need to get 4936kB/5188kB of archives. After unpacking 29.3MB will be used. > > Turbogears 1.0.4? Thank you - can't use that. > >> The fact is that if you need to assemble softwares from many sources, >> you need proper engineering. Isolated environments do not help you >> much with that. Maybe you should consider that distros have an >> experience that ?you don't, > > I don't deny them their experience. Do you deny the experience of other > people with *other* needs? As I already said: I don't propose to ditch > the package management. I'm all fine with a distro that carefully > selects it's packages and dependencies. In your previous email, you were "suggesting" that we should make people use a specific set of python-specific tools. That does not sound very consistent with the idea of letting people choose what they want to use. FWIW, I think those tools are already pushed too aggressively, confusing many people who use pip, virtualenv, etc... for dubious reasons ("I read somewhere that I should use this"), and causing numerous bug reports on the numpy/scipy mailing lists. David From deets at web.de Tue Sep 21 12:44:20 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 18:44:20 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: <87vd5zyrkr.fsf@web.de> Antoine Pitrou writes: > On Tue, 21 Sep 2010 17:59:27 +0200 > deets at web.de (Diez B. Roggisch) wrote: >> >> The problems explained are simply outdated and crippled python >> versions. >> >> And to me, a python version installed that has not the >> distutils module is *crippled*. You can rationalize that as much as you >> want through some package philosophy saying "we don't ship development >> related files", but to me a simple installation instruction that says > > comp.lang.python doesn't handle Linux packaging, so why don't you > complain to your distro instead? Ranting on this group has zero chance > of fixing the problem. comp.lang.python frequently deals with problems caused by this and other distro-related issues. Your are welcome to not participate on these discussions. The state of affairs isn't ideal, and there is improvement options on all sides. I'm just astonished that people seem to think that distros in general are better and should be left alone, than what a more python centric solution could be. Diez From deets at web.de Tue Sep 21 12:47:08 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 18:47:08 +0200 Subject: creating python daemon ? References: Message-ID: <87r5gnyrg3.fsf@web.de> vineet daniel writes: > Hi > > I have succesfully created daemon with python script and as next step > I am trying to give input to that python script daemon from Apache > Logs....here I have got stuck and I have even checked IRC python > channel for solution. Apache is able to call the file but fails to > execute it properly and I get this error continuosly : > > piped log program '/var/www/html/test.py' failed unexpectedly > > How do I rectify the above error and make adjustment to the code so > that it takes input from apache. > > code that I am using is as follows : > > #! /usr/bin/env python > import sys,os > pid = os.fork() > os.chdir("/var/www/html/") > os.setsid() > os.umask(0) > #this line will read apache log in real time as redirected from the > CustomLog directive of Apache. > log = sys.stdin.readlines() > f = open('/var/www/logmongo.txt','a') # append log to this text file > f.write(log) > > I'd appreciate if anybody could share the code that they used for > daemon or used with Apache CustomLog directive. The above code looks errornous - you don't check for the return-value of PID & take appropriate action. Like There is a daemonization recipe on active-state, which works nicely for me. http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way/ Diez From sridharr at activestate.com Tue Sep 21 12:58:32 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Tue, 21 Sep 2010 09:58:32 -0700 Subject: Python 2.6 & bsddb In-Reply-To: References: Message-ID: On 2010-09-21, at 9:04 AM, garyr wrote: > I recently installed ActivePython 2.6.6 and my programs that use anydbm or > shelve generate import errors because bsddb is missing. I installed bsddb3 > (bsddb3-5.0.0.win32-py2.6.exe) but that didn't change anything. What more do > I need to do? You may have to change the imports. Maybe from "import bsddb" to "import bsddb3". The API may be different. Read the bsddb3 documentation. -srid From deets at web.de Tue Sep 21 13:06:56 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 19:06:56 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: <87mxrbyqj3.fsf@web.de> David Cournapeau writes: >> >> I don't deny them their experience. Do you deny the experience of other >> people with *other* needs? As I already said: I don't propose to ditch >> the package management. I'm all fine with a distro that carefully >> selects it's packages and dependencies. > > In your previous email, you were "suggesting" that we should make > people use a specific set of python-specific tools. That does not > sound very consistent with the idea of letting people choose what they > want to use. > > FWIW, I think those tools are already pushed too aggressively, > confusing many people who use pip, virtualenv, etc... for dubious > reasons ("I read somewhere that I should use this"), and causing > numerous bug reports on the numpy/scipy mailing lists. What I suggested was that there is a python-centric solution for managing dependencies for users of Linux, Windows and OSX alike. And which offers recent versions of python to anybody. A lot of wishful thinking, admittedly. But less than trying to deal with *all* the diffences in code, style and politics of various distributions. I was not suggesting that this solution itself be manifold. The sad truth is that there currently seem to be various attempts to improve or even fix perceived or real shortcomings of of distutils or probably even more setuptools, and this is from an outside perspective a waste. But then, the survival of the fittest, so to speak, requires the death of some that are unfit. It's hard to say which approach will "win". So we seem to be stuck with that at least for a while. zc.buildout, btw, seems to be going into the general direction of doing a lot (if not everything) itself. Including complete 3rd-party-packages and their builds. http://pypi.python.org/pypi/zc.buildout#buildout-examples For historic reasons I personally haven't used it yet. But it seems to scratch an itch, don't you think? Regarding the "dubiousness" of these reasons - I'm happy if you don't feel the pain. Good for you. I do, and frankly virtualenv is a life-saver for me in many situations. I wish it was part of core python, to create isolated environments. It sure is better than the Java-way of relying on environment-variables or giant sized commandline argument lists to specify specific version sets. However, *both* solutions cater to the obvious need of something other than pre-packaged versions in the distro. Is that such an abnorm wish? Amazing. Diez From t.koziara at civil.gla.ac.uk Tue Sep 21 13:17:30 2010 From: t.koziara at civil.gla.ac.uk (Tomasz Koziara) Date: Tue, 21 Sep 2010 18:17:30 +0100 Subject: naming the main module in embedded Python Message-ID: Hi I am embedding Python as an interpret in my code. Now, whenever my code or Python itself issues an error/warning message I am getting something like: File "", line 1, in or __main__:46: RuntimeWarning: My warning message I am using PyRun_SimpleString to load part of the code and the I call: sprintf (line, "execfile ('%s')", path); error = PyRun_SimpleString (line). The question is: how can I set up the module name or input file name so that my error/warning messages output them rather than the above default values? Thanks Tomek From john at castleamber.com Tue Sep 21 13:53:01 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 12:53:01 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: <8739t3m1aa.fsf@castleamber.com> geremy condra writes: > It's a joke. Admittedly it's a bit pointed, but it's a joke > nonetheless, and it does at least provide what I consider to be two > valuable pieces of information: that you should have googled this > before asking, and what you should have googled for. If I miss and > you've done your homework already, well, at least you get the smug > satisfaction of knowing that I was too stupid to understand your > question. It makes you a patronizing fuck in my book. And no, that's not a joke. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Tue Sep 21 13:57:34 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 12:57:34 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: <87y6avkmi9.fsf@castleamber.com> Steven D'Aprano writes: > I prefer the old fashioned version: > > "Google Is Your Friend" > > followed by a URL to the appropriate google's search results page. Or > even more to the point: > > "Did you bother to google for the answer first? Because the very first > page that comes up gives exactly the answer you want." > > Although sometimes people genuinely don't know what search terms they > should be using, or if they're too generic. Yes, exactly. I agree 100% with you (including the microsecond amusement value of lmgtfy). Besides the link to the SERP I also provide a link to what I consider the best result found on that page. Sometimes people were able to find the result, and thought it was not right. Or were not able to find the best solution out of the hundreds offered by Google. And some people are ashamed of telling that they have used Google, and couldn't find it. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Tue Sep 21 14:00:54 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 13:00:54 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: <87tyljkmcp.fsf@castleamber.com> Dennis Lee Bieber writes: > On 21 Sep 2010 05:01:45 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > >> Hey, that would be an *awesome* google bombing project... to get lmgtfy >> to come up as the first link for "self-righteous dicks". 4chan, where are >> you when we need you??? >> > I think the news reports are that they are wasting time on a DDoS > attack on the RIAA... > > While I don't agree with the RIAA's methods, I also think a DDoS is > definitely NOT an action to endear one to that one's views... It is/was, from what I understand, a "back at ya" since the RIAA hired a company in India to DDoS torrent related sites. The Indian company is/was also under DDoS. I do agree that it's somewhat pointless. They better could block access to movie theaters all over the world by chaining themselves to the entry. But, hey, then they have to get out of the couch and get out of the house. And their moms might start to ask questions... -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Tue Sep 21 14:04:46 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 13:04:46 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <87pqw7km69.fsf@castleamber.com> Dennis Lee Bieber writes: > On Mon, 20 Sep 2010 20:12:01 -0500, John Bokma > declaimed the following in gmane.comp.python.general: > > >> I never saw the point of the whole X-No-Archive: Yes thing. What happens >> if I quote such a message? It's archived, right? > > Compliant clients (like Agent) will echo the X-No-Archive: Yes in > YOUR reply -- so it too will be deleted at some point in time. Ouch, while asking me first, I hope? -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Tue Sep 21 14:05:44 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 13:05:44 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <87lj6vkm4n.fsf@castleamber.com> Lawrence D'Oliveiro writes: > In message <87aanbx5lq.fsf at castleamber.com>, John Bokma wrote: > >> I never saw the point of the whole X-No-Archive: Yes thing. What happens >> if I quote such a message? It's archived, right? > > Where did they come from? > Posting fragments, followed up-- > Originals? No more. L a s p ENTER -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From emile at fenx.com Tue Sep 21 14:22:09 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 21 Sep 2010 11:22:09 -0700 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: References: Message-ID: On 9/21/2010 5:29 AM Ant said... > Is there a solution to this that anyone knows of? Has Zed jumped to > conclusions? Have I? I'd say the error was in selecting something other that the lowest common subset of python functions when designing and writing a python version dependent Mongrel2. There are certainly ways (and perhaps compatibility libraries as well) to write python at a 2.4 (or 2.2) level to sidestep installation issues related to python versions. Targeting a wide range of installation platforms without taking that into account is the problem. When you issue a 2.5 dependent version and find it easier to convert it all to C rather than write the (relatively minor) python fixes, it speaks to the level of python competency as well. What if I wrote a 64bit app and complained that in 32bit environments it didn't do the right thing? Emile From vineetdaniel at gmail.com Tue Sep 21 14:32:26 2010 From: vineetdaniel at gmail.com (vineet daniel) Date: Tue, 21 Sep 2010 11:32:26 -0700 (PDT) Subject: creating python daemon ? References: <87r5gnyrg3.fsf@web.de> Message-ID: <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> On Sep 21, 9:47?pm, de... at web.de (Diez B. Roggisch) wrote: > vineet daniel writes: > > Hi > > > I have succesfully created daemon with python script and as next step > > I am trying to give input to that python script daemon from Apache > > Logs....here I have got stuck and I have even checked IRC python > > channel for solution. Apache is able to call the file but fails to > > execute it properly and I get this error continuosly : > > > piped log program '/var/www/html/test.py' failed unexpectedly > > > How do I rectify the above error and make adjustment to the code so > > that it takes input from apache. > > > code that I am using is as follows : > > > #! /usr/bin/env python > > import sys,os > > pid = os.fork() > > os.chdir("/var/www/html/") > > os.setsid() > > os.umask(0) > > #this line will read apache log in real time as redirected from the > > CustomLog directive of Apache. > > log = sys.stdin.readlines() > > f = open('/var/www/logmongo.txt','a') # append log to this text file > > f.write(log) > > > I'd appreciate if anybody could share the code that they used for > > daemon or used with Apache CustomLog directive. > > The above code looks errornous - you don't check for the return-value of > PID & take appropriate action. Like > > There is a daemonization recipe on active-state, which works nicely for > me. > > http://code.activestate.com/recipes/278731-creating-a-daemon-the-pyth... > > Diez Hi Diez Thanks for pointing that out. Ever tried giving input to such python daemons from a dynamic source like Apache logs which get generated in real time. I want apache to directly write to this python daemon which in turn will process the logs the way I want. Any help will help me immensely. From debatem1 at gmail.com Tue Sep 21 14:32:42 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 21 Sep 2010 11:32:42 -0700 Subject: Down with tinyurl! In-Reply-To: <8739t3m1aa.fsf@castleamber.com> References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <8739t3m1aa.fsf@castleamber.com> Message-ID: On Tue, Sep 21, 2010 at 10:53 AM, John Bokma wrote: > geremy condra writes: > >> It's a joke. Admittedly it's a bit pointed, but it's a joke >> nonetheless, and it does at least provide what I consider to be two >> valuable pieces of information: that you should have googled this >> before asking, and what you should have googled for. If I miss and >> you've done your homework already, well, at least you get the smug >> satisfaction of knowing that I was too stupid to understand your >> question. > > It makes you a patronizing fuck in my book. And no, that's not a joke. so you've said before. It still doesn't bother me, although it does make me wonder how you're reading my posts- I was under the impression that you'd killfiled me at some point. Geremy Condra From tobias.koeck at gmail.com Tue Sep 21 14:35:14 2010 From: tobias.koeck at gmail.com (joblack) Date: Tue, 21 Sep 2010 11:35:14 -0700 (PDT) Subject: polymorphic function question Message-ID: <93d149a0-5d66-422f-ae5b-39fceff5f531@a11g2000vbn.googlegroups.com> Let's say I've got a function with def doesSomething(A='bla'): ... and I try to call it with a non existent variable with doesSomething(DoesNotExist) What will happen? Will it throw an exception or will it take the defautl value? From emile at fenx.com Tue Sep 21 14:38:11 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 21 Sep 2010 11:38:11 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On 9/20/2010 7:55 PM Lawrence D'Oliveiro said... > In message, geremy > condra wrote: > >> Usually here that just means its a letmegooglethatforyou.com link, which I >> find more amusing than is probably healthy. > > Why hold back, I also use fuckinggoogleit.com. :) more than just a joke fuckinggoogleit.com is still an answer :) Emile From gh at gregor-horvath.com Tue Sep 21 14:39:08 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Tue, 21 Sep 2010 20:39:08 +0200 Subject: polymorphic function question References: <93d149a0-5d66-422f-ae5b-39fceff5f531@a11g2000vbn.googlegroups.com> Message-ID: <20100921203908.32c359ee@valun> Am Tue, 21 Sep 2010 11:35:14 -0700 (PDT) schrieb joblack : > Let's say I've got a function with > > def doesSomething(A='bla'): > ... > > and I try to call it with a non existent variable with > > doesSomething(DoesNotExist) > > What will happen? Will it throw an exception or will it take the > defautl value? The interpreter is omniscient, just ask him: Python 2.6.6 (r266:84292, Aug 29 2010, 12:36:23) [GCC 4.4.5 20100824 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def doesSomething(A='bla'): ... pass ... >>> doesSomething(DoesNotExist) Traceback (most recent call last): File "", line 1, in NameError: name 'DoesNotExist' is not defined -- Greg From astley.lejasper at gmail.com Tue Sep 21 14:41:04 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Tue, 21 Sep 2010 11:41:04 -0700 (PDT) Subject: Grouping pairs - suggested tools References: <79047d2d-4d9a-4e74-b44b-1010cf033525@t11g2000vbc.googlegroups.com> Message-ID: <0e2d95a1-af00-4f2a-acf8-dfa7ef1da80c@c32g2000vbq.googlegroups.com> > I think you have the same bug as Alf's code, you never merge existing > groups. Have you tried Arnaud's counterexample? > > By the way, are ('a', 'b') and ('b', 'a') to be considered equivalent for > your problem? > > Peter Hi Peter, Yes. I realise that this doesn't take into account existing relationships/groupings. For the particular situation that I am looking at this is unlikely to happen and/or not critical. However, I understand that generally you would want to potentially assign an item to one or more groups. In my case the ('a','b') and ('b','a') are equivalent. Perhaps for anyone else looking at this, I can elaborate on the problem to make it a bit more concrete. I have a very long listing of customer details and am trying to clean the data. In particular I am looking for duplicates: << Core Data >> id, Name, Address a, Acme Ltd, 1 Main Street b, Acme Limited, 1 Main St c, Acme L'td, 1 Main Street d, Smiths, 22 Upper Road e, Smyths, 22 Upper Rd f, Smiths ltd, 22 Upperrd g, Apple Empire, 222 Lower Way h, Apple Emp, 222 Lower Way Obviously this is oversimplified. The actual dataset has thousands of records. I am using the difflib module and comparing each item against all those below it, and where the items are similar they are stored in a paired table << Paired Data >> id1, id2, relationship_strength a, b, 0.8 a, c, 0.88 b, c, 0.8 d, e, 0.75 d, f, 0.88 e, f, 0.87 g, h, 0.77 However, these pairing aren't so easy to read and I want to include the full address and account information so it's easier for the lucky person who is going to clean the data. And this is where the grouping cluster comes in. << Grouped Data >> group_id, id 1, a 1, b 1, c 2, d 2, e 2, f 3, g 3, h So in my situation those records that are very similar to each other will be clustered together. Thanks again. ALJ From nad at acm.org Tue Sep 21 14:42:53 2010 From: nad at acm.org (Ned Deily) Date: Tue, 21 Sep 2010 11:42:53 -0700 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: In article <87zkvbytnk.fsf at web.de>, deets at web.de (Diez B. Roggisch) wrote: > The point is that the distro doesn't care about the python eco > system. Which is what I care about, and a lot of people who want to ship > software. I don't think that is totally accurate or fair. There is regular participation in the python-dev group by packagers from various distros. For example, Matthias Klose is not only the primary Debian Python maintainer, he is also has commit privileges for Python itself and he regularly contributes patches. Currently, I see current Python 2.6.6 and 3.1.2 packages in Debian testing with current Python 2.7 and Python 3.2 alpha coming along in Debian experimental. -- Ned Deily, nad at acm.org From brian.curtin at gmail.com Tue Sep 21 14:56:36 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 21 Sep 2010 13:56:36 -0500 Subject: develop for Windows on GNU/Linux, using Python In-Reply-To: References: Message-ID: On Tue, Sep 21, 2010 at 03:36, Lawrence D'Oliveiro wrote: > In message , Kev > Dwyer > wrote: > > > To be confident that your code is good you need to test it on a Windows > > box (we all test, right?). > > Preferably more than one. Test with Seven as well as Vista (yes, there are > still some Vista users out there). What about the difference between > Starter > versus Home Basic versus Home Premium versus Professional versus Ultimate > versus whatever? To be 100% safe, you probably need to test with all those > as well. > > Test on machines running the various major antivirus packages, because you > have no idea how they might screw things up. > > In other words, with Windows the guideline is: test till it hurts. Then > test > some more. Testing with every single Win7 SKU is not necessary. The Windows API is the same on all of them, the file system is the same, they are the same underlying operating system, but they are equipped with different types of tools. For example, at one of those levels they enable Terminal Server, something that should not affect your project (unless your project is a Terminal Server related tool, of course). For CPython, we test with XP (Win32 API version 5.1) and 7 (ver 6.1, same as Server 2008 R2). I have previously done a lot of my development on Server 2003 (ver 5.2, same as XP x64), although there is no buildbot slave running for that OS. If I need anything tested for Vista (ver 6.0, same as Server 2008), another OS without a buildbot slave, I know of a Vista user that can usually lend a hand. There would be no benefit to us to test CPython on all available releases of each OS -- it would be more of a burden, actually. As for antivirus screwing things up, that may be of interest to some projects, mainly those opening and then deleting files very quickly. The CPython test suite occasionally runs into issues deleting temporary files because the AV tools that some users have installed try to scan them in the very small time frame the file is intended to exist. TortoiseSVN also latches on long enough that handles to the file exist when a test tries to clean up after itself, thus causing seemingly random test failures. There's an open issue to fix that, though. -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Tue Sep 21 15:34:17 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 21 Sep 2010 12:34:17 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: On 21 Sep, 11:13, Peter Otten <__pete... at web.de> wrote: [...] > > A straightforward implementation: > > $ cat group_edges.py > def find_groups(edges): > ? ? lookup = {} # node --> group > ? ? groups = {} # id(group) --> group > ? ? for a, b in edges: ? ? ? ? ? ? ? > ? ? ? ? if a in lookup: ? ? ? ? ? ? ? > ? ? ? ? ? ? if b in lookup: ? ? ? ? ? > ? ? ? ? ? ? ? ? ga = lookup[a] ? ? ? > ? ? ? ? ? ? ? ? gb = lookup[b] ? ? ? > ? ? ? ? ? ? ? ? if ga is not gb: ? ? > ? ? ? ? ? ? ? ? ? ? # merge groups ? > ? ? ? ? ? ? ? ? ? ? if len(ga) < len(gb): > ? ? ? ? ? ? ? ? ? ? ? ? # always update the smaller group > ? ? ? ? ? ? ? ? ? ? ? ? ga, gb = gb, ga ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? del groups[id(gb)] ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ga.update(gb) ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? for k in gb: ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? lookup[k] = ga ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? # add b to a's group ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ga = lookup[a] > ? ? ? ? ? ? ? ? ga.add(b) > ? ? ? ? ? ? ? ? lookup[b] = ga > ? ? ? ? elif b in lookup: > ? ? ? ? ? ? # add a to b's group > ? ? ? ? ? ? gb = lookup[b] > ? ? ? ? ? ? gb.add(a) > ? ? ? ? ? ? lookup[a] = gb > ? ? ? ? else: > ? ? ? ? ? ? # create new group > ? ? ? ? ? ? g = set((a, b)) > ? ? ? ? ? ? groups[id(g)] = g > ? ? ? ? ? ? lookup[a] = lookup[b] = g > ? ? return groups.values() > > def show_groups(edges): > ? ? groups = sorted(sorted(g) for g in find_groups(edges)) > ? ? for i, group in enumerate(groups, 1): > ? ? ? ? for node in sorted(group): > ? ? ? ? ? ? print i, node > I think I would go for the two-step approach of constructing the graph first and then recursively building connected components. It sounds more complicated at first but when you implement it it turns out quite simple: from collections import defaultdict from itertools import count def build_groups(edges): neighbors = defaultdict(set) for x, y in edges: neighbors[x].add(y) neighbors[y].add(x) groups, group_indices = {}, count(1) def set_group(x, group_index): groups[x] = group_index for y in neighbors[x]: if y not in groups: set_group(y, group_index) for x in neighbors: if x not in groups: set_group(x, group_indices.next()) return groups if __name__ == "__main__": def print_groups(edges): print " ".join(edges) groups = build_groups(edges) for x, i in sorted(groups.items()): print i, x print examples = [ ['ab', 'bc', 'ad', 'ef', 'gf', 'hi'], ['ac', 'bd', 'cd'], ] for edges in examples: print_groups(edges) $ python connected.py ab bc ad ef gf hi 1 a 1 b 1 c 1 d 2 e 2 f 2 g 3 h 3 i ac bd cd 1 a 1 b 1 c 1 d -- Arnaud From python at rcn.com Tue Sep 21 15:41:40 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 21 Sep 2010 12:41:40 -0700 (PDT) Subject: Combinations or Permutations References: Message-ID: <88b36889-e55b-415e-8a12-9611304683c1@l25g2000prn.googlegroups.com> On Sep 20, 1:54?pm, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] Try this: >>> from itertools import combinations >>> list(combinations('abcde', 2)) [('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'), ('b', 'c'), ('b', 'd'), ('b', 'e'), ('c', 'd'), ('c', 'e'), ('d', 'e')] Raymond From raoulbia at gmail.com Tue Sep 21 16:35:09 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 21 Sep 2010 13:35:09 -0700 (PDT) Subject: basic 2 player wordgame References: <0f3ae081-cab9-43d9-9ddd-2f3f6926dc9d@a11g2000vbn.googlegroups.com> Message-ID: On Sep 21, 1:39?pm, Mel wrote: > Baba wrote: > > I am working on a simple wordgame exercise: 2 players form a word by > > alternating turns saying a letter, which is added on to the end of the > > word fragment. > > > I am familiar with loops, iterations etc but i need a hint as to how > > to approach alternating turns when writing this code? > > One way (not tested): > > thisplayer = Player() > otherplayer = Player() > while not_won: > ? ? thisplayer.take_turn() > ? ? thisplayer, otherplayer = otherplayer, thisplayer > > ? ? ? ? Mel. Hi Mel, Thank you very much. Your suggestion works like a charm :) def alternating_turns(): hand = [] thisPlayer = 'player1' otherPlayer = 'player2' while len(hand) < 3: print 'turn %s: ' %(thisPlayer) letter = raw_input('enter letter: ') hand.append(letter) thisPlayer, otherPlayer = otherPlayer, thisPlayer print hand alternating_turns() thanks again! much appreciated. this was a first for me where i have learned a practical way to apply mutation. Baba From antroy at gmail.com Tue Sep 21 16:54:55 2010 From: antroy at gmail.com (Ant) Date: Tue, 21 Sep 2010 13:54:55 -0700 (PDT) Subject: Python in Linux - barrier to Python 3.x References: Message-ID: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> On Sep 21, 2:04?pm, Philip Semanchuk wrote: > On Sep 21, 2010, at 8:29 AM, Ant wrote: > Don't know about Python 3 on Fedora (I use a Mac), but distrowatch.org reports that Fedora has been using Python >= 2.6 since Fedora 11 which was released in June of 2009. Yes you are right - I've checked on my home machine, and it is indeed 2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading an OS in order to get the latest version of one package is a bit much! I know that this is a distribution issue, and not strictly a Python one, but the issue exists primarily because python is such a successful language it has become deeply embedded in linux distributions, and so there is now a lot of work involved in checking that a python upgrade doesn't break things. Some solution involving virtualenv is perhaps a possibility. From magawake at gmail.com Tue Sep 21 18:04:24 2010 From: magawake at gmail.com (Mag Gam) Date: Tue, 21 Sep 2010 18:04:24 -0400 Subject: ncurses pad question Message-ID: I am having some trouble understanding how padding/windowing works for Python curses. According to this example on http://docs.python.org/howto/curses.html I see: pad = curses.newpad(100, 100) # These loops fill the pad with letters; this is # explained in the next section for y in range(0, 100): for x in range(0, 100): try: pad.addch(y,x, ord('a') + (x*x+y*y) % 26 ) except curses.error: pass # Displays a section of the pad in the middle of the screen pad.refresh( 0,0, 5,5, 20,75) Now if I want another pad, lets call it: pad1=curses.newpad(100,300) pad1.addch(0,0,ord('X')) pad1.refresh(0,0,120,120,110,130) For some reason I get, pad1.refresh(0,0,120,130,140,180) _curses.error:prefresh() return ERR Any ideas? From jsf80238 at gmail.com Tue Sep 21 18:06:00 2010 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 21 Sep 2010 15:06:00 -0700 Subject: Subprocess does not return for longer-running process Message-ID: Hello, The Popen call does not return if the underlying OS call runs longish, as the example below shows. Although, if the underlying OS call is merely "sleep N" it will return even after quite a long time. wikiuser at dvprwiki1:~> python --version Python 2.6.4 wikiuser at dvprwiki1:~> time /opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space TIS --user cli --password cli | head -1 132 pages in list real??? 0m1.245s user??? 0m1.482s sys???? 0m0.153s wikiuser at dvprwiki1:~> time /opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space Oncall --user cli --password cli | head -1 19645 pages in list real??? 0m14.425s user??? 0m9.866s sys???? 0m1.110s wikiuser at dvprwiki1:~> cat $HOME/scripts/subprocess_test.py #!/usr/bin/env python import os, sys from subprocess import Popen, PIPE def execute(command_list=["sleep", "1"]): ??? process = Popen(command_list, shell=False, stdout=PIPE) ??? (pid, exit_code) = os.waitpid(process.pid, 0) ??? if process.stdout != None: ??????? print process.stdout.read() ??? if process.stderr != None: ??????? print process.stderr.read() ??? return exit_code if __name__ == "__main__": ??? if len(sys.argv) > 1: ??????? execute(sys.argv[1].split()) ??? else: ??????? execute() wikiuser at dvprwiki1:~> time $HOME/scripts/subprocess_test.py "/opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space TIS --user cli --password cli" | head -1 132 pages in list real??? 0m1.233s user??? 0m1.437s sys???? 0m0.169s wikiuser at dvprwiki1:~> time $HOME/scripts/subprocess_test.py "/opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space Oncall --user cli --password cli" | head -1 Traceback (most recent call last): ? File "$HOME/scripts/subprocess_test.py", line 18, in ??? execute(sys.argv[1].split()) ? File "$HOME/scripts/subprocess_test.py", line 9, in execute ??? (pid, exit_code) = os.waitpid(process.pid, 0) KeyboardInterrupt real??? 1m25.306s user??? 0m0.021s sys???? 0m0.035s (Note I killed this last command with CNTL-C.) From burton at userful.com Tue Sep 21 18:26:33 2010 From: burton at userful.com (Burton Samograd) Date: Tue, 21 Sep 2010 16:26:33 -0600 Subject: naming the main module in embedded Python References: Message-ID: Tomasz Koziara writes: > I am embedding Python as an interpret in my code. Now, whenever my > code or Python itself issues an error/warning message I am getting > something like: > > File "", line 1, in > > or > > __main__:46: RuntimeWarning: My warning message > > I am using PyRun_SimpleString to load part of the code and the I call: > > sprintf (line, "execfile ('%s')", path); > error = PyRun_SimpleString (line). > > The question is: how can I set up the module name or input file name > so that my error/warning messages output them rather than the above > default values? Use this rather than execfile: exec compile(code, filename, "exec") You'll have to read the contents of the file into the string 'code' first (unless compile will take a file object, which I'm not sure about). -- Burton Samograd From mail at hellmutweber.de Tue Sep 21 18:31:04 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Wed, 22 Sep 2010 00:31:04 +0200 Subject: how to get partition information of a hard disk with python Message-ID: <4C993228.4000201@hellmutweber.de> Hi list, I'm looking for a possibility to access the partiton inforamtion of a hard disk of my computer from within a python program. Googling I found the module 'parted' but didn't see any possibility to get the desired information. Is there any reasonable documentation for the parted module? Any idea is appreciated ;-) TIA Hellmut -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From raoulbia at gmail.com Tue Sep 21 18:39:05 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 21 Sep 2010 15:39:05 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) Message-ID: Hi query level: beginner as part of a learning exercise i have written code that: a) asks for a single letter input (assumption: only 1 letter wil be entered) b) adds that letter to list1 and then goes through list2 and checks: 1) if any item in list2 starts with list1 > if False: break 2) if list1 == any item in list2 > if True: break c) start again until 2) is True wordlist = ['hello', 'bye'] handlist = [] letter = raw_input('enter letter: ') handlist.append(letter) hand = "".join(handlist) for item in wordlist: if item.startswith(hand): while item.startswith(hand): if hand not in wordlist: letter = raw_input('enter letter: ') handlist.append(letter) hand = "".join(handlist) else: break else: break print 'you loose' this code works but can it be optimised? i have the feeling that my nesting of IF, WHILE and FOR statements is overkill? inspired by part IV of http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset5.pdf thanks Baba From python at bdurham.com Tue Sep 21 19:10:42 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 21 Sep 2010 19:10:42 -0400 Subject: Iterate through a single iterator from multiple places in a loop Message-ID: <1285110642.16994.1396217467@webmail.messagingengine.com> Is there a pythonic way to loop through a single iterator from multiple places in a loop? Here's pseudo code for what I would like to do: for char in some_long_string: if char == some_char: for char in some_long_string: <--- using same iterator as above # continue to pull chars from some_long_string # until some conditions are met # repeat above pattern again several times in the loop, # with iterator access potentially nested One solution might be to convert some_long_string into a generator that pops of a single character at a time? Is there a simple way wrap a string as a generator or do I need to create a custom function for this? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Sep 21 19:14:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Sep 2010 00:14:30 +0100 Subject: how to get partition information of a hard disk with python In-Reply-To: <4C993228.4000201@hellmutweber.de> References: <4C993228.4000201@hellmutweber.de> Message-ID: <4C993C56.2050005@mrabarnett.plus.com> On 21/09/2010 23:31, Hellmut Weber wrote: > Hi list, > I'm looking for a possibility to access the partiton inforamtion of a > hard disk of my computer from within a python program. > > Googling I found the module 'parted' but didn't see any possibility to > get the desired information. > Is there any reasonable documentation for the parted module? > > Any idea is appreciated ;-) > Did you see this: http://www.gnu.org/software/parted/manual/ From deets at web.de Tue Sep 21 19:16:18 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 22 Sep 2010 01:16:18 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: Ned Deily writes: > In article <87zkvbytnk.fsf at web.de>, deets at web.de (Diez B. Roggisch) > wrote: >> The point is that the distro doesn't care about the python eco >> system. Which is what I care about, and a lot of people who want to ship >> software. > > I don't think that is totally accurate or fair. There is regular > participation in the python-dev group by packagers from various distros. > For example, Matthias Klose is not only the primary Debian Python > maintainer, he is also has commit privileges for Python itself and he > regularly contributes patches. Currently, I see current Python 2.6.6 > and 3.1.2 packages in Debian testing with current Python 2.7 and Python > 3.2 alpha coming along in Debian experimental. I'm sorry, this was worded stronger than appropriate. Let me rephrase: The distros have their own (perfectly reasonable) agenda. Yet this may still conflict with the needs of users regarding e.g. contemporary package availability. I already mentioned in another post that the current debian stable features TurboGears 1.0.4. Which is by itself a problem, but also ties a lot of dependencies to "ancient" versions. So frankly, if I want to run (which in fact I do) a perfecly fine TurboGears2 system on lenny, I'm *forced* to use virtualenv and consorts. In other words: I think that the goals of a linux distribution don't necessarily are the same than those of a python package maintainer. In an ideal world, they would be congruent. But they aren't. My wish would be that unless that this congruency is achieved (which isn't feasible I fear), a python-only package management solution can be implemented and be adopted even by the distros without neglecting their own issues. Diez From ben+python at benfinney.id.au Tue Sep 21 19:19:12 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 22 Sep 2010 09:19:12 +1000 Subject: creating python daemon ? References: Message-ID: <87tyli4rdb.fsf@benfinney.id.au> vineet daniel writes: > I'd appreciate if anybody could share the code that they used for > daemon or used with Apache CustomLog directive. I don't know about using Apache's CustomLog, but the ?python-daemon? library is specifically intended for creating a well-behaved Unix daemon . -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but if they called them ?Sad Meals?, kids wouldn't buy | _o__) them!? ?_Pinky and The Brain_ | Ben Finney From python at mrabarnett.plus.com Tue Sep 21 19:27:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Sep 2010 00:27:25 +0100 Subject: Iterate through a single iterator from multiple places in a loop In-Reply-To: <1285110642.16994.1396217467@webmail.messagingengine.com> References: <1285110642.16994.1396217467@webmail.messagingengine.com> Message-ID: <4C993F5D.4090205@mrabarnett.plus.com> On 22/09/2010 00:10, python at bdurham.com wrote: > Is there a pythonic way to loop through a single iterator from > multiple places in a loop? > > Here's pseudo code for what I would like to do: > > for char in some_long_string: > if char == some_char: > for char in some_long_string: <--- using same iterator as above > # continue to pull chars from some_long_string > # until some conditions are met > > # repeat above pattern again several times in the loop, > # with iterator access potentially nested > > One solution might be to convert some_long_string into a generator > that pops of a single character at a time? > > Is there a simple way wrap a string as a generator or do I need to > create a custom function for this? it = iter(some_long_string) for char in it: if char == some_char: for char in it: # continue to pull chars from some_long_string # until some conditions are met # repeat above pattern again several times in the loop, # with iterator access potentially nested From python at bdurham.com Tue Sep 21 19:46:39 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 21 Sep 2010 19:46:39 -0400 Subject: Thank-you (Re: Iterate through a single iterator from multiple places in a loop) In-Reply-To: <4C993F5D.4090205@mrabarnett.plus.com> References: <1285110642.16994.1396217467@webmail.messagingengine.com> <4C993F5D.4090205@mrabarnett.plus.com> Message-ID: <1285112799.24980.1396223079@webmail.messagingengine.com> MRAB, > it = iter(some_long_string) Well, that was easy! :) Thanks for your help. Malcolm ----- Original message ----- From: "MRAB" To: python-list at python.org Date: Wed, 22 Sep 2010 00:27:25 +0100 Subject: Re: Iterate through a single iterator from multiple places in a loop On 22/09/2010 00:10, python at bdurham.com wrote: > Is there a pythonic way to loop through a single iterator from > multiple places in a loop? > > Here's pseudo code for what I would like to do: > > for char in some_long_string: > if char == some_char: > for char in some_long_string: <--- using same iterator as above > # continue to pull chars from some_long_string > # until some conditions are met > > # repeat above pattern again several times in the loop, > # with iterator access potentially nested > > One solution might be to convert some_long_string into a generator > that pops of a single character at a time? > > Is there a simple way wrap a string as a generator or do I need to > create a custom function for this? it = iter(some_long_string) for char in it: if char == some_char: for char in it: # continue to pull chars from some_long_string # until some conditions are met # repeat above pattern again several times in the loop, # with iterator access potentially nested -- http://mail.python.org/mailman/listinfo/python-list From nad at acm.org Tue Sep 21 20:17:59 2010 From: nad at acm.org (Ned Deily) Date: Tue, 21 Sep 2010 17:17:59 -0700 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: In article , deets at web.de (Diez B. Roggisch) wrote: > Ned Deily writes: > > In article <87zkvbytnk.fsf at web.de>, deets at web.de (Diez B. Roggisch) > > wrote: > >> The point is that the distro doesn't care about the python eco > >> system. Which is what I care about, and a lot of people who want to ship > >> software. > > I don't think that is totally accurate or fair. There is regular > > participation in the python-dev group by packagers from various distros. > > For example, Matthias Klose is not only the primary Debian Python > > maintainer, he is also has commit privileges for Python itself and he > > regularly contributes patches. Currently, I see current Python 2.6.6 > > and 3.1.2 packages in Debian testing with current Python 2.7 and Python > > 3.2 alpha coming along in Debian experimental. > > I'm sorry, this was worded stronger than appropriate. Let me rephrase: > The distros have their own (perfectly reasonable) agenda. Yet this may > still conflict with the needs of users regarding e.g. contemporary > package availability. I already mentioned in another post that the > current debian stable features TurboGears 1.0.4. Which is by itself a > problem, but also ties a lot of dependencies to "ancient" versions. So > frankly, if I want to run (which in fact I do) a perfecly fine > TurboGears2 system on lenny, I'm *forced* to use virtualenv and > consorts. > > In other words: I think that the goals of a linux distribution don't > necessarily are the same than those of a python package maintainer. In > an ideal world, they would be congruent. But they aren't. My wish would > be that unless that this congruency is achieved (which isn't feasible I > fear), a > python-only package management solution can be implemented and be > adopted even by the distros without neglecting their own issues. Thanks for the clarification. While I too wish such a general python-only package management solution existed, the big blocker is and will remain the effort required to manage the package quirks (local patches), package dependencies, platform differences, unit testing, unit testing across multiple platforms, system testing (packages with their dependencies - think Django or Zope), packaging and distribution. In short think of all the steps and infrastructure that go into, say, the Debian development process, which - not to slight the others out there - I consider to be the most mature and rigorous of the large open source integration projects. While much of it can be (and, to some extent, already is) automated, there is still a strong human involvement required at nearly all stages. Repeatable and predictable does not necessarily mean totally automated or scalable. Getting to where Debian is today has required an almost superhuman and ongoing effort and dedication over many years by many people. Having been intimately involved over the years in various software release processes most involving hundreds of people, I remain somewhat awestruck in what they have accomplished. I'm not optimistic that the resources or leadership are available in the community to make something similar happen for Python packages. It's an enormous task. -- Ned Deily, nad at acm.org From clp2 at rebertia.com Tue Sep 21 20:33:25 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 21 Sep 2010 17:33:25 -0700 Subject: Subprocess does not return for longer-running process In-Reply-To: References: Message-ID: On Tue, Sep 21, 2010 at 3:06 PM, Jason Friedman wrote: > Hello, > > The Popen call does not return if the underlying OS call runs longish, > as the example below shows. > wikiuser at dvprwiki1:~> time $HOME/scripts/subprocess_test.py > "/opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space > Oncall --user cli --password cli" | head -1 > Traceback (most recent call last): > ? File "$HOME/scripts/subprocess_test.py", line 18, in > ??? execute(sys.argv[1].split()) > ? File "$HOME/scripts/subprocess_test.py", line 9, in execute > ??? (pid, exit_code) = os.waitpid(process.pid, 0) > KeyboardInterrupt > > real??? 1m25.306s > user??? 0m0.021s > sys???? 0m0.035s > > (Note I killed this last command with CNTL-C.) As your Traceback clearly indicates, the Popen() call has already completed; it's *the os.waitpid() call* that's blocking, but that's entirely to be expected given its defined behavior. If you don't want to wait around for the process to die, then don't call waitpid() on it in the first place! Cheers, Chris From rplasson at gmail.com Tue Sep 21 22:38:06 2010 From: rplasson at gmail.com (=?ISO-8859-1?Q?Rapha=EBl_Plasson?=) Date: Tue, 21 Sep 2010 19:38:06 -0700 (PDT) Subject: Best way for rotating a matrix of data? Message-ID: <3207b8a9-a566-478d-a5db-859db162b8e4@p24g2000pra.googlegroups.com> Hello, after some computations, I obtain a 2D matrix of data, in a numpy array. I can easily plot them using pyplot, and can easily extract either vertical or horizontal slices by plotting a row or a column of this matrix. I would like to be able to plot slices form this data array, but with an arbitrary angle. Thus my question: what is the best way to do so? For the moment the solution I am using is to go through image transformation, using PIL, by a function returning : array(Image.fromarray().rotate(,resample=Image.BICUBIC)) In short, I convert the array in an image object, I rotate it, and then convert it back to an array. Not very clean, rather a work around than a solution, indeed. Actually, I more precisely extract my 2D array from much higher dimensions data (i.e. 10-20 fields of different data in 3 dimensions of space+1 dimension of time), contained in a hdf5 file. I typically would like to extract arbitrary slices of any of the fields from the 3+1D space... and I don't really know how this can be simply done. I can only extract an "orthogonal" 2D space from this space, and rotate it with the above method. Is there a more direct way to extract arbitrary slices directly from 2/3/4D arrays? Which python modules would be able to do the job? Thank you, Raphael From gburdell1 at gmail.com Tue Sep 21 23:03:42 2010 From: gburdell1 at gmail.com (gburdell1 at gmail.com) Date: Tue, 21 Sep 2010 20:03:42 -0700 (PDT) Subject: Expanding a vector by replicating elements individually Message-ID: Given m=numpy.array([[1, 2, 3]]) I want to obtain array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) One way I've found to do this is: numpy.reshape(numpy.tile(m,(4,1)),(12,1),'f').T Another way is: numpy.reshape(numpy.tile(m,(4,1)).flatten(1),(1,12)) Is there a simpler way to do this, without having to go jump through so many hoops? From kushal.kumaran at gmail.com Tue Sep 21 23:28:31 2010 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Wed, 22 Sep 2010 08:58:31 +0530 Subject: [OT] apache customlog (was Re: creating python daemon ?) Message-ID: On 9/21/10, vineet daniel wrote: > Hi > > I have succesfully created daemon with python script and as next step > I am trying to give input to that python script daemon from Apache > Logs....here I have got stuck and I have even checked IRC python > channel for solution. Apache is able to call the file but fails to > execute it properly and I get this error continuosly : > > piped log program '/var/www/html/test.py' failed unexpectedly > > How do I rectify the above error and make adjustment to the code so > that it takes input from apache. > > >From a quick look at the CustomLog docs, it doesn't seem that you need a daemon. Apache will simply run your program and send logging directives to your program's stdin. In fact, a daemon, which from apache's perspective just exits immediately, will give you the behaviour you're seeing. Googling around should result in some examples. -- regards, kushal From python at rcn.com Wed Sep 22 00:38:40 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 21 Sep 2010 21:38:40 -0700 (PDT) Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: <27971e53-c135-443c-bece-d1535bc2ff62@g6g2000pro.googlegroups.com> [Steven D'Aprano] > But if I try to create a regular dict from this, dict() doesn't call my > __getitem__ method: > > >>> dict(d) > > {0: ('a', 'extra_data'), 1: ('b', 'extra_data')} > > instead of {0: 'a', 1: 'b'} as I expected. > > How can I fix this? Try using dict(d.items()). Raymond From __peter__ at web.de Wed Sep 22 02:30:42 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Sep 2010 08:30:42 +0200 Subject: Expanding a vector by replicating elements individually References: Message-ID: gburdell1 at gmail.com wrote: > Given > > m=numpy.array([[1, 2, 3]]) > > I want to obtain > > array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) >>> numpy.array([1,2,3]).repeat(4) array([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) Peter From nagle at animats.com Wed Sep 22 02:46:20 2010 From: nagle at animats.com (John Nagle) Date: Tue, 21 Sep 2010 23:46:20 -0700 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: <4c99a64e$0$1651$742ec2ed@news.sonic.net> On 9/21/2010 11:42 AM, Ned Deily wrote: > In article<87zkvbytnk.fsf at web.de>, deets at web.de (Diez B. Roggisch) > wrote: >> The point is that the distro doesn't care about the python eco >> system. Which is what I care about, and a lot of people who want to ship >> software. > > I don't think that is totally accurate or fair. There is regular > participation in the python-dev group by packagers from various distros. > For example, Matthias Klose is not only the primary Debian Python > maintainer, he is also has commit privileges for Python itself and he > regularly contributes patches. Currently, I see current Python 2.6.6 > and 3.1.2 packages in Debian testing with current Python 2.7 and Python > 3.2 alpha coming along in Debian experimental. Debian seems to have a well worked out Python policy: http://www.debian.org/doc/packaging-manuals/python-policy/ They address the need to have multiple versions of Python on the same machine in a reasonably clean way. So do the ActiveState people, although their way is different than the Debian way. Trying to make Python play well with distros is probably more useful than trying to make distros play well with Python. Rather than fancier "distutils" or "eggs", I'd suggest developing tools that take in "setup.py" files and make Windows installers, RPMs, or whatever the platform likes. John Nagle From eckhardt at satorlaser.com Wed Sep 22 03:16:12 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 22 Sep 2010 09:16:12 +0200 Subject: utf-8 coding sometimes it works, most of the time it don't work. References: Message-ID: Stef Mientki wrote: > When running this python application from the command line ( or launched > from another Python program), the wrong character encoding (probably > windows-1252) is used. Rule #1: If you know the correct encoding, set it yourself. This particularly applies to files you open yourself (use the codec module). In the case of your program, I guess the stream with the faulty encoding is stdin/stdout, who's encoding is guessed by Python, but which you can override. Check sys.stdin.encoding. > When I run this program from PyScripter ( either internal engine or remote > engine), MSHTML shows the correct character encoding, > perfect! Interesting, I would say that PyScripter sets up the environment differently, so that Python guesses a different encoding. Also make sure both are calling the same Python, I get 'cp850' or 'US-ASCII' depending on whether I call the native MS Windows Python or the Cygwin Python. > In the main file, and in the major files that constains strings I've added > the following 2 lines: > # -*- coding: utf-8 -*- > from __future__ import absolute_import, unicode_literals This shouldn't matter. This just tells Python that the sourcecode itself is encoded in UTF-8 and that you want to use Unicode names in your string literals, it doesn't affect the output of your program. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Wed Sep 22 03:30:42 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Sep 2010 09:30:42 +0200 Subject: Grouping pairs - suggested tools References: Message-ID: Arnaud Delobelle wrote: > I think I would go for the two-step approach of constructing the graph > first and then recursively building connected components. It sounds > more complicated at first but when you implement it it turns out quite > simple: > > from collections import defaultdict > from itertools import count > > def build_groups(edges): > neighbors = defaultdict(set) > for x, y in edges: > neighbors[x].add(y) > neighbors[y].add(x) > > groups, group_indices = {}, count(1) > def set_group(x, group_index): > groups[x] = group_index > for y in neighbors[x]: > if y not in groups: > set_group(y, group_index) > > for x in neighbors: > if x not in groups: > set_group(x, group_indices.next()) > return groups That looks a little less like legwork than mine. My only objection is that you may hit Python's low recursion limit. Peter From bruno.42.desthuilliers at websiteburo.invalid Wed Sep 22 03:59:13 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 22 Sep 2010 09:59:13 +0200 Subject: This Is International =?UTF-8?B?RG9u4oCZdC1TcXVhd2stTGlrZS1B?= =?UTF-8?B?LVBhcnJvdCBEYXk=?= In-Reply-To: References: Message-ID: <4c99b745$0$9306$426a34cc@news.free.fr> Lawrence D'Oliveiro a ?crit : > Next we need an International Surfin? Bird day, a day to go around and tell > everybody that the bird bird bird, the bird is the word. +1 From stef.mientki at gmail.com Wed Sep 22 04:15:30 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 22 Sep 2010 10:15:30 +0200 Subject: utf-8 coding sometimes it works, most of the time it don't work. In-Reply-To: References: Message-ID: hello Uli, thanks, I think you hit the nail on it's head, PyScripter indeed changes default encoding but .. On Wed, Sep 22, 2010 at 9:16 AM, Ulrich Eckhardt wrote: > Stef Mientki wrote: > > When running this python application from the command line ( or launched > > from another Python program), the wrong character encoding (probably > > windows-1252) is used. > > Rule #1: If you know the correct encoding, set it yourself. This > particularly applies to files you open yourself (use the codec module). In > the case of your program, I guess the stream with the faulty encoding is > stdin/stdout, who's encoding is guessed by Python, but which you can > override. Check sys.stdin.encoding. > None, So I guess it's using the windows default, which is windows-1252, and it's ReadOnly so I can't change it. Can you tell me how I change the default Python encoding, or how to set the encoding in Popen, this is the statement I use to launch my program subprocess.Popen ( [ 'python', Filename ] ) thanks, Stef Mientki > > > When I run this program from PyScripter ( either internal engine or > remote > > engine), MSHTML shows the correct character encoding, > > perfect! > > Interesting, I would say that PyScripter sets up the environment > differently, so that Python guesses a different encoding. Also make sure > both are calling the same Python, I get 'cp850' or 'US-ASCII' depending on > whether I call the native MS Windows Python or the Cygwin Python. > > > In the main file, and in the major files that constains strings I've > added > > the following 2 lines: > > # -*- coding: utf-8 -*- > > from __future__ import absolute_import, unicode_literals > > This shouldn't matter. This just tells Python that the sourcecode itself is > encoded in UTF-8 and that you want to use Unicode names in your string > literals, it doesn't affect the output of your program. > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Wed Sep 22 04:29:53 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 22 Sep 2010 01:29:53 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: On Sep 22, 8:30?am, Peter Otten <__pete... at web.de> wrote: > Arnaud Delobelle wrote: > > I think I would go for the two-step approach of constructing the graph > > first and then recursively building connected components. ?It sounds > > more complicated at first but when you implement it it turns out quite > > simple: > > > from collections import defaultdict > > from itertools import count > > > def build_groups(edges): > > ? ? neighbors = defaultdict(set) > > ? ? for x, y in edges: > > ? ? ? ? neighbors[x].add(y) > > ? ? ? ? neighbors[y].add(x) > > > ? ? groups, group_indices = {}, count(1) > > ? ? def set_group(x, group_index): > > ? ? ? ? groups[x] = group_index > > ? ? ? ? for y in neighbors[x]: > > ? ? ? ? ? ? if y not in groups: > > ? ? ? ? ? ? ? ? set_group(y, group_index) > > > ? ? for x in neighbors: > > ? ? ? ? if x not in groups: > > ? ? ? ? ? ? set_group(x, group_indices.next()) > > ? ? return groups > > That looks a little less like legwork than mine. My only objection is that > you may hit Python's low recursion limit. > > Peter True. One could setrecursionlimit() temporarily to work around this. Or here is an alternative set_group() function: def set_group(x, group_index): group = [x] for y in group: groups[y] = group_index group.extend(z for z in neighbors[y] if z not in groups]) It's untested! -- Arnaud From deets at web.de Wed Sep 22 05:20:59 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 22 Sep 2010 11:20:59 +0200 Subject: creating python daemon ? References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> Message-ID: <87fwx2yw04.fsf@web.de> vineet daniel writes: > On Sep 21, 9:47?pm, de... at web.de (Diez B. Roggisch) wrote: >> vineet daniel writes: >> > Hi >> >> > I have succesfully created daemon with python script and as next step >> > I am trying to give input to that python script daemon from Apache >> > Logs....here I have got stuck and I have even checked IRC python >> > channel for solution. Apache is able to call the file but fails to >> > execute it properly and I get this error continuosly : >> >> > piped log program '/var/www/html/test.py' failed unexpectedly >> >> > How do I rectify the above error and make adjustment to the code so >> > that it takes input from apache. >> >> > code that I am using is as follows : >> >> > #! /usr/bin/env python >> > import sys,os >> > pid = os.fork() >> > os.chdir("/var/www/html/") >> > os.setsid() >> > os.umask(0) >> > #this line will read apache log in real time as redirected from the >> > CustomLog directive of Apache. >> > log = sys.stdin.readlines() >> > f = open('/var/www/logmongo.txt','a') # append log to this text file >> > f.write(log) >> >> > I'd appreciate if anybody could share the code that they used for >> > daemon or used with Apache CustomLog directive. >> >> The above code looks errornous - you don't check for the return-value of >> PID & take appropriate action. Like >> >> There is a daemonization recipe on active-state, which works nicely for >> me. >> >> http://code.activestate.com/recipes/278731-creating-a-daemon-the-pyth... >> >> Diez > > Hi Diez > > Thanks for pointing that out. > Ever tried giving input to such python daemons from a dynamic source > like Apache logs which get generated in real time. I want apache to > directly write to this python daemon which in turn will process the > logs the way I want. Any help will help me immensely. I don't understand the question. How is that input produced? How shall the two processes interact? Through some logfile one writes, the other reads? Through RPC-mechanisms? Sockets? Pipes? The fact that process B is a daemon or not has nothing to do with this whatsoever, btw. Diez From arunmohan.c at gmail.com Wed Sep 22 07:35:41 2010 From: arunmohan.c at gmail.com (AMC) Date: Wed, 22 Sep 2010 04:35:41 -0700 (PDT) Subject: Error installing cx_Oracle Message-ID: <7e622b5f-1715-472e-aa47-ea145305fa36@k22g2000prb.googlegroups.com> Hi, >From last months I am using Python for making small but useful tools for my team members. I am doing my development in windows machine and running the program in Solaris machine where Python 2.6.2 is installed. In one of my program file I had to use the module "cx_Oracle".For that I have installed the module in my windows machine and done the programming. But the finished program does not run in Solaris machine, may be because "cx_Oracle" was not installed there.Following is the error shown. root at access1:/home/amohan/python/work/broadcast_report/bin$ ./ runsql.py Traceback (most recent call last): File "./runsql.py", line 3, in import cx_Oracle ImportError: ld.so.1: isapython2.6: fatal: /opt/webstack/python/lib/ python2.6/site-packages/cx_Oracle.so: wrong ELF class: ELFCLASS64 root at access1:/home/amohan/python/work/broadcast_report/bin$ I tried installing "cx_Oracle" with easy_install utility (I am not strong in Solaris). While installing I am getting some error as shown below. root at access1:/$ easy_install cx_Oracle Searching for cx-Oracle Reading http://pypi.python.org/simple/cx_Oracle/ Reading http://cx-oracle.sourceforge.net Reading http://starship.python.net/crew/atuining Best match: cx-Oracle 5.0.4 Downloading http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4.tar.gz?download Processing cx_Oracle-5.0.4.tar.gz Running cx_Oracle-5.0.4/setup.py -q bdist_egg --dist-dir /tmp/ easy_install-FkDQn5/cx_Oracle-5.0.4/egg-dist-tmp-Ogg94s "SessionPool.c", line 200: warning: integer overflow detected: op "<<" ld: fatal: library -lpython2.6: not found ld: fatal: File processing errors. No output written to build/ lib.solaris-2.10-i86pc-2.6-10g/cx_Oracle.so error: Setup script exited with error: command '/opt/webstack/python/ lib/python2.6/pycc' failed with exit status 1 root at access1:/$ I have searched for a solution everywhere and tried many things but didn't work. Can somebody help me in this? Thanks, AMC. From saruviel at hotmail.com Wed Sep 22 09:52:58 2010 From: saruviel at hotmail.com (saruviel) Date: Wed, 22 Sep 2010 06:52:58 -0700 (PDT) Subject: Life Message-ID: <46df27ef-26ee-423e-aaa7-e75351a7e743@a7g2000prb.googlegroups.com> Life By Daniel Daly A series of, perhaps random thoughts, or if you take the time to try and make some coherent sense of the whole, perhaps something deeper. But probably not. I was inspired to start this task by the book ?By the Waters of Galilee? by Fr Luke Fay of Catholic faith. I had read the first two chapters, was enjoying it, and started thinking. And I thought of a work called ?Life? with a similar cover to the cover of Fr Fay?s work. And the idea was simply a writing of life. Perhaps the closest thing that was to come to it was a self-help book, but in its purest form I intended it to not even be that. Perhaps philosophy, but I am not trying to be philosophical, yet it probably is philosophy, even though that is not my intent. I simply wanted to write thoughts on life, thoughts about a positive moral life, which might make it almost a religious or spiritual text, but that was not the intent. It is simply to be about life, not a novel, not a work of science, but just thoughts on life. Perhaps I should be dramatic and write lovely poetical language about the wonders of creation in true King David style. King David wrote some of the Psalms in the Holy Bible and wrote about creation a bit. At least, the psalms are recorded as being written by King David, but some people (Funk of the Historical Jesus) says no to that from memory. I suppose as this work unfolds I will write about nature, but if I was perfectly honest I am no King David. I know I really should care about the plight of the whales and that Japan are really naughty, but I think they just like whale meat, so to hell with that. How about the oil spill off the American coast. Thank God its over there is probably the bottom line for this shallow environmentalist. Anyway, enough with current affairs. Actually, no, I will write on some current affairs. I prayed, a while back, for Kevin Rudd to be Prime Minister for 21 years. I am keeping the faith on that prayer, as I am a left wing idealist. My friend Adrian Chan is not the biggest fan of politicians, but I assume they generally have good intentions, and that the demands of satisfying everyone means they aggravate a lot of people. But that is only life after all. I like listening to music. I have schizophrenia so often go on mad rampages and destroy half of my cd collection in a fit of psychosis. But psychosis affects a lot of people, so I am not alone. I was at the pool recently and I thought up some ideas for a whacky book called ?Zen I?. The dialogue goes something like this. Zen Zen I Zen I Zen I Zen I Zen I Zen I Zen I Zen Zen Zen Zen I I I I Zen I Zen I Zen I Zen I Zen I Zen Zen Zen I Zen Zen I Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen Zen Zen Zen Zen Zen Zen Zen I Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen Zen Zen Zen Zen Zen Zen Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen Zen Zen Zen Zen Zen Zen Zen I I I I I Zen Zen I Zen Zen Zen I Zen I Zen I Zen I & so on and so forth in about 40 pages of a little hardback anthology. On the final page the last line goes: Zen Zen I Zen I Zen I Zen Zen (4XQR#) Zen I Zen I Zen I It is non stop Zen I until that line. I don?t know why, it just is. Heh. I reckon Madonna should go into the studio with a compilation of new songs written by songwriters she has hired. She should do an album a day for 3 years straight ? over 1000 albums ? just doing one or two takes of each song, and being filmed all the time, and with video workers simply making videos for all the songs for her from the ongoing video of her singing. Just one to two takes of the song, get the album finished, and released. And do this every day for 3 years. She can hire countless mixers and producers for the stuff and just realease a shitload of albums and videos. Overkill in the most extreme, and it really doesn?t matter if they sell that much, because there will be enough diehards who will buy all of them and she will sell tonnes. She is a hard worker, could get the job done, and it would get her the highest album sales of all time after a while. Someone with her fame and wealth could do that, and I would if I could sing, had her fame and her money. 4 + 4 = 8 8 + 8 = 16 16 + 16 = 32 Mathematics is a very entertaining subject for intellectuals. You see, intellectuals are what they call in classic American schoolyard jargon, the nerds. And the nerds like Maths, English, Science, and putting computer systems together. I hope to be a fully qualified nerd upon retirement. Think of all the dollar bills they end up getting, hey. I mean look at Billy Gates. Come up with Microsoft and what the Trillions role in. But apparently the kids don?t get a cent, and have to work for themselves. Now that?s a responsible parent. Intellectuals also like philosophy, sneering at religious people who believe in creationism (which I do), and listening to classical or alternative music and disdaining all things commercial. Heavy Metal has a similar attitude, especially back in the day. I mean, if you were a metalhead and listened to the Spice Girls it was a death penalty offense or excommunication from the headbangers ball. And if you touched Boyzone they would torture you first. Heavy Metal gurus are another bunch of pseudo-intellectual snobs. Parading their Black Sabbath albums, saying that Led Zeppelin are gods, and that such and such a band ? their current fave ? has reinvented heavy metal forever. They love to give ratings in heavy metal mags, but rolling stone does that too. And people honestly take an interest in these ratings. But if there is one thing I have discovered is that tastes are often very subjective ? they vary widely from person to person ? and an album that somebody may rate very poorly, another set of persons might enjoy tremendously. Especially poppy commercial stuff which is, again, sneered at, but which usually sells the most because the kids have enough sense to buy albums which are actually fun and not laden down with depressing angst and bullshit feelings of a so-called contemplated soul. Intelligent albums SUCK unless there is a quality of music which is attractive, melodic and memorable. Michael Jackson, for example, may be on many supposedly serious music critics hate list for his pop classic ?Thriller?, but he is at number one because he knows what the kids like. And, funnily enough, these commercial artists who sell the most end up being the ?Beatles? of their era, and end up very respected. It happens to them with time and age. Mozart was an upstart to some to start with, despite his brilliance (apparently). Justin Beiber, for example, would be laughed at by a supposedly serious music critic, but the kids are not dumb. He sings a song which perfectly captures their vibe as teenagers, and is entirely appropriate and critically excellent for his target audience. He doesn?t have to produce Amy Lee or Bob Dylan. That is not his audience, and would be stupid to suggest it is. But that is what people often fall into with age ? they forget the younger generation are learning, and that they too once liked such stuff. Oh, and as a confirmed Noahide, I don?t really mind if the Beatles thought they were bigger than Jesus for a while. They possibly were. When I was younger I felt it important to develop religious morality to be a perfect person. I still think that somewhat, but don?t worry as much anymore. Jesus says in the gospels ?Be Ye Perfect as your Father in Heaven is Perfect.? A challenge to Christians I suppose. You know, there are a hell of a lot of those 2 billion Christians (I have seen the statistics ? approx 1 bill Catholics and 1 bill non- catholic Christians) who work there assess of spiritually to give Jesus a hell of a witness for the continued growth and establishment of his church of Glory. As a Noahide I view Jesus as an ambitious Jewish man, dedicated to his own glory, by and large. Now, as a Christian most of you view Jesus as God. But he isn?t. He wasn?t. And he never will be. He was just a bloke. If you don?t believe me ask God the father (ie Yahweh). These days he might possibly inform you upon the answer to that question, as he is severely pro-Israel from all my personal observations. Anyway, in current rankings of the all time most popular human beings, the rankings approximately come up like this. Number One ? Jesus of Nazareth Number Two ? Muhammed Number Three ? Jesus mother, Mary Number Four ? Buddha Number Five ? Moses, I think Number Six ? Apostle Paul Number Seven ? The current number seven is either Taylor Swift or Miley Cyrus on current myspace page hits. This might surprise you, but this is their era and the current ?Cult of Personality? has HUGE fanbases. Really fucking HUGE fanbases. Anyway Miley and Taylor edge out Apostle Peter, King David, Abraham, Jacob, Adolph Hitler, and Justin Beiber for the present, but he is in the top 20 all time just about. I know that is recent, but you don?t know the power of the current fame monster, as Gaga puts it, with the ever expanding human population. Mao Tse Tung, Joseph Stalin, Karl Marx, Shakespeare, Robert Pattinson, Daniel Radcliffe, Angelina Jolie, Brad Pitt, Victoria Beckham, George Washington, J K Rowling, J R R Tolkien, Marilyn Monroe, Elvis Presley, Winston Churchill & Emma Watson are some of the very big names, likely in the top thirty to forty all time. Add on Wolfgang Amadeus Mozart and Ludwig Van Beethoven who are currently the two number ones in the classical scene ? they share the honour. But number one is the carpenter from Nazareth. Still caining after 2000 years. Believe me, that takes some effort, but with the beloved ?Cross? at his disposal, which the faithful were around their necks with pride, the ?Christ Child? isn?t letting go of the number one slot any time soon. Hey, people think he is actually God himself, and that takes a lot to compete with. But somebody?s got to do it. Probably 666 will show up, some dude or dudette thinking that might work for a while, and take on the JC fellow. Bad news at the moment, though, because most humans are patently aware that the mark of the beast is bad news on judgement day. But, fucking hell, Iron Maiden released ?Number of the Beast? and sold a shitload. I guess the Antichrist is a keen competitor to the big fellow. You never know, he might grab the top slot for a while. What was that? Seven years says my pentecostal friend? Tribulation glory, but it won?t last? Aye Carumba. So how did Jesus get to the top slot? I have written on that before, but lets just say this much. If you can win somebody?s respect, and then start a religious cult, and then have that cult evangelize their socks off for 2000 years, it sure as hell helps. So how do you potential wannabes start a religious cult then? In Christianity every tom dick and harry started a church for a while. They were called protestants. So, to be a protestant, it is simple. Tell your current pastoral overlord to take a running jump, and start preaching those doctrines you have always wanted to preach, and evangelize. Evangelization is easy. First, do up a free website on angelfire, and post your church doctrines and teachings. Go to the library and print off 100 pages of A4 flyers, 4 flyers to a page, and cut them into 4s and make sure you put the name of the church and the website link and email address. And then, if you really want to build wonderchurch, make it your hobby to go to carparks, put flyers on car windows, and do this for 20 years. Its slow, but it works. Now, for you lateral thinkers, Christianity is basically covered. Try something new. L Ron Hubbard did. He called it scientology, and the freaks practically worship him. So go for something pseudo spiritual, a catchy name, special key teachings on enlightenment, and stick to your guns. Oh, and be dramatic. It helps. Those thoughts will do for now. I might continue this some time. Oh, and one last thing. I want to plug a few books which are truly excellent. Hugh Cook ? the 10 Volume epic ?Chronicles of an Age of Darkness?. Intense, weird, novel, original and exciting. David Eddings ? The Eternal ?Belgariad? series. I have SEEN the Harry Potters, but Edding?s, while currently still very popular, deserves to reach J K Rowling numbers in sales. Raymond E Feist ? Magician. The ultimate fantasy epic, and the first volume of the Riftwar saga. Hugely popular, and deserves to be, and really you should read it. And one last plug: My favourite all time rock album ? Bon Jovi ?New Jersey? My favourite all time pop album ? Rihanna ?Good Girl Gone Bad? My favourite all time Christian album ? Susan Ashton ?A Distant Call? Daniel http://noahidebooks.angelfire.com From pruebauno at latinmail.com Wed Sep 22 10:38:12 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 22 Sep 2010 07:38:12 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: Message-ID: <1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com> On Sep 21, 6:39?pm, Baba wrote: > Hi > > query level: beginner > > as part of a learning exercise i have written code that: > > a) asks for a single letter input (assumption: only 1 letter wil be > entered) > b) adds that letter to list1 and then goes through list2 and checks: > > ? ? 1) if any item in list2 starts with list1 > if False: break > ? ? 2) if list1 == any item in list2 > if True: break > > c) start again until 2) is True > > wordlist = ['hello', 'bye'] > handlist = [] > letter = raw_input('enter letter: ') > handlist.append(letter) > hand = "".join(handlist) > for item in wordlist: > ? ? if item.startswith(hand): > ? ? ? ? while item.startswith(hand): > ? ? ? ? ? ? if hand not in wordlist: > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > ? ? ? ? ? ? ? ? handlist.append(letter) > ? ? ? ? ? ? ? ? hand = "".join(handlist) > ? ? ? ? ? ? else: break > ? ? ? ? else: break > print 'you loose' > > this code works but can it be optimised? i have the feeling that my > nesting of IF, WHILE and FOR statements is overkill? > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > thanks > Baba Yes it is overkill. Especially the else:break from the while loop makes it difficult to follow the logic. Also the program breaks down if I use the following word list: wordlist = ['hello', 'hamburger', 'bye'] >>> enter letter: h enter letter: a you loose I am not going to post any spoilers but I wrote your program using one while loop and one generator expression for a total of 5 lines. My version might be a bit too advanced but you should still be able to do it using only one while, one for and one if instead. From nobody at nowhere.com Wed Sep 22 12:38:28 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 22 Sep 2010 17:38:28 +0100 Subject: Subprocess does not return for longer-running process References: Message-ID: On Tue, 21 Sep 2010 23:54:04 -0700, Dennis Lee Bieber wrote: >> As your Traceback clearly indicates, the Popen() call has already >> completed; it's *the os.waitpid() call* that's blocking, but that's >> entirely to be expected given its defined behavior. If you don't want >> to wait around for the process to die, then don't call waitpid() on it >> in the first place! >> > And a likely reason the waitpid() if blocking is that the > sub-process is blocking trying to write to pipe that is full. Which is why you should always use the .communicate() method if you redirect two or more of std{in,out,err} to a pipe (this is why the Unix popen() function only lets you redirect one of the standard descriptors). And I can't think of any reason why you should use os.waitpid() or similar; use the .wait() method. From nobody at nowhere.com Wed Sep 22 12:41:34 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 22 Sep 2010 17:41:34 +0100 Subject: how to get partition information of a hard disk with python References: Message-ID: On Wed, 22 Sep 2010 00:31:04 +0200, Hellmut Weber wrote: > I'm looking for a possibility to access the partiton inforamtion of a > hard disk of my computer from within a python program. Have you considered parsing /proc/partitions? From xahlee at gmail.com Wed Sep 22 12:42:50 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 22 Sep 2010 09:42:50 -0700 (PDT) Subject: HTML6 proposal (Re: sexp xml syntax transformation) References: <2bebbf7e-e30d-41a7-bed5-72a132d9de79@z30g2000prg.googlegroups.com> <30bd8745-ef6a-4c5c-8f30-fbbbf8a9bd91@l32g2000prn.googlegroups.com> Message-ID: cleaned up the previous post. ? ?HTML6, Your HTML/XML Simplified? http://xahlee.org/comp/html6.html plain text version follows -------------------------------------------------- HTML6, Your HTML/XML Simplified Xah Lee, 2010-09-21 Tired of the standard bodies telling us what to do and change their altitude? Tired of the SGML/HTML/XML/XHTML/HTML5 changes? Tire no more, here's a new proposal that will make life easier. Introducing HTML6 HTML6 is based on HTML5, XML, and a rectified LISP syntax. More specifically, it is derived from existing work on this, the SXML. http://okmij.org/ftp/Scheme/SXML.html, except that there is complete regularity at syntax level, and is not considered or compatible with lisp readers. The syntax can be specified by 3 short lines of parsing expression grammar. The aim is far more simpler syntax, 100% regularity, and leaner. but with a far simpler, and more strict, format. First of all, no error is accepted, ever. If a source code has incorrect syntax, that page is not displayed. Example Here's a standard ATOM webfeed XML file. Xah's Emacs Blog Emacs, Emacs, Emacs 2010-09-19T14:53:08-07:00 Xah Lee http://xahlee.org/ http://xahlee.org/emacs/blog.html http://xahlee.org/ics/sum.png ? 2009, 2010 Xah Lee Using Emacs's Abbrev Mode for Abbreviation tag:xahlee.org,2010-09-19:215308 2010-09-19T14:53:08-07:00 tutorial Here's how it looks like in html6: ??xml ?version ?1.0? encoding ?utf-8??? ?feed ?xmlns ?http://www.w3.org/2005/Atom? xml:base ?http://xahlee.org/ emacs/?? ?title Xah's Emacs Blog? ?subtitle Emacs, Emacs, Emacs? ?link ?rel ?self? href ?http://xahlee.org/emacs/blog.xml??? ?link ?rel ?alternate? href ?http://xahlee.org/emacs/blog.html??? ?updated 2010-09-19T14:53:08-07:00? ?author ?name Xah Lee? ?uri http://xahlee.org/? ? ?id http://xahlee.org/emacs/blog.html? ?icon http://xahlee.org/ics/sum.png? ?rights ? 2009, 2010 Xah Lee? ?entry ?title Using Emacs's Abbrev Mode for Abbreviation? ?id tag:xahlee.org,2010-09-19:215308? ?updated 2010-09-19T14:53:08-07:00? ?summary tutorial? ?link ?rel ?alternate? href ?http://xahlee.org/emacs/ emacs_abbrev_mode.html??? ? ? Simple Matching Pairs For Tag Delimiters The standard xml markup bracket is simplified using simple lisp style matching pairs. For example, this code:

HTML6

Is written as: ?h1 HTML6? The delimiter used is: Character Unicode Code Point Unicode Name ? U+3014 LEFT TORTOISE SHELL BRACKET ? U+3015 RIGHT TORTOISE SHELL BRACKET XML Properties and Attributes Syntax In xml:

HTML6

In html6: ?h1?id ?xyz? class ?abc??HTML6? The attributes are specified by matching corner brackets. Items inside are a sequence of pairs. The value must be quoted by curly double quotes. Escape Mechanisms To include the ?tortoise shell? delimiters in data, use ?〔? and ?〕?, similarly for the ?corner brackets?. Unicode; No More CD Data and Entities ?&? There's no Entities. Except the unicode in hexadecimal format ?&#x?unicode code point hexidecimal??. For example, ?&? is not allowed. Treatment of Whitespace Basically identical to XML. Char Encoding; UTF8 and UTF16 Only Source code must be UTF8 or UTF16, only. Nothing else. File Name Extension File name extension is ?.xml6? or ?.html6?. Semantics The semantics should follow xhtml5. Questions and Answers What's wrong with xhtml/html5 exactly? The politics of standard body changes, and their attitude about what is correct also changes whimsically. In around 2000, we are told that XML and XHTML will change society, or, at least, make the web correct and valid and far more easier to develop and flexible. Now it's a decade later. Sure the web has improved, but as far as html/xhtml and browser rendering goes, it's still a syntax soup with extreme complexities. 99.99% of web pages are still not valid, and nobody cares. Major browsers still don't agree on their rendering behavior. Web dev is actually far more complex, involving tens or hundreds of tech that hardly a person even knows about (ajax, jason, lots xml variations). It's hard to say if it is better at all than the HTML3 days with ?font? and ?table? tags and gazillion tricks. The best practical approach is still trial n error with browsers. And, now HTML5 comes alone, from a newfangled hip group primarily from current big corporations Google and Apple, with a attitude that validation is overrated ? a insult to the face about the XML mantra from w3c, just when there starts to be more and more sites with correct XHTML and Microsoft's Internet Explorer getting on track about correctness. XML is break from SGML, with many justifications why it needs be, and with some backward compatible trade-offs, and now HTML5 is a break from both SGML and XML. See also: (Google Earth) KML Validation Fuckup Google's ?rel="nofollow"? Rule HTML Correctness and Validators Why not just adopt SXML from the lisp world? Lisp's SXML is not a stand-alone syntax for the need of the web. Lisp's format typically are made in a way to follow lisp's traditions, and often has quirks of its own. The syntax is not 100% regular of nested parens. SXML is easy for lispers to adopt, but harder for other languages and communities. For lisp's syntax irregularities, see: Fundamental Problems of Lisp. For example, the xml as textual representation of a tree has a quirk, in that each node has this special thing called ?attributes? (aka ?properties?). The ?attribute? is not a node of the tree, but rather, is info attached to a node. The standard lisp syntax (aka sexp) to represent attributes is this, e.g.. (h1 :id "xyz" :class "abc" ...) Syntactically, each of ?:id?, ?"xyz"? etc are not distinguishable from a node/branch in the tree. Only semantically, after lisp reader parsed the special character ?:? in a node's name, then it is considered a property name, and that the next element in the expression is being considered as a value for that property. Another way to represent xml's attribute is this: (h1 ((id . "xyz") (class . "abc")) ...) This too, have syntactical ambiguity. The whole ?((id . "xyz") (class . "abc"))? can be interpreted as a node by itself, where the first element is again a node. But also here, it uses lisp's special ?cons? syntax ?(id . "xyz")? which is itself ambiguous at the syntax level. e.g. it can be considered as a node named ?id? with 2 branches ?.? and ?"xyz"?, or it can be considered as a node named ?cons? with 2 branches ?id? and ?"xyz"?. Another common lisp syntax for attributes is this: (h1 (@ (id . "xyz") (class . "abc")) ...) Again, this whole ?(@ ...)? part at the syntax level is simply a node named ?@?. Only at the semantic level, that it is taken as properties of a node due to semantics attached to the head string ?@?. So, in conceiving html6, i thought a solution for getting rid of syntax ambiguity for node vs attributes is to use a special bracket for properties/attributes of a node. e.g. ??h1?id ?xyz? class ?abc??...??. Why use weird Unicode characters for matching pair? Unicode has become widely adopted today. (See: Unicode Popularity On Web.) Unicode also has a lot proper matching pairs. (See: Matching Brackets in Unicode.) It seems today is the right time to adopt the wide range of proper characters instead of keep relying on the very limited number of ASCII characters. The straight quote character " is not a matching pair, and in code it present several problems. For example, it is difficult to know which quote matches which. Also, it is difficult to recover from a missing quote. (this problem is especially pronounced in text editors for syntax highlighting.) A proper matching pair allow programs and editors to more easily correctly determine the quoted content, and for easily navigating the tree. The unicode characters ?? and ?? may be difficult to input. Possibly, they can be replaced by () and {} for html6. Though, that also means a lot ugly escape will need to happen in text, and if not escaped, that means incorrect syntax. One thing about this html6 is that it is intentionally separate from being a valid sexp of the lisp world. The core idea is that the syntax of html6 is designed specifically as a 2-dimentional textual representation of a tree, and with a attribute quote that attaches a limited form of info (pairs sequence) to any node to fit existing structure of XML. The advantage of this is that it should be extremely easy to parse, in perhaps just 3 lines of parsing expression grammar. And can be easily done in perl, python, ruby... without entailing lisp quirks, and can be trivially tranformed into legal lisp syntax by lisps as well. Any thoughts about flaws? Xah ? xahlee.org ? From nobody at nowhere.com Wed Sep 22 12:50:21 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 22 Sep 2010 17:50:21 +0100 Subject: Best way for rotating a matrix of data? References: <3207b8a9-a566-478d-a5db-859db162b8e4@p24g2000pra.googlegroups.com> Message-ID: On Tue, 21 Sep 2010 19:38:06 -0700, Rapha?l Plasson wrote: > Actually, I more precisely extract my 2D array from much higher > dimensions data (i.e. 10-20 fields of different data in 3 dimensions > of space+1 dimension of time), contained in a hdf5 file. I typically > would like to extract arbitrary slices of any of the fields from the > 3+1D space... and I don't really know how this can be simply done. I > can only extract an "orthogonal" 2D space from this space, and rotate > it with the above method. > > Is there a more direct way to extract arbitrary slices directly from > 2/3/4D arrays? Which python modules would be able to do the job? You can use arrays as indices, so applying a transformation to a set of index arrays (e.g. np.indices) then using those as indices is equivalent to applying a spatial transform to the data. Also: scipy.ndimage. From python at mrabarnett.plus.com Wed Sep 22 13:06:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Sep 2010 18:06:17 +0100 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: <4C9A3789.9050702@mrabarnett.plus.com> On 20/09/2010 22:42, Astley Le Jasper wrote: > I have a list of tuples that indicate a relationship, ie a is related > to b, b is related to c etc etc. What I want to do is cluster these > relationships into groups. An item will only be associated with a > single cluster. > > Before I started, I wondered if there was any particular tool within > Python I should be looking at. I don't expect anyone to code this for > me, just say ... "you need to look at using x". I was going to use > populate a dictionary and > > Sorry for being so vague. > [snip] I thought I'd join in. I've used repr to ensure that I have something that's hashable: def show_groups(pairs): groups = {} items = {} for x, y in pairs: x_repr, y_repr = repr(x), repr(y) items[x_repr] = x items[y_repr] = y x_group = groups.setdefault(x_repr, set([x_repr])) y_group = groups.setdefault(y_repr, set([y_repr])) union = set() for m in x_group | y_group: union |= groups[m] for m in union: groups[m] = union indexes = {} for s in groups.values(): indexes.setdefault(frozenset(s), len(indexes) + 1) indexes = sorted(indexes.items(), key=lambda pair: pair[1]) for s, i in indexes: for m in sorted(s): print("{0} {1}".format(i, items[m])) if __name__ == "__main__": edges = [ ('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'), ('c', 'd'), ('e', 'f'), ('e', 'g'), ('f', 'g'), ('h', 'i'), ] show_groups(edges) print() show_groups([('a', 'c'), ('b', 'd'), ('c', 'd')]) From tjreedy at udel.edu Wed Sep 22 13:30:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Sep 2010 13:30:47 -0400 Subject: Expanding a vector by replicating elements individually In-Reply-To: References: Message-ID: On 9/21/2010 11:03 PM, gburdell1 at gmail.com wrote: > Given > > m=numpy.array([[1, 2, 3]]) > > I want to obtain > > array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) > > One way I've found to do this is: > > numpy.reshape(numpy.tile(m,(4,1)),(12,1),'f').T > > Another way is: > > numpy.reshape(numpy.tile(m,(4,1)).flatten(1),(1,12)) > > Is there a simpler way to do this, without having to go jump through > so many hoops? With a Python list >>> l = [] >>> for rep in [[i]*4 for i in [1,2,3]]: l.extend(rep) >>> l [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3] or >>> list(chain(*[[i]*4 for i in [1,2,3]])) [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3] Can you adapt that with numpy.array instead of list? Might be slower though -- Terry Jan Reedy From dani.valverde at gmail.com Wed Sep 22 13:46:24 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Wed, 22 Sep 2010 19:46:24 +0200 Subject: SetGridCursor not working? Message-ID: <4C9A40F0.9040102@gmail.com> Hello! I have a table with some rows and cells (code at the end), and created a function which searches for text inside the cells and returns the row number where the text is (to simplify the example, only English Name is working). Then, it should set the grid cursor focus to that row (I want to use the wx.grid.Grid.SelectRows style when created the wx.Grid, but to reduce the number of variables I don't use it in the example). To set the cursor focus, I am using def OnSearch(self, event): CommonName = self.CommonNameTXT.GetValue() if CommonName != '': ind = self.parent.EnglishNameList.index(CommonName) self.parent.SpeciesGrid.SetGridCursor(ind, 0) self.parent.SpeciesGrid.MakeCellVisible(ind,0) Theoretically, it should work using only the SetGridCursor method, however somewhere I have read that it will not work unless you also use the MaceCellVisible method as well. Anyway, it does not work at all. Can anyone help? Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From dani.valverde at gmail.com Wed Sep 22 14:07:11 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Wed, 22 Sep 2010 20:07:11 +0200 Subject: Auto size wx.StaticText Message-ID: <4C9A45CF.4090400@gmail.com> Hello! Is there a way to automatically set the size of a wx.StaticText to fit its content? Cheers! Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From invalid at invalid.invalid Wed Sep 22 14:38:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 22 Sep 2010 18:38:34 +0000 (UTC) Subject: Auto size wx.StaticText References: Message-ID: On 2010-09-22, Dani Valverde wrote: > Is there a way to automatically set the size of a wx.StaticText to fit > its content? According to the docs, it should do that by default: http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.StaticText.html Window Styles Window Style Description wx.ALIGN_LEFT Align the text to the left wx.ALIGN_RIGHT Align the text to the right wx.ALIGN_CENTRE Center the text (horizontally) wx.ST_NO_AUTORESIZE By default, the control will adjust its size to exactly fit to the size of the text when SetLabel is called. If this style flag is given, the control will not change its size (this style is especially useful with controls which also have wx.ALIGN_RIGHT or wx.ALIGN_CENTER style because otherwise they won't make sense any longer after a call to SetLabel) -- Grant Edwards grant.b.edwards Yow! PUNK ROCK!! DISCO at DUCK!! BIRTH CONTROL!! gmail.com From martin at v.loewis.de Wed Sep 22 14:59:05 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 22 Sep 2010 20:59:05 +0200 Subject: weird error with python 2.7 installer under windows 7 In-Reply-To: References: Message-ID: > Any ideas? Try running the postinstall script by hand. Regards, Martin From brenNOSPAMbarn at NObrenSPAMbarn.net Wed Sep 22 15:46:14 2010 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Wed, 22 Sep 2010 19:46:14 +0000 (UTC) Subject: Playing sounds at time indexes Message-ID: I'm looking for an audio library for Python. I googled and found a few, but none of them seem to have a simple way to play a particular sound file from a particular start-time to an end-time. Like, I'd want to load a file and say "Play the section of this file from 10.25 seconds to 11.73 seconds." Is there a library that makes this easy in Python? Thanks, -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From jayryan.thompson at gmail.com Wed Sep 22 16:13:47 2010 From: jayryan.thompson at gmail.com (jay thompson) Date: Wed, 22 Sep 2010 13:13:47 -0700 Subject: ctypes Message-ID: Hello, I posted in regard to this in the past but it didn't go very far, no ones fault, but I'm again atempting to make this work and could use some help. I would like to use libraw.dll (http://www.libraw.org/ version 0.10) from python and can access all the functions fine and produce images but there is a structure that holds all the process settings that I cannot access with ctypes. I'm sure it's because I'm going about it the wrong way. I was wondering if there was anyone in this list with experience with this sort of thing that could point me in the right direction. Thanks! jt -- "It's quite difficult to remind people that all this stuff was here for a million years before people. So the idea that we are required to manage it is ridiculous. What we are having to manage is us." ...Bill Ballantine, marine biologist. -------------- next part -------------- An HTML attachment was scrubbed... URL: From raoulbia at gmail.com Wed Sep 22 16:18:18 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 22 Sep 2010 13:18:18 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com Message-ID: On Sep 22, 3:38?pm, nn wrote: > On Sep 21, 6:39?pm, Baba wrote: > > > > > Hi > > > query level: beginner > > > as part of a learning exercise i have written code that: > > > a) asks for a single letter input (assumption: only 1 letter wil be > > entered) > > b) adds that letter to list1 and then goes through list2 and checks: > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > ? ? 2) if list1 == any item in list2 > if True: break > > > c) start again until 2) is True > > > wordlist = ['hello', 'bye'] > > handlist = [] > > letter = raw_input('enter letter: ') > > handlist.append(letter) > > hand = "".join(handlist) > > for item in wordlist: > > ? ? if item.startswith(hand): > > ? ? ? ? while item.startswith(hand): > > ? ? ? ? ? ? if hand not in wordlist: > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > ? ? ? ? ? ? ? ? handlist.append(letter) > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > ? ? ? ? ? ? else: break > > ? ? ? ? else: break > > print 'you loose' > > > this code works but can it be optimised? i have the feeling that my > > nesting of IF, WHILE and FOR statements is overkill? > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > thanks > > Baba > > Yes it is overkill. Especially the else:break from the while loop > makes it difficult to follow the logic. Also the program breaks down > if I use the following word list: > > wordlist = ['hello', 'hamburger', 'bye'] > > enter letter: h > enter letter: a > you loose > > I am not going to post any spoilers but I wrote your program using one > while loop and one generator expression for a total of 5 lines. My > version might be a bit too advanced but you should still be able to do > it using only one while, one for and one if instead. Hi nn, i wasn't expecting my code to fail with an additional word in it. While i was conscious that the whole construct was heavy i thought the reasoning worked. I keep looking at it but can't figure out the problem Can you give me a hint? In the meantime i found out that it is actually possible to populate a string (just like a list, a dictionary or a tuple). Here's what i've got now: wordlist = ['hello', 'bye'] hand = '' for item in wordlist: if item.startswith(hand): while item.startswith(hand): if hand not in wordlist: hand += raw_input('enter letter: ') print hand else: break else: break print 'you loose' But i can't figure out why it won't work when adding the extra word. Thanks by the way, it taught me not to be too confident when things SEEM to work... Why does it work when i use the built-in function any(iterable)?? To me using the any(iterable) function seems just like regrouping 3 lines into one... wordlist = ['hello','hamburger', 'bye', 'cello'] hand = '' while any(item.startswith(hand) for item in wordlist): if hand not in wordlist: hand += raw_input('enter letter: ') else: break print 'you loose' thanks Baba From robert.kern at gmail.com Wed Sep 22 16:28:27 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 22 Sep 2010 15:28:27 -0500 Subject: Expanding a vector by replicating elements individually In-Reply-To: References: Message-ID: On 9/21/10 10:03 PM, gburdell1 at gmail.com wrote: > Given > > m=numpy.array([[1, 2, 3]]) > > I want to obtain > > array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) > > One way I've found to do this is: > > numpy.reshape(numpy.tile(m,(4,1)),(12,1),'f').T > > Another way is: > > numpy.reshape(numpy.tile(m,(4,1)).flatten(1),(1,12)) > > Is there a simpler way to do this, without having to go jump through > so many hoops? Peter Otten gave you the correct answer. If you have more numpy questions, you should ask on the numpy mailing list: http://www.scipy.org/Mailing_Lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From cmpython at gmail.com Wed Sep 22 18:27:52 2010 From: cmpython at gmail.com (CM) Date: Wed, 22 Sep 2010 15:27:52 -0700 (PDT) Subject: Auto size wx.StaticText References: Message-ID: On Sep 22, 2:38?pm, Grant Edwards wrote: > On 2010-09-22, Dani Valverde wrote: > > > Is there a way to automatically set the size of a wx.StaticText to fit > > its content? > > According to the docs, it should do that by default: > > ? ?http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.StaticText.html > > Window Styles > > ? Window Style ? ? ? ? ?Description > > ? wx.ALIGN_LEFT ? ? ? ? Align the text to the left > > ? wx.ALIGN_RIGHT ? ? ? ?Align the text to the right > > ? wx.ALIGN_CENTRE ? ? ? Center the text (horizontally) > > ? wx.ST_NO_AUTORESIZE ? By default, the control will adjust its size to > ? ? ? ? ? ? ? ? ? ? ? ? exactly fit to the size of the text when > ? ? ? ? ? ? ? ? ? ? ? ? SetLabel is called. If this style flag is > ? ? ? ? ? ? ? ? ? ? ? ? given, the control will not change its size > ? ? ? ? ? ? ? ? ? ? ? ? (this style is especially useful with controls > ? ? ? ? ? ? ? ? ? ? ? ? which also have wx.ALIGN_RIGHT or > ? ? ? ? ? ? ? ? ? ? ? ? wx.ALIGN_CENTER style because otherwise they > ? ? ? ? ? ? ? ? ? ? ? ? won't make sense any longer after a call > ? ? ? ? ? ? ? ? ? ? ? ? to SetLabel) > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! PUNK ROCK!! ?DISCO > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? DUCK!! ?BIRTH CONTROL!! > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ? Yes, just make sure, OP, that you don't pass a size to the wx.StaticText when constructing it. Or you can give the size as size=wx.Size(-1,-1), which means default size. Che From raoulbia at gmail.com Wed Sep 22 18:39:54 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 22 Sep 2010 15:39:54 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com Message-ID: <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> On Sep 22, 9:18?pm, Baba wrote: > On Sep 22, 3:38?pm, nn wrote: > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > Hi > > > > query level: beginner > > > > as part of a learning exercise i have written code that: > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > entered) > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > c) start again until 2) is True > > > > wordlist = ['hello', 'bye'] > > > handlist = [] > > > letter = raw_input('enter letter: ') > > > handlist.append(letter) > > > hand = "".join(handlist) > > > for item in wordlist: > > > ? ? if item.startswith(hand): > > > ? ? ? ? while item.startswith(hand): > > > ? ? ? ? ? ? if hand not in wordlist: > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > ? ? ? ? ? ? else: break > > > ? ? ? ? else: break > > > print 'you loose' > > > > this code works but can it be optimised? i have the feeling that my > > > nesting of IF, WHILE and FOR statements is overkill? > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > thanks > > > Baba > > > Yes it is overkill. Especially the else:break from the while loop > > makes it difficult to follow the logic. Also the program breaks down > > if I use the following word list: > > > wordlist = ['hello', 'hamburger', 'bye'] > > > enter letter: h > > enter letter: a > > you loose > > > I am not going to post any spoilers but I wrote your program using one > > while loop and one generator expression for a total of 5 lines. My > > version might be a bit too advanced but you should still be able to do > > it using only one while, one for and one if instead. > > Hi nn, > > i wasn't expecting my code to fail with an additional word in it. > While i was conscious that the whole construct was heavy i thought the > reasoning worked. I keep looking at it but can't figure out the > problem Can you give me a hint? > > In the meantime i found out that it is actually possible to populate a > string (just like a list, a dictionary or a tuple). Here's what i've > got now: > > wordlist = ['hello', 'bye'] > hand = '' > for item in wordlist: > ? ? if item.startswith(hand): > ? ? ? ? while item.startswith(hand): > ? ? ? ? ? ? if hand not in wordlist: > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > ? ? ? ? ? ? ? ? print hand > ? ? ? ? ? ? else: break > ? ? ? ? else: break > print 'you loose' > > But i can't figure out why it won't work when adding the extra word. > Thanks by the way, it taught me not to be too confident when things > SEEM to work... > > Why does it work when i use the built-in function any(iterable)?? To > me using the any(iterable) function seems just like regrouping 3 lines > into one... > > wordlist = ['hello','hamburger', 'bye', 'cello'] > hand = '' > while any(item.startswith(hand) for item in wordlist): > ? ? if hand not in wordlist: > ? ? ? ? hand += raw_input('enter letter: ') > ? ? else: break > print 'you loose' > > thanks > > Baba Hi nn, looking at my original code again i realise that having a raw_input inside a FOR loop is flawed per se (at least for my purposes) so i will just assume that i was taking the wrong approach initially. No point in analysing it further. Thanks for your help. Baba From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 19:12:39 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Sep 2010 23:12:39 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: <4c9a8d66$0$11123$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 00:51:20 -0700, Dennis Lee Bieber wrote: > On 21 Sep 2010 05:01:45 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > >> Hey, that would be an *awesome* google bombing project... to get lmgtfy >> to come up as the first link for "self-righteous dicks". 4chan, where >> are you when we need you??? >> > I think the news reports are that they are wasting time on a DDoS > attack on the RIAA... Heh, it's not a waste of time if you're enjoying yourself :) > While I don't agree with the RIAA's methods, I also think a DDoS > is definitely NOT an action to endear one to that one's views... "The customer is always right, unless they're unhappy with us." You know, I'd give my right arm -- well, perhaps somebody else's right arm -- for the opportunity to some day to be interviewing an ex-RIAA executive, just so I can say: "I see from your CV that you took millions of customers and made them so mad at you that not only did they break the law to give you the finger, but they promised to never, ever pay a cent for your products again. So tell me, how did that business strategy work out for you?" -- Steven From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 19:25:28 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Sep 2010 23:25:28 GMT Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <4c9a9068$0$11123$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 23:17:54 -0700, Dennis Lee Bieber wrote: > On Mon, 20 Sep 2010 20:12:01 -0500, John Bokma > declaimed the following in gmane.comp.python.general: > > >> I never saw the point of the whole X-No-Archive: Yes thing. What >> happens if I quote such a message? It's archived, right? > > Compliant clients (like Agent) will echo the X-No-Archive: Yes in > YOUR reply -- so it too will be deleted at some point in time. WHAT??? That's just wrong in every possible way. Just because I'm replying to somebody who wants X-No-Archive doesn't mean I want that foolishness to infect my post. Thank goodness that my client isn't compliant with that truly awful behaviour. Some standards are just *bad*. -- Steven From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 19:30:42 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Sep 2010 23:30:42 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: <4c9a91a2$0$11123$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 08:17:00 +0000, Duncan Booth wrote: > I guess you have worked hard to forget the and-or hack. It was actually: > > condition and true-clause or false-clause > > so its not quite the same pattern. So I did. Oops. Thanks for the correction. -- Steven From afffg33 at gmail.com Wed Sep 22 19:49:08 2010 From: afffg33 at gmail.com (fcgffj) Date: Wed, 22 Sep 2010 16:49:08 -0700 (PDT) Subject: Here is your chance to make the big bucks and enjoy life. http://salesuper.com/ Message-ID: <0a12c815-f96b-4cc0-b3ee-ea42ea877b6c@t7g2000vbj.googlegroups.com> Here is your chance to make the big bucks and enjoy life. http://salesuper.com/ shows everyone how to become rich. Go and check out what they have to say. ----------http://salesuper.com/--------- ----------http://salesuper.com/--------- From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 20:23:22 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 23 Sep 2010 00:23:22 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 16:17:48 +0200, Antoon Pardon wrote: > On Tue, Sep 21, 2010 at 12:07:07AM +0000, Steven D'Aprano wrote: >> On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: >> >> > Not necessarily. Some of us have the impression that Guido >> > deliberatly chose an ugly format for the ternary operator. >> >> If he did, then he must have changed his mind, because there is nothing >> ugly about the ternary operator we ended up with. > > That is a question of taste Yes, it certainly is. Describing it as "an ugly format" is also a matter of taste -- taste which in my opinion simply isn't justified by anything other than familiarity. > and the poll and discussion earlier made it > clear that this was not the preferred way to have a ternary operator. "Not preferred" != "ugly" > This form only ranked fourth (or maybe third), with the first three all > wanting ar structure with the elelement is this order: condition, true > case, false case > >> > Guido has alwasys been >> > against a ternary operator but the requests kept coming. So >> > eventually he introduced one. But the impression is that he chose an >> > ugly format in the hope of discouraging people to use it. >> >> That's sheer and unadulterated nonsense. The fact is that Guido changed >> his mind about ternary if after discovering that the work-around >> >> true-clause and condition or false-clause >> >> is buggy -- it gives the wrong answer if true-clause happens to be a >> false value like [], 0 or None. If I recall correctly, the bug bit >> Guido himself. > > Nonsense. That the work around was buggy was known years before the > ternary operator was finally introduced. But people kept forgetting it, and it bit the right person one time too many. > The introduction of list > comprehension made a ternary operator that more usefull but every time > it came up the supporters of Guido, told us we just had to define a > function if we wanted the items to depend on a condition. A function can't do the job, because it isn't lazy: def ifte(condition, x, y): if condition: return x else: return y n = 0 ifte(n != 0, 100/n, -1) will fail. This was perhaps *the* killer argument for a ternary-if operator. [...] > It seems that what changed is your memory and not the collective mind of > the python community. Fair call. -- Steven From ldo at geek-central.gen.new_zealand Wed Sep 22 20:25:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 23 Sep 2010 12:25:53 +1200 Subject: Subprocess does not return for longer-running process References: Message-ID: In message , Nobody wrote: > And I can't think of any reason why you should use os.waitpid() or > similar; use the .wait() method. I have used WNOHANG to poll for completion of a subprocess while providing progress updates to the user. From vlastimil.brom at gmail.com Wed Sep 22 20:28:24 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 23 Sep 2010 02:28:24 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: <4C92A584.8060303@mrabarnett.plus.com> <4C92B3BC.6090901@mrabarnett.plus.com> Message-ID: 2010/9/19 Dennis Lee Bieber : > On Sat, 18 Sep 2010 23:00:25 +0200, Vlastimil Brom > declaimed the following in > gmane.comp.python.general: > >> Thank you very much for detailed hints, I see, I should have mention >> the specification with my initial post... >> It is true, that nested tags of the same name aren't supported, but >> tags may appear anywhere in the text and aren't terminated with >> newline. The tag-value association is valid from the tag position >> until the next tag replacing the value or closing tag (like ) or > > ? ? ? ?Okay... Then put the start/end fields back into the database > > ? ? ? ?Also, if the data can span lines, using a foreign key to a table > having the lines is meaningless... I'd probably generate a plain text > file (one that does not contain any tags), and record the start/end > positions for the tags based as a pure character count from start of > file. Optional if you strip new-lines from this file so it is just a > long line of text... > > ? ? ? ?Parsing may need to be recursive so you can determine the end points > for outer tags and generate the full record (type, start, end, > supplement) {I didn't list ID, though my standard practice is to always > have an auto-increment ID field in a table -- it simplifies later > updates}. > > ? ? ? ?Do the tags form a hierarchy? That is, does a "higher level" tag > force a closure of all unclosed lower levels? > >> I'll have a closer look on joins in sql and maybe redesign the data >> structure - now the tags data are copied for each text position with >> some tag change - in order to simplify queries; with multiple tables >> it could be more efficient to store the tags separately and look it up >> individually (probably using bisect (unless there is an SQL equivalent >> ?) > > ? ? ? ?I'm not sure of how you mean "bisect" but I do suggest that you look > up a lesson on "database normalization" (emphasis on first, second, and > third normal forms; the others are rather esoteric). > > ? ? ? ?What I'm pretty sure you do NOT want to do is create a table for > each tag TYPE. The type is just another data value, as in my sample > tables. That makes queries much simpler since you don't run into the > problem of having to generate queries where you change the schema > entities ("schema" is the technical term for the layout of the database > -- the fixed items rather than the data; end users should never directly > enter schema items in an application [you can present a menu of schema > items and let the user pick one, but the selection is never used as-is, > it has to be restricted to a list you generate, and returns values from > your list; look up "sql injection"]) > > ? ? ? ?With the actual text in a plain file, the joins I was using are not > needed -- you'd use the start/end results to seek/read the file as a > separate step. > > ? ? ? ?However, you might have some complex queries that use subselects if > you need to retrieve a passage inside a passage (poor phrasing). > > ? ? ? ?That is, a subselect that specifies you want the start/end range of > a tag with a particular attribute, and you use the start/end as >, < > comparisons to find a different tag. Off the top of my head (hence may > not be valid SQL) > > select t1.type, t1.supplement, t1.start, t1.end from tags as t1 > ? ? ? ?inner join > ? ? ? ? ? ? ? ?(select start, end from tags > ? ? ? ? ? ? ? ? ? ? ? ?where type = "some type" > ? ? ? ? ? ? ? ? ? ? ? ?and supplement = "some value") as t2 > ? ? ? ?where t1.start >= t2.start and t1.end <= t2.end > > -- > ? ? ? ?Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ?wlfraed at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks all for the pointers and recommendations! After some tests I eventually found, that I am (for now) probably better off with nested (default)dict and set data; while querying tags for a given index was very elegant even with a very simple database design, I wasn't able to get the other query (text interval(s) for given combination of tag-values) with a comparably straightforward solution. It seems, that in order to handle tag combinations of arbitrary length either programmatically created queries or maybe recursion or some kind of postprocessing database data using interval arithmetic would be needed (or probably some database features, I am not getting :) In any case the initial custom datastructure seems to meet the requirements after all. Thanks again, Vlastimil Brom From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 20:33:28 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 23 Sep 2010 00:33:28 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> Message-ID: <4c9aa057$0$11123$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 12:26:29 -0400, Andreas Waldenburger wrote: > On Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Carl Banks > wrote: > >> On Sep 17, 1:01?pm, Andreas Waldenburger >> wrote: >> > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: >> > >> > > I also like this construct that works, I think, since 2.6: >> > >> > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] >> > >> > I wonder when this construct will finally start to look good. >> >> I don't know if it'll ever look good, per se, but it looks better when >> it's used in rule-exception sort of case: >> >> something = rule if condition else exception >> > Spot on. I (more or less) like it when used that way, too. But it seems > to invite crackers like the example above, and that irks me. I don't see that one of these is more of a cracker than the other: code = if side == 'l' then dir[int(num):] else dir[:-1*int(num)] code = side == 'l' if dir[int(num):] else dir[:-1*int(num)] code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] If you ask me, the *least* hard to read is the last. Unary and binary operators are natural in a language which is parsed in a single dimension (left-to-right in the case of English). There is no entirely natural way to parse a ternary operator, because you need to fit three operands into two slots. That's why mathematicians often use two dimensions when they need a ternary operator, like sum: ? ? expr i=0 -- Steven From flebber.crue at gmail.com Wed Sep 22 20:41:12 2010 From: flebber.crue at gmail.com (flebber) Date: Wed, 22 Sep 2010 17:41:12 -0700 (PDT) Subject: Python Macros's Not the Power in OOo they should be ? Message-ID: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> I have recently been looking at openoffice because I saw it had support to use python Macro's. I thought this would provide OOo with a great advantage a fully powerful high level language as compared to VBA in Excel. I have found few docs on the subject. http://wiki.services.openoffice.org/wiki/Python_as_a_macro_language http://development.openoffice.org/ http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework Doesn't appear at the moment Python doesn't have the power in OOo it should. Has anyone had much success with python macro's. Or developing powerful macro's in an language? From flebber.crue at gmail.com Wed Sep 22 21:26:50 2010 From: flebber.crue at gmail.com (flebber) Date: Wed, 22 Sep 2010 18:26:50 -0700 (PDT) Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: <8d412c32-d997-40ce-b201-b26ba2f63349@13g2000prf.googlegroups.com> On Sep 23, 10:41?am, flebber wrote: > I have recently been looking at openoffice because I saw it had > support to use python Macro's. I thought this would provide OOo with a > great advantage a fully powerful high level language as compared to > VBA in Excel. > > I have found few docs on the subject.http://wiki.services.openoffice.org/wiki/Python_as_a_macro_languagehttp://development.openoffice.org/http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Scrip... > > Doesn't appear at the moment Python doesn't have the power in OOo it > should. Has anyone had much success with python macro's. Or developing > powerful macro's in an language? I sort of expected they might have had jpython or javascript version of the excel VBA editor. From john at castleamber.com Wed Sep 22 21:37:12 2010 From: john at castleamber.com (John Bokma) Date: Wed, 22 Sep 2010 20:37:12 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> <4c9a8d66$0$11123$c3e8da3@news.astraweb.com> Message-ID: <87r5glme9j.fsf@castleamber.com> Steven D'Aprano writes: > You know, I'd give my right arm -- well, perhaps somebody else's right > arm -- for the opportunity to some day to be interviewing an ex-RIAA > executive, just so I can say: > > "I see from your CV that you took millions of customers and made them so > mad at you that not only did they break the law to give you the finger, > but they promised to never, ever pay a cent for your products again. So > tell me, how did that business strategy work out for you?" I guess he will smile at you and blind you with his diamond teeth :-D. Also, the RIAA has been breaking the law as well. They do it via hired sneeky companies, but in my book they are still responsible. (dDOS of torrent sites/clients) -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Wed Sep 22 21:45:55 2010 From: john at castleamber.com (John Bokma) Date: Wed, 22 Sep 2010 20:45:55 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> <4c9aa057$0$11123$c3e8da3@news.astraweb.com> Message-ID: <87k4mdmdv0.fsf@castleamber.com> Steven D'Aprano writes: For completeness sake: code = side == 'l' ? dir[int(num):] : dir[:-1*int(num)] > code = if side == 'l' then dir[int(num):] else dir[:-1*int(num)] > code = side == 'l' if dir[int(num):] else dir[:-1*int(num)] > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > > If you ask me, the *least* hard to read is the last. For me the (newly added) first one, because it has (for me) less noise. But I can certainly live with the last one. Or all for that matter. Or maybe: since the results are already somewhat complex (or noisy) I probably would use a "normal" if else. What surprises me is that this is still discussed. It's like argueing about significant whitespace. :-) -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From usenet-nospam at seebs.net Wed Sep 22 21:49:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 01:49:44 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-23, Steven D'Aprano wrote: > Yes, it certainly is. Describing it as "an ugly format" is also a matter > of taste -- taste which in my opinion simply isn't justified by anything > other than familiarity. It may not be convincing to other people, but the logical inversion strikes me as a taste issue which goes beyond mere familiarity. It is not unreasonable to continue to dislike something which breaks a general principle even after long familiarity. So I think there is a real issue. There are arguments going the other way, and while they don't fit my sense of aesthetics, I guess they aren't strictly required to. But I do think it's unfair to dismiss it as purely a matter of baby duck syndrome. Consistency in ordering of corresponding idioms seems a reasonable goal. -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 prologic at shortcircuit.net.au Wed Sep 22 22:55:07 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 23 Sep 2010 12:55:07 +1000 Subject: Error installing cx_Oracle In-Reply-To: <7e622b5f-1715-472e-aa47-ea145305fa36@k22g2000prb.googlegroups.com> References: <7e622b5f-1715-472e-aa47-ea145305fa36@k22g2000prb.googlegroups.com> Message-ID: On Wed, Sep 22, 2010 at 9:35 PM, AMC wrote: > Hi, > > >From last months I am using Python for making small but useful tools > for my team members. I am doing my development in windows machine and > running the program in Solaris machine where Python 2.6.2 is > installed. > > In one of my program file I had to use the module "cx_Oracle".For that > I have installed the module in my windows machine and done the > programming. But the finished program does not run in Solaris machine, > may be because "cx_Oracle" was not installed there.Following is the > error shown. > > root at access1:/home/amohan/python/work/broadcast_report/bin$ ./ > runsql.py > Traceback (most recent call last): > ?File "./runsql.py", line 3, in > ? ?import cx_Oracle > ImportError: ld.so.1: isapython2.6: fatal: /opt/webstack/python/lib/ > python2.6/site-packages/cx_Oracle.so: wrong ELF class: ELFCLASS64 > root at access1:/home/amohan/python/work/broadcast_report/bin$ > > I tried installing "cx_Oracle" with easy_install utility (I am not > strong in Solaris). While installing I am getting some error as shown > below. > > root at access1:/$ easy_install cx_Oracle > Searching for cx-Oracle > Reading http://pypi.python.org/simple/cx_Oracle/ > Reading http://cx-oracle.sourceforge.net > Reading http://starship.python.net/crew/atuining > Best match: cx-Oracle 5.0.4 > Downloading http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4.tar.gz?download > Processing cx_Oracle-5.0.4.tar.gz > Running cx_Oracle-5.0.4/setup.py -q bdist_egg --dist-dir /tmp/ > easy_install-FkDQn5/cx_Oracle-5.0.4/egg-dist-tmp-Ogg94s > "SessionPool.c", line 200: warning: integer overflow detected: op "<<" > ld: fatal: library -lpython2.6: not found > ld: fatal: File processing errors. No output written to build/ > lib.solaris-2.10-i86pc-2.6-10g/cx_Oracle.so > error: Setup script exited with error: command '/opt/webstack/python/ > lib/python2.6/pycc' failed with exit status 1 > root at access1:/$ > > I have searched for a solution everywhere and tried many things but > didn't work. Can somebody help me in this? Install the python development libraries. cheers James -- -- James Mills -- -- "Problems are solved by method" From ldo at geek-central.gen.new_zealand Wed Sep 22 23:45:19 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 23 Sep 2010 15:45:19 +1200 Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: In message <4d76a2ad-bf85-472e-8c63-ef16f320a411 at t11g2000vbc.googlegroups.com>, flebber wrote: > Has anyone had much success with python macro's. Or developing powerful > macro's in an language? I did an application for my own use recently, involving automatically generating invoices in editable OOWriter format from my billing database. I gave up on all the PyUNO stuff, and used ODFPY instead?so much easier to generate ODF directly, without having to go through OpenOffice code. And OpenOffice has been able to open the results for final tweaking just fine. From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 23:49:50 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 23 Sep 2010 03:49:50 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> Message-ID: <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> On Thu, 23 Sep 2010 01:49:44 +0000, Seebs wrote: > But I do think it's unfair to dismiss it as purely a matter of baby duck > syndrome. Consistency in ordering of corresponding idioms seems a > reasonable goal. I don't see anyone bitching about: for x in seq: if x: f(x) vs [f(x) for x in seq if x] -- Steven From usenet-nospam at seebs.net Wed Sep 22 23:54:52 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 03:54:52 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-23, Steven D'Aprano wrote: > On Thu, 23 Sep 2010 01:49:44 +0000, Seebs wrote: >> But I do think it's unfair to dismiss it as purely a matter of baby duck >> syndrome. Consistency in ordering of corresponding idioms seems a >> reasonable goal. > I don't see anyone bitching about: > for x in seq: > if x: > f(x) > vs > [f(x) for x in seq if x] In my case, that's because I only ran into that syntax about an hour and a half ago. I have the same basic objection to it. If it were: [for x in seq: if x: f(x)] I'd find it substantially easier to understand. I don't generally like constructs where important structural information comes late in the construct. In the trivial case, I don't suppose it makes a huge difference, but think about the case where seq starts with a ( and x ends with one: [f(x) for x in (1, 2, 3) if foo(x)] As the expressions get complicated, that gets harder to see. IMHO. I dunno. I like the "next if /^$/" idiom, but anything more complicated for either the condition or the thing conditionalized and I tend to prefer to jump back to an explicit if statement. -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 john at castleamber.com Thu Sep 23 00:21:28 2010 From: john at castleamber.com (John Bokma) Date: Wed, 22 Sep 2010 23:21:28 -0500 Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> Message-ID: <877hidm6nr.fsf@castleamber.com> Seebs writes: > I dunno. I like the "next if /^$/" idiom, I don't (as a Perl programmer), I prefer: $line =~ /^$/ and next; Or: $line ne '' or next; which I read as: line must not be empty -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From usenet-nospam at seebs.net Thu Sep 23 00:48:57 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 04:48:57 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> <877hidm6nr.fsf@castleamber.com> Message-ID: On 2010-09-23, John Bokma wrote: > Seebs writes: >> I dunno. I like the "next if /^$/" idiom, > I don't (as a Perl programmer), I prefer: Huh, those are actually nicer. I didn't know that was possible; it wouldn't have occurred to me to try to put "next" (which I think of as a statement) into an expression. Basically, I can live with a postfix "if" as long as everything involved is trivial. Past that... I'd rather see the condition up front. -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 cbrown at cbrownsystems.com Thu Sep 23 01:22:11 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Wed, 22 Sep 2010 22:22:11 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> Message-ID: <09773509-53c8-43ec-9b13-d91df8bc4cf4@q40g2000prg.googlegroups.com> On Sep 22, 3:39?pm, Baba wrote: > On Sep 22, 9:18?pm, Baba wrote: > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > Hi > > > > > query level: beginner > > > > > as part of a learning exercise i have written code that: > > > wordlist = ['hello', 'bye'] > > hand = '' > > for item in wordlist: > > ? ? if item.startswith(hand): > > ? ? ? ? while item.startswith(hand): > > ? ? ? ? ? ? if hand not in wordlist: > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > ? ? ? ? ? ? ? ? print hand > > ? ? ? ? ? ? else: break > > ? ? ? ? else: break > > print 'you loose' > > > But i can't figure out why it won't work when adding the extra word. > > Thanks by the way, it taught me not to be too confident when things > > SEEM to work... > > looking at my original code again i realise that having a raw_input > inside a FOR loop is flawed per se (at least for my purposes) so i > will just assume that i was taking the wrong approach initially. No > point in analysing it further. Thanks for your help. > Yes, the overall structure using the 'for' loop was a bit awkward, and your second attempt using 'any' is much clearer; but I'd say it's still worth seeing how your original logic failed. It has to do with the action of the 'break's. Ask yourself, which code block does the 'if <> else: break' contained /within/ your while loop, break you out of? And which code block does the 'while <> else: break' break you out of? One other thing... it's 'you LOSE', not 'you LOOSE'!!!!! (personal pet peeve ;-) ) Cheers - Chas From vineetdaniel at gmail.com Thu Sep 23 01:30:56 2010 From: vineetdaniel at gmail.com (vineet daniel) Date: Wed, 22 Sep 2010 22:30:56 -0700 (PDT) Subject: creating python daemon ? References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> <87fwx2yw04.fsf@web.de> Message-ID: <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> On Sep 22, 2:20?pm, de... at web.de (Diez B. Roggisch) wrote: > vineet daniel writes: > > On Sep 21, 9:47?pm, de... at web.de (Diez B. Roggisch) wrote: > >> vineet daniel writes: > >> > Hi > > >> > I have succesfully created daemon with python script and as next step > >> > I am trying to give input to that python script daemon from Apache > >> > Logs....here I have got stuck and I have even checked IRC python > >> > channel for solution. Apache is able to call the file but fails to > >> > execute it properly and I get this error continuosly : > > >> > piped log program '/var/www/html/test.py' failed unexpectedly > > >> > How do I rectify the above error and make adjustment to the code so > >> > that it takes input from apache. > > >> > code that I am using is as follows : > > >> > #! /usr/bin/env python > >> > import sys,os > >> > pid = os.fork() > >> > os.chdir("/var/www/html/") > >> > os.setsid() > >> > os.umask(0) > >> > #this line will read apache log in real time as redirected from the > >> > CustomLog directive of Apache. > >> > log = sys.stdin.readlines() > >> > f = open('/var/www/logmongo.txt','a') # append log to this text file > >> > f.write(log) > > >> > I'd appreciate if anybody could share the code that they used for > >> > daemon or used with Apache CustomLog directive. > > >> The above code looks errornous - you don't check for the return-value of > >> PID & take appropriate action. Like > > >> There is a daemonization recipe on active-state, which works nicely for > >> me. > > >>http://code.activestate.com/recipes/278731-creating-a-daemon-the-pyth... > > >> Diez > > > Hi Diez > > > Thanks for pointing that out. > > Ever tried giving input to such python daemons from a dynamic source > > like Apache logs which get generated in real time. I want apache to > > directly write to this python daemon which in turn will process the > > logs the way I want. Any help will help me immensely. > > I don't understand the question. How is that input produced? How shall > the two processes interact? Through some logfile one writes, the other > reads? Through RPC-mechanisms? Sockets? Pipes? > > The fact that process B is a daemon or not has nothing to do with this > whatsoever, btw. > > Diez Hi Diez There is a directive in Apache - CustomLog which can redirect logs to a script or another file by using Pipe. I googled about it and came to know that this works flawlessly with Perl as Apache treats Perl scripts as daemon, for Python to take input from Apache, it needs to work as daemon. Apache will then push its logs lines to this daemon as input. Perl takes this input as but python's stdin is not working as expected it just takes the file name as given in CustomLog directive using Pipe i.e if I use CustomLog '|/var/wwww/script.py' combined, what script reads is just the file name, how and why I am not able to figure it out. And thats the reason I am here. I hope you've got what I am trying to do. From usernet at ilthio.net Thu Sep 23 01:58:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Sep 2010 05:58:59 +0000 (UTC) Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: On 2010-09-23, Lawrence D'Oliveiro wrote: > In message ><4d76a2ad-bf85-472e-8c63-ef16f320a411 at t11g2000vbc.googlegroups.com>, flebber > wrote: > >> Has anyone had much success with python macro's. Or developing powerful >> macro's in an language? > > I did an application for my own use recently, involving automatically > generating invoices in editable OOWriter format from my billing database. I > gave up on all the PyUNO stuff, and used ODFPY instead???so much easier to > generate ODF directly, without having to go through OpenOffice code. Much agreed. The UNO architecture seems to have been rather mishandled. While the general idea was nice, the implementation seems to be overly complicated and poorly documented. The ODF format itself is rather easy to figure out manipulate directly. For those who do not know, the file is just a jar archive with the content and style information all formatted as xml files. I will use the ODF spreadsheet file as an example. ) 00:40,501$ ls demo.ods typescript ) ) 00:40,502$ /usr/lib64/java/bin/jar -xf demo.ods ) ) 00:40,503$ ls ) Configurations2 META-INF Thumbnails content.xml demo.ods ) meta.xml mimetype settings.xml styles.xml typescript ) ) 00:40,504$ xmlformat < content.xml | fmt ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) This is cell A1 ) ) 8 ) ) 64 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) 00:41,505$ exit From simon at brunningonline.net Thu Sep 23 03:28:05 2010 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 23 Sep 2010 08:28:05 +0100 Subject: ctypes In-Reply-To: References: Message-ID: On 22 September 2010 21:13, jay thompson wrote: > Hello, > > I posted in regard to this in the past but it didn't go very far, no ones > fault, but I'm again atempting to make this work and could use some help. > > I would like to use libraw.dll (http://www.libraw.org/? version 0.10) from > python and can access all the functions fine and produce images but there is > a structure that holds all the process settings that I cannot access with > ctypes. I'm sure it's because I'm going about it the wrong way. I was > wondering if there was anyone in this list with experience with this sort of > thing that could point me in the right direction. A good start would be to tell us what you've tried, and what goes wrong when you try it. -- Cheers, Simon B. From shaflich at gmail.com Thu Sep 23 04:18:32 2010 From: shaflich at gmail.com (smh) Date: Thu, 23 Sep 2010 01:18:32 -0700 (PDT) Subject: HTML6 proposal (Re: sexp xml syntax transformation) References: <2bebbf7e-e30d-41a7-bed5-72a132d9de79@z30g2000prg.googlegroups.com> <30bd8745-ef6a-4c5c-8f30-fbbbf8a9bd91@l32g2000prn.googlegroups.com> Message-ID: <1e9d517f-d6d3-4264-8388-66b52cdee0f1@b14g2000pro.googlegroups.com> The following is not exactly what you are looking for, but you might find it interesting. http://www.franz.com/support/tech_corner/xml-generator-blurb.html This blurb is an example of a self-embedding document. I've used this XML generator in many applications, and it is usually elegant to use the structural parallel between an XML tree and the Lisp code that generates it. I haven't thought whether it could be reasonable to port it to scheme. Anyone who wants to think about it has my blessing! From bborcic at gmail.com Thu Sep 23 05:12:20 2010 From: bborcic at gmail.com (Boris Borcic) Date: Thu, 23 Sep 2010 11:12:20 +0200 Subject: Python Macros's Not the Power in OOo they should be ? In-Reply-To: References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > flebber wrote: > >> Has anyone had much success with python macro's. Or developing powerful >> macro's in an language? > > I did an application for my own use recently, involving automatically > generating invoices in editable OOWriter format from my billing database. I > gave up on all the PyUNO stuff, and used ODFPY instead?so much easier to > generate ODF directly, without having to go through OpenOffice code. > > And OpenOffice has been able to open the results for final tweaking just > fine. A nice package to manipulate Ooo text documents with python is the pod module of the appy framework. It uses the same approach with a twist. From xahlee at gmail.com Thu Sep 23 07:33:37 2010 From: xahlee at gmail.com (Xah Lee) Date: Thu, 23 Sep 2010 04:33:37 -0700 (PDT) Subject: HTML6 proposal (Re: sexp xml syntax transformation) References: <2bebbf7e-e30d-41a7-bed5-72a132d9de79@z30g2000prg.googlegroups.com> <30bd8745-ef6a-4c5c-8f30-fbbbf8a9bd91@l32g2000prn.googlegroups.com> <1e9d517f-d6d3-4264-8388-66b52cdee0f1@b14g2000pro.googlegroups.com> Message-ID: <19ce074c-803e-43ad-983a-8d40b69668ae@s17g2000prh.googlegroups.com> On Sep 23, 1:18?am, smh wrote: > The following is not exactly what you are looking for, but you might > find it interesting. > > http://www.franz.com/support/tech_corner/xml-generator-blurb.html > > This blurb is an example of a self-embedding document. > I've used this XML generator in many applications, and it is usually > elegant to use the structural parallel between an XML tree and the > Lisp code that generates it. Thanks. Very interesting. i guess that's like lisp's PHP. > I haven't thought whether it could be reasonable to port it to > scheme. ?Anyone who wants to think about it has my blessing! just curious, i can't believe if there's not already something similar in scheme lisp. Xah ? xahlee.org ? From nn.roh1 at gmail.com Thu Sep 23 07:50:42 2010 From: nn.roh1 at gmail.com (n.a.s) Date: Thu, 23 Sep 2010 14:50:42 +0300 Subject: problem in Gasp ! Message-ID: Hi, I want to ask about graphics using Gasp .Attached is exercise 10 (houses at night) ,if i call the draw_house function once it will work properly ,but more than one call,windows and doors disappear from some houses . Any one can advice? Thanks, Nada -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: house.pyw Type: application/octet-stream Size: 1398 bytes Desc: not available URL: From ldo at geek-central.gen.new_zealand Thu Sep 23 08:31:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 00:31:22 +1200 Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: In message , Tim Harig wrote: > The UNO architecture seems to have been rather mishandled. While the > general idea was nice, the implementation seems to be overly complicated > and poorly documented. For an example of a much nicer way of doing things, compare the Python support in Blender: it?s a lot easier to get something simple working, and there are loads of scripts already written by others that you can refer to. Of course, they?ve completely reworked the scripting API in 2.5, but I think that?s for the better. From funthyme at gmail.com Thu Sep 23 08:50:23 2010 From: funthyme at gmail.com (John Pinner) Date: Thu, 23 Sep 2010 05:50:23 -0700 (PDT) Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: On Sep 23, 10:12?am, Boris Borcic wrote: > Lawrence D'Oliveiro wrote: > > flebber wrote: > > >> Has anyone had much success with python macro's. Or developing powerful > >> macro's in an language? > > > I did an application for my own use recently, involving automatically > > generating invoices in editable OOWriter format from my billing database. I > > gave up on all the PyUNO stuff, and used ODFPY instead?so much easier to > > generate ODF directly, without having to go through OpenOffice code. > > > And OpenOffice has been able to open the results for final tweaking just > > fine. > > A nice package to manipulate Ooo text documents with python is the pod module of > the appy framework. It uses the same approach with a twist. One of our guys, David Chan, has done something you may find useful, 'OpenDocMill': http://www.troi.org/opendoc-mill.html We use it to produce some quite complicated documents, for example Engineering Reports, Invoices, Certificates. Best wishes, John -- From jldunn2000 at gmail.com Thu Sep 23 10:34:15 2010 From: jldunn2000 at gmail.com (loial) Date: Thu, 23 Sep 2010 07:34:15 -0700 (PDT) Subject: Scheduling in python Message-ID: I want to enable my end users to be able to schedule a task(actually running another python or shell script). Rather than scheduling it directly in cron, are there any python modules I could use? From pruebauno at latinmail.com Thu Sep 23 10:56:21 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 23 Sep 2010 07:56:21 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> Message-ID: <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> On Sep 22, 6:39?pm, Baba wrote: > On Sep 22, 9:18?pm, Baba wrote: > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > Hi > > > > > query level: beginner > > > > > as part of a learning exercise i have written code that: > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > entered) > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > c) start again until 2) is True > > > > > wordlist = ['hello', 'bye'] > > > > handlist = [] > > > > letter = raw_input('enter letter: ') > > > > handlist.append(letter) > > > > hand = "".join(handlist) > > > > for item in wordlist: > > > > ? ? if item.startswith(hand): > > > > ? ? ? ? while item.startswith(hand): > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > ? ? ? ? ? ? else: break > > > > ? ? ? ? else: break > > > > print 'you loose' > > > > > this code works but can it be optimised? i have the feeling that my > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > thanks > > > > Baba > > > > Yes it is overkill. Especially the else:break from the while loop > > > makes it difficult to follow the logic. Also the program breaks down > > > if I use the following word list: > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > enter letter: h > > > enter letter: a > > > you loose > > > > I am not going to post any spoilers but I wrote your program using one > > > while loop and one generator expression for a total of 5 lines. My > > > version might be a bit too advanced but you should still be able to do > > > it using only one while, one for and one if instead. > > > Hi nn, > > > i wasn't expecting my code to fail with an additional word in it. > > While i was conscious that the whole construct was heavy i thought the > > reasoning worked. I keep looking at it but can't figure out the > > problem Can you give me a hint? > > > In the meantime i found out that it is actually possible to populate a > > string (just like a list, a dictionary or a tuple). Here's what i've > > got now: > > > wordlist = ['hello', 'bye'] > > hand = '' > > for item in wordlist: > > ? ? if item.startswith(hand): > > ? ? ? ? while item.startswith(hand): > > ? ? ? ? ? ? if hand not in wordlist: > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > ? ? ? ? ? ? ? ? print hand > > ? ? ? ? ? ? else: break > > ? ? ? ? else: break > > print 'you loose' > > > But i can't figure out why it won't work when adding the extra word. > > Thanks by the way, it taught me not to be too confident when things > > SEEM to work... > > > Why does it work when i use the built-in function any(iterable)?? To > > me using the any(iterable) function seems just like regrouping 3 lines > > into one... > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > hand = '' > > while any(item.startswith(hand) for item in wordlist): > > ? ? if hand not in wordlist: > > ? ? ? ? hand += raw_input('enter letter: ') > > ? ? else: break > > print 'you loose' > > > thanks > > > Baba > > Hi nn, > > looking at my original code again i realise that having a raw_input > inside a FOR loop is flawed per se (at least for my purposes) so i > will just assume that i was taking the wrong approach initially. No > point in analysing it further. Thanks for your help. > > Baba Since you seem to have figured it out I will post my version (python 3): wordlist = ['hello', 'hamburger', 'bye'] inp='' while any(word.startswith(inp) and word!=inp for word in wordlist): inp += input('enter letter: ') print('you lose') The reason why your original version didn't work was because each time you add a letter you have to go again over all words (in reality only a subset is required) and find a new one. Your version would find one word using the first letter and then exit. From jldunn2000 at gmail.com Thu Sep 23 11:08:50 2010 From: jldunn2000 at gmail.com (loial) Date: Thu, 23 Sep 2010 08:08:50 -0700 (PDT) Subject: Check whether file is being written to Message-ID: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> How can I check whether a file is being written to by another process before I access it? Platform is unix. From pruebauno at latinmail.com Thu Sep 23 11:17:06 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 23 Sep 2010 08:17:06 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> Message-ID: <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> On Sep 23, 10:56?am, nn wrote: > On Sep 22, 6:39?pm, Baba wrote: > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > Hi > > > > > > query level: beginner > > > > > > as part of a learning exercise i have written code that: > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > entered) > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > c) start again until 2) is True > > > > > > wordlist = ['hello', 'bye'] > > > > > handlist = [] > > > > > letter = raw_input('enter letter: ') > > > > > handlist.append(letter) > > > > > hand = "".join(handlist) > > > > > for item in wordlist: > > > > > ? ? if item.startswith(hand): > > > > > ? ? ? ? while item.startswith(hand): > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > ? ? ? ? ? ? else: break > > > > > ? ? ? ? else: break > > > > > print 'you loose' > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > thanks > > > > > Baba > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > makes it difficult to follow the logic. Also the program breaks down > > > > if I use the following word list: > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > enter letter: h > > > > enter letter: a > > > > you loose > > > > > I am not going to post any spoilers but I wrote your program using one > > > > while loop and one generator expression for a total of 5 lines. My > > > > version might be a bit too advanced but you should still be able to do > > > > it using only one while, one for and one if instead. > > > > Hi nn, > > > > i wasn't expecting my code to fail with an additional word in it. > > > While i was conscious that the whole construct was heavy i thought the > > > reasoning worked. I keep looking at it but can't figure out the > > > problem Can you give me a hint? > > > > In the meantime i found out that it is actually possible to populate a > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > got now: > > > > wordlist = ['hello', 'bye'] > > > hand = '' > > > for item in wordlist: > > > ? ? if item.startswith(hand): > > > ? ? ? ? while item.startswith(hand): > > > ? ? ? ? ? ? if hand not in wordlist: > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > ? ? ? ? ? ? ? ? print hand > > > ? ? ? ? ? ? else: break > > > ? ? ? ? else: break > > > print 'you loose' > > > > But i can't figure out why it won't work when adding the extra word. > > > Thanks by the way, it taught me not to be too confident when things > > > SEEM to work... > > > > Why does it work when i use the built-in function any(iterable)?? To > > > me using the any(iterable) function seems just like regrouping 3 lines > > > into one... > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > hand = '' > > > while any(item.startswith(hand) for item in wordlist): > > > ? ? if hand not in wordlist: > > > ? ? ? ? hand += raw_input('enter letter: ') > > > ? ? else: break > > > print 'you loose' > > > > thanks > > > > Baba > > > Hi nn, > > > looking at my original code again i realise that having a raw_input > > inside a FOR loop is flawed per se (at least for my purposes) so i > > will just assume that i was taking the wrong approach initially. No > > point in analysing it further. Thanks for your help. > > > Baba > > Since you seem to have figured it out I will post my version (python > 3): > > wordlist = ['hello', 'hamburger', 'bye'] > inp='' > while any(word.startswith(inp) and word!=inp for word in wordlist): > ? ? inp += input('enter letter: ') > print('you lose') > > The reason why your original version didn't work was because each time > you add a letter you have to go again over all words (in reality only > a subset is required) and find a new one. Your version would find one > word using the first letter and then exit. Actually my version isn't right (for some values of right): wordlist = ['hello', 'hamburger', 'bye'] inp='' while any(word.startswith(inp) for word in wordlist) and (inp not in wordlist): inp += input('enter letter: ') print('you lose') An explanation of how this changes the rules of the wordgame is left as an exercise to the reader. From usenet-nospam at seebs.net Thu Sep 23 11:20:07 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 15:20:07 GMT Subject: Check whether file is being written to References: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> Message-ID: On 2010-09-23, loial wrote: > How can I check whether a file is being written to by another process > before I access it? You mean "written to" or "open for possible writing"? It may be possible (with sufficient privileges) to determine that a file has been opened for writing. I don't think you can detect being-written-to. More importantly, though, the question is irrelevant, because even if you absolutely, conclusively, prove that a file is not open nor being written to, before your next machine instruction loads, the file could be opened and rewritten multiple times by whole new processes that weren't even running when you checked. I suggest you look into advisory locks. -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 thomas at jollybox.de Thu Sep 23 11:26:09 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 23 Sep 2010 17:26:09 +0200 Subject: Check whether file is being written to In-Reply-To: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> References: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> Message-ID: <201009231726.10000.thomas@jollybox.de> On Thursday 23 September 2010, it occurred to loial to exclaim: > How can I check whether a file is being written to by another process > before I access it? > > Platform is unix. As such, you can't. But you can lock the file using the functions in the fcntl module. From thomas at jollybox.de Thu Sep 23 11:30:21 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 23 Sep 2010 17:30:21 +0200 Subject: Scheduling in python In-Reply-To: References: Message-ID: <201009231730.21829.thomas@jollybox.de> On Thursday 23 September 2010, it occurred to loial to exclaim: > I want to enable my end users to be able to schedule a task(actually > running another python or shell script). Rather than scheduling it > directly in cron, are there any python modules I could use? If you have a "master" process running -- it strongly depends on how that process is structured. Is there a main loop? What does it look like? Is it provided by some toolkit? Maybe that toolkit has an alarm event? In the end, there isn't much too it: periodically check if "it's time", and then possibly do something. I doubt there's a package to do this. The basics are trivial to implement, and everything depends strongly on the program structure, which could vary greatly. From usenot at geekmail.INVALID Thu Sep 23 11:38:33 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 23 Sep 2010 11:38:33 -0400 Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> Message-ID: <20100923113833.58a04826@geekmail.INVALID> On 23 Sep 2010 03:54:52 GMT Seebs wrote: > On 2010-09-23, Steven D'Aprano > wrote: > [snip] > > I don't see anyone bitching about: > > > for x in seq: > > if x: > > f(x) > > > vs > > > [f(x) for x in seq if x] > > In my case, that's because I only ran into that syntax about an hour > and a half ago. I have the same basic objection to it. If it were: > > [for x in seq: if x: f(x)] > > I'd find it substantially easier to understand. > > I don't generally like constructs where important structural > information comes late in the construct. [snip] I think that is precisely the reason that the elements of the list come *first* in the list comprehension expression. The foremost idea of list comprehensions is "build a list", while the idea of a for-loop is "iterate over something". /W -- INVALID? DE! From paul.nospam at rudin.co.uk Thu Sep 23 11:39:41 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 23 Sep 2010 16:39:41 +0100 Subject: Scheduling in python References: Message-ID: <87r5gkbhaa.fsf@rudin.co.uk> loial writes: > I want to enable my end users to be able to schedule a task(actually > running another python or shell script). Rather than scheduling it > directly in cron, are there any python modules I could use? First hit when googling "python schedule"? From usenot at geekmail.INVALID Thu Sep 23 11:40:55 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 23 Sep 2010 11:40:55 -0400 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> <4c9aa057$0$11123$c3e8da3@news.astraweb.com> Message-ID: <20100923114055.11443545@geekmail.INVALID> On 23 Sep 2010 00:33:28 GMT Steven D'Aprano wrote: > On Tue, 21 Sep 2010 12:26:29 -0400, Andreas Waldenburger wrote: > > > On Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Carl Banks > > wrote: > > > >> On Sep 17, 1:01?pm, Andreas Waldenburger > >> wrote: > >> > On Thu, 16 Sep 2010 16:20:33 -0400 AK > >> > wrote: > >> > > >> > > I also like this construct that works, I think, since 2.6: > >> > > >> > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > >> > > >> > I wonder when this construct will finally start to look good. > >> > >> I don't know if it'll ever look good, per se, but it looks better > >> when it's used in rule-exception sort of case: > >> > >> something = rule if condition else exception > >> > > Spot on. I (more or less) like it when used that way, too. But it > > seems to invite crackers like the example above, and that irks me. > > > I don't see that one of these is more of a cracker than the other: > > > code = if side == 'l' then dir[int(num):] else dir[:-1*int(num)] > code = side == 'l' if dir[int(num):] else dir[:-1*int(num)] > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > > If you ask me, the *least* hard to read is the last. > I agree again. I wasn't really talking about the specific order of the ternary operator but rather about the whole idea. It invites messiness. /W -- INVALID? DE! From gslindstrom at gmail.com Thu Sep 23 11:41:41 2010 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Thu, 23 Sep 2010 10:41:41 -0500 Subject: Distributing Packages Message-ID: I am not intending to start anything, here, but would like to know if any consensus has been reached in how to distribute Python modules. Specifically, I'd like to use something to install packages on various machines in our enterprise (mostly Linux, but some windows boxes, too). I've read up on distutils, but also recall hearing about Python eggs and sitting in on a talk or two at PyCon (US) that seemed to indicate that the community was in a state of flux over how to distribute things. What are the current thoughts on the subject? Thanks, --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenot at geekmail.INVALID Thu Sep 23 11:42:25 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 23 Sep 2010 11:42:25 -0400 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> <4c9aa057$0$11123$c3e8da3@news.astraweb.com> <87k4mdmdv0.fsf@castleamber.com> Message-ID: <20100923114225.32f7253e@geekmail.INVALID> On Wed, 22 Sep 2010 20:45:55 -0500 John Bokma wrote: > What surprises me is that this is still discussed. It's like argueing > about significant whitespace. :-) Which is evil! /W -- INVALID? DE! From thomas at jollybox.de Thu Sep 23 11:52:18 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 23 Sep 2010 17:52:18 +0200 Subject: Playing sounds at time indexes In-Reply-To: References: Message-ID: <201009231752.18822.thomas@jollybox.de> On Wednesday 22 September 2010, it occurred to OKB (not okblacke) to exclaim: > I'm looking for an audio library for Python. I googled and found a > few, but none of them seem to have a simple way to play a particular > sound file from a particular start-time to an end-time. Like, I'd want > to load a file and say "Play the section of this file from 10.25 seconds > to 11.73 seconds." Is there a library that makes this easy in Python? platform? From deets at web.de Thu Sep 23 11:55:52 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 23 Sep 2010 17:55:52 +0200 Subject: Check whether file is being written to References: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> Message-ID: <87bp7ozc6v.fsf@web.de> Thomas Jollans writes: > On Thursday 23 September 2010, it occurred to loial to exclaim: >> How can I check whether a file is being written to by another process >> before I access it? >> >> Platform is unix. > > As such, you can't. But you can lock the file using the functions in the fcntl > module. Last time I checked, file-locking in unix was co-operative. Diez From usenet-nospam at seebs.net Thu Sep 23 12:01:04 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 16:01:04 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> <20100923113833.58a04826@geekmail.INVALID> Message-ID: On 2010-09-23, Andreas Waldenburger wrote: > On 23 Sep 2010 03:54:52 GMT Seebs wrote: >> I don't generally like constructs where important structural >> information comes late in the construct. [snip] > I think that is precisely the reason that the elements of the list come > *first* in the list comprehension expression. The foremost idea of list > comprehensions is "build a list", while the idea of a for-loop is > "iterate over something". Interesting! I tend to think of "building a list" as more like a for loop than like a data item with a qualifier. If the first word inside the [] were "for", that would tell me that the list was going to have some kind of looping or generating going on, while if it's an expression, especially a complicated expression, I don't know that right away. But I can see it making sense either way for the loop, just because of the similarity to mathematical notation. -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 burton at userful.com Thu Sep 23 12:16:50 2010 From: burton at userful.com (Burton Samograd) Date: Thu, 23 Sep 2010 10:16:50 -0600 Subject: Playing sounds at time indexes References: Message-ID: "OKB (not okblacke)" writes: > I'm looking for an audio library for Python. I googled and found a > few, but none of them seem to have a simple way to play a particular > sound file from a particular start-time to an end-time. Like, I'd want > to load a file and say "Play the section of this file from 10.25 seconds > to 11.73 seconds." Is there a library that makes this easy in Python? You might want to check out this question on StackOverflow: http://stackoverflow.com/questions/108848/python-music-library -- Burton Samograd From c_barret at qualcomm.com Thu Sep 23 12:28:15 2010 From: c_barret at qualcomm.com (David A. Barrett) Date: Thu, 23 Sep 2010 09:28:15 -0700 Subject: collections.namedtuple: conflicting instances? Message-ID: <4C9B801F.6070304@qualcomm.com> I've noticed that it's possible to create conflicting instances of the collections.namedtuple class: from collections import namedtuple as nt IX = nt('X', 'a b') IY = nt('Y', 'c d') x = IX(0, 1) y = IY(2, 3) The above are non-conflicting class instances and of two distinct namedtuple classes and distinct instances of those classes, but what happens with this? IX2 = nt('X', 'g') z = IX2(10) It looks like IX and IX2 are two distinct classes, which makes sense, but what is the classname parameter passed to the constructor used for? Is it an error to construct two distinct classes with the same value? I was wondering if it's useful to allow duplicate (consistant) constructions, but have them simply return the same class instance. Should inconsistant constructions with the same name raise and exception? From nobody at nowhere.com Thu Sep 23 13:17:59 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 23 Sep 2010 18:17:59 +0100 Subject: Subprocess does not return for longer-running process References: Message-ID: On Thu, 23 Sep 2010 12:25:53 +1200, Lawrence D'Oliveiro wrote: >> And I can't think of any reason why you should use os.waitpid() or >> similar; use the .wait() method. > > I have used WNOHANG to poll for completion of a subprocess while providing > progress updates to the user. This can be done via the .poll() method. From ahz001 at gmail.com Thu Sep 23 13:22:33 2010 From: ahz001 at gmail.com (Andrew Z.) Date: Thu, 23 Sep 2010 10:22:33 -0700 (PDT) Subject: Parsing error for ConfigParser Message-ID: <0c7a4de7-9a1b-40c6-a84f-726295cb311a@w4g2000vbh.googlegroups.com> Is there a way to parse RealPlayer's realplayerrc in Python? I need to support Python 2.5 - 2.7 Example code import urllib2 import ConfigParser f = urllib2.urlopen('http://pastebin.com/download.php?i=N1AcUg3w') config = ConfigParser.RawConfigParser() config.readfp(f) Error Traceback (most recent call last): File "test_config_parser_real_player.py", line 6, in config.readfp(f) File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp self._read(fp, filename) File "/usr/lib/python2.6/ConfigParser.py", line 510, in _read raise e ConfigParser.ParsingError: File contains parsing errors: [line 31]: '%0aCopyright (c) 1995-2000 Macromedia, Inc. All rights reserved.\r\n' [line 34]: '%0a\r\n' From nobody at nowhere.com Thu Sep 23 13:23:34 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 23 Sep 2010 18:23:34 +0100 Subject: Check whether file is being written to References: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> <87bp7ozc6v.fsf@web.de> Message-ID: On Thu, 23 Sep 2010 17:55:52 +0200, Diez B. Roggisch wrote: > Last time I checked, file-locking in unix was co-operative. Linux supports mandatory locking, but it's seldom enabled. From raoulbia at gmail.com Thu Sep 23 13:25:27 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 23 Sep 2010 10:25:27 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> Message-ID: On Sep 23, 4:17?pm, nn wrote: > On Sep 23, 10:56?am, nn wrote: > > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > Hi > > > > > > > query level: beginner > > > > > > > as part of a learning exercise i have written code that: > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > entered) > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > c) start again until 2) is True > > > > > > > wordlist = ['hello', 'bye'] > > > > > > handlist = [] > > > > > > letter = raw_input('enter letter: ') > > > > > > handlist.append(letter) > > > > > > hand = "".join(handlist) > > > > > > for item in wordlist: > > > > > > ? ? if item.startswith(hand): > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > ? ? ? ? ? ? else: break > > > > > > ? ? ? ? else: break > > > > > > print 'you loose' > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > thanks > > > > > > Baba > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > if I use the following word list: > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > enter letter: h > > > > > enter letter: a > > > > > you loose > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > version might be a bit too advanced but you should still be able to do > > > > > it using only one while, one for and one if instead. > > > > > Hi nn, > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > While i was conscious that the whole construct was heavy i thought the > > > > reasoning worked. I keep looking at it but can't figure out the > > > > problem Can you give me a hint? > > > > > In the meantime i found out that it is actually possible to populate a > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > got now: > > > > > wordlist = ['hello', 'bye'] > > > > hand = '' > > > > for item in wordlist: > > > > ? ? if item.startswith(hand): > > > > ? ? ? ? while item.startswith(hand): > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > ? ? ? ? ? ? ? ? print hand > > > > ? ? ? ? ? ? else: break > > > > ? ? ? ? else: break > > > > print 'you loose' > > > > > But i can't figure out why it won't work when adding the extra word. > > > > Thanks by the way, it taught me not to be too confident when things > > > > SEEM to work... > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > into one... > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > hand = '' > > > > while any(item.startswith(hand) for item in wordlist): > > > > ? ? if hand not in wordlist: > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > ? ? else: break > > > > print 'you loose' > > > > > thanks > > > > > Baba > > > > Hi nn, > > > > looking at my original code again i realise that having a raw_input > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > will just assume that i was taking the wrong approach initially. No > > > point in analysing it further. Thanks for your help. > > > > Baba > > > Since you seem to have figured it out I will post my version (python > > 3): > > > wordlist = ['hello', 'hamburger', 'bye'] > > inp='' > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > ? ? inp += input('enter letter: ') > > print('you lose') > > > The reason why your original version didn't work was because each time > > you add a letter you have to go again over all words (in reality only > > a subset is required) and find a new one. Your version would find one > > word using the first letter and then exit. > > Actually my version isn't right (for some values of right): > > wordlist = ['hello', 'hamburger', 'bye'] > inp='' > while any(word.startswith(inp) for word in wordlist) and (inp not in > wordlist): > ? ? inp += input('enter letter: ') > print('you lose') > > An explanation of how this changes the rules of the wordgame is left > as an exercise to the reader. Hi, for now i will stick to Python2.7 but thank you for sharing. for learning purposes i still want to figure out a way to solve this without built-in function ('any' in this case). My understanding was that in programming almost anything can be done with IF, FOR and WHILE statements. However i turn in circles...:( i understand that in my original code my while loop locked me into the first word hello if the first letter was 'h' and therefore if the next letter was 'a' it would break...so far so good but this appears really tricky to solve...here is what i have come up with but it will not exit if for example i enter 'x' ... wordlist = ['hello', 'bye'] hand = '' while hand not in wordlist: hand += raw_input('enter letter: ') print hand for item in wordlist: if not item.startswith(hand): break print 'you lose' but no matter how i turn this around i can't find the magic approach...i was thinking about starting the code with something like "while (something) is True" ... would that be a right approach? Baba From crebert at ucsd.edu Thu Sep 23 13:40:12 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Thu, 23 Sep 2010 10:40:12 -0700 Subject: collections.namedtuple: conflicting instances? In-Reply-To: <4C9B801F.6070304@qualcomm.com> References: <4C9B801F.6070304@qualcomm.com> Message-ID: On Thu, Sep 23, 2010 at 9:28 AM, David A. Barrett wrote: > ?I've noticed that it's possible to create conflicting instances of the > collections.namedtuple class: > > ?from collections ?import namedtuple as nt > ?IX = nt('X', 'a b') > ?IY = nt('Y', 'c d') > ?x = IX(0, 1) > ?y = IY(2, 3) > > The above are non-conflicting class instances and of two distinct namedtuple > classes and distinct instances of those classes, but what happens with this? > > ?IX2 = nt('X', 'g') > ?z = IX2(10) > > It looks like IX and IX2 are two distinct classes, which makes sense, but > what is the classname parameter passed to the constructor used for? Documentation for human readers (the .__name__ class attribute). As your example shows, the name you pass in doesn't have to match the name you assign the resulting class to and actually use (i.e. "X" vs. "IX"); it's rather like how you were able to use "nt" instead of "namedtuple". >?Is it > an error to construct two distinct classes with the same value? Of course not. Otherwise, classes would have to have *globally unique* names, and stuff like the following wouldn't be possible (which would be bad): # mechanical.py class Engineer(object): '''Models a mechanical engineer.''' # ... # trains.py class Engineer(object): '''Models a person who drives a train.''' # ... # main.py # Models a train company and associated repair yard. import mechanical import trains # ... > Should > inconsistant constructions with the same name raise and exception? Probably not (see answer to previous sentence); showing a warning /might/ be appropriate. Cheers, Chris -- http://blog.rebertia.com From pruebauno at latinmail.com Thu Sep 23 13:55:36 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 23 Sep 2010 10:55:36 -0700 (PDT) Subject: collections.namedtuple: conflicting instances? References: <4C9B801F.6070304@qualcomm.com> Message-ID: On Sep 23, 1:40?pm, Chris Rebert wrote: > On Thu, Sep 23, 2010 at 9:28 AM, David A. Barrett wrote: > > > > > ?I've noticed that it's possible to create conflicting instances of the > > collections.namedtuple class: > > > ?from collections ?import namedtuple as nt > > ?IX = nt('X', 'a b') > > ?IY = nt('Y', 'c d') > > ?x = IX(0, 1) > > ?y = IY(2, 3) > > > The above are non-conflicting class instances and of two distinct namedtuple > > classes and distinct instances of those classes, but what happens with this? > > > ?IX2 = nt('X', 'g') > > ?z = IX2(10) > > > It looks like IX and IX2 are two distinct classes, which makes sense, but > > what is the classname parameter passed to the constructor used for? > > Documentation for human readers (the .__name__ class attribute). As > your example shows, the name you pass in doesn't have to match the > name you assign the resulting class to and actually use (i.e. "X" vs. > "IX"); it's rather like how you were able to use "nt" instead of > "namedtuple". > > >?Is it > > an error to construct two distinct classes with the same value? > > Of course not. Otherwise, classes would have to have *globally unique* > names, and stuff like the following wouldn't be possible (which would > be bad): > > # mechanical.py > class Engineer(object): > ? ? '''Models a mechanical engineer.''' > ? ? # ... > > # trains.py > class Engineer(object): > ? ? '''Models a person who drives a train.''' > ? ? # ... > > # main.py > # Models a train company and associated repair yard. > import mechanical > import trains > # ... > > > Should > > inconsistant constructions with the same name raise and exception? > > Probably not (see answer to previous sentence); showing a warning > /might/ be appropriate. > > Cheers, > Chris > --http://blog.rebertia.com This parallels another wrinkle: >>> A=type('X',(),{'a':''}) >>> B=type('X',(),{'z':''}) >>> A >>> B >>> i=A() >>> j=B() >>> i <__main__.X object at 0x013A63F0> >>> j <__main__.X object at 0x013A6ED0> >>> dir(i) ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a'] >>> dir(j) ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'z'] >>> The first parameter to type and namedtuple looks redundant to me. class A: pass should be the equivalent to A=type((),{}) my guess is that it has to do with Python's internals: the function probably has no way to know what variable name it is being assigned to and anonymous classes are not wanted. From ron.eggler at gmail.com Thu Sep 23 14:10:55 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 23 Sep 2010 11:10:55 -0700 (PDT) Subject: upload file using post to https server Message-ID: hi, I've been unsucessfully trying to upload a file using POST to an https server. I've succesfully logged in and gotten to read something from the server.. I have come up with something like this: authinfo = urllib2.HTTPBasicAuthHandler() authinfo.add_password(realm='Configuration Software', uri=url, user='admin', passwd='******') opener = urllib2.build_opener(authinfo) pagePtr = opener.open(url) dataRead = str(pagePtr.read()) #Look for 'Software Upload' in the page if( "Software Upload" in dataRead ): print "FOUND Software Upload in string...
" else: print "Software Upload page not found. Exiting..." sys.exit() values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' } try: data = urllib.urlencode( values ) req = urllib2.Request( url, data ) #response = urllib2.urlopen( req ) response = opener.open( req ) the_page = response.read() #print the_page except Exception,detail: print "err ",detail #Look for 'file must be efs' in the page if( "file must be efs" in the_page ): print "file must be efs. Exiting..." sys.exit() else: print "OK" But the file doesn't seem to get there correctly. What I wanna do, is mocking the upload from the html site with my python script.... the html looks something like this:
  
Thanks for your hints and suggestions on how I have to go about this! Ron From pruebauno at latinmail.com Thu Sep 23 15:13:13 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 23 Sep 2010 12:13:13 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> Message-ID: <6d8a9aac-817c-4c1d-a175-fce403ccebba@t11g2000vbc.googlegroups.com> On Sep 23, 1:25?pm, Baba wrote: > On Sep 23, 4:17?pm, nn wrote: > > > > > On Sep 23, 10:56?am, nn wrote: > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > > Hi > > > > > > > > query level: beginner > > > > > > > > as part of a learning exercise i have written code that: > > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > > entered) > > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > > c) start again until 2) is True > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > handlist = [] > > > > > > > letter = raw_input('enter letter: ') > > > > > > > handlist.append(letter) > > > > > > > hand = "".join(handlist) > > > > > > > for item in wordlist: > > > > > > > ? ? if item.startswith(hand): > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > > ? ? ? ? ? ? else: break > > > > > > > ? ? ? ? else: break > > > > > > > print 'you loose' > > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > > thanks > > > > > > > Baba > > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > > if I use the following word list: > > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > > enter letter: h > > > > > > enter letter: a > > > > > > you loose > > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > > version might be a bit too advanced but you should still be able to do > > > > > > it using only one while, one for and one if instead. > > > > > > Hi nn, > > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > > While i was conscious that the whole construct was heavy i thought the > > > > > reasoning worked. I keep looking at it but can't figure out the > > > > > problem Can you give me a hint? > > > > > > In the meantime i found out that it is actually possible to populate a > > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > > got now: > > > > > > wordlist = ['hello', 'bye'] > > > > > hand = '' > > > > > for item in wordlist: > > > > > ? ? if item.startswith(hand): > > > > > ? ? ? ? while item.startswith(hand): > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > > ? ? ? ? ? ? ? ? print hand > > > > > ? ? ? ? ? ? else: break > > > > > ? ? ? ? else: break > > > > > print 'you loose' > > > > > > But i can't figure out why it won't work when adding the extra word. > > > > > Thanks by the way, it taught me not to be too confident when things > > > > > SEEM to work... > > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > > into one... > > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > > hand = '' > > > > > while any(item.startswith(hand) for item in wordlist): > > > > > ? ? if hand not in wordlist: > > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > > ? ? else: break > > > > > print 'you loose' > > > > > > thanks > > > > > > Baba > > > > > Hi nn, > > > > > looking at my original code again i realise that having a raw_input > > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > > will just assume that i was taking the wrong approach initially. No > > > > point in analysing it further. Thanks for your help. > > > > > Baba > > > > Since you seem to have figured it out I will post my version (python > > > 3): > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > inp='' > > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > > ? ? inp += input('enter letter: ') > > > print('you lose') > > > > The reason why your original version didn't work was because each time > > > you add a letter you have to go again over all words (in reality only > > > a subset is required) and find a new one. Your version would find one > > > word using the first letter and then exit. > > > Actually my version isn't right (for some values of right): > > > wordlist = ['hello', 'hamburger', 'bye'] > > inp='' > > while any(word.startswith(inp) for word in wordlist) and (inp not in > > wordlist): > > ? ? inp += input('enter letter: ') > > print('you lose') > > > An explanation of how this changes the rules of the wordgame is left > > as an exercise to the reader. > > Hi, > > for now i will stick to Python2.7 but thank you for sharing. > > for learning purposes i still want to figure out a way to solve this > without built-in function ('any' in this case). My understanding was > that in programming almost anything can be done with IF, FOR and WHILE > statements. However i turn in circles...:( i understand that in my > original code my while loop locked me into the first word hello if the > first letter was 'h' and therefore if the next letter was 'a' it would > break...so far so good but this appears really tricky to solve...here > is what i have come up with but it will not exit if for example i > enter 'x' ... > > wordlist = ['hello', 'bye'] > hand = '' > while hand not in wordlist: > ? ? hand += raw_input('enter letter: ') > ? ? print hand > ? ? for item in wordlist: > ? ? ? ? if not item.startswith(hand): > ? ? ? ? ? ? break > print 'you lose' > > but no matter how i turn this around i can't find the magic > approach...i was thinking about starting the code with something like > "while (something) is True" ... would that be a right approach? > > Baba This program has 2 problems: 1.) the break only exits one level: i.e. the for loop 2.) your logic is backwards. You stop checking as soon as you find the first mismatch. It should be the other way around: it is invalid only after testing with all words and not finding any match. And yes all of this can be done using just using while, for and if. I just wrote another version with 1 while, 1 for, 2 ifs, 0 breaks, 0 any, 0 genexp. This is like doing algebra: you add 2 here, substract 2 there and the same result comes out. There is an infinite number of programs that can be written to generate the same output. From jayryan.thompson at gmail.com Thu Sep 23 15:16:12 2010 From: jayryan.thompson at gmail.com (jay thompson) Date: Thu, 23 Sep 2010 12:16:12 -0700 Subject: ctypes In-Reply-To: References: Message-ID: My apologies! I worte the email while doing 3 other things. I haven't really tried anything to access this struct other than trying to find different elements with ctypes.c_int.in_dll(dll, 'symbol') and access the elements in the same way I do in C. I didn't think either of these would work but hoped I would get some type of return that would give me a little more info. I have been using a cli to access the library from python and would just send the image data via stdin and the parameters of the struct as command line args. From C the struct is easily accessible through the class instance (libraw::imgdata) and I tried similar variations with ctypes but just get 'function not found'. Makes sense though. this works: lr = ctypes.cdll.LoadLibrary(libraw) handle = lr.libraw_init(0) lr.libraw_open_buffer(handle, buf, len(buf)) # buf is an image read by python lr.libraw_unpack(handle, buf, len(buf)) # imgdata attampt. returns "function 'imgdata' not found" #lr.imgdata.params.bright(2) lr.libraw_dcraw_process(handle) lr.libraw_dcraw_ppm_tiff_writer(handle,'test.ppm') lr.libraw_close(handle) These are the 'exposed' functions, if that is the right term, and will produce an rgb image. There are a few other functions but they are not important atm. I know I don't know what I'm doing with this but it will be worth it if I can struggle through. Is there a way I can access this struct via python? Alternatively I could also write a new function in libraw that can access this struct and be exposed to ctypes. jt On Thu, Sep 23, 2010 at 12:28 AM, Simon Brunning wrote: > On 22 September 2010 21:13, jay thompson > wrote: > > Hello, > > > > I posted in regard to this in the past but it didn't go very far, no ones > > fault, but I'm again atempting to make this work and could use some help. > > > > I would like to use libraw.dll (http://www.libraw.org/ version 0.10) > from > > python and can access all the functions fine and produce images but there > is > > a structure that holds all the process settings that I cannot access with > > ctypes. I'm sure it's because I'm going about it the wrong way. I was > > wondering if there was anyone in this list with experience with this sort > of > > thing that could point me in the right direction. > > A good start would be to tell us what you've tried, and what goes > wrong when you try it. > > -- > Cheers, > Simon B. > -- "It's quite difficult to remind people that all this stuff was here for a million years before people. So the idea that we are required to manage it is ridiculous. What we are having to manage is us." ...Bill Ballantine, marine biologist. -- "It's quite difficult to remind people that all this stuff was here for a million years before people. So the idea that we are required to manage it is ridiculous. What we are having to manage is us." ...Bill Ballantine, marine biologist. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthias.guentert at gmail.com Thu Sep 23 15:41:19 2010 From: matthias.guentert at gmail.com (Matthias Guentert) Date: Thu, 23 Sep 2010 21:41:19 +0200 Subject: Raw Sockets - IP-Encapsulation Message-ID: Hello list members I would like to create an IP tunnel using the IP protocol type 4 (socket.IPPROTO_IPIP) on a Linux host. (I also would be happy if I could create a GRE tunnel) The thing is, I just don't understand how I such a socket could be created and then later on handled. Regarding to help(socket.socke()) the constructor looks like this: | socket([family[, type[, proto]]]) -> socket object | | Open a socket of the given type. The family argument specifies the | address family; it defaults to AF_INET. The type argument specifies | whether this is a stream (SOCK_STREAM, this is the default) | or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0, | specifying the default protocol. Keyword arguments are accepted. This means to create a simple UDP socket I can do the following where the last argument is optional. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP) So to create an IP-Encapsulation socket I would have to do this: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IPIP) or for GRE this. s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_GRE) But how can I now set the fields? How do I really encapsulate other data (=sockets?)? Do I need a Raw socket at all? Or should this work somehow like the following to encapsulate UDP payload? s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IPIP) I really would be happy if someone could help me with this and even better could provide some examples on the usage. Thanks in advance, Matthias From philip at semanchuk.com Thu Sep 23 17:55:26 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 23 Sep 2010 17:55:26 -0400 Subject: Parsing error for ConfigParser In-Reply-To: <0c7a4de7-9a1b-40c6-a84f-726295cb311a@w4g2000vbh.googlegroups.com> References: <0c7a4de7-9a1b-40c6-a84f-726295cb311a@w4g2000vbh.googlegroups.com> Message-ID: On Sep 23, 2010, at 1:22 PM, Andrew Z. wrote: > Is there a way to parse RealPlayer's realplayerrc in Python? I need > to support Python 2.5 - 2.7 > > Example code > > import urllib2 > import ConfigParser > f = urllib2.urlopen('http://pastebin.com/download.php?i=N1AcUg3w') > config = ConfigParser.RawConfigParser() > config.readfp(f) > > > Error > Traceback (most recent call last): > File "test_config_parser_real_player.py", line 6, in > config.readfp(f) > File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp > self._read(fp, filename) > File "/usr/lib/python2.6/ConfigParser.py", line 510, in _read > raise e > ConfigParser.ParsingError: File contains parsing errors: > [line 31]: '%0aCopyright (c) 1995-2000 Macromedia, Inc. All > rights reserved.\r\n' > [line 34]: '%0a\r\n' Hi Andrew, Hopefully someone familiar with the topic of RealPlayer file formats will step in, but while you're waiting here's my $.02. Looks like this is an INI file, and since there's no defined standard for INI files, it's hard for anyone to write a parser that is guaranteed to work with all INI files. In this particular case you've got a multiline entry in the INI file which apparently ConfigParser doesn't like. One approach would be to subclass ConfigParser and massage the lines it doesn't like into something ConfigParser finds more palatable. Or if you're not interested in those lines, parse the error message, delete the offending lines and re-run the INI file through ConfigParser. Good luck Philip From python at bdurham.com Thu Sep 23 20:31:05 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 23 Sep 2010 20:31:05 -0400 Subject: Python 2.6: How to turn off cgitb.py's DeprecationWarning: BaseException.message has been deprecated Message-ID: <1285288265.4428.1396613849@webmail.messagingengine.com> Python 2.6: We're using the standard lib's cgitb module to provide diagnostic messages when unexpected exceptions occur. Unfortunately, this module raises a DeprecationWarning like below when it is used: C:\Python26\lib\cgitb.py:245: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 value = pydoc.text.repr(getattr(evalue, name)) Is there some way to disable this specific warning message (our customers find it disconcerting) or do we have to go in and edit the cgitb.py module itself? Also, wondering if this warning has been addressed in Python 2.7/3.x? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From raoulbia at gmail.com Thu Sep 23 20:43:29 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 23 Sep 2010 17:43:29 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> <6d8a9aac-817c-4c1d-a175-fce403ccebba@t11g2000vbc.googlegroups.com> Message-ID: <3c4802f3-4bcf-4c89-aa29-bb922aa4ee05@l17g2000vbf.googlegroups.com> On Sep 23, 8:13?pm, nn wrote: > On Sep 23, 1:25?pm, Baba wrote: > > > > > On Sep 23, 4:17?pm, nn wrote: > > > > On Sep 23, 10:56?am, nn wrote: > > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > > > Hi > > > > > > > > > query level: beginner > > > > > > > > > as part of a learning exercise i have written code that: > > > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > > > entered) > > > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > > > c) start again until 2) is True > > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > > handlist = [] > > > > > > > > letter = raw_input('enter letter: ') > > > > > > > > handlist.append(letter) > > > > > > > > hand = "".join(handlist) > > > > > > > > for item in wordlist: > > > > > > > > ? ? if item.startswith(hand): > > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > > > ? ? ? ? ? ? else: break > > > > > > > > ? ? ? ? else: break > > > > > > > > print 'you loose' > > > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > > > thanks > > > > > > > > Baba > > > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > > > if I use the following word list: > > > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > > > enter letter: h > > > > > > > enter letter: a > > > > > > > you loose > > > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > > > version might be a bit too advanced but you should still be able to do > > > > > > > it using only one while, one for and one if instead. > > > > > > > Hi nn, > > > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > > > While i was conscious that the whole construct was heavy i thought the > > > > > > reasoning worked. I keep looking at it but can't figure out the > > > > > > problem Can you give me a hint? > > > > > > > In the meantime i found out that it is actually possible to populate a > > > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > > > got now: > > > > > > > wordlist = ['hello', 'bye'] > > > > > > hand = '' > > > > > > for item in wordlist: > > > > > > ? ? if item.startswith(hand): > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > > > ? ? ? ? ? ? ? ? print hand > > > > > > ? ? ? ? ? ? else: break > > > > > > ? ? ? ? else: break > > > > > > print 'you loose' > > > > > > > But i can't figure out why it won't work when adding the extra word. > > > > > > Thanks by the way, it taught me not to be too confident when things > > > > > > SEEM to work... > > > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > > > into one... > > > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > > > hand = '' > > > > > > while any(item.startswith(hand) for item in wordlist): > > > > > > ? ? if hand not in wordlist: > > > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > > > ? ? else: break > > > > > > print 'you loose' > > > > > > > thanks > > > > > > > Baba > > > > > > Hi nn, > > > > > > looking at my original code again i realise that having a raw_input > > > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > > > will just assume that i was taking the wrong approach initially. No > > > > > point in analysing it further. Thanks for your help. > > > > > > Baba > > > > > Since you seem to have figured it out I will post my version (python > > > > 3): > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > inp='' > > > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > > > ? ? inp += input('enter letter: ') > > > > print('you lose') > > > > > The reason why your original version didn't work was because each time > > > > you add a letter you have to go again over all words (in reality only > > > > a subset is required) and find a new one. Your version would find one > > > > word using the first letter and then exit. > > > > Actually my version isn't right (for some values of right): > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > inp='' > > > while any(word.startswith(inp) for word in wordlist) and (inp not in > > > wordlist): > > > ? ? inp += input('enter letter: ') > > > print('you lose') > > > > An explanation of how this changes the rules of the wordgame is left > > > as an exercise to the reader. > > > Hi, > > > for now i will stick to Python2.7 but thank you for sharing. > > > for learning purposes i still want to figure out a way to solve this > > without built-in function ('any' in this case). My understanding was > > that in programming almost anything can be done with IF, FOR and WHILE > > statements. However i turn in circles...:( i understand that in my > > original code my while loop locked me into the first word hello if the > > first letter was 'h' and therefore if the next letter was 'a' it would > > break...so far so good but this appears really tricky to solve...here > > is what i have come up with but it will not exit if for example i > > enter 'x' ... > > > wordlist = ['hello', 'bye'] > > hand = '' > > while hand not in wordlist: > > ? ? hand += raw_input('enter letter: ') > > ? ? print hand > > ? ? for item in wordlist: > > ? ? ? ? if not item.startswith(hand): > > ? ? ? ? ? ? break > > print 'you lose' > > > but no matter how i turn this around i can't find the magic > > approach...i was thinking about starting the code with something like > > "while (something) is True" ... would that be a right approach? > > > Baba > > This program has 2 problems: > 1.) the break only exits one level: i.e. the for loop > 2.) your logic is backwards. You stop checking as soon as you find the > first mismatch. It should be the other way around: it is invalid only > after testing with all words and not finding any match. > > And yes all of this can be done using just using while, for and if. I > just wrote another version with 1 while, 1 for, 2 ifs, 0 breaks, 0 > any, 0 genexp. This is like doing algebra: you add 2 here, substract 2 > there and the same result comes out. There is an infinite number of > programs that can be written to generate the same output. wordlist = ['hello', 'hamburger', 'bye', 'foo'] hand = '' check = True while check == True: check = False hand += raw_input('enter letter: ') for item in wordlist: if item.startswith(hand): check = True break if hand in wordlist: break print 'you lose' pretty long compared to yours but learning objective achieved. Thanks for your help! Baba From raoulbia at gmail.com Thu Sep 23 20:46:25 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 23 Sep 2010 17:46:25 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> <6d8a9aac-817c-4c1d-a175-fce403ccebba@t11g2000vbc.googlegroups.com> Message-ID: On Sep 23, 8:13?pm, nn wrote: > On Sep 23, 1:25?pm, Baba wrote: > > > > > On Sep 23, 4:17?pm, nn wrote: > > > > On Sep 23, 10:56?am, nn wrote: > > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > > > Hi > > > > > > > > > query level: beginner > > > > > > > > > as part of a learning exercise i have written code that: > > > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > > > entered) > > > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > > > c) start again until 2) is True > > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > > handlist = [] > > > > > > > > letter = raw_input('enter letter: ') > > > > > > > > handlist.append(letter) > > > > > > > > hand = "".join(handlist) > > > > > > > > for item in wordlist: > > > > > > > > ? ? if item.startswith(hand): > > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > > > ? ? ? ? ? ? else: break > > > > > > > > ? ? ? ? else: break > > > > > > > > print 'you loose' > > > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > > > thanks > > > > > > > > Baba > > > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > > > if I use the following word list: > > > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > > > enter letter: h > > > > > > > enter letter: a > > > > > > > you loose > > > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > > > version might be a bit too advanced but you should still be able to do > > > > > > > it using only one while, one for and one if instead. > > > > > > > Hi nn, > > > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > > > While i was conscious that the whole construct was heavy i thought the > > > > > > reasoning worked. I keep looking at it but can't figure out the > > > > > > problem Can you give me a hint? > > > > > > > In the meantime i found out that it is actually possible to populate a > > > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > > > got now: > > > > > > > wordlist = ['hello', 'bye'] > > > > > > hand = '' > > > > > > for item in wordlist: > > > > > > ? ? if item.startswith(hand): > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > > > ? ? ? ? ? ? ? ? print hand > > > > > > ? ? ? ? ? ? else: break > > > > > > ? ? ? ? else: break > > > > > > print 'you loose' > > > > > > > But i can't figure out why it won't work when adding the extra word. > > > > > > Thanks by the way, it taught me not to be too confident when things > > > > > > SEEM to work... > > > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > > > into one... > > > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > > > hand = '' > > > > > > while any(item.startswith(hand) for item in wordlist): > > > > > > ? ? if hand not in wordlist: > > > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > > > ? ? else: break > > > > > > print 'you loose' > > > > > > > thanks > > > > > > > Baba > > > > > > Hi nn, > > > > > > looking at my original code again i realise that having a raw_input > > > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > > > will just assume that i was taking the wrong approach initially. No > > > > > point in analysing it further. Thanks for your help. > > > > > > Baba > > > > > Since you seem to have figured it out I will post my version (python > > > > 3): > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > inp='' > > > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > > > ? ? inp += input('enter letter: ') > > > > print('you lose') > > > > > The reason why your original version didn't work was because each time > > > > you add a letter you have to go again over all words (in reality only > > > > a subset is required) and find a new one. Your version would find one > > > > word using the first letter and then exit. > > > > Actually my version isn't right (for some values of right): > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > inp='' > > > while any(word.startswith(inp) for word in wordlist) and (inp not in > > > wordlist): > > > ? ? inp += input('enter letter: ') > > > print('you lose') > > > > An explanation of how this changes the rules of the wordgame is left > > > as an exercise to the reader. > > > Hi, > > > for now i will stick to Python2.7 but thank you for sharing. > > > for learning purposes i still want to figure out a way to solve this > > without built-in function ('any' in this case). My understanding was > > that in programming almost anything can be done with IF, FOR and WHILE > > statements. However i turn in circles...:( i understand that in my > > original code my while loop locked me into the first word hello if the > > first letter was 'h' and therefore if the next letter was 'a' it would > > break...so far so good but this appears really tricky to solve...here > > is what i have come up with but it will not exit if for example i > > enter 'x' ... > > > wordlist = ['hello', 'bye'] > > hand = '' > > while hand not in wordlist: > > ? ? hand += raw_input('enter letter: ') > > ? ? print hand > > ? ? for item in wordlist: > > ? ? ? ? if not item.startswith(hand): > > ? ? ? ? ? ? break > > print 'you lose' > > > but no matter how i turn this around i can't find the magic > > approach...i was thinking about starting the code with something like > > "while (something) is True" ... would that be a right approach? > > > Baba > > This program has 2 problems: > 1.) the break only exits one level: i.e. the for loop > 2.) your logic is backwards. You stop checking as soon as you find the > first mismatch. It should be the other way around: it is invalid only > after testing with all words and not finding any match. > > And yes all of this can be done using just using while, for and if. I > just wrote another version with 1 while, 1 for, 2 ifs, 0 breaks, 0 > any, 0 genexp. This is like doing algebra: you add 2 here, substract 2 > there and the same result comes out. There is an infinite number of > programs that can be written to generate the same output. wordlist = ['hello', 'hamburger', 'bye', 'foo'] hand = '' check = True while check == True: check = False hand += raw_input('enter letter: ') for item in wordlist: if item.startswith(hand): check = True break if hand in wordlist: break print 'you lose' learning objective achieved :) Thanks for your help! Baba From rplasson at gmail.com Thu Sep 23 20:50:01 2010 From: rplasson at gmail.com (=?ISO-8859-1?Q?Rapha=EBl_Plasson?=) Date: Thu, 23 Sep 2010 17:50:01 -0700 (PDT) Subject: Best way for rotating a matrix of data? References: <3207b8a9-a566-478d-a5db-859db162b8e4@p24g2000pra.googlegroups.com> Message-ID: <18eacefa-ec05-4fba-9b35-6e8f938d88dc@z34g2000pro.googlegroups.com> On Sep 23, 1:50?am, Nobody wrote: > You can use arrays as indices, so applying a transformation to a set of > index arrays (e.g. np.indices) then using those as indices is equivalent > to applying a spatial transform to the data. I am not sure that this would do the trick, e.g. for extracting a transversal slice of a 3D array. > Also: scipy.ndimage. But this seems to do exactly what I am looking for, thanks :). There actually may be another solution, that is to use the VTK library. However, it is a much more complex package, much more powerful but maybe too much for what I want to do. The scipy.ndimage module ("Multi- dimensional image processing") is probably the best solution for me. Thank you, Raphael From missive at hotmail.com Thu Sep 23 20:56:50 2010 From: missive at hotmail.com (Lee Harr) Date: Fri, 24 Sep 2010 05:26:50 +0430 Subject: pyqt on portable python? Message-ID: Is it possible / easy to use PyQt with portable python? I've done some googling and found one message that said this is coming in the next version, but I can't find anything on portablepython.com that mentions it. Has anyone done this before? Have any better information on how to set it up, or when it might come to the default version of portable python? Thanks. From jnoller at gmail.com Thu Sep 23 21:31:59 2010 From: jnoller at gmail.com (Jesse Noller) Date: Thu, 23 Sep 2010 21:31:59 -0400 Subject: Call for proposals -- PyCon 2011 Message-ID: Call for proposals -- PyCon 2011 -- =============================================================== Proposal Due date: November 1st, 2010 PyCon is back! With a rocking new website, a great location and more Python hackers and luminaries under one roof than you could possibly shake a stick at. We've also added an "Extreme" talk track this year - no introduction, no fluff - only the pure technical meat! PyCon 2011 will be held March 9th through the 17th, 2011 in Atlanta, Georgia. (Home of some of the best southern food you can possibly find on Earth!) The PyCon conference days will be March 11-13, preceded by two tutorial days (March 9-10), and followed by four days of development sprints (March 14-17). PyCon 2011 is looking for proposals for the formal presentation tracks (this includes "extreme talks"). A request for proposals for poster sessions and tutorials will come separately. Want to showcase your skills as a Python Hacker? Want to have hundreds of people see your talk on the subject of your choice? Have some hot button issue you think the community needs to address, or have some package, code or project you simply love talking about? Want to launch your master plan to take over the world with Python? PyCon is your platform for getting the word out and teaching something new to hundreds of people, face to face. In the past, PyCon has had a broad range of presentations, from reports on academic and commercial projects, tutorials on a broad range of subjects, and case studies. All conference speakers are volunteers and come from a myriad of backgrounds: some are new speakers, some have been speaking for years. Everyone is welcome, so bring your passion and your code! We've had some incredible past PyCons, and we're looking to you to help us top them! Online proposal submission is open now! Proposals will be accepted through November 10th, with acceptance notifications coming out by January 20th. To get started, please see: For videos of talks from previous years - check out: For more information on "Extreme Talks" see: We look forward to seeing you in Atlanta! Please also note - registration for PyCon 2011 will also be capped at a maximum of 1,500 delegates, including speakers. When registration opens (soon), you're going to want to make sure you register early! Speakers with accepted talks will have a guaranteed slot. Important Dates: * November 1st, 2010: Talk proposals due. * December 15th, 2010: Acceptance emails sent. * January 19th, 2010: Early bird registration closes. * March 9-10th, 2011: Tutorial days at PyCon. * March 11-13th, 2011: PyCon main conference. * March 14-17th, 2011: PyCon sprints days. Contact Emails: Van Lindberg (Conference Chair) - van at python.org Jesse Noller (Co-Chair) - jnoller at python.org PyCon Organizers list: pycon-organizers at python.org From skyepn at gmail.com Thu Sep 23 22:31:20 2010 From: skyepn at gmail.com (Skye) Date: Thu, 23 Sep 2010 19:31:20 -0700 (PDT) Subject: Finding email threads with mailbox.mbox Message-ID: <22f7b135-1ba7-4177-aa54-87d23b6fa058@j5g2000vbg.googlegroups.com> Hello, I'm working on a script to read large numbers of mail list archives in mbox format and dump them into a database. I was happy to find mailbox.mbox because I like writing Python =) However I need to find email threads (replies, quoted test, Re: subjects etc) and it doesn't look like anything in the standard Python library will help me with that. I suppose I could yank some code from Mailman's pipermail or something for identifying discussion threads, but I was wondering if anyone had any other suggestions before I reinvent the wheel. Thanks, Skye From ldo at geek-central.gen.new_zealand Thu Sep 23 23:18:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 15:18:47 +1200 Subject: Subprocess does not return for longer-running process References: Message-ID: In message , Nobody wrote: > On Thu, 23 Sep 2010 12:25:53 +1200, Lawrence D'Oliveiro wrote: > >>> And I can't think of any reason why you should use os.waitpid() or >>> similar; use the .wait() method. >> >> I have used WNOHANG to poll for completion of a subprocess while >> providing progress updates to the user. > > This can be done via the .poll() method. And what do you think the poll method uses? From ldo at geek-central.gen.new_zealand Thu Sep 23 23:23:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 15:23:08 +1200 Subject: Python in Linux - barrier to Python 3.x References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> Message-ID: In message <2ab95324-4394-4510-b953-3c8555b0a9bd at q9g2000vbd.googlegroups.com>, Ant wrote: > Still, no Python 3 unless I upgrade to Fedora 13, and upgrading > an OS in order to get the latest version of one package is a bit much! You?re using Fedora, a distro that pretty much demands you upgrade at least every 12 months, and you?re complaining about it? From ldo at geek-central.gen.new_zealand Thu Sep 23 23:28:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 15:28:39 +1200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: In message <87zkvbytnk.fsf at web.de>, Diez B. Roggisch wrote: > Of course, in a ideal world, distutils would hook into the distros > dependency system + simply say "please install python-dev first". > > But I'm not convinced that putting the weight here on the shoulders of > the python-communtiy to deal with arbirtray decisions of the dozen or > how many distros + packaging schemes out there is possible - and helpful. Fair enough. I think the right answer is for the package-management systems to bear the burden of coping with the established installation mechanisms of particular major subsystems. There may be a slight mismatch, in that distutils is source-based, whereas most Linux distros (with the notable exception of Gentoo) expect to distribute and install prebuilt binaries. I suspect this is not insurmountable. From ldo at geek-central.gen.new_zealand Thu Sep 23 23:31:17 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 15:31:17 +1200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: In message , Antoine Pitrou wrote: > comp.lang.python doesn't handle Linux packaging [issues] ... Why not? We regularly seem to was^H^H^Hspend a lot of time with Windows- specific packaging problems, installation problems and configuration problems, why not Linux ones as well? From aahz at pythoncraft.com Fri Sep 24 00:56:19 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Sep 2010 21:56:19 -0700 Subject: Help needed with Windows Service in Python References: Message-ID: In article , Ian Hobson wrote: > >I am attempting to create a Windows Service in Python. BTW, you probably want to subscribe to http://mail.python.org/mailman/listinfo/python-win32 -- 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 steve at REMOVE-THIS-cybersource.com.au Fri Sep 24 03:04:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Sep 2010 07:04:47 GMT Subject: Python in Linux - barrier to Python 3.x References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> Message-ID: <4c9c4d8e$0$28657$c3e8da3@news.astraweb.com> On Fri, 24 Sep 2010 15:23:08 +1200, Lawrence D'Oliveiro wrote: > In message > <2ab95324-4394-4510-b953-3c8555b0a9bd at q9g2000vbd.googlegroups.com>, Ant > wrote: > >> Still, no Python 3 unless I upgrade to Fedora 13, and upgrading an OS >> in order to get the latest version of one package is a bit much! > > You?re using Fedora, a distro that pretty much demands you upgrade at > least every 12 months, and you?re complaining about it? "Demands"? I'm using Fedora 7. Obviously the demands have been going to my old address. -- Steven From deluxstar at gmail.com Fri Sep 24 03:05:23 2010 From: deluxstar at gmail.com (deluxstar) Date: Fri, 24 Sep 2010 00:05:23 -0700 (PDT) Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" Message-ID: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> Hi, We have an application working on several servers generally written with Python 2.6 and Twisted 10. The source codes are located in one server and compiled in this server. The compiled files are copied to other server via network and application server works with these compiled files. In this application, I have to write a function to return a value of the caller object that calles this function. The function may be called from several modules of the application. To achieve this goal, I try to use the python inspect module: curframe = inspect.currentframe() calframe = inspect.getouterframes(curframe, 2) calframe[1][0].f_locals['variable'] This sample code works on local development environment both on linux and windows. When checked in to production environment, inspect.currentframe() or inspect.stack() function gives "List index out of range error". When I googled, I found only one clue of copying pyc files: http://forum.webfaction.com/viewtopic.php?pid=16808 Why inspect modules gives this error? OR Is there another way to get the caller objects variable value? Thanks in advance. From steve at REMOVE-THIS-cybersource.com.au Fri Sep 24 03:23:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Sep 2010 07:23:25 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> <4c9aa057$0$11123$c3e8da3@news.astraweb.com> <87k4mdmdv0.fsf@castleamber.com> <20100923114225.32f7253e@geekmail.INVALID> Message-ID: <4c9c51ec$0$28657$c3e8da3@news.astraweb.com> On Thu, 23 Sep 2010 11:42:25 -0400, Andreas Waldenburger wrote: > On Wed, 22 Sep 2010 20:45:55 -0500 John Bokma > wrote: > >> What surprises me is that this is still discussed. It's like argueing >> about significant whitespace. :-) > > Which is evil! Iagreethatsignioficantwhitespaceisevil.Pythonshouldbelikeearlyver sionsofFortran,whichhadnosignificantwhitespace.Muchbetter,inmyopi nion. *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Sep 24 03:51:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Sep 2010 07:51:52 GMT Subject: Python in Linux - barrier to Python 3.x References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> Message-ID: <4c9c5897$0$28659$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 13:54:55 -0700, Ant wrote: > Yes you are right - I've checked on my home machine, and it is indeed > 2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading an > OS in order to get the latest version of one package is a bit much! Or you could install from source, which takes all of three minutes of effort. Well, maybe four. Eight if you've never done it before. Maybe twelve if you're cautious. Here's a link to get you started: http://www.python.org/download/releases/3.1.2/ The only gotchas you're likely to run into are, you need root, or at least sudo (which you would need for an rpm installation as well), and don't forget to run `make altinstall` instead of `make install`. Read the README for details. You might have a policy of never installing anything that doesn't go through the system packaging system, and that's a perfectly good policy. But that's not Python's responsibility. Go nag the Fedora folks. Or ask around, somebody surely has built an rpm for Python 3.1. > I know that this is a distribution issue, and not strictly a Python > one, It's not a Python issue *at all*. > but the issue exists primarily because python is such a > successful language it has become deeply embedded in linux > distributions, and so there is now a lot of work involved in checking > that a python upgrade doesn't break things. Well, maybe so, but that has nothing to do with the availability of one or more non-system Pythons. My sys admin foo is mediocre at best, but I've had no problems at all with installing Pythons 1.5 through 3.2 inclusive on my system, while leaving 2.5 as the system Python. In my experience installing from source on Fedora systems Just Works. -- Steven From boolegue at gmail.com Fri Sep 24 03:53:22 2010 From: boolegue at gmail.com (antoine) Date: Fri, 24 Sep 2010 00:53:22 -0700 (PDT) Subject: SocketServer: replace network by hard drive Message-ID: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Hello, I would like to create a python server for which the requests are passed by files on the hard drive instead of a network. I am currently looking at the SocketServer python module, hoping for an easy modification. Is it doable at all? If yes, how should it be done? Thanks, Antoine. From wim at go2people.nl Fri Sep 24 03:57:29 2010 From: wim at go2people.nl (Wim Feijen) Date: Fri, 24 Sep 2010 09:57:29 +0200 Subject: feature request: string.contains('...') Message-ID: Hello, I was wondering, how to make a feature request? I would really like having a string.contains('...') function which returns either True or False. I know I can mimick this behaviour by saying string.find('...') != -1 , however, I find this harder to read. string.contains('...') is easier to understand and more closely resembles natural language. Thanks for your help and best regards, Wim Feijen -- Wim Feijen Algemeen directeur wim at go2people.nl 06 11113316 Go2People Keizersgracht 8 1015 CN Amsterdam 020 7370378 www.go2people.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfgang at rohdewald.de Fri Sep 24 04:10:53 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Fri, 24 Sep 2010 10:10:53 +0200 Subject: feature request: string.contains('...') In-Reply-To: References: Message-ID: <201009241010.53578.wolfgang@rohdewald.de> On Freitag 24 September 2010, Wim Feijen wrote: > would really like having a string.contains('...') function > which returns either True or False. I know I can mimick this > behaviour by saying string.find('...') != -1 , however, I > find this harder to read. >>> a = 'xy134' >>> '13' in a True >>> '15' in a False >>> -- Wolfgang From __peter__ at web.de Fri Sep 24 04:21:47 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Sep 2010 10:21:47 +0200 Subject: feature request: string.contains('...') References: Message-ID: Wim Feijen wrote: > I was wondering, how to make a feature request? You can post suggestions to improve python on the python-ideas mailing list or make feature requests on the bugtracker at bugs.python.org > I would really like having a string.contains('...') function which returns > either True or False. I know I can mimick this behaviour by saying > string.find('...') != -1 , however, I find this harder to read. > > string.contains('...') is easier to understand and more closely resembles > natural language. In modern python those functions provided by the string module that are also available as methods should not be used anymore. Instead of string.find(s, substr) write s.find(substr) If you are not interested in the position of the substr use the "in" operator: if substr in s: print "found" else: print "not found" Peter From chris at simplistix.co.uk Fri Sep 24 04:28:47 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 24 Sep 2010 09:28:47 +0100 Subject: os.path.normcase rationale? In-Reply-To: <4c97f629$0$28658$c3e8da3@news.astraweb.com> References: <87lj727lu7.fsf@benfinney.id.au> <4c97f629$0$28658$c3e8da3@news.astraweb.com> Message-ID: <4C9C613F.4000009@simplistix.co.uk> On 21/09/2010 01:02, Steven D'Aprano wrote: > On Mon, 20 Sep 2010 19:45:37 +0100, Chris Withers wrote: > >> Well, no, that doesn't feel right. Normalisation of case, for me, means >> "give me the case as the filesystem thinks it should be", > > What do you mean "the filesystem"? > > If I look at the available devices on my system now, I see: > > 2 x FAT-32 filesystems > 1 x ext2 filesystem > 3 x ext3 filesystems > 1 x NTFS filesystem > 1 x UDF filesystem Right, and each of these will know what it thinks a file's "real" name is, along with potentially accepting as set of synonyms for them... > and if I ever get my act together to install Basilisk II, as I've been > threatening to do for the last five years, there will also be at least > one 1 x HFS filesystem. Which one is "the" filesystem? Whichever one you're getting the file from... > If you are suggesting that os.path.normcase(filename) should determine > which filesystem actually applies to filename at runtime, and hence work > out what rules apply, what do you suggest should happen if the given path > doesn't actually exist? I'd suggest an exception be raised. Really, what's the point of normcase if it's basically just "if os=='win': return path.lower()" > What if it's a filesystem that the normpath > developers haven't seen or considered before? I didn't say it was an easy problem, but the current normpath is a waste of space... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From cournape at gmail.com Fri Sep 24 04:35:38 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 24 Sep 2010 17:35:38 +0900 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <4c9c5897$0$28659$c3e8da3@news.astraweb.com> References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> <4c9c5897$0$28659$c3e8da3@news.astraweb.com> Message-ID: On Fri, Sep 24, 2010 at 4:51 PM, Steven D'Aprano wrote: > On Tue, 21 Sep 2010 13:54:55 -0700, Ant wrote: > >> Yes you are right - I've checked on my home machine, and it is indeed >> 2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading an >> OS in order to get the latest version of one package is a bit much! > > Or you could install from source, which takes all of three minutes of > effort. Well, maybe four. Eight if you've never done it before. Maybe > twelve if you're cautious. That only works if some cases. If you need some additional packages, especially ones which depend on C extensions, that may be difficult or even hopelessly intractable. Typically, if your want to install say matplotlib with pygtk with a custom built python, you are in for a fun ride because you have to rebuild everything. That the cases where you really want something that integrates well with the native packaging system, whatever that ends up to be. cheers, David From matthias.guentert at gmail.com Fri Sep 24 04:38:56 2010 From: matthias.guentert at gmail.com (Matthias Guentert) Date: Fri, 24 Sep 2010 10:38:56 +0200 Subject: Raw Sockets - IP-Encapsulation In-Reply-To: References: Message-ID: Hello list members I would like to create an IP tunnel using the IP protocol type 4 (socket.IPPROTO_IPIP) on a Linux host. (I also would be happy if I could create a GRE tunnel) The thing is, I just don't understand how I such a socket could be created and then later on handled. Regarding to help(socket.socke()) the constructor looks like this: ?| socket([family[, type[, proto]]]) -> socket object ?| ?| ?Open a socket of the given type. ?The family argument specifies the ?| ?address family; it defaults to AF_INET. ?The type argument specifies ?| ?whether this is a stream (SOCK_STREAM, this is the default) ?| ?or datagram (SOCK_DGRAM) socket. ?The protocol argument defaults to 0, ?| ?specifying the default protocol. ?Keyword arguments are accepted. This means to create a simple UDP socket I can do the following where the last argument is optional. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP) So to create an IP-Encapsulation socket I would have to do this: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IPIP) or for GRE this. s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_GRE) But how can I now set the fields? How do I really encapsulate other data (=sockets?)? Do I need a Raw socket at all? Or should this work somehow like the following to encapsulate UDP payload? s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IPIP) I really would be happy if someone could help me with this and even better could provide some examples on the usage. Thanks in advance, Matthias From steve at REMOVE-THIS-cybersource.com.au Fri Sep 24 05:23:33 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Sep 2010 09:23:33 GMT Subject: Python in Linux - barrier to Python 3.x References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> <4c9c5897$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4c9c6e15$0$28659$c3e8da3@news.astraweb.com> On Fri, 24 Sep 2010 17:35:38 +0900, David Cournapeau wrote: > On Fri, Sep 24, 2010 at 4:51 PM, Steven D'Aprano > wrote: >> On Tue, 21 Sep 2010 13:54:55 -0700, Ant wrote: >> >>> Yes you are right - I've checked on my home machine, and it is indeed >>> 2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading >>> an OS in order to get the latest version of one package is a bit much! >> >> Or you could install from source, which takes all of three minutes of >> effort. Well, maybe four. Eight if you've never done it before. Maybe >> twelve if you're cautious. > > That only works if some cases. If you need some additional packages, > especially ones which depend on C extensions, that may be difficult or > even hopelessly intractable. First of all, the issue being raised was Python itself, not third party packages. Just because my distro supports Python 3.1 doesn't mean it supports Some_Random_Package-0.2.1 too. And secondly, if it's hopelessly intractable to install a package from source, it will be hopelessly intractable for your distro packagers to build a package for it too. The difference is that if it's merely inhumanly difficult, the packagers can do it *once*, instead of expecting everyone to do so. > Typically, if your want to install say > matplotlib with pygtk with a custom built python, you are in for a fun > ride because you have to rebuild everything. That's not what I consider a typical case. But I take your point. > That the cases where you > really want something that integrates well with the native packaging > system, whatever that ends up to be. Oh of course. That's the ideal situation. But just because something falls short of the ideal doesn't mean you can't still get it. If you want Python 3.1 and your distro doesn't support it, you don't *have* to change distros. -- Steven From chris at simplistix.co.uk Fri Sep 24 05:27:18 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 24 Sep 2010 10:27:18 +0100 Subject: Distributing Packages In-Reply-To: References: Message-ID: <4C9C6EF6.7010106@simplistix.co.uk> On 23/09/2010 16:41, Greg Lindstrom wrote: > I am not intending to start anything, here, but would like to know if > any consensus has been reached in how to distribute Python modules. Hi Greg, The following shows a pattern that's working well for me: https://secure.simplistix.co.uk/svn/Simplistix/errorhandler/trunk The "work" is in setup.py. The development docs are here: http://packages.python.org/errorhandler/development.html Ignore the sphinx and buildout stuff if you're not using them, although I find both extremely valuable... > Specifically, I'd like to use something to install packages on various > machines in our enterprise (mostly Linux, but some windows boxes, too). With the above, I'd do: python setup.py sdist ...and then put the resulting sdist in a folder served by Apache. To install on a given box, I'd then do: easy_install --find-links=http://yourserver/your/folder yourpackage Using setuptools for the setup.py means you can specify any other packages your need via the install_requires parameter . I'd suggestion buildout or virtualenv for deploying to the servers too, installing into the system python's site-packages is yucky and means all projects on one box have to use the same versions of the same libraries... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From __peter__ at web.de Fri Sep 24 05:39:57 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Sep 2010 11:39:57 +0200 Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> Message-ID: deluxstar wrote: > We have an application working on several servers generally written > with Python 2.6 and Twisted 10. > The source codes are located in one server and compiled in this > server. The compiled files are copied to other server via network and > application server works with these compiled files. > > In this application, I have to write a function to return a value of > the caller object that calles this function. The function may be > called from several modules of the application. To achieve this goal, > I try to use the python inspect module: > > curframe = inspect.currentframe() > calframe = inspect.getouterframes(curframe, 2) > calframe[1][0].f_locals['variable'] > > This sample code works on local development environment both on linux > and windows. When checked in to production environment, > inspect.currentframe() or inspect.stack() function gives "List index > out of range error". > > When I googled, I found only one clue of copying pyc files: > http://forum.webfaction.com/viewtopic.php?pid=16808 > > Why inspect modules gives this error? OR Is there another way to get > the caller objects variable value? Can you provide the actual traceback? Provide a small script that reproduces the error? Add print statements and post their output? print inspect.currentframe > curframe = inspect.currentframe() print curframe > calframe = inspect.getouterframes(curframe, 2) print calframe Peter From geoff.bache at gmail.com Fri Sep 24 05:49:56 2010 From: geoff.bache at gmail.com (Geoff Bache) Date: Fri, 24 Sep 2010 02:49:56 -0700 (PDT) Subject: inspect.getmodulename giving unexpected results Message-ID: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> Hi all, I'm trying to examine some things in my stack. The information I get out of inspect.stack() gives file names and I would like to convert them to module names. I naturally assumes inspect.getmodulename would fix this for me. Unfortunately, it doesn't seem to do that in some cases. Consider the following code: ## file 'inspect_test' #!/usr/bin/env python import logging, inspect print inspect.getmodulename(logging.__file__), inspect.getmodulename(__file__) I hoped that this would print logging __main__ or at least logging inspect_test but instead it prints __init__ None which isn't very helpful, although it could technically be considered correct (I can go to the 'logging' directory and type "import __init__" but nobody ever does) I guess I was hoping to get the names of the modules as they appear in sys.modules. Maybe there is some other way to do that? I can naturally write my own method to do this but wondered if I'm missing something here. Regards, Geoff Bache From cournape at gmail.com Fri Sep 24 05:57:21 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 24 Sep 2010 18:57:21 +0900 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <4c9c6e15$0$28659$c3e8da3@news.astraweb.com> References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> <4c9c5897$0$28659$c3e8da3@news.astraweb.com> <4c9c6e15$0$28659$c3e8da3@news.astraweb.com> Message-ID: On Fri, Sep 24, 2010 at 6:23 PM, Steven D'Aprano wrote: >> Typically, if your want to install say >> matplotlib with pygtk with a custom built python, you are in for a fun >> ride because you have to rebuild everything. > > That's not what I consider a typical case. But I take your point. It is an acute problem in the numpy/scipy community, and I think it generalizes to any community which depends quite a bit on C extensions. I am convinced that the only solution that can work in those cases is *more* integration with native solutions, not less. That's why I worry when people suggest to *only* focus on making python-only solutions. Of course, python-specific solutions are fine as long as they don't make it more difficult to support the native-integration goal (which sadly has been the trend up to now). cheers, David From premjee07 at gmail.com Fri Sep 24 08:02:08 2010 From: premjee07 at gmail.com (christopher S Sam) Date: Fri, 24 Sep 2010 05:02:08 -0700 (PDT) Subject: Trade easy and double your money in One month,.,..,.,..,.,.., Message-ID: Trading is the best and simple way of making money online,,,,, Know the trick to double your money in a month http://www.fxtradingmoney.com http://www.fxtradingmoney.com http://www.fxtradingmoney.com http://www.fxtradingmoney.com http://www.fxtradingmoney.com From thomas at jollybox.de Fri Sep 24 08:29:55 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 24 Sep 2010 14:29:55 +0200 Subject: inspect.getmodulename giving unexpected results In-Reply-To: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> References: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> Message-ID: <201009241429.56319.thomas@jollybox.de> On Friday 24 September 2010, it occurred to Geoff Bache to exclaim: > Hi all, > > I'm trying to examine some things in my stack. The information I get > out of inspect.stack() gives file names and I would like to convert > them to module names. I naturally assumes inspect.getmodulename would > fix this for me. > > Unfortunately, it doesn't seem to do that in some cases. Consider the > following code: It does behave as documented: it does not find package names, or investigate sys.modules > ## file 'inspect_test' rename this file to "inspect_test.py", and the filename will make sense to inspect.getmodulename, which should *then* return "inspect_test" instead of None. > > #!/usr/bin/env python > > import logging, inspect > > print inspect.getmodulename(logging.__file__), > inspect.getmodulename(__file__) > > I hoped that this would print > logging __main__ > > or at least > logging inspect_test > > but instead it prints > __init__ None > > which isn't very helpful, although it could technically be considered > correct (I can go to the 'logging' directory and type "import > __init__" but nobody ever does) > > I guess I was hoping to get the names of the modules as they appear in > sys.modules. Maybe there is some other way to do that? I can naturally > write my own method to do this but wondered if I'm missing something > here. Not that I know of. From pruebauno at latinmail.com Fri Sep 24 09:14:22 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 24 Sep 2010 06:14:22 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> <6d8a9aac-817c-4c1d-a175-fce403ccebba@t11g2000vbc.googlegroups.com> Message-ID: <1da382f3-50a5-4e48-b038-4bcb72630ef0@q9g2000vbd.googlegroups.com> On Sep 23, 8:46?pm, Baba wrote: > On Sep 23, 8:13?pm, nn wrote: > > > > > On Sep 23, 1:25?pm, Baba wrote: > > > > On Sep 23, 4:17?pm, nn wrote: > > > > > On Sep 23, 10:56?am, nn wrote: > > > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > > > > Hi > > > > > > > > > > query level: beginner > > > > > > > > > > as part of a learning exercise i have written code that: > > > > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > > > > entered) > > > > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > > > > c) start again until 2) is True > > > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > > > handlist = [] > > > > > > > > > letter = raw_input('enter letter: ') > > > > > > > > > handlist.append(letter) > > > > > > > > > hand = "".join(handlist) > > > > > > > > > for item in wordlist: > > > > > > > > > ? ? if item.startswith(hand): > > > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > > > > ? ? ? ? ? ? else: break > > > > > > > > > ? ? ? ? else: break > > > > > > > > > print 'you loose' > > > > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > > > > thanks > > > > > > > > > Baba > > > > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > > > > if I use the following word list: > > > > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > > > > enter letter: h > > > > > > > > enter letter: a > > > > > > > > you loose > > > > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > > > > version might be a bit too advanced but you should still be able to do > > > > > > > > it using only one while, one for and one if instead. > > > > > > > > Hi nn, > > > > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > > > > While i was conscious that the whole construct was heavy i thought the > > > > > > > reasoning worked. I keep looking at it but can't figure out the > > > > > > > problem Can you give me a hint? > > > > > > > > In the meantime i found out that it is actually possible to populate a > > > > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > > > > got now: > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > hand = '' > > > > > > > for item in wordlist: > > > > > > > ? ? if item.startswith(hand): > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > > > > ? ? ? ? ? ? ? ? print hand > > > > > > > ? ? ? ? ? ? else: break > > > > > > > ? ? ? ? else: break > > > > > > > print 'you loose' > > > > > > > > But i can't figure out why it won't work when adding the extra word. > > > > > > > Thanks by the way, it taught me not to be too confident when things > > > > > > > SEEM to work... > > > > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > > > > into one... > > > > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > > > > hand = '' > > > > > > > while any(item.startswith(hand) for item in wordlist): > > > > > > > ? ? if hand not in wordlist: > > > > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > > > > ? ? else: break > > > > > > > print 'you loose' > > > > > > > > thanks > > > > > > > > Baba > > > > > > > Hi nn, > > > > > > > looking at my original code again i realise that having a raw_input > > > > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > > > > will just assume that i was taking the wrong approach initially. No > > > > > > point in analysing it further. Thanks for your help. > > > > > > > Baba > > > > > > Since you seem to have figured it out I will post my version (python > > > > > 3): > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > inp='' > > > > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > > > > ? ? inp += input('enter letter: ') > > > > > print('you lose') > > > > > > The reason why your original version didn't work was because each time > > > > > you add a letter you have to go again over all words (in reality only > > > > > a subset is required) and find a new one. Your version would find one > > > > > word using the first letter and then exit. > > > > > Actually my version isn't right (for some values of right): > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > inp='' > > > > while any(word.startswith(inp) for word in wordlist) and (inp not in > > > > wordlist): > > > > ? ? inp += input('enter letter: ') > > > > print('you lose') > > > > > An explanation of how this changes the rules of the wordgame is left > > > > as an exercise to the reader. > > > > Hi, > > > > for now i will stick to Python2.7 but thank you for sharing. > > > > for learning purposes i still want to figure out a way to solve this > > > without built-in function ('any' in this case). My understanding was > > > that in programming almost anything can be done with IF, FOR and WHILE > > > statements. However i turn in circles...:( i understand that in my > > > original code my while loop locked me into the first word hello if the > > > first letter was 'h' and therefore if the next letter was 'a' it would > > > break...so far so good but this appears really tricky to solve...here > > > is what i have come up with but it will not exit if for example i > > > enter 'x' ... > > > > wordlist = ['hello', 'bye'] > > > hand = '' > > > while hand not in wordlist: > > > ? ? hand += raw_input('enter letter: ') > > > ? ? print hand > > > ? ? for item in wordlist: > > > ? ? ? ? if not item.startswith(hand): > > > ? ? ? ? ? ? break > > > print 'you lose' > > > > but no matter how i turn this around i can't find the magic > > > approach...i was thinking about starting the code with something like > > > "while (something) is True" ... would that be a right approach? > > > > Baba > > > This program has 2 problems: > > 1.) the break only exits one level: i.e. the for loop > > 2.) your logic is backwards. You stop checking as soon as you find the > > first mismatch. It should be the other way around: it is invalid only > > after testing with all words and not finding any match. > > > And yes all of this can be done using just using while, for and if. I > > just wrote another version with 1 while, 1 for, 2 ifs, 0 breaks, 0 > > any, 0 genexp. This is like doing algebra: you add 2 here, substract 2 > > there and the same result comes out. There is an infinite number of > > programs that can be written to generate the same output. > > wordlist = ['hello', 'hamburger', 'bye', 'foo'] > hand = '' > check = True > while check == True: > ? ? check = False > ? ? hand += raw_input('enter letter: ') > ? ? for item in wordlist: > ? ? ? ? if item.startswith(hand): > ? ? ? ? ? ? check = True > ? ? ? ? ? ? break > ? ? if hand in wordlist: > ? ? ? ? break > print 'you lose' > > learning objective achieved :) Thanks for your help! > > Baba You are welcome. Just for completeness I post my version too: wordlist = ['hello', 'ham', 'hamburger', 'bye'] hand = '' found_start = not_word = True while found_start and not_word: hand += input('enter letter: ') found_start = not_word = False for word in wordlist: if word.startswith(hand): found_start = True if hand not in wordlist: not_word = True print('you lose') From bkjones at gmail.com Fri Sep 24 10:10:12 2010 From: bkjones at gmail.com (Brian Jones) Date: Fri, 24 Sep 2010 10:10:12 -0400 Subject: upload file using post to https server In-Reply-To: References: Message-ID: I just did this yesterday with the 'poster' module after fumbling around with various other ideas, which in the end just produced a lot of code and didn't get me very far. Poster makes this pretty easy, and if you can't install it to the system python path, use 'setup.py install --user' and it'll put it in your home directory under ~/.local. With poster, it's a breeze. Here's what I've done. Hope it helps: #!/usr/bin/env python import random from poster.encode import multipart_encode from poster.streaminghttp import register_openers import urllib2 import threading import time class Requestor(threading.Thread): def __init__(self, port): threading.Thread.__init__(self) self.port = port def run(self): register_openers() post_param1 = 'cheddar' post_param2 = 'leicester' params, headers = multipart_encode({"pic": open("image.jpg"), "param1": post_param1, "param2": post_param2}) request = urllib2.Request("http://mybox:%s/" % self.port, params, headers) curtime = time.time() response = urllib2.urlopen(request).read() perftime = time.time() - curtime print "Query time: %s\n" % perftime if __name__ == "__main__": for i in range(2000): port = random.choice(range(8885,8905)) t = Requestor(port) t.start() This is a basic threaded performance testing script that sends an image, and two other paramters, all in a POST request to a web server that opens multiple ports. If you don't need the threading, you should be able to rip the 'run()' method out of the class and just run it by itself (save an edit or two -- like hard-coding or otherwise replacing self.port). Good luck! brian On Fri, Sep 24, 2010 at 4:23 AM, Dennis Lee Bieber wrote: > On Thu, 23 Sep 2010 11:10:55 -0700 (PDT), cerr > declaimed the following in gmane.comp.python.general: > > > > values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' } > > > > try: > > data = urllib.urlencode( values ) > > > But the file doesn't seem to get there correctly. What I wanna do, is > > mocking the upload from the html site with my python script.... the > > html looks something like this: > > And are you expecting the server to somehow crawl down the socket > to > your machine to find the file, then suck it up? > > Where do you actually attach the file data to the outgoing response? > > Suggest you reference the RFC that added file upload to HTML: > http://www.faqs.org/rfcs/rfc1867.html > > In particular, section 3.3 > -=-=-=-=-=- > 3.3 use of multipart/form-data > > The definition of multipart/form-data is included in section 7. A > boundary is selected that does not occur in any of the data. (This > selection is sometimes done probabilisticly.) Each field of the form > is sent, in the order in which it occurs in the form, as a part of > the multipart stream. Each part identifies the INPUT name within the > original HTML form. Each part should be labelled with an appropriate > content-type if the media type is known (e.g., inferred from the file > extension or operating system typing information) or as > application/octet-stream. > -=-=-=-=-=- > > You've just supplied the file NAME part of the form, but not the > file data. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Fri Sep 24 10:10:26 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 24 Sep 2010 10:10:26 -0400 Subject: feature request: string.contains('...') In-Reply-To: References: Message-ID: <4C9CB152.2040604@optimum.net> On 9/24/2010 4:21 AM, Peter Otten wrote: > > If you are not interested in the position of the substr use the "in" > operator: > > if substr in s: > print "found" > else: > print "not found" > Another "missing feature" candidate: sublist >>> 'bc' in 'abcde' True >>> list('bc') in list('abcde') False A little Googling indicates that Haskell *does* have this feature: [1] ghci> [2,6] `isInfixOf` [3,1,4,1,5,9,2,6,5,3,5,8,9,7,9] True I haven't located an equivalent Python idiom, though. I took a quick look through numpy, but no luck. Can anyone help? Tx, John [1] http://book.realworldhaskell.org/read/functional-programming.html From gburdell1 at gmail.com Fri Sep 24 10:33:36 2010 From: gburdell1 at gmail.com (gburdell1 at gmail.com) Date: Fri, 24 Sep 2010 07:33:36 -0700 (PDT) Subject: Expanding a vector by replicating elements individually References: Message-ID: <330c1e7d-1340-4090-953f-1068271f3ba7@l17g2000vbf.googlegroups.com> On Sep 22, 1:30?am, Peter Otten <__pete... at web.de> wrote: > > array([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) > > Peter Thanks! From nobody at nowhere.com Fri Sep 24 10:53:46 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 24 Sep 2010 15:53:46 +0100 Subject: Subprocess does not return for longer-running process References: Message-ID: On Fri, 24 Sep 2010 15:18:47 +1200, Lawrence D'Oliveiro wrote: >>>> And I can't think of any reason why you should use os.waitpid() or >>>> similar; use the .wait() method. >>> >>> I have used WNOHANG to poll for completion of a subprocess while >>> providing progress updates to the user. >> >> This can be done via the .poll() method. > > And what do you think the poll method uses? 1. Not relevant; use the defined interface. 2. It currently uses waitpid() on Unix, WaitForSingleObject() on Windows, maybe other functions if subprocess gets ported to other platforms or extended. If you use the .poll() method, you don't need to worry about any of this. More importantly the .poll() method sets the .returncode attribute. Why is this important? Because if the .returncode attribute is None, Popen.__del__ will add the object to the _active list. Not only does this prevent the object from being finalised, it will continue to poll for termination via _cleanup(). But if you have manually reaped the child, its PID becomes available for re-use. This can result in a subsequent _cleanup() reaping some other child process. In the 2.6 implementation, manually setting the .returncode attribute will solve this. In future implementations ... who knows? Again: use the .wait() or .poll() methods. These are portable, can be assumed to do the right thing for subclasses of subprocess.Popen(), and will perform any necessary maintenance of "internal" state. If those methods don't suffice, you can't reliably use subprocess. E.g. if you need to wait until any child terminates, using os.wait() will cause the child to be reaped, which will confuse Popen(). POSIX (and Linux since 2.6.9) has waitid(), which allows you to wait for a child *without* reaping it (via the WNOWAIT flag), but Python doesn't include an interface for this. From geoff.bache at gmail.com Fri Sep 24 11:03:20 2010 From: geoff.bache at gmail.com (Geoff Bache) Date: Fri, 24 Sep 2010 08:03:20 -0700 (PDT) Subject: inspect.getmodulename giving unexpected results References: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> Message-ID: > > Unfortunately, it doesn't seem to do that in some cases. Consider the > > following code: > > It does behave as documented: it does not find package names, or investigate > sys.modules Possibly, although for me "logging" is exposed as a module, and ought to behave as one when requesting the module name. The fact that it's a package internally doesn't seem relevant to me in this context. It's weird to me that when I do import os, logging treating these things as normal modules I can get the right name for "os" but get "__init__" when requesting "logging". Externally, these things appear to be the same. I can accept from the docs that if I did "getmodulename" on "logging.config" I would get "config" back. > > > ## file 'inspect_test' > > rename this file to "inspect_test.py", and the filename will make sense to > inspect.getmodulename, which should *then* return "inspect_test" instead of > None. I realise that, but of course I can't do that in the real code. It's a long-established convention to drop the ".py" from executable programs on UNIX. Regards, Geoff From thomas at jollybox.de Fri Sep 24 11:29:43 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 24 Sep 2010 17:29:43 +0200 Subject: inspect.getmodulename giving unexpected results In-Reply-To: References: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> Message-ID: <201009241729.43312.thomas@jollybox.de> On Friday 24 September 2010, it occurred to Geoff Bache to exclaim: > > > Unfortunately, it doesn't seem to do that in some cases. Consider the > > > > > following code: > > It does behave as documented: it does not find package names, or > > investigate sys.modules > > Possibly, although for me "logging" is exposed as a module, and ought > to behave as one when requesting the module name. The fact that it's a > package internally doesn't seem relevant to me in this context. It's > weird to me that when I do > > import os, logging > > treating these things as normal modules I can get the right name for > "os" but get "__init__" when requesting "logging". Externally, these > things appear to be the same. I can accept from the docs that if I did > "getmodulename" on "logging.config" I would get "config" back. > > > > ## file 'inspect_test' > > > > rename this file to "inspect_test.py", and the filename will make sense > > to inspect.getmodulename, which should *then* return "inspect_test" > > instead of None. > > I realise that, but of course I can't do that in the real code. It's a > long-established convention to drop the ".py" from executable programs > on UNIX. Then again, it's a classic trick to put your Python code in ../site-packages/ (or the like) and just put a tiny stub script in bin/ for projects of the same kind of dimensions where anybody would care about the executable having a file extension or not ;-) From nobody at nowhere.com Fri Sep 24 11:51:01 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 24 Sep 2010 16:51:01 +0100 Subject: Raw Sockets - IP-Encapsulation References: Message-ID: On Thu, 23 Sep 2010 21:41:19 +0200, Matthias Guentert wrote: > I would like to create an IP tunnel using the IP protocol type 4 > (socket.IPPROTO_IPIP) on a Linux host. (I also would be happy if I > could create a GRE tunnel) > > The thing is, I just don't understand how I such a socket could be > created and then later on handled. You don't create sockets for IPPROTO_IPIP or IPPROTO_GRE. Outside of the kernel, those identifiers are only likely to be used for specifying protocols when e.g. configuring packet filtering. Tunnelling only involves user-space for configuration. Once a tunnel has been configured, it's just a networking interface, and any traffic is handled by the kernel. Tunnel interfaces are manipulated using the ioctl()s in linux/if_tunnel.h. Refer to the iproute2 source code for clues. If for some reason you wanted perform the encapsulation or decapsulation yourself, you would need to create a packet socket. From thomas at jollybox.de Fri Sep 24 13:25:08 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 24 Sep 2010 19:25:08 +0200 Subject: Python 2.6: How to turn off cgitb.py's DeprecationWarning: BaseException.message has been deprecated In-Reply-To: <1285288265.4428.1396613849@webmail.messagingengine.com> References: <1285288265.4428.1396613849@webmail.messagingengine.com> Message-ID: <201009241925.09168.thomas@jollybox.de> On Friday 24 September 2010, it occurred to python at bdurham.com to exclaim: > Python 2.6: We're using the standard lib's cgitb module to > provide diagnostic messages when unexpected exceptions occur. > > Unfortunately, this module raises a DeprecationWarning like below > when it is used: > > C:\Python26\lib\cgitb.py:245: DeprecationWarning: > BaseException.message has been > deprecated as of Python 2.6 > value = pydoc.text.repr(getattr(evalue, name)) > > Is there some way to disable this specific warning message (our > customers find it disconcerting) or do we have to go in and edit > the cgitb.py module itself? Also, wondering if this warning has > been addressed in Python 2.7/3.x? Yes. Filtering is an important part of the Python warnings framework: http://docs.python.org/library/warnings.html#warnings.filterwarnings http://www.python.org/dev/peps/pep-0230/ From thomas at jollybox.de Fri Sep 24 13:28:45 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 24 Sep 2010 19:28:45 +0200 Subject: SocketServer: replace network by hard drive In-Reply-To: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: <201009241928.45441.thomas@jollybox.de> On Friday 24 September 2010, it occurred to antoine to exclaim: > Hello, > > I would like to create a python server for which the requests are > passed by files on the hard drive instead of a network. > I am currently looking at the SocketServer python module, hoping for > an easy modification. > > Is it doable at all? > If yes, how should it be done? If you're using UNIX, and you don't actually need the stream to be passed via the hard drive (why would you?), but for some reason want to use the file system, look info UNIX/local sockets. But, really, I'm guessing that local TCP sockets (our old friend 127.0.0.1/8) will work just as well for whatever you're doing (though I may be mistaken), are portable to non-UNIX system, and won't be any slower than UNIX domain sockets on most, if not all, systems. From ethan at stoneleaf.us Fri Sep 24 14:01:27 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 24 Sep 2010 11:01:27 -0700 Subject: feature request: string.contains('...') In-Reply-To: <4C9CB152.2040604@optimum.net> References: <4C9CB152.2040604@optimum.net> Message-ID: <4C9CE777.5030200@stoneleaf.us> John Posner wrote: > Another "missing feature" candidate: sublist > > >>> 'bc' in 'abcde' > True > >>> list('bc') in list('abcde') > False I'm not aware of any idioms, but how about a simple function? def listinlist(list1, list2): "checks if list1 is in list2" if not list1: return True if not list2: return False length = len(list1) pos = 0 while True: try: pos = list2.index(list1[0], pos) except ValueError: return False if list2[pos:pos+length] == list1: return True pos += 1 ~Ethan~ From python.list at tim.thechases.com Fri Sep 24 14:45:26 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 24 Sep 2010 13:45:26 -0500 Subject: feature request: string.contains('...') In-Reply-To: <4C9CE777.5030200@stoneleaf.us> References: <4C9CB152.2040604@optimum.net> <4C9CE777.5030200@stoneleaf.us> Message-ID: <4C9CF1C6.30707@tim.thechases.com> On 09/24/10 13:01, Ethan Furman wrote: > John Posner wrote: >> Another "missing feature" candidate: sublist >> >> >>> 'bc' in 'abcde' >> True >> >>> list('bc') in list('abcde') >> False > > I'm not aware of any idioms, but how about a simple function? > > def listinlist(list1, list2): > "checks if list1 is in list2" > if not list1: > return True > if not list2: > return False > length = len(list1) > pos = 0 > while True: > try: > pos = list2.index(list1[0], pos) > except ValueError: > return False > if list2[pos:pos+length] == list1: > return True > pos += 1 Which I suppose could be rewritten something like def listinlist(l1, l2): len1 = len(l1) offsets_to_consider = 1 + len(l2) - len1 return any( l1 == l2[i:i+len1] for i in xrange(offsets_to_consider) ) Foldable into a one-line version if one's sick enough to use it: list_in_list = lambda l1, l2: any(l1 == l2[i:i+len(l1)] for i in range(1 + len(l2) - len(l1))) -tkc From nagle at animats.com Fri Sep 24 15:22:09 2010 From: nagle at animats.com (John Nagle) Date: Fri, 24 Sep 2010 12:22:09 -0700 Subject: SocketServer: replace network by hard drive In-Reply-To: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: <4c9cfa71$0$1648$742ec2ed@news.sonic.net> On 9/24/2010 12:53 AM, antoine wrote: > Hello, > > I would like to create a python server for which the requests are > passed by files on the hard drive instead of a network. > I am currently looking at the SocketServer python module, hoping for > an easy modification. > > Is it doable at all? > If yes, how should it be done? > > Thanks, > Antoine. Yes, it can be done. But why? ICVERIFY, the first web-based credit card processing system, worked that way. Remember web sites which put up messages like "Wait up to 3 minutes for your credit card transaction to be processed. DO NOT REFRESH THIS PAGE". That's ICverify. The ICVERIFY concept was that the client-facing side created files in an input directory, then waited for response files to appear. The back end drove a farm of dial-up modems, each emulating a 1200 baud credit card terminal. Each back-end process looked for incoming work files, marked them as in use, dialed up the credit card processing system, did the transaction, and wrote a response file. All the process coordination was through files. That was 1995 technology, before the banking system had direct Internet connections. John Nagle From dsrtegle at gmail.com Fri Sep 24 16:59:36 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Fri, 24 Sep 2010 13:59:36 -0700 (PDT) Subject: Pyflakes and IPython does not work for Emacs on Windows? Message-ID: Hi, With Python on Windows, I tried to use Emacs as the programming environment. For syntax checking I installed pyflakes, but flymake always reports "fail to launch. No such file or directory: pyflakes" when opening a Python file. Is pyflakes not for Windows? What Python syntax checking tools work for Emacs on Windows? I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el only works for Linux? Thanks for your comments From benjamin.kaplan at case.edu Fri Sep 24 17:26:29 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 24 Sep 2010 17:26:29 -0400 Subject: Pyflakes and IPython does not work for Emacs on Windows? In-Reply-To: References: Message-ID: On Friday, September 24, 2010, Dsrt Egle wrote: > Hi, > > With Python on Windows, I tried to use Emacs as the programming > environment. For syntax checking I installed pyflakes, but flymake > always reports "fail to launch. No such file or directory: pyflakes" > when opening a Python file. Is pyflakes not for Windows? What Python > syntax checking tools work for Emacs on Windows? > > I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el > only works for Linux? > I don't use emacs but my guess would be that this is a path issue. In Linux, most executables, like ipython, are put into /usr/bin or /usr/local/bin. Both ipod those locations are on the shell's path-the places it look s when you don't specify the full path of a program. On Windows, user-installed programs don't typically get put on the path. Check the path to make sure the directory is on there. It's probably a similar issue with pyflakes- you didn't put the file in the place where flatmate looks for it. > Thanks for your comments > -- > http://mail.python.org/mailman/listinfo/python-list > From jjposner at optimum.net Fri Sep 24 17:31:16 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 24 Sep 2010 17:31:16 -0400 Subject: feature request: string.contains('...') In-Reply-To: References: <4C9CB152.2040604@optimum.net> <4C9CE777.5030200@stoneleaf.us> Message-ID: <4C9D18A4.1070609@optimum.net> On 9/24/2010 2:45 PM, Tim Chase wrote: > On 09/24/10 13:01, Ethan Furman wrote: >> John Posner wrote: >>> Another "missing feature" candidate: sublist >>> >>> >>> 'bc' in 'abcde' >>> True >>> >>> list('bc') in list('abcde') >>> False >> >> I'm not aware of any idioms, but how about a simple function? > > Foldable into a one-line version if one's sick enough to use it: Looking at this a bit more, I can see why the *in* operator applies to strings, but not to lists. Consider the ambiguity in this "heterogeneous" list: mylist = [0, 1, 2, 3, [a, b], 10, 11, 12, a, b, 13] Should the expression *[a, b] in mylist* get a hit at offset 4, or at slice [8:10]? If you know that your lists will be homogeneous ("scalar" values only), or if you're willing to program around the potential ambiguity, then Ethan's function can easily be adapted into a __contains__() method of a *list* subclass. Tx, John From aonlazio at gmail.com Fri Sep 24 18:45:43 2010 From: aonlazio at gmail.com (AON LAZIO) Date: Fri, 24 Sep 2010 18:45:43 -0400 Subject: Regular Expression match Message-ID: Hi, Say I have p = re.compile('a|b') text = 'a' d = p.findall(text) #d -> ['a'] What is the way to find out which pattern p match (the former or latter)? I mean without knowing the outcome of p.findall Thanks -- Aonlazio 'Peace is always the way.' NW -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Fri Sep 24 19:00:01 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 25 Sep 2010 09:00:01 +1000 Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> <4c97f629$0$28658$c3e8da3@news.astraweb.com> Message-ID: <87bp7m4uj2.fsf@benfinney.id.au> Chris Withers writes: > On 21/09/2010 01:02, Steven D'Aprano wrote: > > What do you mean "the filesystem"? > > > > If I look at the available devices on my system now, I see: > > > > 2 x FAT-32 filesystems > > 1 x ext2 filesystem > > 3 x ext3 filesystems > > 1 x NTFS filesystem > > 1 x UDF filesystem > > Right, and each of these will know what it thinks a file's "real" name > is, along with potentially accepting as set of synonyms for them... They will know internally, but Python has no way of asking them AFAICT, short of creating a file on the filesystem. That's far outside the bailiwick of the function in question. > > Which one is "the" filesystem? > > Whichever one you're getting the file from... Who said anything about ?getting the file?? The parameter to the function is a path, which need not already exist, and which need not refer to *any* extant filesystem. > > If you are suggesting that os.path.normcase(filename) should > > determine which filesystem actually applies to filename at runtime, > > and hence work out what rules apply, what do you suggest should > > happen if the given path doesn't actually exist? > > I'd suggest an exception be raised. You really must have an entirely different function in mind. I suggest you look for it by another name, because ?os.path.normcase? already does something entirely different. > I didn't say it was an easy problem, but the current normpath is a > waste of space... This seems to be code for ?it doesn't do what I expected, and now I don't want to use it?. Surely the solution is clear: don't use it. -- \ ?The industrial system is profoundly dependent on commercial | `\ television and could not exist in its present form without it.? | _o__) ?John Kenneth Galbraith, _The New Industrial State_, 1967 | Ben Finney From drobinow at gmail.com Fri Sep 24 19:53:09 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 24 Sep 2010 19:53:09 -0400 Subject: Pyflakes and IPython does not work for Emacs on Windows? In-Reply-To: References: Message-ID: On Fri, Sep 24, 2010 at 4:59 PM, Dsrt Egle wrote: > ... > I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el > only works for Linux? There don't appear to be a lot of ipython.el users on Windows. You may have better look on an emacs list since there appear to be some configuration issues. Does https://bugs.launchpad.net/ipython/+bug/290228 help at all? From vlastimil.brom at gmail.com Fri Sep 24 19:53:12 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 25 Sep 2010 01:53:12 +0200 Subject: Regular Expression match In-Reply-To: References: Message-ID: 2010/9/25 AON LAZIO : > Hi, > ?? Say I have > ?? p???? = re.compile('a|b') > ?? text = 'a' > ?? d???? = p.findall(text) > ?? #d -> ['a'] > ?? What is the way to find out which pattern p match (the former or latter)? > I mean without knowing the outcome of p.findall > ?? Thanks > > -- > Aonlazio > 'Peace is always the way.' NW > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, I am not sure, I understand the task completely, but maybe named subpatterns and the groupdict data for the match objects may help? for m in re.finditer(r"(?PA)|(?PB)", "QABCZ"): print m.group(), m.groupdict() A {'patternB': None, 'patternA': 'A'} B {'patternB': 'B', 'patternA': None} regards, vbr From dsrtegle at gmail.com Fri Sep 24 19:54:07 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Fri, 24 Sep 2010 16:54:07 -0700 (PDT) Subject: Pyflakes and IPython does not work for Emacs on Windows? References: Message-ID: On Sep 24, 2:26?pm, Benjamin Kaplan wrote: > On Friday, September 24, 2010, Dsrt Egle wrote: > > Hi, > > > With Python on Windows, I tried to use Emacs as the programming > > environment. For syntax checking I installed pyflakes, but flymake > > always reports "fail to launch. No such file or directory: pyflakes" > > when opening a Python file. Is pyflakes not for Windows? What Python > > syntax checking tools work for Emacs on Windows? > > > I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el > > only works for Linux? > > I don't use emacs but my guess would be that this is a path issue. In > Linux, most executables, like ipython, are put into /usr/bin or > /usr/local/bin. Both ipod those locations are on the shell's path-the > places it look s when you don't specify the full path of a program. On > Windows, user-installed programs don't typically get put on the path. > Check the path to make sure the directory is on there. It's probably a > similar issue with pyflakes- you didn't put the file in the place > where flatmate looks for it. > > > Thanks for your comments > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Thanks for your reply, Ben. Actually I have the paths "C:\Python25;C: \Python25\Scripts" in the %PATH% variable, and the %PYTHONPATH% has the following: C:\Python25\Lib\site-packages\pyflakes;C:\Python25\Lib\site-packages \Pymacs;C:\Python25\Lib\site-packages\rope;C:\Python25\Lib\site- packages\ropemacs;C:\Python25\Lib\site-packages\ropemode Pymacs, rope, ropemacs, ropemode all work in Emacs, except pyflakes. Looking at the file C:\Python25\Lib\site-packages\pyflakes-0.4.0- py2.5.egg\EGG-INFO\scripts\pyflakes, it shows #!C:\Python25\python.exe from pyflakes.scripts.pyflakes import main main() So this script needs to trigger Python interpreter to run. I can successfully run pyflakes by manually triggering Python like this: C:\>python C:\Python25\Lib\site-packages\pyflakes-0.4.0-py2.5.egg\EGG- INFO\scripts\pyflakes test_new_lib.py test_new_lib.py:13: invalid syntax sa.CoreObj. So pyflakes is running correctly. But it seems Emacs treats pyflakes as an executable program instead of Python script. I include the following in my .emacs file for pyflakes: ;;===== PyFlakes ;; code checking via pyflakes+flymake (when (load "flymake" t) (defun flymake-pyflakes-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "pyflakes" (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pyflakes-init))) (add-hook 'find-file-hook 'flymake-find-file-hook) What should I do to configure Emacs to make pyflakes working? Thank you! From nn.roh1 at gmail.com Sat Sep 25 01:18:26 2010 From: nn.roh1 at gmail.com (n.a.s) Date: Sat, 25 Sep 2010 08:18:26 +0300 Subject: problem in Gasp ! In-Reply-To: References: Message-ID: Hi, I want to ask about graphics using Gasp .Attached is exercise 10 (houses at night) ,if i call the draw_house function once it will work properly ,but more than one call,windows and doors disappear from some houses . Any one can advice? Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: house.pyw Type: application/octet-stream Size: 1398 bytes Desc: not available URL: From brenNOSPAMbarn at NObrenSPAMbarn.net Sat Sep 25 01:58:24 2010 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 25 Sep 2010 05:58:24 +0000 (UTC) Subject: Playing sounds at time indexes References: Message-ID: Thomas Jollans wrote: > On Wednesday 22 September 2010, it occurred to OKB (not okblacke) > to exclaim: >> I'm looking for an audio library for Python. I googled >> and found a >> few, but none of them seem to have a simple way to play a >> particular sound file from a particular start-time to an end-time. >> Like, I'd want to load a file and say "Play the section of this >> file from 10.25 seconds to 11.73 seconds." Is there a library >> that makes this easy in Python? > > platform? Windows XP. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From deluxstar at gmail.com Sat Sep 25 03:53:13 2010 From: deluxstar at gmail.com (deluxstar) Date: Sat, 25 Sep 2010 00:53:13 -0700 (PDT) Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> Message-ID: <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> On 24 Eyl?l, 12:39, Peter Otten <__pete... at web.de> wrote: > deluxstar wrote: > > We have an application working on several servers generally written > > with Python 2.6 and Twisted 10. > > The source codes are located in one server and compiled in this > > server. The compiled files are copied to other server via network and > > application server works with these compiled files. > > > In this application, I have to write a function to return a value of > > the caller object that calles this function. The function may be > > called from several modules of the application. To achieve this goal, > > I try to use the python inspect module: > > > curframe = inspect.currentframe() > > calframe = inspect.getouterframes(curframe, 2) > > calframe[1][0].f_locals['variable'] > > > This sample code works on local development environment both on linux > > and windows. When checked in to production environment, > > inspect.currentframe() or inspect.stack() function gives "List index > > out of range error". > > > When I googled, I found only one clue of copying pyc files: > >http://forum.webfaction.com/viewtopic.php?pid=16808 > > > Why inspect modules gives this error? OR Is there another way to get > > the caller objects variable value? > > Can you provide the actual traceback? Provide a small script that reproduces > the error? Add print statements and post their output? > > print inspect.currentframe> curframe = inspect.currentframe() > print curframe > > calframe = inspect.getouterframes(curframe, 2) > > print calframe > > Peter The traceback is: 2010-09-25 10:50:38+0300 [-] Traceback (most recent call last): 2010-09-25 10:50:38+0300 [-] File "../appsrv/lqcommon.py", line 983, in getPRMS 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", line 931, in getouterframes 2010-09-25 10:50:38+0300 [-] framelist.append((frame,) + getframeinfo(frame, context)) 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", line 906, in getframeinfo 2010-09-25 10:50:38+0300 [-] lines, lnum = findsource(frame) 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", line 568, in findsource 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range It is hard to reproduce the error with a script. I will work and send if I success. If the traceback tells smth, please tell me :) Thnx From lanyjie at yahoo.com Sat Sep 25 04:22:04 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 01:22:04 -0700 (PDT) Subject: sequence multiplied by -1 Message-ID: <299735.67644.qm@web54205.mail.re2.yahoo.com> Hi, I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics. Simply put, a sequence multiplied by -1 can give a reversed sequence. Then for any sequence "seq", and integer n>0, we can have "seq * -n" producing "(seq * -1) * n". Any thoughts? Yingjie From steve at REMOVE-THIS-cybersource.com.au Sat Sep 25 04:25:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Sep 2010 08:25:51 GMT Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> Message-ID: <4c9db20f$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 00:53:13 -0700, deluxstar wrote: > The traceback is: > 2010-09-25 10:50:38+0300 [-] Traceback (most recent call last): > 2010-09-25 10:50:38+0300 [-] File "../appsrv/lqcommon.py", line 983, > in getPRMS > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 931, in getouterframes > 2010-09-25 10:50:38+0300 [-] framelist.append((frame,) + > getframeinfo(frame, context)) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 906, in getframeinfo > 2010-09-25 10:50:38+0300 [-] lines, lnum = findsource(frame) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 568, in findsource > 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break > 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range I'm going to take a wild guess here. My guess is that you've copied the .pyc file onto the server, BUT there is also an *older* version of the .py file there as well. Because the modification date is older than that of the .pyc file, Python executes the compiled code from the .pyc file. But when you search for the source code, the old .py file is discovered -- but it doesn't have the right number of lines, and so you end up with an IndexError. -- Steven From wolfgang at rohdewald.de Sat Sep 25 07:28:33 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Sat, 25 Sep 2010 13:28:33 +0200 Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" In-Reply-To: <4c9db20f$0$28659$c3e8da3@news.astraweb.com> References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> <4c9db20f$0$28659$c3e8da3@news.astraweb.com> Message-ID: <201009251328.33937.wolfgang@rohdewald.de> On Samstag 25 September 2010, Steven D'Aprano wrote: > My guess is that you've copied the .pyc file onto the server, > BUT there is also an older version of the .py file there as > well. Because the modification date is older than that of the > .pyc file, Python executes the compiled code from the .pyc > file. that would be horrible - this is what our own legacy software does. A maintenance nightmare. Think adjusting system time or "cp -a spam.py" Actually the docs say something different: The modification time of the version of spam.py used to create spam.pyc is recorded in spam.pyc, and the .pyc file is ignored if these don?t match. found here: http://docs.python.org/tutorial/modules.html -- Wolfgang From thomas at jollybox.de Sat Sep 25 07:35:09 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 25 Sep 2010 13:35:09 +0200 Subject: Pyflakes and IPython does not work for Emacs on Windows? In-Reply-To: References: Message-ID: <201009251335.10365.thomas@jollybox.de> On Saturday 25 September 2010, it occurred to Dsrt Egle to exclaim: > Thanks for your reply, Ben. Actually I have the paths "C:\Python25;C: > \Python25\Scripts" in the %PATH% variable, and the %PYTHONPATH% has > the following: > > [...] > > Looking at the file C:\Python25\Lib\site-packages\pyflakes-0.4.0- > py2.5.egg\EGG-INFO\scripts\pyflakes, it shows > C:\Python25\Lib\site-packages\pyflakes-0.4.0-py2.5.egg\EGG-INFO\scripts\ doesn't appear to be on your PATH then? Also, the file "pyflakes" won't be executable without a file extension on Windows. I suggest you try either creating a pyflakes.bat file somewhere on your PATH, or using the pyflakes script as pyflakes.py, locates somewhere on the PATH (will this work? I'm not sure) > > #!C:\Python25\python.exe > > from pyflakes.scripts.pyflakes import main > main() > > > So this script needs to trigger Python interpreter to run. I can > successfully run pyflakes by manually triggering Python like this: > > C:\>python C:\Python25\Lib\site-packages\pyflakes-0.4.0-py2.5.egg\EGG- > INFO\scripts\pyflakes test_new_lib.py > test_new_lib.py:13: invalid syntax > sa.CoreObj. > > > > So pyflakes is running correctly. But it seems Emacs treats pyflakes > as an executable program instead of Python script. I include the > following in my .emacs file for pyflakes: > > > > ;;===== PyFlakes > ;; code checking via pyflakes+flymake > > (when (load "flymake" t) > (defun flymake-pyflakes-init () > (let* ((temp-file (flymake-init-create-temp-buffer-copy > 'flymake-create-temp-inplace)) > (local-file (file-relative-name > temp-file > (file-name-directory buffer-file-name)))) > (list "pyflakes" (list local-file)))) > > (add-to-list 'flymake-allowed-file-name-masks > '("\\.py\\'" flymake-pyflakes-init))) > > (add-hook 'find-file-hook 'flymake-find-file-hook) > > > > What should I do to configure Emacs to make pyflakes working? Thank > you! From thomas at jollybox.de Sat Sep 25 07:45:11 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 25 Sep 2010 13:45:11 +0200 Subject: sequence multiplied by -1 In-Reply-To: <299735.67644.qm@web54205.mail.re2.yahoo.com> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: <201009251345.11944.thomas@jollybox.de> On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: > Hi, > > I noticed that in python3k, multiplying a sequence by a negative integer is > the same as multiplying it by 0, and the result is an empty sequence. It > seems to me that there is a more meaningful symantics. Um... for every list l and integer n >= 0: len(l*n) == len(l)*n Multiplying a list by a negative integer should produce a list of negative length, which does not exist. IMHO, the only correct behaviour would be to raise an exception, though one could argue that there are practical benefits for the operation to succeed for any integer operand. > > Simply put, a sequence multiplied by -1 can give a reversed sequence. For that, we have slicing. A negative step value produces a reverse slice of the list. You can't argue that this makes sense, can you >>> [1,2,3,4][::-1] [4, 3, 2, 1] >>> [1,2,3,4][::-2] [4, 2] >>> From lanyjie at yahoo.com Sat Sep 25 08:11:39 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 05:11:39 -0700 (PDT) Subject: sequence multiplied by -1 In-Reply-To: <201009251345.11944.thomas@jollybox.de> Message-ID: <494697.63610.qm@web54206.mail.re2.yahoo.com> --- On Sat, 9/25/10, Thomas Jollans wrote: > for every list l and integer n >= 0: > ? ? len(l*n) == len(l)*n Well, this invariance is indeed broken under my proposal. But it is *already broken* in current python3k. However, the following invariance is maintained under my proposal: len(l*n) == len(l) * abs(n), which is also broken under current python3k. if you think len(..) as a mathematical norm, the above invariance makes perfect sense: || a * b || == ||a|| * |b|, b is real > > > Simply put, a sequence multiplied by -1 can give a > reversed sequence. > > For that, we have slicing. A negative step value produces a > reverse slice of > the list. You can't argue that this makes sense, can you > > >>> [1,2,3,4][::-1] > [4, 3, 2, 1] > >>> [1,2,3,4][::-2] > [4, 2] > >>> Having more than one way of doing things sometimes is good. Slicing is a little more complex, what if you want this: >>> ([1,2,3,4]*2)[::-1] [4, 3, 2, 1, 4, 3, 2, 1] under my new proposal, you simply do this: >>> [1,2,3,4]*-2 [4, 3, 2, 1, 4, 3, 2, 1] Cheers, Yingjie From nobody at nowhere.com Sat Sep 25 08:37:55 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 25 Sep 2010 13:37:55 +0100 Subject: SocketServer: replace network by hard drive References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: On Fri, 24 Sep 2010 19:28:45 +0200, Thomas Jollans wrote: > If you're using UNIX, and you don't actually need the stream to be > passed via the hard drive (why would you?), but for some reason want to > use the file system, look info UNIX/local sockets. But, really, I'm > guessing that local TCP sockets (our old friend 127.0.0.1/8) will work > just as well for whatever you're doing (though I may be mistaken), are > portable to non-UNIX system, and won't be any slower than UNIX domain > sockets on most, if not all, systems. The problem with using the loopback interface is that it's still "network access", which can run into all kinds of issues with security policies, firewalls, etc. From thomas at jollybox.de Sat Sep 25 08:45:29 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 25 Sep 2010 14:45:29 +0200 Subject: SocketServer: replace network by hard drive In-Reply-To: References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: <201009251445.29780.thomas@jollybox.de> On Saturday 25 September 2010, it occurred to Nobody to exclaim: > On Fri, 24 Sep 2010 19:28:45 +0200, Thomas Jollans wrote: > > If you're using UNIX, and you don't actually need the stream to be > > passed via the hard drive (why would you?), but for some reason want to > > use the file system, look info UNIX/local sockets. But, really, I'm > > guessing that local TCP sockets (our old friend 127.0.0.1/8) will work > > just as well for whatever you're doing (though I may be mistaken), are > > portable to non-UNIX system, and won't be any slower than UNIX domain > > sockets on most, if not all, systems. > > The problem with using the loopback interface is that it's still > "network access", which can run into all kinds of issues with security > policies, firewalls, etc. What kind of crappy firewall blocks loopback traffic? Really? From sschwarzer at sschwarzer.net Sat Sep 25 09:19:27 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 25 Sep 2010 15:19:27 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: Message-ID: <4C9DF6DF.6040409@sschwarzer.net> Hi, On 2010-09-25 14:11, Yingjie Lan wrote: > Having more than one way of doing things sometimes is good. In my opinion this _isn't_ a situation where it's good. :) L[::-1] is only marginally longer than -1 * L I think this small gain doesn't justify "violating" this "Python Zen" rule (from `import this`): There should be one-- and preferably only one --obvious way to do it. One could argue that using L[::-1] isn't "obvious" but I believe the rule refers to being obvious to people who have used Python for a while. Besides that, multiplying a list with a negative value to give a reverse list isn't so intuitive either. :-) On 2010-09-25 13:45, Thomas Jollans wrote: > Multiplying a list by a negative integer should produce a list of negative > length, which does not exist. IMHO, the only correct behaviour would be to > raise an exception, though one could argue that there are practical benefits > for the operation to succeed for any integer operand. I agree with raising an exception, probably a ValueError. Stefan From lanyjie at yahoo.com Sat Sep 25 09:54:36 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 06:54:36 -0700 (PDT) Subject: sequence multiplied by -1 In-Reply-To: <4C9DF6DF.6040409@sschwarzer.net> Message-ID: <464007.12232.qm@web54201.mail.re2.yahoo.com> Hi, > > In my opinion this _isn't_ a situation where it's good. :) > > ? ? L[::-1] > > is only marginally longer than > > ? ? -1 * L > > I think this small gain doesn't justify "violating" this > "Python Zen" rule (from `import this`): > > ? ? There should be one-- and preferably only one > --obvious way to do it. > Thanks for the insightful remarks. For the rule above, how about the case to reverse and multiply: >>> L*-3 #L reversed and repeated three times v.s. >>> L[::-1]*3 #L reversed and repeated three times The first one is simpler (4 chars v.s. 9 chars). I thought it was also intuitive because if you multiply a vector by -1, you should get a vector in the reversed direction. But, intuitiveness depends on who you are, what you do, etc.... Regards, Yingjie From lanyjie at yahoo.com Sat Sep 25 09:59:47 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 06:59:47 -0700 (PDT) Subject: solve alphametic puzzles in just 9 lines of code Message-ID: <164829.96277.qm@web54204.mail.re2.yahoo.com> Hi, I am teaching Python this semester and as I am trying to explain the code by Raymond Hettinger, I need to make it simpler (this is an introductory course). And it ends up to be just 9 lines of code. Just for fun. See also: http://diveintopython3.org/advanced-iterators.html Regards, Yingjie ############Code starts here########### import itertools def solve(puzzle): "solve alphametic puzzles in just 9 lines of code." words = [w for w in puzzle.split() if w.isalpha()] nonzeros = {w[0] for w in words} others = {a for a in ''.join(words) if a not in nonzeros} chars = [ord(c) for c in nonzeros]+[ord(c) for c in others] assert len(chars) <= 10, 'Too many letters' for guess in itertools.permutations('0123456789', len(chars)): if '0' not in guess[:len(nonzeros)]: equation = puzzle.translate(dict(zip(chars, guess))) if eval(equation): return equation From sschwarzer at sschwarzer.net Sat Sep 25 11:11:29 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 25 Sep 2010 17:11:29 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: Message-ID: <4C9E1121.2000201@sschwarzer.net> Hi, On 2010-09-25 15:54, Yingjie Lan wrote: > The first one is simpler (4 chars v.s. 9 chars). One thing is whether a certain form is shorter, another thing to take into account is how often you need the functionality. > I thought it was also intuitive because if you multiply > a vector by -1, you should get a vector > in the reversed direction. But, intuitiveness depends > on who you are, what you do, etc.... Sure ... in math, multiplying a vector by -1 gives a vector with all its elements negated: -1 * [1, 2, 3] -> [-1, -2, -3] :-) Stefan From mwilson at the-wire.com Sat Sep 25 12:28:38 2010 From: mwilson at the-wire.com (Mel) Date: Sat, 25 Sep 2010 12:28:38 -0400 Subject: sequence multiplied by -1 References: <4C9E1121.2000201@sschwarzer.net> Message-ID: Stefan Schwarzer wrote: > On 2010-09-25 15:54, Yingjie Lan wrote: >> The first one is simpler (4 chars v.s. 9 chars). >> I thought it was also intuitive because if you multiply >> a vector by -1, you should get a vector >> in the reversed direction. But, intuitiveness depends >> on who you are, what you do, etc.... > > Sure ... in math, multiplying a vector by -1 gives a vector > with all its elements negated: > > -1 * [1, 2, 3] -> [-1, -2, -3] > > :-) And math applies associativity v * (3 - 1) == v * 3 + v * -1 Mel. From tjreedy at udel.edu Sat Sep 25 13:12:07 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Sep 2010 13:12:07 -0400 Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" In-Reply-To: <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> Message-ID: On 9/25/2010 3:53 AM, deluxstar wrote: > The traceback is: > 2010-09-25 10:50:38+0300 [-] Traceback (most recent call last): > 2010-09-25 10:50:38+0300 [-] File "../appsrv/lqcommon.py", line 983, > in getPRMS > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 931, in getouterframes > 2010-09-25 10:50:38+0300 [-] framelist.append((frame,) + > getframeinfo(frame, context)) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 906, in getframeinfo > 2010-09-25 10:50:38+0300 [-] lines, lnum = findsource(frame) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 568, in findsource > 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break > 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range > > It is hard to reproduce the error with a script. I will work and send > if I success. > If the traceback tells smth, please tell me :) The traceback is terribly difficult to read with the timestamps added. They are not from Python. In the future, please try to suppress them or use a global search/replace (with nothing) before posting such. -- Terry Jan Reedy From tjreedy at udel.edu Sat Sep 25 13:24:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Sep 2010 13:24:17 -0400 Subject: sequence multiplied by -1 In-Reply-To: <299735.67644.qm@web54205.mail.re2.yahoo.com> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: On 9/25/2010 4:22 AM, Yingjie Lan wrote: > Hi, > > I noticed that in python3k, multiplying a sequence by a negative > integer is the same as multiplying it by 0, and the result is an > empty sequence. This is explicitly documented: "Values of n less than 0 are treated as 0 (which yields an empty sequence of the same type as s).) I would have made this raise a ValueError, but someone must have had a use case for getting an empty sequence. > It seems to me that there is a more meaningful symantics. > Simply put, a sequence multiplied by -1 can give a reversed > sequence. There is already a builtin reversed() function whose output can be multiplied. -- Terry Jan Reedy From emile at fenx.com Sat Sep 25 13:57:35 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 25 Sep 2010 10:57:35 -0700 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: On 9/25/2010 10:24 AM Terry Reedy said... > On 9/25/2010 4:22 AM, Yingjie Lan wrote: >> I noticed that in python3k, multiplying a sequence by a negative >> integer is the same as multiplying it by 0, and the result is an >> empty sequence. > > This is explicitly documented: "Values of n less than 0 are treated as 0 > (which yields an empty sequence of the same type as s).) I would have > made this raise a ValueError, but someone must have had a use case for > getting an empty sequence. At least it's consistent with slicing not generating a ValueError ala ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> ham = range(10) >>> ham[11:21] [] ... which in version 3 behaves differently? ActivePython 3.1.2.3 (ActiveState Software Inc.) based on Python 3.1.2 (r312:79147, Mar 22 2010, 12:20:29) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> ham = range(10) >>> ham[11:21] Traceback (most recent call last): File "", line 1, in TypeError: sequence index must be integer, not 'slice' >>> Oh wait -- it's a range thing... >>> ham[1:3] Traceback (most recent call last): File "", line 1, in TypeError: sequence index must be integer, not 'slice' >>> ham range(0, 10) >>> type(ham) >>> ham = list(range(10)) >>> ham[11:21] [] >>> Well, that's annoying, but it is what xrange did and the docs do say range 3.0 is the old xrange 2.x and that the old range 2.x I've deployed. Stutter-stepping-to-3.x-ly yrs, Emile From jonas at codeazur.com.br Sat Sep 25 15:02:54 2010 From: jonas at codeazur.com.br (Jonas Galvez) Date: Sat, 25 Sep 2010 16:02:54 -0300 Subject: Python2.7 on OSX Message-ID: Just installed Python2.7 on my OSX Leopard with make altinstall. No missing dependencies, but I have one annoying problem: the delete key prints '^H' on the Python shell. Does anyone know how to fix that? Thanks in advance, -- Jonas -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Sep 25 15:05:33 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 26 Sep 2010 00:35:33 +0530 Subject: Python2.7 on OSX In-Reply-To: References: Message-ID: On Sun, Sep 26, 2010 at 12:32 AM, Jonas Galvez wrote: > Just installed Python2.7 on my OSX Leopard with make altinstall. > > No missing dependencies, but I have one annoying problem: the delete key > prints '^H' on the Python shell. > > Does anyone know how to fix that? > > Thanks in advance, > Is readline module installed in yours ? try 'import readline' to check. > > -- Jonas > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From sschwarzer at sschwarzer.net Sat Sep 25 15:54:49 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 25 Sep 2010 21:54:49 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: <4C9E5389.2080103@sschwarzer.net> Hi Terry, On 2010-09-25 19:24, Terry Reedy wrote: > On 9/25/2010 4:22 AM, Yingjie Lan wrote: > There is already a builtin reversed() function whose output can be > multiplied. Seemingly, it can't: $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> L = [1, 2, 3] >>> 3 * reversed(L) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for *: 'int' and 'listreverseiterator' $ python3 Python 3.1.2 (r312:79147, Apr 15 2010, 12:35:07) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> L = [1, 2, 3] >>> 3 * reversed(L) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for *: 'int' and 'list_reverseiterator' You can convert the result of `reversed` to a list though: >>> 3 * list(reversed(L)) [3, 2, 1, 3, 2, 1, 3, 2, 1] Stefan From arnodel at gmail.com Sat Sep 25 16:38:56 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 25 Sep 2010 13:38:56 -0700 (PDT) Subject: sequence multiplied by -1 References: Message-ID: On 25 Sep, 09:22, Yingjie Lan wrote: > Hi, > > I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics. > > Simply put, a sequence multiplied by -1 can give a reversed sequence. > > Then for any sequence "seq", and integer n>0, we can have > > "seq * -n" producing "(seq * -1) * n". > > Any thoughts? > > Yingjie If [1, 2]*-1 is correct, then, arguably, so should be -[1, 2] :) Some answers have invoked mathematics to weigh the value of this proposal, e.g. likening lists to vectors. But the obvious mathematical analogy is that the set of all lists forms a monoid under the operation of concatenation, which (unfortunately?) is performed with the "+" operator in Python. So it is natural that "*" represents repeated concatenation. Now under concatenation, non-empty lists do not have an inverse, i.e. for any non-empty list l, there does not exist a list l' such that l + l' == []. So there is no natural interpretation of -l and therefore of l*-1. However, by using "+" for list (and string) concatenation, Python already breaks the mathematical pledge of commutativity that this operator implies. -- Arnaud From niklasro at gmail.com Sat Sep 25 18:48:56 2010 From: niklasro at gmail.com (Niklasro) Date: Sat, 25 Sep 2010 15:48:56 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> <8632bf75-3963-4e85-99f3-684dcde99589@i17g2000vbq.googlegroups.com> <4c970fa2$0$7946$426a74cc@news.free.fr> Message-ID: <47bee975-56fa-458b-b191-14252308f7cb@i13g2000yqd.googlegroups.com> On Sep 20, 7:39?am, Bruno Desthuilliers wrote: > Niklasro a ?crit : > > > Good to learn what I'm doing :-) since important being able to explain > > choices taken farther than "doing it because it works". > > I understand the concept of modules may not correspond to java > > programming where I come from. > > Coming from Java - and specially if you only have experience with Java > -, you'll have to unlearn quite a few things. Python is 100% object - in > that everything you can bind to a name is an object, including classes, > functions, methods, and even modules - but it doesn't try to force you > into using classes when you don't need them. Which is good since always questioning the empty declarations Java has we know empty getters and setters forced to a class and interfaces with nothing but names and no logic. With this respect I prefer python solving same problem with ? MB python 30 MB J2EE used to with drawback only that Java had the faster physical response. You can have the buggiest code respond the fastest like a hijacked environment physically boosted you don't want and naturally choosing the slower physical response time in favor of decent development environment. Thanks Niklas From niklasro at gmail.com Sat Sep 25 18:51:45 2010 From: niklasro at gmail.com (Niklasro) Date: Sat, 25 Sep 2010 15:51:45 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <4c970e7f$0$21775$426a74cc@news.free.fr> <65e3f364-3b47-407e-a0d4-326c5a3b2f6b@k17g2000prf.googlegroups.com> Message-ID: <7c50b086-d34d-4813-8a14-99c926c8e240@n3g2000yqb.googlegroups.com> On Sep 21, 1:30?am, alex23 wrote: > Bruno Desthuilliers > wrote: > > > alex23 a ?crit : > > > Python only actually executes a module the first time it's imported, > > > Beware of multithreading and modules imported under different names... > > There can be issues with both in some web frameowrks. > > Good points, Bruno, thank you. > > Niklasro, a good example of Bruno's second point: running a module as > a script and then importing it elsewhere later will execute the module > in the second import, creating two module objects - '__main__' and > ''. > > The issue with threading is the more important one of which to be > aware. I follow it means learning when constructors get called twice. Normally a constructor should get called once only. Many thanks for the insights both solving my problem and referencing important topics From nobody at nowhere.com Sat Sep 25 20:12:45 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 26 Sep 2010 01:12:45 +0100 Subject: SocketServer: replace network by hard drive References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: On Sat, 25 Sep 2010 14:45:29 +0200, Thomas Jollans wrote: >> The problem with using the loopback interface is that it's still >> "network access", which can run into all kinds of issues with security >> policies, firewalls, etc. > > What kind of crappy firewall blocks loopback traffic? Really? The sort that restricts the ability to create sockets rather than filtering traffic. ZoneAlarm works like this. From steve at REMOVE-THIS-cybersource.com.au Sat Sep 25 21:34:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Sep 2010 01:34:34 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: <4c9ea32a$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 13:45:11 +0200, Thomas Jollans wrote: > On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: >> Hi, >> >> I noticed that in python3k, multiplying a sequence by a negative >> integer is the same as multiplying it by 0, and the result is an empty >> sequence. It seems to me that there is a more meaningful symantics. > > Um... > > for every list l and integer n >= 0: > len(l*n) == len(l)*n > > Multiplying a list by a negative integer should produce a list of > negative length, which does not exist. Look at the domain of your invariance. It says nothing about negative n, and nor should it. > IMHO, the only correct behaviour > would be to raise an exception, though one could argue that there are > practical benefits for the operation to succeed for any integer operand. Since lists of negative length don't exist, we're free to set the invariance to something which has a less restrictive domain and is more useful than raising an exception: for every list l and integer n: len(l*n) == len(l)*max(0, n) >> Simply put, a sequence multiplied by -1 can give a reversed sequence. > > For that, we have slicing. A negative step value produces a reverse > slice of the list. You can't argue that this makes sense, can you > >>>> [1,2,3,4][::-1] > [4, 3, 2, 1] >>>> [1,2,3,4][::-2] > [4, 2] Why does it not make sense? I'm more concerned that the simple idiom: # list L must have at least 5 items, so extend it with None if needed L.extend([None]*(5 - len(L)) would suddenly break with this proposal. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Sep 25 22:11:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Sep 2010 02:11:55 GMT Subject: sequence multiplied by -1 References: Message-ID: <4c9eabeb$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 06:54:36 -0700, Yingjie Lan wrote: > For the rule above, how about the > case to reverse and multiply: > >>>> L*-3 #L reversed and repeated three times > > v.s. > >>>> L[::-1]*3 #L reversed and repeated three times > > The first one is simpler (4 chars v.s. 9 chars). I thought it was also > intuitive because if you multiply a vector by -1, you should get a > vector in the reversed direction. Reversing the order of elements in a vector does NOT reverse the vector's direction. Vector multiplication by a scalar does elementwise multiplication. In mathematics and physics: [1, 2, 3]*5 => [5, 10, 15] [1, 2, 3]*-1 => [-1, -2, -3] is a reflection of the vector. It certainly doesn't reverse the order of elements! [1, 2, 3] => [3, 2, 1] is a rotation, not a reflection. Python doesn't treat sequences as vectors, since it's a programming language and sequences are more general. Instead it performs repetition. This is conceptually simple: multiplying a sequence by n *repeats* the sequence n times: L*n = L+L+L+...+L # n times where + is concatenation, not elementwise addition. If n is zero, you get the empty sequence: L*0 = an empty sequence of the same type as L just like you get nothing if you multiply a number by n. If you ask for zero copies of a sequence, you get nothing. The only tricky parts are what to do for fractional values of n, and negative values. For practical reasons, the current behaviour is the most useful thing to do. Once you see sequence multiplication as repetition, then the natural interpretation of multiplication by a negative value *cannot* be reversal, or any other re-ordering or permutation. How many repetitions of [1, 2, 3, 4] does it take to give [1, 4, 2, 3]? Answer -- you can't get any other permutation by repeating the original. Singling out reversal as a privileged permutation is just "tacking on" extra functionality, for no real benefit. It would be like making: sorted(my_list) => sequence in sorted order sorted(my_list, reversed=True) => sequence in reverse sorted order sorted(my_list, reversed=3) => sequence with every element multiplied by 3, then sorted Yes, you could do it, and yes, it might save somebody a line of code somewhere, but WTF??? But even if it wasn't, for reasons of backward compatibility, to say nothing of the moratorium, it isn't going to change. -- Steven From lanyjie at yahoo.com Sat Sep 25 23:07:08 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 20:07:08 -0700 (PDT) Subject: sequence multiplied by -1 In-Reply-To: <4c9eabeb$0$28659$c3e8da3@news.astraweb.com> Message-ID: <143743.27067.qm@web54208.mail.re2.yahoo.com> Hi all, Thanks for considering this proposal seriously and all your discussions shed light on the pro's and cons (well, more cons than pros, to be honest). It occurrs to me that this proposal is not a sound one, for the reasons already well documented in this thread, which I need not repeat. Thanks all for participation! Yingjie From lanyjie at yahoo.com Sat Sep 25 23:35:05 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 20:35:05 -0700 (PDT) Subject: solve alphametic puzzles in just 9 lines of code In-Reply-To: <164829.96277.qm@web54204.mail.re2.yahoo.com> Message-ID: <56462.44143.qm@web54201.mail.re2.yahoo.com> Sorry, didn't document my code well enough. Here is the code with an example. Yingjie #############Code begins############### from itertools import permutations def solve(puzzle): """solve alphametic puzzles in just 9 lines of code. Make sure each operator is seperated from the words by white-spaces, e.g.: >>> solve('send + more == money') """ words = [w for w in puzzle.split() if w.isalpha()] nonzeros = {w[0] for w in words} others = {a for a in ''.join(words) if a not in nonzeros} chars = [ord(c) for c in nonzeros]+[ord(c) for c in others] assert len(chars) <= 10, 'Too many letters' for guess in permutations('0123456789', len(chars)): if '0' not in guess[:len(nonzeros)]: equation = puzzle.translate(dict(zip(chars, guess))) if eval(equation): return puzzle, equation if __name__ == '__main__': print ('\n'.join(solve("send + more == money"))) From xahlee at gmail.com Sun Sep 26 00:05:13 2010 From: xahlee at gmail.com (Xah Lee) Date: Sat, 25 Sep 2010 21:05:13 -0700 (PDT) Subject: toy list processing problem: collect similar terms Message-ID: here's a interesting toy list processing problem. I have a list of lists, where each sublist is labelled by a number. I need to collect together the contents of all sublists sharing the same label. So if I have the list ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t)) where the first element of each sublist is the label, I need to produce: output: ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) a Mathematica solution is here: http://xahlee.org/UnixResource_dir/writ/notations_mma.html R5RS Scheme lisp solution: http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_gmail.scm by Sourav Mukherjee also, a Common Lisp solution can be found here: http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1ded8824bc750b? anyone care to give a solution in Python, Perl, javascript, or other lang? am guessing the scheme solution can be much improved... perhaps using some lib but that seems to show scheme is pretty weak if the lib is non-standard. Xah ? xahlee.org ? From nagle at animats.com Sun Sep 26 01:08:54 2010 From: nagle at animats.com (John Nagle) Date: Sat, 25 Sep 2010 22:08:54 -0700 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: <4c9ed575$0$1644$742ec2ed@news.sonic.net> On 9/25/2010 4:45 AM, Thomas Jollans wrote: > On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: >> Hi, >> >> I noticed that in python3k, multiplying a sequence by a negative integer is >> the same as multiplying it by 0, and the result is an empty sequence. It >> seems to me that there is a more meaningful symantics. The concept that the multiply operator should be overloaded to do something l33t on sequences was a Python design mistake. It leads to semantics like this: x = 10 y = "10" x*2 20 y*2 '1010' int(y*2) 1010 int(y)*2 20 That's awful. It's the kind of thing a novice C++ programmer would write shortly after they discovered operator overloading. Now, ask yourself, when you get a numeric value back from a database, is it an integer or a string? How about the CSV module? Are you sure? John Nagle From gherron at digipen.edu Sun Sep 26 01:21:48 2010 From: gherron at digipen.edu (Gary Herron) Date: Sat, 25 Sep 2010 22:21:48 -0700 Subject: toy list processing problem: collect similar terms In-Reply-To: References: Message-ID: <4C9ED86C.70807@digipen.edu> On 09/25/2010 09:05 PM, Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > a Mathematica solution is here: > http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > R5RS Scheme lisp solution: > http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_gmail.scm > by Sourav Mukherjee > > also, a Common Lisp solution can be found here: > http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1ded8824bc750b? > > anyone care to give a solution in Python, Perl, javascript, or other > lang? am guessing the scheme solution can be much improved... perhaps > using some lib but that seems to show scheme is pretty weak if the lib > is non-standard. > > Xah ? xahlee.org ? > Python 3: (I have not tried to match the exact format of your output, but I get the right things is the right order.) data = ((0,'a','b'), (1,'c','d'), (2,'e','f'), (3,'g','h'), (1,'i','j'), (2,'k','l'), (4,'m','n'), (2,'o','p'), (4,'q','r'), (5,'s','t')) from collections import OrderedDict r = OrderedDict() for label,*rest in data: r.setdefault(label, []).extend(rest) print(list(r.values())) produces: (['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'], ['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']) -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From abu at software-lab.de Sun Sep 26 01:29:20 2010 From: abu at software-lab.de (Alexander Burger) Date: Sun, 26 Sep 2010 05:29:20 +0000 (UTC) Subject: toy list processing problem: collect similar terms References: Message-ID: In PicoLisp: (mapcar '((X) (apply conc (cdr X))) (group List) ) Cheers, - Alex From no.email at nospam.invalid Sun Sep 26 02:17:23 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 25 Sep 2010 23:17:23 -0700 Subject: toy list processing problem: collect similar terms References: Message-ID: <7xzkv5hvv0.fsf@ruckus.brouhaha.com> Python solution follows (earlier one with an error cancelled). All crossposting removed since crossposting is a standard trolling tactic. from collections import defaultdict def collect(xss): d = defaultdict(list) for xs in xss: d[xs[0]].extend(xs[1:]) return list(v for k,v in sorted(d.items())) y = [[0,'a','b'], [1,'c','d'], [2,'e','f'], [3,'g','h'], [1,'i','j'], [2,'k','l'], [4,'m','n'], [2,'o','p'], [4,'q','r'], [5,'s','t']] print collect(y) From oddron at gmail.com Sun Sep 26 02:19:59 2010 From: oddron at gmail.com (Ronald Guida) Date: Sun, 26 Sep 2010 02:19:59 -0400 Subject: Python 2.7 installation problem Message-ID: Hi, I am trying to perform a user-install of python 2.7 on Ubuntu 10.04, and my installation is failing. This sequence of commands reproduces the failure on my system: $ tar -zxvf Python-2.7.tgz $ cd Python-2.7/ $ ./configure --prefix=$HOME $ make $ ./python Lib/test/test_collections.py doctest (collections) ... 54 tests with zero failures $ make altinstall $ cd $ which python2.7 /home/oddron/bin/python2.7 $ python2.7 Python 2.7 (r27:82500, Sep 26 2010, 01:49:59) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import collections Traceback (most recent call last): File "", line 1, in File "/home/oddron/lib/python2.7/collections.py", line 8, in from _collections import deque, defaultdict ImportError: No module named _collections >>> import sys >>> sys.path ['', '/home/oddron/lib/python27.zip', '/home/oddron/lib/python2.7', '/home/oddron/lib/python2.7/plat-linux2', '/home/oddron/lib/python2.7/lib-tk', '/home/oddron/lib/python2.7/lib-old', '/home/oddron/lib/python2.7/lib-dynload', '/home/oddron/.local/lib/python2.7/site-packages', '/home/oddron/lib/python2.7/site-packages'] >>> Things I have already checked: * My path includes ~/bin * None of PYTHONHOME and friends are set. * I have also tried "make install" instead of "make altinstall", and I get the same failure. Can anyone give me a hint regarding what has gone wrong? Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Sep 26 02:27:00 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Sep 2010 06:27:00 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> Message-ID: <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 22:08:54 -0700, John Nagle wrote: > On 9/25/2010 4:45 AM, Thomas Jollans wrote: >> On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: >>> Hi, >>> >>> I noticed that in python3k, multiplying a sequence by a negative >>> integer is the same as multiplying it by 0, and the result is an empty >>> sequence. It seems to me that there is a more meaningful symantics. > > The concept that the multiply operator should be overloaded to > do something l33t on sequences was a Python design mistake. Repetition is a simple, useful operation, and describing it pejoratively as "l33t" is just silly. > It leads to semantics like this: > > x = 10 > y = "10" > > x*2 > 20 > y*2 > '1010' > int(y*2) > 1010 > int(y)*2 > 20 Yes. Where's the problem? Are you also concerned that int(max("230", "9")) returns 9 but max(int ("230"), int("9")) returns 230? It's obvious that there is no such invariant that int(f(y)) must equal f(int(y)) for arbitrary functions f, so why do you think that the failure of this invariant to hold for the * operator matters in the least? > That's awful. It's the kind of thing a novice C++ > programmer would write shortly after they discovered operator > overloading. So you say. > Now, ask yourself, when you get a numeric value back from > a database, is it an integer or a string? How about the CSV module? > Are you sure? If you're not sure what sort of data you're getting, you've got no business blindly applying functions in some arbitrary order to it in the hope that the result will be sensible. If the data is meant to be an integer, and you might get a string from the database, then convert it to an integer as soon as possible. I'm surprised that you think that you should be able to apply arbitrary mathematical operations to strings *before* turning them into an int and still get sensible results. That boggles my mind. -- Steven From lie.1296 at gmail.com Sun Sep 26 02:44:24 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 26 Sep 2010 16:44:24 +1000 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <87vd5zyrkr.fsf@web.de> References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> <87vd5zyrkr.fsf@web.de> Message-ID: <4c9eeb19$1@dnews.tpgi.com.au> On 09/22/10 02:44, Diez B. Roggisch wrote: > Antoine Pitrou writes: > >> On Tue, 21 Sep 2010 17:59:27 +0200 >> deets at web.de (Diez B. Roggisch) wrote: >>> >>> The problems explained are simply outdated and crippled python >>> versions. >>> >>> And to me, a python version installed that has not the >>> distutils module is *crippled*. You can rationalize that as much as you >>> want through some package philosophy saying "we don't ship development >>> related files", but to me a simple installation instruction that says >> >> comp.lang.python doesn't handle Linux packaging, so why don't you >> complain to your distro instead? Ranting on this group has zero chance >> of fixing the problem. > > comp.lang.python frequently deals with problems caused by this and other > distro-related issues. Your are welcome to not participate on these > discussions. > > The state of affairs isn't ideal, and there is improvement options on > all sides. I'm just astonished that people seem to think that distros in > general are better and should be left alone, than what a more python > centric solution could be. If your distro's package management system doesn't provide you with the packages you need, then you have made the wrong choice of distro; it's neither the fault of the distro, package manager, or python; the distro's policies just does not suit your needs, and either you have made the mistake of choosing that distro or the other distros are even worse. Maybe it's time to evaluate whether staying in your current distro is still beneficial, or it's more hassle than its worth, or if you want to fix the distro's package manager in some way. Package Management Triangle reliability / \ / Pick \ / any \ / two \ simplicity ------------ configurability Ubuntu's (and I believe Debian's) apt-get and Add/Remove Program is very easy to use and stable, but there is not much configurability, you get what your package manager gives you. Gentoo's Portage is extremely configurable, it almost always gives you the latest versions and almost all of the valid configurations allowed by upstream developer, but the system is nowhere near simple, and every system you build using Portage is basically untested system. From no.email at nospam.invalid Sun Sep 26 02:46:57 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 25 Sep 2010 23:46:57 -0700 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> Message-ID: <7xd3s1knmm.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > I'm surprised that you think that you should be able to apply > arbitrary mathematical operations to strings *before* turning them > into an int and still get sensible results. That boggles my mind. I think the idea is you should not be able to do mathematical operations on strings, and if you try to do one, Python should raise an exception, rather than using hokey analogies to guess at what you were trying to do. If you want to replicate a sequence, introduce a function with a name like "replicate", rather than overloading an arithmetic operator. From livibetter at gmail.com Sun Sep 26 03:47:23 2010 From: livibetter at gmail.com (livibetter) Date: Sun, 26 Sep 2010 00:47:23 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: Message-ID: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Here is mine for Python: l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], [5, 's', 't']] d = {} for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx] + items if idx in d else items print d.values() Output: [['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'], ['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']] From steve at REMOVE-THIS-cybersource.com.au Sun Sep 26 03:56:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Sep 2010 07:56:59 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> Message-ID: <4c9efccb$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 23:46:57 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> I'm surprised that you think that you should be able to apply arbitrary >> mathematical operations to strings *before* turning them into an int >> and still get sensible results. That boggles my mind. > > I think the idea is you should not be able to do mathematical operations > on strings, and if you try to do one, Python should raise an exception, > rather than using hokey analogies to guess at what you were trying to > do. If you want to replicate a sequence, introduce a function with a > name like "replicate", rather than overloading an arithmetic operator. But * isn't a mathematical operation on sequences. It's a repetition operator. And repetition isn't a "hokey analogy" of multiplication -- you've got it completely backwards. Multiplication is a generalisation of repetition, and sequence repetition is more fundamental than mathematical multiplication. Long before anyone said 2.3 * 5.7 people were able to talk about "two bags of wheat, and another two bags of wheat, and repeat six more times". That's how multiplication was invented -- from repeated addition. Think of writing numbers as tallies, before the invention of arabic numerals. III groups of II would be IIIIII. The semantics of list.index() and str.index() are not quite the same (string indexing finds substrings, while list indexing does not find sublists). So what? We have classes and modules and namespaces so that you don't need every function to have a unique. It's okay that the index method behaves slightly differently when operating on strings and lists, and it's okay for the * operator to behave slightly differently too. It is true that there's a certain class of coders who apparently like line-noise, and so they overload operators to do arbitrary things with no concern about familiarity with common convention or readability: # sort the sequence by length my_seq ** len But this is bad because there's no convention for exponentiation being related to sorting, and so the code is obscure and unintuitive. Without the comments, you would have no idea what the line did. But that's just the same as doing this: def raise_to_power(alist, key): alist.sort(key=key) return alist This is dumb whether you overload the ** operator or write a function called "raise_to_power". There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", and the fact that it doesn't do the same thing as int("spam")*3 is a foolish argument. -- Steven From chris at simplistix.co.uk Sun Sep 26 04:13:09 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Sun, 26 Sep 2010 09:13:09 +0100 Subject: Checker 1.4 Released! Message-ID: <4C9F0095.7030705@simplistix.co.uk> I'm pleased to announce a new release of Checker. This is a cross-platform, pluggable tool for comparing the configuration of a machine with a known configuration stored in text files in a source control system all written in Python. This release adds a 'command' checker that lets you record and check the output of arbitrary commands. The initial use case was for dealing with the output of 'chkconfig --list' on Red Hat. For more information, please see: http://www.simplistix.co.uk/software/python/checker cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From no.email at nospam.invalid Sun Sep 26 04:16:49 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 26 Sep 2010 01:16:49 -0700 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: <7x4odcc426.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? Should "spam"*2.5 be "spamspamsp"? Should "spam"-"a" be "spm"? What about "spamspam"-"a"? And what about "spam"/2? "sp" be an ok first guess, but "sa" might make more sense (it means (1,2,3,...)/2 would be (1,3,5...)). I say it's all hokey from the get-go ;-). From arnodel at gmail.com Sun Sep 26 04:29:53 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 26 Sep 2010 01:29:53 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Message-ID: <10e80524-3d6e-4655-8b2b-f82e38531966@m15g2000yqm.googlegroups.com> On 26 Sep, 08:47, livibetter wrote: > Here is mine for Python: > > l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, > 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], > [5, 's', 't']] > d = {} > for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx] + items > if idx in d else items > print d.values() > > Output: > [['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'], > ['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']] from itertools import groupby from operator import itemgetter l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], [5, 's', 't']] [ [x for g in gs for x in g[1:]] for _, gs in groupby(sorted(l), itemgetter(0)) ] -- Arnaud From sschwarzer at sschwarzer.net Sun Sep 26 05:20:18 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 26 Sep 2010 11:20:18 +0200 Subject: creating python daemon ? In-Reply-To: <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> <87fwx2yw04.fsf@web.de> <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> Message-ID: <4C9F1052.9050700@sschwarzer.net> Hi Daniel, On 2010-09-23 07:30, vineet daniel wrote: > On Sep 22, 2:20 pm, de... at web.de (Diez B. Roggisch) wrote: >> vineet daniel writes: >>> On Sep 21, 9:47 pm, de... at web.de (Diez B. Roggisch) wrote: >>>> vineet daniel writes: >>>>> code that I am using is as follows : >> >>>>> #! /usr/bin/env python >>>>> import sys,os >>>>> pid = os.fork() >>>>> os.chdir("/var/www/html/") >>>>> os.setsid() >>>>> os.umask(0) >>>>> #this line will read apache log in real time as redirected from the >>>>> CustomLog directive of Apache. >>>>> log = sys.stdin.readlines() >>>>> f = open('/var/www/logmongo.txt','a') # append log to this text file >>>>> f.write(log) I guess you'll need some loop to process the input from Apache. > There is a directive in Apache - CustomLog which can redirect logs to > a script or another file by using Pipe. I googled about it and came to > know that this works flawlessly with Perl as Apache treats Perl > scripts as daemon, for Python to take input from Apache, it needs to > work as daemon. Apache will then push its logs lines to this daemon as > input. Perl takes this input as but python's stdin is not > working as expected it just takes the file name as given in CustomLog > directive using Pipe i.e if I use CustomLog '|/var/wwww/script.py' Are the _four_ ws intentional? > combined, what script reads is just the file name, how and why I am > not able to figure it out. And thats the reason I am here. I hope > you've got what I am trying to do. Do you have a line for the interpreter at the top of your script, like #!/usr/bin/python Is the script executable (e. g. chmod +x script.py)? Stefan From usenet-nospam at seebs.net Sun Sep 26 05:30:08 2010 From: usenet-nospam at seebs.net (Seebs) Date: 26 Sep 2010 09:30:08 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-26, Steven D'Aprano wrote: > On Sat, 25 Sep 2010 23:46:57 -0700, Paul Rubin wrote: >> I think the idea is you should not be able to do mathematical operations >> on strings, and if you try to do one, Python should raise an exception, >> rather than using hokey analogies to guess at what you were trying to >> do. If you want to replicate a sequence, introduce a function with a >> name like "replicate", rather than overloading an arithmetic operator. > But * isn't a mathematical operation on sequences. It's a repetition > operator. I think Paul's point is that "*" is in general a mathematical operation, and discovering that for some types of objects, it's been given a fundamentally unrelated meaning can certainly be a bit of a surprise. I actually sort of like that perl has a separate repetition operator. And really, when you find yourself saying something nice about perl's syntax or punctuation, that's always scary territory to be in. > There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > and the fact that it doesn't do the same thing as int("spam")*3 is a > foolish argument. The languages in which it's surprising are mostly things like perl, where there's a certain amount of implicit coercion going on, so it's ambiguous whether "3"*3 ought to mean "333" or 9. (Except it isn't, because repetition is a separate operator, written "3" x 3 rather than "3" * 3...) People coming from that kind of background may be expecting * to stay an arithmetic operator, rather than having it change form when applied to non-arithmetic objects. I'm not sure either way. I think on the whole, I like the notion of a repetition operator which is distinct from multiplication, but I also definitely prefer the lack of implicit coercion, and without implicit coercion, there's a lot less underlying ambiguity to worry about. >From the top, I guess my analysis is: * It seems clear that, given two sequences x and y, "x + y" ought to be the concatenation of these sequences. * Thus, "x + x" should be x concatenated to itself. * Idiomatically, it is not unreasonable to assert that "x * 2" and "x + x" could be the same value. * It thus makes some sense for * to indicate repetition of the sequence. * Since a string is a kind of a sequence, it also makes sense for * to indicate repetition. So I think I'm pretty much convinced that Python's behavior makes sense, but it makes sense only because I'm going into this expecting operators to be defined by types, so I don't expect every '*' to mean 'multiplication'. Helps, perhaps, that I got exposed to group theory early enough to be used to redefining + and * to be any two operations which have interesting properties*. -s [*] What's purple and commutes? An abelian grape. -- 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 rvtol+usenet at xs4all.nl Sun Sep 26 05:41:23 2010 From: rvtol+usenet at xs4all.nl (Dr.Ruud) Date: Sun, 26 Sep 2010 11:41:23 +0200 Subject: toy list processing problem: collect similar terms In-Reply-To: References: Message-ID: <4c9f1543$0$41105$e4fe514c@news.xs4all.nl> On 2010-09-26 06:05, Xah Lee wrote: > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) The input is a string on STDIN, and the output is a string on STDOUT? Use a hash: perl -MData::Dumper -wle '$Data::Dumper::Sortkeys = 1; my $t = "((0 a b) (1 c d) (2 e f) (3 g h) (1 i j)" . " (2 k l) (4 m n) (2 o p) (4 q r) (5 s t))"; push @{ $h{ $1 } }, $2 while $t =~ /(\w+)([^)]*)/g; # gist print Dumper \%h; ' or an array: perl -wle ' my $t = "((0 a b) (1 c d) (2 e f) (3 g h) (1 i j)" . " (2 k l) (4 m n) (2 o p) (4 q r) (5 s t))"; push @{$a[$1]},$2 while $t =~ /(\w+)\s+([^)]*)/g; # gist.1 print "((".join(") (",map join(" ",@$_), at a )."))"; # gist.2 ' Or if the list is not just a string, but a real data structure in the script: perl -wle' my $t = [ [qw/0 a b/], [qw/1 c d/], [qw/2 e f/], [qw/3 g h/], [qw/1 i j/], [qw/2 k l/], [qw/4 m n/], [qw/2 o p/], [qw/4 q r/], [qw/5 s t/] ]; push @{ $a[ $_->[0] ] }, [ @$_[ 1, 2 ] ] for @$t; # AoAoA printf "((%s))\n", join ") (", map join( " ", map join( " ", @$_ ), @$_ ), @a; ' Etc. -- Ruud From no.email at nospam.invalid Sun Sep 26 06:06:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 26 Sep 2010 03:06:03 -0700 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: <7xtylcx1is.fsf@ruckus.brouhaha.com> Seebs writes: > * It seems clear that, given two sequences x and y, "x + y" ought to > be the concatenation of these sequences. >... > Helps, perhaps, that I got exposed to group theory early enough to be used > to redefining + and * to be any two operations which have interesting > properties*. But groups have only one of those operators, and when it's written as + that usually means the group is commutative. So you wouldn't want + to denote sequence concatenation. If + and * are both present, that sounds like a ring, in which case you'd want "foo"*"bar" to work. It actually seems to me that exponentiation makes more sense than multiplication for turning "a" into "aaa". We think of aaa as what results from writing "a" with "3" in the superscript position. From Tribulations at Paralleles.invalid Sun Sep 26 06:17:38 2010 From: Tribulations at Paralleles.invalid (TP) Date: Sun, 26 Sep 2010 12:17:38 +0200 Subject: equivalent of bash "set -x" in Python Message-ID: <27j3n7-vaj.ln1@rama.universe> Hi everybody, I am interested in having the possibility to print every Python commands in a script (for didactic purpose). So I am looking for some sort of equivalent of bash "set -x". Does it exist? Thanks Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From prologic at shortcircuit.net.au Sun Sep 26 06:28:00 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Sun, 26 Sep 2010 20:28:00 +1000 Subject: equivalent of bash "set -x" in Python In-Reply-To: <27j3n7-vaj.ln1@rama.universe> References: <27j3n7-vaj.ln1@rama.universe> Message-ID: On Sun, Sep 26, 2010 at 8:17 PM, TP wrote: > Hi everybody, > > I am interested in having the possibility to print every Python commands in > a script (for didactic purpose). > So I am looking for some sort of equivalent of bash "set -x". > Does it exist? What do you mean by "command" ? cheers James -- -- James Mills -- -- "Problems are solved by method" From clp2 at rebertia.com Sun Sep 26 06:28:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 26 Sep 2010 03:28:57 -0700 Subject: equivalent of bash "set -x" in Python In-Reply-To: <27j3n7-vaj.ln1@rama.universe> References: <27j3n7-vaj.ln1@rama.universe> Message-ID: On Sun, Sep 26, 2010 at 3:17 AM, TP wrote: > Hi everybody, > > I am interested in having the possibility to print every Python commands in > a script (for didactic purpose). > So I am looking for some sort of equivalent of bash "set -x". > Does it exist? Not exactly. However, defining an appropriate function and passing it to sys.settrace() would be the closest analogue: http://docs.python.org/library/sys.html#sys.settrace You could also step through your code manually using the debugger: http://docs.python.org/library/pdb.html Cheers, Chris -- http://blog.rebertia.com From hobson42 at gmaiil.com Sun Sep 26 06:33:36 2010 From: hobson42 at gmaiil.com (Ian) Date: Sun, 26 Sep 2010 11:33:36 +0100 Subject: sequence multiplied by -1 In-Reply-To: <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4C9F2180.7050903@gmaiil.com> On 26/09/2010 07:27, Steven D'Aprano wrote: > I'm surprised that you think that you > should be able to apply arbitrary mathematical operations to strings > *before* turning them into an int and still get sensible results. That > boggles my mind. > You clearly have not been "spoiled rotten" by php. Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From Tribulations at Paralleles.invalid Sun Sep 26 06:46:12 2010 From: Tribulations at Paralleles.invalid (TP) Date: Sun, 26 Sep 2010 12:46:12 +0200 Subject: equivalent of bash "set -x" in Python References: <27j3n7-vaj.ln1@rama.universe> Message-ID: James Mills wrote: > What do you mean by "command" ? For example, print statements, but it could extend to class definitions, etc. I am going to examine the solution given by Chris. Cheers, Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From bc at freeuk.com Sun Sep 26 08:41:49 2010 From: bc at freeuk.com (BartC) Date: Sun, 26 Sep 2010 13:41:49 +0100 Subject: sequence multiplied by -1 In-Reply-To: References: Message-ID: "Yingjie Lan" wrote in message news:mailman.1050.1285403326.29448.python-list at python.org... > Hi, > > I noticed that in python3k, multiplying a sequence by a negative integer > is the same as multiplying it by 0, and the result is an empty sequence. > It seems to me that there is a more meaningful symantics. > > Simply put, a sequence multiplied by -1 can give a reversed sequence. > > Then for any sequence "seq", and integer n>0, we can have > > "seq * -n" producing "(seq * -1) * n". > > Any thoughts? Gimmicky. Best to define multiplication only by unsigned or positive values. -- Bartc From bkjones at gmail.com Sun Sep 26 08:55:53 2010 From: bkjones at gmail.com (Brian Jones) Date: Sun, 26 Sep 2010 08:55:53 -0400 Subject: creating python daemon ? In-Reply-To: <4C9F1052.9050700@sschwarzer.net> References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> <87fwx2yw04.fsf@web.de> <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> <4C9F1052.9050700@sschwarzer.net> Message-ID: I don't believe you need to be doing all kinds of acrobatics with apache and your python process. On Linux and Unix machines, you can tell the stock syslog daemon that messages sent to a certain syslog facility are to be sent to a named pipe. So, if you tell syslog that, say, the local6 facility should go to a named pipe, then point apache at that to do its logging, then your script becomes as simple as reading from the named pipe. I did something years ago similar to this to get syslog messages sent to my jabber client. It's perl (it predates my conversion to python), but doing the same in python would be way easier :) The code is here: http://linuxlaboratory.org/snippets/2/ And an old article from Linux.com which explains the syslog bits is here: http://www.linux.com/archive/feature/36631 I occasionally still hear from people that all of it still works. hth. brian On Sun, Sep 26, 2010 at 5:20 AM, Stefan Schwarzer wrote: > Hi Daniel, > > On 2010-09-23 07:30, vineet daniel wrote: > > On Sep 22, 2:20 pm, de... at web.de (Diez B. Roggisch) wrote: > >> vineet daniel writes: > >>> On Sep 21, 9:47 pm, de... at web.de (Diez B. Roggisch) wrote: > >>>> vineet daniel writes: > >>>>> code that I am using is as follows : > >> > >>>>> #! /usr/bin/env python > >>>>> import sys,os > >>>>> pid = os.fork() > >>>>> os.chdir("/var/www/html/") > >>>>> os.setsid() > >>>>> os.umask(0) > >>>>> #this line will read apache log in real time as redirected from the > >>>>> CustomLog directive of Apache. > >>>>> log = sys.stdin.readlines() > >>>>> f = open('/var/www/logmongo.txt','a') # append log to this text file > >>>>> f.write(log) > > I guess you'll need some loop to process the input from > Apache. > > > There is a directive in Apache - CustomLog which can redirect logs to > > a script or another file by using Pipe. I googled about it and came to > > know that this works flawlessly with Perl as Apache treats Perl > > scripts as daemon, for Python to take input from Apache, it needs to > > work as daemon. Apache will then push its logs lines to this daemon as > > input. Perl takes this input as but python's stdin is not > > working as expected it just takes the file name as given in CustomLog > > directive using Pipe i.e if I use CustomLog '|/var/wwww/script.py' > > Are the _four_ ws intentional? > > > combined, what script reads is just the file name, how and why I am > > not able to figure it out. And thats the reason I am here. I hope > > you've got what I am trying to do. > > Do you have a line for the interpreter at the top of your > script, like > > #!/usr/bin/python > > Is the script executable (e. g. chmod +x script.py)? > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones -------------- next part -------------- An HTML attachment was scrubbed... URL: From jurgenex at hotmail.com Sun Sep 26 09:53:41 2010 From: jurgenex at hotmail.com (Jürgen Exner) Date: Sun, 26 Sep 2010 06:53:41 -0700 Subject: toy list processing problem: collect similar terms References: Message-ID: <12ku961maljpqr0vpecl4cc1m4r34addt6@4ax.com> Alexander Burger wrote: >In PicoLisp: What the f**** does PicoLisp have to with Perl? jue From jurgenex at hotmail.com Sun Sep 26 09:54:17 2010 From: jurgenex at hotmail.com (Jürgen Exner) Date: Sun, 26 Sep 2010 06:54:17 -0700 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Message-ID: livibetter wrote: >Here is mine for Python: What the f*** does Python have to do with Perl? jue From pjb at informatimago.com Sun Sep 26 10:24:46 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Sun, 26 Sep 2010 16:24:46 +0200 Subject: toy list processing problem: collect similar terms References: Message-ID: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Xah Lee writes: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > a Mathematica solution is here: > http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > R5RS Scheme lisp solution: > http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_gmail.scm > by Sourav Mukherjee > > also, a Common Lisp solution can be found here: > http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1ded8824bc750b? It's too complex. Just write: (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t)))) (mapcar (lambda (class) (reduce (function append) class :key (function rest))) (com.informatimago.common-lisp.list:equivalence-classes list :key (function first))) ) --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) -- __Pascal Bourguignon__ http://www.informatimago.com/ From sherm.pendley at gmail.com Sun Sep 26 10:56:07 2010 From: sherm.pendley at gmail.com (Sherm Pendley) Date: Sun, 26 Sep 2010 10:56:07 -0400 Subject: toy list processing problem: collect similar terms References: <12ku961maljpqr0vpecl4cc1m4r34addt6@4ax.com> Message-ID: J?rgen Exner writes: > Alexander Burger wrote: >>In PicoLisp: > > What the f**** does PicoLisp have to with Perl? It's Xah. He cross-posts in an attempt to start a language feud. Please don't feed the troll. sherm-- -- Sherm Pendley Cocoa Developer From sherm.pendley at gmail.com Sun Sep 26 10:56:48 2010 From: sherm.pendley at gmail.com (Sherm Pendley) Date: Sun, 26 Sep 2010 10:56:48 -0400 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Message-ID: J?rgen Exner writes: > livibetter wrote: >>Here is mine for Python: > > What the f*** does Python have to do with Perl? Xah is a cross-posting troll. Please don't feed the troll. sherm-- -- Sherm Pendley Cocoa Developer From typhoondauntless at gmail.com Sun Sep 26 11:07:22 2010 From: typhoondauntless at gmail.com (=?UTF-8?Q?tayfury=C4=B1lmaz?=) Date: Sun, 26 Sep 2010 08:07:22 -0700 (PDT) Subject: Qt not working o Wing ide 3.2 Message-ID: <650f047f-9ab4-4c17-8728-b31583d18563@28g2000yqm.googlegroups.com> hi everyone ? develop a program with pythoon and qt on wing ide ? use pyqt module in my program bu when ? debug a program,python is not debugging and o.s show a screen for solution.. and solution says python is not debugging. can he/she explain this solve problem.. thanks regards.. From invalid at invalid.invalid Sun Sep 26 11:20:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 26 Sep 2010 15:20:18 +0000 (UTC) Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: On 2010-09-26, Paul Rubin wrote: > Steven D'Aprano writes: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? Because 3 * "spam" == "spam" + "spam" + "spam" Just like 3 * 6 = 6 + 6 + 6 So now I suppose "+" for string concatenation is a bad thing. -- Grant From thomas at jollybox.de Sun Sep 26 11:20:39 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 26 Sep 2010 17:20:39 +0200 Subject: Qt not working o Wing ide 3.2 In-Reply-To: <650f047f-9ab4-4c17-8728-b31583d18563@28g2000yqm.googlegroups.com> References: <650f047f-9ab4-4c17-8728-b31583d18563@28g2000yqm.googlegroups.com> Message-ID: <201009261720.39427.thomas@jollybox.de> On Sunday 26 September 2010, it occurred to tayfury?lmaz to exclaim: > hi everyone ? develop a program with pythoon and qt on wing ide > ? use pyqt module in my program bu when ? debug a program,python is > not debugging and o.s show a screen for solution.. and solution says > python is not debugging. can he/she explain this solve problem.. > thanks > regards.. Quite frankly, I don't have the faintest idea what you're getting at. You'll have to be a lot clearer and more precise if you want to enable us to offer you useful help. * Minimal example script? * exact output (traceback!) of Python? * possibly, exact output of some other component? Just a thought - if you're using Wing IDE, you probably paid for it? Did you also pay for a support contract? Maybe that's part of the deal? If it is, maybe you should phone them up - they probably know a lot more about Wing IDE than most of us here. From mwilson at the-wire.com Sun Sep 26 11:31:51 2010 From: mwilson at the-wire.com (Mel) Date: Sun, 26 Sep 2010 11:31:51 -0400 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: Grant Edwards wrote: > On 2010-09-26, Paul Rubin wrote: >> Steven D'Aprano writes: >>> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > >> Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > > Because > > 3 * "spam" == "spam" + "spam" + "spam" > > Just like > > 3 * 6 = 6 + 6 + 6 > > So now I suppose "+" for string concatenation is a bad thing. It's awkward for math purists because there's no additive inverse .. hence the original poster's idea to simply create one out of the blue. For string lengths and list lengths we're stuck with non-negative integers, and no hope of general-purpose subtraction. I wouldn't change it. As an idiom, ' '*20 is just too handy a way to get a 20-blank string to give up. Mel. From ben at morrow.me.uk Sun Sep 26 11:39:56 2010 From: ben at morrow.me.uk (Ben Morrow) Date: Sun, 26 Sep 2010 16:39:56 +0100 Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Message-ID: Quoth pjb at informatimago.com (Pascal J. Bourguignon): > > It's too complex. Just write: > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > (2 o p) (4 q r) (5 s t)))) Unless you're going to talk about Perl, please take clpmisc out of the xpost. Ben From Tribulations at Paralleles.invalid Sun Sep 26 12:07:22 2010 From: Tribulations at Paralleles.invalid (TP) Date: Sun, 26 Sep 2010 18:07:22 +0200 Subject: adding a method to an existing builtin class Message-ID: Hi everybody, Today I have learned a bit of the news of Python 3.0 compared to 2.4 version. By the way, I have asked myself if it is possible to add a method to a builtin type as 'unicode': >>> a="foo" >>> type(a) >>> print(dir(a)) ['__add__', ..., 'zfill'] For example, I would like to add a "colorize" method to 'unicode' objects. Is this possible? Or am I compelled to derive the unicode builtin as below: class my_unicode(unicode): def __init__( self, unicode_string ): super( my_unicode, self ).__init__( ) def colorize( self ): return "\x1b[93;102m" + self + "\x1b[0m" my_unicode_string = my_unicode( "coucou" ) print( type( my_unicode_string ) ) print( my_unicode_string.colorize() ) print( my_unicode_string.upper() ) Thanks, Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From clp2 at rebertia.com Sun Sep 26 12:15:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 26 Sep 2010 09:15:29 -0700 Subject: adding a method to an existing builtin class In-Reply-To: References: Message-ID: On Sun, Sep 26, 2010 at 9:07 AM, TP wrote: > Hi everybody, > > Today I have learned a bit of the news of Python 3.0 compared to 2.4 > version. > > By the way, I have asked myself if it is possible to add a method to a > builtin type The built-in types' classes are immutable; you can only add/override their methods via subclassing, like you showed. Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Sun Sep 26 13:13:12 2010 From: nagle at animats.com (John Nagle) Date: Sun, 26 Sep 2010 10:13:12 -0700 Subject: sequence multiplied by -1 In-Reply-To: <7x4odcc426.fsf@ruckus.brouhaha.com> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: <4c9f7f36$0$1666$742ec2ed@news.sonic.net> On 9/26/2010 1:16 AM, Paul Rubin wrote: > Steven D'Aprano writes: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > Should "spam"*2.5 be "spamspamsp"? > Should "spam"-"a" be "spm"? What about "spamspam"-"a"? > And what about "spam"/2? "sp" be an ok first guess, but "sa" might > make more sense (it means (1,2,3,...)/2 would be (1,3,5...)). > > I say it's all hokey from the get-go ;-). I tend to agree. "+" as concatenation is at least associative. Trying to concatenate a string with an integer raises an exception, so that's not going to generate unexpected values. "*" as repetition, on the other hand, is a mixed-mode operation. That's why this is troublesome. Where the type spaces are isolated, overloading isn't so risky. We should have something like "repeat" or "dup" as a string method rather than an overloading of the "*" operator. Strings already have a range of methods which perform basic operations on the string and return a new string, so that's consistent. "xyz".dup(3) is clear enough. And allowing "xyz"*-3 was just lame. What reasonable use case does that have? John Nagle From detlev at die-offenbachs.de Sun Sep 26 14:35:08 2010 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sun, 26 Sep 2010 20:35:08 +0200 Subject: Qt not working o Wing ide 3.2 References: <650f047f-9ab4-4c17-8728-b31583d18563@28g2000yqm.googlegroups.com> Message-ID: Thomas Jollans wrote: > On Sunday 26 September 2010, it occurred to tayfury?lmaz to exclaim: >> hi everyone ? develop a program with pythoon and qt on wing ide >> ? use pyqt module in my program bu when ? debug a program,python is >> not debugging and o.s show a screen for solution.. and solution says >> python is not debugging. can he/she explain this solve problem.. >> thanks >> regards.. > > Quite frankly, I don't have the faintest idea what you're getting at. > You'll have to be a lot clearer and more precise if you want to enable > us to offer you useful help. > > * Minimal example script? > * exact output (traceback!) of Python? > * possibly, exact output of some other component? > > Just a thought - if you're using Wing IDE, you probably paid for it? > Did you also pay for a support contract? Maybe that's part of the deal? > If it is, maybe you should phone them up - they probably know a lot > more about Wing IDE than most of us here. Alternatively I would recommend the eric IDE, which is free and works very well with PyQt (actually it is written in PyQt). And it is available for Python2 and Python3. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From john at castleamber.com Sun Sep 26 14:43:51 2010 From: john at castleamber.com (John Bokma) Date: Sun, 26 Sep 2010 13:43:51 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Message-ID: <87y6ao9wgo.fsf@castleamber.com> J?rgen Exner writes: > livibetter wrote: >>Here is mine for Python: > > What the f*** does Python have to do with Perl? Clueless fuck. I unsubscribed from comp.lang.perl.misc to avoid the retards like you and now you come in via the backdoor. If you have a problem with Xah report him with Google Groups and with his hosting provider 1&1 like I do. Dreamhost kicked him out that way. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From jonas at codeazur.com.br Sun Sep 26 14:44:50 2010 From: jonas at codeazur.com.br (Jonas Galvez) Date: Sun, 26 Sep 2010 15:44:50 -0300 Subject: Python2.7 on OSX In-Reply-To: References: Message-ID: Bingo, that was it. Thanks! -- Jonas On Sat, Sep 25, 2010 at 4:05 PM, Shashwat Anand wrote: > > > On Sun, Sep 26, 2010 at 12:32 AM, Jonas Galvez wrote: > >> Just installed Python2.7 on my OSX Leopard with make altinstall. >> >> No missing dependencies, but I have one annoying problem: the delete key >> prints '^H' on the Python shell. >> >> Does anyone know how to fix that? >> >> Thanks in advance, >> > > Is readline module installed in yours ? > try 'import readline' to check. > > >> >> -- Jonas >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > ~l0nwlf > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vineetdaniel at gmail.com Sun Sep 26 14:50:09 2010 From: vineetdaniel at gmail.com (vineet daniel) Date: Sun, 26 Sep 2010 11:50:09 -0700 (PDT) Subject: creating python daemon ? References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> <87fwx2yw04.fsf@web.de> <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> <4C9F1052.9050700@sschwarzer.net> Message-ID: <444fcb6f-c4ae-467a-946f-f60107119c6a@e34g2000prn.googlegroups.com> On Sep 26, 2:20?pm, Stefan Schwarzer wrote: > Hi Daniel, > > On 2010-09-23 07:30, vineet daniel wrote: > > > > > On Sep 22, 2:20 pm, de... at web.de (Diez B. Roggisch) wrote: > >> vineet daniel writes: > >>> On Sep 21, 9:47 pm, de... at web.de (Diez B. Roggisch) wrote: > >>>> vineet daniel writes: > >>>>> code that I am using is as follows : > > >>>>> #! /usr/bin/env python > >>>>> import sys,os > >>>>> pid = os.fork() > >>>>> os.chdir("/var/www/html/") > >>>>> os.setsid() > >>>>> os.umask(0) > >>>>> #this line will read apache log in real time as redirected from the > >>>>> CustomLog directive of Apache. > >>>>> log = sys.stdin.readlines() > >>>>> f = open('/var/www/logmongo.txt','a') # append log to this text file > >>>>> f.write(log) > > I guess you'll need some loop to process the input from > Apache. > > > There is a directive in Apache - CustomLog which can redirect logs to > > a script or another file by using Pipe. I googled about it and came to > > know that this works flawlessly with Perl as Apache treats Perl > > scripts as daemon, for Python to take input from Apache, it needs to > > work as daemon. Apache will then push its logs lines to this daemon as > > input. Perl takes this input as but python's stdin is not > > working as expected it just takes the file name as given in CustomLog > > directive using Pipe i.e if I use CustomLog '|/var/wwww/script.py' > > Are the _four_ ws intentional? > > > combined, what script reads is just the file name, how and why I am > > not able to figure it out. And thats the reason I am here. I hope > > you've got what I am trying to do. > > Do you have a line for the interpreter at the top of your > script, like > > #!/usr/bin/python > > Is the script executable (e. g. chmod +x script.py)? > > Stefan Hi Stefan The four w's is a typo error its just 'www' and using #!/usr/bin/env python.........yes script is executable. From arnodel at gmail.com Sun Sep 26 14:51:02 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 26 Sep 2010 19:51:02 +0100 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7xtylcx1is.fsf@ruckus.brouhaha.com> Message-ID: <871v8gmj8p.fsf@gmail.com> Paul Rubin writes: > Seebs writes: >> * It seems clear that, given two sequences x and y, "x + y" ought to >> be the concatenation of these sequences. >>... >> Helps, perhaps, that I got exposed to group theory early enough to be used >> to redefining + and * to be any two operations which have interesting >> properties*. > > But groups have only one of those operators, and when it's written as + > that usually means the group is commutative. So you wouldn't want + to > denote sequence concatenation. If + and * are both present, that sounds > like a ring, in which case you'd want "foo"*"bar" to work. It actually > seems to me that exponentiation makes more sense than multiplication > for turning "a" into "aaa". We think of aaa as what results from > writing "a" with "3" in the superscript position This is common notation in Computer Science. Word concatenation is often denoted multiplicatively (with the sign generally omitted) and so it follows naturally that exponentiation is used for repeated concatenation of a word with itself. This is also in keeping with group (or rather in in this case, monoid) theory notation where commutative group / monoid composition laws are denoted additively and non-commutative ones multiplicatively. So it would probably have been more in keeping with established mathematical / theoretical CS notation to write: "spam" * "eggs" instead of "spam" + "eggs" and "spam"**3 instead of "spam"*3 However it wouldn't prevent people from thinking about giving a meaning to e.g. "spam"**-2 -- Arnaud From xahlee at gmail.com Sun Sep 26 16:56:52 2010 From: xahlee at gmail.com (Xah Lee) Date: Sun, 26 Sep 2010 13:56:52 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <7xzkv5hvv0.fsf@ruckus.brouhaha.com> Message-ID: 2010-09-26 On Sep 25, 11:17?pm, Paul Rubin wrote: > Python solution follows (earlier one with an error cancelled). ?All > crossposting removed since crossposting is a standard trolling tactic. > > ? ? from collections import defaultdict > > ? ? def collect(xss): > ? ? ? ? d = defaultdict(list) > ? ? ? ? for xs in xss: > ? ? ? ? ? ? d[xs[0]].extend(xs[1:]) > ? ? ? ? return list(v for k,v in sorted(d.items())) > > ? ? y = [[0,'a','b'], [1,'c','d'], [2,'e','f'], [3,'g','h'], [1,'i','j'], > ? ? ? ? ?[2,'k','l'], [4,'m','n'], [2,'o','p'], [4,'q','r'], [5,'s','t']] > > ? ? print collect(y) Hi Paul, thanks for your solution, and thanks to many other who provided solutions. It'll take some time to go thru them. btw, i disagree about your remark on crossposting. For those interested, you can read in the following: ? ?Cross-posting & Language Factions? http://xahlee.org/Netiquette_dir/cross-post.html if anyone wants to argue with me about this, there's a my blog link at the bottom of the page where you can leave a comment. Feel free to use that. i'll go over the solutions and post if i have anything interesting to say. ? Possbly will select some to show on my site with credit of course. Xah ? xahlee.org ? From xahlee at gmail.com Sun Sep 26 17:03:40 2010 From: xahlee at gmail.com (Xah Lee) Date: Sun, 26 Sep 2010 14:03:40 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <12ku961maljpqr0vpecl4cc1m4r34addt6@4ax.com> Message-ID: <8055818b-a78d-4847-b39c-98c1edaa4b49@x20g2000pro.googlegroups.com> On Sep 26, 7:56?am, Sherm Pendley wrote: > J?rgen Exner writes: > > Alexander Burger wrote: > >>In PicoLisp: > > > What the f**** does PicoLisp have to with Perl? > > It's Xah. He cross-posts in an attempt to start a language feud. > > Please don't feed the troll. sorry i disagree. And please don't randomly accuse... I posted the following in reply to Paul Rubin's very valuable post, to comp.lang.python only. But since you cross-posted your accusation, and there are about 3 other posts of similar nature accusing me cross- posted to all groups, so am posting a response to all groups too. -------------------------------------------------- Paul, ... btw, i disagree about your remark on crossposting. For those interested, you can read in the following: ? ?Cross-posting & Language Factions? http://xahlee.org/Netiquette_dir/cross-post.html if anyone wants to argue with me about this, there's a my blog link at the bottom of the page where you can leave a comment. Feel free to use that. i'll go over the solutions and post if i have anything interesting to say. ? Possbly will select some to show on my site with credit of course. Xah ? xahlee.org ? From jbperez at gmail.com Sun Sep 26 17:29:03 2010 From: jbperez at gmail.com (Jon P.) Date: Sun, 26 Sep 2010 14:29:03 -0700 (PDT) Subject: xml.etree - why no HTMLTreeBuilder included? Message-ID: <48bc4eb7-5866-46f1-996c-715c65744a22@n19g2000prf.googlegroups.com> It is great that Fredrik Lundh's ElementTree is now a part of the Python Standard Library. However, Is it correct that if you want to use xml.etree.ElementTree to parse an HTML Document that you will have to install a separate HTMLTreeBuilder (e.g. TidyHTMLTreeBuilder) and that the only TreeBuilder objects that come with the Standard Library is the one for XML source? Seems like some kind of HTMLTreeBuilder ought to be included by default. For a script I'm doing which deals with HTML, I thought I could jettison lxml and use xml.etree instead, but since I would need to have to ask the end-user to install an external library anyways even if I use xml.etree, I switched back to lxml. From usenet at bitblocks.com Sun Sep 26 18:10:46 2010 From: usenet at bitblocks.com (Bakul Shah) Date: Sun, 26 Sep 2010 15:10:46 -0700 Subject: toy list processing problem: collect similar terms In-Reply-To: References: Message-ID: <4C9FC4E6.3030405@bitblocks.com> On 9/25/10 9:05 PM, Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) ... > anyone care to give a solution in Python, Perl, javascript, or other > lang? am guessing the scheme solution can be much improved... perhaps > using some lib but that seems to show scheme is pretty weak if the lib > is non-standard. In Q (from kx.com)[1]: x:((0; "a"; "b");(1; "c"; "d");(2; "e"; "f");(3; "g"; "h");(1; "i"; "j") (2; "k"; "l");(4; "m"; "n");(2; "o"; "p");(4; "q"; "r");(5; "s"; "t")) f:{each [,/] each [each [1 _]] x @ value group x[;0]} f x outputs "ab" "cdij" "efklop" "gh" "mnqr" "st" Note that this is actually a pretty general solution in that *all* the functions used in it operate on a variety of types. - The label could be anything, not just an integer. - What follows a label can be a list of anything. - Everything, except for = (the group function), has to do with *shaping* the output in the way you want. It is all basically cut-n-paste or pulling apart your Lego blocks and constructing a new toy from them! And most languages are really poor at that. *This* is why proponents of various languages should pay attention to such problems. ---- [1] In k3 (an older language from kx.com that you may be able to find online), x is the same but f is as follows: f:{,/'1_''x@=x[;0]} From jurgenex at hotmail.com Sun Sep 26 18:16:24 2010 From: jurgenex at hotmail.com (Jürgen Exner) Date: Sun, 26 Sep 2010 15:16:24 -0700 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> Message-ID: John Bokma wrote: >J?rgen Exner writes: > >> livibetter wrote: >>>Here is mine for Python: >> >> What the f*** does Python have to do with Perl? > >Clueless fuck. I unsubscribed from comp.lang.perl.misc to avoid the >retards like you and now you come in via the backdoor. If you have a >problem with Xah report him with Google Groups and with his hosting >provider 1&1 like I do. Dreamhost kicked him out that way. I have solved my problems with Xah years ago, that's what killfiles are for. And I have no idea why you are bringing up Xah in your current rant. It was livibetter who without any motivation or reasoning posted Python code in CLPM. If at least he had asked something like "How can I write something similar in Perl?" or _ANYTHING_ that would have made this even remotely meaningful for CLPM, then ok. But he didn't. He just dumped 7 lines of Python code to CLPM and his only comment was "Here is mine for Python". Yeah, great comment. Why would anyone in CLPM possibly care about those 7 lines of Phython code? jue jue From xahlee at gmail.com Sun Sep 26 18:20:33 2010 From: xahlee at gmail.com (Xah Lee) Date: Sun, 26 Sep 2010 15:20:33 -0700 (PDT) Subject: Unicode usenet posting. This is a test. References: Message-ID: On Sep 26, 5:40?am, Spiros Bousbouras wrote: > > And just for good measure, some ?European style quotes? and ?balanced smart > > quotes? which I intend some day to try to convince people to start using > > to eliminate the scourge of backslash escapes. ?But that's a topic for > > another day. > > I don't see how they would help to eliminate backslash escapes. Let's > imagine that strings were delimited by ? and ?. If you wanted a > string which contained a ? you would still need to escape it. I thought about these, but ultimately I don't think it is avoidable. However, using matching pairs eliminate many unnecessary escapes. For example in my recent essay about html6, I thought about the escape issue. Ultimately, if your content refers to the language itself, then you will need escapes, unless your language can switch to another quoting mechanism. For example, in perl: "this" 'this' q[this] q(this) q{this} print <<'xyzxyz'; this xyzxyz Are all equivalent. (technically except the last one which contains extra new line) Note that it has variable quoting chars. Similarly with Python. e.g. "this" 'this' """this""" '''this''' In python , the variability is less than perl. Now, suppose, if you need to quote perl code in perl itself or python in python. e.g. suppose you are writing a perl script that parse a perl snippet that contains all perl lang's quoting mechanisms, then, basically you'll start to need escapes. (worse when this is nested. A practical example that happens to me often is when writing a blog in html about using perl to parse html, and the html contains complex javascript or php, which may contain regex string, and you need to show the perl source code in html marked up syntax highlight.) in the study of symbolic logic, this is a form of self reference, and is a unavoidable problem (to not to have to escape chars yet still want the ability to quote the lang itself). the variable quoting chars also introduces some complexity. Namely, your lang at syntax level is no longer simple. e.g. in emacs lisp, whenever the symbol straight double quote appears, it has only one meaning (unless in special cases such as in comments or being escaped). Or, when you need to get strings in a lang, the only char you need to look for is double straight quote. In langs with variable quotes such as perl, this can no longer be true, in one or both ways. doesn't matter which is your philosophy in lang design with regards to quoting mechanism, unicode introduce many proper matching pairs that are helpful, and avoid multiple semantic meanings for a given char. in a similar way, this is one of my pet peeve in math notation and computer lang syntaxes. e.g. In Mathematica, paren is used for one single purpose only, always. Namely, grouping. The square bracket [] has one single purpose only, namely as bracket for function arguments. The curly brackets {} again has one single purpose only, as a syntax sugar for list, e.g. List[1,2] is the same as {1,2}. In traditional math notation and most comp langs, it's all context dependent soup. ? ?Strings in Perl and Python? http://xahlee.org/perl-python/quoting_strings.html ? ?Strings in PHP? http://xahlee.org/php/quoting_strings.html ? ?HTML6, Your HTML/XML Simplified? http://xahlee.org/comp/html6.html ? ?Matching Brackets in Unicode? http://xahlee.org/comp/unicode_matching_brackets.html Xah ? xahlee.org ? From flebber.crue at gmail.com Sun Sep 26 19:10:29 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 16:10:29 -0700 (PDT) Subject: Errors with PyPdf Message-ID: I was trying to use Pypdf following a recipe from the Activestate cookbooks. However I cannot get it too work. Unsure if it is me or it is beacuse sets are deprecated. I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- NET.pdf" You could use anything I was just testing with it. I was using the last script on that page that was most recently updated. I am using python 2.6. http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-converter/ import pyPdf def getPDFContent(path): content = "C:\Components-of-Dot-NET.pdf" # Load PDF into pyPDF pdf = pyPdf.PdfFileReader(file(path, "rb")) # Iterate pages for i in range(0, pdf.getNumPages()): # Extract text from page and add to content content += pdf.getPage(i).extractText() + "\n" # Collapse whitespace content = " ".join(content.replace(u"\xa0", " ").strip().split()) return content print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", "ignore") This is my error. >>> Warning (from warnings module): File "C:\Documents and Settings\Family\Application Data\Python \Python26\site-packages\pyPdf\pdf.py", line 52 from sets import ImmutableSet DeprecationWarning: the sets module is deprecated Traceback (most recent call last): File "C:/Python26/Pdfread", line 15, in print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", "ignore") File "C:/Python26/Pdfread", line 6, in getPDFContent pdf = pyPdf.PdfFileReader(file(path, "rb")) IOError: [Errno 2] No such file or directory: 'Components-of-Dot- NET.pdf' >>> From rhodri at wildebst.demon.co.uk Sun Sep 26 19:19:58 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 27 Sep 2010 00:19:58 +0100 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> Message-ID: On Sun, 26 Sep 2010 23:16:24 +0100, J?rgen Exner wrote: > I have solved my problems with Xah years ago, that's what killfiles are > for. And I have no idea why you are bringing up Xah in your current > rant. > > It was livibetter who without any motivation or reasoning posted Python > code in CLPM. If at least he had asked something like "How can I write > something similar in Perl?" or _ANYTHING_ that would have made this even > remotely meaningful for CLPM, then ok. > But he didn't. He just dumped 7 lines of Python code to CLPM and his > only comment was "Here is mine for Python". Yeah, great comment. Why > would anyone in CLPM possibly care about those 7 lines of Phython code? Check the Newsgroups line: this is a standard Xah "cross-post to everywhere in sight" troll. Hence (a) bringing up Xah, since he originated this thread, and (b) livibetter not thinking to trim the crossposts. Which you didn't either, I note. The only downside to killfiles is that you have to pay attention or you sometimes get bitten by this stuff. -- Rhodri James *-* Wildebeest Herder to the Masses From python at mrabarnett.plus.com Sun Sep 26 19:35:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 27 Sep 2010 00:35:20 +0100 Subject: Errors with PyPdf In-Reply-To: References: Message-ID: <4C9FD8B8.9050805@mrabarnett.plus.com> On 27/09/2010 00:10, flebber wrote: > I was trying to use Pypdf following a recipe from the Activestate > cookbooks. However I cannot get it too work. Unsure if it is me or it > is beacuse sets are deprecated. > The 'sets' module pre-dates the built-in 'set' class. The warning is just to inform you that the module will be removed in due course (it's still in Python 2.7, but not Python 3), so you can still use it in those versions. > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > NET.pdf" You could use anything I was just testing with it. > > I was using the last script on that page that was most recently > updated. I am using python 2.6. > > http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-converter/ > > import pyPdf > > def getPDFContent(path): > content = "C:\Components-of-Dot-NET.pdf" > # Load PDF into pyPDF > pdf = pyPdf.PdfFileReader(file(path, "rb")) > # Iterate pages > for i in range(0, pdf.getNumPages()): > # Extract text from page and add to content > content += pdf.getPage(i).extractText() + "\n" > # Collapse whitespace > content = " ".join(content.replace(u"\xa0", " ").strip().split()) > return content > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > > This is my error. > >>>> > > Warning (from warnings module): > File "C:\Documents and Settings\Family\Application Data\Python > \Python26\site-packages\pyPdf\pdf.py", line 52 > from sets import ImmutableSet > DeprecationWarning: the sets module is deprecated > > Traceback (most recent call last): > File "C:/Python26/Pdfread", line 15, in > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > File "C:/Python26/Pdfread", line 6, in getPDFContent > pdf = pyPdf.PdfFileReader(file(path, "rb")) > IOError: [Errno 2] No such file or directory: 'Components-of-Dot- > NET.pdf' >>>> You put the file in C:\, but you didn't tell Python where it is. You gave just the filename "Components-of-Dot-NET.pdf", and it's looking in the current directory, which probably isn't C:\. Try providing the full pathname: print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", "ignore") From w.g.sneddon at gmail.com Sun Sep 26 19:38:39 2010 From: w.g.sneddon at gmail.com (w.g.sneddon at gmail.com) Date: Sun, 26 Sep 2010 16:38:39 -0700 (PDT) Subject: Errors with PyPdf References: Message-ID: On Sep 26, 7:10?pm, flebber wrote: > I was trying to use Pypdf following a recipe from the Activestate > cookbooks. However I cannot get it too work. Unsure if it is me or it > is beacuse sets are deprecated. > > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > NET.pdf" You could use anything I was just testing with it. > > I was using the last script on that page that was most recently > updated. I am using python 2.6. > > http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > import pyPdf > > def getPDFContent(path): > ? ? content = "C:\Components-of-Dot-NET.pdf" > ? ? # Load PDF into pyPDF > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > ? ? # Iterate pages > ? ? for i in range(0, pdf.getNumPages()): > ? ? ? ? # Extract text from page and add to content > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > ? ? # Collapse whitespace > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > ? ? return content > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > > This is my error. > > > > Warning (from warnings module): > ? File "C:\Documents and Settings\Family\Application Data\Python > \Python26\site-packages\pyPdf\pdf.py", line 52 > ? ? from sets import ImmutableSet > DeprecationWarning: the sets module is deprecated > > Traceback (most recent call last): > ? File "C:/Python26/Pdfread", line 15, in > ? ? print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > ? File "C:/Python26/Pdfread", line 6, in getPDFContent > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot- > NET.pdf' > > > > Looks like a issue with finding the file. how do you pass the path? From es at ertes.de Sun Sep 26 19:41:37 2010 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Mon, 27 Sep 2010 01:41:37 +0200 Subject: toy list processing problem: collect similar terms References: Message-ID: <20100927014137.41627b49@tritium.streitmacht.eu> Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by a number. I > need to collect together the contents of all sublists sharing the same > label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > [...] > > anyone care to give a solution in Python, Perl, javascript, or other > lang? am guessing the scheme solution can be much improved... perhaps > using some lib but that seems to show scheme is pretty weak if the lib > is non-standard. In Haskell the solution looks like this: import qualified Data.Map as M import qualified Data.Set as S import Data.Map (Map) import Data.Set (Set) collect :: (Ord a, Ord k) => [Map k (Set a)] -> Map k (Set a) collect = M.unionsWith S.union Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ From es at ertes.de Sun Sep 26 19:47:59 2010 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Mon, 27 Sep 2010 01:47:59 +0200 Subject: toy list processing problem: collect similar terms References: <20100927014137.41627b49@tritium.streitmacht.eu> Message-ID: <20100927014759.2ccee77f@tritium.streitmacht.eu> Ertugrul S?ylemez wrote: > In Haskell the solution looks like this: > > [...] And before anyone starts to rant, I didn't pay attention to where I'm X-posting this stuff. Sorry for that. But on the other hand you could say that I'm giving the Perl people (apparently the only people feeling the urge to rant anyway) the chance to come up with a more elegant solution. =) Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ From rjngrj2010 at gmail.com Sun Sep 26 20:31:47 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sun, 26 Sep 2010 17:31:47 -0700 (PDT) Subject: Problems reading tif files Message-ID: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> Hi, I have read several related e-mails dating back as far as 2006. I am quite confused whether PIL can open tif images. Some posts seem to say there isn't yet any support for PIL while there are few posts where PIL has been able to open tif images. So I guess, I have to ask this probably trivial question again. I am just learning python and PIL. I have tiff images which are 8 bit and 16 bit gray scale images. I cannot open them. Here are the errors that I encounter. >> Image.open('filename') >> im.info (640, 480) {'resolution': (1, 1), 'compression': 'raw'} F;32BF TIFF But when I run the im.show() it gives the following error. >>> im.show() Traceback (most recent call last): File "", line 1, in im.show() File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 1483, in show _show(self, title=title, command=command) File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 2123, in _show apply(_showxv, (image,), options) File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 2127, in _showxv apply(ImageShow.show, (image, title), options) File "/usr/lib/python2.6/dist-packages/PIL/ImageShow.py", line 41, in show if viewer.show(image, title=title, **options): File "/usr/lib/python2.6/dist-packages/PIL/ImageShow.py", line 62, in show base = Image.getmodebase(image.mode) File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 245, in getmodebase return ImageMode.getmode(mode).basemode File "/usr/lib/python2.6/dist-packages/PIL/ImageMode.py", line 50, in getmode return _modes[mode] KeyError: 'F;32BF' I have no idea why this happens. I will appreciate a resolution. The file opens with ImageJ and ImageMagick. It is a 8-bit RGB file. I have associated default viewer to be ImageMagick. I am on Lucid Linux, and other programs such as F- spot and Gimp cannot open those files either. I don't yet know how to attach image files to the post so please bear with me till I figure that out. Thanks, gujax From flebber.crue at gmail.com Sun Sep 26 20:39:28 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 17:39:28 -0700 (PDT) Subject: Errors with PyPdf References: Message-ID: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> On Sep 27, 9:38?am, "w.g.sned... at gmail.com" wrote: > On Sep 26, 7:10?pm, flebber wrote: > > > I was trying to use Pypdf following a recipe from the Activestate > > cookbooks. However I cannot get it too work. Unsure if it is me or it > > is beacuse sets are deprecated. > > > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > > NET.pdf" You could use anything I was just testing with it. > > > I was using the last script on that page that was most recently > > updated. I am using python 2.6. > > >http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > > import pyPdf > > > def getPDFContent(path): > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > ? ? # Load PDF into pyPDF > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > ? ? # Iterate pages > > ? ? for i in range(0, pdf.getNumPages()): > > ? ? ? ? # Extract text from page and add to content > > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > > ? ? # Collapse whitespace > > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > ? ? return content > > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > > This is my error. > > > Warning (from warnings module): > > ? File "C:\Documents and Settings\Family\Application Data\Python > > \Python26\site-packages\pyPdf\pdf.py", line 52 > > ? ? from sets import ImmutableSet > > DeprecationWarning: the sets module is deprecated > > > Traceback (most recent call last): > > ? File "C:/Python26/Pdfread", line 15, in > > ? ? print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > ? File "C:/Python26/Pdfread", line 6, in getPDFContent > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> NET.pdf' > > Looks like a issue with finding the file. > how do you pass the path? okay thanks I thought that when I set content here def getPDFContent(path): content = "C:\Components-of-Dot-NET.pdf" that i was defining where it is. but yeah I updated script to below and it works. That is the contents are displayed to the interpreter. How do I output to a .txt file? import pyPdf def getPDFContent(path): content = "C:\Components-of-Dot-NET.pdf" # Load PDF into pyPDF pdf = pyPdf.PdfFileReader(file(path, "rb")) # Iterate pages for i in range(0, pdf.getNumPages()): # Extract text from page and add to content content += pdf.getPage(i).extractText() + "\n" # Collapse whitespace content = " ".join(content.replace(u"\xa0", " ").strip().split()) return content print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", "ignore") From lists at cheimes.de Sun Sep 26 21:19:28 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 27 Sep 2010 03:19:28 +0200 Subject: Problems reading tif files In-Reply-To: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> References: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> Message-ID: Am 27.09.2010 02:31, schrieb gujax: > Hi, > I have read several related e-mails dating back as far as 2006. I am > quite confused whether PIL can open tif images. Some posts seem to say > there isn't yet any support for PIL while there are few posts where > PIL has been able to open tif images. So I guess, I have to ask this > probably trivial question again. I am just learning python and PIL. I > have tiff images which are 8 bit and 16 bit gray scale images. I > cannot open them. Here are the errors that I encounter. PIL only supports a limited subset of TIFF files. Several compression algorithms like G3 and G4 fax compression are not supported yet. PIL may have a problem with partly broken TIFF files, too. > I have no idea why this happens. > I will appreciate a resolution. The file opens with ImageJ and > ImageMagick. It is a 8-bit RGB file. I have associated default viewer > to be ImageMagick. I am on Lucid Linux, and other programs such as F- > spot and Gimp cannot open those files either. > I don't yet know how to attach image files to the post so please bear > with me till I figure that out. Can you please post the output of tiffinfo for the specific file? It may give me a hint what's going wrong. There aren't a lot of good alternatives for image processing in Python. I've evaluated most of them and decided to write my own one for my employer. It's a Cython based library around FreeImage [1] and LCMS2 [2] and works very well. So far we have processed several million TIFF files with more than 100 TB of raw data smoothly. I've permission to release the software as open source but haven't found time to do a proper release. Christian Heimes [1] http://freeimage.sourceforge.net/ [2] http://www.littlecms.com/ From oddron at gmail.com Sun Sep 26 21:25:25 2010 From: oddron at gmail.com (Ronald Guida) Date: Sun, 26 Sep 2010 21:25:25 -0400 Subject: Python 2.7 installation problem In-Reply-To: References: Message-ID: Solved -- "make install" failed to actually install a subset of files. I had to manually copy them instead. Specifics: I started from /home/oddron/installers/python/Python-2.7/ and executed the usual commands: $ ./configure --prefix=$HOME $ make $ make install I have found that the installer failed to install the contents of "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", which contains *.so files. This explains why "import collections" would work from the built python in /home/oddron/installers/python/Python-2.7/, but would fail in the installed python in /home/oddron/bin/ . I manually copied the contents of "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", to /home/oddron/lib/python2.7/ and now everything seems to work. Thank you On Sun, Sep 26, 2010 at 2:19 AM, Ronald Guida wrote: > Hi, > > I am trying to perform a user-install of python 2.7 on Ubuntu 10.04, and my > installation is failing. > > This sequence of commands reproduces the failure on my system: > > $ tar -zxvf Python-2.7.tgz > $ cd Python-2.7/ > $ ./configure --prefix=$HOME > $ make > $ ./python Lib/test/test_collections.py > doctest (collections) ... 54 tests with zero failures > $ make altinstall > $ cd > $ which python2.7 > /home/oddron/bin/python2.7 > $ python2.7 > Python 2.7 (r27:82500, Sep 26 2010, 01:49:59) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import collections > Traceback (most recent call last): > File "", line 1, in > File "/home/oddron/lib/python2.7/collections.py", line 8, in > from _collections import deque, defaultdict > ImportError: No module named _collections > >>> import sys > >>> sys.path > ['', '/home/oddron/lib/python27.zip', '/home/oddron/lib/python2.7', > '/home/oddron/lib/python2.7/plat-linux2', > '/home/oddron/lib/python2.7/lib-tk', '/home/oddron/lib/python2.7/lib-old', > '/home/oddron/lib/python2.7/lib-dynload', > '/home/oddron/.local/lib/python2.7/site-packages', > '/home/oddron/lib/python2.7/site-packages'] > >>> > > > Things I have already checked: > * My path includes ~/bin > * None of PYTHONHOME and friends are set. > * I have also tried "make install" instead of "make altinstall", and I get > the same failure. > > Can anyone give me a hint regarding what has gone wrong? > > Thank you > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oddron at gmail.com Sun Sep 26 21:38:17 2010 From: oddron at gmail.com (Ronald Guida) Date: Sun, 26 Sep 2010 21:38:17 -0400 Subject: Python 2.7 installation problem In-Reply-To: References: Message-ID: Sorry, I have one additional piece of information that might be helpful to others. I have discovered that the *.so files that were not installed, were actually installed to the ~/lib/python2.6/ folder instead of the ~/lib/python2.7/ folder where they belong. On Sun, Sep 26, 2010 at 9:25 PM, Ronald Guida wrote: > Solved -- "make install" failed to actually install a subset of files. I > had to manually copy them instead. > > Specifics: > I started from /home/oddron/installers/python/Python-2.7/ and executed the > usual commands: > $ ./configure --prefix=$HOME > $ make > $ make install > > I have found that the installer failed to install the contents of > "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", > which contains *.so files. This explains why "import collections" would > work from > the built python in /home/oddron/installers/python/Python-2.7/, but would > fail in the installed > python in /home/oddron/bin/ . > > I manually copied the contents of > "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", > to /home/oddron/lib/python2.7/ and now everything seems to work. > > Thank you > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From flebber.crue at gmail.com Sun Sep 26 22:08:28 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 19:08:28 -0700 (PDT) Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> Message-ID: <06b51e31-4ecc-4e51-a323-3649b7dab12e@g21g2000prn.googlegroups.com> On Sep 27, 10:39?am, flebber wrote: > On Sep 27, 9:38?am, "w.g.sned... at gmail.com" > wrote: > > > > > On Sep 26, 7:10?pm, flebber wrote: > > > > I was trying to use Pypdf following a recipe from the Activestate > > > cookbooks. However I cannot get it too work. Unsure if it is me or it > > > is beacuse sets are deprecated. > > > > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > > > NET.pdf" You could use anything I was just testing with it. > > > > I was using the last script on that page that was most recently > > > updated. I am using python 2.6. > > > >http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > > > import pyPdf > > > > def getPDFContent(path): > > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > > ? ? # Load PDF into pyPDF > > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > > ? ? # Iterate pages > > > ? ? for i in range(0, pdf.getNumPages()): > > > ? ? ? ? # Extract text from page and add to content > > > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > > > ? ? # Collapse whitespace > > > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > > ? ? return content > > > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > > "ignore") > > > > This is my error. > > > > Warning (from warnings module): > > > ? File "C:\Documents and Settings\Family\Application Data\Python > > > \Python26\site-packages\pyPdf\pdf.py", line 52 > > > ? ? from sets import ImmutableSet > > > DeprecationWarning: the sets module is deprecated > > > > Traceback (most recent call last): > > > ? File "C:/Python26/Pdfread", line 15, in > > > ? ? print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > > "ignore") > > > ? File "C:/Python26/Pdfread", line 6, in getPDFContent > > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > > ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> NET.pdf' > > > Looks like a issue with finding the file. > > how do you pass the path? > > okay thanks I thought that when I set content here > > def getPDFContent(path): > ? ? content = "C:\Components-of-Dot-NET.pdf" > > that i was defining where it is. > > but yeah I updated script to below and it works. That is the contents > are displayed to the interpreter. How do I output to a .txt file? > > import pyPdf > > def getPDFContent(path): > ? ? content = "C:\Components-of-Dot-NET.pdf" > ? ? # Load PDF into pyPDF > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > ? ? # Iterate pages > ? ? for i in range(0, pdf.getNumPages()): > ? ? ? ? # Extract text from page and add to content > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > ? ? # Collapse whitespace > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > ? ? return content > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > "ignore") I have found far more advanced scripts searching around. But will have to keep trying as I cannot get an output file or specify the path. Edit very strangely whilst searching for examples I found my own post just written here ranking number 5 on google within 2 hours. Bizzare. http://www.eggheadcafe.com/software/aspnet/36237766/errors-with-pypdf.aspx Replicates our thread as thiers. I was searching ggole with "pypdf return to txt file" From flebber.crue at gmail.com Sun Sep 26 22:19:40 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 19:19:40 -0700 (PDT) Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> <06b51e31-4ecc-4e51-a323-3649b7dab12e@g21g2000prn.googlegroups.com> Message-ID: On Sep 27, 12:08?pm, flebber wrote: > On Sep 27, 10:39?am, flebber wrote: > > > > > On Sep 27, 9:38?am, "w.g.sned... at gmail.com" > > wrote: > > > > On Sep 26, 7:10?pm, flebber wrote: > > > > > I was trying to use Pypdf following a recipe from the Activestate > > > > cookbooks. However I cannot get it too work. Unsure if it is me or it > > > > is beacuse sets are deprecated. > > > > > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > > > > NET.pdf" You could use anything I was just testing with it. > > > > > I was using the last script on that page that was most recently > > > > updated. I am using python 2.6. > > > > >http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > > > > import pyPdf > > > > > def getPDFContent(path): > > > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > > > ? ? # Load PDF into pyPDF > > > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > > > ? ? # Iterate pages > > > > ? ? for i in range(0, pdf.getNumPages()): > > > > ? ? ? ? # Extract text from page and add to content > > > > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > > > > ? ? # Collapse whitespace > > > > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > > > ? ? return content > > > > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > > > "ignore") > > > > > This is my error. > > > > > Warning (from warnings module): > > > > ? File "C:\Documents and Settings\Family\Application Data\Python > > > > \Python26\site-packages\pyPdf\pdf.py", line 52 > > > > ? ? from sets import ImmutableSet > > > > DeprecationWarning: the sets module is deprecated > > > > > Traceback (most recent call last): > > > > ? File "C:/Python26/Pdfread", line 15, in > > > > ? ? print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > > > "ignore") > > > > ? File "C:/Python26/Pdfread", line 6, in getPDFContent > > > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > > > ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> NET.pdf' > > > > Looks like a issue with finding the file. > > > how do you pass the path? > > > okay thanks I thought that when I set content here > > > def getPDFContent(path): > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > > that i was defining where it is. > > > but yeah I updated script to below and it works. That is the contents > > are displayed to the interpreter. How do I output to a .txt file? > > > import pyPdf > > > def getPDFContent(path): > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > ? ? # Load PDF into pyPDF > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > ? ? # Iterate pages > > ? ? for i in range(0, pdf.getNumPages()): > > ? ? ? ? # Extract text from page and add to content > > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > > ? ? # Collapse whitespace > > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > ? ? return content > > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > I have found far more advanced scripts searching around. But will have > to keep trying as I cannot get an output file or specify the path. > > Edit very strangely whilst searching for examples I found my own post > just written here ranking number 5 on google within 2 hours. Bizzare. > > http://www.eggheadcafe.com/software/aspnet/36237766/errors-with-pypdf... > > Replicates our thread as thiers. I was searching ggole with "pypdf > return to txt file" Traceback (most recent call last): File "C:/Python26/Pdfread", line 16, in open('x.txt', 'w').write(content) NameError: name 'content' is not defined >>> When i use. import pyPdf def getPDFContent(path): content = "C:\Components-of-Dot-NET.txt" # Load PDF into pyPDF pdf = pyPdf.PdfFileReader(file(path, "rb")) # Iterate pages for i in range(0, pdf.getNumPages()): # Extract text from page and add to content content += pdf.getPage(i).extractText() + "\n" # Collapse whitespace content = " ".join(content.replace(u"\xa0", " ").strip().split()) return content print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", "ignore") open('x.txt', 'w').write(content) From python at mrabarnett.plus.com Sun Sep 26 22:49:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 27 Sep 2010 03:49:21 +0100 Subject: Errors with PyPdf In-Reply-To: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> Message-ID: <4CA00631.8090105@mrabarnett.plus.com> On 27/09/2010 01:39, flebber wrote: > On Sep 27, 9:38 am, "w.g.sned... at gmail.com" > wrote: >> On Sep 26, 7:10 pm, flebber wrote: >> >>> I was trying to use Pypdf following a recipe from the Activestate >>> cookbooks. However I cannot get it too work. Unsure if it is me or it >>> is beacuse sets are deprecated. >> >>> I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- >>> NET.pdf" You could use anything I was just testing with it. >> >>> I was using the last script on that page that was most recently >>> updated. I am using python 2.6. >> >>> http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... >> >>> import pyPdf >> >>> def getPDFContent(path): >>> content = "C:\Components-of-Dot-NET.pdf" >>> # Load PDF into pyPDF >>> pdf = pyPdf.PdfFileReader(file(path, "rb")) >>> # Iterate pages >>> for i in range(0, pdf.getNumPages()): >>> # Extract text from page and add to content >>> content += pdf.getPage(i).extractText() + "\n" >>> # Collapse whitespace >>> content = " ".join(content.replace(u"\xa0", " ").strip().split()) >>> return content >> >>> print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", >>> "ignore") >> >>> This is my error. >> >>> Warning (from warnings module): >>> File "C:\Documents and Settings\Family\Application Data\Python >>> \Python26\site-packages\pyPdf\pdf.py", line 52 >>> from sets import ImmutableSet >>> DeprecationWarning: the sets module is deprecated >> >>> Traceback (most recent call last): >>> File "C:/Python26/Pdfread", line 15, in >>> print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", >>> "ignore") >>> File "C:/Python26/Pdfread", line 6, in getPDFContent >>> pdf = pyPdf.PdfFileReader(file(path, "rb")) >> >> ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> NET.pdf' >> >> Looks like a issue with finding the file. >> how do you pass the path? > > okay thanks I thought that when I set content here > > def getPDFContent(path): > content = "C:\Components-of-Dot-NET.pdf" > > that i was defining where it is. > > but yeah I updated script to below and it works. That is the contents > are displayed to the interpreter. How do I output to a .txt file? > > import pyPdf > > def getPDFContent(path): > content = "C:\Components-of-Dot-NET.pdf" That simply binds to a local name; 'content' is a local variable in the function 'getPDFContent'. > # Load PDF into pyPDF > pdf = pyPdf.PdfFileReader(file(path, "rb")) You're opening a file whose path is in 'path'. > # Iterate pages > for i in range(0, pdf.getNumPages()): > # Extract text from page and add to content > content += pdf.getPage(i).extractText() + "\n" That appends to 'content'. > # Collapse whitespace 'content' now contains the text of the PDF, starting with r"C:\Components-of-Dot-NET.pdf". > content = " ".join(content.replace(u"\xa0", " ").strip().split()) > return content > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > Outputting to a .txt file is simple: open the file for writing using 'open', write the string to it, and then close it. From flebber.crue at gmail.com Sun Sep 26 22:56:40 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 19:56:40 -0700 (PDT) Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> Message-ID: On Sep 27, 12:49?pm, MRAB wrote: > On 27/09/2010 01:39, flebber wrote: > > > > > On Sep 27, 9:38 am, "w.g.sned... at gmail.com" > > wrote: > >> On Sep 26, 7:10 pm, flebber ?wrote: > > >>> I was trying to use Pypdf following a recipe from the Activestate > >>> cookbooks. However I cannot get it too work. Unsure if it is me or it > >>> is beacuse sets are deprecated. > > >>> I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > >>> NET.pdf" You could use anything I was just testing with it. > > >>> I was using the last script on that page that was most recently > >>> updated. I am using python 2.6. > > >>>http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > >>> import pyPdf > > >>> def getPDFContent(path): > >>> ? ? ?content = "C:\Components-of-Dot-NET.pdf" > >>> ? ? ?# Load PDF into pyPDF > >>> ? ? ?pdf = pyPdf.PdfFileReader(file(path, "rb")) > >>> ? ? ?# Iterate pages > >>> ? ? ?for i in range(0, pdf.getNumPages()): > >>> ? ? ? ? ?# Extract text from page and add to content > >>> ? ? ? ? ?content += pdf.getPage(i).extractText() + "\n" > >>> ? ? ?# Collapse whitespace > >>> ? ? ?content = " ".join(content.replace(u"\xa0", " ").strip().split()) > >>> ? ? ?return content > > >>> print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > >>> "ignore") > > >>> This is my error. > > >>> Warning (from warnings module): > >>> ? ?File "C:\Documents and Settings\Family\Application Data\Python > >>> \Python26\site-packages\pyPdf\pdf.py", line 52 > >>> ? ? ?from sets import ImmutableSet > >>> DeprecationWarning: the sets module is deprecated > > >>> Traceback (most recent call last): > >>> ? ?File "C:/Python26/Pdfread", line 15, in > >>> ? ? ?print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > >>> "ignore") > >>> ? ?File "C:/Python26/Pdfread", line 6, in getPDFContent > >>> ? ? ?pdf = pyPdf.PdfFileReader(file(path, "rb")) > > >> ---> ?IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> ?NET.pdf' > > >> Looks like a issue with finding the file. > >> how do you pass the path? > > > okay thanks I thought that when I set content here > > > def getPDFContent(path): > > ? ? ?content = "C:\Components-of-Dot-NET.pdf" > > > that i was defining where it is. > > > but yeah I updated script to below and it works. That is the contents > > are displayed to the interpreter. How do I output to a .txt file? > > > import pyPdf > > > def getPDFContent(path): > > ? ? ?content = "C:\Components-of-Dot-NET.pdf" > > That simply binds to a local name; 'content' is a local variable in the > function 'getPDFContent'. > > > ? ? ?# Load PDF into pyPDF > > ? ? ?pdf = pyPdf.PdfFileReader(file(path, "rb")) > > You're opening a file whose path is in 'path'. > > > ? ? ?# Iterate pages > > ? ? ?for i in range(0, pdf.getNumPages()): > > ? ? ? ? ?# Extract text from page and add to content > > ? ? ? ? ?content += pdf.getPage(i).extractText() + "\n" > > That appends to 'content'. > > > ? ? ?# Collapse whitespace > > 'content' now contains the text of the PDF, starting with > r"C:\Components-of-Dot-NET.pdf". > > > ? ? ?content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > ? ? ?return content > > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > Outputting to a .txt file is simple: open the file for writing using > 'open', write the string to it, and then close it. Thats what I was trying to do with open('x.txt', 'w').write(content) the rest of the script works it wont output the tect though From timr at probo.com Sun Sep 26 23:12:14 2010 From: timr at probo.com (Tim Roberts) Date: Sun, 26 Sep 2010 20:12:14 -0700 Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> Message-ID: flebber wrote: > >okay thanks I thought that when I set content here > >def getPDFContent(path): > content = "C:\Components-of-Dot-NET.pdf" You have a backslash problem here. You need need to say: content = "C:\\Components-of-Dot-NET.pdf" or content = "C:/Components-of-Dot-NET.pdf" or content = "C:/Components-of-Dot-NET.pdf" -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From research at johnohagan.com Sun Sep 26 23:41:13 2010 From: research at johnohagan.com (John O'Hagan) Date: Mon, 27 Sep 2010 03:41:13 +0000 Subject: Calling an arbitrary function with the right arguments Message-ID: <201009270341.14372.research@johnohagan.com> How to call a function with the right arguments without knowing in advance which function? For example: import random def f1(): pass def f2(foo): pass def f3(foo, bar): pass foo=random.choice((1,2,3)) bar=random.choice((1,2,3)) myfunc=random.choice((f1, f2, f3)) How to call myfunc with the right arguments? I've been doing it this way: f1.args=() f2.args=('foo',) f3.args=('foo', 'bar') args=[vars()[i] for i in myfunc.args] myfunc(*args) But it seems redundant to manually tag the functions with their own arguments' names, and I don't like using vars(). Is there a nicer pattern? Regards, John From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 00:10:46 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 27 Sep 2010 04:10:46 GMT Subject: Calling an arbitrary function with the right arguments References: Message-ID: <4ca01946$0$28670$c3e8da3@news.astraweb.com> On Mon, 27 Sep 2010 03:41:13 +0000, John O'Hagan wrote: > How to call a function with the right arguments without knowing in > advance which function? For example: > > import random > > def f1(): > pass > > def f2(foo): > pass > > def f3(foo, bar): > pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) > > myfunc=random.choice((f1, f2, f3)) > > How to call myfunc with the right arguments? If f1, f2 and f3 require different arguments, it's not sensible to expect them to be interchangeable. The right way to do this is to re-write the functions so they all have the same call signature (even if that is just to ignore unnecessary arguments). Or wrap the functions (perhaps using functools.partial) so they don't need the extra args. f3 = lambda f=f3: f(foo, bar) f2 = lambda f=f2: f(foo) Either way, there's a reason you never see callback functions that accept arbitrary arguments. They always have a standard, fixed argument list. -- Steven From clp2 at rebertia.com Mon Sep 27 00:19:23 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 26 Sep 2010 21:19:23 -0700 Subject: Calling an arbitrary function with the right arguments In-Reply-To: <201009270341.14372.research@johnohagan.com> References: <201009270341.14372.research@johnohagan.com> Message-ID: On Sun, Sep 26, 2010 at 8:41 PM, John O'Hagan wrote: > How to call a function with the right arguments without knowing in advance > which function? For example: > > import random > > def f1(): > ? ?pass > > def f2(foo): > ? ?pass > > def f3(foo, bar): > ? ?pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) > > myfunc=random.choice((f1, f2, f3)) > > How to call myfunc with the right arguments? > I've been doing it this way: > > f1.args=() > f2.args=('foo',) > f3.args=('foo', 'bar') > > args=[vars()[i] for i in myfunc.args] > > myfunc(*args) > > But it seems redundant to manually tag the functions with their own arguments' > names, and I don't like using vars(). Is there a nicer pattern? Yes; as Steven said, just define the functions so they all have the same signature in the first place and simply ignore any inapplicable arguments. However, alternatively, you could use inspect.getargspec() (http://docs.python.org/library/inspect.html#inspect.getargspec ) to figure out what arguments each functions needs. I do not actually recommend this method, but merely mention it for completeness. Cheers, Chris -- http://blog.rebertia.com From rplasson at gmail.com Mon Sep 27 00:20:56 2010 From: rplasson at gmail.com (=?ISO-8859-1?Q?Rapha=EBl_Plasson?=) Date: Sun, 26 Sep 2010 21:20:56 -0700 (PDT) Subject: Simple interface to minidom for creating XML files Message-ID: <2c6116b4-1c7d-4afa-b9a0-38ef6787c446@y32g2000prc.googlegroups.com> Hello, I want to create some XML files, following a simple template. For that purpose, I created a simple interface to minidom. This is simple code, but as I spend a little time for understanding how minidom was working, I thought that this may be useful for someone (not that minidom is complex, but even if simplified from the full XML implementation, it still possesses too many functions for what I simply wanted to do). What you have to do is just to import the class doc, and then: In [258]: xml=doc("toto") In [259]: xml["part1"]=None In [260]: xml["part1"]["1.1"]="coucou" In [261]: xml["part1"]["1.2"]="toto" In [262]: xml["part1"]["1.2"]["1.2.1"]="a" In [263]: xml["part1"]["1.2"]["1.2.2"]="b" In [264]: xml["part2"]="That's all folks!" In [265]: xml["part1"]["1.2"]["1.2.2"]="really b" In [266]: xml["part1"]["cdata"]="This is\nMore complex data\n:-p\n" In [267]: xml.write("test.xml") is sufficient to obtain the following file: <1.1> coucou <1.2> toto <1.2.1> a <1.2.2> really b That's all folks! This piece of code is way too small for being considered as a real package, but it may help someone. Thus, I am just posting it here so that it doesn't get lost. Please feel free to use it and extend it as will (I put a GPL licence in that purpose). If you have some comments/suggestion about this code, I would also be happy to discuss about it :). Rapha?l Here is the code: 8x----------------------------------------------------------------------- x8 # Copyright 2010 Raphael Plasson, rplasson_at_gmail_dot_com # # This program is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from xml.dom.minidom import Document class node: def __init__(self,name,parent,doc): '''Add a node called to the document inside the node ''' self.name=name self.parent=parent self.doc=doc self.element=self.doc.createElement(self.name) self.parent.element.appendChild(self.element) self.children={} def __getitem__(self,key): return self.children[key] def __setitem__(self,key,val): if key=="text": self.set_text(val) elif key=="cdata": self.set_cdata(val) else: tmp=self.set_node(key) if val != None: tmp.set_text(val) def __repr__(self): tmp=self.name+" : " for i in self.children: tmp += i+", " return tmp def __newchild(self,child,name): self.children[name] = child def set_node(self,name): '''Add a node . If a node with the same name already exists, it is simply returned.''' if self.children.has_key(name): return self.children[name] else: tmp=node(name,self,self.doc) self.__newchild(tmp,name) return tmp def set_text(self,text): '''Add or update the node text ''' if self.children.has_key("text"): self.children["text"].data=text else: tmp=self.doc.createTextNode(text) self.__newchild(tmp,"text") self.element.appendChild(tmp) def set_cdata(self,cdata): '''Add or update the node cdata ''' if self.children.has_key("cdata"): self.children["cdata"].data=cdata else: tmp=self.doc.createCDATASection(cdata) self.__newchild(tmp,"cdata") self.element.appendChild(tmp) self.element.appendChild(self.doc.createTextNode("")) # dirty hack for adding newline after CDATA in file def set_attr(self,attr,val): '''Add or set the attribute to ''' self.element.setAttribute(attr,val) def comment(self,comm): '''Add the comment ''' self.element.appendChild(self.doc.createComment(comm)) class doc(node): def __init__(self,name): ''' Create an xml document, with root node ''' self.name=name self.parent=None self.doc=Document() self.element=self.doc.createElement(self.name) self.doc.appendChild(self.element) self.children={} self.text="" def write(self,filename): ''' Write the xml document to ''' out=file(filename,"w") self.doc.writexml(out, newl="\n", addindent=" ") out.close() 8x----------------------------------------------------------------------- x8 From davea at ieee.org Mon Sep 27 00:46:18 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 27 Sep 2010 00:46:18 -0400 Subject: Errors with PyPdf In-Reply-To: References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> <06b51e31-4ecc-4e51-a323-3649b7dab12e@g21g2000prn.googlegroups.com> Message-ID: <4CA0219A.2030601@ieee.org> On 2:59 PM, flebber wrote: > > Traceback (most recent call last): > File "C:/Python26/Pdfread", line 16, in > open('x.txt', 'w').write(content) > NameError: name 'content' is not defined > When i use. > > import pyPdf > > def getPDFContent(path): > content =C:\Components-of-Dot-NET.txt" > # Load PDF into pyPDF > pdf =yPdf.PdfFileReader(file(path, "rb")) > # Iterate pages > for i in range(0, pdf.getNumPages()): > # Extract text from page and add to content > content +=df.getPage(i).extractText() + "\n" > # Collapse whitespace > content = ".join(content.replace(u"\xa0", " ").strip().split()) > return content > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > open('x.txt', 'w').write(content) > There's no global variable content, that was local to the function. So it's lost when the function exits. it does return the value, but you give it to print, and don't save it anywhere. data = getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", "ignore") outfile = open('x.txt', 'w') outfile.write(data) close(outfile) I used a different name to emphasize that this is *not* the same variable as content inside the function. In this case, it happens to have the same value. And if you used the same name, you could be confused about which is which. DaveA From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 00:46:30 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 27 Sep 2010 04:46:30 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: <4ca021a6$0$28670$c3e8da3@news.astraweb.com> On Sun, 26 Sep 2010 01:16:49 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? The first one would be a reasonable design choice, although less useful than what Python does. Instead of: rule = "="*12 you would need to write: rule = ''.join("="*12) which is a pain. The second one is just a lousy design. If you ask for three sheep, you expect three sheep, not three sheep heads, plus three sheep tails, plus three sheep left-front legs, plus... "ssspppaaammm" fails the Principle of Least Surprise. For any positive n, you would expect: "spam" in ("spam"*n) to return True. "ssspppaaammm" fails this test. > Should "spam"*2.5 be "spamspamsp"? Trying to determine a fraction of a string is troublesome... what is 1/100th of "abcde"? Some fraction of the letter "a"? What does that even mean? The question has no sensible answer, in the same way that asking for the real-valued square-root of -1 has no sensible answer. Unlike real numbers, which are easily extended to complex values, there's no obvious extension of strings to include fractions of characters. So the only sensible thing is to say that fractions of strings doesn't have any meaning. When faced with "spam"*2.5, you can either raise an exception (as Python does), or truncate the second argument to an integer value. Which you do is a matter of taste, although I'd argue in favour of truncation. > Should "spam"-"a" be "spm"? What about "spamspam"-"a"? And what about > "spam"/2? "sp" be an ok first guess, but "sa" might make more sense (it > means (1,2,3,...)/2 would be (1,3,5...)). What makes you think that "spam" - "a" should be anything at all? Just because an operator exists doesn't mean it *has* to be defined for every possible data set. You're over-thinking this. Repetition of sequences is simple and straight-forward. Trying to come up with complicated analogues to arbitrary real-number operators is a waste of time and effort. That is exactly the sort of nonsense that I already agreed should be avoided. -- Steven From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 01:17:27 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 27 Sep 2010 05:17:27 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4ca028e6$0$28670$c3e8da3@news.astraweb.com> On Sun, 26 Sep 2010 09:30:08 +0000, Seebs wrote: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", >> and the fact that it doesn't do the same thing as int("spam")*3 is a >> foolish argument. > > The languages in which it's surprising are mostly things like perl, > where there's a certain amount of implicit coercion going on, so it's > ambiguous whether "3"*3 ought to mean "333" or 9. (Except it isn't, > because repetition is a separate operator, written "3" x 3 rather than > "3" * 3...) People coming from that kind of background may be expecting > * to stay an arithmetic operator, rather than having it change form when > applied to non-arithmetic objects. And people with no programming background at all will be surprised that * and x aren't two different symbols for the same operation. > I'm not sure either way. I think on the whole, I like the notion of a > repetition operator which is distinct from multiplication, but I also > definitely prefer the lack of implicit coercion, and without implicit > coercion, there's a lot less underlying ambiguity to worry about. > > From the top, I guess my analysis is: > > * It seems clear that, given two sequences x and y, "x + y" ought to > be the concatenation of these sequences. > * Thus, "x + x" should be x concatenated to itself. * Idiomatically, it > is not unreasonable to assert that "x * 2" and "x + x" > could be the same value. > * It thus makes some sense for * to indicate > repetition of the sequence. > * Since a string is a kind of a sequence, it also makes sense for > * to indicate repetition. My analysis as well, except that I see repetition (repeated concatenation/ addition) as more fundamental than multiplication. Think about being back in primary school, where you learn to do this: 21 21 +21 ---- 63 before you learned this: 21 x3 ---- 63 > So I think I'm pretty much convinced that Python's behavior makes sense, > but it makes sense only because I'm going into this expecting operators > to be defined by types, so I don't expect every '*' to mean > 'multiplication'. Perhaps you should say "real-valued multiplication" rather than just multiplication, because of course matrix multiplication A*B behaves quite differently from integer multiplication a*b as well. > Helps, perhaps, that I got exposed to group theory early enough to be > used to redefining + and * to be any two operations which have > interesting properties*. > > -s > [*] What's purple and commutes? An abelian grape. Heh :) -- Steven From farkmor at gmail.com Mon Sep 27 02:56:11 2010 From: farkmor at gmail.com (Tim Diels) Date: Mon, 27 Sep 2010 08:56:11 +0200 Subject: Python3: API Documentation generator Message-ID: <4CA0400B.7000405@gmail.com> Hi all I've just switched to python3 and it turns out my current API documentation generator (epydoc) no longer works. I am looking for a tool that reads the docstrings of all classes, ... in my project and turns it into HTML documentation. Thanks for your time limyreth From clp2 at rebertia.com Mon Sep 27 03:02:03 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 27 Sep 2010 00:02:03 -0700 Subject: Python3: API Documentation generator In-Reply-To: <4CA0400B.7000405@gmail.com> References: <4CA0400B.7000405@gmail.com> Message-ID: On Sun, Sep 26, 2010 at 11:56 PM, Tim Diels wrote: > ?Hi all > > I've just switched to python3 and it turns out my current API documentation > generator (epydoc) no longer works. I am looking for a tool that reads the > docstrings of all classes, ... in my project and turns it into HTML > documentation. Sphinx (http://sphinx.pocoo.org/ ) is the new gold standard. You'll want to enable the `autodoc` extension: http://sphinx.pocoo.org/ext/autodoc.html Cheers, Chris -- http://blog.rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 27 04:19:19 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 27 Sep 2010 10:19:19 +0200 Subject: Calling an arbitrary function with the right arguments In-Reply-To: References: Message-ID: <4ca05388$0$23138$426a74cc@news.free.fr> John O'Hagan a ?crit : > How to call a function with the right arguments without knowing in advance > which function? (snip) For most use case I can think of, I can only second Steven and Chris - if your functions are interchangeable then they should have a same API. Now there's at least one use case I know where you need to dynamically select a function then build the right arguments set for it: when mapping urls to http request handler functions. There's a good example in Django's url to "view" mapping system. From __peter__ at web.de Mon Sep 27 04:42:02 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 27 Sep 2010 10:42:02 +0200 Subject: Calling an arbitrary function with the right arguments References: Message-ID: John O'Hagan wrote: > How to call a function with the right arguments without knowing in advance > which function? For example: > > import random > > def f1(): > pass > > def f2(foo): > pass > > def f3(foo, bar): > pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) > > myfunc=random.choice((f1, f2, f3)) > > How to call myfunc with the right arguments? > I've been doing it this way: > > f1.args=() > f2.args=('foo',) > f3.args=('foo', 'bar') > > args=[vars()[i] for i in myfunc.args] > > myfunc(*args) > > But it seems redundant to manually tag the functions with their own > arguments' names, and I don't like using vars(). Is there a nicer pattern? You can use inspect.getargspec() to determine the argument names: args = [vars()[argname] for argname in inspect.getargspec(myfunc).args] From jeanmichel at sequans.com Mon Sep 27 05:08:05 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 27 Sep 2010 11:08:05 +0200 Subject: Calling an arbitrary function with the right arguments In-Reply-To: <201009270341.14372.research@johnohagan.com> References: <201009270341.14372.research@johnohagan.com> Message-ID: <4CA05EF5.4040507@sequans.com> John O'Hagan wrote: > How to call a function with the right arguments without knowing in advance > which function? For example: > > import random > > def f1(): > pass > > def f2(foo): > pass > > def f3(foo, bar): > pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) > > myfunc=random.choice((f1, f2, f3)) > > How to call myfunc with the right arguments? > I've been doing it this way: > > f1.args=() > f2.args=('foo',) > f3.args=('foo', 'bar') > > args=[vars()[i] for i in myfunc.args] > > myfunc(*args) > > But it seems redundant to manually tag the functions with their own arguments' > names, and I don't like using vars(). Is there a nicer pattern? > > Regards, > > John > > Hi, func, args = random.choice(((f1, ()), (f2, (foo,)), (f3, (foo, bar)))) func(*args) JM From alexxx.magni at gmail.com Mon Sep 27 05:23:12 2010 From: alexxx.magni at gmail.com (Alessandro) Date: Mon, 27 Sep 2010 02:23:12 -0700 (PDT) Subject: check path.exists() with a "converted" path Message-ID: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Hi, I'm a python newbie with a problem too hard to tackle. I have a string defining a path, were all the spaces have been converted to underscores. How can I find if it corresponds to a real path? e.g. a string like '/some/path_to/directory_1/and_to/directory_2' with a real path: '/some/path_to/directory 1/and_to/directory 2' notice that the real path can contain BOTH spaces and underscores. How can I feed it to os.path.exists() ??? thanks alessandro From clp2 at rebertia.com Mon Sep 27 05:35:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 27 Sep 2010 02:35:24 -0700 Subject: check path.exists() with a "converted" path In-Reply-To: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: On Mon, Sep 27, 2010 at 2:23 AM, Alessandro wrote: > Hi, I'm a python newbie with a problem too hard to tackle. > > I have a string defining a path, were all the spaces have been > converted to underscores. > How can I find if it corresponds to a real path? > > e.g. a string like '/some/path_to/directory_1/and_to/directory_2' > with a real path: '/some/path_to/directory 1/and_to/directory 2' > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ??? Use the `glob` module instead: http://docs.python.org/library/glob.html from glob import glob real_paths = glob(underscored_path.replace('_','[_ ]')) #note: it's possible for there to be multiple matches Cheers, Chris -- http://blog.rebertia.com From paul.nospam at rudin.co.uk Mon Sep 27 05:35:44 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 27 Sep 2010 10:35:44 +0100 Subject: check path.exists() with a "converted" path References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: <87tylbfs0f.fsf@rudin.co.uk> Alessandro writes: > Hi, I'm a python newbie with a problem too hard to tackle. > > I have a string defining a path, were all the spaces have been > converted to underscores. > How can I find if it corresponds to a real path? > > e.g. a string like '/some/path_to/directory_1/and_to/directory_2' > with a real path: '/some/path_to/directory 1/and_to/directory 2' > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ??? If you just have the converted string then you can't know what the original string is, you have no way of knowing which underscores were actually underscores in the original and which where spaces. You could generate all possible candidate original strings and check for file existence, but in general there are many different original strings that will yield the same converted string, possibly more than one of those corresponds to a file that exists. From __peter__ at web.de Mon Sep 27 05:43:49 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 27 Sep 2010 11:43:49 +0200 Subject: check path.exists() with a "converted" path References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: Alessandro wrote: > Hi, I'm a python newbie with a problem too hard to tackle. > > I have a string defining a path, were all the spaces have been > converted to underscores. > How can I find if it corresponds to a real path? > > e.g. a string like '/some/path_to/directory_1/and_to/directory_2' > with a real path: '/some/path_to/directory 1/and_to/directory 2' > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ??? $ mkdir -p aa{\ ,_}aa/bb{\ ,_}b{\ ,_}/c\ c $ tree . |-- aa aa | |-- bb b | | `-- c c | |-- bb b_ | | `-- c c | |-- bb_b | | `-- c c | `-- bb_b_ | `-- c c `-- aa_aa |-- bb b | `-- c c |-- bb b_ | `-- c c |-- bb_b | `-- c c `-- bb_b_ `-- c c 18 directories, 0 files $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import glob >>> path = "aa_aa/bb_b_/c_c" >>> glob.glob(path.replace("_", "[_ ]")) ['aa_aa/bb b_/c c', 'aa_aa/bb_b /c c', 'aa_aa/bb b /c c', 'aa_aa/bb_b_/c c', 'aa aa/bb b_/c c', 'aa aa/bb_b /c c', 'aa aa/bb b /c c', 'aa aa/bb_b_/c c'] I didn't want to throw away my demo just because your question was already anwered ;) Peter From rplasson at gmail.com Mon Sep 27 05:46:08 2010 From: rplasson at gmail.com (=?ISO-8859-1?Q?Rapha=EBl_Plasson?=) Date: Mon, 27 Sep 2010 02:46:08 -0700 (PDT) Subject: check path.exists() with a "converted" path References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: On Sep 27, 6:23?pm, Alessandro wrote: > > I have a string defining a path, were all the spaces have been > converted to underscores. > (...) > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ??? You are losing some information, there is no other choice to test all the combinations. Something like this should do the trick (/!\ quick and dirty solution /!\) def testpath(path): tmp=path.split("_") for i in range(2**(len(tmp)-1)): res="" for j in range(len(tmp)): if j>0: if (i & 2**(j-1))==0: res += " " else: res += "_" res+=tmp[j] if os.path.exists(res): return True return False Raphael From alexxx.magni at gmail.com Mon Sep 27 05:51:07 2010 From: alexxx.magni at gmail.com (Alessandro) Date: Mon, 27 Sep 2010 02:51:07 -0700 (PDT) Subject: check path.exists() with a "converted" path References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: people, you're great - best newsgroup I've ever been! I think I'll go with the glob suggestion - works like a charm!!! thank you... alessandro From matth at netsight.co.uk Mon Sep 27 06:48:46 2010 From: matth at netsight.co.uk (Matt Hamilton) Date: Mon, 27 Sep 2010 10:48:46 +0000 (UTC) Subject: Plone Conference 2010 schedule published Message-ID: Over 400 attendees are set to meet at the 8th annual Plone Conference for a week-long programme of training, talks and developer sprints from the 25th to 31st October at the Thistle Grand Hotel in Bristol, UK. Plone Conference 2010 registrations are open. Plone, an Open Source Content Management System used throughout the world has a massive following and Plone events are held around the globe. The largest of these is the annual Plone Conference and this year will be held in the UK. Plone is used for developing websites, intranet and portals for corporations, NGOs and the public sector. Organised by Netsight Internet Solutions, it promises to bring together developers, designers, end users and business people. This year an additional event is being planned as a one-day mini-conference on the 26th October called "Plone in Business" which will be aimed specifically at analysts, advisors, evaluators and information professionals looking to find out more about Plone and see a showcase of successful Plone projects from across the sectors. It will also see the launch of the JBoye Plone Community of Practice. The main part of the conference, from the 27th - 29th October, has over 50 scheduled talks from speakers from 19 countries and includes an 'unconference' day in which talks will be proposed by the attendees. Plone Conference 2010 scheduled talks include: * Easier and faster Plone theming with Deliverance * Design and Development with Dexterity * Enterprise Search in Plone with Solr * Boosting productivity with "Plone-driven Plone development" * Brasil.gov.br: Building a digital nation with Plone Alan Runyan, co-founder of Plone and president of Enfold Systems along with Alex Limi, fellow co-founder of Plone and now Firefox User Experience Lead at Mozilla will be delivering a keynote. There will also be a guest keynote by Richard Noble, OBE, project director of the Bloodhound SSC project attempting be build a car to pass the 1,000mph land speed mark. The conference falls at a great time, with the recent release of Plone 4, a product that raises the bar in the Content Management System market with a faster, more user-friendly and more refined version of the product. So far, registrations for the conference have come from over 30 countries around the world. To find out more about the conference and to register, visit http://ploneconf2010.org. -- Matt Hamilton matth at netsight.co.uk Netsight Internet Solutions, Ltd. Business Vision on the Internet http://www.netsight.co.uk +44 (0)117 9090901 Web Design | Zope/Plone Development and Consulting | Co-location | Hosting From Antoon.Pardon at rece.vub.ac.be Mon Sep 27 07:07:49 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 27 Sep 2010 13:07:49 +0200 Subject: Too much code - slicing In-Reply-To: <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> References: <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> Message-ID: <20100927110749.GB2272@rcpc42.vub.ac.be> On Thu, Sep 23, 2010 at 12:23:22AM +0000, Steven D'Aprano wrote: > On Tue, 21 Sep 2010 16:17:48 +0200, Antoon Pardon wrote: > > > On Tue, Sep 21, 2010 at 12:07:07AM +0000, Steven D'Aprano wrote: > >> On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: > >> > >> > Not necessarily. Some of us have the impression that Guido > >> > deliberatly chose an ugly format for the ternary operator. > >> > >> If he did, then he must have changed his mind, because there is nothing > >> ugly about the ternary operator we ended up with. > > > > That is a question of taste > > Yes, it certainly is. Describing it as "an ugly format" is also a matter > of taste -- taste which in my opinion simply isn't justified by anything > other than familiarity. There is the facts that it broke familiarity with a common pattern. > > This form only ranked fourth (or maybe third), with the first three all > > wanting ar structure with the elelement is this order: condition, true > > case, false case > > > >> > Guido has alwasys been > >> > against a ternary operator but the requests kept coming. So > >> > eventually he introduced one. But the impression is that he chose an > >> > ugly format in the hope of discouraging people to use it. > >> > >> That's sheer and unadulterated nonsense. The fact is that Guido changed > >> his mind about ternary if after discovering that the work-around > >> > >> true-clause and condition or false-clause > >> > >> is buggy -- it gives the wrong answer if true-clause happens to be a > >> false value like [], 0 or None. If I recall correctly, the bug bit > >> Guido himself. > > > > Nonsense. That the work around was buggy was known years before the > > ternary operator was finally introduced. > > But people kept forgetting it, and it bit the right person one time too > many. So? That it took years between the knowledge that the work-around failed and a ternary operator finally appearing is still a fact. Which casts doubts that is was this knowledge that made him change his mind. > > The introduction of list > > comprehension made a ternary operator that more usefull but every time > > it came up the supporters of Guido, told us we just had to define a > > function if we wanted the items to depend on a condition. > > A function can't do the job, because it isn't lazy: > > def ifte(condition, x, y): > if condition: return x > else: return y > > n = 0 > ifte(n != 0, 100/n, -1) > > will fail. This was perhaps *the* killer argument for a ternary-if > operator. You really don't seem to remember what happened then. Someone would come with a problem that we can now solve as follows. ls = [ el / 2 if el % 2 == 0 else 3 * el + 1 for el in ls ] and the respons would be that we just needed to write is as follows: def f(el): if el % 2 == 0: return el / 2 else: return 3 * el + 1 ls = [ f(el) for el in ls ] -- Antoon Pardon From dsdale24 at gmail.com Mon Sep 27 09:21:49 2010 From: dsdale24 at gmail.com (Darren Dale) Date: Mon, 27 Sep 2010 06:21:49 -0700 (PDT) Subject: possible circular import problem with python-3, but not python-2 Message-ID: <1c6985e5-26ef-489b-bb4a-0e8d9717d3b5@z28g2000yqh.googlegroups.com> I am attempting to contribute to the h5py project by porting the code for python-3. The code is available in a branch at github: http://github.com/darrendale/h5py/tree/py3k . That code uses cython to wrap the hdf5 library. So far, only a few minor changes have been needed (relative imports, changes concerning strings/bytes), and I have been able to generate the c sources, build and install h5py for py3k. But I can't actually import the library. On Snow Leopard, using the python-3 installed via MacPorts: >>> import h5py Traceback (most recent call last): File "", line 1, in File "/Users/darren/.local/lib/python3.1/site-packages/ h5py-1.3.1.dev-py3.1-macosx-10.6-x86_64.egg/h5py/__init__.py", line 34, in from . import h5, h5a, h5d, h5f, h5fd, h5g, h5l, h5o, h5i, h5p, h5r, h5s, h5t, h5z File "h5t.pxd", line 17, in init h5py.h5a (h5py/h5a.c:5248) File "h5p.pxd", line 23, in init h5py.h5t (h5py/h5t.c:16481) File "h5t.pxd", line 17, in init h5py.h5p (h5py/h5p.c:9297) ImportError: No module named h5t That looks like it might be a circular import problem, but it works fine with python-2.6. I'm at a loss on how to proceed, could anyone please offer a suggestion? Thanks, Darren From flebber.crue at gmail.com Mon Sep 27 10:19:34 2010 From: flebber.crue at gmail.com (flebber) Date: Mon, 27 Sep 2010 07:19:34 -0700 (PDT) Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> <06b51e31-4ecc-4e51-a323-3649b7dab12e@g21g2000prn.googlegroups.com> Message-ID: <5fa8234c-fe73-4a49-a714-a6777116e806@u4g2000prn.googlegroups.com> On Sep 27, 2:46?pm, Dave Angel wrote: > On 2:59 PM, flebber wrote: > > > > > Traceback (most recent call last): > > ? ?File "C:/Python26/Pdfread", line 16, in > > ? ? ?open('x.txt', 'w').write(content) > > NameError: name 'content' is not defined > > When i use. > > > import pyPdf > > > def getPDFContent(path): > > ? ? ?content =C:\Components-of-Dot-NET.txt" > > ? ? ?# Load PDF into pyPDF > > ? ? ?pdf =yPdf.PdfFileReader(file(path, "rb")) > > ? ? ?# Iterate pages > > ? ? ?for i in range(0, pdf.getNumPages()): > > ? ? ? ? ?# Extract text from page and add to content > > ? ? ? ? ?content +=df.getPage(i).extractText() + "\n" > > ? ? ?# Collapse whitespace > > ? ? ?content = ".join(content.replace(u"\xa0", " ").strip().split()) > > ? ? ?return content > > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > open('x.txt', 'w').write(content) > > There's no global variable content, that was local to the function. ?So > it's lost when the function exits. ?it does return the value, but you > give it to print, and don't save it anywhere. > > data = getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > > outfile = open('x.txt', 'w') > outfile.write(data) > > close(outfile) > > I used a different name to emphasize that this is *not* the same > variable as content inside the function. ?In this case, it happens to > have the same value. ?And if you used the same name, you could be > confused about which is which. > > DaveA Thank You everyone. From xrgtn at yandex.ru Mon Sep 27 10:28:29 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Mon, 27 Sep 2010 17:28:29 +0300 Subject: Raw Sockets - IP-Encapsulation In-Reply-To: References: Message-ID: <20100927142829.GG11974@xrgtn-q40> Hello, On Fri, Sep 24, 2010 at 04:51:01PM +0100, Nobody wrote: > On Thu, 23 Sep 2010 21:41:19 +0200, Matthias > Guentert wrote: > > I would like to create an IP tunnel using the > > IP protocol type 4 (socket.IPPROTO_IPIP) on a > > Linux host. (I also would be happy if I could > > create a GRE tunnel) > > > > The thing is, I just don't understand how I > > such a socket could be created and then later > > on handled. > > You don't create sockets for IPPROTO_IPIP or > IPPROTO_GRE. Outside of the kernel, those > identifiers are only likely to be used for > specifying protocols when e.g. configuring > packet filtering. > > Tunnelling only involves user-space for > configuration. For GRE/IPIP this is true, but with /dev/tun and /dev/tap tunnels it isn't -- userspace program actually reads from/writes to tun/tap device file descriptor. -- With best regards, xrgtn From darragh.ssa at gmail.com Mon Sep 27 11:07:38 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Mon, 27 Sep 2010 08:07:38 -0700 (PDT) Subject: minimal D: need software testers Message-ID: <43bd55e3-e924-40b5-a157-b57ac8544b5f@f25g2000yqc.googlegroups.com> Hey, I've released the second alpha for minimal-D a program I've written in python which should make developing easier. I need people to test the app on bugs and give ideas. It is written in python using the wxPython toolkit and is linux-only. (using on windows is on own risk) You can download a .deb or a .tar.gz from http://launchpad.net/minimal From mirko.vukovic at gmail.com Mon Sep 27 11:18:22 2010 From: mirko.vukovic at gmail.com (Mirko) Date: Mon, 27 Sep 2010 08:18:22 -0700 (PDT) Subject: reduced-tagged (was Re: toy list processing problem: collect similar terms) References: Message-ID: <8e54fd9c-1d6b-433c-b306-288a7341bc98@a36g2000yqc.googlegroups.com> On Sep 26, 12:05?am, Xah Lee wrote: I am hijacking the following post and driving it to Cuba (the Monthy Python fans will know what I refer to). I want to create a `reduce'- like function that can handle similar problems. Xah said: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > stuffed deleted. Here is my Common Lisp (and I only care about Common Lisp answers) attempt to create a `reduce'-like function to handle this kind of a problem (you will see that I am still struggling with the code and the documentation). (defun reduce-tagged (function sequence &key (key-tag #'first) (key-datum #'rest)) "Use a binary operation, `function' to combine a sequence of tagged elements. like-tagged elements are `reduce'd according to `function' and returned in a list ... `sequence' is a sequence of tagged elements. reduce-m will reduce like-tagged-elements. If `key-tag' is supplied it is used to extract the element tag. If `key-tag' is not supplied, the function `first' is used. If `key-datum' is supplied, it is used to extract the element datum. If `key-datum' is not supplied, the function `rest' is used. " (let ((hash (make-hash-table))) (dolist (datum sequence) (let ((tag (funcall key-tag datum)) (values (funcall key-datum datum))) (multiple-value-bind (it present) (gethash tag hash) (if present (setf (gethash tag hash) (apply function (gethash tag hash) values)) (setf (gethash tag hash) values))))) (let (result) (dohash (key value hash) (push (list key value) result)) result))) Comments, improvements? I am looking for a general purpose function like reduce that I can apply in various situations. Thanks, Mirko From mirko.vukovic at gmail.com Mon Sep 27 11:40:45 2010 From: mirko.vukovic at gmail.com (Mirko) Date: Mon, 27 Sep 2010 08:40:45 -0700 (PDT) Subject: reduce-tagged (was Re: toy list processing problem: collect similar terms) References: <8e54fd9c-1d6b-433c-b306-288a7341bc98@a36g2000yqc.googlegroups.com> Message-ID: <99efd0f5-36cd-496e-8941-9e1ba1227929@w4g2000vbh.googlegroups.com> On Sep 27, 11:18?am, Mirko wrote: > On Sep 26, 12:05?am, Xah Lee wrote: > > I am hijacking the following post and driving it to Cuba (the Monthy > Python fans will know what I refer to). ?I want to create a `reduce'- > like function that can handle similar problems. > > Xah said: > > > > > here's a interesting toy list processing problem. > > > I have a list of lists, where each sublist is labelled by > > a number. I need to collect together the contents of all sublists > > sharing > > the same label. So if I have the list > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > r) (5 s t)) > > > where the first element of each sublist is the label, I need to > > produce: > > > output: > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > stuffed deleted. > > Here is my Common Lisp (and I only care about Common Lisp answers) > attempt to create a `reduce'-like function to handle this kind of a > problem (you will see that I am still struggling with the code and the > documentation). > > (defun reduce-tagged (function sequence &key > ? ? ? ? ? ? ? ? ?(key-tag #'first) > ? ? ? ? ? ? ? ? ?(key-datum #'rest)) > ? "Use a binary operation, `function' to combine a sequence of tagged > elements. ?like-tagged elements are `reduce'd according to `function' > and returned in a list ... > > `sequence' is a sequence of tagged elements. ?reduce-m will reduce > like-tagged-elements. > > If `key-tag' is supplied it is used to extract the element tag. ?If > `key-tag' is not supplied, the function `first' is used. > > If `key-datum' is supplied, it is used to extract the element datum. > If `key-datum' is not supplied, the function `rest' is used. > > " > ? (let ((hash (make-hash-table))) > ? ? (dolist (datum sequence) > ? ? ? (let ((tag (funcall key-tag datum)) > ? ? ? ? ? ? (values (funcall key-datum datum))) > ? ? ? ? (multiple-value-bind (it present) > ? ? ? ? ? ? (gethash tag hash) > ? ? ? ? ? (if present > ? ? ? ? ? ? ? (setf (gethash tag hash) > ? ? ? ? ? ? ? ? ? ? (apply function (gethash tag hash) values)) > ? ? ? ? ? ? ? (setf (gethash tag hash) values))))) > ? ? (let (result) > ? ? ? (dohash (key value hash) > ? ? ? ? (push (list key value) result)) > ? ? ? result))) > > Comments, improvements? ?I am looking for a general purpose function > like reduce that I > can apply in various situations. > > Thanks, > > Mirko Correction: the previous code used a non-portable clisp macro `dohash' (looks nice, doesn't it?) Here is the version with maphash: (defun reduce-tagged (function sequence &key (key-tag #'first) (key-datum #'rest)) "Use a binary operation, `function' to combine a sequence of tagged elements. like-tagged elements are `reduce'd according to `function' `sequence' is a sequence of tagged elements. reduce-m will reduce like-tagged-elements. If `key-tag' is supplied it is used to extract the element tag. If `key-tag' is not supplied, the function `first' is used. If `key-datum' is supplied, it is used to extract the element datum. If `key-datum' is not supplied, the function `rest' is used. " (let ((hash (make-hash-table))) (dolist (datum sequence) (let ((tag (funcall key-tag datum)) (values (funcall key-datum datum))) (multiple-value-bind (it present) (gethash tag hash) (declare (ignore it)) (if present (setf (gethash tag hash) (apply function (gethash tag hash) values)) (setf (gethash tag hash) values))))) (let (result) (maphash #'(lambda(key value) (push (list key value) result)) hash) result))) Mirko From marco at gallotta.co.za Mon Sep 27 11:48:06 2010 From: marco at gallotta.co.za (Marco Gallotta) Date: Mon, 27 Sep 2010 17:48:06 +0200 Subject: Introducing Kids to Programming: 2 or 3? Message-ID: Hi there I'm sure you get a lot of "2 or 3" questions, but here's another. Umonya [1] uses Python to introduce school kids to programming. The initiative is only 15 months old and up till now we've been using existing notes and exercises and thus Python 2. But we're at the stage where we can either stick with 2 for the next few years, or go to 3 now. We received a grant from Google to reach 1,000 kids in South Africa with our course in 2011. People have also shown interest in running the course in Croatia, Poland and Egypt. We're also eyeing developing African countries in the long-term. As such, we're taking the time now to write our very own specialised course notes and exercises, and we this is why we need to decide *now* which path to take: 2 or 3? As we will be translating the notes we'll probably stick with out choice for the next few years. Since these are kids, we feel the nice changes in 3 such as removing integer division will help in teaching. It will also remove confusion when they go to download Python and grab the latest version. Since they're just starting, chances are almost none will be hit by the limited library support for at least a year or two. They will, however, be hit by the confusion of seeing Python 2 code all over the web. We're tending towards 3, but I am a little cautious myself. Marco [1] http://umonya.co.za -- Marco Gallotta MSc Student Department of Computer Science, University of Cape Town people.cs.uct.ac.za/~mgallott | marco-za.blogspot.com marco AT gallotta DOT co DOT za | 073 170 4444 | 021 552 2731 From mirko.vukovic at gmail.com Mon Sep 27 11:50:39 2010 From: mirko.vukovic at gmail.com (Mirko) Date: Mon, 27 Sep 2010 08:50:39 -0700 (PDT) Subject: reduce-tagged (was Re: toy list processing problem: collect similar terms) References: <8e54fd9c-1d6b-433c-b306-288a7341bc98@a36g2000yqc.googlegroups.com> <99efd0f5-36cd-496e-8941-9e1ba1227929@w4g2000vbh.googlegroups.com> Message-ID: <319ddef7-1ad0-4913-bded-ddf97bc40476@j18g2000yqd.googlegroups.com> On Sep 27, 11:40?am, Mirko wrote: > On Sep 27, 11:18?am, Mirko wrote: > > > > > On Sep 26, 12:05?am, Xah Lee wrote: > > > I am hijacking the following post and driving it to Cuba (the Monthy > > Python fans will know what I refer to). ?I want to create a `reduce'- > > like function that can handle similar problems. > > > Xah said: > > > > here's a interesting toy list processing problem. > > > > I have a list of lists, where each sublist is labelled by > > > a number. I need to collect together the contents of all sublists > > > sharing > > > the same label. So if I have the list > > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > > r) (5 s t)) > > > > where the first element of each sublist is the label, I need to > > > produce: > > > > output: > > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > > stuffed deleted. > > > Here is my Common Lisp (and I only care about Common Lisp answers) > > attempt to create a `reduce'-like function to handle this kind of a > > problem (you will see that I am still struggling with the code and the > > documentation). > > ... faulty code deleted Aaand one more fix (apply -> funcall) (This version at least produces a close facsimile of the desired output) (defun reduce-tagged (function sequence &key (key-tag #'first) (key-datum #'rest)) "Use a binary operation, `function' to combine a sequence of tagged elements. like-tagged elements are `reduce'd according to `function' `sequence' is a sequence of tagged elements. reduce-m will reduce like-tagged-elements. If `key-tag' is supplied it is used to extract the element tag. If `key-tag' is not supplied, the function `first' is used. If `key-datum' is supplied, it is used to extract the element datum. If `key-datum' is not supplied, the function `rest' is used. " (let ((hash (make-hash-table))) (dolist (datum sequence) (let ((tag (funcall key-tag datum)) (values (funcall key-datum datum))) (multiple-value-bind (it present) (gethash tag hash) (declare (ignore it)) (if present (setf (gethash tag hash) (funcall function (gethash tag hash) values)) (setf (gethash tag hash) values))))) (let (result) (maphash #'(lambda(key value) (push (list key value) result)) hash) result))) From usenot at geekmail.INVALID Mon Sep 27 12:45:44 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 27 Sep 2010 12:45:44 -0400 Subject: Introducing Kids to Programming: 2 or 3? References: Message-ID: <20100927124544.1d9e2ba4@geekmail.INVALID> On Mon, 27 Sep 2010 17:48:06 +0200 Marco Gallotta wrote: > Since these are kids, we feel the nice changes in 3 such as removing > integer division will help in teaching. It will also remove confusion > when they go to download Python and grab the latest version. Since > they're just starting, chances are almost none will be hit by the > limited library support for at least a year or two. That's your answer right there. > They will, however, be hit by the confusion of seeing Python 2 code > all over the web. Good point. Here is may suggestion: Make the kids aware of the 2/3 issue as early as possible, but don't go into detail. Maybe start with the obligatory "Hello world" program, and a few other simple things. Then, when you get to the "how do help myself on the net" part of the course (you're including that, right?), you make strong distinction between Py2 and Py3 and tell them to make absolutely certain that it's Python 3 code they're looking at. Maybe give the "print()" syntax as a hint, but have them rely on more explicit descriptions that come with the code. Later on (once they know more programming constructs to appreciate the differences), include another lecture, specifically on the difference between Python 2 and Python 3. Disclaimer: I'm not an educator. Maybe this is horrible advice. Someone with a better understanding of kids' and learner's minds please debunk any nonsense I may have spouted here. I just like to go by the general rule that, unlike adults, most kids aren't idiots. /W -- INVALID? DE! From seyfisuna at gmail.com Mon Sep 27 12:49:03 2010 From: seyfisuna at gmail.com (Seyfi Suna) Date: Mon, 27 Sep 2010 09:49:03 -0700 (PDT) Subject: Konya - Turkish Company Directory - NEW ! - Seyfi Suna www.een.kso.org.tr Message-ID: <768a62d0-cae2-472e-a6c5-b108464ee2b1@l6g2000yqb.googlegroups.com> Konya - Turkish Company Directory - NEW ! - Seyfi Suna www.een.kso.org.tr http://www.een.kso.org.tr/en/konya-firma-rehberi/ From limyreth at gmail.com Mon Sep 27 13:15:19 2010 From: limyreth at gmail.com (Tim Diels) Date: Mon, 27 Sep 2010 19:15:19 +0200 Subject: Python3: API Documentation generator In-Reply-To: References: <4CA0400B.7000405@gmail.com> Message-ID: On 27/09/2010 09:02, Chris Rebert wrote: > On Sun, Sep 26, 2010 at 11:56 PM, Tim Diels wrote: >> Hi all >> >> I've just switched to python3 and it turns out my current API documentation >> generator (epydoc) no longer works. I am looking for a tool that reads the >> docstrings of all classes, ... in my project and turns it into HTML >> documentation. > > Sphinx (http://sphinx.pocoo.org/ ) is the new gold standard. You'll > want to enable the `autodoc` extension: > http://sphinx.pocoo.org/ext/autodoc.html > > Cheers, > Chris > -- > http://blog.rebertia.com I tried, but it fails to run through python code that's not backwards compatible with older python versions. It fails with: ...autodoc can't import/find module 'pytilities', it reported error: "invalid syntax (overload.py, line 55)"... This is line 55 (runs in python3, not in python): def process_args(self, *args, kwargs={}) Greetings Tim (limyreth) From namekuseijin at gmail.com Mon Sep 27 13:46:32 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 27 Sep 2010 10:46:32 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> Message-ID: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> On 27 set, 05:46, TheFlyingDutchman wrote: > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > wrote: > > RG writes: > > > In article > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, > > > ?TheFlyingDutchman wrote: > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > >> > This might have been mentioned here before, but I just came across it: a > > >> > 2003 essay by Bruce Eckel on how reliable systems can get built in > > >> > dynamically-typed languages. ?It echoes things we've all said here, but > > >> > I think it's interesting because it describes a conversion experience: > > >> > Eckel started out in the strong-typing camp and was won over. > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > >> > -- Scott > > > >> If you are writing a function to determine the maximum of two numbers > > >> passed as arguents in a dynamic typed language, what is the normal > > >> procedure used by Eckel and others to handle someone passing in > > >> invalid values - such as a file handle for one varible and an array > > >> for the other? > > > > The normal procedure is to hit such a person over the head with a stick > > > and shout "FOO". > > > Moreover, the functions returning the maximum may be able to work on > > non-numbers, as long as they're comparable. ?What's more, there are > > numbers that are NOT comparable by the operator you're thinking about!. > > > So to implement your specifications, that function would have to be > > implemented for example as: > > > (defmethod lessp ((x real) (y real)) (< x y)) > > (defmethod lessp ((x complex) (y complex)) > > ? (or (< (real-part x) (real-part y)) > > ? ? ? (and (= (real-part x) (real-part y)) > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > (defun maximum (a b) > > ? (if (lessp a b) b a)) > > > And then the client of that function could very well add methods: > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > and call: > > > (maximum 'hello "WORLD") --> "WORLD" > > > and who are you to forbid it!? > > > -- > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/-Hide quoted text - > > > - Show quoted text - > > in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. If someone > tries to call it incorrectly it is a compile error. > In a dynamic typed language maximum(a, b) can be called with incorrect > datatypes. Even if I make it so it can handle many types as you did > above, it could still be inadvertantly called with a file handle for a > parameter or some other type not provided for. So does Eckel and > others, when they are writing their dynamically typed code advocate > just letting the function blow up or give a bogus answer, or do they > check for valid types passed? If they are checking for valid types it > would seem that any benefits gained by not specifying type are lost by > checking for type. And if they don't check for type it would seem that > their code's error handling is poor. that is a lie. Compilation only makes sure that values provided at compilation-time are of the right datatype. What happens though is that in the real world, pretty much all computation depends on user provided values at runtime. See where are we heading? this works at compilation time without warnings: int m=numbermax( 2, 6 ); this too: int a, b, m; scanf( "%d", &a ); scanf( "%d", &b ); m=numbermax( a, b ); no compiler issues, but will not work just as much as in python if user provides "foo" and "bar" for a and b... fail. What you do if you're feeling insecure and paranoid? Just what dynamically typed languages do: add runtime checks. Unit tests are great to assert those. Fact is: almost all user data from the external words comes into programs as strings. No typesystem or compiler handles this fact all that graceful... From animator333 at gmail.com Mon Sep 27 13:54:28 2010 From: animator333 at gmail.com (King) Date: Mon, 27 Sep 2010 10:54:28 -0700 (PDT) Subject: relative imports and sub-module execution Message-ID: <73156baa-5774-45f9-a92c-50f9573eedd9@p24g2000pra.googlegroups.com> Hi, After reading couple of docs and articles, I have implemented a simple test package with nested modules. When running "main.py", everything is working fine. Some of my sub- modules has some small test routines for debug purpose. It's because I am using relative package imports at the top, I am not able to run these sub modules individually. For example, this works when running from main.py Here is example structure main.py __init__.py core/ __init__.py folder1 __init__.py f1a.py f1b.py folder2 __init__.py f2a.py f2b.py in folder2/f2b.py, I am importing from core.folder1 import f1a print f1a.myvar Now I can't execute 'f2b.py' individually. It's giving an error: ImportError: No module named core.folder2 Is this mean when you have created a package where modules are using relative imports, they can't execute individually? Another solution that I have discovered is using sys.path. Check this: import sys import os sys.path.append(os.path.abspath("../../")) from core.folder1 import f1a print f1a.myvar This works fine and easier too. I can execute modules individually as well as package is also working. Are there any disadvantages when using above technique? Couple of articles suggests that this is a bad practice and should not be used. Need some clarifications. Thanks Prashant From kee at kagi.com Mon Sep 27 14:04:17 2010 From: kee at kagi.com (Kee Nethery) Date: Mon, 27 Sep 2010 11:04:17 -0700 Subject: Introducing Kids to Programming: Scratch In-Reply-To: References: Message-ID: My son has been writing games using MIT's Scratch. It is visual and highly interactive. In an afternoon he can build something that looks cool to him, is interactive, and that he can share with others. It's not Python but he is learning how to make the tools do what he wants and he is getting results. He's 8 years old. http://scratch.mit.edu For introducing kids to programming, I recommend Scratch. Kee Nethery From tjreedy at udel.edu Mon Sep 27 14:13:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Sep 2010 14:13:45 -0400 Subject: Introducing Kids to Programming: 2 or 3? In-Reply-To: References: Message-ID: On 9/27/2010 11:48 AM, Marco Gallotta wrote: > Hi there > > I'm sure you get a lot of "2 or 3" questions, but here's another. > Umonya [1] uses Python to introduce school kids to programming. The > initiative is only 15 months old and up till now we've been using > existing notes and exercises and thus Python 2. But we're at the stage > where we can either stick with 2 for the next few years, or go to 3 > now. > > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. As such, we're taking the time now > to write our very own specialised course notes and exercises, and we > this is why we need to decide *now* which path to take: 2 or 3? As we > will be translating the notes we'll probably stick with out choice for > the next few years. I would absolutely, definitely, move to Python3, with the the intention of using 3.2 when it comes out in a few months. I suspect that most of your exercise code will need little change beyond what 2to3 does for you. > Since these are kids, we feel the nice changes in 3 such as removing > integer division will help in teaching. There are several half-finished transitions in late 2.x. Removal of old-style classes, not only as the default, but completely, removes a source of confusion. The range/xrange confusion is gone. The input/raw_imput confusion is gome. I think most important for an international project is the shift to unicode as the default text type, including for identifiers. Kids who are not masters of English will want to write identifiers in their own language. > It will also remove confusion > when they go to download Python and grab the latest version. Since > they're just starting, chances are almost none will be hit by the > limited library support for at least a year or two. I personally consider this pretty irrelevant for teaching programming to kids. There is a *lot* in the stdlib to work with. And stdlib improvement is getting special emphasis for 3.2. Bug fixes may be backported, feature additions are not. Even if one disagrees, 3rd-party library support is improving and will continue to improve especially after 3.2 is released. For instance, the recent release of numpy for 3.1 enables conversions that were blocked waiting for that. http://sourceforge.net/projects/numpy/files/NumPy/1.5.0/numpy-1.5.0-win32-superpack-python3.1.exe/download For another example, the web-sig appears to have agreed on a minimal, backward-compatible extension to PEP 333 to make wsgi work with Python3. This will be PEP 3333. (It appears the problem was too many choices rather than no choice. Discussion continues on more extensive non-compatible changes.) This will allow existing wsgi tools to both work with Python3 *and* continue to be intercompatible. (The latter was the problem. If each tool made its own non-standard choice for Python3, that latter property would be lost.) -- Terry Jan Reedy From tjreedy at udel.edu Mon Sep 27 14:25:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Sep 2010 14:25:20 -0400 Subject: Python3: API Documentation generator In-Reply-To: References: <4CA0400B.7000405@gmail.com> Message-ID: On 9/27/2010 1:15 PM, Tim Diels wrote: > On 27/09/2010 09:02, Chris Rebert wrote: >> On Sun, Sep 26, 2010 at 11:56 PM, Tim Diels wrote: >>> Hi all >>> >>> I've just switched to python3 and it turns out my current API >>> documentation >>> generator (epydoc) no longer works. I am looking for a tool that >>> reads the >>> docstrings of all classes, ... in my project and turns it into HTML >>> documentation. >> >> Sphinx (http://sphinx.pocoo.org/ ) is the new gold standard. You'll >> want to enable the `autodoc` extension: >> http://sphinx.pocoo.org/ext/autodoc.html >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > I tried, but it fails to run through python code that's not backwards > compatible with older python versions. > > It fails with: ...autodoc can't import/find module 'pytilities', it > reported error: "invalid syntax (overload.py, line 55)"... > > This is line 55 (runs in python3, not in python): > def process_args(self, *args, kwargs={}) Unless the autodoc doc says that it does not work with all Python3 code, that strikes me as a bug (a new 3.x feature that was overlooked) that should be reported. The sphinx tracker is linked on the sphinx homepage http://bitbucket.org/birkenfeld/sphinx/issues/ There is also a link to a google group for sphinx. Does epydoc not work because is does not run on 3.1 or because it also chokes when fed the above code. In the meanwhile, you could change the api ;-). -- Terry Jan Reedy From kwatford+python at gmail.com Mon Sep 27 14:44:08 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Mon, 27 Sep 2010 14:44:08 -0400 Subject: Python3: API Documentation generator In-Reply-To: References: <4CA0400B.7000405@gmail.com> Message-ID: On Mon, Sep 27, 2010 at 1:15 PM, Tim Diels wrote: > On 27/09/2010 09:02, Chris Rebert wrote: >> >> On Sun, Sep 26, 2010 at 11:56 PM, Tim Diels ?wrote: >>> >>> ?Hi all >>> >>> I've just switched to python3 and it turns out my current API >>> documentation >>> generator (epydoc) no longer works. I am looking for a tool that reads >>> the >>> docstrings of all classes, ... in my project and turns it into HTML >>> documentation. >> >> Sphinx (http://sphinx.pocoo.org/ ) is the new gold standard. You'll >> want to enable the `autodoc` extension: >> http://sphinx.pocoo.org/ext/autodoc.html >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > I tried, but it fails to run through python code that's not backwards > compatible with older python versions. > > It fails with: ...autodoc can't import/find module 'pytilities', it reported > error: "invalid syntax (overload.py, line 55)"... > > This is line 55 (runs in python3, not in python): > def process_args(self, *args, kwargs={}) > As far as I'm aware, autodoc works by importing the modules and then reading doctext straight from the __doc__ attributes. So the module in question has to import correctly in whatever interpreter Sphinx is using. You probably need to install Sphinx with python3 to get it to use the right interpreter. If you're using easy_install or pip, check if you have an easy_install-3.1 or pip-3.1 (or similar) script installed. From xahlee at gmail.com Mon Sep 27 15:06:50 2010 From: xahlee at gmail.com (Xah Lee) Date: Mon, 27 Sep 2010 12:06:50 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> Message-ID: <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> 2010-09-27 > For instance, this is far more convenient: > [x+1 for x in [1,2,3,4,5] if x%2==0] > than this: > map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) How about this: LC(func, inputList, P) compared to [func for myVar in inputList if P] the functional form is: ? shorter ? not another idiysyncratic new syntax -------------------- now, a separate issue. Suppose we want some ?list comprehension? feature in a functional lang. Normally, by default this can be done by filter( map(func, inputList), Predicate) but perhaps this usage is so frequent that we want to create a new fuction for it, to make it more convenient, and perhaps easier to make the compiler to optimize more. e.g. LC(func, inputList, Predicate) this is about whether a lang should create a new convenient function that otherwise require 2 function combinations. Common Lisp vs Scheme Lisp are the typical example of extreme opposites. note, there's no new syntax involved. -------------------- Now, let's consider another separated issue related to so-called ?list comprehension?. Suppose we decided that generating list by a filter is so frequently used that it worth it to create a new func for it. LC(func, inputList, Predicate) Now, in functional langs, in general a design principle is that you want to reduce the number of function unless you really need. Because, any combination of list related functions could potentionally be a new function in your lang. So, if we really think LC is useful, we might want to generalize it. e.g. in LC(func, inputList, Predicate) is it worthwhile say to add a 4th param, that says return just the first n? (here we presume the lang doesn't support list of infinite elements) e.g. LC(func, inputList, Predicate, n) what about partition the list to m sublists? LC(func, inputList, Predicate, n, m) what about actualy more generalized partition, by m sublist then by m1 sublist then by m2 sublist? LC(func, inputList, Predicate, n, list(m,m1,m2,...)) what about sorting? maybe that's always used together when you need a list? LC(func, inputList, Predicate, n, list(m,m1,m2,...), sortPredcate) what if actually frequently we want LC to map parallel to branches? e.g. LC(func, inputList, Predicate, n, list(m,m1,m2,...), sortPredcate, mapBranch:True) what if ... you see, each of these or combination of these can be done by default in the lang by sequenceing one or more functions (i.e. composition). But when we create a new function, we really should think a lot about its justification, because otherwise the lang becomes a bag of functions that are non-essential, confusing. In summary: ? ?list comprehension? is a bad jargon. ? The concept of ?list comprehension? is redundant. There's no justification for the concept to exist except historical. ? The syntax of ?list comprehension? in most lang is ad hoc syntax. for those who find imperative lang good, then perhaps ?list comprehension? is good, because it adds another idiosyncratic syntax to the lang, but such is with the tradition of imperative langs. The ad hoc syntax aids in reading code by various syntactical forms and hint words such as ?[... for ... in ...]?. Xah ? xahlee.org ? From namekuseijin at gmail.com Mon Sep 27 15:11:20 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 27 Sep 2010 12:11:20 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> Message-ID: On 27 set, 16:06, Xah Lee wrote: > 2010-09-27 > > > For instance, this is far more convenient: > > [x+1 for x in [1,2,3,4,5] if x%2==0] > > than this: > > map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) > > How about this: [snip] how about this: read before replying. From pjb at informatimago.com Mon Sep 27 15:29:44 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 27 Sep 2010 21:29:44 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> namekuseijin writes: >> in C I can have a function maximum(int a, int b) that will always >> work. Never blow up, and never give an invalid answer. If someone >> tries to call it incorrectly it is a compile error. >> In a dynamic typed language maximum(a, b) can be called with incorrect >> datatypes. Even if I make it so it can handle many types as you did >> above, it could still be inadvertantly called with a file handle for a >> parameter or some other type not provided for. So does Eckel and >> others, when they are writing their dynamically typed code advocate >> just letting the function blow up or give a bogus answer, or do they >> check for valid types passed? If they are checking for valid types it >> would seem that any benefits gained by not specifying type are lost by >> checking for type. And if they don't check for type it would seem that >> their code's error handling is poor. > > that is a lie. > > Compilation only makes sure that values provided at compilation-time > are of the right datatype. > > What happens though is that in the real world, pretty much all > computation depends on user provided values at runtime. See where are > we heading? > > this works at compilation time without warnings: > int m=numbermax( 2, 6 ); > > this too: > int a, b, m; > scanf( "%d", &a ); > scanf( "%d", &b ); > m=numbermax( a, b ); > > no compiler issues, but will not work just as much as in python if > user provides "foo" and "bar" for a and b... fail. > > What you do if you're feeling insecure and paranoid? Just what > dynamically typed languages do: add runtime checks. Unit tests are > great to assert those. > > Fact is: almost all user data from the external words comes into > programs as strings. No typesystem or compiler handles this fact all > that graceful... I would even go further. Types are only part of the story. You may distinguish between integers and floating points, fine. But what about distinguishing between floating points representing lengths and floating points representing volumes? Worse, what about distinguishing and converting floating points representing lengths expressed in feets and floating points representing lengths expressed in meters. If you start with the mindset of static type checking, you will consider that your types are checked and if the types at the interface of two modules matches you'll think that everything's ok. And six months later you Mars mission will crash. On the other hand, with the dynamic typing mindset, you might even wrap your values (of whatever numerical type) in a symbolic expression mentionning the unit and perhaps other meta data, so that when the other module receives it, it may notice (dynamically) that two values are not of the same unit, but if compatible, it could (dynamically) convert into the expected unit. Mission saved! -- __Pascal Bourguignon__ http://www.informatimago.com/ From Scott at ergy.com Mon Sep 27 16:36:39 2010 From: Scott at ergy.com (Scott L. Burson) Date: Mon, 27 Sep 2010 13:36:39 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: Pascal J. Bourguignon wrote: > > On the other hand, with the dynamic typing mindset, you might even wrap > your values (of whatever numerical type) in a symbolic expression > mentionning the unit and perhaps other meta data, so that when the other > module receives it, it may notice (dynamically) that two values are not > of the same unit, but if compatible, it could (dynamically) convert into > the expected unit. Mission saved! In fairness, you could do this statically too, and without the consing required by the dynamic approach. -- Scott From pjb at informatimago.com Mon Sep 27 16:38:17 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 27 Sep 2010 22:38:17 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <877hi6sz0m.fsf@kuiper.lan.informatimago.com> "Scott L. Burson" writes: > Pascal J. Bourguignon wrote: >> >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. Mission saved! > > In fairness, you could do this statically too, and without the consing > required by the dynamic approach. I don't deny it. My point is that it's a question of mindset. -- __Pascal Bourguignon__ http://www.informatimago.com/ From cartercc at gmail.com Mon Sep 27 16:43:37 2010 From: cartercc at gmail.com (ccc31807) Date: Mon, 27 Sep 2010 13:43:37 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: Message-ID: On Sep 26, 12:05?am, Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) Here is a solution in Perl -- the verbose version. Please see my note below. SCRIPT: use strict; use warnings; my %lists; while () { chomp; my ($k, @v) = split(/ /, $_); push(@{$lists{$k}}, @v); } foreach my $k (sort keys %lists) { print "$k - @{$lists{$k}}\n"; } exit(0); __DATA__ 0 a b 1 c d 2 e f 3 g h 1 i j 2 k l 4 m n 2 o p 4 q r 5 s t OUTPUT: >perl lists.plx 0 - a b 1 - c d i j 2 - e f k l o p 3 - g h 4 - m n q r 5 - s t NOTE: I assume that you want an idiomatic solution for the language. I have therefore converted your data into a typical record oriented structure. Perlistas don't use parenthesis. If you want a Lispy solution, use Lisp. Further, Perl was made for exactly this kind of problem, which is simple data munging, taking some input, transforming it, and printing it out -- Practical Extraction and Reporting Language. I know that some Lispers (R.G., are you reading?) will object to a formulation like this: @{$lists{$k}}, but all this says (in Perl) is to spit out the value contained in the hash element $lists{$k} as an array, and is good idiomatic Perl, even if some Lispers aren't quite up to the task of understanding it. CC. From hodgestar at gmail.com Mon Sep 27 17:12:14 2010 From: hodgestar at gmail.com (Simon Cross) Date: Mon, 27 Sep 2010 23:12:14 +0200 Subject: [ctpug] Introducing Kids to Programming: 2 or 3? In-Reply-To: References: Message-ID: On Mon, Sep 27, 2010 at 5:48 PM, Marco Gallotta wrote: > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. As such, we're taking the time now > to write our very own specialised course notes and exercises, and we > this is why we need to decide *now* which path to take: 2 or 3? As we > will be translating the notes we'll probably stick with out choice for > the next few years. If you were going to start running the course tomorrow I'd suggest sticking with Python 2. Python 3 ports are rapidly becoming available but few have had the bugs shaken out of them yet. In three or four months I expect that the important bugs will have been dealt with. Given that 2.x will not receive any new features, I think it is effectively dead. I would explicitly mention the existence of 2.7 and 3.2 [1] to students (perhaps near the end of the first day or whenever they're about to go off and download Python for themselves). One caveat is that web applications may only start to migrate to 3.x late next year. There are a number of reasons for this. First it's not yet clear what form the WSGI standard will take under Python 3 (and if 3.2 is released before this decision is made it will effectively have to wait for 3.3 to be included). Secondly the software stack involved is quite deep in some places. For example, database support might require porting MySQLdb, then SQLAlchemy, then the web framework and only after that the web application itself. [1] Which should hopefully make it out before 2011. :) Schiavo Simon From xahlee at gmail.com Mon Sep 27 17:39:56 2010 From: xahlee at gmail.com (Xah Lee) Date: Mon, 27 Sep 2010 14:39:56 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> Message-ID: <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> On Sep 27, 12:11?pm, namekuseijin wrote: > On 27 set, 16:06, Xah Lee wrote:> 2010-09-27 > > > > For instance, this is far more convenient: > > > [x+1 for x in [1,2,3,4,5] if x%2==0] > > > than this: > > > map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) > > > How about this: > > [snip] > > how about this: ?read before replying. hum??? i read your post quite carefully, and rather thought i replied well. In fact, i really wanted to tell you ?read before replying? before but refrained from making any of that expression. here's 2 previous posts about list compre. http://groups.google.com/group/comp.lang.lisp/msg/145f6ecf29ebbdaf http://groups.google.com/group/comp.lang.lisp/msg/62ca84062c9fcdca Xah From hansyin at gmail.com Mon Sep 27 18:13:28 2010 From: hansyin at gmail.com (Hans) Date: Mon, 27 Sep 2010 15:13:28 -0700 (PDT) Subject: program organization question for web development with python References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> <4c933693$0$4439$426a34cc@news.free.fr> Message-ID: On Sep 17, 2:36?am, Bruno Desthuilliers wrote: > Hans a ?crit : > (snip) > > > Maybe I did not make my question clear. I never tried python web > > programing before, so I want to start from CGI. > > You can indeed learn quite a few things doing raw CGI - the most > important one being why frameworks are a good idea !-) > > > I read something about web framework like django, but seems it's a > > little bit complicated. > > Not that much IMHO, but being an early django user I'm probably a bit > biased. Now Python is known as "the language with more web frameworks > than keywords", so you could probably check some lighter framework like > ? web.py (http://webpy.org/) or flask (http://flask.pocoo.org/). > > > my task is actually very simple: get search > > string from input, and then search database, print search result. I > > thought CGI should be good enough to do this. > > CGI is "good enough" to do any web stuff - just like assembler is "good > enough" to write any application !-) > > > > > I don't have any idea about how to organize those cgi codes, so what > > I'm asking is: > > > 1. do I have to have each single file for each hyper-link? Can I put > > them together? how? > > > 2. how can I pass a db_cursor to another file? ? can I use db_cursor as > > a parameter? > > Obviously not. FWIW, both questions show a lack of understanding of the > HTTP protocol, and you can't hope to do anything good in web programming > if you don't understand at least the basics of the HTTP protocol, > specially the request/response cycle. > > Now for a couple more practical answers: > > There are basically two ways to organize your url => code mapping: > 1/ have only one cgi script and use querystring params to tell which > action should be executed. > 2/ have one cgi script per action. > > The choice is up to you. For a simple app like yours, the first solution > is probably the most obvious : always display the seach form, if the > user submitted the form also display the result list. That's how google > works (wrt/ user interface I mean). > > Now if you still need / want to have distinct scripts and want to factor > out some common code, you just put the common code in a module that you > import from each script. Thank you very much! I got your meaning. The choice 1 is definitely what I want, I just cannot think about this idea by myself. Thank you again! From asaferibeiro4 at ymail.com Mon Sep 27 18:28:34 2010 From: asaferibeiro4 at ymail.com (Eduardo Ribeiro) Date: Mon, 27 Sep 2010 15:28:34 -0700 (PDT) Subject: Nautilus Python Message-ID: <262676.77946.qm@web59614.mail.ac4.yahoo.com> I'm a python noob and wrote the following code for a nautilus extension: #!/usr/local/bin/python # -*- coding: utf-8 -*- import urllib import gtk import pygtk import nautilus import gconf import gtk.glade class Slide (nautilus.MenuProvider): f = None def __init__(self): self.client = gconf.client_get_default() self.f = gtk.glade.XML( "papel.glade" ) self.window = self.f.get_widget("window1") gtk.main() def oi (self): self.window.show() def menu_activate_cb(self, menu, file): self.oi() def get_file_items(self, window,files): if len(files) != 1: return item = nautilus.MenuItem('NautilusPython::slide_file_item','Slide','Slide') item.connect('activate', self.menu_activate_cb, files[0]) return item, def get_background_items(self, window, file): item = nautilus.MenuItem('NautilusPython::slide_item','Slide','Slide') item.connect('activate', self.menu_background_activate_cb, file) return item, def menu_background_activate_cb(self, menu, file): self.oi() But it doesn't work. If I comment the lines: self.f = gtk.glade.XML( "papel.glade" ) self.window = self.f.get_widget("window1") gtk.main() the code works but I can't see any problem in those lines. Any help? From sjmachin at lexicon.net Mon Sep 27 19:01:34 2010 From: sjmachin at lexicon.net (John Machin) Date: Tue, 28 Sep 2010 09:01:34 +1000 Subject: strange results from sys.version Message-ID: <4CA1224E.5040101@lexicon.net> I am trying to help a user of my xlrd package who says he is getting anomalous results on his "work computer" but not on his "home computer". Attempts to reproduce his alleged problem in a verifiable manner on his "work computer" have failed, so far ... the only meaning difference in script output is in sys.version User (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc Me : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc I have just now downloaded the Windows x86 msi from www.python.org and reinstalled it on another computer. It gives the same result as on my primary computer (above). User result looks whacked: lower patch number, later date. www.python.org says "Python 2.7 was released on July 3rd, 2010." Is it possible that the "work computer" is using an unofficial release? What other possibilities are there? Thanks in advance ... From afffg33 at gmail.com Mon Sep 27 19:04:41 2010 From: afffg33 at gmail.com (fcgffj) Date: Mon, 27 Sep 2010 16:04:41 -0700 (PDT) Subject: vhttp://www.vipshops.org/ nike air jordan shoe for sale,nike , chanal, gucci, juicy, polo tshirt.adidas and so on.all are free shipping. Message-ID: nike air jordan shoes http://www.vipshops.org/ nike shoes http://www.vipshops.org/ ed hardy http://www.vipshops.org/ SUIT ShortJ ERSEY Jean Jacket Hoody http://www.vipshops.org/ T-ShirtT http://www.vipshops.org/ -Shirt_W http://www.vipshops.org/ Tracksuit_W http://www.vipshops.org/ Skirt_W http://www.vipshops.org/ Short_W http://www.vipshops.org/ Jean sunglass http://www.vipshops.org/ more info http://www.vipshops.org/ ED Hardy_menDG menCOACH_menLV menLacoste manKobe http://www.vipshops.org/ manPuma manTimberland bootRift_man Super http://www.vipshops.org/Size(14_15)Prada_man Nike_shox Nike_Air_Jordan Nike_Air_Force_1 Nike_Air_Dunk Jordan Ring Jordan Fusion Jordan 23 Mixture GucciFashion BOOTBape shoesASCIS Air_max_man ADIDAS SHOE http://www.vipshops.org/ Shoes For Female http://www.vipshops.org/ Woman BootSandal Nike_shox_woman Nike_Air_Jordan_w Jordan_Fusion_w Gucci woman Dunk_Shoe_woman Air_max_woman AF1_Shoe_woman Timberland_WRift_W Puma_WPrada_W LV_W Louboutin_W juicy couture shoe_W DG_WCOACH_W christian louboutin ASCIS_WADIDAS_W Kid Apparel http://www.vipshops.org/ Shoe For KidClothing For Kid Handbag_Wallet http://www.vipshops.org/ Wallet Handbag Other Product http://www.vipshops.org/ Watch Sunglass Software Jewerly Hair Straigher CapBelt ED Hardy_men DG menCOACH_men LV men Lacoste man Kobe man Puma_man Timberland bootRift_man Super Size(14_15)Prada_manNike_shoxNike_Air_JordanNike_Air_Force_1Nike_Air_DunkJordan RingJordan FusionJordan 23 Mixture GucciFashion BOOTBape shoes ASCISAir_max_manADIDAS SHOE more info http://www.vipshops.org/ From robert.kern at gmail.com Mon Sep 27 19:30:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 27 Sep 2010 18:30:02 -0500 Subject: strange results from sys.version In-Reply-To: <4CA1224E.5040101@lexicon.net> References: <4CA1224E.5040101@lexicon.net> Message-ID: On 9/27/10 6:01 PM, John Machin wrote: > I am trying to help a user of my xlrd package who says he is getting anomalous > results on his "work computer" but not on his "home computer". > > Attempts to reproduce his alleged problem in a verifiable manner on his "work > computer" have failed, so far ... the only meaning difference in script output > is in sys.version > > User (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc > Me : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc > > I have just now downloaded the Windows x86 msi from www.python.org and > reinstalled it on another computer. It gives the same result as on my primary > computer (above). > > User result looks whacked: lower patch number, later date. www.python.org says > "Python 2.7 was released on July 3rd, 2010." > > Is it possible that the "work computer" is using an unofficial release? What > other possibilities are there? ActivePython 2.7.0.2 was released on Aug 25: http://downloads.activestate.com/ActivePython/releases/2.7.0.2/ -- 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 sridharr at activestate.com Mon Sep 27 19:36:01 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 27 Sep 2010 16:36:01 -0700 Subject: strange results from sys.version In-Reply-To: References: <4CA1224E.5040101@lexicon.net> Message-ID: <550E2DB8-49FD-462F-B449-E922A12D270D@activestate.com> On 2010-09-27, at 4:30 PM, Robert Kern wrote: > On 9/27/10 6:01 PM, John Machin wrote: >> I am trying to help a user of my xlrd package who says he is getting anomalous >> results on his "work computer" but not on his "home computer". >> >> Attempts to reproduce his alleged problem in a verifiable manner on his "work >> computer" have failed, so far ... the only meaning difference in script output >> is in sys.version >> >> User (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc >> Me : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc >> >> I have just now downloaded the Windows x86 msi from www.python.org and >> reinstalled it on another computer. It gives the same result as on my primary >> computer (above). >> >> User result looks whacked: lower patch number, later date. www.python.org says >> "Python 2.7 was released on July 3rd, 2010." >> >> Is it possible that the "work computer" is using an unofficial release? What >> other possibilities are there? > > ActivePython 2.7.0.2 was released on Aug 25: > > http://downloads.activestate.com/ActivePython/releases/2.7.0.2/ John, If it is ActivePython, the first line of the interactive shell (in credits section) should print something like: ActivePython 2.7.0.2 (ActiveState Software Inc.) Also what is the output of "python -m activestate"? -srid From sridharr at activestate.com Mon Sep 27 19:44:55 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 27 Sep 2010 16:44:55 -0700 Subject: strange results from sys.version In-Reply-To: <4CA1224E.5040101@lexicon.net> References: <4CA1224E.5040101@lexicon.net> Message-ID: <6131A5C1-5DCD-4EE8-8851-91DA2CB13AA1@activestate.com> On 2010-09-27, at 4:01 PM, John Machin wrote: > User (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc > Me : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc > > [...] User result looks whacked: lower patch number, later date Perusing http://svn.python.org/view/python/branches/release27-maint/?view=log - the difference in svn versions (there is no difference in patch number) seems insignificant. Both revisions are past the 2.7 final release. Perhaps, the python.org installer was created using a later revision. -srid From namekuseijin at gmail.com Mon Sep 27 19:58:52 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 27 Sep 2010 16:58:52 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> Message-ID: <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> On 27 set, 18:39, Xah Lee wrote: > On Sep 27, 12:11?pm, namekuseijin wrote: > > > On 27 set, 16:06, Xah Lee wrote:> 2010-09-27 > > > > > For instance, this is far more convenient: > > > > [x+1 for x in [1,2,3,4,5] if x%2==0] > > > > than this: > > > > map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) > > > > How about this: > > > [snip] > > > how about this: ?read before replying. > > hum??? > > i read your post quite carefully, and rather thought i replied well. I don't think so. You completely missed the point where I agreed about filter map being more convenient when calling predefined functions and also the detailed explanation of why do in scheme is not imperative at all. From danny at picolina.net Mon Sep 27 20:07:45 2010 From: danny at picolina.net (Danny Levinson) Date: Mon, 27 Sep 2010 17:07:45 -0700 Subject: Debugger - fails to "continue" with breakpoint set In-Reply-To: <4C914610.5060904@greenberg.org> References: <4C914610.5060904@greenberg.org> Message-ID: <4CA131D1.1080009@picolina.net> Does this describe the problem you are having? http://bugs.python.org/issue5294 From rjngrj2010 at gmail.com Mon Sep 27 21:22:33 2010 From: rjngrj2010 at gmail.com (gujax) Date: Mon, 27 Sep 2010 18:22:33 -0700 (PDT) Subject: Problems reading tif files References: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> Message-ID: <53e93b52-fc29-4643-8d91-4fcad3463540@t11g2000vbc.googlegroups.com> On Sep 26, 9:19?pm, Christian Heimes wrote: > Am 27.09.2010 02:31, schrieb gujax: > > > Hi, > > I have read several related e-mails dating back as far as 2006. I am > > quite confused whether PIL can open tif images. Some posts seem to say > > there isn't yet any support for PIL while there are few posts where > > PIL has been able to open tif images. So I guess, I have to ask this > > probably trivial question again. I am just learning python and PIL. I > > have tiff images which are 8 bit and 16 bit gray scale images. I > > cannot open them. Here are the errors that I encounter. > > PIL only supports a limited subset of TIFF files. Several compression > algorithms like G3 and G4 fax compression are not supported yet. PIL may > have a problem with partly broken TIFF files, too. > > > I have no idea why this happens. > > I will appreciate a resolution. The file opens with ImageJ and > > ImageMagick. It is a 8-bit RGB file. I have associated default viewer > > to be ImageMagick. I am on Lucid Linux, and other programs such as F- > > spot and Gimp cannot open those files either. > > I don't yet know how to attach image files to the post so please bear > > with me till I figure that out. > > Can you please post the output of tiffinfo for the specific file? It may > give me a hint what's going wrong. > > There aren't a lot of good alternatives for image processing in Python. > I've evaluated most of them and decided to write my own one for my > employer. It's a Cython based library around FreeImage [1] and LCMS2 [2] > and works very well. So far we have processed several million TIFF files > with more than 100 TB of raw data smoothly. I've permission to release > the software as open source but haven't found time to do a proper release. > > Christian Heimes > > [1]http://freeimage.sourceforge.net/ > [2]http://www.littlecms.com/ Thanks Christian, Here is the tiffinfo: TIFF Directory at offset 0x8 (8) Subfile Type: (0 = 0x0) Image Width: 640 Image Length: 480 Bits/Sample: 32 Sample Format: IEEE floating point Compression Scheme: None Photometric Interpretation: min-is-black Samples/Pixel: 1 Rows/Strip: 480 Planar Configuration: single image plane ImageDescription: ImageJ=1.44f min=0.0 max=255.0 How do I use freeimage with python. Is there a backend? Can these files be converted to something else such as bmp and then read out? I should have tried it out before asking you, Thanks From rjngrj2010 at gmail.com Mon Sep 27 21:25:45 2010 From: rjngrj2010 at gmail.com (gujax) Date: Mon, 27 Sep 2010 18:25:45 -0700 (PDT) Subject: Problems reading tif files References: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> Message-ID: <2d426eec-9cfa-4e3f-a418-f6f3e8ef77c2@c32g2000vbq.googlegroups.com> Thanks Christian, Here is the info: TIFF Directory at offset 0x8 (8) Subfile Type: (0 = 0x0) Image Width: 640 Image Length: 480 Bits/Sample: 32 Sample Format: IEEE floating point Compression Scheme: None Photometric Interpretation: min-is-black Samples/Pixel: 1 Rows/Strip: 480 Planar Configuration: single image plane ImageDescription: ImageJ=1.44f min=0.0 max=255.0 How can I use freeimage. Can I incorporate it with python? Any idea what do ImageJ or Matlab use. Don't they have a robust imaging toolbox. Unfortunately, I cannot afford Matlab and I am not good at Java programing to be able to implement ImageJ with numerical analysis software. Thanks much, gujax On Sep 26, 9:19?pm, Christian Heimes wrote: > Am 27.09.2010 02:31, schrieb gujax: > > > Hi, > > I have read several related e-mails dating back as far as 2006. I am > > quite confused whether PIL can open tif images. Some posts seem to say > > there isn't yet any support for PIL while there are few posts where > > PIL has been able to open tif images. So I guess, I have to ask this > > probably trivial question again. I am just learning python and PIL. I > > have tiff images which are 8 bit and 16 bit gray scale images. I > > cannot open them. Here are the errors that I encounter. > > PIL only supports a limited subset of TIFF files. Several compression > algorithms like G3 and G4 fax compression are not supported yet. PIL may > have a problem with partly broken TIFF files, too. > > > I have no idea why this happens. > > I will appreciate a resolution. The file opens with ImageJ and > > ImageMagick. It is a 8-bit RGB file. I have associated default viewer > > to be ImageMagick. I am on Lucid Linux, and other programs such as F- > > spot and Gimp cannot open those files either. > > I don't yet know how to attach image files to the post so please bear > > with me till I figure that out. > > Can you please post the output of tiffinfo for the specific file? It may > give me a hint what's going wrong. > > There aren't a lot of good alternatives for image processing in Python. > I've evaluated most of them and decided to write my own one for my > employer. It's a Cython based library around FreeImage [1] and LCMS2 [2] > and works very well. So far we have processed several million TIFF files > with more than 100 TB of raw data smoothly. I've permission to release > the software as open source but haven't found time to do a proper release. > > Christian Heimes > > [1]http://freeimage.sourceforge.net/ > [2]http://www.littlecms.com/ From nagle at animats.com Mon Sep 27 22:14:44 2010 From: nagle at animats.com (John Nagle) Date: Mon, 27 Sep 2010 19:14:44 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <4ca14fa1$0$1595$742ec2ed@news.sonic.net> On 9/27/2010 10:46 AM, namekuseijin wrote: > On 27 set, 05:46, TheFlyingDutchman wrote: >> On Sep 27, 12:58 am, p... at informatimago.com (Pascal J. Bourguignon) >> wrote: >>> RG writes: >>>> In article >>>> <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, >>>> TheFlyingDutchman wrote: >> >>>>> On Sep 22, 10:26 pm, "Scott L. Burson" wrote: >>>>>> This might have been mentioned here before, but I just came across it: a >>>>>> 2003 essay by Bruce Eckel on how reliable systems can get built in >>>>>> dynamically-typed languages. It echoes things we've all said here, but >>>>>> I think it's interesting because it describes a conversion experience: >>>>>> Eckel started out in the strong-typing camp and was won over. >> >>>>>> https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk >> The trouble with that essay is that he's comparing with C++. C++ stands alone as offering hiding without memory safety. No language did that before C++, and no language has done it since. The basic problem with C++ is that it take's C's rather lame concept of "array=pointer" and wallpapers over it with objects. This never quite works. Raw pointers keep seeping out. The mold always comes through the wallpaper. There have been better strongly typed languages. Modula III was quite good, but it was from DEC's R&D operation, which was closed down when Compaq bought DEC. John Nagle From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 22:31:33 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 28 Sep 2010 02:31:33 GMT Subject: Nautilus Python References: Message-ID: <4ca15385$0$28657$c3e8da3@news.astraweb.com> On Mon, 27 Sep 2010 15:28:34 -0700, Eduardo Ribeiro wrote: > But it doesn't work. What do you mean "doesn't work"? - It crashes the operating system; - You get a core dump; - You get an exception; - It hangs forever, never doing anything; - It does something unexpected; - Something else? -- Steven From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 22:34:39 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 28 Sep 2010 02:34:39 GMT Subject: reduced-tagged (was Re: toy list processing problem: collect similar terms) References: <8e54fd9c-1d6b-433c-b306-288a7341bc98@a36g2000yqc.googlegroups.com> Message-ID: <4ca1543f$0$28657$c3e8da3@news.astraweb.com> On Mon, 27 Sep 2010 08:18:22 -0700, Mirko wrote: > Here is my Common Lisp (and I only care about Common Lisp answers) Good for you. So why are you spamming other newsgroups with your CL solution? Not once, but three times. Replies to /dev/null. -- Steven From usenet-nospam at seebs.net Mon Sep 27 22:43:34 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 02:43:34 GMT Subject: toy list processing problem: collect similar terms References: <7xzkv5hvv0.fsf@ruckus.brouhaha.com> Message-ID: On 2010-09-26, Xah Lee wrote: > On Sep 25, 11:17??pm, Paul Rubin wrote: >> Python solution follows (earlier one with an error cancelled). ??All >> crossposting removed since crossposting is a standard trolling tactic. > btw, i disagree about your remark on crossposting. You're wrong. Crossposting is indeed a standard trolling tactic. This does not prove that all crossposters are trolls, nor does it assert that all crossposters are trolls, but it is absolutely factually correct that it's a standard trolling tactic. -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 Sep 27 22:45:50 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 02:45:50 GMT Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> Message-ID: On 2010-09-26, J?rgen Exner wrote: > It was livibetter who without any motivation or reasoning posted Python > code in CLPM. Not exactly; he posted it in a crossposted thread, which happened to include CLPM and other groups, including comp.lang.python. It is quite possible that he didn't know about the crossposting. However, while I would agree that this would constitute a form of ignorance, I'd think that, especially with how well some newsreading interfaces hide that detail, I don't think it's really worth getting angry over. -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 john at castleamber.com Mon Sep 27 23:29:46 2010 From: john at castleamber.com (John Bokma) Date: Mon, 27 Sep 2010 22:29:46 -0500 Subject: How to Deal with Xah Lee Spam/Abuse (was: toy list processing problem: collect similar terms) References: <7xzkv5hvv0.fsf@ruckus.brouhaha.com> Message-ID: <87bp7i8s0l.fsf_-_@castleamber.com> Seebs writes: > On 2010-09-26, Xah Lee wrote: >> On Sep 25, 11:17??pm, Paul Rubin wrote: >>> Python solution follows (earlier one with an error cancelled). ??All >>> crossposting removed since crossposting is a standard trolling tactic. > >> btw, i disagree about your remark on crossposting. > > You're wrong. FYI: Xah Lee is well known for his abuse of cross posting. Be happy that Google Groups limits the number of groups to crosspost to five. Related: his spamming behaviour has already resulted in Xah Lee having to look for another hosting provider [1]. Currently 1and1 provides him shelter, most likely carefully selected by Xah (as Google Groups) since 1and1 is not known for their spam fighting reputation nor clue. But one can only hope, so if you want to do something about this Xah thing, please report it with 1and1 and abuse at google.com. He won't learn respect from it, but maybe you end up being honored [2] on his collection of drivel [3]. In short: = don't reply to Xah Lee: at best it's a waste of time = if his post is abusive (crossposting to 5 groups just because you can is) report it with /and/ his hosting provider (since most of his posts are copy paste jobs of articles on his site just to drive traffic) and Google Groups (his Usenet provider of choice since they hardly do a thing about spam). [1] http://www.mail-archive.com/python-list at python.org/msg91631.html [2] http://www.google.com/search?q=site%3Axahlee.org%20bokma [3] What's sad is that some of its stuff is actually good/not bad. But tainted: Xah Lee is a spammer and a Usenet abuser. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Mon Sep 27 23:36:27 2010 From: john at castleamber.com (John Bokma) Date: Mon, 27 Sep 2010 22:36:27 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> Message-ID: <877hi68rpg.fsf@castleamber.com> Seebs writes: > On 2010-09-26, J?rgen Exner wrote: >> It was livibetter who without any motivation or reasoning posted Python >> code in CLPM. > > Not exactly; he posted it in a crossposted thread, which happened to include > CLPM and other groups, including comp.lang.python. > > It is quite possible that he didn't know about the crossposting. Oh, he does. It has been Xah's game for years. > while I would agree that this would constitute a form of ignorance, I'd think > that, especially with how well some newsreading interfaces hide that detail, > I don't think it's really worth getting angry over. You think wrong. And Jurgen should have known better than to reply several times (but like too many people in cplm he posts for posting's sake, the main reason why I don't follow that group anymore). Xah has been doing this for many years and most of his posts are just made to drive traffic to his site (hence they are copy paste of articles on his site + link(s) to his site). It's Usenet abuse, on purpose. The reason it pisses off people is that nearly weekly it causes a lot of noise in newsgroups that are really better off without the noise (IMNSHO). See my other post on how to deal with this spammer. If you've missed it: report him for spamming, since that's what he does. It already made him have to move hosting providers once. While it's not going to stop him, it will cost him money. See: http://www.google.com/search?q=site%3Axahlee.org%20bokma While I am named in that article be assured that I was not the only one contacting dreamhost (+10 for doing this, btw). Quite some people contacted me via email that they also talked with Dreamhost. Just keep reporting this spammer, and maybe 1and1 will kick it out. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From prathibhag2k4 at gmail.com Mon Sep 27 23:54:24 2010 From: prathibhag2k4 at gmail.com (Prathibha G) Date: Tue, 28 Sep 2010 09:24:24 +0530 Subject: Example of exec_proxy Message-ID: Hi Team, I am very new to this python world. Below is my problem. I have a "Machine A" where i want to execute some commands(dos commands from command prompt), delete/create some files, delete/create some directories. All this i need to do from my local host. Is there a way which i can do? Can ayone help me in achieving this? I tried using WMI module, but it only starts the processes. It is not allowing me to execute commands/ work with files and directories. I got to see this EXEC_PROXY module but i find no examples of it which is used to connect to remote machine. Could any of you provide that? -- Thank You, Prathibha -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.milliken at gmail.com Mon Sep 27 23:57:09 2010 From: peter.milliken at gmail.com (Peter) Date: Mon, 27 Sep 2010 20:57:09 -0700 (PDT) Subject: Nautilus Python References: <4ca15385$0$28657$c3e8da3@news.astraweb.com> Message-ID: On Sep 28, 12:31?pm, Steven D'Aprano wrote: > On Mon, 27 Sep 2010 15:28:34 -0700, Eduardo Ribeiro wrote: > > But it doesn't work. > > What do you mean "doesn't work"? > > - It crashes the operating system; > - You get a core dump; > - You get an exception; > - It hangs forever, never doing anything; > - It does something unexpected; > - Something else? > > -- > Steven It seems to be a fairly absolute statement - so I would assume all of the above! :-) From usenet-nospam at seebs.net Tue Sep 28 00:18:38 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 04:18:38 GMT Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> Message-ID: On 2010-09-28, John Bokma wrote: > Seebs writes: >> On 2010-09-26, J?rgen Exner wrote: >>> It was livibetter who without any motivation or reasoning posted Python >>> code in CLPM. >> Not exactly; he posted it in a crossposted thread, which happened to include >> CLPM and other groups, including comp.lang.python. >> It is quite possible that he didn't know about the crossposting. > Oh, he does. It has been Xah's game for years. But did "livibetter" know about it? I wasn't defending Xah, who is indeed at the very least clueless and disruptive. But I was sort of defending the poster who was accused of posting Python code in CLPM, because that poster may not have understood the game. -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 john at castleamber.com Tue Sep 28 00:34:22 2010 From: john at castleamber.com (John Bokma) Date: Mon, 27 Sep 2010 23:34:22 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> Message-ID: <874odajxkh.fsf@castleamber.com> Seebs writes: fup set to poster > On 2010-09-28, John Bokma wrote: >> Seebs writes: >>> On 2010-09-26, J?rgen Exner wrote: >>>> It was livibetter who without any motivation or reasoning posted Python >>>> code in CLPM. > >>> Not exactly; he posted it in a crossposted thread, which happened to include >>> CLPM and other groups, including comp.lang.python. > >>> It is quite possible that he didn't know about the crossposting. > >> Oh, he does. It has been Xah's game for years. > > But did "livibetter" know about it? I wasn't defending Xah, who is indeed > at the very least clueless and disruptive. Heh, he's not clueless, the problem is that he knows exactly what he's doing. And like most spammers, very hard to get rid off. > But I was sort of defending > the poster who was accused of posting Python code in CLPM, because that > poster may not have understood the game. Ah, clear. Well, the problem is somewhat also in CLPM where people somehow have to reply to messages like this :-(. And I am sure Xah laughes his ass off each time it happens. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From oswald.harry at gmail.com Tue Sep 28 02:30:43 2010 From: oswald.harry at gmail.com (harryos) Date: Mon, 27 Sep 2010 23:30:43 -0700 (PDT) Subject: tix problem in ubuntu karmic Message-ID: <07faa482-ce42-4297-81f4-8e45aba58a2a@a4g2000prm.googlegroups.com> hi I posted this question in ubuntu users forum but no help was forthcoming.. I hope someone can help me here. I had been using jaunty as o.s and was coding in python 2.6. While using Tix widgets in my code I came across a bug as mentioned in https://bugs.launchpad.net/ubuntu/+source/tix/+bug/371720 Also ,there was a suggested fix http://skriticos.blogspot.com/2009/07/ubuntu-jaunty-904-python-tix-fi... After that I began to get segmentation fault when I ran the code!! So ,I thought upgrading to karmic would help .But even after the upgrade I am getting segmentation fault..I reinstalled python ,tk and tix through synaptic..Still the problem persists. The versions of packages installed are python =2.6.4-0ubuntu3 python-tk =2.6.3-0ubuntu1 tix =8.4.0-6ubuntu1 tix-dev =8.4.0-6ubuntu1 tk8.5 =8.5.7-1 tk8.4 =8.4.19-3 Can someone tell me how I can solve this problem? thanks, harry From wbrehaut at mcsnet.ca Tue Sep 28 02:38:44 2010 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Tue, 28 Sep 2010 00:38:44 -0600 Subject: Nautilus Python References: <4ca15385$0$28657$c3e8da3@news.astraweb.com> Message-ID: On Mon, 27 Sep 2010 20:57:09 -0700 (PDT), Peter wrote: >On Sep 28, 12:31?pm, Steven D'Aprano T... at cybersource.com.au> wrote: >> On Mon, 27 Sep 2010 15:28:34 -0700, Eduardo Ribeiro wrote: >> > But it doesn't work. >> >> What do you mean "doesn't work"? >> >> - It crashes the operating system; >> - You get a core dump; >> - You get an exception; >> - It hangs forever, never doing anything; >> - It does something unexpected; >> - Something else? >> >> -- >> Steven > >It seems to be a fairly absolute statement - so I would assume all of >the above! :-) I assume "None of the above." Each of the above requires doing some work, so if "doesn't work" implies "does no work", then the closest it could come to that is: - It terminates almost immediately* without producing any output. *Required, or it might have been doing some work and just forgot to output the results. wwwayne From wbrehaut at mcsnet.ca Tue Sep 28 03:36:09 2010 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Tue, 28 Sep 2010 01:36:09 -0600 Subject: Introducing Kids to Programming: 2 or 3? References: <20100927124544.1d9e2ba4@geekmail.INVALID> Message-ID: <9h63a6hkui7lq68aogr5js4n4urnaia94j@4ax.com> On Mon, 27 Sep 2010 12:45:44 -0400, Andreas Waldenburger wrote: >On Mon, 27 Sep 2010 17:48:06 +0200 Marco Gallotta > wrote: > >> Since these are kids, we feel the nice changes in 3 such as removing >> integer division will help in teaching. It will also remove confusion >> when they go to download Python and grab the latest version. Since >> they're just starting, chances are almost none will be hit by the >> limited library support for at least a year or two. > >That's your answer right there. > > >> They will, however, be hit by the confusion of seeing Python 2 code >> all over the web. > >Good point. Here is may suggestion: Make the kids aware of the 2/3 >issue as early as possible, but don't go into detail. === 8< === > Later on (once they know more programming constructs to >appreciate the differences), include another lecture, specifically on >the difference between Python 2 and Python 3. > >Disclaimer: I'm not an educator. Maybe this is horrible advice. Someone >with a better understanding of kids' and learner's minds please debunk >any nonsense I may have spouted here. The only obvious bit was assuming one should "lecture" to kids. Everything else sounds good. wwwayne >/W From sensorflo at gmail.com Tue Sep 28 04:10:07 2010 From: sensorflo at gmail.com (Florian Kaufmann) Date: Tue, 28 Sep 2010 01:10:07 -0700 (PDT) Subject: How to match where the search started? Message-ID: >From the documentation: 7.2.4. Regular Expression Objects, search(string[, pos[, endpos]]) ... the '^' pattern character matches at the real beginning of the string and at positions just after a newline, but not necessarily at the index where the search is to start.... But I'd like to do just that. In Emacs regexps, I think the closest equivalent would be \=. Then I could do something like that, and also find directly adjacent matches reo = re.compile( r'(\=|...)...' ); while True mo = reo.search(text,pos) if not mo: break ... Flo From sensorflo at gmail.com Tue Sep 28 04:20:24 2010 From: sensorflo at gmail.com (Florian Kaufmann) Date: Tue, 28 Sep 2010 01:20:24 -0700 (PDT) Subject: How to match where the search started? References: Message-ID: <21a28abc-28e7-4125-b705-41168d5eb419@a9g2000yqg.googlegroups.com> The thing is that the (\=|...) group is not really part of the match. I think this gives you more the idea what I want reo = re.compile( r'(\=|.)...' ); while True mo = reo.search(text,pos) if not mo: break if text[mo.start()] == '\\' # a pseudo match. continue after the backslash else # a real match. continue after the match From sensorflo at gmail.com Tue Sep 28 04:21:17 2010 From: sensorflo at gmail.com (Florian Kaufmann) Date: Tue, 28 Sep 2010 01:21:17 -0700 (PDT) Subject: How to match where the search started? References: Message-ID: The thing is that the (\=|...) group is not really part of the match. I think this gives you more the idea what I want reo = re.compile( r'(\=|.)...' ); while True mo = reo.search(text,pos) if not mo: break if text[mo.start()] == '\\' # a pseudo match. continue after the backslash else # a real match. continue after the match From malcolm.mclean5 at btinternet.com Tue Sep 28 05:13:19 2010 From: malcolm.mclean5 at btinternet.com (Malcolm McLean) Date: Tue, 28 Sep 2010 02:13:19 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <538865ac-87c0-4a2d-81bb-6050c6d5f9df@a9g2000yqg.googlegroups.com> On Sep 27, 7:46?pm, namekuseijin wrote: > On 27 set, 05:46, TheFlyingDutchman wrote: > > Fact is: almost all user data from the external words comes into > programs as strings. No typesystem or compiler handles this fact all > that graceful...- Hide quoted text - > You're right. C should have a much better library than it does for parsing user-supplied string input. The scanf() family of functions is fine for everyday use, but not robust enough for potentially hostile inputs. atoi() had to be replaced by strtol(), but there's a need for a higher-leve function built on strtol(). I wrote a generic commandline parser once, however it's almost impossible to achieve something that is both useable and 100% bulletproof. From alexleewalk at 163.com Tue Sep 28 05:27:31 2010 From: alexleewalk at 163.com (AlexWalk) Date: Tue, 28 Sep 2010 17:27:31 +0800 (CST) Subject: About __class__ of an int literal Message-ID: In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ of an int literal will raise a SyntaxException, while other literals will not. For example. 1.__class__ is an error, while 1.1.__class__ runs ok. I searched the python issue tracker but failed to find relevant reports. I wonder if this is an unreported issue. Alex Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: From malcolm.mclean5 at btinternet.com Tue Sep 28 05:55:19 2010 From: malcolm.mclean5 at btinternet.com (Malcolm McLean) Date: Tue, 28 Sep 2010 02:55:19 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) wrote: > > On the other hand, with the dynamic typing mindset, you might even wrap > your values (of whatever numerical type) in a symbolic expression > mentionning the unit and perhaps other meta data, so that when the other > module receives it, it may notice (dynamically) that two values are not > of the same unit, but if compatible, it could (dynamically) convert into > the expected unit. ?Mission saved! > I'd like to design a language like this. If you add a quantity in inches to a quantity in centimetres you get a quantity in (say) metres. If you multiply them together you get an area, if you divide them you get a dimeionless scalar. If you divide a quantity in metres by a quantity in seconds you get a velocity, if you try to subtract them you get an error. From rgrdev_ at gmail.com Tue Sep 28 06:10:26 2010 From: rgrdev_ at gmail.com (Richard) Date: Tue, 28 Sep 2010 12:10:26 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: Malcolm McLean writes: > On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. ?Mission saved! >> > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. > or simply use c++ etc and simply use overridden operators which pick the correct algorithm.... -- "Avoid hyperbole at all costs, its the most destructive argument on the planet" - Mark McIntyre in comp.lang.c From bc at freeuk.com Tue Sep 28 06:18:41 2010 From: bc at freeuk.com (BartC) Date: Tue, 28 Sep 2010 11:18:41 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: "Malcolm McLean" wrote in message news:1d6e115c-cada-46fc-9444-01e80e0afd75 at c10g2000yqh.googlegroups.com... > On Sep 27, 9:29 pm, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. Mission saved! >> > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. As you suggested in 'Varaibles with units' comp.programming Feb 16 2008? [Yes with that spelling...] I have a feeling that would quickly make programming impossible (if you consider how many combinations of dimensions/units, and operators there might be). One approach I've used is to specify a dimension (ie. unit) only for constant values, which are then immediately converted (at compile time) to a standard unit: a:=sin(60?) # becomes sin(1.047... radians) d:=6 ins # becomes 152.4 mm Here the standard units are radians, and mm. Every other calculation uses implied units. -- Bartc From antonyjeevaraj at gmail.com Tue Sep 28 06:19:39 2010 From: antonyjeevaraj at gmail.com (antony jeevaraj) Date: Tue, 28 Sep 2010 03:19:39 -0700 (PDT) Subject: HOW I MADE $2000 IN WEEKEND WITHOUT INVEST ANYTHING (YOU CAN TOO) Message-ID: HOW I MADE $2000 IN WEEKEND WITHOUT INVEST ANYTHING (YOU CAN TOO) Easy $2 per lead (Free Referral) + Referral Commission Today I receive a email from my friend that inform me about new Pay Per Lead that pay $2 per active member during their prelaunch. Tim bekker?s internet marketing guide is a new innovative, international free Membership system where members will be able to learn new methods to make money online with detailed step by step instructions Best of all this will be totally free, and you will have a chance to Earn extra money by doing Online marketing How do I earn money? At the moment you can earn $2.50 for every active friend you refer to this free internet guide using your personal referral link which can be found at your account. you will see this link in your account after joining this network http://snipurl.com/homeearnings What?s the cost? ?As a Member of this network, you never owe us a dime?that?s our responsibility to you. What?s the Minimum Payout? ?For Pay Pal its $20, for Bank Wire transfer to any country it?s $100 So what are you waiting for ? JOIN NOW!! Discover The Secrets That Earn Me $4,256.37 Everyday! Submit your primary email address below to get FREE money making tips NOW! Start Promote Earn $2.50 Per Lead http://snipurl.com/homeearnings From tfb at tfeb.org Tue Sep 28 06:19:55 2010 From: tfb at tfeb.org (Tim Bradshaw) Date: Tue, 28 Sep 2010 11:19:55 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On 2010-09-28 10:55:19 +0100, Malcolm McLean said: > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. There are several existing systems which do this. The HP48 (and descendants I expect) support "units" which are essentially dimensions. I don't remember if it signals errors for incoherent dimensions. Mathematica also has some units support, and it definitely does not indicate an error: "1 Inch + 1 Second" is fine. There are probably lots of other systems which do similar things. From antonyjeevaraj at gmail.com Tue Sep 28 06:20:33 2010 From: antonyjeevaraj at gmail.com (antony jeevaraj) Date: Tue, 28 Sep 2010 03:20:33 -0700 (PDT) Subject: HOW I MADE $2000 IN WEEKEND WITHOUT INVEST ANYTHING (YOU CAN TOO) Message-ID: <8ce32ff9-8b3d-4984-a48b-9ade3d811476@z28g2000yqh.googlegroups.com> HOW I MADE $2000 IN WEEKEND WITHOUT INVEST ANYTHING (YOU CAN TOO) Easy $2 per lead (Free Referral) + Referral Commission Today I receive a email from my friend that inform me about new Pay Per Lead that pay $2 per active member during their prelaunch. Tim bekker?s internet marketing guide is a new innovative, international free Membership system where members will be able to learn new methods to make money online with detailed step by step instructions Best of all this will be totally free, and you will have a chance to Earn extra money by doing Online marketing How do I earn money? At the moment you can earn $2.50 for every active friend you refer to this free internet guide using your personal referral link which can be found at your account. you will see this link in your account after joining this network http://snipurl.com/homeearnings What?s the cost? ?As a Member of this network, you never owe us a dime?that?s our responsibility to you. What?s the Minimum Payout? ?For Pay Pal its $20, for Bank Wire transfer to any country it?s $100 So what are you waiting for ? JOIN NOW!! Discover The Secrets That Earn Me $4,256.37 Everyday! Submit your primary email address below to get FREE money making tips NOW! Start Promote Earn $2.50 Per Lead http://snipurl.com/homeearnings From mail at timgolden.me.uk Tue Sep 28 06:24:34 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 28 Sep 2010 11:24:34 +0100 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: <4CA1C262.6080504@timgolden.me.uk> On 28/09/2010 10:27, AlexWalk wrote: > In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ of an int literal will raise a SyntaxException, while other literals will not. For example. 1.__class__ is an error, while 1.1.__class__ runs ok. > > > I searched the python issue tracker but failed to find relevant reports. I wonder if this is an unreported issue. It's a little bit subtle. The trouble is that the parser sees a number followed by a dot and assumes that it's looking at a decimal number. When the next thing isn't a number, it raises a SyntaxError exception. You can achieve what you're after by putting a space before the dot: 1 .__class__ TJG From albert at spenarnc.xs4all.nl Tue Sep 28 08:42:40 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 28 Sep 2010 12:42:40 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: In article <87fwwvrnmf.fsf at kuiper.lan.informatimago.com>, Pascal J. Bourguignon wrote: >namekuseijin writes: > >>> in C I can have a function maximum(int a, int b) that will always >>> work. Never blow up, and never give an invalid answer. If someone >>> tries to call it incorrectly it is a compile error. >>> In a dynamic typed language maximum(a, b) can be called with incorrect >>> datatypes. Even if I make it so it can handle many types as you did >>> above, it could still be inadvertantly called with a file handle for a >>> parameter or some other type not provided for. So does Eckel and >>> others, when they are writing their dynamically typed code advocate >>> just letting the function blow up or give a bogus answer, or do they >>> check for valid types passed? If they are checking for valid types it >>> would seem that any benefits gained by not specifying type are lost by >>> checking for type. And if they don't check for type it would seem that >>> their code's error handling is poor. >> >> that is a lie. >> >> Compilation only makes sure that values provided at compilation-time >> are of the right datatype. >> >> What happens though is that in the real world, pretty much all >> computation depends on user provided values at runtime. See where are >> we heading? >> >> this works at compilation time without warnings: >> int m=numbermax( 2, 6 ); >> >> this too: >> int a, b, m; >> scanf( "%d", &a ); >> scanf( "%d", &b ); >> m=numbermax( a, b ); >> >> no compiler issues, but will not work just as much as in python if >> user provides "foo" and "bar" for a and b... fail. >> >> What you do if you're feeling insecure and paranoid? Just what >> dynamically typed languages do: add runtime checks. Unit tests are >> great to assert those. >> >> Fact is: almost all user data from the external words comes into >> programs as strings. No typesystem or compiler handles this fact all >> that graceful... > > >I would even go further. > >Types are only part of the story. You may distinguish between integers >and floating points, fine. But what about distinguishing between >floating points representing lengths and floating points representing >volumes? Worse, what about distinguishing and converting floating >points representing lengths expressed in feets and floating points >representing lengths expressed in meters. When I was at Shell (late eighties) there were people claiming to have done exactly that, statically, in ADA. I would say the dimensional checking is underrated. It must be complemented with a hard and fast rule about only using standard (SI) units internally. Oil output internal : m^3/sec Oil output printed: kbarrels/day > >If you start with the mindset of static type checking, you will consider >that your types are checked and if the types at the interface of two >modules matches you'll think that everything's ok. And six months later >you Mars mission will crash. A mission failure is a failure of management. The Ariadne crash was. Management must take care that engineering mistakes don't lead to mission failure. In the Ariadne case it was not so much engineering mistakes, but management actually standing in the way of good engineering practice. >__Pascal Bourguignon__ http://www.informatimago.com/ Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From malcolm.mclean5 at btinternet.com Tue Sep 28 09:39:27 2010 From: malcolm.mclean5 at btinternet.com (Malcolm McLean) Date: Tue, 28 Sep 2010 06:39:27 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: <4836eb5b-94d8-46b5-8b2f-f5e6a1300464@h7g2000yqn.googlegroups.com> On Sep 28, 12:19?pm, Tim Bradshaw wrote: > > There are several existing systems which do this. ?The HP48 (and > descendants I expect) support "units" which are essentially dimensions. > ?I don't remember if it signals errors for incoherent dimensions. ? > Mathematica also has some units support, and it definitely does not > indicate an error: "1 Inch + 1 Second" is fine. ?There are probably > lots of other systems which do similar things. > The problem is that if you allow expressions rather than terms then the experssions can get arbitrarily complex. sqrt(1 inch + 1 Second), for instance. On the other hand sqrt(4 inches^2) is quite well defined. The question is whether to allow sqrt(1 inch). It means using rationals rather than integers for unit superscripts. (You can argue that you can get things like km^9s^-9g^3 even in a simple units system. The difference is that these won't occur very often in real programs, just when people are messing sbout with the system, and we don't need to make messing about efficient or easy to use). From thomas at jollybox.de Tue Sep 28 10:44:54 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Tue, 28 Sep 2010 16:44:54 +0200 Subject: How to match where the search started? In-Reply-To: References: Message-ID: <201009281644.55411.thomas@jollybox.de> On Tuesday 28 September 2010, it occurred to Florian Kaufmann to exclaim: > >From the documentation: > 7.2.4. Regular Expression Objects, search(string[, pos[, endpos]]) > ... the '^' pattern character matches at the real beginning of the > string and at positions just after a newline, but not necessarily at > the index where the search is to start.... > > But I'd like to do just that. In Emacs regexps, I think the closest > equivalent would be \=. Then I could do something like that, and also > find directly adjacent matches > > reo = re.compile( r'(\=|...)...' ); > while True > mo = reo.search(text,pos) > if not mo: break > ... > > Flo You could prefix your regexp with r'(.*?)' to create a match of stuff that is between the start of search and the start of the first thing you're interested in. (untested...) From tfb at tfeb.org Tue Sep 28 10:55:26 2010 From: tfb at tfeb.org (Tim Bradshaw) Date: Tue, 28 Sep 2010 15:55:26 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <4836eb5b-94d8-46b5-8b2f-f5e6a1300464@h7g2000yqn.googlegroups.com> Message-ID: On 2010-09-28 14:39:27 +0100, Malcolm McLean said: > he problem is that if you allow expressions rather than terms then > the experssions can get arbitrarily complex. sqrt(1 inch + 1 Second), > for instance. I can't imagine a context where 1 inch + 1 second would not be an error, so this is a slightly odd example. Indeed I think that in dimensional analysis summing (or comparing) things with different dimensions is always an error. > > On the other hand sqrt(4 inches^2) is quite well defined. The question > is whether to allow sqrt(1 inch). It means using rationals rather than > integers for unit superscripts. There's a large existing body of knowledge on dimensional analysis (it's a very important tool for physics, for instance), and obviously the answer is to do whatever it does. Raising to any power is fine, I think (but transcendental functions, for instance, are never fine, because they are equivalent to summing things with different dimensions, which is obvious if you think about the Taylor expansion of a transcendental function). --tim From python at mrabarnett.plus.com Tue Sep 28 11:07:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Sep 2010 16:07:47 +0100 Subject: How to match where the search started? In-Reply-To: References: Message-ID: <4CA204C3.903@mrabarnett.plus.com> On 28/09/2010 09:10, Florian Kaufmann wrote: >> From the documentation: > > 7.2.4. Regular Expression Objects, search(string[, pos[, endpos]]) > ... the '^' pattern character matches at the real beginning of the > string and at positions just after a newline, but not necessarily at > the index where the search is to start.... > > But I'd like to do just that. In Emacs regexps, I think the closest > equivalent would be \=. Then I could do something like that, and also > find directly adjacent matches > > reo = re.compile( r'(\=|...)...' ); > while True > mo = reo.search(text,pos) > if not mo: break > ... > If you want to anchor the regex at the start position 'pos' then use the 'match' method instead. From deets at web.de Tue Sep 28 11:11:29 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 28 Sep 2010 17:11:29 +0200 Subject: relative imports and sub-module execution References: <73156baa-5774-45f9-a92c-50f9573eedd9@p24g2000pra.googlegroups.com> Message-ID: <874od9q4wu.fsf@web.de> King writes: > Hi, > > After reading couple of docs and articles, I have implemented a simple > test package with nested modules. > When running "main.py", everything is working fine. Some of my sub- > modules has some small test routines for debug purpose. > It's because I am using relative package imports at the top, I am not > able to run these sub modules individually. > > For example, this works when running from main.py > > Here is example structure > > main.py > __init__.py > core/ > __init__.py > folder1 > __init__.py > f1a.py > f1b.py > folder2 > __init__.py > f2a.py > f2b.py > > in folder2/f2b.py, I am importing > > from core.folder1 import f1a > print f1a.myvar > > Now I can't execute 'f2b.py' individually. It's giving an error: > > ImportError: No module named core.folder2 > > Is this mean when you have created a package where modules are using > relative imports, they can't execute individually? The problem is your python-path. Python will put the path of the script that you execute into the sys.path - but not attempt to guess that you actually are deep within a package hierarchy and want the path two up from there in sys.path as well. Which is the reason why you have to do that yourself. My solution to this is to always use setuptools, even for the tiniest of projects, and simply create a setup.py with some minimal information in it, and then do python setup.py develop This will put a EGG-link into the site-packages directory. Usually, for not clobbering my system's python, I use a virtualenv also. With this setup, I can safely import from "core" all the time. Diez From sensorflo at gmail.com Tue Sep 28 12:32:10 2010 From: sensorflo at gmail.com (Florian Kaufmann) Date: Tue, 28 Sep 2010 09:32:10 -0700 (PDT) Subject: How to match where the search started? References: Message-ID: > If you want to anchor the regex at the start position 'pos' then use > the 'match' method instead. The wickedly problem is that matching at position 'pos' is not a requirement, its an option. Look again at my 2nd example, the r'(\=|.)...' part, which (of course wrongly) assumes that \= means 'match at the beginning of the search'. Before the match I am really interested in, there is the start of the search, OR there is any character. From brian.curtin at gmail.com Tue Sep 28 12:33:24 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 28 Sep 2010 11:33:24 -0500 Subject: minimal D: need software testers In-Reply-To: <43bd55e3-e924-40b5-a157-b57ac8544b5f@f25g2000yqc.googlegroups.com> References: <43bd55e3-e924-40b5-a157-b57ac8544b5f@f25g2000yqc.googlegroups.com> Message-ID: On Mon, Sep 27, 2010 at 10:07, Kruptein wrote: > Hey, > > I've released the second alpha for minimal-D a program I've written in > python which should make developing easier. > I need people to test the app on bugs and give ideas. > > It is written in python using the wxPython toolkit and is linux-only. > (using on windows is on own risk) > > You can download a .deb or a .tar.gz from http://launchpad.net/minimal What type of testing do you currently do? -------------- next part -------------- An HTML attachment was scrubbed... URL: From niklas.holsti at tidorum.invalid Tue Sep 28 12:52:43 2010 From: niklas.holsti at tidorum.invalid (Niklas Holsti) Date: Tue, 28 Sep 2010 19:52:43 +0300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <8gekqrFnbnU1@mid.individual.net> Albert van der Horst wrote: > In article <87fwwvrnmf.fsf at kuiper.lan.informatimago.com>, ... >> I would even go further. >> >> Types are only part of the story. You may distinguish between integers >> and floating points, fine. But what about distinguishing between >> floating points representing lengths and floating points representing >> volumes? Worse, what about distinguishing and converting floating >> points representing lengths expressed in feets and floating points >> representing lengths expressed in meters. > > When I was at Shell (late eighties) there were people claiming > to have done exactly that, statically, in ADA. It is cumbersome to do it statically, in the current Ada standard. Doing it by run-time checks in overloaded operators is easier, but of course has some run-time overhead. There are proposals to extend Ada a bit to make a static check of physical units ("dimensions") simpler. See http://www.ada-auth.org/cgi-bin/cvsweb.cgi/acs/ac-00184.txt?rev=1.3&raw=Y and inparticular the part where Edmond Schonberg explains a suggestion for the GNAT Ada compiler. > A mission failure is a failure of management. The Ariadne crash was. Just a nit, the launcher is named "Ariane". -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ . From jeff.hobbs at gmail.com Tue Sep 28 13:24:11 2010 From: jeff.hobbs at gmail.com (Jeff Hobbs) Date: Tue, 28 Sep 2010 10:24:11 -0700 (PDT) Subject: tix problem in ubuntu karmic References: <07faa482-ce42-4297-81f4-8e45aba58a2a@a4g2000prm.googlegroups.com> Message-ID: <2b38fd3e-ee3c-4297-a8ed-43ebaf380987@p24g2000pra.googlegroups.com> On Sep 27, 11:30?pm, harryos wrote: > I had been using ?jaunty as o.s and was coding in python 2.6. While > using Tix widgets in my code I came across a bug as mentioned in > > https://bugs.launchpad.net/ubuntu/+source/tix/+bug/371720 ... > So ,I ?thought upgrading to karmic would help .But even after the > upgrade I am getting segmentation fault..I reinstalled python ,tk and > tix through synaptic..Still the problem persists. > > The versions of packages installed ?are > > python ? =2.6.4-0ubuntu3 > python-tk =2.6.3-0ubuntu1 > tk8.5 =8.5.7-1 > tk8.4 =8.4.19-3 > tix ?=8.4.0-6ubuntu1 > tix-dev =8.4.0-6ubuntu1 As the first link indicates, Tix 8.4.3 has this fixed, which is the latest stable version: https://sourceforge.net/projects/tix/files/ Try building that from source and using it in place of Tix 8.4.0 that you are currently using. Jeff From tar at sevak.isi.edu Tue Sep 28 13:28:08 2010 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 28 Sep 2010 10:28:08 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: Malcolm McLean writes: > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. Done in 1992. See citation at and my extension to it as part of the Loom system: -- Thomas A. Russ, USC/Information Sciences Institute From sylvain.thenault at logilab.fr Tue Sep 28 13:34:01 2010 From: sylvain.thenault at logilab.fr (Sylvain =?utf-8?B?VGjDqW5hdWx0?=) Date: Tue, 28 Sep 2010 19:34:01 +0200 Subject: [ANN] (probably) last version of Pylint supporting python 2.3 released Message-ID: <20100928173401.GM2916@lupus.logilab.fr> Hi there! As someone stuck with python 2.3 tried to use pylint, we made some fixes to get python 2.3 supports back. This resulted in the release of pylint 0.21.3, logilab-astng 0.20.3 and logilab-common 0.52 today. At the time of porting pylint to py3k, this will much probably be the latest set of versions to use to get pylint working with python 2.3 code. And maybe, unless you people think it would be a shame, also for python 2.4, so we can drop support for the old compiler module. ciao, -- Sylvain Th?nault LOGILAB, Paris (France) Formations Python, Debian, M?th. Agiles: http://www.logilab.fr/formations D?veloppement logiciel sur mesure: http://www.logilab.fr/services CubicWeb, the semantic web framework: http://www.cubicweb.org From xahlee at gmail.com Tue Sep 28 13:39:31 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 28 Sep 2010 10:39:31 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> <874odajxkh.fsf@castleamber.com> Message-ID: On Sep 27, 9:34?pm, John Bokma wrote: > Seebs writes: > > fup set to poster > > > On 2010-09-28, John Bokma wrote: > >> Seebs writes: > >>> On 2010-09-26, J?rgen Exner wrote: > >>>> It was livibetter who without any motivation or reasoning posted Python > >>>> code in CLPM. > > >>> Not exactly; he posted it in a crossposted thread, which happened to include > >>> CLPM and other groups, including comp.lang.python. > > >>> It is quite possible that he didn't know about the crossposting. > > >> Oh, he does. It has been Xah's game for years. > > > But did "livibetter" know about it? ?I wasn't defending Xah, who is indeed > > at the very least clueless and disruptive. > > Heh, he's not clueless, the problem is that he knows exactly what he's > doing. And like most spammers, very hard to get rid off. > > > But I was sort of defending > > the poster who was accused of posting Python code in CLPM, because that > > poster may not have understood the game. > > Ah, clear. Well, the problem is somewhat also in CLPM where people > somehow have to reply to messages like this :-(. And I am sure Xah > laughes his ass off each time it happens. Hi John Bokma, can you stop this? doesn't seems fruitful to keep on this. if you don't like my posts, ignore them? i don't post in comp.lang.python or comp.lang.perl.misc that often... maybe have done so 5 times this year. i visited your home page http://johnbokma.com/mexit/2010/08/15/ and there are really a lot beautiful photos. this isn't bribery or something like that. I've been annoyed by you, of course, but it's not fruitful to keep going on this. Best, Xah ? xahlee.org ? From python at mrabarnett.plus.com Tue Sep 28 13:54:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Sep 2010 18:54:05 +0100 Subject: How to match where the search started? In-Reply-To: References: Message-ID: <4CA22BBD.6020800@mrabarnett.plus.com> On 28/09/2010 17:32, Florian Kaufmann wrote: >> If you want to anchor the regex at the start position 'pos' then use >> the 'match' method instead. > > The wickedly problem is that matching at position 'pos' is not a > requirement, its an option. Look again at my 2nd example, the > r'(\=|.)...' part, which (of course wrongly) assumes that \= means > 'match at the beginning of the search'. Before the match I am really > interested in, there is the start of the search, OR there is any > character. An alternative is to use the 'regex' module, available from PyPI: http://pypi.python.org/pypi/regex It has \G, which is the anchor for the start position. From xahlee at gmail.com Tue Sep 28 13:56:55 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 28 Sep 2010 10:56:55 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> Message-ID: <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> xah wrote: > in anycase, how's ?do? not imperative? On Sep 28, 6:27?am, namekuseijin wrote: > > how's ?do? a ?named let?? can you show example or reference of that > > proposal? (is it worthwhile?) > > I'll post it again in the hope you'll read this time: > > " > (do ((i 0 (+ 1 i)) ?; i initially 1, (+ 1 i) at each "step" > ? ? ?(r 0 (+ i r))) ; r initially 0, (+ i r) at each "step" > ? ((> i 5) r)) ? ? ?; when i>5, return r > => 15 > > it's merely a macro (syntax) that gets transformed into this: > (let loop ((i 0) > ? ? ? ? ? ?(r 0)) > ? (if (> i 5) r > ? ? (loop (+ 1 i) (+ i r)))) > => 15 > > which is merely a macro that essentially gets transformed into this: > ((lambda (loop) > ? ?(loop loop 0 0)) > ?(lambda (loop i r) > ? ?(if (> i 5) r > ? ? ? ?(loop loop (+ 1 i) (+ i r))))) > => 15 > > which, as you can see, is merely function application. ?There's > nothing there except evaluation of arguments, application of arguments > to function and function return. ?It's not because they chose `do', or > `for' or `while' for naming such syntax, that it behaves the same as > their imperative homographs." > > > as i said, regarding do: ?do? in general in any lang is simply > > impreative. We don't even have to know the details. I don't care > > whatnot fuck proposal from whatnot lisp of what's actually going on. > > If it is named ?do?, it is imperative. > > It's not: ?one can name factorial do. ?It's just a name. ?Who doesn't > like do? ?It's short, to the point... ultimately, all lang gets transformed at the compiler level to become machine instructions, which is imperative programing in the ultimate sense. You say that ?do? is merely macro and ultimately function application. But to what level should we go down this chain on how the language actually works when evaluating a function in source code? any functional lang, quickly becomes imperative when compiled to some intermediate code or interpreted. In a sense, it can't be any other way. Functions are abstract mathematical ideas, while ?do? loop or any instruction are actual steps of algorithms. Xah ? xahlee.org ? From john at castleamber.com Tue Sep 28 14:13:27 2010 From: john at castleamber.com (John Bokma) Date: Tue, 28 Sep 2010 13:13:27 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> <874odajxkh.fsf@castleamber.com> Message-ID: <87bp7hybw8.fsf@castleamber.com> Xah Lee writes: > can you stop this? Can you stop crossposting? And if there is really, really a need to crosspost, can you please set the follow-up to? > doesn't seems fruitful to keep on this. > > if you don't like my posts, ignore them? i don't post in > comp.lang.python or comp.lang.perl.misc that often... maybe have done > so 5 times this year. Which is enough to disrupt those groups for days. > i visited your home page > http://johnbokma.com/mexit/2010/08/15/ > and there are really a lot beautiful photos. Thanks Xah. Like I wrote, your site /does/ have good information, it's so sad that you somehow think it's necessary to spam Usenet to get visitors. Or maybe you've another reason, don't know. But it /is/ Usenet abuse. > this isn't bribery or something like that. I've been annoyed by you, > of course, but it's not fruitful to keep going on this. Well, you annoy me, I annoy you. It's in your hands to make it stop. My advice is: 1) remove all the excessive swearing from your site. If you have a point, you don't need it. Your argument(s) without the swearing should speak for themselves 2) Stop abusing Usenet. Instead focus on writing more good stuff on your site. 1) & 2) will keep me from linking to your site, ever. And I am sure I am not alone in this. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From gneuner2 at comcast.net Tue Sep 28 14:21:29 2010 From: gneuner2 at comcast.net (George Neuner) Date: Tue, 28 Sep 2010 14:21:29 -0400 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: On 28 Sep 2010 12:42:40 GMT, Albert van der Horst wrote: >I would say the dimensional checking is underrated. It must be >complemented with a hard and fast rule about only using standard >(SI) units internally. > >Oil output internal : m^3/sec >Oil output printed: kbarrels/day "barrel" is not an SI unit. And when speaking about oil there isn't even a simple conversion. 42 US gallons ? 34.9723 imp gal ? 158.9873 L [In case those marks don't render, they are meant to be the double-tilda sign meaning "approximately equal".] George From python at mrabarnett.plus.com Tue Sep 28 14:40:19 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Sep 2010 19:40:19 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <4CA23693.3060605@mrabarnett.plus.com> On 28/09/2010 19:21, George Neuner wrote: > On 28 Sep 2010 12:42:40 GMT, Albert van der Horst > wrote: > >> I would say the dimensional checking is underrated. It must be >> complemented with a hard and fast rule about only using standard >> (SI) units internally. >> >> Oil output internal : m^3/sec >> Oil output printed: kbarrels/day > > "barrel" is not an SI unit. And when speaking about oil there isn't > even a simple conversion. > > 42 US gallons ? 34.9723 imp gal ? 158.9873 L > > [In case those marks don't render, they are meant to be the > double-tilda sign meaning "approximately equal".] > Do you mean: 42 US gallons ? 34.9723 imp gal ? 158.9873 l The post as I received it was encoded as 7-bit us-ascii, so definitely no double-tilde. This post was encoded as utf-8. From rog at pynguins.com Tue Sep 28 14:44:59 2010 From: rog at pynguins.com (Rog) Date: Tue, 28 Sep 2010 19:44:59 +0100 Subject: list problem... Message-ID: Hi all, Have been grappling with a list problem for hours... a = [2, 3, 4, 5,.....] b = [4, 8, 2, 6,.....] Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and b[2] is present. I have tried sets, zip etc with no success. I am tackling Euler projects with Python 3.1, with minimal knowledge, and having to tackle the language as I progress. Enjoyable frustration :) -- Rog http://www.rog.pynguins.com From emayssat at gmail.com Tue Sep 28 14:55:18 2010 From: emayssat at gmail.com (Toto) Date: Tue, 28 Sep 2010 11:55:18 -0700 (PDT) Subject: Reoedering indexes in list of list Message-ID: Hello, I have a list of list assume myList[x][y] is integer I would like to create an alias to that list which I could call this way: alias[y][x] returns myList[x][y] how can I do that ? (python 2.6) (I have a feeling I should use 'property' ;) Thanks, -- From anand.shashwat at gmail.com Tue Sep 28 14:55:27 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 29 Sep 2010 00:25:27 +0530 Subject: list problem... In-Reply-To: References: Message-ID: On Wed, Sep 29, 2010 at 12:14 AM, Rog wrote: > Hi all, > Have been grappling with a list problem for hours... > a = [2, 3, 4, 5,.....] > b = [4, 8, 2, 6,.....] > Basicly I am trying to place a[0], b[0] in a seperate list > IF a[2] and b[2] is present. > You are not exactly clear with your problem statement. Care to elaborate it more. > I have tried sets, zip etc with no success. > I am tackling Euler projects with Python 3.1, with minimal > knowledge, and having to tackle the language as I progress. > Enjoyable frustration :) > > -- > Rog > http://www.rog.pynguins.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Tue Sep 28 14:59:08 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 28 Sep 2010 11:59:08 -0700 Subject: list problem... In-Reply-To: References: Message-ID: On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > Hi all, > Have been grappling with a list problem for hours... > a = [2, 3, 4, 5,.....] > b = [4, 8, 2, 6,.....] > Basicly I am trying to place a[0], b[0] in a seperate list > IF a[2] and b[2] is present. > I have tried sets, zip etc with no success. > I am tackling Euler projects with Python 3.1, with minimal > knowledge, and having to tackle the language as I progress. > Enjoyable frustration ?:) I'm not clear on what your actual problem is, could you restate it? It sounds like you want to copy the ith element out of a and b into some other list- call it c- when the (i+2)th element meets some condition. What's the condition? Geremy Condra From clp2 at rebertia.com Tue Sep 28 15:10:26 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 28 Sep 2010 12:10:26 -0700 Subject: Reoedering indexes in list of list In-Reply-To: References: Message-ID: On Tue, Sep 28, 2010 at 11:55 AM, Toto wrote: > Hello, > > I have a list of list > assume myList[x][y] is integer > I would like to create an alias to that list which I could call this > way: > alias[y][x] returns myList[x][y] If your "alias" can be read-only: alias = zip(*myList) Cheers, Chris -- http://blog.rebertia.com From no.email at nospam.invalid Tue Sep 28 15:11:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 28 Sep 2010 12:11:39 -0700 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> <874odajxkh.fsf@castleamber.com> <87bp7hybw8.fsf@castleamber.com> Message-ID: <7xmxr1isyc.fsf@ruckus.brouhaha.com> John Bokma writes: > Xah Lee writes: ... > Can you stop crossposting? John, can you ALSO stop crossposting? From rog at pynguins.com Tue Sep 28 15:11:51 2010 From: rog at pynguins.com (Rog) Date: Tue, 28 Sep 2010 20:11:51 +0100 Subject: list problem... References: Message-ID: On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >> Hi all, >> Have been grappling with a list problem for hours... a = [2, 3, 4, >> 5,.....] >> b = [4, 8, 2, 6,.....] >> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and >> b[2] is present. >> I have tried sets, zip etc with no success. I am tackling Euler projects >> with Python 3.1, with minimal knowledge, and having to tackle the >> language as I progress. Enjoyable frustration ?:) > > I'm not clear on what your actual problem is, could you restate it? > > It sounds like you want to copy the ith element out of a and b into some > other list- call it c- when the (i+2)th element meets some condition. > What's the condition? > > Geremy Condra The condition is that the i-th element is inverted, but not equal. eg 4,2 - 2,4 , 34,5 - 5,34 etc. Hope that is clearer. Thanks for the response. -- Rog http://www.rog.pynguins.com From 3-nospam at temporary-address.org.uk Tue Sep 28 15:12:51 2010 From: 3-nospam at temporary-address.org.uk (Nick) Date: Tue, 28 Sep 2010 20:12:51 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: <87sk0tvg0c.fsf@temporary-address.org.uk> tar at sevak.isi.edu (Thomas A. Russ) writes: > Malcolm McLean writes: > >> I'd like to design a language like this. If you add a quantity in >> inches to a quantity in centimetres you get a quantity in (say) >> metres. If you multiply them together you get an area, if you divide >> them you get a dimeionless scalar. If you divide a quantity in metres >> by a quantity in seconds you get a velocity, if you try to subtract >> them you get an error. > > Done in 1992. > > See > > citation at > > and my extension to it as part of the Loom system: > I didn't go as far as that, but: $ cat test.can database input 'canal.sqlite' for i=link 'Braunston Turn' to '.*' print 'It is ';i.distance into 'distance:%M';' miles (which is '+i.distance into 'distance:%K'+' km) to ';i.place2 into 'name:place' end for i $ canal test.can It is 0.10 miles (which is 0.16 km) to London Road Bridge No 90 It is 0.08 miles (which is 0.13 km) to Bridge No 95 It is 0.19 miles (which is 0.30 km) to Braunston A45 Road Bridge No 91 -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk From kst-u at mib.org Tue Sep 28 15:15:07 2010 From: kst-u at mib.org (Keith Thompson) Date: Tue, 28 Sep 2010 12:15:07 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: George Neuner writes: > On 28 Sep 2010 12:42:40 GMT, Albert van der Horst > wrote: >>I would say the dimensional checking is underrated. It must be >>complemented with a hard and fast rule about only using standard >>(SI) units internally. >> >>Oil output internal : m^3/sec >>Oil output printed: kbarrels/day > > "barrel" is not an SI unit. He didn't say it was. Internal calculations are done in SI units (in this case, m^3/sec); on output, the internal units can be converted to whatever is convenient. > And when speaking about oil there isn't > even a simple conversion. > > 42 US gallons ? 34.9723 imp gal ? 158.9873 L > > [In case those marks don't render, they are meant to be the > double-tilda sign meaning "approximately equal".] There are multiple different kinds of "barrels", but "barrels of oil" are (consistently, as far as I know) defined as 42 US liquid gallons. A US liquid gallon is, by definition, 231 cubic inches; an inch is, by definition, 0.0254 meter. So a barrel of oil is *exactly* 0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 kbarrels/day. (Please feel free to check my math.) That's admittedly a lot of digits, but there's no need for approximations (unless they're imposed by the numeric representation you're using). -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From emayssat at gmail.com Tue Sep 28 15:29:23 2010 From: emayssat at gmail.com (Toto) Date: Tue, 28 Sep 2010 12:29:23 -0700 (PDT) Subject: Reoedering indexes in list of list References: Message-ID: <7d4f519e-f1f4-494a-bf74-36669e236839@t5g2000prd.googlegroups.com> > If your "alias" can be read-only: > alias = zip(*myList) a=[['00','01'],['10','11']] l=zip(*a) print(l) returns... [('00', '10'), ('01', '11')] IS NOT AT ALL WHAT I WANT ;-) What I want is print a[1][0] '10' but print l[1][0] '01' notice the indexes of the list l are inverted... From nad at acm.org Tue Sep 28 15:30:29 2010 From: nad at acm.org (Ned Deily) Date: Tue, 28 Sep 2010 12:30:29 -0700 Subject: Python 2.7 installation problem References: Message-ID: In article , Ronald Guida wrote: > Sorry, I have one additional piece of information that might be helpful to > others. I have discovered that the *.so files that were not installed, were > actually installed to the ~/lib/python2.6/ folder instead of the > ~/lib/python2.7/ folder where they belong. > > On Sun, Sep 26, 2010 at 9:25 PM, Ronald Guida wrote: > > > Solved -- "make install" failed to actually install a subset of files. I > > had to manually copy them instead. > > > > Specifics: > > I started from /home/oddron/installers/python/Python-2.7/ and executed the > > usual commands: > > $ ./configure --prefix=$HOME > > $ make > > $ make install > > > > I have found that the installer failed to install the contents of > > "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", > > which contains *.so files. This explains why "import collections" would > > work from > > the built python in /home/oddron/installers/python/Python-2.7/, but would > > fail in the installed > > python in /home/oddron/bin/ . > > > > I manually copied the contents of > > "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", > > to /home/oddron/lib/python2.7/ and now everything seems to work. Works for me on a current Debian "testing" system and elsewhere. Any problem in this area is almost surely due to contamination of the build environment by an environment variable setting or possibly something in $HOME/.pydistutils.cfg or not starting with a clean If you still have the build directory, examine the configured Makefile for suspicious values, particularly DESTSHARED. -- Ned Deily, nad at acm.org From emayssat at gmail.com Tue Sep 28 15:30:54 2010 From: emayssat at gmail.com (Toto) Date: Tue, 28 Sep 2010 12:30:54 -0700 (PDT) Subject: Reoedering indexes in list of list References: <7d4f519e-f1f4-494a-bf74-36669e236839@t5g2000prd.googlegroups.com> Message-ID: <03bb8b3d-6bdd-4f45-8f5f-ec14267bf5e4@g6g2000pro.googlegroups.com> again I want: alias[y][x] returns myList[x][y] > print a[1][0] > '10' > but print l[1][0] > '01' > > notice the indexes ?of the list l are inverted... From emayssat at gmail.com Tue Sep 28 15:34:57 2010 From: emayssat at gmail.com (Toto) Date: Tue, 28 Sep 2010 12:34:57 -0700 (PDT) Subject: Reoedering indexes in list of list References: <7d4f519e-f1f4-494a-bf74-36669e236839@t5g2000prd.googlegroups.com> <03bb8b3d-6bdd-4f45-8f5f-ec14267bf5e4@g6g2000pro.googlegroups.com> Message-ID: <422ddb9f-ea12-4e36-8b19-1312b93dceb0@g6g2000pro.googlegroups.com> heu.... the zip trick actually works... my mistake! From pjdelport at gmail.com Tue Sep 28 15:42:18 2010 From: pjdelport at gmail.com (Piet Delport) Date: Tue, 28 Sep 2010 21:42:18 +0200 Subject: [ctpug] Introducing Kids to Programming: 2 or 3? In-Reply-To: References: Message-ID: On Mon, Sep 27, 2010 at 5:48 PM, Marco Gallotta wrote: > > > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. This is really great news! Sounds like you guys have been doing an amazing job. As for your course notes and exercises, targeting 3.x sounds like the more productive choice: - As you point, many of the changes in 3.x make it directly more sensible and suitable for teaching purposes. The avoidance of 2.x's str/unicode confusion should be one of the biggest points for first-time programmers, but all the other special cases and legacy cruft that's been removed from 3.x will help reduce distractions to learning. - As Niel Muller points out, library compatibility with 3.x is relatively good, and will only grow with time, while 2.x will become increasingly unsupported. The fact that you'll probably have to stick for the next few years with the material you produce now should seal the deal in favor of targeting 3.x. - The students whose learning advances far enough that they want to play around with more involved Python libraries are also the ones for whom learning 2.x/3.x differences shouldn't pose any difficulty anymore: if they *really* hit a sticking point that requires the use of 2.x (for now), they can just use it, without having to saddle all beginning learners with it. I doubt that students will be confused much more by seeing 2.x code all over the web, though; it's not really any different to 2.x users seeing code that uses old-style classes, string exceptions, and so on. There's not much that can be done about this: at some point, interested learners will have to encounter old idioms and legacy code, regardless of the choice of 2.x or 3.x now. -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Tue Sep 28 15:46:58 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 28 Sep 2010 20:46:58 +0100 Subject: Reoedering indexes in list of list References: <7d4f519e-f1f4-494a-bf74-36669e236839@t5g2000prd.googlegroups.com> Message-ID: <87r5gdlkgd.fsf@gmail.com> Toto writes: >> If your "alias" can be read-only: >> alias = zip(*myList) > > > > a=[['00','01'],['10','11']] > l=zip(*a) > print(l) > > returns... [('00', '10'), ('01', '11')] > > IS NOT AT ALL WHAT I WANT ;-) > > What I want is > > print a[1][0] > '10' > but print l[1][0] > '01' > > notice the indexes of the list l are inverted... Ahem... >>> a = [['00', '01'], ['10', '11']] >>> l = zip(*a) >>> a[1][0] '10' >>> l[1][0] '01' Looks *exactly* like what you want to me. It doesn't take that long to check. -- Arnaud From sschwarzer at sschwarzer.net Tue Sep 28 16:07:09 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Tue, 28 Sep 2010 22:07:09 +0200 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: <4CA24AED.7000901@sschwarzer.net> Hello Alex, On 2010-09-28 11:27, AlexWalk wrote: > In python 3.1.2(I'm using windows edition, 32bit), > accessing __class__ of an int literal will raise a > SyntaxException, while other literals will not. For > example. 1.__class__ is an error, while 1.1.__class__ runs > ok. > > I searched the python issue tracker but failed to find > relevant reports. I wonder if this is an unreported > issue. It's nothing serious; the Python parser gets a bit confused and probably reads the dot as decimal point. If you use (1).__class__, you get what you expected. Stefan From hansmu at xs4all.nl Tue Sep 28 16:08:44 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 28 Sep 2010 22:08:44 +0200 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: <4ca24b73$0$41110$e4fe514c@news.xs4all.nl> Tim Golden wrote: > On 28/09/2010 10:27, AlexWalk wrote: >> In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ >> of an int literal will raise a SyntaxException, while other literals >> will not. For example. 1.__class__ is an error, while 1.1.__class__ >> runs ok. >> >> >> I searched the python issue tracker but failed to find relevant >> reports. I wonder if this is an unreported issue. > > It's a little bit subtle. The trouble is that the parser > sees a number followed by a dot and assumes that it's looking > at a decimal number. When the next thing isn't a number, it > raises a SyntaxError exception. > > You can achieve what you're after by putting a space before the dot: > > 1 .__class__ Alternatively, you can use parenthesis: (1).__class__ Some people find one solution uglier than the other. -- HansM From anand.shashwat at gmail.com Tue Sep 28 16:09:42 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 29 Sep 2010 01:39:42 +0530 Subject: list problem... In-Reply-To: <4CA245DB.7080609@pynguins.com> References: <4CA245DB.7080609@pynguins.com> Message-ID: On Wed, Sep 29, 2010 at 1:15 AM, rog wrote: > Shashwat Anand wrote: > > >> >> On Wed, Sep 29, 2010 at 12:14 AM, Rog > rog at pynguins.com>> wrote: >> >> Hi all, >> Have been grappling with a list problem for hours... >> a = [2, 3, 4, 5,.....] >> b = [4, 8, 2, 6,.....] >> Basicly I am trying to place a[0], b[0] in a seperate list >> IF a[2] and b[2] is present. >> >> >> You are not exactly clear with your problem statement. >> Care to elaborate it more. >> >> I have tried sets, zip etc with no success. >> I am tackling Euler projects with Python 3.1, with minimal >> knowledge, and having to tackle the language as I progress. >> Enjoyable frustration :) >> >> -- >> Rog >> http://www.rog.pynguins.com >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> >> -- >> ~l0nwlf >> > > "Let d(/n/) be defined as the sum of proper divisors of /n/ (numbers less > than /n/ which divide evenly into /n/). > If d(/a/) = /b/ and d(/b/) = /a/, where /a/ ? /b/, then /a/ and /b/ are an > amicable pair and each of /a/ and /b/ are called amicable numbers. > > For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, > 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, > 71 and 142; so d(284) = 220. > > Evaluate the sum of all the amicable numbers under 10000." > > from Project Euler. > I have all answers contained in two lists but need to extract the amicable > pairs. > eg > a = [200, 4, 284,.....] > b = [284, 9, 200, ......] > Hope that helps. > Thanks for the link. > I am not sure how and what you managed, but what I understand you need to calculate sum of divisors. A quick unoptimized solution can be, >>> def divsum(n):return sum(i for i in range(1, n) if not n % i)... >>> divsum(220)284>>> divsum(284)220 Now all is left is looping and little maths, since upper bound is not high, brute force is Ok. http://codepad.org/g6PRyoiV # For reference Also I guess you missed 'Reply All', please take care of it next time. > Rog > > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Tue Sep 28 16:12:56 2010 From: john at castleamber.com (John Bokma) Date: Tue, 28 Sep 2010 15:12:56 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> <874odajxkh.fsf@castleamber.com> <87bp7hybw8.fsf@castleamber.com> <7xmxr1isyc.fsf@ruckus.brouhaha.com> Message-ID: <8739sty6d3.fsf@castleamber.com> Paul Rubin writes: > John Bokma writes: >> Xah Lee writes: ... >> Can you stop crossposting? > > John, can you ALSO stop crossposting? Since the issue is on-topic in all groups: no. I did set a follow-up header, which you ignored and on top of that redirected the thing to comp.lang.python. So: Paul, can you ALSO stop acting like a complete ass? -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From irmen.NOSPAM at xs4all.nl Tue Sep 28 16:30:58 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 28 Sep 2010 22:30:58 +0200 Subject: Pyro 4.2 released Message-ID: <4ca25083$0$41112$e4fe514c@news.xs4all.nl> Pyro 4.2 --------- I'm pleased to announce the release of Pyro 4.2! Detailed info here: http://www.razorvine.net/python/Pyro Download here: http://www.xs4all.nl/~irmen/pyro4/download/ Python package index entry: http://pypi.python.org/pypi/Pyro4 License: MIT software license. Note: Pyro 4 is not finalized, this is still a beta release. Changes ------- The most important changes compared to Pyro 4.1 are: - toplevel package renamed to Pyro4 to allow parallel installation of Pyro 3.x and Pyro4 - python 3.x compatibility What is Pyro? ------------- PYthon Remote Objects provides a very easy way of remote communication between python objects somewhere in a network. It enables you to do remote method calls on objects as if they were normal local objects. Objects can be located by a direct identifier or indirectly by logical, humanly-readable names that are managed in a name server. Pyro is designed to be simple (but powerful) so it's only a manner of adding a few lines of code to ignite your objects. Simple example: http://www.razorvine.net/python/Pyro/Example Enjoy, Irmen de Jong From digitig at gmail.com Tue Sep 28 16:58:58 2010 From: digitig at gmail.com (Tim Rowe) Date: Tue, 28 Sep 2010 21:58:58 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: On 27 September 2010 18:46, namekuseijin wrote: > Fact is: ?almost all user data from the external words comes into > programs as strings. Sorry, sent this to the individual, not the group. I'd be very surprised if that were true. I suspect the majority of programs are in embedded systems, and they will get their "user data" come straight from the hardware. I doubt the engine controller in your car or the computer inside your TV pass much data around as strings. Of course, Python probably isn't the ideal language for real-time embedded systems (I expect an advocate will be along in a moment to tell me I'm wrong) but it's important to remember that the desktop isn't the be-all and end-all of computing. For what it's worth, all the research I've seen has found that compile-time checking and testing tend to catch different bugs, so if correctness is really important to you then you'll want both. The truth of the matter is that correctness is only one factor in the equation, and cost is another. Python tilts the balance in favour of cost -- it's really fast to develop in Python compared to some other languages, but you lose compiler checks. That's the right balance for a lot of applications, but not for all. If it's really critical that the program be correct then you'll want a bondage-and-discipline language that does masses of check, you might even do separate static analysis, and you'll *still* do all the dynamic testing you would have in Python. -- Tim Rowe From bthate at gmail.com Tue Sep 28 17:15:25 2010 From: bthate at gmail.com (Bart Thate) Date: Tue, 28 Sep 2010 14:15:25 -0700 (PDT) Subject: JSONBOT 0.4 RELEASED Message-ID: <14f0bdf5-5471-4927-b632-09bc027207cc@30g2000yqm.googlegroups.com> Yesterday i pushed version 0.4 of JSONBOT to pypi and googlecode. This version has a rewritten core that makes it easier to develop bots for and has lots of bugs fixed. A karma plugin was added as well as a silent mode that forwards bot responses to /msg. You can grab a copy on http://jsonbot.googlecode.com or use the mercurial reposistory: "hg clone http://jsonbot.googlecode.com/hg jsonbot". please file any bugs reports at http://code.google.com/p/jsonbot/issues/list we are at #dunkbots on freenode and IRCnet. Have fun ! about JSONBOT: JSONBOT is a remote event-driven framework for building bots that talk JSON to each other over XMPP. IRC/Console/XMPP (shell) Wave/Web/XMPP (GAE) implementations provided. From max at alcyone.com Tue Sep 28 18:02:10 2010 From: max at alcyone.com (Erik Max Francis) Date: Tue, 28 Sep 2010 15:02:10 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Malcolm McLean wrote: > On Sep 27, 9:29 pm, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. Mission saved! >> > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. There are already numerous libraries that help you with this kind of things in various languages; Python (you're crossposting to comp.lang.python), for instance, has several, such as Unum, and including one I've written but not yet released. It's not clear why one would need this built into the language: >>> print si kg m s A K cd mol >>> length = 3*si.in_ # underscore is needed since `in` is a keyword >>> print length 3.0 in_ >>> lengthInCentimeters = length.convert(si.cm) >>> print lengthInCentimeters 7.62 cm >>> area = lengthInCentimeters*lengthInCentimeters >>> print area 58.0644 cm**2 >>> biggerArea = 10.0*area >>> ratio = area/biggerArea >>> print ratio 0.1 >>> speed = (3.0*si.m)/(1.5*si.s) >>> print speed 2.0 m/s >>> ratio - speed Traceback (most recent call last): File "", line 1, in ? File "unity.py", line 218, in __sub__ converted = other.convert(self.strip()) File "unity.py", line 151, in convert raise IncompatibleUnitsError, "%r and %r do not have compatible units" % (self, other) __main__.IncompatibleUnitsError: and do not have compatible units And everybody's favorite: >>> print ((epsilon_0*mu_0)**-0.5).simplify() 299792458.011 m/s >>> print c # floating point accuracy aside 299792458.0 m/s -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis In Heaven all the interesting people are missing. -- Friedrich Nietzsche From ndonohue at gmail.com Tue Sep 28 18:02:14 2010 From: ndonohue at gmail.com (Nick Donohue) Date: Tue, 28 Sep 2010 15:02:14 -0700 (PDT) Subject: function decorators Message-ID: I came across this code just now: def time_me(function): def wrap(*arg): start = time.time() r = function(*arg) end = time.time() print "%s (%0.3f ms)" %(function.func_name, (end-start)*1000) return wrap @time_me def some_function(somearg) some_function(arg) I've been looking online about what I think is going on, and from what I can tell this code is using function decorators. I guess what I'm asking is if someone could tell me what exactly is going on in this code - how is it different from passing: time_me(some_function(123))? I've tried it this way and it works. why would I use these? wouldn't it be more flexible to not write the decorator before the function definition, so I could choose to wrap it or not? thanks From usenet-nospam at seebs.net Tue Sep 28 18:12:47 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 22:12:47 GMT Subject: function decorators References: Message-ID: On 2010-09-28, Nick Donohue wrote: > why would I use these? wouldn't it be more flexible to not write the > decorator before the function definition, so I could choose to wrap it > or not? The utility is that it lets you modify all calls to a function at once, without changing all the instances in a ton of source code. -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 deets at web.de Tue Sep 28 18:24:45 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 29 Sep 2010 00:24:45 +0200 Subject: function decorators References: Message-ID: Nick Donohue writes: > I came across this code just now: > > def time_me(function): > def wrap(*arg): > start = time.time() > r = function(*arg) > end = time.time() > print "%s (%0.3f ms)" %(function.func_name, (end-start)*1000) > return wrap > > @time_me > def some_function(somearg) > > some_function(arg) > > I've been looking online about what I think is going on, and from what > I can tell this code is using function decorators. > > I guess what I'm asking is if someone could tell me what exactly is > going on in this code - how is it different from passing: > time_me(some_function(123))? I've tried it this way and it works. This is *not* what the decorator is doing. The equivalent of a decorator and then calling the result is this: >>> some_function = time_me(some_function) >>> some_function(123) Notice the difference? The decorator (a badly written one, by the way - it doesn't deal with a possible return value and keyword args) wraps the function into time measuring code. In general, a decorator is a callable that takes one argument. And whatever that callable returns is then bound under the same name as the original function (or class, since python 2.6 I believe) Which is what >>> some_function = time_me(some_function) actually does. So decorator syntax with the @ is really just that - a bit of syntactic sugar. > why would I use these? wouldn't it be more flexible to not write the > decorator before the function definition, so I could choose to wrap it > or not? Of course it's more flexible to do whatever the decorator does only if you need it. If you need that, it's a sign of a misuse of decorators. Their strength is in making boiler-plate code run without you having to type it out all the time. E.g. putting transactional boundaries around some code that deals with a database. Checking for proper authentication and authorization. Uniformely deal with exceptions. And so forth. Amongst the more popular decorators in python are the classmethod and property decorators. Go look them up in the stdlib. Diez From ian.g.kelly at gmail.com Tue Sep 28 18:28:21 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Sep 2010 16:28:21 -0600 Subject: function decorators In-Reply-To: References: Message-ID: On Tue, Sep 28, 2010 at 4:02 PM, Nick Donohue wrote: > I came across this code just now: > > def time_me(function): > def wrap(*arg): > start = time.time() > r = function(*arg) > end = time.time() > print "%s (%0.3f ms)" %(function.func_name, (end-start)*1000) > return wrap > > @time_me > def some_function(somearg) > > some_function(arg) > > I've been looking online about what I think is going on, and from what > I can tell this code is using function decorators. > > I guess what I'm asking is if someone could tell me what exactly is > going on in this code - how is it different from passing: > time_me(some_function(123))? I've tried it this way and it works. > Not quite. It's actually equivalent to calling time_me(some_function)(123). > why would I use these? wouldn't it be more flexible to not write the > decorator before the function definition, so I could choose to wrap it > or not? > In general, yes. In the particular case above, I don't know why it would have been written as a decorator, unless it was merely meant to be toy code. Generally I'll use a decorator in order to add common functionality that is critical to the function's operation. Dynamically adding a default keyword argument is one example that comes to mind, or wrapping the function in a context manager without adding indentation to the entire function body. Also, decorators can also be used for things besides wrapping functions, such as registering them with a framework. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From hidura at gmail.com Tue Sep 28 18:31:28 2010 From: hidura at gmail.com (Hidura) Date: Tue, 28 Sep 2010 19:31:28 -0300 Subject: Upload files with wsgi Message-ID: Hello, i have a project on Python3k, and i have a very big problem i don' t find how take an upload file i am using the wsgiref lib, and or theres any way to connect to the client in order to get the file by myself? Thank you Diego Hidalgo. -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From xahlee at gmail.com Tue Sep 28 18:38:23 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 28 Sep 2010 15:38:23 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> Message-ID: <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> 2010-09-28 On Sep 28, 12:07?pm, namekuseijin wrote: > On 28 set, 14:56, Xah Lee wrote: > > > ultimately, all lang gets transformed at the compiler level to become > > machine instructions, which is imperative programing in the ultimate > > sense. > > > You say that ?do? is merely macro and ultimately function application. > > But to what level should we go down this chain on how the language > > actually works when evaluating a function in source code? > > > any functional lang, quickly becomes imperative when compiled to some > > intermediate code or interpreted. In a sense, it can't be any other > > way. Functions are abstract mathematical ideas, while ?do? loop or any > > instruction are actual steps of algorithms. > > That is true as of Mathematica too. ?Difference being that do in > scheme is pretty-much user-level syntax. ?If you look in most (good) > implementations sources, do and let are defined in scheme itself, not > C or lower-level: ?C code only deals with transforming lambda > application and tail calls into proper gotos. > > So, as far as we're talking about scheme, haskell or Mathematica code, > it's all functional in its abstraction context. > > do syntax does allow for imperative commands to be issued in scheme, > just like let. ?It does not mean it was used in said examples nor that > do is automatically inherently imperative just because of choice of > name. ?imperative do -> (do (steppers ...) (final-condition? result) > malign-imperative-code-here ...) > > so, now that we got it clear why do in scheme is not (inherently) > imperative why were you bashing useful (at times) functional syntax in > the form of list comprehensions again? le's get precise. The argument i want to make, is this: ? ?list comprehension? is a very bad jargon; thus harmful to functional programing or programing in general. Being a bad jargon, it encourage mis-communication, mis-understanding. ? ?list comprehension? is a redundant concept in programing. The concept is of historical interest. e.g. when people talk about the history of computer languages. The LC can simply be filter(map(func, list), predicate). ? The special syntax of ?list comprehension? as it exists in many langs, are not necessary. It can simply be a plain function, e.g LC(function, list, filter). I gave a stand-alone explanation of these points at: http://groups.google.com/group/comp.lang.lisp/msg/329b3b68ff034453 Do you disagree or agree with the above? This is the point _I_ want to argue about, but you don't seem to admit any part of it, but you seems to want to discuss about ?do? in Scheme lisp being functional. So, perhaps we can now focus on this subject: The ?do? in Scheme lisp is not imperative, or, it can be considered as functional. Alright. To be honest, i haven't had enough experience to comment on, but in general, i understand the example you've given, and i disagree. Full report on your argument on this is given at: http://groups.google.com/group/comp.lang.lisp/msg/87a987070e80231f Now, in your message (quoted above), you made further argument on this. I think the main point is this, quote: ?do syntax does allow for imperative commands to be issued in scheme, just like let. It does not mean it was used in said examples nor that do is automatically inherently imperative just because of choice of name. imperative do -> (do (steppers ...) (final-condition? result) malign-imperative-code-here ...)? i don't think your argument is forceful enough. It appears that by this argument you even say that ?let? is not functional. Here, the issue verges on what is functional? What is a function? If a function in lisp is defined as macro, does it ceases to be considered as a function? Likewise, if a lisp's has ?for? loop that is defined as a macro, is that ?for? now considered a function? this is getting quite iffy. What level or aspect are we considering? In each lang, usually they define certain terms specifically to the lang, and to various degree of precision. For eample, the term ?object? means very different things in a technical way in different langs. Same for the word ?function?, ?keyword?, ?command?, ?module?, ?package? ... So, overall, i consider your argument for ?do? in Scheme lisp being functional is weak, or trivial. It seems to be a pet peeve. You got annoyed because i seem to have ignored it entirely. But i got annoyed by you because you don't get the point about what i consider more significant opinion on ?list comprehension?, which you totally ignored and kept at hacking the ?do? in Scheme lisp. Xah ? xahlee.org ? From nagle at animats.com Tue Sep 28 18:41:52 2010 From: nagle at animats.com (John Nagle) Date: Tue, 28 Sep 2010 15:41:52 -0700 Subject: Upload files with wsgi In-Reply-To: References: Message-ID: <4ca26f3c$0$1675$742ec2ed@news.sonic.net> On 9/28/2010 3:31 PM, Hidura wrote: > Hello, i have a project on Python3k, and i have a very big problem i > don' t find how take an upload file i am using the wsgiref lib, and or > theres any way to connect to the client in order to get the file by > myself? > > Thank you > Diego Hidalgo. This is not clear. Are you trying to upload a Python program to a server, where a web server will run it in response to web requests? Or what? Does this involve an Apache server? John Nagle From kst-u at mib.org Tue Sep 28 18:51:14 2010 From: kst-u at mib.org (Keith Thompson) Date: Tue, 28 Sep 2010 15:51:14 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Message-ID: Erik Max Francis writes: [...] > >>> print c # floating point accuracy aside > 299792458.0 m/s Actually, the speed of light is exactly 299792458.0 m/s by definition. (The meter and the second are defined in terms of the same wavelength of light; this was changed relatively recently.) -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From catphive at catphive.net Tue Sep 28 18:54:31 2010 From: catphive at catphive.net (Brendan Miller) Date: Tue, 28 Sep 2010 15:54:31 -0700 Subject: utf-8 and ctypes Message-ID: I'm using python 2.5. Currently I have some python bindings written in ctypes. On the C side, my strings are in utf-8. On the python side I use ctypes.c_char_p to convert my strings to python strings. However, this seems to break for non-ascii characters. It seems that characters not in the ascii subset of UTF-8 are discarded by c_char_p during the conversion, or at least they don't print out when I go to print the string. Does python not support utf-8 strings? Is there some other way I should be doing the conversion? Thanks, Brendan From no.email at please.post Tue Sep 28 18:57:08 2010 From: no.email at please.post (kj) Date: Tue, 28 Sep 2010 22:57:08 +0000 (UTC) Subject: partial sums problem Message-ID: The following attempt to get a list of partial sums fails: >>> s = 0 >>> [((s += t) and s) for t in range(1, 10)] File "", line 1 [((s += t) and s) for t in range(1, 10)] ^ SyntaxError: invalid syntax What's the best way to get a list of partial sums? TIA! kj From gherron at digipen.edu Tue Sep 28 19:29:50 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 28 Sep 2010 16:29:50 -0700 Subject: partial sums problem In-Reply-To: References: Message-ID: <4CA27A6E.3010008@digipen.edu> On 09/28/2010 03:57 PM, kj wrote: > > The following attempt to get a list of partial sums fails: > > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] >>>> > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > > What's the best way to get a list of partial sums? > > TIA! > > kj > Program in C (if that's what you want), or learn Python (if you'd prefer), but don't try to mix the two. Python does have "s+=t" as a statement, and it does have list comprehensions [... for ...] as expressions, but you cannot put a statement inside an expression. -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From hidura at gmail.com Tue Sep 28 19:30:30 2010 From: hidura at gmail.com (Hidura) Date: Tue, 28 Sep 2010 20:30:30 -0300 Subject: Upload files with wsgi In-Reply-To: <4ca26f3c$0$1675$742ec2ed@news.sonic.net> References: <4ca26f3c$0$1675$742ec2ed@news.sonic.net> Message-ID: I am trying to upload any type of file ext to an app written in Py3k, using Apache+mod_wsgi i can't use django or cherryPy because i manage the data in the request creating an xml to store the data from selected areas and send it to the server. I am using the wsgiref library to handle the request and the responses. 2010/9/28, John Nagle : > On 9/28/2010 3:31 PM, Hidura wrote: >> Hello, i have a project on Python3k, and i have a very big problem i >> don' t find how take an upload file i am using the wsgiref lib, and or >> theres any way to connect to the client in order to get the file by >> myself? >> >> Thank you >> Diego Hidalgo. > > This is not clear. > > Are you trying to upload a Python program to a server, where > a web server will run it in response to web requests? Or what? > > Does this involve an Apache server? > > John Nagle > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From python at mrabarnett.plus.com Tue Sep 28 19:33:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 00:33:12 +0100 Subject: utf-8 and ctypes In-Reply-To: References: Message-ID: <4CA27B38.4090502@mrabarnett.plus.com> On 28/09/2010 23:54, Brendan Miller wrote: > I'm using python 2.5. > > Currently I have some python bindings written in ctypes. On the C > side, my strings are in utf-8. On the python side I use > ctypes.c_char_p to convert my strings to python strings. However, this > seems to break for non-ascii characters. > > It seems that characters not in the ascii subset of UTF-8 are > discarded by c_char_p during the conversion, or at least they don't > print out when I go to print the string. > > Does python not support utf-8 strings? Is there some other way I > should be doing the conversion? > Python does support bytestrings (8 bits per character, 'str' in Python 2), so you should be getting all the bytes that comprise the UTF-8 string up to the terminating zero-byte). You then need to decode the string from UTF-8 to Unicode. From emile at fenx.com Tue Sep 28 19:35:16 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 28 Sep 2010 16:35:16 -0700 Subject: partial sums problem In-Reply-To: References: Message-ID: On 9/28/2010 3:57 PM kj said... > > > The following attempt to get a list of partial sums fails: > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > > What's the best way to get a list of partial sums? > I'm pretty sure the consensus isn't this... >>> R=[] >>> [ sum(R) for s in range(1,10) if not R.append(s) ] Emile From usenet-nospam at seebs.net Tue Sep 28 19:36:01 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 23:36:01 GMT Subject: partial sums problem References: Message-ID: On 2010-09-28, Gary Herron wrote: > Python does have "s+=t" as a statement, and it does have list > comprehensions [... for ...] as expressions, but you cannot put a > statement inside an expression. I've inferred that, in Python, all assignments are by definition statements, rather than expressions, so they can't be arbitrarily substituted in for expressions. It's interesting to see the two ways in which people seem to go from C's middle ground of expressions and statements; some languages go to making statements into expressions, others go for even further narrowing the set of "expressions". I'm not yet sure which I prefer; both have some appeal in avoiding some of the occasional-complexity that can make C hard for people to learn. (Meaning, complexity which is only sometimes at issue, so you have to know about it, but you can't just use it all the time, so you can't assume it's how things work.) -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 python at mrabarnett.plus.com Tue Sep 28 19:36:03 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 00:36:03 +0100 Subject: partial sums problem In-Reply-To: References: Message-ID: <4CA27BE3.1060105@mrabarnett.plus.com> On 28/09/2010 23:57, kj wrote: > > > The following attempt to get a list of partial sums fails: > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > > What's the best way to get a list of partial sums? > Probably: s = 0 p = [] for t in range(1, 10): s += t p.append(s) From rpw3 at rpw3.org Tue Sep 28 19:52:11 2010 From: rpw3 at rpw3.org (Rob Warnock) Date: Tue, 28 Sep 2010 18:52:11 -0500 Subject: "Strong typing vs. strong testing" References: <4836eb5b-94d8-46b5-8b2f-f5e6a1300464@h7g2000yqn.googlegroups.com> Message-ID: EXECUTIVE SUMMARY: 1 inch + 1 second = ~4.03e38 grams. GORY DETAILS: Tim Bradshaw wrote: +--------------- | Malcolm McLean said: | > he problem is that if you allow expressions rather than terms then | > the experssions can get arbitrarily complex. sqrt(1 inch + 1 Second), | > for instance. | | I can't imagine a context where 1 inch + 1 second would not be an | error, so this is a slightly odd example. Indeed I think that in | dimensional analysis summing (or comparing) things with different | dimensions is always an error. +--------------- Unless you convert them to equivalent units first. For example, in relativistic or cosmological physics, one often uses a units basis wherein (almost) everything is scaled to "1": http://en.wikipedia.org/wiki/Natural_units When you set c = 1, then: Einstein's equation E = mc2 can be rewritten in Planck units as E = m. This equation means "The rest-energy of a particle, measured in Planck units of energy, equals the rest-mass of a particle, measured in Planck units of mass." See also: http://en.wikipedia.org/wiki/Planck_units ... The constants that Planck units, by definition, normalize to 1 are the: * Gravitational constant, G; * Reduced Planck constant, h-bar; [h/(2*pi)] * Speed of light in a vacuum, c; * Coulomb constant, 1/(4*pi*epsilon_0) (sometimes k_e or k); * Boltzmann's constant, k_B (sometimes k). This sometimes leads people to do things that would appear sloppy or even flat-out wrong in MKS or CGS units, such as expressing mass in terms of length: Consider the equation A=1e10 in Planck units. If A represents a length, then the equation means A=1.6e-25 meters. If A represents a mass, then the equation means A=220 kilograms. ... In fact, natural units are especially useful when this ambiguity is *deliberate*: For example, in special relativity space and time are so closely related that it can be useful to not specify whether a variable represents a distance or a time. So it is that we find that the mass of the Sun is 1.48 km or 4.93 us, see: http://en.wikipedia.org/wiki/Solar_mass#Related_units In this limited sense, then, one could convert both 1 inch and 1 second to masses[1], and *then* add them, hence: 1 inch + 1 second = ~4.03e38 grams. ;-} ;-} -Rob [1] 1 inch is "only" ~3.41e28 g, whereas 1 second is ~4.03e38 g, so the latter completely dominates in the sum. ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From ian.g.kelly at gmail.com Tue Sep 28 19:52:36 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Sep 2010 17:52:36 -0600 Subject: partial sums problem In-Reply-To: References: Message-ID: On Tue, Sep 28, 2010 at 4:57 PM, kj wrote: > > > The following attempt to get a list of partial sums fails: > > >>> s = 0 > >>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > Because in Python assignment is a statement, not an expression. What's the best way to get a list of partial sums? > sum = 0 sums = [] for t in range(1, 10): sum += t sums.append(sum) Or, if you prefer to keep it functional in nature: def append_sum(sums, x): return sums + [(sums[-1] if sums else 0) + x] reduce(append_sum, range(1, 10), []) Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Sep 28 20:19:03 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Sep 2010 20:19:03 -0400 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: On 9/28/2010 5:27 AM, AlexWalk wrote: > In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ > of an int literal will raise a SyntaxException, while other literals > will not. For example. 1.__class__ is an error, while 1.1.__class__ runs > ok. Third solution: >>> type(0) is 0 .__class__ True A person using instances of a class should seldom use special names directly. They are, in a sense, implementation details, even if documented. The idiom "if __name__ == '__main__':" is an exception. -- Terry Jan Reedy From clp2 at rebertia.com Tue Sep 28 20:32:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 28 Sep 2010 17:32:04 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On Tue, Sep 28, 2010 at 2:55 AM, Malcolm McLean wrote: > On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. ?Mission saved! >> > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. Sounds just like Frink: http://futureboy.us/frinkdocs/ http://en.wikipedia.org/wiki/Frink Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Tue Sep 28 20:57:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Sep 2010 20:57:16 -0400 Subject: function decorators In-Reply-To: References: Message-ID: On 9/28/2010 6:02 PM, Nick Donohue wrote: > I came across this code just now: > > def time_me(function): > def wrap(*arg): > start = time.time() > r = function(*arg) > end = time.time() > print "%s (%0.3f ms)" %(function.func_name, (end-start)*1000) > return wrap > > @time_me > def some_function(somearg) As others noted, this is an bad example of a decorator. Please forget it. Let us move on... #deco def func_name(*args): pass is syntactic sugar for (which is to say, is almost and for practical purposes is exactly equivalent to) def func_name(*args): pass func_name = deco(func_name) Indeed, Python did well without them until they were added. But there are 2 advantages of the decorator syntax: 1. Without it, one write (and read!) func_name 3 times instead of 1. One of the use cases that motivated decorators was a situation where someone was required to wrap numerous functions with stylized names about 30 chars long, like 'get_hopscotch_version_a_code_123x76' 2. Understanding the code may require that one know that it will never see the light of day as is. If the body is several lines, the wrapping call may be hard to see. To put it another way, the wrapping calls often belong near the doc string since they are part of a high-level overview of the function. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 28 21:12:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Sep 2010 21:12:48 -0400 Subject: partial sums problem In-Reply-To: References: Message-ID: On 9/28/2010 6:57 PM, kj wrote: > > > The following attempt to get a list of partial sums fails: > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > > What's the best way to get a list of partial sums? Do not try to do a reduction with a comprehension. Just write clear, straightforward code that obviously works. s=[1,2,3,4,5,6] def cusum(s): t = 0 for i in s: t += i yield t print(list(cusum(s))) >>> [1, 3, 6, 10, 15, 21] -- Terry Jan Reedy From zed.shaw at gmail.com Tue Sep 28 21:18:07 2010 From: zed.shaw at gmail.com (Zed Shaw) Date: Tue, 28 Sep 2010 18:18:07 -0700 Subject: Request For Comments: Learn Python The Hard Way Message-ID: Hi Everyone, I rarely post to the list, but I'm getting near the end of the book I wrote to help people learn Python and I would like some feedback on it if you please: * Web: http://learnpythonthehardway.org/ * PDF: http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf The book so far has been successful in teaching Python to people who couldn't learn it previously, but I have to still test it with real learners more extensively. It is also in rough draft form, so any grammar errors, spelling, or just plain wrong code/concepts/terms are possible. I'd appreciate if Python experts and newbies could read through the book or choice sections and submit tickets to me if you find errors: http://learnpythonthehardway.org/tktnew Which will require an anonymous login to cut down on spam in the tickets. I'd also appreciate discussion here on the list about the approach I took with the book and what you think. Thanks for your time. Zed P.S. The book is totally free so long as you don't charge for it and you don't change it or break it up. Thanks. From python at mrabarnett.plus.com Tue Sep 28 21:20:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 02:20:55 +0100 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: <4CA29477.5070304@mrabarnett.plus.com> On 29/09/2010 01:19, Terry Reedy wrote: > On 9/28/2010 5:27 AM, AlexWalk wrote: >> In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ >> of an int literal will raise a SyntaxException, while other literals >> will not. For example. 1.__class__ is an error, while 1.1.__class__ runs >> ok. > > Third solution: > >>> type(0) is 0 .__class__ > True > > A person using instances of a class should seldom use special names > directly. They are, in a sense, implementation details, even if documented. > The idiom "if __name__ == '__main__':" is an exception. > __file__ is another exception. From msarro at gmail.com Tue Sep 28 21:22:55 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 28 Sep 2010 21:22:55 -0400 Subject: Request For Comments: Learn Python The Hard Way In-Reply-To: References: Message-ID: Cool idea! I'll gladly take a look and get back to you. -Matthew On Tue, Sep 28, 2010 at 9:18 PM, Zed Shaw wrote: > Hi Everyone, > > I rarely post to the list, but I'm getting near the end of the book I > wrote to help people learn Python and I would like some feedback on it > if you please: > > * Web: http://learnpythonthehardway.org/ > * PDF: http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf > > The book so far has been successful in teaching Python to people who > couldn't learn it previously, but I have to still test it with real > learners more extensively. It is also in rough draft form, so any > grammar errors, spelling, or just plain wrong code/concepts/terms are > possible. > > > I'd appreciate if Python experts and newbies could read through the > book or choice sections and submit tickets to me if you find errors: > > http://learnpythonthehardway.org/tktnew > > Which will require an anonymous login to cut down on spam in the tickets. > > I'd also appreciate discussion here on the list about the approach I > took with the book and what you think. > > > Thanks for your time. > > Zed > > P.S. The book is totally free so long as you don't charge for it and > you don't change it or break it up. Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gneuner2 at comcast.net Tue Sep 28 21:35:17 2010 From: gneuner2 at comcast.net (George Neuner) Date: Tue, 28 Sep 2010 21:35:17 -0400 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson wrote: >George Neuner writes: >> On 28 Sep 2010 12:42:40 GMT, Albert van der Horst >> wrote: >>>I would say the dimensional checking is underrated. It must be >>>complemented with a hard and fast rule about only using standard >>>(SI) units internally. >>> >>>Oil output internal : m^3/sec >>>Oil output printed: kbarrels/day >> >> "barrel" is not an SI unit. > >He didn't say it was. Internal calculations are done in SI units (in >this case, m^3/sec); on output, the internal units can be converted to >whatever is convenient. That's true. But it is a situation where the conversion to SI units loses precision and therefore probably shouldn't be done. > >> And when speaking about oil there isn't >> even a simple conversion. >> >> 42 US gallons ? 34.9723 imp gal ? 158.9873 L >> >> [In case those marks don't render, they are meant to be the >> double-tilda sign meaning "approximately equal".] > >There are multiple different kinds of "barrels", but "barrels of oil" >are (consistently, as far as I know) defined as 42 US liquid gallons. >A US liquid gallon is, by definition, 231 cubic inches; an inch >is, by definition, 0.0254 meter. So a barrel of oil is *exactly* >0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 >kbarrels/day. (Please feel free to check my math.) That's >admittedly a lot of digits, but there's no need for approximations >(unless they're imposed by the numeric representation you're using). I don't care to check it ... the fact that the SI unit involves 12 decimal places whereas the imperial unit involves 3 tells me the conversion probably shouldn't be done in a program that wants accuracy. George From hidura at gmail.com Tue Sep 28 23:22:48 2010 From: hidura at gmail.com (Hidura) Date: Wed, 29 Sep 2010 00:22:48 -0300 Subject: Example or recomendation of a webserver Message-ID: I am working on a web project written on Py3k and using mod_wsgi on the Apache that have to recibes the request client via a xml structure and i am facing a lot of troubles with the upload files mainly because i can' t see where they are, so i' ve decide to write my own web server-django and the others doen' t work for my propouse-, what you recomend me for start that? -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From usenet-nospam at seebs.net Wed Sep 29 00:34:04 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 04:34:04 GMT Subject: Example or recomendation of a webserver References: Message-ID: On 2010-09-29, Hidura wrote: > I am working on a web project written on Py3k and using mod_wsgi on > the Apache that have to recibes the request client via a xml structure > and i am facing a lot of troubles with the upload files mainly because > i can' t see where they are, so i' ve decide to write my own web > server-django and the others doen' t work for my propouse-, what you > recomend me for start that? I suggest learning to use one of the existing ones. The chances that, if you can't make the existing ones work, you can write something better, are usually pretty much nil. -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 max at alcyone.com Wed Sep 29 02:03:55 2010 From: max at alcyone.com (Erik Max Francis) Date: Tue, 28 Sep 2010 23:03:55 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Message-ID: Keith Thompson wrote: > Erik Max Francis writes: > [...] >> >>> print c # floating point accuracy aside >> 299792458.0 m/s > > Actually, the speed of light is exactly 299792458.0 m/s by > definition. (The meter and the second are defined in terms of the > same wavelength of light; this was changed relatively recently.) I know. Hence why I wrote the comment "floating point accuracy aside" when printing it. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis If the past sits in judgment on the present, the future will be lost. -- Winston Churchill From rustompmody at gmail.com Wed Sep 29 02:43:13 2010 From: rustompmody at gmail.com (rustom) Date: Tue, 28 Sep 2010 23:43:13 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On Sep 29, 5:32?am, Chris Rebert wrote: > On Tue, Sep 28, 2010 at 2:55 AM, Malcolm McLean > > > > wrote: > > On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) > > wrote: > >> On the other hand, with the dynamic typing mindset, you might even wrap > >> your values (of whatever numerical type) in a symbolic expression > >> mentionning the unit and perhaps other meta data, so that when the other > >> module receives it, it may notice (dynamically) that two values are not > >> of the same unit, but if compatible, it could (dynamically) convert into > >> the expected unit. ?Mission saved! > > > I'd like to design a language like this. If you add a quantity in > > inches to a quantity in centimetres you get a quantity in (say) > > metres. If you multiply them together you get an area, if you divide > > them you get a dimeionless scalar. If you divide a quantity in metres > > by a quantity in seconds you get a velocity, if you try to subtract > > them you get an error. > > Sounds just like Frink:http://futureboy.us/frinkdocs/http://en.wikipedia.org/wiki/Frink A currently developed language with units is curl: see http://developers.curl.com/userdocs/docs/en/dguide/quantities-basic.html From nospam at torek.net Wed Sep 29 02:59:42 2010 From: nospam at torek.net (Chris Torek) Date: 29 Sep 2010 06:59:42 GMT Subject: partial sums problem References: Message-ID: In article kj wrote: >The following attempt to get a list of partial sums fails: > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ >SyntaxError: invalid syntax > >What's the best way to get a list of partial sums? Well, define "best"; but curiously enough, I wrote this just a few days ago for other purposes, so here you go, a slightly cleaned-up / better documented version of what I wrote: def iaccumulate(vec, op): """Do an accumulative operation on a vector (any iterable, really). The result is a generator whose first call produces vec[0], second call produces vec[0] op vec[1], third produces (vec[0] op vec[1]) op vec[2], and so on. Mostly useful with + and *, probably. """ iterable = iter(vec) acc = iterable.next() yield acc for x in iterable: acc = op(acc, x) yield acc def cumsum(vec): """Return a list of the cumulative sums of a vector.""" import operator return list(iaccumulate(vec, operator.add)) -- 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 clp2 at rebertia.com Wed Sep 29 03:14:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 29 Sep 2010 00:14:35 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On Tue, Sep 28, 2010 at 11:43 PM, rustom wrote: > On Sep 29, 5:32?am, Chris Rebert wrote: >> On Tue, Sep 28, 2010 at 2:55 AM, Malcolm McLean >> wrote: >> > On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) >> > wrote: >> >> On the other hand, with the dynamic typing mindset, you might even wrap >> >> your values (of whatever numerical type) in a symbolic expression >> >> mentionning the unit and perhaps other meta data, so that when the other >> >> module receives it, it may notice (dynamically) that two values are not >> >> of the same unit, but if compatible, it could (dynamically) convert into >> >> the expected unit. ?Mission saved! >> >> > I'd like to design a language like this. If you add a quantity in >> > inches to a quantity in centimetres you get a quantity in (say) >> > metres. If you multiply them together you get an area, if you divide >> > them you get a dimeionless scalar. If you divide a quantity in metres >> > by a quantity in seconds you get a velocity, if you try to subtract >> > them you get an error. >> >> Sounds just like Frink: >> http://futureboy.us/frinkdocs/ > > A currently developed language with units is curl: see > http://developers.curl.com/userdocs/docs/en/dguide/quantities-basic.html Frink's most recent version is only 17 days old. (You seemed to imply Frink isn't under active development.) Cheers, Chris From rustompmody at gmail.com Wed Sep 29 03:48:28 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 29 Sep 2010 13:18:28 +0530 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On Wed, Sep 29, 2010 at 12:44 PM, Chris Rebert wrote: > On Tue, Sep 28, 2010 at 11:43 PM, rustom wrote: > > A currently developed language with units is curl: see > > http://developers.curl.com/userdocs/docs/en/dguide/quantities-basic.html > > Frink's most recent version is only 17 days old. (You seemed to imply > Frink isn't under active development.) > > Cheers, > Chris > Sorry... I was really referring/comparing with some earlier posts that seemed to be about old/obsolete systems (HP48...) -------------- next part -------------- An HTML attachment was scrubbed... URL: From chardster at gmail.com Wed Sep 29 03:55:32 2010 From: chardster at gmail.com (Richard Thomas) Date: Wed, 29 Sep 2010 00:55:32 -0700 (PDT) Subject: Upload files with wsgi References: Message-ID: <470d630b-717b-4dd1-8a86-0fc3928cf49d@l6g2000yqb.googlegroups.com> On Sep 28, 11:31?pm, Hidura wrote: > Hello, i have a project on Python3k, and i have a very big problem i > don' t find how take an upload file i am using the wsgiref lib, and or > theres any way to connect to the client in order to get the file by > myself? > > Thank you > Diego Hidalgo. > > -- > Enviado desde mi dispositivo m?vil > > Diego I. Hidalgo D. 'wsgiref' doesn't do that part of request handling. You want to use the 'cgi' module to parse the POST data: http://docs.python.org/library/cgi.html Remember to set the enctype on your
tags to multipart/form- data. Chard. From karaken12 at gmail.com Wed Sep 29 05:05:49 2010 From: karaken12 at gmail.com (Tom Potts) Date: Wed, 29 Sep 2010 10:05:49 +0100 Subject: File holes in Linux Message-ID: Hi, all. I'm not sure if this is a bug report, a feature request or what, so I'm posting it here first to see what people make of it. I was copying over a large number of files using shutil, and I noticed that the final files were taking up a lot more space than the originals; a bit more investigation showed that files with a positive nominal filesize which originally took up 0 blocks were now taking up the full amount. It seems that Python does not write back file holes as it should; here is a simple program to illustrate: data = '\0' * 1000000 file = open('filehole.test', 'wb') file.write(data) file.close() A quick `ls -sl filehole.test' will show that the created file actually takes up about 980k, rather than the 0 bytes expected. If anyone can let me know if this is indeed a bug or feature request, how to get around it, or where to take it next, I'd really appreciate it. Thanks a lot, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From vivanov at ivanov-nest.com Wed Sep 29 05:53:02 2010 From: vivanov at ivanov-nest.com (Velko Ivanov) Date: Wed, 29 Sep 2010 12:53:02 +0300 Subject: Certificate validation with HTTPSConnection Message-ID: Hello, I've always wandered why HTTPSConnection does not validate certificates? It is fairly simple to use the SSL socket's validation: > class HTTPSConnection(HTTPConnection): > """This class allows communication via SSL. > It is a copy of the http.client.HTTPSConnection with added certificate validation > """ > > default_port = HTTPS_PORT > > def __init__(self, host, port=None, key_file=None, cert_file=None, ca_file=None, > cert_reqs=ssl.CERT_NONE, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): > HTTPConnection.__init__(self, host, port, strict, timeout) > self.key_file = key_file > self.cert_file = cert_file > self.cert_reqs = cert_reqs > self.ca_file = ca_file > > def connect(self): > "Connect to a host on a given (SSL) port." > > sock = socket.create_connection((self.host, self.port), self.timeout) > > if self._tunnel_host: > self.sock = sock > self._tunnel() > > self.sock = ssl.wrap_socket(sock, keyfile=self.key_file, certfile=self.cert_file, cert_reqs=self.cert_reqs, ca_certs=self.ca_file) > conn = HTTPSConnection(host, cert_file=certfile, cert_reqs=ssl.CERT_REQUIRED, ca_file=cafile) IMO it doesn't matter how well is the validation covered in the ssl lib, or the filenames vs. files issues of ssl.wrap_socket() - HTTPSConnection should only provide the means to use what is available in SSL and include a link in docs to explanations of how SSL does what it does, so that people can make their decisions. The above code works quite well for me in production, where client nodes connect to apache and nginx servers by HTTPS with certificate based authentication. I'm using self signed CA though and I don't need revocation lists, so I know nothing of whether that part of validation is/could be working. Just sharing a simple solution to a simple problem on which I spent more that few hours in reading, hope this helps the next lost soul Best Regards Velko Ivanov -------------- next part -------------- An HTML attachment was scrubbed... URL: From foo at meisterderspiele.de Wed Sep 29 05:53:17 2010 From: foo at meisterderspiele.de (=?ISO-8859-1?Q?Torsten_Z=FChlsdorff?=) Date: Wed, 29 Sep 2010 11:53:17 +0200 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Message-ID: Keith Thompson schrieb: >> >>> print c # floating point accuracy aside >> 299792458.0 m/s > > Actually, the speed of light is exactly 299792458.0 m/s by > definition. Yes, but just in vacuum. Greetings, Torsten -- http://www.dddbl.de - ein Datenbank-Layer, der die Arbeit mit 8 verschiedenen Datenbanksystemen abstrahiert, Queries von Applikationen trennt und automatisch die Query-Ergebnisse auswerten kann. From jacob.abraham at gmail.com Wed Sep 29 06:09:49 2010 From: jacob.abraham at gmail.com (Jacob Abraham) Date: Wed, 29 Sep 2010 15:39:49 +0530 Subject: Paramiko and Threading Message-ID: Hi, Could someone help me understand how to using threading along with paramiko. For some reason only one of two of the threads returns the output correctly. Some of the threads returns an empty string as command output, but no errors are thrown. My attempt is pasted below. regards, Jacob Abraham import time import socket import sys from threading import Thread import os from paramiko import AutoAddPolicy, SSHClient, SSHException, AuthenticationException class SSHCollector(Thread): def __init__(self, hostname, username, password, proto, loggername, zapiport, sshport=22, keepalive=True, tmo=60): Thread.__init__(self) self.hostname = hostname self.username = username self.password = password self.keepalive = keepalive self.tmo = tmo self._conn = None self.success = False self.client = SSHClient() self.client.load_system_host_keys() self.client.set_missing_host_key_policy(AutoAddPolicy()) self.client.set_log_channel(loggername) def _connect(self): if None is not self.client.get_transport() and self.client.get_transport().is_active(): return if None is self.username: self.client.connect(hostname=self.hostname, timeout=self.tmo) elif None is self.password: self.client.connect(hostname=self.hostname, username=self.username, password=self.password, timeout=self.tmo) else: self.client.connect(hostname=self.hostname, username=self.username, password=self.password, look_for_keys=False, timeout=self.tmo) trans = self.client.get_transport() trans.use_compression(True) trans.set_keepalive(1) def close(self): self.client.close() __del__ = close def execute(self, lcmd, auto_close=False, tmo=300, read_max=10*1024*1024): output = r'' err = r'' self._error = "" read_max = int(read_max/2) exit_status = False self._connect() chan = self.client.get_transport().open_session() if not self.keepalive: self.client.get_transport().set_keepalive(0) chan.settimeout(tmo) chan.exec_command(lcmd) stdin = chan.makefile('wb', -1) stdout = chan.makefile('rb', -1) stderr = chan.makefile_stderr('rb', -1) start_time = time.time() while True: if stderr.channel.recv_stderr_ready(): ret = stderr.read() if ret: err += ret if stdout.channel.recv_ready(): try: ret = stdout.read(read_max) if ret: output += ret except socket.timeout: pass exit_status = chan.exit_status_ready() if exit_status or ((int(start_time) + tmo) < int(time.time())): timeout = False if exit_status: exit_status = str(stderr.channel.recv_exit_status()) else: self.signal(chan, 'KILL') exit_status = str(stderr.channel.recv_exit_status()) timeout = True if stdin: stdin.channel.shutdown_write() stdin.close() if stdout.channel.recv_ready(): ret = stdout.read(read_max) if ret: output += ret stdout.close() if stderr.channel.recv_stderr_ready(): ret = stderr.read() if ret: err += ret err += "exit_status("+str(exit_status)+") to("+str(timeout)+")" stderr.close() break self.success = True if auto_close: self.client.close() return (output, err) def setCommand(self, cmd): self.cmd = cmd def runcmd(self, cmd): return self.execute(cmd, auto_close=True) def run(self): self.resultset = self.runcmd(self.cmd) if __name__ == '__main__': cmd = 'date' threads = [] a = time.time() for i in range(3): collector = SSHCollector('11.11.111.111', 'dummyusername', 'dummypassword', \ 'auto', 'dummylogger', None) collector.setCommand(cmd) threads.append(collector) for i in threads: i.start() for i in threads: i.join() for i in threads: print i.resultset b=time.time() print b-a -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Wed Sep 29 06:11:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 29 Sep 2010 23:11:45 +1300 Subject: utf-8 and ctypes References: Message-ID: In message , Brendan Miller wrote: > It seems that characters not in the ascii subset of UTF-8 are > discarded by c_char_p during the conversion ... Not a chance. > ... or at least they don't print out when I go to print the string. So it seems there?s a problem on the printing side. What happens when you construct a UTF-8-encoded string directly in Python and try printing it the same way? From ldo at geek-central.gen.new_zealand Wed Sep 29 06:13:41 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 29 Sep 2010 23:13:41 +1300 Subject: Nautilus Python References: Message-ID: In message , Eduardo Ribeiro wrote: > But it doesn't work. What messages do you get? From pjb at informatimago.com Wed Sep 29 06:40:58 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Wed, 29 Sep 2010 12:40:58 +0200 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <87bp7gq1c5.fsf@kuiper.lan.informatimago.com> George Neuner writes: > On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson > wrote: > >>George Neuner writes: >>> On 28 Sep 2010 12:42:40 GMT, Albert van der Horst >>> wrote: >>>>I would say the dimensional checking is underrated. It must be >>>>complemented with a hard and fast rule about only using standard >>>>(SI) units internally. >>>> >>>>Oil output internal : m^3/sec >>>>Oil output printed: kbarrels/day >>> >>> "barrel" is not an SI unit. >> >>He didn't say it was. Internal calculations are done in SI units (in >>this case, m^3/sec); on output, the internal units can be converted to >>whatever is convenient. > > That's true. But it is a situation where the conversion to SI units > loses precision and therefore probably shouldn't be done. > >> >>> And when speaking about oil there isn't >>> even a simple conversion. >>> >>> 42 US gallons ? 34.9723 imp gal ? 158.9873 L >>> >>> [In case those marks don't render, they are meant to be the >>> double-tilda sign meaning "approximately equal".] >> >>There are multiple different kinds of "barrels", but "barrels of oil" >>are (consistently, as far as I know) defined as 42 US liquid gallons. >>A US liquid gallon is, by definition, 231 cubic inches; an inch >>is, by definition, 0.0254 meter. So a barrel of oil is *exactly* >>0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 >>kbarrels/day. (Please feel free to check my math.) That's >>admittedly a lot of digits, but there's no need for approximations >>(unless they're imposed by the numeric representation you're using). > > I don't care to check it ... the fact that the SI unit involves 12 > decimal places whereas the imperial unit involves 3 tells me the > conversion probably shouldn't be done in a program that wants > accuracy. Because perhaps you're thinking that oil is sent over the oceans, and sold retails in barrils of 42 gallons? Actually, when I buy oil, it's from a pump that's graduated in liters! It comes from trucks with citerns containing 24 m?. And these trucks get it from reservoirs of 23,850 m?. "Tankers move approximately 2,000,000,000 metric tons" says the English Wikipedia page... Now perhaps it all depends on whether you buy your oil from Total or from Texaco, but in my opinion, you're forgetting something: the last drop. You never get exactly 42 gallons of oil, there's always a little drop more or less, so what you get is perhaps 158.987 liter or 41.9999221 US gallons, or even 158.98 liter = 41.9980729 US gallons, where you need more significant digits. -- __Pascal Bourguignon__ http://www.informatimago.com/ From affdfsdfdsfsd at b.com Wed Sep 29 06:42:37 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 29 Sep 2010 10:42:37 GMT Subject: if the else short form Message-ID: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Hi all, I'm studying PyGTK tutorial and i've found this strange form: button = gtk.Button(("False,", "True,")[fill==True]) the label of button is True if fill==True, is False otherwise. i have googled for this form but i haven't found nothing, so can any of you pass me any reference/link to this particular if/then/else form? thanks Nico From deets at web.de Wed Sep 29 06:45:08 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 29 Sep 2010 12:45:08 +0200 Subject: Example or recomendation of a webserver References: Message-ID: <87r5gcomkr.fsf@web.de> Hidura writes: > I am working on a web project written on Py3k and using mod_wsgi on > the Apache that have to recibes the request client via a xml structure > and i am facing a lot of troubles with the upload files mainly because > i can' t see where they are, so i' ve decide to write my own web > server-django and the others doen' t work for my propouse-, what you > recomend me for start that? not doing it. Reading the HTTP-RFC and the WSGI-PEP. And trying print environ["wsgi.input"].read() inside your wsgi-script. Then, use webob to wrap the whole WSGI-stuff to have at least a minimum of sensible abstraction. Or simply use Django or TurboGears2, follow the advices in their docs on how to depoly them using mod_wsgi, and be happy. Diez From karaken12 at gmail.com Wed Sep 29 07:19:53 2010 From: karaken12 at gmail.com (Tom Potts) Date: Wed, 29 Sep 2010 12:19:53 +0100 Subject: if the else short form In-Reply-To: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: This is just a sneaky shorthand, which is fine if that's what you want, but it makes it harder to read. The reason it works is that 'fill==True' is a boolean expression, which evaluates to True or False, but if you force a True into being an integer, it will be 1, and a False will become 0. Try writing 'True == 1' on the Python interpreter to see what I mean. So this code snippet is creating a tuple with two elements, and then selecting the first if 'fill==True' is False, or 0, and selecting the second if 'fill==True' is True, or 1. As I say, this kind of coding is absolutely fine, but it makes things harder to read and doesn't really save much space. I wouldn't recommend using this kind of style yourself, at least until you're more familiar with programming in Python. Tom On 29 September 2010 11:42, Tracubik wrote: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can any of > you pass me any reference/link to this particular if/then/else form? > > thanks > Nico > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.j.molenaar at gmail.com Wed Sep 29 07:19:55 2010 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Wed, 29 Sep 2010 13:19:55 +0200 Subject: if the else short form In-Reply-To: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: Hi Nico, it's converting fill==True to an int, thereby choosing the string "False," or "True," by indexing into the tuple. Try this in an interpreter: >>> ['a','b'][False] 'a' >>> ['a','b'][True] 'b' >>> int(False) 0 >>>?int(True) 1 Joost On 29 September 2010 12:42, Tracubik wrote: > > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can any of > you pass me any reference/link to this particular if/then/else form? > > thanks > Nico > -- > http://mail.python.org/mailman/listinfo/python-list From hugol at fastmail.net Wed Sep 29 07:27:04 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Wed, 29 Sep 2010 07:27:04 -0400 Subject: System idle time under Linux Message-ID: <1285759624.9416.1397468677@webmail.messagingengine.com> I have found it for windows and mac, but no luck under linux. Any idea? Thanks -- Hugo L?veill? hugol at fastmail.net From hniksic at xemacs.org Wed Sep 29 07:38:48 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 29 Sep 2010 13:38:48 +0200 Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: <877hi44w53.fsf@xemacs.org> Tracubik writes: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. The tutorial likely predates if/else expression syntax introduced in 2.5, which would be spelled as: button = gtk.Button("True" if fill else "False") BTW adding "==True" to a boolean value is redundant and can even break for logically true values that don't compare equal to True (such as the number 10 or the string "foo"). From oswald.harry at gmail.com Wed Sep 29 07:59:13 2010 From: oswald.harry at gmail.com (harryos) Date: Wed, 29 Sep 2010 04:59:13 -0700 (PDT) Subject: scheduler or infinite loop Message-ID: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> hi I am trying to write a program to read data from a site url. The program must read the data from site every 5 minutes. def get_data_from_site(pageurlstr): h=urllib.urlopen(pageurlstr) data=h.read() process_data(data) At first, I thought of using the sched module ,but then it doesn't look right adding so many scheduler.enter() statements.The program is supposed to execute the above function every 5 minutes until the application is shut down by the user. I created an infinite loop while True: print time.asctime() get_data_from_site('http://somesite.com/') time.sleep(300) Is there a better way to do this?Any suggestions ,pointers most welcome thanks harry From nitinpawar432 at gmail.com Wed Sep 29 08:02:23 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Wed, 29 Sep 2010 17:32:23 +0530 Subject: scheduler or infinite loop In-Reply-To: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> Message-ID: why not schedule cron */5 * * * * and check in your code that previous execution was successful or not On Wed, Sep 29, 2010 at 5:29 PM, harryos wrote: > hi > I am trying to write a program to read data from a site url. > The program must read the data from site every 5 minutes. > > def get_data_from_site(pageurlstr): > h=urllib.urlopen(pageurlstr) > data=h.read() > process_data(data) > > At first, I thought of using the sched module ,but then it doesn't > look right adding so many scheduler.enter() statements.The program is > supposed to execute the above function every > 5 minutes until the application is shut down by the user. > > I created an infinite loop > while True: > print time.asctime() > get_data_from_site('http://somesite.com/') > time.sleep(300) > > Is there a better way to do this?Any suggestions ,pointers most > welcome > thanks > harry > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Wed Sep 29 08:07:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Sep 2010 12:07:56 GMT Subject: About __class__ of an int literal References: Message-ID: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> On Wed, 29 Sep 2010 02:20:55 +0100, MRAB wrote: > On 29/09/2010 01:19, Terry Reedy wrote: >> A person using instances of a class should seldom use special names >> directly. They are, in a sense, implementation details, even if >> documented. The idiom "if __name__ == '__main__':" is an exception. >> > __file__ is another exception. As are __iter__, __next__, __add__, __dict__, and, yes, __class__, to say nothing of all the other special methods. I'm afraid that I have to disagree with Terry here. Double-underscore special variables don't start with double underscores because they're implementation details, or to indicate that they're private. They are reserved names for attributes or methods that have special meaning to Python. An implementation that didn't use __dict__ for the namespace of an ordinary class, or didn't call __add__ for the + operator, would be considered to be buggy. Naturally one has to be careful about the assumptions you make with such special methods. You shouldn't assume, for example, that all classes will have a __dict__ attribute. If the class has __slots__ defined, it may not. But I think that it is safe to assume any object will have a __class__ attribute. At least, I'd report it as a bug if I found one that didn't. (This may change in the future. Given type(), and isinstance(), I'm not sure what value __class__ adds.) -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Sep 29 08:17:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Sep 2010 12:17:13 GMT Subject: list problem... References: Message-ID: <4ca32e49$0$28654$c3e8da3@news.astraweb.com> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >>> Hi all, >>> Have been grappling with a list problem for hours... a = [2, 3, 4, >>> 5,.....] >>> b = [4, 8, 2, 6,.....] >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and >>> b[2] is present. >>> I have tried sets, zip etc with no success. I am tackling Euler >>> projects with Python 3.1, with minimal knowledge, and having to tackle >>> the language as I progress. Enjoyable frustration ?:) >> >> I'm not clear on what your actual problem is, could you restate it? >> >> It sounds like you want to copy the ith element out of a and b into >> some other list- call it c- when the (i+2)th element meets some >> condition. What's the condition? >> >> Geremy Condra > > The condition is that the i-th element is inverted, but not equal. eg > 4,2 - 2,4 , 34,5 - 5,34 etc. > Hope that is clearer. Clear as mud. Perhaps you should given an example. Given input a = [2, 3, 4, 5, 6, 7] b = [4, 8, 2, 6, 10, 42] what output are you expecting, and how would you work it out by hand? -- Steven From brendan.simon at etrix.com.au Wed Sep 29 08:23:31 2010 From: brendan.simon at etrix.com.au (Brendan Simon (eTRIX)) Date: Wed, 29 Sep 2010 22:23:31 +1000 Subject: [Python-list] if the else short form In-Reply-To: References: Message-ID: <4CA32FC3.5090106@etrix.com.au> On 29/09/10 9:20 PM, python-list-request at python.org wrote: > Subject: > if the else short form > From: > Tracubik > Date: > 29 Sep 2010 10:42:37 GMT > > To: > python-list at python.org > > > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can any of > you pass me any reference/link to this particular if/then/else form? > As others have pointed out, a tuple with two items is created and then indexed by the integer conversion of conditional. It is "creative" coding but I wouldn't recommend using it either. For this particular case you may achieve the same thing with: button = gtk.Button(str(fill==True)) or possibly just: button = gtk.Button(fill==True) It's a little better but still not great. A verbose form of something more generic may be: if fill: label = 'True' else: label = 'False' button = gtk.Button(label) or possibly: label = 'True' if fill else 'False' button = gtk.Button(label) or using a dict for label lookup: label = { True : 'True', False : 'False' } button = gtk.Button(label[fill]) Cheers, Brendan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Wed Sep 29 08:34:33 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 29 Sep 2010 14:34:33 +0200 Subject: About __class__ of an int literal References: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> Message-ID: <8739ss4tk6.fsf@xemacs.org> Steven D'Aprano writes: > On Wed, 29 Sep 2010 02:20:55 +0100, MRAB wrote: > >> On 29/09/2010 01:19, Terry Reedy wrote: > >>> A person using instances of a class should seldom use special names >>> directly. They are, in a sense, implementation details, even if >>> documented. The idiom "if __name__ == '__main__':" is an exception. >>> >> __file__ is another exception. > > > As are __iter__, __next__, __add__, __dict__, and, yes, __class__, to > say nothing of all the other special methods. I think by "person using instances of a class" Terry referred to the user of a class as opposed to the implementor. In that sense the user should be calling iter(foo) instead of foo.__iter__(), next(foo) instead of foo.__next__(), and foo+bar instead of foo.__add__(bar). Direct calls to special-name methods, such as __len__, often indicate that the programmer hasn't grasped how those methods are intended to be used in Python. Obviously, none of this applies to __dict__, __class__, and friends, nor does it apply to cases where you know what you're doing, such as invoking ____ of a superclass. > (This may change in the future. Given type(), and isinstance(), I'm not > sure what value __class__ adds.) None whatsoever. __class__ used to be necessary to tell the appart instances of different old-style classes: >>> class X: pass # old-style ... >>> X().__class__ >>> type(X()) Now that classes produce real types, they are equivalent. From bruno.desthuilliers at gmail.com Wed Sep 29 08:52:32 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 29 Sep 2010 05:52:32 -0700 (PDT) Subject: list problem... References: <4ca32e49$0$28654$c3e8da3@news.astraweb.com> Message-ID: <0e563359-c2fd-4fbc-808b-02cb2e483ad5@l20g2000yqm.googlegroups.com> On 29 sep, 14:17, Steven D'Aprano wrote: > On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > > >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > >>> Hi all, > >>> Have been grappling with a list problem for hours... a = [2, 3, 4, > >>> 5,.....] > >>> b = [4, 8, 2, 6,.....] > >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and > >>> b[2] is present. > >>> I have tried sets, zip etc with no success. I am tackling Euler > >>> projects with Python 3.1, with minimal knowledge, and having to tackle > >>> the language as I progress. Enjoyable frustration ?:) > > >> I'm not clear on what your actual problem is, could you restate it? > > >> It sounds like you want to copy the ith element out of a and b into > >> some other list- call it c- when the (i+2)th element meets some > >> condition. What's the condition? > > >> Geremy Condra > > > The condition is that the i-th element is inverted, but not equal. eg > > 4,2 - 2,4 , 34,5 - 5,34 etc. > > Hope that is clearer. > > Clear as mud. > > Perhaps you should given an example. Given input > > a = [2, 3, 4, 5, 6, 7] > b = [4, 8, 2, 6, 10, 42] > > what output are you expecting, AFAICT, the OP expects [2, 4] in this case, but it's not clear what he'd expect for let's say: a = [2, 3, 21, 4, 5, 6, 7] b = [4, 8, 22, 2, 6, 10, 42] (the 'reversed' pair is at i+3, not i+2) or a = [0, 2, 3, 4, 5, 6, 7] b = [3, 4, 8, 2, 6, 10, 42] (the first pair is at pos 1, not 0) or a = [2, 3, 4, 8, 6, 7] b = [4, 8, 2, 3, 10, 42] (there's a second 'non-reversed/reversed' match at positions resp. 1 & 3) From philip at semanchuk.com Wed Sep 29 08:53:17 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 29 Sep 2010 08:53:17 -0400 Subject: if the else short form In-Reply-To: References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: On Sep 29, 2010, at 7:19 AM, Tom Potts wrote: > This is just a sneaky shorthand, which is fine if that's what you want, but > it makes it harder to read. The reason it works is that 'fill==True' is a > boolean expression, which evaluates to True or False, but if you force a > True into being an integer, it will be 1, and a False will become 0. Try > writing 'True == 1' on the Python interpreter to see what I mean. So this > code snippet is creating a tuple with two elements, and then selecting the > first if 'fill==True' is False, or 0, and selecting the second if > 'fill==True' is True, or 1. > > As I say, this kind of coding is absolutely fine, but it makes things harder > to read and doesn't really save much space. I wouldn't recommend using this > kind of style yourself, at least until you're more familiar with programming > in Python. Does Python make any guarantee that int(True) == 1 and int(False) == 0 will always hold, or are their values an implementation detail? Thanks Philip > On 29 September 2010 11:42, Tracubik wrote: > >> Hi all, >> I'm studying PyGTK tutorial and i've found this strange form: >> >> button = gtk.Button(("False,", "True,")[fill==True]) >> >> the label of button is True if fill==True, is False otherwise. >> >> i have googled for this form but i haven't found nothing, so can any of >> you pass me any reference/link to this particular if/then/else form? >> >> thanks >> Nico >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list From pw at panix.com Wed Sep 29 08:55:57 2010 From: pw at panix.com (Paul Wallich) Date: Wed, 29 Sep 2010 08:55:57 -0400 Subject: "Strong typing vs. strong testing" In-Reply-To: <87bp7gq1c5.fsf@kuiper.lan.informatimago.com> References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <87bp7gq1c5.fsf@kuiper.lan.informatimago.com> Message-ID: On 9/29/10 6:40 AM, Pascal J. Bourguignon wrote: > George Neuner writes: > >> On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson >> wrote: >> >>> George Neuner writes: >>>> On 28 Sep 2010 12:42:40 GMT, Albert van der Horst >>>> wrote: >>>>> I would say the dimensional checking is underrated. It must be >>>>> complemented with a hard and fast rule about only using standard >>>>> (SI) units internally. >>>>> >>>>> Oil output internal : m^3/sec >>>>> Oil output printed: kbarrels/day >>>> >>>> "barrel" is not an SI unit. >>> >>> He didn't say it was. Internal calculations are done in SI units (in >>> this case, m^3/sec); on output, the internal units can be converted to >>> whatever is convenient. >> >> That's true. But it is a situation where the conversion to SI units >> loses precision and therefore probably shouldn't be done. >> >>> >>>> And when speaking about oil there isn't >>>> even a simple conversion. >>>> >>>> 42 US gallons ? 34.9723 imp gal ? 158.9873 L >>>> >>>> [In case those marks don't render, they are meant to be the >>>> double-tilda sign meaning "approximately equal".] >>> >>> There are multiple different kinds of "barrels", but "barrels of oil" >>> are (consistently, as far as I know) defined as 42 US liquid gallons. >>> A US liquid gallon is, by definition, 231 cubic inches; an inch >>> is, by definition, 0.0254 meter. So a barrel of oil is *exactly* >>> 0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 >>> kbarrels/day. (Please feel free to check my math.) That's >>> admittedly a lot of digits, but there's no need for approximations >>> (unless they're imposed by the numeric representation you're using). >> >> I don't care to check it ... the fact that the SI unit involves 12 >> decimal places whereas the imperial unit involves 3 tells me the >> conversion probably shouldn't be done in a program that wants >> accuracy. [...] > > Now perhaps it all depends on whether you buy your oil from Total or > from Texaco, but in my opinion, you're forgetting something: the last > drop. You never get exactly 42 gallons of oil, there's always a little > drop more or less, so what you get is perhaps 158.987 liter or > 41.9999221 US gallons, or even 158.98 liter = 41.9980729 US gallons, > where you need more significant digits. And even that pales in comparison to the expansion and contraction of petroleum products with temperature. Compensation to standard temp is required in some jurisdictions but not in others... From bruno.desthuilliers at gmail.com Wed Sep 29 08:58:16 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 29 Sep 2010 05:58:16 -0700 (PDT) Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <877hi44w53.fsf@xemacs.org> Message-ID: On 29 sep, 13:38, Hrvoje Niksic wrote: > Tracubik writes: > > > button = gtk.Button(("False,", "True,")[fill==True]) (snip) > BTW adding "==True" to a boolean value is redundant and can even break > for logically true values that don't compare equal to True (such as the > number 10 or the string "foo"). Note that if fill is actually an int outside the (0, 1) domain, it will break too. The correct test would be: ("False,", "True,")[bool(fill)]) >>> ['a', 'b'][bool(10)] 'b' >>> ['a', 'b'][bool('')] 'a' >>> ['a', 'b'][bool("yes")] 'b' >>> ['a', 'b'][bool([])] 'a' >>> ['a', 'b'][bool([42, 24])] 'b' >>> ['a', 'b'][bool(None)] 'a' >>> From alex at moreati.org.uk Wed Sep 29 08:59:51 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Wed, 29 Sep 2010 05:59:51 -0700 (PDT) Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <877hi44w53.fsf@xemacs.org> Message-ID: <95b7daae-a086-4575-8a67-23097ea98f07@i5g2000yqe.googlegroups.com> On Sep 29, 12:38?pm, Hrvoje Niksic wrote: > Tracubik writes: > > Hi all, > > I'm studying PyGTK tutorial and i've found this strange form: > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > the label of button is True if fill==True, is False otherwise. > > The tutorial likely predates if/else expression syntax introduced in > 2.5, which would be spelled as: > > button = gtk.Button("True" if fill else "False") > > BTW adding "==True" to a boolean value is redundant and can even break > for logically true values that don't compare equal to True (such as the > number 10 or the string "foo"). Totally agreed with one nit. If one chooses to fake x = true_val if expr else false_val prior to Python 2.5, with x = (false_val, true_val)[expr] then one should ensure that expr evaluates to either 0, 1 or a bool. If expr evaluates to "fred" or 42 a TypeError or IndexError will occur. So better to use (in original line) button = gtk.Button(("False,", "True,")[bool(fill)]) but still best for readability, to use a full if-else block From ldo at geek-central.gen.new_zealand Wed Sep 29 09:01:07 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 30 Sep 2010 02:01:07 +1300 Subject: System idle time under Linux References: Message-ID: /proc/stat or /proc/uptime, depending. See the proc(5) man page. From frank at chagford.com Wed Sep 29 09:04:23 2010 From: frank at chagford.com (Frank Millman) Date: Wed, 29 Sep 2010 15:04:23 +0200 Subject: scheduler or infinite loop References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> Message-ID: harryos wrote: > hi > I am trying to write a program to read data from a site url. > The program must read the data from site every 5 minutes. > > def get_data_from_site(pageurlstr): > h=urllib.urlopen(pageurlstr) > data=h.read() > process_data(data) > > At first, I thought of using the sched module ,but then it doesn't > look right adding so many scheduler.enter() statements.The program is > supposed to execute the above function every > 5 minutes until the application is shut down by the user. > > I created an infinite loop > while True: > print time.asctime() > get_data_from_site('http://somesite.com/') > time.sleep(300) > > Is there a better way to do this?Any suggestions ,pointers most > welcome > thanks > harry Here is a technique that allows the loop to run in the background, in its own thread, leaving the main program to do other processing - import threading class DataGetter(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.event = threading.Event() def run(self): event = self.event # make local while not event.is_set(): print time.asctime() # either call the function from here, # or put the body of the function here get_data_from_site('http://somesite.com/') event.wait(300) def stop(self): self.event.set() In the startup of the main program, insert the following - data_getter = DataGetter() data_getter.start() At the end of the program, terminate the loop like this - data_getter.stop() HTH Frank Millman From ldo at geek-central.gen.new_zealand Wed Sep 29 09:07:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 30 Sep 2010 02:07:44 +1300 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: In message , Seebs wrote: > Helps, perhaps, that I got exposed to group theory early enough to be used > to redefining + and * to be any two operations which have interesting > properties ... But groups only have one such operation; it?s rings and fields (and number systems) that have two. From oswald.harry at gmail.com Wed Sep 29 09:26:41 2010 From: oswald.harry at gmail.com (harryos) Date: Wed, 29 Sep 2010 06:26:41 -0700 (PDT) Subject: scheduler or infinite loop References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> Message-ID: <344a231a-1ed7-4be6-bd14-aa6adf965b03@n19g2000prf.googlegroups.com> thanks Frank > > Here is a technique that allows the loop to run in the background, in its > own thread, leaving the main program to do other processing - > > import threading > > class DataGetter(threading.Thread): > From emekamicro at gmail.com Wed Sep 29 09:46:55 2010 From: emekamicro at gmail.com (Emeka) Date: Wed, 29 Sep 2010 14:46:55 +0100 Subject: Introducing Kids to Programming: 2 or 3? In-Reply-To: References: Message-ID: Marco, This is a great news coming out of Africa. I would very much like to see this your success story replicate across the continent. I would like to participate and to have your programs for my country, Nigeria. >From what you asked for, I would say that those kids should be part of the future and not the past. So, go for Python 3. Being new to programming, what matters most is learning programming and not the minor syntactical differences. Get them to understand the real thing and they would build up from there. Regards , Emeka On Mon, Sep 27, 2010 at 4:48 PM, Marco Gallotta wrote: > Hi there > > I'm sure you get a lot of "2 or 3" questions, but here's another. > Umonya [1] uses Python to introduce school kids to programming. The > initiative is only 15 months old and up till now we've been using > existing notes and exercises and thus Python 2. But we're at the stage > where we can either stick with 2 for the next few years, or go to 3 > now. > > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. As such, we're taking the time now > to write our very own specialised course notes and exercises, and we > this is why we need to decide *now* which path to take: 2 or 3? As we > will be translating the notes we'll probably stick with out choice for > the next few years. > > Since these are kids, we feel the nice changes in 3 such as removing > integer division will help in teaching. It will also remove confusion > when they go to download Python and grab the latest version. Since > they're just starting, chances are almost none will be hit by the > limited library support for at least a year or two. They will, > however, be hit by the confusion of seeing Python 2 code all over the > web. > > We're tending towards 3, but I am a little cautious myself. > > Marco > > [1] http://umonya.co.za > > -- > Marco Gallotta > MSc Student > Department of Computer Science, University of Cape Town > people.cs.uct.ac.za/~mgallott | > marco-za.blogspot.com > marco AT gallotta DOT co DOT za | 073 170 4444 | 021 552 2731 > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom.conneely at gmail.com Wed Sep 29 09:50:05 2010 From: tom.conneely at gmail.com (Tom Conneely) Date: Wed, 29 Sep 2010 06:50:05 -0700 (PDT) Subject: PyCObject & malloc creating memory leak Message-ID: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> I'm attempting to write a library for reading data via USB from a device and processing the data to display graphs. I have already implemented parts of this code as pure python, as a proof of concept but I have now moved on to implementing the functions in a C extension. My original plan was to have the data processing and data acquisition functions running in separate processes, with a multiprocessing.Queue for passing the raw data packets. The raw data is read in as a char*, with a non constant length, hence I have allocated memory using PyMem_Malloc and I am returning from the acquisition function a PyCObject containing a pointer to this char* buffer, along with a destructor. The following code shows a simple test function I've written (with some module/class boilerplate removed) to demonstrate this. static void p_destruct(void *p) { PyMem_Free((void*)p); } static PyObject *malloc_buffer(MyClass *k1) { PyObject *cobj; char *foo = PyMem_Malloc(1024 * sizeof(char)); if (foo == NULL) { return NULL; } foo = "foo"; cobj = PyCObject_FromVoidPtr(foo, p_destruct); return cobj; } static PyObject *retrieve_buffer(MyClass *k1, PyObject *args) { char *foo2; PyObject cobj2; char *kwlist[] = {"foo1", NULL}; if (!PyArg_ParseTuple(args, "O", &cobj2)) { return NULL; } foo2 = PyCObject_AsVoidPtr(cobj2); //Do something PySys_WriteStdout(foo2); Py_RETURN_NONE; } So if I call these functions in a loop, e.g. The following will generate ~10GB of data x = MyClass() for i in xrange(0, 10 * 2**20): c = x.malloc_buffer() x.retrieve_buffer(c) All my memory disapears, until python crashes with a MemoryError. By placing a print in the destructor function I know it's being called, however it's not actually freeing the memory. So in short, what am I doing wrong? This is the first time I've written a non-trivial python C extension, and I'm still getting my head round the whole Py_INC/DECREF and the correct way to manage memory, so I spent a while playing around with incref/decref but I left these out of my above example to keep what I'm trying to achieve clearer. Also, I'm aware PyCObject is deprecated in >=2.7 but I'm targeting Python 2.6 at the moment, and I will move on to using capsules once I've made the big jump with some other libraries. So if there is anything that could be hugely different using capsules could you point this out. I'm developing using: Python - 2.6.5 Windows XP (although linux is a future target platform) msvc compiler Cheers, any help would be greatly appreciated. From no.email at please.post Wed Sep 29 09:54:18 2010 From: no.email at please.post (kj) Date: Wed, 29 Sep 2010 13:54:18 +0000 (UTC) Subject: Supplementing the std lib (Was: partial sums problem) References: Message-ID: In Terry Reedy writes: >Do not try to do a reduction with a comprehension. Just write clear, >straightforward code that obviously works. >s=[1,2,3,4,5,6] >def cusum(s): > t = 0 > for i in s: > t += i > yield t >print(list(cusum(s))) > >>> >[1, 3, 6, 10, 15, 21] Actually, this is just fine. Thank you! But it brings up a new question, of an entirely different nature. It's a recurrent conundrum, actually, and I have not found a good solution. Your cusum function is one that I would like to see somewhere in the standard library (in itertools maybe?). Maybe some future version of the standard library will have it, or something like it (I'm thinking of a generalized form which, like reduce, takes a function and an initial value as arguments). But in the immediate term, cusum is not part of the standard library. Where would you put it if you wanted to reuse it? Do you create a module just for it? Or do you create a general stdlib2 module with all those workhorse functions that have not made it to the standard library? Or something else entirely? (I'm not expecting to get *the* solution from anyone reply; rather, I'm interested in reading people's take on the question and their way of dealing with those functions they consider worthy of the standard library.) kj From hugol at fastmail.net Wed Sep 29 09:55:33 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Wed, 29 Sep 2010 09:55:33 -0400 Subject: System idle time under Linux In-Reply-To: References: Message-ID: <1285768533.14918.1397491647@webmail.messagingengine.com> Thanks, will take a closer look on that But to get me started, how would you get, via python, the info from that ? Thanks alot On Thu, 30 Sep 2010 02:01 +1300, "Lawrence D'Oliveiro" wrote: > /proc/stat or /proc/uptime, depending. See the proc(5) man page. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hugo L?veill? hugol at fastmail.net From usenot at geekmail.INVALID Wed Sep 29 09:57:10 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 29 Sep 2010 09:57:10 -0400 Subject: Reoedering indexes in list of list References: Message-ID: <20100929095710.550552bf@geekmail.INVALID> On Tue, 28 Sep 2010 11:55:18 -0700 (PDT) Toto wrote: > Hello, > > I have a list of list > assume myList[x][y] is integer > I would like to create an alias to that list which I could call this > way: > alias[y][x] returns myList[x][y] > > how can I do that ? (python 2.6) > > (I have a feeling I should use 'property' ;) > The zip thing certainly seems nice. But I can never get my head around zip quick enough to not be confused by it. So my initial idea would have been a function: def reverse_indices(lst, x, y): return lst[y][x] (or, possibly, a subclass of list with this as an additional method.) Granted, the invocation is different from what you want, but I don't know enough about your problem to judge whether this is an issue. /W -- INVALID? DE! From kst-u at mib.org Wed Sep 29 10:00:56 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 07:00:56 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Message-ID: Erik Max Francis writes: > Keith Thompson wrote: >> Erik Max Francis writes: >> [...] >>> >>> print c # floating point accuracy aside >>> 299792458.0 m/s >> >> Actually, the speed of light is exactly 299792458.0 m/s by >> definition. (The meter and the second are defined in terms of the >> same wavelength of light; this was changed relatively recently.) > > I know. Hence why I wrote the comment "floating point accuracy aside" > when printing it. Ok. I took the comment to be an indication that the figure was subject to floating point accuracy concerns; in fact you meant just the opposite. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From w_a_x_man at yahoo.com Wed Sep 29 10:04:26 2010 From: w_a_x_man at yahoo.com (w_a_x_man) Date: Wed, 29 Sep 2010 07:04:26 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Message-ID: On Sep 26, 9:24?am, p... at informatimago.com (Pascal J. Bourguignon) wrote: > Xah Lee writes: > > here's a interesting toy list processing problem. > > > I have a list of lists, where each sublist is labelled by > > a number. I need to collect together the contents of all sublists > > sharing > > the same label. So if I have the list > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > r) (5 s t)) > > > where the first element of each sublist is the label, I need to > > produce: > > > output: > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > a Mathematica solution is here: > >http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > > R5RS Scheme lisp solution: > >http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_... > > by Sourav Mukherjee > > > also, a Common Lisp solution can be found here: > >http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1de... > > It's too complex. Just write: > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > ? ? ? ? ? ? ? (2 o p) (4 q r) (5 s t)))) > > ? (mapcar (lambda (class) (reduce (function append) class :key (function rest))) > ? ? ? ? ? ?(com.informatimago.common-lisp.list:equivalence-classes list :key (function first))) > > ? ?) > > --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) > > -- > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/ Ruby: [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], [5, 's', 't']]. group_by{|x| x.first}.values.map{|x| x.map{|y| y[1..-1]}.flatten} ==>[["s", "t"], ["a", "b"], ["c", "d", "i", "j"], ["e", "f", "k", "l", "o", "p"], ["g", "h"], ["m", "n", "q", "r"]] From tinauser at libero.it Wed Sep 29 10:06:43 2010 From: tinauser at libero.it (tinauser at libero.it) Date: Wed, 29 Sep 2010 16:06:43 +0200 (CEST) Subject: embedding python in macOS 10.6 Message-ID: <12106339.2710371285769203628.JavaMail.defaultUser@defaultHost> hi there, i'm trying to embed python in a c++ code.i'm starting with the example in the tutorial.i've problem with setting up the enveiroment. I've installed python with the distributed version (i.e., i did not, as a start, build it myself); i added the library where both python.h and pyconfig are stored and i linked to libpython2.6.a (which is, in the distributed version, an alias). the program builds and links correctely, but if I try to run it, i get the following error: Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] 'import site' failed; use -v for traceback Traceback (most recent call last): File "", line 1, in ImportError: No module named time what is the problem? in my .profile i have set PATH: /Library/Frameworks/Python. framework/Versions/2.6/bin From wizzardx at gmail.com Wed Sep 29 10:24:27 2010 From: wizzardx at gmail.com (David) Date: Wed, 29 Sep 2010 16:24:27 +0200 Subject: Python becoming orphaned over ssh Message-ID: Hi there, I have a strange situation. If I do this: 1. Make a script /tmp/test.py on a remote server, with this contents: #!/usr/bin/python from subprocess import check_call check_call(['ping', 'www.google.com']) 2. Call the script like this over SSH: ssh root at testbox /tmp/test.py 3. Interrupt the script with Ctrl+C. Then what happens: The SSH session terminates, as expected. However: On the testing box, the Python script is still running, and so is the ping session. However, if I make an equivalent shell script, /tmp/test.sh, with this contents: #!/bin/bash ping www.google.com And then run it over ssh like this: ssh root at testbox /tmp/test.sh And then hit Ctrl+C, then the shell script and ping are both interrupted remotely, as expected. Here is how 'pstree -p' looks for the python script on the test box, before Ctrl+C: ??sshd(1158)???sshd(19756)???test.py(19797)???ping(19798) ? ??sshd(20233)???bash(20269)???pstree(19875) And after Ctrl+C: ??sshd(1158)???sshd(20233)???bash(20269)???pstree(20218) ??test.py(19797)???ping(19798) Basically, the server-side sshd sub-process has disconnected, but the Python script (and it's ping subprocess) have become orphaned, and now belong to the init process. Note, this only seems to happen if Python is executing a subprocess, and only while Python is being run through a non-interactive ssh session. How can I make Python behave better? I want it to close down itself and it's subprocess, and not orphan itself when I hit ctrl+C PS: The Python version on the testing box: 2.6.4, and the box itself is running Ubuntu Karmic. Also, it's not just ping, but other utilities, eg wget. PPS: I did also try adding logic to the python script, to keep an eye on all the ppids (parent, grandparent, etc), and then to interrupt itself and kill it's subprocess, but that doesn't seem to work: For whatever reason, Python seems to be unable to kill it's subprocess in this situation. The Python process closes, and ping becomes a child of init. But I can then kill ping manually, from a separate ssh session. From tinauser at libero.it Wed Sep 29 10:26:49 2010 From: tinauser at libero.it (tinauser at libero.it) Date: Wed, 29 Sep 2010 16:26:49 +0200 (CEST) Subject: R: embedding python in macOS 10.6 Message-ID: <29636155.2715721285770409375.JavaMail.defaultUser@defaultHost> sorry, my error; in order to achieve what written before, i had to link to the libpython2.6.a that i find downloading the surce code. instead, if I link to the one of the distributed version, i get the following error: missing required architecture x86_64 in file. i tried to build with the -m32 option,but then to that message, another is added for the object file file was built for i386 which is not the architecture being linked (x86_64) >----Messaggio originale---- >Da: tinauser at libero.it >Data: 29/09/2010 16.06 >A: >Ogg: embedding python in macOS 10.6 > >hi there, > >i'm trying to embed python in a c++ code.i'm starting with the example in the >tutorial.i've problem with setting up the enveiroment. >I've installed python with the distributed version (i.e., i did not, as a >start, build it myself); i added the library where both python.h and pyconfig >are stored and i linked to libpython2.6.a (which is, in the distributed >version, an alias). >the program builds and links correctely, but if I try to run it, i get the >following error: > >Could not find platform independent libraries >Could not find platform dependent libraries >Consider setting $PYTHONHOME to [:] >'import site' failed; use -v for traceback >Traceback (most recent call last): > File "", line 1, in >ImportError: No module named time > >what is the problem? > >in my .profile i have set PATH: /Library/Frameworks/Python. >framework/Versions/2.6/bin From hidura at gmail.com Wed Sep 29 10:29:40 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Wed, 29 Sep 2010 14:29:40 +0000 Subject: Upload files with wsgi In-Reply-To: <90e6ba4fc572b3f22a0491653fe5@google.com> Message-ID: <90e6ba53acdcbc11b4049166caf7@google.com> That is what i get: FieldStorage(None, None, []) On Sep 29, 2010 8:39am, hidura at gmail.com wrote: > Python3k give me an error doing that. > On Sep 29, 2010 3:55am, Richard Thomas chardster at gmail.com> wrote: > > On Sep 28, 11:31 pm, Hidura hid... at gmail.com> wrote: > > > > > Hello, i have a project on Python3k, and i have a very big problem i > > > > > don' t find how take an upload file i am using the wsgiref lib, and or > > > > > theres any way to connect to the client in order to get the file by > > > > > myself? > > > > > > > > > > Thank you > > > > > Diego Hidalgo. > > > > > > > > > > -- > > > > > Enviado desde mi dispositivo m?vil > > > > > > > > > > Diego I. Hidalgo D. > > > > > > > > 'wsgiref' doesn't do that part of request handling. You want to use > > > > the 'cgi' module to parse the POST data: > http://docs.python.org/library/cgi.html > > > > > > > > Remember to set the enctype on your tags to multipart/form- > > > > data. > > > > > > > > Chard. > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Wed Sep 29 10:48:49 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Sep 2010 14:48:49 +0000 (UTC) Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > > Thanks, will take a closer look on that > > But to get me started, how would you get, via python, the info from that? Good grief. They're text files. You open them, you read them, you parse the contents for the stuff you want. -- Grant Edwards grant.b.edwards Yow! Did something bad at happen or am I in a gmail.com drive-in movie?? From thomas at jollybox.de Wed Sep 29 10:56:22 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 29 Sep 2010 16:56:22 +0200 Subject: System idle time under Linux In-Reply-To: <1285768533.14918.1397491647@webmail.messagingengine.com> References: <1285768533.14918.1397491647@webmail.messagingengine.com> Message-ID: <201009291656.23480.thomas@jollybox.de> On Wednesday 29 September 2010, it occurred to Hugo L?veill? to exclaim: > Thanks, will take a closer look on that > > But to get me started, how would you get, via python, the info from that > ? Parse the files. They may be very special files, but they are just files. > > Thanks alot > > > On Thu, 30 Sep 2010 02:01 +1300, "Lawrence D'Oliveiro" > > wrote: > > /proc/stat or /proc/uptime, depending. See the proc(5) man page. From hugol at fastmail.net Wed Sep 29 10:57:47 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Wed, 29 Sep 2010 10:57:47 -0400 Subject: System idle time under Linux In-Reply-To: References: Message-ID: <1285772267.31332.1397503573@webmail.messagingengine.com> Sorry, I am not a linux guy. Did not know it was a text file On Wed, 29 Sep 2010 14:48 +0000, "Grant Edwards" wrote: > On 2010-09-29, Hugo L?veill? wrote: > > > > Thanks, will take a closer look on that > > > > But to get me started, how would you get, via python, the info from that? > > Good grief. They're text files. You open them, you read them, > you parse the contents for the stuff you want. > > -- > Grant Edwards grant.b.edwards Yow! Did something bad > at happen or am I in a > gmail.com drive-in movie?? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hugo L?veill? hugol at fastmail.net From invalid at invalid.invalid Wed Sep 29 11:36:33 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Sep 2010 15:36:33 +0000 (UTC) Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > Sorry, I am not a linux guy. Did not know it was a text file And the "file" command (the usual way to figure that out) doesn't appear to be helpful: $ file /etc/passwd /etc/passwd: ASCII text [That's helpful] $ file /proc/stat /proc/stat: empty [That's not] However, as usual, Google comes to rescue. The first hit for "/proc/stat" has a detailed description: http://www.linuxhowtos.org/System/procstat.htm -- Grant Edwards grant.b.edwards Yow! My mind is a potato at field ... gmail.com From philip at semanchuk.com Wed Sep 29 11:44:53 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 29 Sep 2010 11:44:53 -0400 Subject: how to test get_special_folder_path()? Message-ID: <8CEC873D-98E1-4D3A-AEDC-52784EA5D927@semanchuk.com> Hi all, The documentation for get_special_folder_path() and friends says that they're "available as additional built-in functions in the installation script". http://docs.python.org/distutils/builtdist.html#the-postinstallation-script Does anyone know of a way to play around with these functions outside of a post-install script? It's time-consuming to install something just to experiment with a single function. Thanks Philip From emile at fenx.com Wed Sep 29 11:46:43 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 29 Sep 2010 08:46:43 -0700 Subject: if the else short form In-Reply-To: References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: On 9/29/2010 5:53 AM Philip Semanchuk said... > > Does Python make any guarantee that int(True) == 1 and int(False) == 0 will always hold, or are their values an implementation detail? > I had exactly this same question occur to me yesterday, and yes, I believe it does. From http://docs.python.org/reference/datamodel.html#objects-values-and-types Booleans These represent the truth values False and True. The two objects representing the values False and True are the only Boolean objects. The Boolean type is a subtype of plain integers, and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively. Emile From usenot at geekmail.INVALID Wed Sep 29 11:47:01 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 29 Sep 2010 11:47:01 -0400 Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: <20100929114701.110c18b5@geekmail.INVALID> On Wed, 29 Sep 2010 08:53:17 -0400 Philip Semanchuk wrote: > Does Python make any guarantee that int(True) == 1 and int(False) == > 0 will always hold, or are their values an implementation detail? > Booleans (bool) These represent the truth values False and True. The two objects representing the values False and True are the only Boolean objects. The Boolean type is a subtype of the integer type, and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively. /W -- INVALID? DE! From sridharr at activestate.com Wed Sep 29 12:16:54 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Wed, 29 Sep 2010 09:16:54 -0700 Subject: bzr 2.2.1 released ! In-Reply-To: References: Message-ID: Hi, It seems that you forgot to update PyPI - which lists 2.1.0rc1 as the latest version. -srid On 2010-09-28, at 7:20 AM, Vincent Ladeuil wrote: > The Bazaar team is happy to announce availability of a new > release of the bzr adaptive version control system. > Bazaar is part of the GNU system . > > This is a bugfix release which also includes bugfixes from 2.0.6 and > 2.1.3. None are critical, but upgrading is recommended for all users on > earlier 2.2 releases. > > Thanks to everyone who contributed patches, suggestions, and > feedback. > > Bazaar is now available for download from > > https://launchpad.net/bzr/2.2/2.2.1/ > > as a source tarball. Packages are already available for Ubuntu, FreeBSD > and others. Installers are available for OSX, windows installers should > be available Really Soon Now (watch the url above where they should pop > up as soon as they become available). > > bzr 2.2.1 > ######### > > :2.2.1: 2010-09-17 > > This is a bugfix release which also includes bugfixes from 2.0.6 and > 2.1.3. None are critical, but upgrading is recommended for all users on > earlier 2.2 releases. > > Bug Fixes > ********* > > * Additional merges after an unrelated branch has been merged with its > history no longer crash when deleted files are involved. > (Vincent Ladeuil, John Arbash Meinel, #375898) > > * ``bzr add SYMLINK/FILE`` now works properly when the symlink points to a > previously-unversioned directory within the tree: the directory is > marked versioned too. > (Martin Pool, #192859) > > * ``bzr commit SYMLINK`` now works, rather than trying to commit the > target of the symlink. > (Martin Pool, John Arbash Meinel, #128562) > > * ``bzr upgrade`` now creates the ``backup.bzr`` directory with the same > permissions as ``.bzr`` directory on a POSIX OS. > (Parth Malwankar, #262450) > > * CommitBuilder now uses the committer instead of _config.username to generate > the revision-id. (Aaron Bentley, #614404) > > * Configuration files in ``${BZR_HOME}`` are now written in an atomic > way which should help avoid problems with concurrent writers. > (Vincent Ladeuil, #525571) > > * Cope with Microsoft FTP server that returns reply '250 Directory > created' when mkdir succeeds. (Martin Pool, #224373) > > * Don't traceback trying to unversion children files of an already > unversioned directory. (Vincent Ladeuil, #494221) > > * Don't traceback when a lockdir's ``held/info`` file is corrupt (e.g. > contains only NUL bytes). Instead warn the user, and allow ``bzr > break-lock`` to remove it. (Andrew Bennetts, #619872) > > * Fix ``AttributeError on parent.children`` when adding a file under a > directory that was a symlink in the previous commit. > (Martin Pool, #192859) > > * Fix ``AttributeError: 'NoneType' object has no attribute 'close'`` in > ``_close_ssh_proc`` when using ``bzr+ssh://``. This was causing > connections to pre-1.6 bzr+ssh servers to fail, and causing warnings on > stderr in some other circumstances. (Andrew Bennetts, #633745) > > * Only call ``setlocale`` in the bzr startup script on posix systems. This > avoids an issue with the newer windows C runtimes used by Python 2.6 and > later which can mangle bytestrings printed to the console. > (Martin [gz], #631350) > > * Prevent ``CHKMap.apply_delta`` from generating non-canonical CHK maps, > which can result in "missing referenced chk root keys" errors when > fetching from repositories with affected revisions. > (Andrew Bennetts, #522637) > > * Raise ValueError instead of a string exception. > (John Arbash Meinel, #586926) > > * Reduce peak memory by one copy of compressed text. > (John Arbash Meinel, #566940) > > * Repositories accessed via a smart server now reject being stacked on a > repository in an incompatible format, as is the case when accessing them > via other methods. This was causing fetches from those repositories via > a smart server (e.g. using ``bzr branch``) to receive invalid data. > (Andrew Bennetts, #562380) > > * Selftest with versions of subunit that support ``stopTestRun`` will no longer > error. This error was caused by 2.0 not being updated when upstream > python merged the end of run patch, which chose ``stopTestRun`` rather than > ``done``. (Robert Collins, #571437) > > * Stop ``AttributeError: 'module' object has no attribute 'ElementTree'`` > being thrown from ``xml_serializer`` on certain cElementTree setups. > (Martin [gz], #254278) > > * Upgrading or fetching from a non-rich-root repository to a rich-root > repository (e.g. from pack-0.92 to 2a) no longer fails with > ``'Inter1and2Helper' object has no attribute 'source_repo'``. This was > a regression from Bazaar 2.1. (Andrew Bennetts, #636930) > > * When passing a file to ``UTF8DirReader`` make sure to close the current > directory file handle after the chdir fails. Otherwise when passing many > filenames into a command line ``bzr status`` we would leak descriptors. > (John Arbash Meinel, #583486) > > Documentation > ************* > > * Fix a lot of references in the docs to the old http://bazaar-vcs.org to > the new http://bazaar.canonical.com or http://wiki.bazaar.canonical.com > (John Arbash Meinel, #617503) > > Internals > ********* > > * Remove used and broken code path in ``BranchInitHookParams.__repr__``. > (Andrew Bennetts) > > Testing > ******* > > * ``build_tree_contents`` can create symlinks. > (Martin Pool, John Arbash Meinel) > > * Tracebacks from a parameterized test are no longer reported against every > parameterization of that test. This was done by adding a hack to > ``bzrlib.tests.clone_test`` so that it no longer causes > testtools.TestCase instances to share a details dict. > (Andrew Bennetts, #625574) > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ From nagle at animats.com Wed Sep 29 12:49:37 2010 From: nagle at animats.com (John Nagle) Date: Wed, 29 Sep 2010 09:49:37 -0700 Subject: Python becoming orphaned over ssh In-Reply-To: References: Message-ID: <4ca36e44$0$1584$742ec2ed@news.sonic.net> On 9/29/2010 7:24 AM, David wrote: > Hi there, I have a strange situation. > > If I do this: > > 1. Make a script /tmp/test.py on a remote server, with this contents: > > #!/usr/bin/python > from subprocess import check_call Python's signal handling for multithread and multiprocess programs leaves something to be desired. John Nagle From jmellander at lbl.gov Wed Sep 29 12:50:21 2010 From: jmellander at lbl.gov (Jim Mellander) Date: Wed, 29 Sep 2010 09:50:21 -0700 Subject: Determine sockets in use by python Message-ID: Hi: I'm a newbie to python, although not to programming. Briefly, I am using a binding to an external library used for communication in a client-server context, with the server in python. Typically, I would set this up with event callbacks, and then enter a select loop, which, most the time idles and processes input events when the socket shows activity, kinda like: while True: socket.select((my_socket),(),()) process_event() Unfortunately, the API does not expose the socket to the script level, and the developer recommends a busy loop: while True: sleep(1) process_event() which I hope to avoid, for many reasons. If the socket can be exposed to the script level, then the problem would be solved. Failing that, it would be nice to be able to pythonically determine the sockets in use and select on those. Does anyone have any suggestions on how to proceed? Thanks in advance From ethan at stoneleaf.us Wed Sep 29 13:11:13 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 29 Sep 2010 10:11:13 -0700 Subject: Supplementing the std lib (Was: partial sums problem) In-Reply-To: References: Message-ID: <4CA37331.2020704@stoneleaf.us> kj wrote: > I'm interested in reading people's take on the question and their > way of dealing with those functions they consider worthy of the > standard library.) Well, I have no functions than I'm lobbying to get into the stdlib, but for all those handy-dandy utility functions, decorators, and classes, I have a cookbook package that I add them to. Mine currently looks like this: cookbook __init__.py decorators.py meters.py simplegeneric.py utils.py collections __init__.py NamedTuple.py RecordType.py From usenet-nospam at seebs.net Wed Sep 29 13:20:39 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 17:20:39 GMT Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: On 2010-09-29, Tracubik wrote: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can any of > you pass me any reference/link to this particular if/then/else form? Oh, what a nasty idiom. Here's the gimmick. ("False,", "True,") is a tuple. That means you can index it. For instance: ("False,", "True,")[0] is the string "False,". So, what is the numeric value of "fill == True"? Apparently, at least at the time this was written, it was 0 if fill was not equal to True, and 1 if fill was equal to True. Let me say, though, that I'm a C programmer, so I'm coming from a language where the result of 0-or-1 for test operators is guaranteed, and I still wouldn't use this in live code. It's insufficiently legible. -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 Sep 29 13:25:03 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 17:25:03 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-29, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> Helps, perhaps, that I got exposed to group theory early enough to be used >> to redefining + and * to be any two operations which have interesting >> properties ... > But groups only have one such operation; it???s rings and fields (and number > systems) that have two. They're covered in the same class, therefore, they're part of the same field (of study, that is). :P -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 Sep 29 13:27:13 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 17:27:13 GMT Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > I have found it for windows and mac, but no luck under linux. Any idea? I don't think it's semantically well-defined. What makes a system "idle"? Is the machine in my basement idle? I don't think anyone's touched the keyboard in a week, but it's spent a big chunk of that time with 100% CPU load across all eight processors, and I was running a bunch of work on it yesterday, including interactive sessions. Windows and Mac systems *typically* have a well-defined "console" on which the primary user is active... But as a counterexample, my news reader is actually running on an OS X box that's about fifty feet from me, which I connect to via ssh. I would be very curious to see whether your test for "system idle time" would realize that the machine I'm currently working on is actively in use, even though I don't think the console is even logged in... Basically, I can't help you, but I can tell you that you are quite possibly asking the wrong question. -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 tar at sevak.isi.edu Wed Sep 29 13:54:53 2010 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 29 Sep 2010 10:54:53 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: George Neuner writes: > On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson > wrote: > >He didn't say it was. Internal calculations are done in SI units (in > >this case, m^3/sec); on output, the internal units can be converted to > >whatever is convenient. > > That's true. But it is a situation where the conversion to SI units > loses precision and therefore probably shouldn't be done. I suppose that one has to choose between two fundamental designs for any computational system of units. One can either store the results internally in a canonical form, which generally means an internal representation in SI units. Then all calculations are performed using the interal units representation and conversion happens only on input or output. Or one can store the values in their original input form, and perform conversions on the fly during calculations. For calculations one will still need to have some canonical representation for cases where the result value doesn't have a preferred unit provided. For internal calculations this will often be the case. Now whether one will necessarily have a loss of precision depends on whether the conversion factors are exact or approximations. As long as the factors are exact, one can have the internal representation be exact as well. One method would be to use something like the Commmon Lisp rational numbers or the Gnu mp library. And a representation where one preserves the "preferred" unit for display purposes based on the original data as entered is also nice. Roman Cunis' Common Lisp library does that, and with the use of rational numbers for storing values and conversion factors allows one to do nice things like make sure that 30mph * 3h = 90mi even when the internal representation is in SI units (m/s, s, m). -- Thomas A. Russ, USC/Information Sciences Institute From namekuseijin at gmail.com Wed Sep 29 14:02:03 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Wed, 29 Sep 2010 11:02:03 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> Message-ID: <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> On 28 set, 19:38, Xah Lee wrote: > ? ?list comprehension? is a very bad jargon; thus harmful to > functional programing or programing in general. Being a bad jargon, it > encourage mis-communication, mis-understanding. I disagree: it is a quite intuitive term to describe what the expression does. > ? ?list comprehension? is a redundant concept in programing. The > concept is of historical interest. e.g. when people talk about the > history of computer languages. The LC can simply be filter(map(func, > list), predicate). I agree it is redundant. Like pretty much all syntax: all one needs is a way to define functions and to apply function to arguments (or assignment and pre-defined loops for imperative folks). Syntax may still be more convenient, though. Which is strange since you were an ardent syntax lover a few iterations ago. > ? The special syntax of ?list comprehension? as it exists in many > langs, are not necessary. It can simply be a plain function, e.g > LC(function, list, filter). I disagree. Syntax may be redundant, but it is there to be convenient. I'll quote it again: "For instance, this is far more convenient: [x+1 for x in [1,2,3,4,5] if x%2==0] than this: map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) but on the other hand, this is more convenient: map(inc,filter(evenp,[1,2,3,4,5])) (ignoring the lines of code for inc and evenp, of course. But as long as they are used in many parts, it *is* more convenient) In short, list comprehensions are useful syntatic expressions returning lists as long as you don't care for the short functions used in them." > ?do syntax does allow for imperative commands to be issued in scheme, > just like let. It does not mean it was used in said examples nor that > do is automatically inherently imperative just because of choice of > name. imperative do -> (do (steppers ...) (final-condition? result) > malign-imperative-code-here ...)? > > i don't think your argument is forceful enough. > > It appears that by this argument you even say that ?let? is not > functional. In the case of Lisps, it depends on context: let is an expression returning a value, but Lisps are not purely functional languages and you *may* use imperative statements in the body, resulting in useful side-effect computations. That's why I said do is no more imperative than let: 1) because it *is* let and 2) because Lisps *allow* imperative constructs in the body of lambdas. do is not inherently imperative in the same sense Lisp/Scheme is not inherently imperative: they allow you to do purely functional evaluation of expressions but also to tint the computations with side-effects... your choice. > So, overall, i consider your argument for ?do? in Scheme lisp being > functional is weak, or trivial. It seems to be a pet peeve. It is a pet peeve in that you call `do' imperative without arguments while a few other Schemers call `do' imperative on the basis of political bickering. Nobody gives `do' a chance of the base of it being what it is: a macro transform into let. Any imperative programming you do with `do' will get the same effect as if you do the same imperative programming with let. Imperative or functional, it's up to the user, not inherently from any language construct. > You got > annoyed because i seem to have ignored it entirely. But i got annoyed > by you because you don't get the point about what i consider more > significant opinion on ?list comprehension?, which you totally ignored > and kept at hacking the ?do? in Scheme lisp. It's because I don't think I have much to comment on list comprehensions other than being useful syntax at times for an expression returning a list. From gherron at digipen.edu Wed Sep 29 14:05:14 2010 From: gherron at digipen.edu (Gary Herron) Date: Wed, 29 Sep 2010 11:05:14 -0700 Subject: Determine sockets in use by python In-Reply-To: References: Message-ID: <4CA37FDA.3080605@digipen.edu> On 09/29/2010 09:50 AM, Jim Mellander wrote: > Hi: > > I'm a newbie to python, although not to programming. Briefly, I am > using a binding to an external library used for communication in a > client-server context, with the server in python. Typically, I would > set this up with event callbacks, and then enter a select loop, which, > most the time idles and processes input events when the socket shows > activity, kinda like: > > while True: > socket.select((my_socket),(),()) > process_event() > > Unfortunately, the API does not expose the socket to the script level, > and the developer recommends a busy loop: > > while True: > sleep(1) > process_event() > > which I hope to avoid, for many reasons. If the socket can be exposed > to the script level, then the problem would be solved. > > Failing that, it would be nice to be able to pythonically determine > the sockets in use and select on those. Does anyone have any > suggestions on how to proceed? > > Thanks in advance > It's certain that any answer to this will depend on which operating system you are using. So do tell: What OS? -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From gneuner2 at comcast.net Wed Sep 29 14:18:27 2010 From: gneuner2 at comcast.net (George Neuner) Date: Wed, 29 Sep 2010 14:18:27 -0400 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <87bp7gq1c5.fsf@kuiper.lan.informatimago.com> Message-ID: On Wed, 29 Sep 2010 12:40:58 +0200, pjb at informatimago.com (Pascal J. Bourguignon) wrote: >George Neuner writes: > >> On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson >> wrote: >> >>>George Neuner writes: >>>> On 28 Sep 2010 12:42:40 GMT, Albert van der Horst >>>> wrote: >>>>>I would say the dimensional checking is underrated. It must be >>>>>complemented with a hard and fast rule about only using standard >>>>>(SI) units internally. >>>>> >>>>>Oil output internal : m^3/sec >>>>>Oil output printed: kbarrels/day >>>> >>>> "barrel" is not an SI unit. >>> >>>He didn't say it was. Internal calculations are done in SI units (in >>>this case, m^3/sec); on output, the internal units can be converted to >>>whatever is convenient. >> >> That's true. But it is a situation where the conversion to SI units >> loses precision and therefore probably shouldn't be done. >> >>> >>>> And when speaking about oil there isn't >>>> even a simple conversion. >>>> >>>> 42 US gallons ? 34.9723 imp gal ? 158.9873 L >>>> >>>> [In case those marks don't render, they are meant to be the >>>> double-tilda sign meaning "approximately equal".] >>> >>>There are multiple different kinds of "barrels", but "barrels of oil" >>>are (consistently, as far as I know) defined as 42 US liquid gallons. >>>A US liquid gallon is, by definition, 231 cubic inches; an inch >>>is, by definition, 0.0254 meter. So a barrel of oil is *exactly* >>>0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 >>>kbarrels/day. (Please feel free to check my math.) That's >>>admittedly a lot of digits, but there's no need for approximations >>>(unless they're imposed by the numeric representation you're using). >> >> I don't care to check it ... the fact that the SI unit involves 12 >> decimal places whereas the imperial unit involves 3 tells me the >> conversion probably shouldn't be done in a program that wants >> accuracy. > > >Because perhaps you're thinking that oil is sent over the oceans, and >sold retails in barrils of 42 gallons? > >Actually, when I buy oil, it's from a pump that's graduated in liters! > >It comes from trucks with citerns containing 24 m?. > >And these trucks get it from reservoirs of 23,850 m?. > >"Tankers move approximately 2,000,000,000 metric tons" says the English >Wikipedia page... > > > >Now perhaps it all depends on whether you buy your oil from Total or >from Texaco, but in my opinion, you're forgetting something: the last >drop. You never get exactly 42 gallons of oil, there's always a little >drop more or less, so what you get is perhaps 158.987 liter or >41.9999221 US gallons, or even 158.98 liter = 41.9980729 US gallons, >where you need more significant digits. No. I'm just reacting to the "significant figures" issue. Real world issues like US vs Eurozone and measurement error aside - and without implying anyone here - many people seem to forget that multiplying significant figures doesn't add them, and results to 12 decimal places are not necessarily any more accurate than results to 2 decimal places. It makes sense to break macro barrel into micro units only when necessary. When a refinery purchases 500,000 barrels, it is charged a barrel price, not some multiple of gallon or liter price and regardless of drop over/under. The refinery's process is continuous and it needs a delivery if it has less than 20,000 barrels - so the current reserve figure of 174,092 barrels is as accurate as is needed (they need to order by tomorrow because delivery will take 10 days). OTOH, because the refinery sells product to commercial vendors of gasoline/petrol and heating oil in gallons or liters, it does makes sense to track inventory and sales in (large multiples of) those units. Similarly, converting everything to m? simply because you can does not make sense. When talking about the natural gas reserve of the United States, the figures are given in Km? - a few thousand m? either way is irrelevant. George From python at mrabarnett.plus.com Wed Sep 29 14:18:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 19:18:51 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <4CA3830B.60807@mrabarnett.plus.com> On 29/09/2010 18:54, Thomas A. Russ wrote: > George Neuner writes: > >> On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson >> wrote: >>> He didn't say it was. Internal calculations are done in SI units (in >>> this case, m^3/sec); on output, the internal units can be converted to >>> whatever is convenient. >> >> That's true. But it is a situation where the conversion to SI units >> loses precision and therefore probably shouldn't be done. > > I suppose that one has to choose between two fundamental designs for any > computational system of units. One can either store the results > internally in a canonical form, which generally means an internal > representation in SI units. Then all calculations are performed using > the interal units representation and conversion happens only on input or > output. > > Or one can store the values in their original input form, and perform > conversions on the fly during calculations. For calculations one will > still need to have some canonical representation for cases where the > result value doesn't have a preferred unit provided. For internal > calculations this will often be the case. > > Now whether one will necessarily have a loss of precision depends on > whether the conversion factors are exact or approximations. As long as > the factors are exact, one can have the internal representation be exact > as well. One method would be to use something like the Commmon Lisp > rational numbers or the Gnu mp library. > > And a representation where one preserves the "preferred" unit for > display purposes based on the original data as entered is also nice. > Roman Cunis' Common Lisp library does that, and with the use of rational > numbers for storing values and conversion factors allows one to do nice > things like make sure that > > 30mph * 3h = 90mi > > even when the internal representation is in SI units (m/s, s, m). > You could compare it to handling strings, where Unicode is used internally and the encoding can be preserved for when you want to output. From catphive at catphive.net Wed Sep 29 14:33:46 2010 From: catphive at catphive.net (Brendan Miller) Date: Wed, 29 Sep 2010 11:33:46 -0700 Subject: utf-8 and ctypes In-Reply-To: References: Message-ID: 2010/9/29 Lawrence D'Oliveiro : > In message , Brendan > Miller wrote: > >> It seems that characters not in the ascii subset of UTF-8 are >> discarded by c_char_p during the conversion ... > > Not a chance. > >> ... or at least they don't print out when I go to print the string. > > So it seems there?s a problem on the printing side. What happens when you > construct a UTF-8-encoded string directly in Python and try printing it the > same way? Doing this seems to confirm something is broken in ctypes w.r.t. UTF-8... if I enter: str = "???????" Then: print str ??????? However, when I create a string buffer, pass it into my c++ code, and write the same UTF-8 string into it, python seems to discard pretty much all the text. The same code works for pure ascii strings. Python code: _std_string_size = _lib_mbxclient.std_string_size _std_string_size.restype = c_long _std_string_size.argtypes = [c_void_p] _std_string_copy = _lib_mbxclient.std_string_copy _std_string_copy.restype = None _std_string_copy.argtypes = [c_void_p, POINTER(c_char)] # This function works for ascii, but breaks on strings with UTF-8! def std_string_to_string(str_ptr): buf = create_string_buffer(_std_string_size(str_ptr)) _std_string_copy(str_ptr, buf) return buf.raw C++ code: extern "C" long std_string_size(string* str) { return str->size(); } extern "C" void std_string_copy(string* str, char* buf) { std::copy(str->begin(), str->end(), buf); } From hugol at fastmail.net Wed Sep 29 14:36:00 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Wed, 29 Sep 2010 14:36:00 -0400 Subject: System idle time under Linux In-Reply-To: References: Message-ID: <1285785360.27605.1397544741@webmail.messagingengine.com> Good point One I am looking for, is time since last user mouse or keyboard action. So I guess I am looking for the exact same thing a screensaver is looking for On Wed, 29 Sep 2010 17:27 +0000, "Seebs" wrote: > On 2010-09-29, Hugo L?veill? wrote: > > I have found it for windows and mac, but no luck under linux. Any idea? > > I don't think it's semantically well-defined. What makes a system > "idle"? > > Is the machine in my basement idle? I don't think anyone's touched the > keyboard in a week, but it's spent a big chunk of that time with 100% CPU > load across all eight processors, and I was running a bunch of work on > it yesterday, including interactive sessions. > > Windows and Mac systems *typically* have a well-defined "console" on > which > the primary user is active... But as a counterexample, my news reader is > actually running on an OS X box that's about fifty feet from me, which I > connect to via ssh. > > I would be very curious to see whether your test for "system idle time" > would realize that the machine I'm currently working on is actively in > use, > even though I don't think the console is even logged in... > > Basically, I can't help you, but I can tell you that you are quite > possibly > asking the wrong question. > > -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 > -- Hugo L?veill? hugol at fastmail.net From tjreedy at udel.edu Wed Sep 29 14:46:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Sep 2010 14:46:18 -0400 Subject: About __class__ of an int literal In-Reply-To: <8739ss4tk6.fsf@xemacs.org> References: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> <8739ss4tk6.fsf@xemacs.org> Message-ID: On 9/29/2010 8:34 AM, Hrvoje Niksic wrote: > Steven D'Aprano writes: > >> On Wed, 29 Sep 2010 02:20:55 +0100, MRAB wrote: >> >>> On 29/09/2010 01:19, Terry Reedy wrote: >> >>>> A person using instances of a class should seldom use special names >>>> directly. They are, in a sense, implementation details, even if >>>> documented. The idiom "if __name__ == '__main__':" is an exception. >>>> >>> __file__ is another exception. >> As are __iter__, __next__, __add__, __dict__, and, yes, __class__, to >> say nothing of all the other special methods. I strongly disagree. > I think by "person using instances of a class" Terry referred to the > user of a class as opposed to the implementor. Yes. > In that sense the user > should be calling iter(foo) instead of foo.__iter__(), next(foo) instead > of foo.__next__(), and foo+bar instead of foo.__add__(bar). Yes. Guido added iter() and next() to the list of built-in functions, even though they seem reduncant.. I believe it is his intention that the use of special names outside of class statements should be fairly rare. If I remember right, in the old, pre-2.2 system that separated built-in types and user-written classes, the builtins did not have accessible special method attributes. They are only for customizing user classes. So one could not have generically written foo.__add__(bar). Special-method attribute were added to builtins so that they could be inherited (or replaced) by user-written subclasses, not so that one could replace normal syntax. > Direct > calls to special-name methods, such as __len__, often indicate that the > programmer hasn't grasped how those methods are intended to be used in > Python. Right. That fact that *Python* interpreters implement syntax with special methods is an implementation detail of the *language*. The importance is that it allow *writers* of new classes to rather easily imitate built-in classes so that their classes seamlessly plug into the syntax. -- Terry Jan Reedy From usenet-nospam at seebs.net Wed Sep 29 15:07:55 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 19:07:55 GMT Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > One I am looking for, is time since last user mouse or keyboard action. > So I guess I am looking for the exact same thing a screensaver is > looking for You can probably get it from X somehow, but... Basically, be aware that it is entirely possible for a Linux user to invoke python scripts in an enviromnent where this information cannot be obtained, and may not even meaningfully exist. So be sure you fail back gracefully when that happens. Decide in advance what you will infer from "there is no way to obtain this information". Also provide an override. Imagine how helpful it would be to a user to have your script act as though the user had gone idle based on what some OTHER user was doing! -s From invalid at invalid.invalid Wed Sep 29 15:23:54 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Sep 2010 19:23:54 +0000 (UTC) Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > One I am looking for, is time since last user mouse or keyboard action. > So I guess I am looking for the exact same thing a screensaver is > looking for Oh. That's not what "idle" generally means in a Unix/Linux context, so you can disregard previous answers involving /proc/stat et al. -- Grant Edwards grant.b.edwards Yow! It's some people at inside the wall! This is gmail.com better than mopping! From squeamz at hotmail.com Wed Sep 29 15:41:00 2010 From: squeamz at hotmail.com (Squeamizh) Date: Wed, 29 Sep 2010 12:41:00 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> On Sep 27, 10:46?am, namekuseijin wrote: > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > wrote: > > > RG writes: > > > > In article > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, > > > > ?TheFlyingDutchman wrote: > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > >> > This might have been mentioned here before, but I just came across it: a > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get built in > > > >> > dynamically-typed languages. ?It echoes things we've all said here, but > > > >> > I think it's interesting because it describes a conversion experience: > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > >> > -- Scott > > > > >> If you are writing a function to determine the maximum of two numbers > > > >> passed as arguents in a dynamic typed language, what is the normal > > > >> procedure used by Eckel and others to handle someone passing in > > > >> invalid values - such as a file handle for one varible and an array > > > >> for the other? > > > > > The normal procedure is to hit such a person over the head with a stick > > > > and shout "FOO". > > > > Moreover, the functions returning the maximum may be able to work on > > > non-numbers, as long as they're comparable. ?What's more, there are > > > numbers that are NOT comparable by the operator you're thinking about!. > > > > So to implement your specifications, that function would have to be > > > implemented for example as: > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > (defmethod lessp ((x complex) (y complex)) > > > ? (or (< (real-part x) (real-part y)) > > > ? ? ? (and (= (real-part x) (real-part y)) > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > (defun maximum (a b) > > > ? (if (lessp a b) b a)) > > > > And then the client of that function could very well add methods: > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > and call: > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > and who are you to forbid it!? > > > > -- > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/-Hidequoted text - > > > > - Show quoted text - > > > in C I can have a function maximum(int a, int b) that will always > > work. Never blow up, and never give an invalid answer. If someone > > tries to call it incorrectly it is a compile error. > > In a dynamic typed language maximum(a, b) can be called with incorrect > > datatypes. Even if I make it so it can handle many types as you did > > above, it could still be inadvertantly called with a file handle for a > > parameter or some other type not provided for. So does Eckel and > > others, when they are writing their dynamically typed code advocate > > just letting the function blow up or give a bogus answer, or do they > > check for valid types passed? If they are checking for valid types it > > would seem that any benefits gained by not specifying type are lost by > > checking for type. And if they don't check for type it would seem that > > their code's error handling is poor. > > that is a lie. > > Compilation only makes sure that values provided at compilation-time > are of the right datatype. > > What happens though is that in the real world, pretty much all > computation depends on user provided values at runtime. ?See where are > we heading? > > this works at compilation time without warnings: > int m=numbermax( 2, 6 ); > > this too: > int a, b, m; > scanf( "%d", &a ); > scanf( "%d", &b ); > m=numbermax( a, b ); > > no compiler issues, but will not work just as much as in python if > user provides "foo" and "bar" for a and b... fail. > > What you do if you're feeling insecure and paranoid? ?Just what > dynamically typed languages do: ?add runtime checks. ?Unit tests are > great to assert those. > > Fact is: ?almost all user data from the external words comes into > programs as strings. ?No typesystem or compiler handles this fact all > that graceful... I disagree with your conclusion. Sure, the data was textual when it was initially read by the program, but that should only be relevant to the input processing code. The data is likely converted to some internal representation immediately after it is read and validated, and in a sanely-designed program, it maintains this representation throughout its life time. If the structure of some data needs to change during development, the compiler of a statically-typed language will automatically tell you about any client code that was not updated to account for the change. Dynamically typed languages do not provide this assurance. From jmellander at lbl.gov Wed Sep 29 16:08:30 2010 From: jmellander at lbl.gov (Jim Mellander) Date: Wed, 29 Sep 2010 13:08:30 -0700 Subject: Determine sockets in use by python In-Reply-To: <4CA37FDA.3080605@digipen.edu> References: <4CA37FDA.3080605@digipen.edu> Message-ID: Hi Gary: Certainly not windows.... I'm developing on OS/X but for production probably Linux and FreeBSD (I'm hoping for something a bit more portable than running 'lsof' and parsing the output, but appreciate any/all advice) On Wed, Sep 29, 2010 at 11:05 AM, Gary Herron wrote: > On 09/29/2010 09:50 AM, Jim Mellander wrote: >> >> Hi: >> >> I'm a newbie to python, although not to programming. ?Briefly, I am >> using a binding to an external library used for communication in a >> client-server context, with the server in python. ?Typically, I would >> set this up with event callbacks, and then enter a select loop, which, >> most the time idles and processes input events when the socket shows >> activity, kinda like: >> >> while True: >> ? ? socket.select((my_socket),(),()) >> ? ? process_event() >> >> Unfortunately, the API does not expose the socket to the script level, >> and the developer recommends a busy loop: >> >> while True: >> ? ? sleep(1) >> ? ? process_event() >> >> which I hope to avoid, for many reasons. ?If the socket can be exposed >> to the script level, then the problem would be solved. >> >> Failing that, it would be nice to be able to pythonically determine >> the sockets in use and select on those. ?Does anyone have any >> suggestions on how to proceed? >> >> Thanks in advance >> > > It's certain that any answer to this will depend on which operating system > you are using. ?So do tell: What OS? > > -- > Gary Herron, PhD. > Department of Computer Science > DigiPen Institute of Technology > (425) 895-4418 > > -- > http://mail.python.org/mailman/listinfo/python-list > From nad at acm.org Wed Sep 29 16:12:49 2010 From: nad at acm.org (Ned Deily) Date: Wed, 29 Sep 2010 13:12:49 -0700 Subject: File holes in Linux References: Message-ID: In article , Tom Potts wrote: > Hi, all. I'm not sure if this is a bug report, a feature request or what, > so I'm posting it here first to see what people make of it. I was copying > over a large number of files using shutil, and I noticed that the final > files were taking up a lot more space than the originals; a bit more > investigation showed that files with a positive nominal filesize which > originally took up 0 blocks were now taking up the full amount. It seems > that Python does not write back file holes as it should; here is a simple > program to illustrate: > data = '\0' * 1000000 > file = open('filehole.test', 'wb') > file.write(data) > file.close() > A quick `ls -sl filehole.test' will show that the created file actually > takes up about 980k, rather than the 0 bytes expected. I would expect the file size to be 980k in that case. AFAIK, simply writing null bytes doesn't automatically create a sparse file on Unix-y systems. Generally, on file systems that support it, files become sparse when you don't write to certain parts of it, i.e. by using lseek(2) to position forward past the end of the file when writing, thereby implying that the intermediate blocks should be treated as zero when reading. Only files on certain file systems on certain platforms support operations like that. Python makes no claim to do that optimization in either its lower-level i/o routines or in the shutil module. The latter's copyfile just copies bytes from input to output. If you want to always preserve sparse files, you could use the GNU cp routine with --sparse=always. If you look at its code, you see that it checks for all-zero blocks when copying and then uses lseek to skip over them when writing. Something like that could be added to shutil, with the necessary tests for which platforms support it. If you are interested in adding that feature, you could write a patch and open a feature request on the Python bug tracker (http://bugs.python.org/). It's not likely to progress without a supplied patch and even then maybe not. -- Ned Deily, nad at acm.org From nad at acm.org Wed Sep 29 16:18:48 2010 From: nad at acm.org (Ned Deily) Date: Wed, 29 Sep 2010 13:18:48 -0700 Subject: Certificate validation with HTTPSConnection References: Message-ID: In article , Velko Ivanov wrote: > I've always wandered why HTTPSConnection does not validate > certificates? > > It is fairly simple to use the SSL socket's validation: [...] Perhaps you can write up your example as a documentation patch to the http.client documentation page and submit it to the Python bug tracker (http://bugs.python.org/). -- Ned Deily, nad at acm.org From lists at cheimes.de Wed Sep 29 16:32:05 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 29 Sep 2010 22:32:05 +0200 Subject: File holes in Linux In-Reply-To: References: Message-ID: Am 29.09.2010 11:05, schrieb Tom Potts: > A quick `ls -sl filehole.test' will show that the created file actually > takes up about 980k, rather than the 0 bytes expected. > > If anyone can let me know if this is indeed a bug or feature request, how to > get around it, or where to take it next, I'd really appreciate it. It's not a bug in Python. You simply misunderstand how sparse files are created. When you write null bytes to a file each null byte takes up space on the file system, too. In order to create a hole, you have to set the file handler's position beyond the file's end. >>> with open("sparse", "w") as fh: ... fh.seek(1000**3) ... fh.write("data") ... $ ls -l --si sparse -rw-r--r-- 1 heimes heimes 1,1G 2010-09-29 22:25 sparse $ ls -s sparse 4 sparse $ du sparse 4 sparse Christian From invalid at invalid.invalid Wed Sep 29 16:38:14 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Sep 2010 20:38:14 +0000 (UTC) Subject: File holes in Linux References: Message-ID: On 2010-09-29, Ned Deily wrote: >, > Tom Potts wrote: >> Hi, all. I'm not sure if this is a bug report, a feature request or what, >> so I'm posting it here first to see what people make of it. I was copying >> over a large number of files using shutil, and I noticed that the final >> files were taking up a lot more space than the originals; a bit more >> investigation showed that files with a positive nominal filesize which >> originally took up 0 blocks were now taking up the full amount. It seems >> that Python does not write back file holes as it should; here is a simple >> program to illustrate: >> data = '\0' * 1000000 >> file = open('filehole.test', 'wb') >> file.write(data) >> file.close() >> A quick `ls -sl filehole.test' will show that the created file actually >> takes up about 980k, rather than the 0 bytes expected. > > I would expect the file size to be 980k in that case. AFAIK, simply > writing null bytes doesn't automatically create a sparse file on Unix-y > systems. Correct. As Ned says, you create holes by seeking past the end of the file before writing data, not by writing 0x00 bytes. Here's a demonstration: Writing 0x00 values: $ dd if=/dev/zero of=foo1 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB) copied, 0.0315967 s, 332 MB/s $ ls -l foo1 -rw-r--r-- 1 grante users 10485760 Sep 29 15:32 foo1 $ du -s foo1 10256 foo1 Seeking, then write a single byte: $ dd if=/dev/zero of=foo2 bs=1 count=1 seek=10485759 1+0 records in 1+0 records out 1 byte (1 B) copied, 8.3075e-05 s, 12.0 kB/s $ ls -l foo2 -rw-r--r-- 1 grante users 10485760 Sep 29 15:35 foo2 $ du -s foo2 16 foo2 -- Grant Edwards grant.b.edwards Yow! Please come home with at me ... I have Tylenol!! gmail.com From nagle at animats.com Wed Sep 29 16:41:15 2010 From: nagle at animats.com (John Nagle) Date: Wed, 29 Sep 2010 13:41:15 -0700 Subject: Certificate validation with HTTPSConnection In-Reply-To: References: Message-ID: <4CA3A46B.4080006@animats.com> On 9/29/2010 1:18 PM, Ned Deily wrote: > In article, > Velko Ivanov wrote: > >> I've always wandered why HTTPSConnection does not validate >> certificates? >> >> It is fairly simple to use the SSL socket's validation: > [...] > > Perhaps you can write up your example as a documentation patch to the > http.client documentation page and submit it to the Python bug tracker > (http://bugs.python.org/). We've been through this. Too many times. http://bugs.python.org/issue1114345 (2005: Broken in Python 2.2, eventually fixed) http://www.justinsamuel.com/2008/12/25/the-importance-of-validating-ssl-certificates/ (2008: Why this matters) http://www.mail-archive.com/python-list at python.org/msg281736.html (2010: Broken in new Python 2.6 SSL module.) http://bugs.python.org/issue1589 (2010: Developer "Bill Jansen" in denial, others disagree. Currently being debated. See bug tracker.) The really stupid thing about the current SSL module is that it accepts a file of root certificates as a parameter, but ignores it. So it creates the illusion of security without providing it. As someone pointed out, the current SSL module "lets you talk encrypted to your attacker". John Nagle From xahlee at gmail.com Wed Sep 29 16:46:08 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 29 Sep 2010 13:46:08 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> Message-ID: <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> On Sep 29, 11:02?am, namekuseijin wrote: > On 28 set, 19:38, Xah Lee wrote: > > > ? ?list comprehension? is a very bad jargon; thus harmful to > > functional programing or programing in general. Being a bad jargon, it > > encourage mis-communication, mis-understanding. > > I disagree: ?it is a quite intuitive term to describe what the > expression does. what's your basis in saying that ?list comprehension? is intuitive? any statics, survery, research, references you have to cite? to put this in context, are you saying that lambda, is also intuitive? ?let? is intuitive? ?for? is intuitive? ?when? is intuitive? I mean, give your evaluation of some common computer language termilogies, and tell us which you think are good and which are bad, so we have some context to judge your claim. For example, let us know, in your view, how good are terms: currying, lisp1 lisp2, tail recursion, closure, subroutine, command, object. Or, perhaps expound on the comparative merits and meaning on the terms module vs package vs add-on vs library. I would like to see your view on this with at least few paragraphs of analysis on each. If you, say, write a essay that's at least 1k words on this topic, then we all can make some judgement of your familiarity and understanding in this area. Also, ?being intuitive? is not the only aspect to consider whether a term is good or bad. For example, emacs's uses the term ?frame?. It's quite intuitive, because frame is a common english word, everyone understands. You know, door frame, window frame, picture frame, are all analogous to emacs's ?frame? on a computer. However, by some turn of history, in computer software we call such as ?window? now, and by happance the term ?window? also has a technical meaning in emacs, what we call ?split window? or ?pane? today. So, in emacs, the term ?frame? and ?window? is confusing, because emacs's ?frame? is what we call ?window?, while emacs's ?window? is what me might call a pane of a split window. So here, is a example, that even when a term is intuitive, it can still be bad. as another example, common understanding by the target group the term is to be used is also a important aspect. For example, the term ?lambda?, which is a name of greek char, does not convey well what we use it for. The word's meaning by itself has no connection to the concept of function. The char happens to be used by a logician as a shorthand notation in his study of what's called ?lambda calculus? (the ?calculus? part is basically 1700's terminology for a systematic science, especially related to mechanical reasoning). However, the term ?lambda? used in this way in computer science and programing has been long and wide, around 50 years in recent history (and more back if we trace origins). So, because of established use, here it may decrease the level of what we might think of it as a bad jargon, by the fact that it already become a standard usage or understanding. Even still, note that just because a term has establish use, if the term itself is very bad in many other aspects, it may still warrant a need for change. For one example of a reason, the argon will be a learning curve problem for all new generations. You see, when you judge a terminology, you have to consider many aspects. It is quite involved. When judging a jargon, some question you might ask are: ? does the jargon convey its meaning by the word itself? (i.e. whether the jargon as a word is effective in communication) ? how long has been the jargon in use? ? do people in the community understand the jargon? (e.g. what percentage) each of these sample questions can get quite involved. For example, it calls for expertise in linguistics (many sub-fields are relevant: pragmatics, history of language, etymology), practical experience in the field (programing or computer science), educational expertise (e.g. educators, professors, programing book authors/teachers), scientific survey, social science of communication... also, you may not know, there are bodies of professional scientists who work on terminologies for publication. It is not something like ?O think it's good, becus it is intuitive to me.?. I wrote about 14 essays on various jargons in past decade. You can find them on my site. i removed your arguments on other parts about ?list comprehension?, because i didn't find them valuable. (barely read them) However, i appreciate your inputs on the ?do? in Scheme lisp has a functional usage, and some other misc chat info from the beginning of this thread on comp.lang.lisp. Xah ? xahlee.org ? From ian.g.kelly at gmail.com Wed Sep 29 17:48:06 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 29 Sep 2010 15:48:06 -0600 Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] In-Reply-To: <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> Message-ID: On Wed, Sep 29, 2010 at 2:46 PM, Xah Lee wrote: > what's your basis in saying that ?list comprehension? is intuitive? > > any statics, survery, research, references you have to cite? > > to put this in context, are you saying that lambda, is also intuitive? > ?let? is intuitive? ?for? is intuitive? ?when? is intuitive? I mean, > give your evaluation of some common computer language termilogies, and > tell us which you think are good and which are bad, so we have some > context to judge your claim. > > For example, let us know, in your view, how good are terms: currying, > lisp1 lisp2, tail recursion, closure, subroutine, command, object. Or, > perhaps expound on the comparative merits and meaning on the terms > module vs package vs add-on vs library. I would like to see your view > on this with at least few paragraphs of analysis on each. If you, say, > write a essay that's at least 1k words on this topic, then we all can > make some judgement of your familiarity and understanding in this > area. > Have you actually written an essay on this topic of the sort that you are requesting here? I googled your site, but all I could find was your Perl-Python tutorial in which you simply stated that "This construct has acquired a [sic] incomprehensible name 'list comprehension' in computing industry and academia." The obvious pun aside, I don't understand why you find the name to be incomprehensible. All it means is that the list is being defined by comprehension (i.e. intension) in the logical sense, as opposed to the more common extensive definition (e.g. myList = [1, 2, 3]). The suggestion that this nomenclature is any more obscure than "lambda", in either origin or industry, is dubious to me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rog at pynguins.com Wed Sep 29 17:50:56 2010 From: rog at pynguins.com (Rog) Date: Wed, 29 Sep 2010 22:50:56 +0100 Subject: list problem... References: <4ca32e49$0$28654$c3e8da3@news.astraweb.com> <0e563359-c2fd-4fbc-808b-02cb2e483ad5@l20g2000yqm.googlegroups.com> Message-ID: On Wed, 29 Sep 2010 05:52:32 -0700, bruno.desthuilliers at gmail.com wrote: > On 29 sep, 14:17, Steven D'Aprano > wrote: >> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: >> > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: >> >> >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >> >>> Hi all, >> >>> Have been grappling with a list problem for hours... a = [2, 3, 4, >> >>> 5,.....] >> >>> b = [4, 8, 2, 6,.....] >> >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] >> >>> and b[2] is present. >> >>> I have tried sets, zip etc with no success. I am tackling Euler >> >>> projects with Python 3.1, with minimal knowledge, and having to >> >>> tackle the language as I progress. Enjoyable frustration ?:) >> >> >> I'm not clear on what your actual problem is, could you restate it? >> >> >> It sounds like you want to copy the ith element out of a and b into >> >> some other list- call it c- when the (i+2)th element meets some >> >> condition. What's the condition? >> >> >> Geremy Condra >> >> > The condition is that the i-th element is inverted, but not equal. eg >> > 4,2 - 2,4 , 34,5 - 5,34 etc. >> > Hope that is clearer. >> >> Clear as mud. >> >> Perhaps you should given an example. Given input >> >> a = [2, 3, 4, 5, 6, 7] >> b = [4, 8, 2, 6, 10, 42] >> >> what output are you expecting, > > AFAICT, the OP expects [2, 4] in this case, but it's not clear what he'd > expect for let's say: > > a = [2, 3, 21, 4, 5, 6, 7] > b = [4, 8, 22, 2, 6, 10, 42] > > (the 'reversed' pair is at i+3, not i+2) > > or > > a = [0, 2, 3, 4, 5, 6, 7] > b = [3, 4, 8, 2, 6, 10, 42] > > (the first pair is at pos 1, not 0) > > or > > a = [2, 3, 4, 8, 6, 7] > b = [4, 8, 2, 3, 10, 42] > > (there's a second 'non-reversed/reversed' match at positions resp. 1 & 3) It is true that I would have needed any 'non-reversed/reversed' pairs, these would have been the amicable pairs I was looking for. The method to recognise them eluded me. Eyes are not good enough :) I have now joined Python-List and will follow the correct route. I have used a method suggested that has made the problem redundant, though it will bug me from now on. g = [] def divsum(n): return sum(i for i in range(1, n) if not n % i) for x in range(10000, 2, -1): c = divsum(x) v = divsum(c) if v == x and v != c: g.append(divsum(x)) else: continue print(sum(g)) -- Rog http://www.rog.pynguins.com From rNOSPAMon at flownet.com Wed Sep 29 18:02:43 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 15:02:43 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> Message-ID: In article <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1 at k22g2000prb.googlegroups.com>, Squeamizh wrote: > On Sep 27, 10:46?am, namekuseijin wrote: > > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > > > > > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > > wrote: > > > > RG writes: > > > > > In article > > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, > > > > > ?TheFlyingDutchman wrote: > > > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > > >> > This might have been mentioned here before, but I just came across > > > > >> > it: a > > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get built in > > > > >> > dynamically-typed languages. ?It echoes things we've all said > > > > >> > here, but > > > > >> > I think it's interesting because it describes a conversion > > > > >> > experience: > > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > > > >> > -- Scott > > > > > > >> If you are writing a function to determine the maximum of two > > > > >> numbers > > > > >> passed as arguents in a dynamic typed language, what is the normal > > > > >> procedure used by Eckel and others to handle someone passing in > > > > >> invalid values - such as a file handle for one varible and an array > > > > >> for the other? > > > > > > > The normal procedure is to hit such a person over the head with a > > > > > stick > > > > > and shout "FOO". > > > > > > Moreover, the functions returning the maximum may be able to work on > > > > non-numbers, as long as they're comparable. ?What's more, there are > > > > numbers that are NOT comparable by the operator you're thinking about!. > > > > > > So to implement your specifications, that function would have to be > > > > implemented for example as: > > > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > > (defmethod lessp ((x complex) (y complex)) > > > > ? (or (< (real-part x) (real-part y)) > > > > ? ? ? (and (= (real-part x) (real-part y)) > > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > > > (defun maximum (a b) > > > > ? (if (lessp a b) b a)) > > > > > > And then the client of that function could very well add methods: > > > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > > > and call: > > > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > > > and who are you to forbid it!? > > > > > > -- > > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? > > > > ?http://www.informatimago.com/-Hidequoted text - > > > > > > - Show quoted text - > > > > > in C I can have a function maximum(int a, int b) that will always > > > work. Never blow up, and never give an invalid answer. If someone > > > tries to call it incorrectly it is a compile error. > > > In a dynamic typed language maximum(a, b) can be called with incorrect > > > datatypes. Even if I make it so it can handle many types as you did > > > above, it could still be inadvertantly called with a file handle for a > > > parameter or some other type not provided for. So does Eckel and > > > others, when they are writing their dynamically typed code advocate > > > just letting the function blow up or give a bogus answer, or do they > > > check for valid types passed? If they are checking for valid types it > > > would seem that any benefits gained by not specifying type are lost by > > > checking for type. And if they don't check for type it would seem that > > > their code's error handling is poor. > > > > that is a lie. > > > > Compilation only makes sure that values provided at compilation-time > > are of the right datatype. > > > > What happens though is that in the real world, pretty much all > > computation depends on user provided values at runtime. ?See where are > > we heading? > > > > this works at compilation time without warnings: > > int m=numbermax( 2, 6 ); > > > > this too: > > int a, b, m; > > scanf( "%d", &a ); > > scanf( "%d", &b ); > > m=numbermax( a, b ); > > > > no compiler issues, but will not work just as much as in python if > > user provides "foo" and "bar" for a and b... fail. > > > > What you do if you're feeling insecure and paranoid? ?Just what > > dynamically typed languages do: ?add runtime checks. ?Unit tests are > > great to assert those. > > > > Fact is: ?almost all user data from the external words comes into > > programs as strings. ?No typesystem or compiler handles this fact all > > that graceful... > > I disagree with your conclusion. Sure, the data was textual when it > was initially read by the program, but that should only be relevant to > the input processing code. The data is likely converted to some > internal representation immediately after it is read and validated, > and in a sanely-designed program, it maintains this representation > throughout its life time. If the structure of some data needs to > change during development, the compiler of a statically-typed language > will automatically tell you about any client code that was not updated > to account for the change. Dynamically typed languages do not provide > this assurance. This is a red herring. You don't have to invoke run-time input to demonstrate bugs in a statically typed language that are not caught by the compiler. For example: [ron at mighty:~]$ cat foo.c #include int maximum(int a, int b) { return (a > b ? a : b); } int foo(int x) { return 9223372036854775807+x; } int main () { printf("%d\n", maximum(foo(1), 1)); return 0; } [ron at mighty:~]$ gcc -Wall foo.c [ron at mighty:~]$ ./a.out 1 Even simple arithmetic is Turing-complete, so catching all type-related errors at compile time would entail solving the halting problem. rg From hidura at gmail.com Wed Sep 29 18:09:40 2010 From: hidura at gmail.com (Hidura) Date: Wed, 29 Sep 2010 18:09:40 -0400 Subject: Example or recomendation of a webserver In-Reply-To: References: <87r5gcomkr.fsf@web.de> Message-ID: I use Python3.1, TurboGears, webOb, CherryPy and the others don' t work on Python 3, please somebody recomend me a web framework for Python3.1 I AM DESPERATE On Wed, Sep 29, 2010 at 6:08 PM, Hidura wrote: > I use Python3.1, TurboGears, webOb, CherryPy and the others don' t work on > Python 3, please somebody recomend me a web framework for Python3.1 I AM > DESPERATE > > On Wed, Sep 29, 2010 at 6:45 AM, Diez B. Roggisch wrote: > >> Hidura writes: >> >> > I am working on a web project written on Py3k and using mod_wsgi on >> > the Apache that have to recibes the request client via a xml structure >> > and i am facing a lot of troubles with the upload files mainly because >> > i can' t see where they are, so i' ve decide to write my own web >> > server-django and the others doen' t work for my propouse-, what you >> > recomend me for start that? >> >> not doing it. Reading the HTTP-RFC and the WSGI-PEP. And trying >> >> print environ["wsgi.input"].read() >> >> inside your wsgi-script. Then, use webob to wrap the whole WSGI-stuff to >> have at least a minimum of sensible abstraction. >> >> Or simply use Django or TurboGears2, follow the advices in their docs on >> how to depoly them using mod_wsgi, and be happy. >> >> Diez >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Diego I. Hidalgo D. > -- Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From squeamz at hotmail.com Wed Sep 29 18:11:18 2010 From: squeamz at hotmail.com (Squeamizh) Date: Wed, 29 Sep 2010 15:11:18 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> Message-ID: <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> On Sep 29, 3:02?pm, RG wrote: > In article > <996bd4e6-37ff-4a55-8db5-6e7574fbd... at k22g2000prb.googlegroups.com>, > > > > > > ?Squeamizh wrote: > > On Sep 27, 10:46?am, namekuseijin wrote: > > > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > > > wrote: > > > > > RG writes: > > > > > > In article > > > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, > > > > > > ?TheFlyingDutchman wrote: > > > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > > > >> > This might have been mentioned here before, but I just came across > > > > > >> > it: a > > > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get built in > > > > > >> > dynamically-typed languages. ?It echoes things we've all said > > > > > >> > here, but > > > > > >> > I think it's interesting because it describes a conversion > > > > > >> > experience: > > > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > > > >> > -- Scott > > > > > > >> If you are writing a function to determine the maximum of two > > > > > >> numbers > > > > > >> passed as arguents in a dynamic typed language, what is the normal > > > > > >> procedure used by Eckel and others to handle someone passing in > > > > > >> invalid values - such as a file handle for one varible and an array > > > > > >> for the other? > > > > > > > The normal procedure is to hit such a person over the head with a > > > > > > stick > > > > > > and shout "FOO". > > > > > > Moreover, the functions returning the maximum may be able to work on > > > > > non-numbers, as long as they're comparable. ?What's more, there are > > > > > numbers that are NOT comparable by the operator you're thinking about!. > > > > > > So to implement your specifications, that function would have to be > > > > > implemented for example as: > > > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > > > (defmethod lessp ((x complex) (y complex)) > > > > > ? (or (< (real-part x) (real-part y)) > > > > > ? ? ? (and (= (real-part x) (real-part y)) > > > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > > > (defun maximum (a b) > > > > > ? (if (lessp a b) b a)) > > > > > > And then the client of that function could very well add methods: > > > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > > > and call: > > > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > > > and who are you to forbid it!? > > > > > > -- > > > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? > > > > > ?http://www.informatimago.com/-Hidequotedtext - > > > > > > - Show quoted text - > > > > > in C I can have a function maximum(int a, int b) that will always > > > > work. Never blow up, and never give an invalid answer. If someone > > > > tries to call it incorrectly it is a compile error. > > > > In a dynamic typed language maximum(a, b) can be called with incorrect > > > > datatypes. Even if I make it so it can handle many types as you did > > > > above, it could still be inadvertantly called with a file handle for a > > > > parameter or some other type not provided for. So does Eckel and > > > > others, when they are writing their dynamically typed code advocate > > > > just letting the function blow up or give a bogus answer, or do they > > > > check for valid types passed? If they are checking for valid types it > > > > would seem that any benefits gained by not specifying type are lost by > > > > checking for type. And if they don't check for type it would seem that > > > > their code's error handling is poor. > > > > that is a lie. > > > > Compilation only makes sure that values provided at compilation-time > > > are of the right datatype. > > > > What happens though is that in the real world, pretty much all > > > computation depends on user provided values at runtime. ?See where are > > > we heading? > > > > this works at compilation time without warnings: > > > int m=numbermax( 2, 6 ); > > > > this too: > > > int a, b, m; > > > scanf( "%d", &a ); > > > scanf( "%d", &b ); > > > m=numbermax( a, b ); > > > > no compiler issues, but will not work just as much as in python if > > > user provides "foo" and "bar" for a and b... fail. > > > > What you do if you're feeling insecure and paranoid? ?Just what > > > dynamically typed languages do: ?add runtime checks. ?Unit tests are > > > great to assert those. > > > > Fact is: ?almost all user data from the external words comes into > > > programs as strings. ?No typesystem or compiler handles this fact all > > > that graceful... > > > I disagree with your conclusion. ?Sure, the data was textual when it > > was initially read by the program, but that should only be relevant to > > the input processing code. ?The data is likely converted to some > > internal representation immediately after it is read and validated, > > and in a sanely-designed program, it maintains this representation > > throughout its life time. ?If the structure of some data needs to > > change during development, the compiler of a statically-typed language > > will automatically tell you about any client code that was not updated > > to account for the change. ?Dynamically typed languages do not provide > > this assurance. > > This is a red herring. ?You don't have to invoke run-time input to > demonstrate bugs in a statically typed language that are not caught by > the compiler. ?For example: > > [ron at mighty:~]$ cat foo.c > #include > > int maximum(int a, int b) { > ? return (a > b ? a : b); > > } > > int foo(int x) { return 9223372036854775807+x; } > > int main () { > ? printf("%d\n", maximum(foo(1), 1)); > ? return 0;} > > [ron at mighty:~]$ gcc -Wall foo.c > [ron at mighty:~]$ ./a.out > 1 > > Even simple arithmetic is Turing-complete, so catching all type-related > errors at compile time would entail solving the halting problem. > > rg In short, static typing doesn't solve all conceivable problems. We are all aware that there is no perfect software development process or tool set. I'm interested in minimizing the number of problems I run into during development, and the number of bugs that are in the finished product. My opinion is that static typed languages are better at this for large projects, for the reasons I stated in my previous post. From rNOSPAMon at flownet.com Wed Sep 29 18:14:51 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 15:14:51 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, Squeamizh wrote: > On Sep 29, 3:02?pm, RG wrote: > > In article > > <996bd4e6-37ff-4a55-8db5-6e7574fbd... at k22g2000prb.googlegroups.com>, > > > > > > > > > > > > ?Squeamizh wrote: > > > On Sep 27, 10:46?am, namekuseijin wrote: > > > > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > > > > wrote: > > > > > > RG writes: > > > > > > > In article > > > > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com > > > > > > > >, > > > > > > > ?TheFlyingDutchman wrote: > > > > > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > > > > >> > This might have been mentioned here before, but I just came > > > > > > >> > across > > > > > > >> > it: a > > > > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get > > > > > > >> > built in > > > > > > >> > dynamically-typed languages. ?It echoes things we've all said > > > > > > >> > here, but > > > > > > >> > I think it's interesting because it describes a conversion > > > > > > >> > experience: > > > > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > > > > > >> > -- Scott > > > > > > > > >> If you are writing a function to determine the maximum of two > > > > > > >> numbers > > > > > > >> passed as arguents in a dynamic typed language, what is the > > > > > > >> normal > > > > > > >> procedure used by Eckel and others to handle someone passing in > > > > > > >> invalid values - such as a file handle for one varible and an > > > > > > >> array > > > > > > >> for the other? > > > > > > > > > The normal procedure is to hit such a person over the head with a > > > > > > > stick > > > > > > > and shout "FOO". > > > > > > > > Moreover, the functions returning the maximum may be able to work > > > > > > on > > > > > > non-numbers, as long as they're comparable. ?What's more, there are > > > > > > numbers that are NOT comparable by the operator you're thinking > > > > > > about!. > > > > > > > > So to implement your specifications, that function would have to be > > > > > > implemented for example as: > > > > > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > > > > (defmethod lessp ((x complex) (y complex)) > > > > > > ? (or (< (real-part x) (real-part y)) > > > > > > ? ? ? (and (= (real-part x) (real-part y)) > > > > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > > > > > (defun maximum (a b) > > > > > > ? (if (lessp a b) b a)) > > > > > > > > And then the client of that function could very well add methods: > > > > > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > > > > > and call: > > > > > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > > > > > and who are you to forbid it!? > > > > > > > > -- > > > > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? > > > > > > ?http://www.informatimago.com/-Hidequotedtext - > > > > > > > > - Show quoted text - > > > > > > > in C I can have a function maximum(int a, int b) that will always > > > > > work. Never blow up, and never give an invalid answer. If someone > > > > > tries to call it incorrectly it is a compile error. > > > > > In a dynamic typed language maximum(a, b) can be called with > > > > > incorrect > > > > > datatypes. Even if I make it so it can handle many types as you did > > > > > above, it could still be inadvertantly called with a file handle for > > > > > a > > > > > parameter or some other type not provided for. So does Eckel and > > > > > others, when they are writing their dynamically typed code advocate > > > > > just letting the function blow up or give a bogus answer, or do they > > > > > check for valid types passed? If they are checking for valid types it > > > > > would seem that any benefits gained by not specifying type are lost > > > > > by > > > > > checking for type. And if they don't check for type it would seem > > > > > that > > > > > their code's error handling is poor. > > > > > > that is a lie. > > > > > > Compilation only makes sure that values provided at compilation-time > > > > are of the right datatype. > > > > > > What happens though is that in the real world, pretty much all > > > > computation depends on user provided values at runtime. ?See where are > > > > we heading? > > > > > > this works at compilation time without warnings: > > > > int m=numbermax( 2, 6 ); > > > > > > this too: > > > > int a, b, m; > > > > scanf( "%d", &a ); > > > > scanf( "%d", &b ); > > > > m=numbermax( a, b ); > > > > > > no compiler issues, but will not work just as much as in python if > > > > user provides "foo" and "bar" for a and b... fail. > > > > > > What you do if you're feeling insecure and paranoid? ?Just what > > > > dynamically typed languages do: ?add runtime checks. ?Unit tests are > > > > great to assert those. > > > > > > Fact is: ?almost all user data from the external words comes into > > > > programs as strings. ?No typesystem or compiler handles this fact all > > > > that graceful... > > > > > I disagree with your conclusion. ?Sure, the data was textual when it > > > was initially read by the program, but that should only be relevant to > > > the input processing code. ?The data is likely converted to some > > > internal representation immediately after it is read and validated, > > > and in a sanely-designed program, it maintains this representation > > > throughout its life time. ?If the structure of some data needs to > > > change during development, the compiler of a statically-typed language > > > will automatically tell you about any client code that was not updated > > > to account for the change. ?Dynamically typed languages do not provide > > > this assurance. > > > > This is a red herring. ?You don't have to invoke run-time input to > > demonstrate bugs in a statically typed language that are not caught by > > the compiler. ?For example: > > > > [ron at mighty:~]$ cat foo.c > > #include > > > > int maximum(int a, int b) { > > ? return (a > b ? a : b); > > > > } > > > > int foo(int x) { return 9223372036854775807+x; } > > > > int main () { > > ? printf("%d\n", maximum(foo(1), 1)); > > ? return 0;} > > > > [ron at mighty:~]$ gcc -Wall foo.c > > [ron at mighty:~]$ ./a.out > > 1 > > > > Even simple arithmetic is Turing-complete, so catching all type-related > > errors at compile time would entail solving the halting problem. > > > > rg > > In short, static typing doesn't solve all conceivable problems. More specifically, the claim made above: > in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. is false. And it is not necessary to invoke the vagaries of run-time input to demonstrate that it is false. > We are all aware that there is no perfect software development process > or tool set. I'm interested in minimizing the number of problems I > run into during development, and the number of bugs that are in the > finished product. My opinion is that static typed languages are > better at this for large projects, for the reasons I stated in my > previous post. More power to you. What are you doing here on cll then? rg From tar at sevak.isi.edu Wed Sep 29 18:19:08 2010 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 29 Sep 2010 15:19:08 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: > > More power to you. What are you doing here on cll then? This thread is massively cross-posted. -- Thomas A. Russ, USC/Information Sciences Institute From nad at acm.org Wed Sep 29 18:24:01 2010 From: nad at acm.org (Ned Deily) Date: Wed, 29 Sep 2010 15:24:01 -0700 Subject: Certificate validation with HTTPSConnection References: <4CA3A46B.4080006@animats.com> Message-ID: In article <4CA3A46B.4080006 at animats.com>, John Nagle wrote: > We've been through this. Too many times. > > http://bugs.python.org/issue1114345 > (2005: Broken in Python 2.2, eventually fixed) > > http://www.justinsamuel.com/2008/12/25/the-importance-of-validating-ssl-certif > icates/ > (2008: Why this matters) > > http://www.mail-archive.com/python-list at python.org/msg281736.html > (2010: Broken in new Python 2.6 SSL module.) > > http://bugs.python.org/issue1589 > (2010: Developer "Bill Jansen" in denial, others disagree. > Currently being debated. See bug tracker.) > > The really stupid thing about the current SSL module is that it > accepts a file of root certificates as a parameter, but ignores it. > So it creates the illusion of security without providing it. > As someone pointed out, the current SSL module "lets you talk > encrypted to your attacker". I'll just note in passing that Issue1589 is being discussed again. Feel free to contribute. -- Ned Deily, nad at acm.org From python at mrabarnett.plus.com Wed Sep 29 18:34:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 23:34:22 +0100 Subject: utf-8 and ctypes In-Reply-To: References: Message-ID: <4CA3BEEE.2030005@mrabarnett.plus.com> On 29/09/2010 19:33, Brendan Miller wrote: > 2010/9/29 Lawrence D'Oliveiro: >> In message, Brendan >> Miller wrote: >> >>> It seems that characters not in the ascii subset of UTF-8 are >>> discarded by c_char_p during the conversion ... >> >> Not a chance. >> >>> ... or at least they don't print out when I go to print the string. >> >> So it seems there?s a problem on the printing side. What happens when you >> construct a UTF-8-encoded string directly in Python and try printing it the >> same way? > > Doing this seems to confirm something is broken in ctypes w.r.t. UTF-8... > > if I enter: > str = "???????" > > Then: > print str > ??????? > > However, when I create a string buffer, pass it into my c++ code, and > write the same UTF-8 string into it, python seems to discard pretty > much all the text. The same code works for pure ascii strings. > > Python code: > _std_string_size = _lib_mbxclient.std_string_size > _std_string_size.restype = c_long > _std_string_size.argtypes = [c_void_p] > > _std_string_copy = _lib_mbxclient.std_string_copy > _std_string_copy.restype = None > _std_string_copy.argtypes = [c_void_p, POINTER(c_char)] > > # This function works for ascii, but breaks on strings with UTF-8! > def std_string_to_string(str_ptr): > buf = create_string_buffer(_std_string_size(str_ptr)) > _std_string_copy(str_ptr, buf) > return buf.raw > > C++ code: > > extern "C" > long std_string_size(string* str) > { > return str->size(); > } > > extern "C" > void std_string_copy(string* str, char* buf) > { > std::copy(str->begin(), str->end(), buf); > } It might have something to do with the character encoding of your source files. Also, try printing out the character codes of the string and the size of the string's character in the C++ code. From solipsis at pitrou.net Wed Sep 29 18:51:05 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 30 Sep 2010 00:51:05 +0200 Subject: PyCObject & malloc creating memory leak References: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> Message-ID: <20100930005105.767d0f58@pitrou.net> On Wed, 29 Sep 2010 06:50:05 -0700 (PDT) Tom Conneely wrote: > > My original plan was to have the data processing and data acquisition > functions running in separate processes, with a multiprocessing.Queue > for passing the raw data packets. The raw data is read in as a char*, > with a non constant length, hence I have allocated memory using > PyMem_Malloc and I am returning from the acquisition function a > PyCObject containing a pointer to this char* buffer, along with a > destructor. That sounds overkill, and I also wonder how you plan to pass that object in a multiprocessing Queue (which relies on objects being pickleable). Why don't you simply create a PyString object instead? > So if I call these functions in a loop, e.g. The following will > generate ~10GB of data > > x = MyClass() > for i in xrange(0, 10 * 2**20): > c = x.malloc_buffer() > x.retrieve_buffer(c) > > All my memory disapears, until python crashes with a MemoryError. By > placing a print in the destructor function I know it's being called, > however it's not actually freeing the memory. So in short, what am I > doing wrong? Python returns memory to the OS by calling free(). Not all OSes actually relinquish memory when free() is called; some will simply set it aside for the next allocation. Another possible (and related) issue is memory fragmentation. Again, it depends on the memory allocator. Regards Antoine. From solipsis at pitrou.net Wed Sep 29 18:51:55 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 30 Sep 2010 00:51:55 +0200 Subject: Certificate validation with HTTPSConnection References: <4CA3A46B.4080006@animats.com> Message-ID: <20100930005155.0727523d@pitrou.net> On Wed, 29 Sep 2010 13:41:15 -0700 John Nagle wrote: > > The really stupid thing about the current SSL module is that it > accepts a file of root certificates as a parameter, but ignores it. That's not true. You have to pass CERT_OPTIONAL or CERT_REQUIRED as a parameter (CERT_NONE is though). Regards Antoine. From kst-u at mib.org Wed Sep 29 19:07:19 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 16:07:19 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: > In article > <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, > Squeamizh wrote: >> On Sep 29, 3:02?pm, RG wrote: [...] >> > This is a red herring. ?You don't have to invoke run-time input to >> > demonstrate bugs in a statically typed language that are not caught by >> > the compiler. ?For example: >> > >> > [ron at mighty:~]$ cat foo.c >> > #include >> > >> > int maximum(int a, int b) { >> > ? return (a > b ? a : b); >> > >> > } >> > >> > int foo(int x) { return 9223372036854775807+x; } >> > >> > int main () { >> > ? printf("%d\n", maximum(foo(1), 1)); >> > ? return 0;} >> > >> > [ron at mighty:~]$ gcc -Wall foo.c >> > [ron at mighty:~]$ ./a.out >> > 1 >> > >> > Even simple arithmetic is Turing-complete, so catching all type-related >> > errors at compile time would entail solving the halting problem. >> > >> > rg >> >> In short, static typing doesn't solve all conceivable problems. > > More specifically, the claim made above: > >> in C I can have a function maximum(int a, int b) that will always >> work. Never blow up, and never give an invalid answer. > > is false. And it is not necessary to invoke the vagaries of run-time > input to demonstrate that it is false. But the above maximum() function does exactly that. The program's behavior happens to be undefined or implementation-defined for reasons unrelated to the maximum() function. Depending on the range of type int on the given system, either the behavior of the addition in foo() is undefined (because it overflows), or the implicit conversion of the result to int either yields an implementation-defined result or (in C99) raises an implementation-defined signal; the latter can lead to undefined behavior. Since 9223372036854775807 is 2**63-1, what *typically* happens is that the addition yields the value 0, but the C language doesn't require that particular result. You then call maximum with arguments 0 and 1, and it quite correctly returns 1. >> We are all aware that there is no perfect software development process >> or tool set. I'm interested in minimizing the number of problems I >> run into during development, and the number of bugs that are in the >> finished product. My opinion is that static typed languages are >> better at this for large projects, for the reasons I stated in my >> previous post. > > More power to you. What are you doing here on cll then? This thread is cross-posted to several newsgroups, including comp.lang.c. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From pjb at informatimago.com Wed Sep 29 19:17:39 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 01:17:39 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <87k4m4nnqk.fsf@kuiper.lan.informatimago.com> Squeamizh writes: > In short, static typing doesn't solve all conceivable problems. > > We are all aware that there is no perfect software development process > or tool set. I'm interested in minimizing the number of problems I > run into during development, and the number of bugs that are in the > finished product. My opinion is that static typed languages are > better at this for large projects, for the reasons I stated in my > previous post. Our experience is that a garbage collector and native bignums are much more important to minimize the number of problems we run into during development and the number of bugs that are in the finished products. -- __Pascal Bourguignon__ http://www.informatimago.com/ From rNOSPAMon at flownet.com Wed Sep 29 19:47:38 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 16:47:38 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > RG writes: > > In article > > <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, > > Squeamizh wrote: > >> On Sep 29, 3:02?pm, RG wrote: > [...] > >> > This is a red herring. ?You don't have to invoke run-time input to > >> > demonstrate bugs in a statically typed language that are not caught by > >> > the compiler. ?For example: > >> > > >> > [ron at mighty:~]$ cat foo.c > >> > #include > >> > > >> > int maximum(int a, int b) { > >> > ? return (a > b ? a : b); > >> > > >> > } > >> > > >> > int foo(int x) { return 9223372036854775807+x; } > >> > > >> > int main () { > >> > ? printf("%d\n", maximum(foo(1), 1)); > >> > ? return 0;} > >> > > >> > [ron at mighty:~]$ gcc -Wall foo.c > >> > [ron at mighty:~]$ ./a.out > >> > 1 > >> > > >> > Even simple arithmetic is Turing-complete, so catching all type-related > >> > errors at compile time would entail solving the halting problem. > >> > > >> > rg > >> > >> In short, static typing doesn't solve all conceivable problems. > > > > More specifically, the claim made above: > > > >> in C I can have a function maximum(int a, int b) that will always > >> work. Never blow up, and never give an invalid answer. > > > > is false. And it is not necessary to invoke the vagaries of run-time > > input to demonstrate that it is false. > > But the above maximum() function does exactly that. The program's > behavior happens to be undefined or implementation-defined for reasons > unrelated to the maximum() function. > > Depending on the range of type int on the given system, either the > behavior of the addition in foo() is undefined (because it overflows), > or the implicit conversion of the result to int either yields an > implementation-defined result or (in C99) raises an > implementation-defined signal; the latter can lead to undefined > behavior. > > Since 9223372036854775807 is 2**63-1, what *typically* happens is that > the addition yields the value 0, but the C language doesn't require that > particular result. You then call maximum with arguments 0 and 1, and > it quite correctly returns 1. This all hinges on what you consider to be "a function maximum(int a, int b) that ... always work[s] ... [and] never give[s] an invalid answer." But if you don't consider an incorrect answer (according to the rules of arithmetic) to be an invalid answer then the claim becomes vacuous. You could simply ignore the arguments and return 0, and that would meet the criteria. If you try to refine this claim so that it is both correct and non-vacuous you will find that static typing does not do nearly as much for you as most of its adherents think it does. > >> We are all aware that there is no perfect software development process > >> or tool set. I'm interested in minimizing the number of problems I > >> run into during development, and the number of bugs that are in the > >> finished product. My opinion is that static typed languages are > >> better at this for large projects, for the reasons I stated in my > >> previous post. > > > > More power to you. What are you doing here on cll then? > > This thread is cross-posted to several newsgroups, including > comp.lang.c. Ah, so it is. My bad. rg From kst-u at mib.org Wed Sep 29 20:26:38 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 17:26:38 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: > In article , > Keith Thompson wrote: > >> RG writes: >> > In article >> > <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, >> > Squeamizh wrote: >> >> On Sep 29, 3:02?pm, RG wrote: >> [...] >> >> > This is a red herring. ?You don't have to invoke run-time input to >> >> > demonstrate bugs in a statically typed language that are not caught by >> >> > the compiler. ?For example: >> >> > >> >> > [ron at mighty:~]$ cat foo.c >> >> > #include >> >> > >> >> > int maximum(int a, int b) { >> >> > ? return (a > b ? a : b); >> >> > >> >> > } >> >> > >> >> > int foo(int x) { return 9223372036854775807+x; } >> >> > >> >> > int main () { >> >> > ? printf("%d\n", maximum(foo(1), 1)); >> >> > ? return 0;} >> >> > >> >> > [ron at mighty:~]$ gcc -Wall foo.c >> >> > [ron at mighty:~]$ ./a.out >> >> > 1 >> >> > >> >> > Even simple arithmetic is Turing-complete, so catching all type-related >> >> > errors at compile time would entail solving the halting problem. >> >> > >> >> > rg >> >> >> >> In short, static typing doesn't solve all conceivable problems. >> > >> > More specifically, the claim made above: >> > >> >> in C I can have a function maximum(int a, int b) that will always >> >> work. Never blow up, and never give an invalid answer. >> > >> > is false. And it is not necessary to invoke the vagaries of run-time >> > input to demonstrate that it is false. >> >> But the above maximum() function does exactly that. The program's >> behavior happens to be undefined or implementation-defined for reasons >> unrelated to the maximum() function. >> >> Depending on the range of type int on the given system, either the >> behavior of the addition in foo() is undefined (because it overflows), >> or the implicit conversion of the result to int either yields an >> implementation-defined result or (in C99) raises an >> implementation-defined signal; the latter can lead to undefined >> behavior. >> >> Since 9223372036854775807 is 2**63-1, what *typically* happens is that >> the addition yields the value 0, but the C language doesn't require that >> particular result. You then call maximum with arguments 0 and 1, and >> it quite correctly returns 1. > > This all hinges on what you consider to be "a function maximum(int a, > int b) that ... always work[s] ... [and] never give[s] an invalid > answer." int maximum(int a, int b) { return a > b ? a : b; } > But if you don't consider an incorrect answer (according to > the rules of arithmetic) to be an invalid answer then the claim becomes > vacuous. You could simply ignore the arguments and return 0, and that > would meet the criteria. I don't believe it's possible in any language to write a maximum() function that returns a correct result *when given incorrect argument values*. The program (assuming a typical implementation) calls maximum() with arguments 0 and 1. maximum() returns 1. It works. The problem is elsewhere in the program. (And on a hypothetical system with INT_MAX >= 9223372036854775808, the program's entire behavior is well defined and mathematically correct. C requires INT_MAX >= 32767; it can be as large as the implementation chooses. In practice, the largest value I've ever seen for INT_MAX is 9223372036854775807.) > If you try to refine this claim so that it is both correct and > non-vacuous you will find that static typing does not do nearly as much > for you as most of its adherents think it does. Speaking only for myself, I've never claimed that static typing solves all conceivable problems. My point is only about this specific example of a maximum() function. [...] -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From anand.shashwat at gmail.com Wed Sep 29 20:42:56 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 30 Sep 2010 06:12:56 +0530 Subject: list problem... In-Reply-To: References: <4ca32e49$0$28654$c3e8da3@news.astraweb.com> <0e563359-c2fd-4fbc-808b-02cb2e483ad5@l20g2000yqm.googlegroups.com> Message-ID: On Thu, Sep 30, 2010 at 3:20 AM, Rog wrote: > On Wed, 29 Sep 2010 05:52:32 -0700, bruno.desthuilliers at gmail.com wrote: > > > On 29 sep, 14:17, Steven D'Aprano > > > wrote: > >> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > >> > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > >> > >> >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > >> >>> Hi all, > >> >>> Have been grappling with a list problem for hours... a = [2, 3, 4, > >> >>> 5,.....] > >> >>> b = [4, 8, 2, 6,.....] > >> >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] > >> >>> and b[2] is present. > >> >>> I have tried sets, zip etc with no success. I am tackling Euler > >> >>> projects with Python 3.1, with minimal knowledge, and having to > >> >>> tackle the language as I progress. Enjoyable frustration :) > >> > >> >> I'm not clear on what your actual problem is, could you restate it? > >> > >> >> It sounds like you want to copy the ith element out of a and b into > >> >> some other list- call it c- when the (i+2)th element meets some > >> >> condition. What's the condition? > >> > >> >> Geremy Condra > >> > >> > The condition is that the i-th element is inverted, but not equal. eg > >> > 4,2 - 2,4 , 34,5 - 5,34 etc. > >> > Hope that is clearer. > >> > >> Clear as mud. > >> > >> Perhaps you should given an example. Given input > >> > >> a = [2, 3, 4, 5, 6, 7] > >> b = [4, 8, 2, 6, 10, 42] > >> > >> what output are you expecting, > > > > AFAICT, the OP expects [2, 4] in this case, but it's not clear what he'd > > expect for let's say: > > > > a = [2, 3, 21, 4, 5, 6, 7] > > b = [4, 8, 22, 2, 6, 10, 42] > > > > (the 'reversed' pair is at i+3, not i+2) > > > > or > > > > a = [0, 2, 3, 4, 5, 6, 7] > > b = [3, 4, 8, 2, 6, 10, 42] > > > > (the first pair is at pos 1, not 0) > > > > or > > > > a = [2, 3, 4, 8, 6, 7] > > b = [4, 8, 2, 3, 10, 42] > > > > (there's a second 'non-reversed/reversed' match at positions resp. 1 & 3) > > > It is true that I would have needed any 'non-reversed/reversed' pairs, > these would have been the amicable pairs I was looking for. > The method to recognise them eluded me. Eyes are not good enough :) > I have now joined Python-List and will follow the correct route. > I have used a method suggested that has made the problem redundant, > though it will bug me from now on. > > g = [] > > def divsum(n): > return sum(i for i in range(1, n) if not n % i) > You can optimize divsum. Remember that factors exist in pairs except when numbers are squares. Like say 12 have factors = 1, 12, 2, 6, 3, 4 so you can run the loop till sqrt(n) for n since floor(sqrt(n)) = 3 where n = 12 now factors are , (1, n/1), (2, n/2), (3, n/2). for a square number say n = 9, the factors are (1, 3, 12) If you run the loop till sqrt(n) for n since floor(sqrt(n)) = 3 where n = 9 we get the factors as (1, 9), (3, 3) One of the factor will be redundant, so you need to take care of that. > > for x in range(10000, 2, -1): > c = divsum(x) > v = divsum(c) > Can be done as, c, v = divsum(x), divsum(divsum(x)) > if v == x and v != c: > g.append(divsum(x)) > No need for else part, what is the use ? > else: > continue > > print(sum(g)) > You could pack this up as, >>> sum(i for i in range(10000, 0, -2) if divsum(divsum(i)) == i and divsum(i) != i) 31626 > -- > Rog > http://www.rog.pynguins.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve-REMOVE-THIS at cybersource.com.au Wed Sep 29 20:54:36 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 30 Sep 2010 00:54:36 GMT Subject: About __class__ of an int literal References: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> <8739ss4tk6.fsf@xemacs.org> Message-ID: <4ca3dfcc$0$28672$c3e8da3@news.astraweb.com> On Wed, 29 Sep 2010 14:46:18 -0400, Terry Reedy wrote: >> In that sense the user >> should be calling iter(foo) instead of foo.__iter__(), next(foo) >> instead of foo.__next__(), and foo+bar instead of foo.__add__(bar). > > Yes. Guido added iter() and next() to the list of built-in functions, > even though they seem reduncant.. I believe it is his intention that the > use of special names outside of class statements should be fairly rare. Fairly rare but not non-existent. For example, there's nothing wrong with using a callback function of (say) instance.__sub__ instead of lambda b, a=instance: a - b. Not only is the direct call to the method slightly faster, but more importantly it's easier to read and more clear to intent. Admittedly beginners may find instance.__sub__ to be a tad mysterious, but then beginners are likely to find the lambda form with its two arguments and default value mysterious too. > If I remember right, in the old, pre-2.2 system that separated built-in > types and user-written classes, the builtins did not have accessible > special method attributes. Yes, that's correct. But we're talking about Python *now*, not back in the mists of time before new-style classes. Would you argue that users shouldn't use decorators, iterators or closures because Python 2.1 didn't have them? I don't think so. > They are only for customizing user classes. Say "were" rather than "are" and I will agree with you. Say "primarily for" rather than "only" and I will also agree with you. > So one could not have generically written foo.__add__(bar). > Special-method attribute were added to builtins so that they could be > inherited (or replaced) by user-written subclasses, not so that one > could replace normal syntax. Of course one shouldn't prefer seq.__len__() over len(seq). But that's a readability issue, and not because Python implementations are free to change __len__ to something else. If I gave the opposite impression, that was not my intention and I'm sorry for the failure to be more clear. >> Direct >> calls to special-name methods, such as __len__, often indicate that the >> programmer hasn't grasped how those methods are intended to be used in >> Python. > > Right. That fact that *Python* interpreters implement syntax with > special methods is an implementation detail of the *language*. The > importance is that it allow *writers* of new classes to rather easily > imitate built-in classes so that their classes seamlessly plug into the > syntax. If I've understood this paragraph correctly, you're trying to say that since *other languages* that aren't Python are free to implement syntax features using some other mechanism, *Python* developers shouldn't use special methods because they are implementation details. If we're prohibited from using anything which is an implementation detail of "the *language*" (your emphasis), then we can't use *anything*. Yes, special methods are an implementation detail of Python, but only in the same sense that it is an implementation detail of Python that we write this: def f(a, b): x = a + b return math.sqrt(x) rather than this: function f(a, b: integer):float: var x: integer; begin x := a + b; f := sqrt(x) end; -- Steven From squeamz at hotmail.com Wed Sep 29 20:58:23 2010 From: squeamz at hotmail.com (Squeamizh) Date: Wed, 29 Sep 2010 17:58:23 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <1d035a69-dc5f-4321-9ca4-2828fb64a3c8@z34g2000pro.googlegroups.com> On Sep 29, 3:14?pm, RG wrote: > In article > <07f75df3-778d-4e3d-8aa0-fbd4bd108... at k22g2000prb.googlegroups.com>, > > > > > > ?Squeamizh wrote: > > On Sep 29, 3:02?pm, RG wrote: > > > In article > > > <996bd4e6-37ff-4a55-8db5-6e7574fbd... at k22g2000prb.googlegroups.com>, > > > > ?Squeamizh wrote: > > > > On Sep 27, 10:46?am, namekuseijin wrote: > > > > > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > > > > > wrote: > > > > > > > RG writes: > > > > > > > > In article > > > > > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com > > > > > > > > >, > > > > > > > > ?TheFlyingDutchman wrote: > > > > > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > > > > > >> > This might have been mentioned here before, but I just came > > > > > > > >> > across > > > > > > > >> > it: a > > > > > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get > > > > > > > >> > built in > > > > > > > >> > dynamically-typed languages. ?It echoes things we've all said > > > > > > > >> > here, but > > > > > > > >> > I think it's interesting because it describes a conversion > > > > > > > >> > experience: > > > > > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > > > > > >> > -- Scott > > > > > > > > >> If you are writing a function to determine the maximum of two > > > > > > > >> numbers > > > > > > > >> passed as arguents in a dynamic typed language, what is the > > > > > > > >> normal > > > > > > > >> procedure used by Eckel and others to handle someone passing in > > > > > > > >> invalid values - such as a file handle for one varible and an > > > > > > > >> array > > > > > > > >> for the other? > > > > > > > > > The normal procedure is to hit such a person over the head with a > > > > > > > > stick > > > > > > > > and shout "FOO". > > > > > > > > Moreover, the functions returning the maximum may be able to work > > > > > > > on > > > > > > > non-numbers, as long as they're comparable. ?What's more, there are > > > > > > > numbers that are NOT comparable by the operator you're thinking > > > > > > > about!. > > > > > > > > So to implement your specifications, that function would have to be > > > > > > > implemented for example as: > > > > > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > > > > > (defmethod lessp ((x complex) (y complex)) > > > > > > > ? (or (< (real-part x) (real-part y)) > > > > > > > ? ? ? (and (= (real-part x) (real-part y)) > > > > > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > > > > > (defun maximum (a b) > > > > > > > ? (if (lessp a b) b a)) > > > > > > > > And then the client of that function could very well add methods: > > > > > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > > > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > > > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > > > > > and call: > > > > > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > > > > > and who are you to forbid it!? > > > > > > > > -- > > > > > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? > > > > > > > ?http://www.informatimago.com/-Hidequotedtext- > > > > > > > > - Show quoted text - > > > > > > > in C I can have a function maximum(int a, int b) that will always > > > > > > work. Never blow up, and never give an invalid answer. If someone > > > > > > tries to call it incorrectly it is a compile error. > > > > > > In a dynamic typed language maximum(a, b) can be called with > > > > > > incorrect > > > > > > datatypes. Even if I make it so it can handle many types as you did > > > > > > above, it could still be inadvertantly called with a file handle for > > > > > > a > > > > > > parameter or some other type not provided for. So does Eckel and > > > > > > others, when they are writing their dynamically typed code advocate > > > > > > just letting the function blow up or give a bogus answer, or do they > > > > > > check for valid types passed? If they are checking for valid types it > > > > > > would seem that any benefits gained by not specifying type are lost > > > > > > by > > > > > > checking for type. And if they don't check for type it would seem > > > > > > that > > > > > > their code's error handling is poor. > > > > > > that is a lie. > > > > > > Compilation only makes sure that values provided at compilation-time > > > > > are of the right datatype. > > > > > > What happens though is that in the real world, pretty much all > > > > > computation depends on user provided values at runtime. ?See where are > > > > > we heading? > > > > > > this works at compilation time without warnings: > > > > > int m=numbermax( 2, 6 ); > > > > > > this too: > > > > > int a, b, m; > > > > > scanf( "%d", &a ); > > > > > scanf( "%d", &b ); > > > > > m=numbermax( a, b ); > > > > > > no compiler issues, but will not work just as much as in python if > > > > > user provides "foo" and "bar" for a and b... fail. > > > > > > What you do if you're feeling insecure and paranoid? ?Just what > > > > > dynamically typed languages do: ?add runtime checks. ?Unit tests are > > > > > great to assert those. > > > > > > Fact is: ?almost all user data from the external words comes into > > > > > programs as strings. ?No typesystem or compiler handles this fact all > > > > > that graceful... > > > > > I disagree with your conclusion. ?Sure, the data was textual when it > > > > was initially read by the program, but that should only be relevant to > > > > the input processing code. ?The data is likely converted to some > > > > internal representation immediately after it is read and validated, > > > > and in a sanely-designed program, it maintains this representation > > > > throughout its life time. ?If the structure of some data needs to > > > > change during development, the compiler of a statically-typed language > > > > will automatically tell you about any client code that was not updated > > > > to account for the change. ?Dynamically typed languages do not provide > > > > this assurance. > > > > This is a red herring. ?You don't have to invoke run-time input to > > > demonstrate bugs in a statically typed language that are not caught by > > > the compiler. ?For example: > > > > [ron at mighty:~]$ cat foo.c > > > #include > > > > int maximum(int a, int b) { > > > ? return (a > b ? a : b); > > > > } > > > > int foo(int x) { return 9223372036854775807+x; } > > > > int main () { > > > ? printf("%d\n", maximum(foo(1), 1)); > > > ? return 0;} > > > > [ron at mighty:~]$ gcc -Wall foo.c > > > [ron at mighty:~]$ ./a.out > > > 1 > > > > Even simple arithmetic is Turing-complete, so catching all type-related > > > errors at compile time would entail solving the halting problem. > > > > rg > > > In short, static typing doesn't solve all conceivable problems. > > More specifically, the claim made above: > > > in C I can have a function maximum(int a, int b) that will always > > work. Never blow up, and never give an invalid answer. > > is false. ?And it is not necessary to invoke the vagaries of run-time > input to demonstrate that it is false. OK. You finished your post with a reference to the halting problem, which does not help to bolster any practical argument. That is why I summarized your post in the manner I did. I agree that static typed languages do not prevent these types of overflow errors. From rNOSPAMon at flownet.com Wed Sep 29 21:01:02 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 18:01:02 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > RG writes: > > In article , > > Keith Thompson wrote: > > > >> RG writes: > >> > In article > >> > <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, > >> > Squeamizh wrote: > >> >> On Sep 29, 3:02?pm, RG wrote: > >> [...] > >> >> > This is a red herring. ?You don't have to invoke run-time input to > >> >> > demonstrate bugs in a statically typed language that are not caught > >> >> > by > >> >> > the compiler. ?For example: > >> >> > > >> >> > [ron at mighty:~]$ cat foo.c > >> >> > #include > >> >> > > >> >> > int maximum(int a, int b) { > >> >> > ? return (a > b ? a : b); > >> >> > > >> >> > } > >> >> > > >> >> > int foo(int x) { return 9223372036854775807+x; } > >> >> > > >> >> > int main () { > >> >> > ? printf("%d\n", maximum(foo(1), 1)); > >> >> > ? return 0;} > >> >> > > >> >> > [ron at mighty:~]$ gcc -Wall foo.c > >> >> > [ron at mighty:~]$ ./a.out > >> >> > 1 > >> >> > > >> >> > Even simple arithmetic is Turing-complete, so catching all > >> >> > type-related > >> >> > errors at compile time would entail solving the halting problem. > >> >> > > >> >> > rg > >> >> > >> >> In short, static typing doesn't solve all conceivable problems. > >> > > >> > More specifically, the claim made above: > >> > > >> >> in C I can have a function maximum(int a, int b) that will always > >> >> work. Never blow up, and never give an invalid answer. > >> > > >> > is false. And it is not necessary to invoke the vagaries of run-time > >> > input to demonstrate that it is false. > >> > >> But the above maximum() function does exactly that. The program's > >> behavior happens to be undefined or implementation-defined for reasons > >> unrelated to the maximum() function. > >> > >> Depending on the range of type int on the given system, either the > >> behavior of the addition in foo() is undefined (because it overflows), > >> or the implicit conversion of the result to int either yields an > >> implementation-defined result or (in C99) raises an > >> implementation-defined signal; the latter can lead to undefined > >> behavior. > >> > >> Since 9223372036854775807 is 2**63-1, what *typically* happens is that > >> the addition yields the value 0, but the C language doesn't require that > >> particular result. You then call maximum with arguments 0 and 1, and > >> it quite correctly returns 1. > > > > This all hinges on what you consider to be "a function maximum(int a, > > int b) that ... always work[s] ... [and] never give[s] an invalid > > answer." > > int maximum(int a, int b) { return a > b ? a : b; } > > > But if you don't consider an incorrect answer (according to > > the rules of arithmetic) to be an invalid answer then the claim becomes > > vacuous. You could simply ignore the arguments and return 0, and that > > would meet the criteria. > > I don't believe it's possible in any language to write a maximum() > function that returns a correct result *when given incorrect argument > values*. > > The program (assuming a typical implementation) calls maximum() with > arguments 0 and 1. maximum() returns 1. It works. The problem > is elsewhere in the program. That the problem is "elsewhere in the program" ought to be small comfort. But very well, try this instead: [ron at mighty:~]$ cat foo.c #include int maximum(int a, int b) { return a > b ? a : b; } int main() { long x = 8589934592; printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); return 0; } [ron at mighty:~]$ gcc -Wall foo.c [ron at mighty:~]$ ./a.out Max of 8589934592 and 1 is 1 From zooko at zooko.com Wed Sep 29 21:04:57 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Wed, 29 Sep 2010 19:04:57 -0600 Subject: ANNOUNCING Tahoe, the Least-Authority File System, v1.8.0 Message-ID: Hello, people of python-list. This storage project uses Python for almost everything, except we use C/C++ for the CPU-intensive computations (cryptography and erasure coding) and we use JavaScript for some user interface bits. We're even looking at the possibility of replacing the C/C++ crypto code with pure-Python code, relying on JIT compilers such as PyPy to make it efficient enough. :-) http://twitter.com/#!/fijall/status/25314330015 Regards, Zooko ANNOUNCING Tahoe, the Least-Authority File System, v1.8.0 The Tahoe-LAFS team is pleased to announce the immediate availability of version 1.8.0 of Tahoe-LAFS, an extremely reliable distributed storage system. Get it here: http://tahoe-lafs.org/source/tahoe/trunk/docs/quickstart.html Tahoe-LAFS is the first distributed storage system to offer "provider-independent security" ? meaning that not even the operators of your storage servers can read or alter your data without your consent. Here is the one-page explanation of its unique security and fault-tolerance properties: http://tahoe-lafs.org/source/tahoe/trunk/docs/about.html The previous stable release of Tahoe-LAFS was v1.7.1, which was released July 18, 2010 [1]. v1.8.0 offers greatly improved performance and fault-tolerance of downloads and improved Windows support. See the NEWS file [2] for details. WHAT IS IT GOOD FOR? With Tahoe-LAFS, you distribute your filesystem across multiple servers, and even if some of the servers fail or are taken over by an attacker, the entire filesystem continues to work correctly, and continues to preserve your privacy and security. You can easily share specific files and directories with other people. In addition to the core storage system itself, volunteers have built other projects on top of Tahoe-LAFS and have integrated Tahoe-LAFS with existing systems, including Windows, JavaScript, iPhone, Android, Hadoop, Flume, Django, Puppet, bzr, mercurial, perforce, duplicity, TiddlyWiki, and more. See the Related Projects page on the wiki [3]. We believe that strong cryptography, Free and Open Source Software, erasure coding, and principled engineering practices make Tahoe-LAFS safer than RAID, removable drive, tape, on-line backup or cloud storage. This software is developed under test-driven development, and there are no known bugs or security flaws which would compromise confidentiality or data integrity under recommended use. (For all important issues that we are currently aware of please see the known_issues.txt file [4].) COMPATIBILITY This release is compatible with the version 1 series of Tahoe-LAFS. Clients from this release can write files and directories in the format used by clients of all versions back to v1.0 (which was released March 25, 2008). Clients from this release can read files and directories produced by clients of all versions since v1.0. Servers from this release can serve clients of all versions back to v1.0 and clients from this release can use servers of all versions back to v1.0. This is the eleventh release in the version 1 series. This series of Tahoe-LAFS will be actively supported and maintained for the forseeable future, and future versions of Tahoe-LAFS will retain the ability to read and write files compatible with this series. LICENCE You may use this package under the GNU General Public License, version 2 or, at your option, any later version. See the file "COPYING.GPL" [5] for the terms of the GNU General Public License, version 2. You may use this package under the Transitive Grace Period Public Licence, version 1 or, at your option, any later version. (The Transitive Grace Period Public Licence has requirements similar to the GPL except that it allows you to delay for up to twelve months after you redistribute a derived work before releasing the source code of your derived work.) See the file "COPYING.TGPPL.html" [6] for the terms of the Transitive Grace Period Public Licence, version 1. (You may choose to use this package under the terms of either licence, at your option.) INSTALLATION Tahoe-LAFS works on Linux, Mac OS X, Windows, Cygwin, Solaris, *BSD, and probably most other systems. Start with "docs/quickstart.html" [7]. HACKING AND COMMUNITY Please join us on the mailing list [8]. Patches are gratefully accepted -- the RoadMap page [9] shows the next improvements that we plan to make and CREDITS [10] lists the names of people who've contributed to the project. The Dev page [11] contains resources for hackers. SPONSORSHIP Tahoe-LAFS was originally developed by Allmydata, Inc., a provider of commercial backup services. After discontinuing funding of Tahoe-LAFS R&D in early 2009, they continued to provide servers, bandwidth, small personal gifts as tokens of appreciation, and bug reports. Google, Inc. sponsored Tahoe-LAFS development as part of the Google Summer of Code 2010. They awarded four sponsorships to students from around the world to hack on Tahoe-LAFS that summer. Thank you to Allmydata and Google for their generous and public-spirited support. HACK TAHOE-LAFS! If you can find a security flaw in Tahoe-LAFS which is serious enough that feel compelled to warn our users and issue a fix, then we will award you with a customized t-shirts with your exploit printed on it and add you to the "Hack Tahoe-LAFS Hall Of Fame" [12]. ACKNOWLEDGEMENTS This is the fifth release of Tahoe-LAFS to be created solely as a labor of love by volunteers. Thank you very much to the team of "hackers in the public interest" who make Tahoe-LAFS possible. David-Sarah Hopwood and Zooko Wilcox-O'Hearn on behalf of the Tahoe-LAFS team September 23, 2010 Rainhill, Merseyside, UK and Boulder, Colorado, USA [1] http://tahoe-lafs.org/trac/tahoe/browser/relnotes.txt?rev=4579 [2] http://tahoe-lafs.org/trac/tahoe/browser/NEWS?rev=4732 [3] http://tahoe-lafs.org/trac/tahoe/wiki/RelatedProjects [4] http://tahoe-lafs.org/trac/tahoe/browser/docs/known_issues.txt [5] http://tahoe-lafs.org/trac/tahoe/browser/COPYING.GPL [6] http://tahoe-lafs.org/source/tahoe/trunk/COPYING.TGPPL.html [7] http://tahoe-lafs.org/source/tahoe/trunk/docs/quickstart.html [8] http://tahoe-lafs.org/cgi-bin/mailman/listinfo/tahoe-dev [9] http://tahoe-lafs.org/trac/tahoe/roadmap [10] http://tahoe-lafs.org/trac/tahoe/browser/CREDITS?rev=4591 [11] http://tahoe-lafs.org/trac/tahoe/wiki/Dev [12] http://tahoe-lafs.org/hacktahoelafs/ From no.email at nospam.invalid Wed Sep 29 21:06:26 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 29 Sep 2010 18:06:26 -0700 Subject: Supplementing the std lib (Was: partial sums problem) References: Message-ID: <7x1v8cm44t.fsf@ruckus.brouhaha.com> kj writes: > But in the immediate term, cusum is not part of the standard library. > > Where would you put it if you wanted to reuse it? Do you create > a module just for it? Or do you create a general stdlib2 module > with all those workhorse functions that have not made it to the > standard library? Or something else entirely? In a typical application you'd have a bunch of such utility functions in a single "utils.py" module or something like that. Java programs use separate files for each class, so you get zillions of files, but Python users tend to put more code in each file. As for the stdlib, the natural places for such a function would be either itertools or functools, and the function should probably be called "scan", inspired by this: http://en.wikibooks.org/wiki/Haskell/List_processing#Scans Python's version would be like "scanl" with an optional arg to make it like "scanl1". From usenet-nospam at seebs.net Wed Sep 29 21:17:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 01:17:53 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: On 2010-09-30, RG wrote: > That the problem is "elsewhere in the program" ought to be small > comfort. It is, perhaps, but it's also an important technical point: You CAN write correct code for such a thing. > int maximum(int a, int b) { return a > b ? a : b; } > int main() { > long x = 8589934592; > printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); You invoked implementation-defined behavior here by calling maximum() with a value which was outside the range. The defined behavior is that the arguments are converted to the given type, namely int. The conversion is implementation-defined and could include yielding an implementation-defined signal which aborts execution. Again, the maximum() function is 100% correct -- your call of it is incorrect. You didn't pass it the right sort of data. That's your problem. (And no, the lack of a diagnostic doesn't necessarily prove anything; see the gcc documentation for details of what it does when converting an out of range value into a signed type, it may well have done exactly what it is defined to do.) -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-REMOVE-THIS at cybersource.com.au Wed Sep 29 21:21:38 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 30 Sep 2010 01:21:38 GMT Subject: About __class__ of an int literal References: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> <8739ss4tk6.fsf@xemacs.org> Message-ID: <4ca3e622$0$28672$c3e8da3@news.astraweb.com> On Wed, 29 Sep 2010 14:34:33 +0200, Hrvoje Niksic wrote: > Steven D'Aprano writes: >> (This may change in the future. Given type(), and isinstance(), I'm not >> sure what value __class__ adds.) > > None whatsoever. __class__ used to be necessary to tell the appart > instances of different old-style classes: > >>>> class X: pass # old-style > ... >>>> X().__class__ > >>>> type(X()) > > > Now that classes produce real types, they are equivalent. I've been thinking about this, and I think that there may be a use-case for changing __class__ manually. I'm not entirely sure if this is a good idea or not, I'd need to spend some time experimenting, but imagine a class that wraps another object and uses delegation instead of inheritance. If you also set __class__ (on the class itself, naturally, not the instance) appropriately, then type(instance) and instance.__class__ will be different. type() will return the "real" type of the delegation class, while instance.__class__ returns the class that it is trying to be. And of course, presumably metaclasses can do anything they like with __class__, for good or ill. I'm not sure if and when this would be useful, but it's a hint that perhaps the distinction is not entirely meaningless. -- Steven From kst-u at mib.org Wed Sep 29 21:28:15 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 18:28:15 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: [...] > That the problem is "elsewhere in the program" ought to be small > comfort. I don't claim that it's comforting, merely that it's true. > But very well, try this instead: > > [ron at mighty:~]$ cat foo.c > #include > > int maximum(int a, int b) { return a > b ? a : b; } > > int main() { > long x = 8589934592; > printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > return 0; > } > [ron at mighty:~]$ gcc -Wall foo.c > [ron at mighty:~]$ ./a.out > Max of 8589934592 and 1 is 1 That exhibits a very similar problem. 8589934592 is 2**33. Given the output you got, I presume your system has 32-bit int and 64-bit long. The call maximum(x, 1) implicitly converts the long value 8589934592 to int. The result is implementation-defined, but typically 0. So maximum() is called with arguments of 0 and 1, as you could see by adding a printf call to maximum(). Even here, maximum() did exactly what was asked of it. I'll grant you that having a conversion from a larger type to a smaller type quietly discard high-order bits is unfriendly. But it matches the behavior of most CPUs. Here's another example: #include int maximum(int a, int b) { return a > b ? a : b; } int main(void) { double x = 1.8; printf("Max of %f and 1 is %d\n", x, maximum(x, 1)); return 0; } Output: Max of 1.800000 and 1 is 1 -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From ian-news at hotmail.com Wed Sep 29 22:00:59 2010 From: ian-news at hotmail.com (Ian Collins) Date: Thu, 30 Sep 2010 15:00:59 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <8gi9arFg2jU5@mid.individual.net> On 09/30/10 02:17 PM, Seebs wrote: > On 2010-09-30, RG wrote: >> That the problem is "elsewhere in the program" ought to be small >> comfort. > > It is, perhaps, but it's also an important technical point: You CAN write > correct code for such a thing. > >> int maximum(int a, int b) { return a> b ? a : b; } > >> int main() { >> long x = 8589934592; >> printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > > You invoked implementation-defined behavior here by calling maximum() with > a value which was outside the range. The defined behavior is that the > arguments are converted to the given type, namely int. The conversion > is implementation-defined and could include yielding an implementation-defined > signal which aborts execution. > > Again, the maximum() function is 100% correct -- your call of it is incorrect. > You didn't pass it the right sort of data. That's your problem. > > (And no, the lack of a diagnostic doesn't necessarily prove anything; see > the gcc documentation for details of what it does when converting an out > of range value into a signed type, it may well have done exactly what it > is defined to do.) Note that the mistake can be diagnosed: lint /tmp/u.c -m64 -errchk=all (7) warning: passing 64-bit integer arg, expecting 32-bit integer: maximum(arg 1) -- Ian Collins From ian.g.kelly at gmail.com Wed Sep 29 22:17:46 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 29 Sep 2010 20:17:46 -0600 Subject: Supplementing the std lib (Was: partial sums problem) In-Reply-To: <7x1v8cm44t.fsf@ruckus.brouhaha.com> References: <7x1v8cm44t.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Sep 29, 2010 at 7:06 PM, Paul Rubin wrote: > As for the stdlib, the natural places for such a function would be > either itertools or functools, and the function should probably be called > "scan", inspired by this: > > http://en.wikibooks.org/wiki/Haskell/List_processing#Scans > > Python's version would be like "scanl" with an optional arg to make it > like "scanl1". > Something like this? NoInitialValue = object() def scan(function, iterable, initial=NoInitialValue): iterator = iter(iterable) if initial is NoInitialValue: try: accumulator = iterator.next() except StopIteration: return else: accumulator = initial yield accumulator for arg in iterator: accumulator = function(accumulator, arg) yield accumulator Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruce at futurewavedesigns.com Wed Sep 29 22:32:13 2010 From: bruce at futurewavedesigns.com (Bruce Whealton) Date: Wed, 29 Sep 2010 22:32:13 -0400 Subject: Clarification of notation Message-ID: <4CA3F6AD.3020603@futurewavedesigns.com> Hello all, I recently started learning python. I am a bit thrown by a certain notation that I see. I was watching a training course on lynda.com and this notation was not presented. For lists, when would you use what appears to be nested lists, like: [[], [], []] a list of lists? Would you, and could you combine a dictionary with a list in this fashion? Next, from the documentation I see and this is just an example (this kind of notation is seen elsewhere in the documentation: str.count(sub[, start[, end]]) This particular example is from the string methods. Is this a nesting of two lists inside a a third list? I know that it would suggest that some of the arguments are optional, so perhaps if there are 2 items the first is the sub, and the second is start? Or did I read that backwards? Thanks, Bruce From pbloom at crystald.com Wed Sep 29 22:38:29 2010 From: pbloom at crystald.com (Philip Bloom) Date: Wed, 29 Sep 2010 19:38:29 -0700 Subject: Strange os.stat behavior Message-ID: I'm on python 2.6.1: Ran into some os.stat behavior that knocked me for a loop. I was using os.stat to retrieve file st_ctime and st_mtime from a remote server through a unc path, and doing this I encountered that os.stat was returning me st_ctime and st_mtime values that were months off, reporting values that not only were months in the past, but also relatively wrong (Reporting a greater difference between Modified and Created than there should be). Below, run through localtime and formatted a little for easier reading.). C++ stat, Win32API, and Windows own directory report all match with the same seen time (and are correct). Has anyone seen something like this before? It's quite scary to me that os.stat is returning a different value that it's getting from somewhere and doesn't match with either the Windows API or the C++ stat library. I read over the release notes for 2.6.x and didn't see any mention of os.stat relevant bugs or fixes. I'm curious what it could possibly be doing differently than the others (I thought it used the windows api under the hood for Windows nt derived systems). Ex: \\mpkarc01\Build_stats\tras\MayaExportKernel_p.config\mabahazy~RWCWRK_70 01470.stats\9-27-2010_log.txt 1279755701.87 1285810489.65 Created: time.struct_time(tm_year=2010, tm_mon=7, tm_mday=21, tm_hour=16, tm_min=41, tm_sec=41, tm_wday=2, tm_yday=202, tm_isdst=1) Modified: time.struct_time(tm_year=2010, tm_mon=7, tm_mday=25, tm_hour=0, tm_min=59, tm_sec=45, tm_wday=6, tm_yday=206, tm_isdst=1), raw: 1280044785 Accessed: time.struct_time(tm_year=2010, tm_mon=9, tm_mday=29, tm_hour=17, tm_min=25, tm_sec=31, tm_wday=2, tm_yday=272, tm_isdst=1) Raw Time.Time(): time.struct_time(tm_year=2010, tm_mon=9, tm_mday=29, tm_hour=18, tm_min=34, tm_sec=49, tm_wday=2, tm_yday=272, tm_isdst=1), raw: 1285810489.65 Win32API Ctime: 09/27/10 20:18:11 Win32API MTime: 09/28/10 01:18:37 Win32API ATime: 09/29/10 00:24:46 Relevant code segment: import win32api import win32con import win32file import time import os ... statinfo = os.stat(os.path.join(root, name)) print os.path.join(root, name) + " " + str(statinfo.st_ctime) + " " + str(time.time()) print "Modified: ", time.localtime(int(statinfo.st_mtime)),int(statinfo.st_mtime) print "Created: ", time.localtime(int(statinfo.st_ctime)) print "Accessed: ", time.localtime(int(statinfo.st_atime)) print time.localtime(),time.time() fh = win32file.CreateFile(os.path.join(root, name), win32file.GENERIC_READ | win32file.GENERIC_WRITE, 0, None, win32file.OPEN_EXISTING,0, 0) sts, creationTime, accessTime, writeTime = win32file.GetFileTime(fh) print creationTime, accessTime, writeTime win32file.CloseHandle(fh) Platform of executing code: Windows XP, 64 bit. ______________________________________________________________________ This email has been scanned by the MessageLabs ______________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From namekuseijin at gmail.com Wed Sep 29 23:28:35 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Wed, 29 Sep 2010 20:28:35 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> Message-ID: On 29 set, 17:46, Xah Lee wrote: > On Sep 29, 11:02?am, namekuseijin wrote: > > > On 28 set, 19:38, Xah Lee wrote: > > > > ? ?list comprehension? is a very bad jargon; thus harmful to > > > functional programing or programing in general. Being a bad jargon, it > > > encourage mis-communication, mis-understanding. > > > I disagree: ?it is a quite intuitive term to describe what the > > expression does. > > what's your basis in saying that ?list comprehension? is intuitive? it generates a list from syntax comprehended in list-like syntax! > any statics, survery, research, references you have to cite? how about common sense? > to put this in context, are you saying that lambda, is also intuitive? No. > ?let? is intuitive? yes, it's focking everyday term used in the same way: let this be this and that be that and thus... > ?for? is intuitive? yes, it's focking everyday term used in the same way: for this and this and this do that... > ?when? is intuitive? when this, then that? common sense, Xah! > For example, let us know, in your view, how good are terms: currying, > lisp1 lisp2, tail recursion, closure, subroutine, command, object. These terms have a technical meaning coming from historic events in the areas they are used. It's like that in all areas, you may also bash medicine jargon if you want. Though subroutine, command and object are pretty intuitive by common sense alone. > perhaps expound on the comparative merits and meaning on the terms > module vs package vs add-on vs library. I would like to see your view > on this with at least few paragraphs of analysis on each. They are all the same shit. These were developed by managers and buzzwriters... ;) > Also, ?being intuitive? is not the only aspect to consider whether a > term is good or bad. For example, emacs's uses the term ?frame?. It's > quite intuitive, because frame is a common english word, everyone > understands. You know, door frame, window frame, picture frame, are > all analogous to emacs's ?frame? on a computer. However, by some turn > of history, in computer software we call such as ?window? now, and by > happance the term ?window? also has a technical meaning in emacs, what > we call ?split window? or ?pane? today. So, in emacs, the term ?frame? > and ?window? is confusing, because emacs's ?frame? is what we call > ?window?, while emacs's ?window? is what me might call a pane of a > split window. So here, is a example, that even when a term is > intuitive, it can still be bad. emacs is all FUBAR in more than one way. being intuitive is not exactly what it is known for... ;) well, I shouldn't be bashing it, my vim is not that funky among commoners anymore anyway... :p > I wrote about 14 essays on various jargons in past decade. You can > find them on my site. yeah, I've read them once in a while... From nagle at animats.com Wed Sep 29 23:41:00 2010 From: nagle at animats.com (John Nagle) Date: Wed, 29 Sep 2010 20:41:00 -0700 Subject: Certificate validation with HTTPSConnection In-Reply-To: References: <4CA3A46B.4080006@animats.com> Message-ID: <4ca406ef$0$1633$742ec2ed@news.sonic.net> On 9/29/2010 3:51 PM, Antoine Pitrou wrote: > On Wed, 29 Sep 2010 13:41:15 -0700 > John Nagle wrote: >> >> The really stupid thing about the current SSL module is that it >> accepts a file of root certificates as a parameter, but ignores it. > > That's not true. You have to pass CERT_OPTIONAL or CERT_REQUIRED as a > parameter (CERT_NONE is though). If you pass CERT_REQUIRED and a root certificate authority file, there has to be some certificate, but the signature chain is not validated against the CA file, so the cert doesn't certify anything. Phony web sites look valid to Python's SSL library. John Nagle From usenet-nospam at seebs.net Wed Sep 29 23:48:06 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 03:48:06 GMT Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> Message-ID: On 2010-09-30, namekuseijin wrote: > it generates a list from syntax comprehended in list-like syntax! Okay, help me out here. (Killed the crossposting.) I am not understanding how the word applies. I'm fine with it, but I don't see any relation at all between the thing called a list comprehension and the word "comprehension" as I normally understand it. Who or what is doing the comprehending? Is this a sense of "comprehension" other than "to understand"? It seems like it's perhaps related to "comprehensive". However, I've never seen "comprehension" used to refer to anything other than understanding prior to encountering "list comprehensions". [... hmm. maybe time to go searching...] Looking around, it seems this is from mathematical jargon, to wit, "set comprehensions". Since I hadn't run into that jargon, I had no clue what the etymology was, and "comprehended" is not a verb I would ever have used with this. However, looking around, it appears that this usage also occurs in the same jargon; once you've got one of them the other follows. I guess the key, though, is that this is purely jargon, and jargon from another field -- not all programmers have done all mathematics. I even took a ton of bonus math in college, but happened not to have done anything where this terminology was used. So the usage is, pardon the pun, incomprehensible to me to begin with, and saying it's called a comprehension because it's comprehended doesn't help -- that's two forms of the same unfamiliar jargon. Of course, the jargon is pretty reasonable as such goes, in no small part because of the plain English sense of "comprehensive" in the sense of covering something completely, so it's not awful. But from where I'm coming, it would be every bit as obvious to call it a "list exhaustion", by analagous derivation from "exhaustive". -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 Sep 30 00:27:38 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 04:27:38 GMT Subject: Clarification of notation References: Message-ID: On 2010-09-30, Bruce Whealton wrote: > Next, from the documentation I see and this is just an example (this > kind of notation is seen elsewhere in the documentation: > str.count(sub[, start[, end]]) > This particular example is from the string methods. > Is this a nesting of two lists inside a a third list? No, it's not -- it's a different use of [] to indicate that things are optional, a convention which dates back to long before Python existed. >I know that it > would suggest that some of the arguments are optional, so perhaps if > there are 2 items the first is the sub, and the second is start? Or did > I read that backwards? That is exactly correct. The key is the implication that you can omit end, or both start and end. (But you can't omit start and provide end.) -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 Thu Sep 30 00:29:58 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 29 Sep 2010 21:29:58 -0700 (PDT) Subject: Clarification of notation References: Message-ID: <80347433-9acd-4958-8786-cd5acd8a7b79@u4g2000prn.googlegroups.com> Bruce Whealton wrote: > For lists, when would > you use what appears to be nested lists, like: > [[], [], []] > a list of lists? Well, you'd use it when you'd want a list of lists ;) There's nothing magical about a list of lists, it's just a list with objects inside like any other, in this case they just happen to be lists. Possibly the canonical example is for a simple multidimensional array: >>> array5x5 = [[0]*5 for i in range(5)] >>> array5x5[2][3] = 7 >>> array5x5[4][1] = 2 >>> array5x5 [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 7, 0], [0, 0, 0, 0, 0], [0, 2, 0, 0, 0]] > Would you, and could you combine a dictionary with a list in this fashion? Lists can contain dictionaries that contain dictionaries containing lists :) So yes, they can easily be combined. Here's a list with dictionaries: elements = [ {'tag': 'strong', 'style': 'bold'}, {'tag': 'header', 'style': 'bolder', 'color': 'red}, ] And a dictionary of lists: classes_2010 = { 'economics': ['John Crowley', 'Jack Savage', 'Jane Austen'], 'voodoo economics': ['Ronald Reagan', 'Ferris Beuller'], } (Note that the formatting style is a personal taste and not essential). Generally, you tend to use a list when you want to work on items in sequence, and a dictionary when you want to work on an item on demand. > Next, from the documentation I see and this is just an example (this > kind of notation is seen elsewhere in the documentation: > > str.count(sub[, start[, end]]) > This particular example is from the string methods. > Is this a nesting of two lists inside a a third list? ?I know that it > would suggest that some of the arguments are optional, so perhaps if > there are 2 items the first is the sub, and the second is start? ?Or did In documentation (as opposed to code), [] represents optional arguments, and have nothing at all to do with Python lists. The above example is showing that the method can be called in the following ways: 'foobarbazbam'.count('ba') 'foobarbazbam'.count('ba', 6) 'foobarbazbam'.count('ba', 6, 9) Hope this helps. From clp2 at rebertia.com Thu Sep 30 00:50:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 29 Sep 2010 21:50:42 -0700 Subject: Clarification of notation In-Reply-To: <4CA3F6AD.3020603@futurewavedesigns.com> References: <4CA3F6AD.3020603@futurewavedesigns.com> Message-ID: On Wed, Sep 29, 2010 at 7:32 PM, Bruce Whealton wrote: > Hello all, > ? ? ? ? I recently started learning python. ?I am a bit thrown by a certain > notation that I see. ?I was watching a training course on lynda.com and this > notation was not presented. ?For lists, when would you use what appears to > be nested lists, like: > [[], [], []] > a list of lists? Lists are for working with a group of data. Sometimes each datum happens to itself be a list; thus, one naturally ends up with a list-of-lists. Say I have, for each school in my school district, a list of its students' test scores. I want to compute each school's average score. So I put all the lists of scores into a nested list. I then iterate over the nested list, taking the average of each inner list of scores. (Do the analogous thing at higher and higher levels of aggregation (e.g. county, state, country) and you naturally get progressively more nested lists.) > Would you, and could you combine a dictionary with a list in this fashion? Yes, of course: {'a' : [1,2,3]} [{'a' : 1}, {'b' : 2}] Just note that lists can't be dictionary keys due to their mutability. {[1,2,3] : "one two three"} # ERROR > Next, from the documentation I see and this is just an example (this kind of > notation is seen elsewhere in the documentation: > > str.count(sub[, start[, end]]) > This particular example is from the string methods. > I know that it would > suggest that some of the arguments are optional, so perhaps if there are 2 > items the first is the sub, and the second is start? ?Or did I read that > backwards? No, you read it exactly correctly. The []s here indicate levels of optional-ness and have nothing to do with the list datatype. Basically, if you want to pass an optional argument, you have to have also specified any less-nested arguments (unless you use keyword rather than positional arguments). str.count(a) # sub = a str.count(a, b) # sub = a, start = b str.count(a, b, c) # sub = a, start = b, end = c Usually, it's straightforward left-to-right as you specify more arguments (doing otherwise requires kludges or black magic). However, there are rare exceptions, the most common one being range()/xrange(): range(...) range([start,] stop[, step]) -> list of integers Thus: range(a) # stop = a (*not* start = a, as would be normal) range(a, b) # start = a, stop = b range(a, b, c) # start = a, stop = b, step = c Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Thu Sep 30 00:55:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Sep 2010 00:55:59 -0400 Subject: Clarification of notation In-Reply-To: <4CA3F6AD.3020603@futurewavedesigns.com> References: <4CA3F6AD.3020603@futurewavedesigns.com> Message-ID: On 9/29/2010 10:32 PM, Bruce Whealton wrote: > Would you, and could you combine a dictionary with a list in this fashion? A python list is a mutable sequence of Python objects. Extremely mixed example. >>> mixed = [1, 1.0, '1', [1], (1,), {1:1}, set((1,)), list, list.append] >>> mixed.append(mixed) # make the list recursive >>> mixed # list to string can handle that! [1, 1.0, '1', [1], (1,), {1: 1}, {1}, , , [...]] > Next, from the documentation I see and this is just an example (this > kind of notation is seen elsewhere in the documentation: > > str.count(sub[, start[, end]]) square bracket are standard for indicating optional items in extended Backus-Naur context-free grammar notations. https://secure.wikimedia.org/wikipedia/en/wiki/Backus%E2%80%93Naur_Form In Python3 docs, they have been removed as redundant when an explicit default value is given: compile(source, filename, mode, flags=0, dont_inherit=False) -- Terry Jan Reedy From rNOSPAMon at flownet.com Thu Sep 30 00:57:46 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 21:57:46 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > RG writes: > [...] > > That the problem is "elsewhere in the program" ought to be small > > comfort. > > I don't claim that it's comforting, merely that it's true. > > > But very well, try this instead: > > > > [ron at mighty:~]$ cat foo.c > > #include > > > > int maximum(int a, int b) { return a > b ? a : b; } > > > > int main() { > > long x = 8589934592; > > printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > > return 0; > > } > > [ron at mighty:~]$ gcc -Wall foo.c > > [ron at mighty:~]$ ./a.out > > Max of 8589934592 and 1 is 1 > > That exhibits a very similar problem. > > 8589934592 is 2**33. > > Given the output you got, I presume your system has 32-bit int and > 64-bit long. The call maximum(x, 1) implicitly converts the long > value 8589934592 to int. The result is implementation-defined, > but typically 0. So maximum() is called with arguments of 0 and 1, > as you could see by adding a printf call to maximum(). > > Even here, maximum() did exactly what was asked of it. Of course. Computers always do only exactly what you ask of them. On this view there is, by definition, no such thing as a bug, only specifications that don't correspond to one's intentions. Unfortunately, correspondence to intentions is the thing that actually matters when writing code. > I'll grant you that having a conversion from a larger type to a smaller > type quietly discard high-order bits is unfriendly. "Unfriendly" is not the adjective that I would choose to describe this behavior. There is a whole hierarchy of this sort of "unfriendly" behavior, some of which can be caught at compile time using a corresponding hierarchy of ever more sophisticated tools. But sooner or later if you are using Turing-complete operations you will encounter the halting problem, at which point your compile-time tools will fail. (c.f. the Collatz problem) I'm not saying one should not use compile-time tools, only that one should not rely on them. "Compiling without errors" is not -- and cannot ever be -- be a synonym for "bug-free." rg From frank at chagford.com Thu Sep 30 01:01:14 2010 From: frank at chagford.com (Frank Millman) Date: Thu, 30 Sep 2010 07:01:14 +0200 Subject: scheduler or infinite loop References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> <344a231a-1ed7-4be6-bd14-aa6adf965b03@n19g2000prf.googlegroups.com> Message-ID: harryos wrote >> >> Here is a technique that allows the loop to run in the background, in its >> own thread, leaving the main program to do other processing - >> >> import threading >> >> class DataGetter(threading.Thread): >> > thanks Frank A pleasure. I left out a line that will usually be desirable. At the end of the program, you should have - data_getter.stop() + data_getter.join() This forces the main program to wait until the thread has terminated before continuing. Frank From usenet-nospam at seebs.net Thu Sep 30 01:05:45 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 05:05:45 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: On 2010-09-30, RG wrote: > Of course. Computers always do only exactly what you ask of them. On > this view there is, by definition, no such thing as a bug, only > specifications that don't correspond to one's intentions. f00f. That said... I think you're missing Keith's point. > Unfortunately, correspondence to intentions is the thing that actually > matters when writing code. Yes. Nonetheless, the maximum() function does exactly what it is intended to do *with the inputs it receives*. The failure is outside the function; it did the right thing with the data actually passed to it, the problem was a user misunderstanding as to what data were being passed to it. So there's a bug -- there's code which does not do what it was intended to do. However, that bug is in the caller, not in the maximum() function. This is an important distinction -- it means we can write a function which performs that function reliably. Now we just need to figure out how to call it with valid data... :) -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-news at hotmail.com Thu Sep 30 01:08:13 2010 From: ian-news at hotmail.com (Ian Collins) Date: Thu, 30 Sep 2010 18:08:13 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <8gik9tFq44U4@mid.individual.net> On 09/30/10 05:57 PM, RG wrote: > > I'm not saying one should not use compile-time tools, only that one > should not rely on them. "Compiling without errors" is not -- and > cannot ever be -- be a synonym for "bug-free." We is why wee all have run time tools called unit tests, don't we? -- Ian Collins From nagle at animats.com Thu Sep 30 01:24:53 2010 From: nagle at animats.com (John Nagle) Date: Wed, 29 Sep 2010 22:24:53 -0700 Subject: scheduler or infinite loop In-Reply-To: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> Message-ID: <4ca41f48$0$1648$742ec2ed@news.sonic.net> On 9/29/2010 4:59 AM, harryos wrote: > hi > I am trying to write a program to read data from a site url. > The program must read the data from site every 5 minutes. > > def get_data_from_site(pageurlstr): > h=urllib.urlopen(pageurlstr) > data=h.read() > process_data(data) A key point here is that you're not handling network failures. The first time you have a brief network outage, your program will fail. Consider something like this: def get_data_from_site(pageurlstr): try : h=urllib.urlopen(pageurlstr) data=h.read() except EnvironmentError as message : print("Error reading %s from network at %s: %s" % (pageurlstr, time.asctime(), str(message)) return(False) process_data(data) return(True) lastpoll = 0 # time of last successful read POLLINTERVAL = 300.0 RETRYINTERVAL = 30.0 while True: status = get_data_from_site('http://somesite.com/') if not status : # if fail time.sleep(RETRYINTERVAL) # try again soon print("Retrying...") continue now = time.time() # success # Wait for the next poll period. Compensate for how # long the read took. waittime = max(POLLINTERVAL - (now - lastpoll), 1.0) lastpoll = now time.sleep(waittime) From no.email at nospam.invalid Thu Sep 30 01:34:08 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 29 Sep 2010 22:34:08 -0700 Subject: Supplementing the std lib (Was: partial sums problem) References: <7x1v8cm44t.fsf@ruckus.brouhaha.com> Message-ID: <7xbp7fhk1b.fsf@ruckus.brouhaha.com> Dennis Lee Bieber writes: >> Python's version would be like "scanl" with an optional arg to make it >> like "scanl1". > Vs APL's "expand" operator? I'm not familiar with that but maybe it's similar. From lie.1296 at gmail.com Thu Sep 30 01:38:28 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 30 Sep 2010 15:38:28 +1000 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <4ca421a1$1@dnews.tpgi.com.au> On 09/30/10 11:17, Seebs wrote: > On 2010-09-30, RG wrote: >> That the problem is "elsewhere in the program" ought to be small >> comfort. > > It is, perhaps, but it's also an important technical point: You CAN write > correct code for such a thing. > >> int maximum(int a, int b) { return a > b ? a : b; } > >> int main() { >> long x = 8589934592; >> printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > > You invoked implementation-defined behavior here by calling maximum() with > a value which was outside the range. The defined behavior is that the > arguments are converted to the given type, namely int. The conversion > is implementation-defined and could include yielding an implementation-defined > signal which aborts execution. > > Again, the maximum() function is 100% correct -- your call of it is incorrect. > You didn't pass it the right sort of data. That's your problem. That argument can be made for dynamic language as well. If you write in dynamic language (e.g. python): def maximum(a, b): return a if a > b else b The dynamic language's version of maximum() function is 100% correct -- if you passed an uncomparable object, instead of a number, your call of it is incorrect; you just didn't pass the right sort of data. And that's your problem as a caller. In fact, since Python's integer is infinite precision (only bounded by available memory); in practice, Python's version of maximum() has less chance of producing erroneous result. The /most/ correct version of maximum() function is probably one written in Haskell as: maximum :: Integer -> Integer -> Integer maximum a b = if a > b then a else b Integer in Haskell has infinite precision (like python's int, only bounded by memory), but Haskell also have static type checking, so you can't pass just any arbitrary objects. But even then, it's still not 100% correct. If you pass a really large values that exhaust the memory, the maximum() could still produce unwanted result. Second problem is that Haskell has Int, the bounded integer, and if you have a calculation in Int that overflowed in some previous calculation, then you can still get an incorrect result. In practice, the type-agnostic language with *mandatory* infinite precision arithmetic wins in terms of correctness. Any language which only has optional infinite precision arithmetic can always produce erroneous result. Anyone can dream of 100% correct program; but anyone who believes they can write a 100% correct program is just a dreamer. In reality, we don't usually need 100% correct program; we just need a program that runs correctly enough most of the times that the 0.0000001% chance of producing erroneous result becomes irrelevant. In summary, in this particular case with maximum() function, static checking does not help in producing the most correct code; if you need to ensure the highest correctness, you must use a language with *mandatory* infinite precision integers. From zzbbaadd at aol.com Thu Sep 30 01:51:28 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Wed, 29 Sep 2010 22:51:28 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: > > More specifically, the claim made above: > > > in C I can have a function maximum(int a, int b) that will always > > work. Never blow up, and never give an invalid answer. > > is false. ?And it is not necessary to invoke the vagaries of run-time > input to demonstrate that it is false. > I don't think you demonstrated it is false. Any values larger than an int get truncated before they ever get to maximum. The problem does not lie with the maximum function. It correctly returns the maximum of whatever two integers it is provided. Calling it with values that are larger than an int, that get converted to an int _before_ maximum is called, is an issue outside of maximum. From metolone+gmane at gmail.com Thu Sep 30 01:55:06 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Wed, 29 Sep 2010 22:55:06 -0700 Subject: utf-8 and ctypes References: Message-ID: "Brendan Miller" wrote in message news:AANLkTi=2f3L++398St-16MPEs8wzfbLbu+Qa8zTPAbsd at mail.gmail.com... > 2010/9/29 Lawrence D'Oliveiro : >> In message , >> Brendan >> Miller wrote: >> >>> It seems that characters not in the ascii subset of UTF-8 are >>> discarded by c_char_p during the conversion ... >> >> Not a chance. >> >>> ... or at least they don't print out when I go to print the string. >> >> So it seems there?s a problem on the printing side. What happens when >> you >> construct a UTF-8-encoded string directly in Python and try printing it >> the >> same way? > > Doing this seems to confirm something is broken in ctypes w.r.t. UTF-8... > > if I enter: > str = "???????" > > Then: > print str > ??????? > > However, when I create a string buffer, pass it into my c++ code, and > write the same UTF-8 string into it, python seems to discard pretty > much all the text. The same code works for pure ascii strings. > > Python code: > _std_string_size = _lib_mbxclient.std_string_size > _std_string_size.restype = c_long > _std_string_size.argtypes = [c_void_p] > > _std_string_copy = _lib_mbxclient.std_string_copy > _std_string_copy.restype = None > _std_string_copy.argtypes = [c_void_p, POINTER(c_char)] > > # This function works for ascii, but breaks on strings with UTF-8! > def std_string_to_string(str_ptr): > buf = create_string_buffer(_std_string_size(str_ptr)) > _std_string_copy(str_ptr, buf) > return buf.raw > > C++ code: > > extern "C" > long std_string_size(string* str) > { > return str->size(); > } > > extern "C" > void std_string_copy(string* str, char* buf) > { > std::copy(str->begin(), str->end(), buf); > } I didn't see what OS you are using, but I fleshed out your example code and have a working example for Windows. Below is the code for the DLL and script: --------- x.cpp [cl /LD /EHsc /W4 x.cpp] ---------------------------------------------------- #include #include using namespace std; extern "C" __declspec(dllexport) long std_string_size(string* str) { return str->size(); } extern "C" __declspec(dllexport) void std_string_copy(string* str, char* buf) { std::copy(str->begin(), str->end(), buf); } extern "C" __declspec(dllexport) void* make(const char* s) { return new string(s); } extern "C" __declspec(dllexport) void destroy(void* s) { delete (string*)s; } ---- x.py --------------------------------------------------------- # coding: utf8 from ctypes import * _lib_mbxclient = CDLL('x') _std_string_size = _lib_mbxclient.std_string_size _std_string_size.restype = c_long _std_string_size.argtypes = [c_void_p] _std_string_copy = _lib_mbxclient.std_string_copy _std_string_copy.restype = None _std_string_copy.argtypes = [c_void_p, c_char_p] make = _lib_mbxclient.make make.restype = c_void_p make.argtypes = [c_char_p] destroy = _lib_mbxclient.destroy destroy.restype = None destroy.argtypes = [c_void_p] # This function works for ascii, but breaks on strings with UTF-8! def std_string_to_string(str_ptr): buf = create_string_buffer(_std_string_size(str_ptr)) _std_string_copy(str_ptr, buf) return buf.raw s = make(u'??????'.encode('utf8')) print std_string_to_string(s).decode('utf8') ------------------------------------------------------ And output (in Pythonwin...US Windows console doesn't support Chinese): ?????? I used c_char_p instead of POINTER(c_char) and added functions to create and destroy a std::string for Python's use, but it is otherwise the same as your code. Hope this helps you work it out, -Mark From kst-u at mib.org Thu Sep 30 02:00:56 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 23:00:56 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: > In article , > Keith Thompson wrote: [...] >> Even here, maximum() did exactly what was asked of it. > > Of course. Computers always do only exactly what you ask of them. On > this view there is, by definition, no such thing as a bug, only > specifications that don't correspond to one's intentions. > Unfortunately, correspondence to intentions is the thing that actually > matters when writing code. Of course there's such a thing as a bug. This version of maximum: int maximum(int a, int b) { return a > b ? a : a; } has a bug. This version: int maximum(int a, int b) { return a > b ? a : b; } I would argue, does not. The fact that it might be included in a buggy program does not mean that it is itself buggy. [...] > I'm not saying one should not use compile-time tools, only that one > should not rely on them. "Compiling without errors" is not -- and > cannot ever be -- be a synonym for "bug-free." Agreed. (Though C does make it notoriously easy to sneak buggy code past the compiler.) -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From zzbbaadd at aol.com Thu Sep 30 02:09:05 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Wed, 29 Sep 2010 23:09:05 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> Message-ID: > > That argument can be made for dynamic language as well. If you write in > dynamic language (e.g. python): > > def maximum(a, b): > ? ? return a if a > b else b > > The dynamic language's version of maximum() function is 100% correct -- > if you passed an uncomparable object, instead of a number, your call of > it is incorrect; you just didn't pass the right sort of data. And that's > your problem as a caller. > > In fact, since Python's integer is infinite precision (only bounded by > available memory); in practice, Python's version of maximum() has less > chance of producing erroneous result. "in C I can have a function maximum(int a, int b) that will always work. Never blow up, and never give an invalid answer. " Dynamic typed languages like Python fail in this case on "Never blows up". From rNOSPAMon at flownet.com Thu Sep 30 02:29:55 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 23:29:55 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > > I'm not saying one should not use compile-time tools, only that one > > should not rely on them. "Compiling without errors" is not -- and > > cannot ever be -- be a synonym for "bug-free." > > Agreed. (Though C does make it notoriously easy to sneak buggy code > past the compiler.) Let's just leave it at that then. rg From rNOSPAMon at flownet.com Thu Sep 30 02:38:14 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 23:38:14 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Seebs wrote: > On 2010-09-30, RG wrote: > > Of course. Computers always do only exactly what you ask of them. On > > this view there is, by definition, no such thing as a bug, only > > specifications that don't correspond to one's intentions. > > f00f. > > That said... I think you're missing Keith's point. > > > Unfortunately, correspondence to intentions is the thing that actually > > matters when writing code. > > Yes. Nonetheless, the maximum() function does exactly what it is intended > to do *with the inputs it receives*. The failure is outside the function; > it did the right thing with the data actually passed to it, the problem > was a user misunderstanding as to what data were being passed to it. > > So there's a bug -- there's code which does not do what it was intended > to do. However, that bug is in the caller, not in the maximum() > function. > > This is an important distinction -- it means we can write a function > which performs that function reliably. Now we just need to figure out > how to call it with valid data... :) We lost some important context somewhere along the line: > > > in C I can have a function maximum(int a, int b) that will always > > > work. Never blow up, and never give an invalid answer. If someone > > > tries to call it incorrectly it is a compile error. Please take note of the second sentence. One way or another, this claim is plainly false. The point I was trying to make is not so much that the claim is false (someone else was already doing that), but that it can be demonstrated to be false without having to rely on any run-time input. rg From 3-nospam at temporary-address.org.uk Thu Sep 30 02:48:18 2010 From: 3-nospam at temporary-address.org.uk (Nick) Date: Thu, 30 Sep 2010 07:48:18 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <8gik9tFq44U4@mid.individual.net> Message-ID: <87hbh7afrh.fsf@temporary-address.org.uk> Ian Collins writes: > On 09/30/10 05:57 PM, RG wrote: >> >> I'm not saying one should not use compile-time tools, only that one >> should not rely on them. "Compiling without errors" is not -- and >> cannot ever be -- be a synonym for "bug-free." > > We is why wee all have run time tools called unit tests, don't we? But you have to know a lot about the language to know that there's a problem. You cannot sensibly test your max function on every combination of (even int) input which it's designed for (and, of course, it works for those). -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk From v.ladeuil+lp at free.fr Thu Sep 30 02:51:36 2010 From: v.ladeuil+lp at free.fr (Vincent Ladeuil) Date: Thu, 30 Sep 2010 08:51:36 +0200 Subject: bzr 2.2.1 released ! In-Reply-To: (Sridhar Ratnakumar's message of "Wed, 29 Sep 2010 09:16:54 -0700") References: Message-ID: >>>>> Sridhar Ratnakumar writes: > Hi, > It seems that you forgot to update PyPI - which lists 2.1.0rc1 as the latest version. > -srid This should be fixed now. Let us know if you encounter problems. Vincent From ian-news at hotmail.com Thu Sep 30 03:03:14 2010 From: ian-news at hotmail.com (Ian Collins) Date: Thu, 30 Sep 2010 20:03:14 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: <4ca421a1$1@dnews.tpgi.com.au> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> Message-ID: <8gir4qFc8bU1@mid.individual.net> On 09/30/10 06:38 PM, Lie Ryan wrote: > > The /most/ correct version of maximum() function is probably one written > in Haskell as: > > maximum :: Integer -> Integer -> Integer > maximum a b = if a> b then a else b > > Integer in Haskell has infinite precision (like python's int, only > bounded by memory), but Haskell also have static type checking, so you > can't pass just any arbitrary objects. > > But even then, it's still not 100% correct. If you pass a really large > values that exhaust the memory, the maximum() could still produce > unwanted result. > > Second problem is that Haskell has Int, the bounded integer, and if you > have a calculation in Int that overflowed in some previous calculation, > then you can still get an incorrect result. In practice, the > type-agnostic language with *mandatory* infinite precision arithmetic > wins in terms of correctness. Any language which only has optional > infinite precision arithmetic can always produce erroneous result. > > Anyone can dream of 100% correct program; but anyone who believes they > can write a 100% correct program is just a dreamer. In reality, we don't > usually need 100% correct program; we just need a program that runs > correctly enough most of the times that the 0.0000001% chance of > producing erroneous result becomes irrelevant. > > In summary, in this particular case with maximum() function, static > checking does not help in producing the most correct code; if you need > to ensure the highest correctness, you must use a language with > *mandatory* infinite precision integers. Or using the new suffix return syntax in C++0x. Something like template [] maximum( T0 a, T1 b) { return a > b ? a : b; } Where the return type is deduced at compile time. -- Ian Collins From zzbbaadd at aol.com Thu Sep 30 03:23:55 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 00:23:55 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> > > Yes. ?Nonetheless, the maximum() function does exactly what it is intended > > to do *with the inputs it receives*. ?The failure is outside the function; > > it did the right thing with the data actually passed to it, the problem > > was a user misunderstanding as to what data were being passed to it. > > > So there's a bug -- there's code which does not do what it was intended > > to do. ?However, that bug is in the caller, not in the maximum() > > function. > > > This is an important distinction -- it means we can write a function > > which performs that function reliably. ?Now we just need to figure out > > how to call it with valid data... :) > > We lost some important context somewhere along the line: > > > > > in C I can have a function maximum(int a, int b) that will always > > > > work. Never blow up, and never give an invalid answer. If someone > > > > tries to call it incorrectly it is a compile error. > > Please take note of the second sentence. > > One way or another, this claim is plainly false. ?The point I was trying > to make is not so much that the claim is false (someone else was already > doing that), but that it can be demonstrated to be false without having > to rely on any run-time input. > The second sentence is not disproved by a cast from one datatype to another (which changes the value) that happens before maximum() is called. From ldo at geek-central.gen.new_zealand Thu Sep 30 04:01:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 30 Sep 2010 21:01:53 +1300 Subject: System idle time under Linux References: Message-ID: In message , Hugo L?veill? wrote: > Sorry, I am not a linux guy. Did not know it was a text file That?s why I said to check the proc(5) man page for further details. From no.email at nospam.invalid Thu Sep 30 04:02:49 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 01:02:49 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: <7xlj6j3bh2.fsf@ruckus.brouhaha.com> >> > > > in C I can have a function maximum(int a, int b) that will always >> > > > work. Never blow up, and never give an invalid answer. If someone >> > > > tries to call it incorrectly it is a compile error. > The second sentence is not disproved by a cast from one datatype to > another (which changes the value) that happens before maximum() is called. int maximum(int a, int b); int foo() { int (*barf)() = maximum; return barf(3); } This compiles fine for me. Where is the cast? Where is the error message? Are you saying barf(3) doesn't call maximum? From pjb at informatimago.com Thu Sep 30 04:07:12 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 10:07:12 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <8gir4qFc8bU1@mid.individual.net> Message-ID: <87fwwrodsf.fsf@kuiper.lan.informatimago.com> Ian Collins writes: > On 09/30/10 06:38 PM, Lie Ryan wrote: >> >> The /most/ correct version of maximum() function is probably one written >> in Haskell as: >> >> maximum :: Integer -> Integer -> Integer >> maximum a b = if a> b then a else b >> >> Integer in Haskell has infinite precision (like python's int, only >> bounded by memory), but Haskell also have static type checking, so you >> can't pass just any arbitrary objects. >> >> But even then, it's still not 100% correct. If you pass a really large >> values that exhaust the memory, the maximum() could still produce >> unwanted result. >> >> Second problem is that Haskell has Int, the bounded integer, and if you >> have a calculation in Int that overflowed in some previous calculation, >> then you can still get an incorrect result. In practice, the >> type-agnostic language with *mandatory* infinite precision arithmetic >> wins in terms of correctness. Any language which only has optional >> infinite precision arithmetic can always produce erroneous result. >> >> Anyone can dream of 100% correct program; but anyone who believes they >> can write a 100% correct program is just a dreamer. In reality, we don't >> usually need 100% correct program; we just need a program that runs >> correctly enough most of the times that the 0.0000001% chance of >> producing erroneous result becomes irrelevant. >> >> In summary, in this particular case with maximum() function, static >> checking does not help in producing the most correct code; if you need >> to ensure the highest correctness, you must use a language with >> *mandatory* infinite precision integers. > > Or using the new suffix return syntax in C++0x. Something like > > template > [] maximum( T0 a, T1 b) { return a > b ? a : b; } > > Where the return type is deduced at compile time. Indeed. This is generic programming. And it happens that in Lisp (and I assume in languages such as Python), sinte types are not checked at compilation time, all the functions you write are always generic functions. In particular, the property "arguments are not comparable" is not something that can be determined at compilation time, since the program may add a compare method for the given argument at run-time (if the comparison operator used is a generic function). -- __Pascal Bourguignon__ http://www.informatimago.com/ From ifrit at underground Thu Sep 30 04:19:42 2010 From: ifrit at underground (Ifrit) Date: Thu, 30 Sep 2010 10:19:42 +0200 Subject: System idle time under Linux References: Message-ID: <4ca44815$0$41117$e4fe514c@news.xs4all.nl> Hugo L?veill? heeft het volgende neergekrabbeld: > > Thanks, will take a closer look on that > > But to get me started, how would you get, via python, the info from that >From a unix command prompt use the cat command to view their contents. You'll notice that they plain text files with very informative content: # cat /proc/stat cpu 3799492 103198 3546212 82899838 1183162 137849 118698 0 0 cpu0 1071799 22089 1141874 20155255 262512 2714 1704 0 0 cpu1 926425 27349 694583 21016324 302881 2488 4253 0 0 cpu2 938331 29131 736412 21113333 202243 123636 104475 0 0 cpu3 862937 24629 973343 20614926 415526 9011 8266 0 0 intr 153564472 28 10 0 0 0 0 0 7 1 3018879 0 0 173 0 0 0 62 55962320 0 0 0 0 0 9620148 749 0 0 0 0 0 0 0 0 0 0 3136950 4742352 320982 1 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 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 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 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 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 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 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 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 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 ctxt 478141455 btime 1285609820 processes 45111 procs_running 1 procs_blocked 0 softirq 195073836 0 34148873 30536 22265404 4426357 0 55946604 22390786 370319 55494957 -- Ifrit http://nl.wikipedia.org/wiki/Ifriet From ifrit at underground Thu Sep 30 04:22:31 2010 From: ifrit at underground (Ifrit) Date: Thu, 30 Sep 2010 10:22:31 +0200 Subject: System idle time under Linux References: <4ca44815$0$41117$e4fe514c@news.xs4all.nl> Message-ID: <4ca448be$0$41117$e4fe514c@news.xs4all.nl> Ifrit heeft het volgende neergekrabbeld: > Hugo L?veill? heeft het volgende neergekrabbeld: > >> >> Thanks, will take a closer look on that >> >> But to get me started, how would you get, via python, the info from that > > From a unix command prompt use the cat command to view their contents. > You'll notice that they plain text files with very informative content: > > # cat /proc/stat And the man proc command gives info on the format of the content: /proc/stat kernel/system statistics. Varies with architecture. Common entries include: cpu 3357 0 4313 1362393 The amount of time, measured in units of USER_HZ (1/100ths of a second on most architectures, use sysconf(_SC_CLK_TCK) to obtain the right value), that the system spent in user mode, user mode with low priority (nice), system mode, and the idle task, respectively. The last value should be USER_HZ times the second entry in the uptime pseudo-file. In Linux 2.6 this line includes three additional columns: iowait - time waiting for I/O to complete (since 2.5.41); irq - time servicing interrupts (since 2.6.0-test4); softirq - time servicing softirqs (since 2.6.0-test4). Since Linux 2.6.11, there is an eighth column, steal - stolen time, which is the time spent in other operating systems when running in a virtualized environment Since Linux 2.6.24, there is a ninth column, guest, which is the time spent running a virtual CPU for guest operating systems under the control of the Linux kernel. page 5741 1808 The number of pages the system paged in and the number that were paged out (from disk). swap 1 0 The number of swap pages that have been brought in and out. intr 1462898 This line shows counts of interrupts serviced since boot time, for each of the possible system interrupts. The first column is the total of all interrupts serviced; each subsequent column is the total for a particular interrupt. disk_io: (2,0):(31,30,5764,1,2) (3,0):... (major,disk_idx):(noinfo, read_io_ops, blks_read, write_io_ops, blks_written) (Linux 2.4 only) ctxt 115315 The number of context switches that the system underwent. btime 769041601 boot time, in seconds since the Epoch (January 1, 1970). processes 86031 Number of forks since boot. procs_running 6 Number of processes in runnable state. (Linux 2.5.45 onwards.) procs_blocked 2 Number of processes blocked waiting for I/O to complete. (Linux 2.5.45 onwards.) -- Ifrit http://nl.wikipedia.org/wiki/Ifriet From rNOSPAMon at flownet.com Thu Sep 30 04:40:43 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 01:40:43 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: In article <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21 at y12g2000prb.googlegroups.com>, TheFlyingDutchman wrote: > > > Yes. ?Nonetheless, the maximum() function does exactly what it is intended > > > to do *with the inputs it receives*. ?The failure is outside the function; > > > it did the right thing with the data actually passed to it, the problem > > > was a user misunderstanding as to what data were being passed to it. > > > > > So there's a bug -- there's code which does not do what it was intended > > > to do. ?However, that bug is in the caller, not in the maximum() > > > function. > > > > > This is an important distinction -- it means we can write a function > > > which performs that function reliably. ?Now we just need to figure out > > > how to call it with valid data... :) > > > > We lost some important context somewhere along the line: > > > > > > > in C I can have a function maximum(int a, int b) that will always > > > > > work. Never blow up, and never give an invalid answer. If someone > > > > > tries to call it incorrectly it is a compile error. > > > > Please take note of the second sentence. > > > > One way or another, this claim is plainly false. ?The point I was trying > > to make is not so much that the claim is false (someone else was already > > doing that), but that it can be demonstrated to be false without having > > to rely on any run-time input. > > > > The second sentence is not disproved by a cast from one datatype to > another (which changes the value) that happens before maximum() is > called. You can't have it both ways. Either I am calling it incorrectly, in which case I should get a compiler error, or I am calling it correctly, and I should get the right answer. That I got neither does in fact falsify the claim. The only way out of this is to say that maximum(8589934592, 1) returning 1 is in fact "correct", in which case we'll just have to agree to disagree. rg From as at sci.fi Thu Sep 30 04:41:48 2010 From: as at sci.fi (Anssi Saari) Date: Thu, 30 Sep 2010 11:41:48 +0300 Subject: how to get partition information of a hard disk with python References: Message-ID: Nobody writes: > On Wed, 22 Sep 2010 00:31:04 +0200, Hellmut Weber wrote: > >> I'm looking for a possibility to access the partiton inforamtion of a >> hard disk of my computer from within a python program. > > Have you considered parsing /proc/partitions? One could also just read the partition table directly, it's on the first sector usually. (Assuming a PC without a GUID partition table...) The partition table is just 64 bytes at offset 446 into the sector. In unixlikes you can just open the disk with file.open()... Then again, unixlikes other than Linux have somewhat different ideas about partitioning... From zzbbaadd at aol.com Thu Sep 30 04:43:38 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 01:43:38 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: <785d0d80-c4ec-4e02-94ff-fe18dc4a7ddd@e34g2000prn.googlegroups.com> On Sep 30, 1:02?am, Paul Rubin wrote: > >> > > > in C I can have a function maximum(int a, int b) that will always > >> > > > work. Never blow up, and never give an invalid answer. If someone > >> > > > tries to call it incorrectly it is a compile error. > > The second sentence is not disproved by a cast from one datatype to > > another (which changes the value) that happens before maximum() is called. > > ? ? int maximum(int a, int b); > > ? ? int foo() { > ? ? ? int (*barf)() = maximum; > ? ? ? return barf(3); > ? ? } > > This compiles fine for me. ?Where is the cast? ?Where is the error message? > Are you saying barf(3) doesn't call maximum? With Tiny C on my system, your code does not cause maximum to give an incorrect value, or to blow up: int maximum(int a, int b) { printf("entering maximum %d %d\n",a,b); if ( a > b ) return a; else return b; } int foo() { int (*barf)() = maximum; return barf(3); } int main (int argc, char *argv[]) { printf("maximum is %d\n",foo()); } ------------- output ----------------------------------- entering maximum 3 4198400 maximum is 4198400 From zzbbaadd at aol.com Thu Sep 30 04:55:39 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 01:55:39 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: On Sep 30, 1:40?am, RG wrote: > In article > <5bf24e59-1be0-4d31-9fa7-c03a8bf9b... at y12g2000prb.googlegroups.com>, > > > > > > ?TheFlyingDutchman wrote: > > > > Yes. ?Nonetheless, the maximum() function does exactly what it is intended > > > > to do *with the inputs it receives*. ?The failure is outside the function; > > > > it did the right thing with the data actually passed to it, the problem > > > > was a user misunderstanding as to what data were being passed to it. > > > > > So there's a bug -- there's code which does not do what it was intended > > > > to do. ?However, that bug is in the caller, not in the maximum() > > > > function. > > > > > This is an important distinction -- it means we can write a function > > > > which performs that function reliably. ?Now we just need to figure out > > > > how to call it with valid data... :) > > > > We lost some important context somewhere along the line: > > > > > > > in C I can have a function maximum(int a, int b) that will always > > > > > > work. Never blow up, and never give an invalid answer. If someone > > > > > > tries to call it incorrectly it is a compile error. > > > > Please take note of the second sentence. > > > > One way or another, this claim is plainly false. ?The point I was trying > > > to make is not so much that the claim is false (someone else was already > > > doing that), but that it can be demonstrated to be false without having > > > to rely on any run-time input. > > > The second sentence is not disproved by a cast from one datatype to > > another (which changes the value) that happens before maximum() is > > called. > > You can't have it both ways. ?Either I am calling it incorrectly, in > which case I should get a compiler error, or I am calling it correctly, > and I should get the right answer. ?That I got neither does in fact > falsify the claim. ?The only way out of this is to say that > maximum(8589934592, 1) returning 1 is in fact "correct", in which case > we'll just have to agree to disagree. > 1) long trying_to_break_maximum = 8589934592; 2) /* compiler adds */ int created_to_allow_maximum_call = (int) trying_to_break_maximum; 3) maximum(created_to_allow_maximum_call, 1); I think we have to agree to disagree, because I don't see the lack of a compiler error at step 2 as a problem with the maximum() function. From lie.1296 at gmail.com Thu Sep 30 04:55:57 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 30 Sep 2010 18:55:57 +1000 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> Message-ID: <4ca44fea@dnews.tpgi.com.au> On 09/30/10 16:09, TheFlyingDutchman wrote: > >> >> That argument can be made for dynamic language as well. If you write in >> dynamic language (e.g. python): >> >> def maximum(a, b): >> return a if a > b else b >> >> The dynamic language's version of maximum() function is 100% correct -- >> if you passed an uncomparable object, instead of a number, your call of >> it is incorrect; you just didn't pass the right sort of data. And that's >> your problem as a caller. >> >> In fact, since Python's integer is infinite precision (only bounded by >> available memory); in practice, Python's version of maximum() has less >> chance of producing erroneous result. > > "in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. " > > Dynamic typed languages like Python fail in this case on "Never blows > up". How do you define "Never blows up"? Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow up, and of the worst kind since it passes silently. From deets at web.de Thu Sep 30 04:59:28 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 30 Sep 2010 10:59:28 +0200 Subject: utf-8 and ctypes References: Message-ID: <87iq1nobdb.fsf@web.de> Brendan Miller writes: > 2010/9/29 Lawrence D'Oliveiro : >> In message , Brendan >> Miller wrote: >> >>> It seems that characters not in the ascii subset of UTF-8 are >>> discarded by c_char_p during the conversion ... >> >> Not a chance. >> >>> ... or at least they don't print out when I go to print the string. >> >> So it seems there?s a problem on the printing side. What happens when you >> construct a UTF-8-encoded string directly in Python and try printing it the >> same way? > > Doing this seems to confirm something is broken in ctypes w.r.t. UTF-8... > > if I enter: > str = "???????" What is this? Which encoding is used by your editor to produce this byte-string? If you want to be sure you have the right encoding, you need to do this: - put a coding: utf-8 (or actually whatever your editor uses) in the first or second line - use unicode literals. That are the funny little strings with a "u" in front of them. They will be *decoded* using the declared encoding. - when passing this to C, explicitly *encode* with utf-8 first. Diez From rbrown780 at gmail.com Thu Sep 30 05:02:39 2010 From: rbrown780 at gmail.com (roronron) Date: Thu, 30 Sep 2010 09:02:39 -0000 Subject: install 3.1 Message-ID: My python installed but the gui gives me syntax error on any code I type or paste in. Newbie needs help. From clp2 at rebertia.com Thu Sep 30 05:16:34 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 30 Sep 2010 02:16:34 -0700 Subject: install 3.1 In-Reply-To: References: Message-ID: On Thu, Sep 30, 2010 at 2:02 AM, roronron wrote: > My python installed but the gui gives me syntax error on any code I type > or paste in. Newbie needs help. Post the full, exact text of the error message. See also: http://www.catb.org/esr/faqs/smart-questions.html Cheers, Chris From funthyme at gmail.com Thu Sep 30 05:26:23 2010 From: funthyme at gmail.com (John Pinner) Date: Thu, 30 Sep 2010 02:26:23 -0700 (PDT) Subject: System idle time under Linux References: Message-ID: <51c5b69c-1a8e-47d7-b90d-f377334c69ae@k10g2000yqa.googlegroups.com> On Sep 29, 7:36?pm, Hugo L?veill? wrote: > Good point > > One I am looking for, is time since last user mouse or keyboard action. > So I guess I am looking for the exact same thing a screensaver is > looking for The command who -Hu). will give you idle time for each logged-in user ( H - print headers; u - list users ) and you could run this command via subprocess, then read and parse its output. Alternatively you could parse the same file(s) as who - I think it reads /var/run/utmp - but that would be a lot more work, as it is a binary file (run man utmp to see its format, use the struct module to decode) Best wishes, John -- From pc at p-cos.net Thu Sep 30 05:27:48 2010 From: pc at p-cos.net (Pascal Costanza) Date: Thu, 30 Sep 2010 11:27:48 +0200 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> Message-ID: <8gj3gkFtsmU1@mid.individual.net> On 30/09/2010 08:09, TheFlyingDutchman wrote: > >> >> That argument can be made for dynamic language as well. If you write in >> dynamic language (e.g. python): >> >> def maximum(a, b): >> return a if a> b else b >> >> The dynamic language's version of maximum() function is 100% correct -- >> if you passed an uncomparable object, instead of a number, your call of >> it is incorrect; you just didn't pass the right sort of data. And that's >> your problem as a caller. >> >> In fact, since Python's integer is infinite precision (only bounded by >> available memory); in practice, Python's version of maximum() has less >> chance of producing erroneous result. > > "in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. " > > Dynamic typed languages like Python fail in this case on "Never blows > up". They don't "blow up". They may throw an exception, on which you can act. You make it sound like a core dump, which it isn't. Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ From ian-news at hotmail.com Thu Sep 30 05:52:40 2010 From: ian-news at hotmail.com (Ian Collins) Date: Thu, 30 Sep 2010 22:52:40 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: <7xlj6j3bh2.fsf@ruckus.brouhaha.com> References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: <8gj4v8Fc8aU1@mid.individual.net> On 09/30/10 09:02 PM, Paul Rubin wrote: > > int maximum(int a, int b); > > int foo() { > int (*barf)() = maximum; > return barf(3); > } > > This compiles fine for me. Where is the cast? Where is the error message? > Are you saying barf(3) doesn't call maximum? Try a language with stricter type checking: CC /tmp/u.c "/tmp/u.c", line 7: Error: Cannot use int(*)(int,int) to initialize int(*)(). "/tmp/u.c", line 8: Error: Too many arguments in call to "int(*)()". -- Ian Collins From nobody at nowhere.com Thu Sep 30 06:01:32 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 30 Sep 2010 11:01:32 +0100 Subject: how to get partition information of a hard disk with python References: Message-ID: On Thu, 30 Sep 2010 11:41:48 +0300, Anssi Saari wrote: >>> I'm looking for a possibility to access the partiton inforamtion of a >>> hard disk of my computer from within a python program. >> >> Have you considered parsing /proc/partitions? > > One could also just read the partition table directly, it's on the > first sector usually. (Assuming a PC without a GUID partition > table...) The partition table is just 64 bytes at offset 446 into the > sector. In unixlikes you can just open the disk with file.open()... > Then again, unixlikes other than Linux have somewhat different ideas > about partitioning... Apart from the portability issues, you usually need elevated privileges to read the disk directly, while /proc/partitions is normally readable by anyone. OTOH, many of the tasks for which partition information is necessary would require root privilege anyhow. From zzbbaadd at aol.com Thu Sep 30 06:14:47 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 03:14:47 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> > > > "in C I can have a function maximum(int a, int b) that will always > > work. Never blow up, and never give an invalid answer. " > > > Dynamic typed languages like Python fail in this case on "Never blows > > up". > > How do you define "Never blows up"? Never has execution halt. I think a key reason in the big rise in the popularity of interpreted languages is that when execution halts, they normally give a call stack and usually a good reason for why things couldn't continue. As opposed to compiled languages which present you with a blank screen and force you to - fire up a debugger, or much much worse, look at a core dump - to try and discern all the information the interpreter presents to you immediately. > > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > up, and of the worst kind since it passes silently. If I had to choose between "blow up" or "invalid answer" I would pick "invalid answer". In this example RG is passing a long literal greater than INT_MAX to a function that takes an int and the compiler apparently didn't give a warning about the change in value as it created the cast to an int, even with the option -Wall (all warnings). I think it's legitmate to consider that an option for a warning/error on this condition should be available. As far the compiler generating code that checks for a change in value at runtime when a number is cast to a smaller data type, I think that's also a legitimate request for a C compiler option (in addition to other runtime check options like array subscript out of bounds). From joel.hedlund at gmail.com Thu Sep 30 06:17:18 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 03:17:18 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness Message-ID: I'm having a weird problem with the 'External Tools' plugin for gedit, that seems to get weirder the more I dig into it. When I start gedit by clicking a launcher (from the Ubuntu menu, panel or desktop) everything is dandy and the 'External Tools' plugin works as expected. When gedit is launched from the terminal, the 'External Tools' plugin is greyed out in the plugin list and I get this traceback on stderr: $ gedit Traceback (most recent call last): File "/usr/lib/gedit-2/plugins/externaltools/__init__.py", line 24, in from manager import Manager File "/usr/lib/gedit-2/plugins/externaltools/manager.py", line 27, in import hashlib File "/usr/lib/python2.6/hashlib.py", line 136, in md5 = __get_builtin_constructor('md5') File "/usr/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor import _md5 ImportError: No module named _md5 ** (gedit:8714): WARNING **: Error loading plugin 'External Tools' The same thing happens if I try to activate the plugin from a gedit launched from the terminal (if it's already been deactivated from a gedit launched from the menu). My analysis is that gedit tries to import the externaltools package, which imports hashlib, which tries to import _hashlib but fails and falls back to _md5 which also fails, which apparently /should not happen/, or so google tells me. One of _hashlib and _md5 should always exist. However, importing _hashlib in a python interpreter works just fine, i.e: $ python -c 'import _hashlib' returns nothing. What also puzzles me is that I don't seem to have _hashlib* anywhere on my system (am I supposed to?) and getting the __file__ attribute off the module doesn't work, and help(_hashlib) says FILE is (built-in). >>> import _hashlib >>> _hashlib.__file__ Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute '__file__' Google drops vague hints that there may be a a virtualenv that one might have to rebuild, but in that case I have no idea where to begin. I've tried reinstalling the ubuntu packages gedit, gedit-common and gedit-plugins, but to no avail. And the machine runs a fully updated ubuntu karmic koala (10.4) that has survived numerous dist-upgrades, if that's of any use to anybody. I'd appreciate any input on this, even if it's just new bushes to whack for scaring the problem out into the light. Cheers! /Joel From sion at viridian.paintbox Thu Sep 30 06:21:49 2010 From: sion at viridian.paintbox (Sion Arrowsmith) Date: Thu, 30 Sep 2010 10:21:49 GMT Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <20100929114701.110c18b5@geekmail.INVALID> Message-ID: <1xZoo.1781$Fk6.1722@newsfe13.ams2> Andreas Waldenburger wrote: > > [ ... ] > Boolean values behave like the values 0 and 1, respectively, in > almost all contexts, the exception being that when converted to a > string, the strings "False" or "True" are returned, respectively. Hmm. So the original problem of: button = gtk.Button(("False,", "True,")[fill==True]) could also rewritten as: button = gtk.Button(str(bool(fill))+",") -- \S under construction From affdfsdfdsfsd at b.com Thu Sep 30 06:41:01 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 30 Sep 2010 10:41:01 GMT Subject: will Gnome 3.0 kill pygtk? Message-ID: <4ca4693d$0$40283$4fafbaef@reader2.news.tin.it> Hi! It seem that the new version of gnome 3.0 will dismiss pygtk support. link: [1] http://live.gnome.org/TwoPointNinetyone/ (search killing pygtk) [2] http://live.gnome.org/GnomeGoals/PythonIntrospectionPorting i'm studying pygtk right now, am i wasting my time considering that my preferred platform is linux/gnome? thanks Nico From bruno.desthuilliers at gmail.com Thu Sep 30 06:42:29 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 30 Sep 2010 03:42:29 -0700 (PDT) Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: On 29 sep, 19:20, Seebs wrote: > On 2010-09-29, Tracubik wrote: > > button = gtk.Button(("False,", "True,")[fill==True]) > Oh, what a nasty idiom. > Well, it's not very different from dict-based dispatch , which is the core of OO polymorphic dispatch in quite a few dynamic OOPLs. Anyway, it's a common Python idiom and one that's not specially hard to grasp so I don't see any legibility problem here. From hugol at fastmail.net Thu Sep 30 06:58:47 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Thu, 30 Sep 2010 06:58:47 -0400 Subject: System idle time under Linux In-Reply-To: <51c5b69c-1a8e-47d7-b90d-f377334c69ae@k10g2000yqa.googlegroups.com> References: <51c5b69c-1a8e-47d7-b90d-f377334c69ae@k10g2000yqa.googlegroups.com> Message-ID: <1285844327.4647.1397663319@webmail.messagingengine.com> Ok after some testing, what the who -Hu is giving me is the idle time of each running open shell. The first line always return a "?" as the IDLE time. ex: NAME LINE TIME IDLE PID COMMENT vg0619hl :0 2010-09-30 06:10 ? 13091 vg0619hl pts/1 2010-09-30 06:27 00:11 14084 (:0.0) vg0619hl pts/2 2010-09-30 06:54 . 14084 (:0.0) On Thu, 30 Sep 2010 02:26 -0700, "John Pinner" wrote: > On Sep 29, 7:36?pm, Hugo L?veill? wrote: > > Good point > > > > One I am looking for, is time since last user mouse or keyboard action. > > So I guess I am looking for the exact same thing a screensaver is > > looking for > > The command > > who -Hu). > > > will give you idle time for each logged-in user > > ( H - print headers; u - list users ) > > and you could run this command via subprocess, then read and parse its > output. > > Alternatively you could parse the same file(s) as who - I think it > reads /var/run/utmp - but that would be a lot more work, as it is a > binary file (run man utmp to see its format, use the struct module to > decode) > > Best wishes, > > John > -- > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hugo L?veill? hugol at fastmail.net From santiago.caracol at gmail.com Thu Sep 30 07:05:21 2010 From: santiago.caracol at gmail.com (Santiago Caracol) Date: Thu, 30 Sep 2010 04:05:21 -0700 (PDT) Subject: sys.setrecursionlimit() and regular expressions Message-ID: Hello, in my program I use recursive functions. A recursion limit of 10 would be by far sufficient. Yet, I also use some (not very complicated) regular expressions, which only compile if I set the recursion limit to 100, or so. This means, of course, an unnecessary loss of speed. Can I use one recursion limit for my functions and another one for the re module? Santiago From tom.conneely at gmail.com Thu Sep 30 07:06:03 2010 From: tom.conneely at gmail.com (Tom Conneely) Date: Thu, 30 Sep 2010 04:06:03 -0700 (PDT) Subject: PyCObject & malloc creating memory leak References: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> Message-ID: <4bf06438-5c31-4809-89bb-c335289fffe9@a15g2000yqm.googlegroups.com> Thanks for your reply, you've given me plenty to think about On Sep 29, 11:51?pm, Antoine Pitrou wrote: > > > My original plan was to have the data processing and data acquisition > > functions running in separate processes, with a multiprocessing.Queue > > for passing the raw data packets. The raw data is read in as a char*, > > with a non constant length, hence I have allocated memory using > > PyMem_Malloc and I am returning from the acquisition function a > > PyCObject containing a pointer to this char* buffer, along with a > > destructor. > > That sounds overkill, and I also wonder how you plan to pass that > object in a multiprocessing Queue (which relies on objects being > pickleable). Why don't you simply create a PyString object instead? Could you elaborate on why you feel this is overkill? Also, your right about passing the PyCObjects through a Queue, something which I hadn't really considered, so I've switched to using python strings as you suggested, an overhead I hoped to avoid but you can't win them all I suppose. > > So if I call these functions in a loop, e.g. The following will > > generate ~10GB of data > > > ? ? x = MyClass() > > ? ? for i in xrange(0, 10 * 2**20): > > ? ? ? ? c = x.malloc_buffer() > > ? ? ? ? x.retrieve_buffer(c) > > > All my memory disapears, until python crashes with a MemoryError. By > > placing a print in the destructor function I know it's being called, > > however it's not actually freeing the memory. So in short, what am I > > doing wrong? > > Python returns memory to the OS by calling free(). Not all OSes > actually relinquish memory when free() is called; some will simply set > it aside for the next allocation. > Another possible (and related) issue is memory fragmentation. Again, it > depends on the memory allocator. Yes, I know that's the case but the "freed" memory should be used for the next allocation, or atleast at some point before python runs out of memory. Anyway, this is besides the point as I've switched to using strings. Again thanks for taking the time to help me out, Tom Conneely From joel.hedlund at gmail.com Thu Sep 30 07:34:59 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 04:34:59 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: Message-ID: <2f87f2f8-3f23-42df-a5b0-3c5b84d51870@d25g2000yqc.googlegroups.com> bah, I meant to say I'm running "a fully updated ubuntu lucid lynx (10.4)". From __peter__ at web.de Thu Sep 30 07:35:09 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 13:35:09 +0200 Subject: sys.setrecursionlimit() and regular expressions References: Message-ID: Santiago Caracol wrote: > in my program I use recursive functions. A recursion limit of 10 would > be by far sufficient. Yet, I also use some (not very complicated) > regular expressions, which only compile if I set the recursion limit > to 100, or so. This means, of course, an unnecessary loss of speed. Why do you think so? The recursion limit has no effect on the speed of your script. It's just a number that the interpreter checks against. Peter From santiago.caracol at gmail.com Thu Sep 30 07:53:32 2010 From: santiago.caracol at gmail.com (Santiago Caracol) Date: Thu, 30 Sep 2010 04:53:32 -0700 (PDT) Subject: sys.setrecursionlimit() and regular expressions References: Message-ID: > Why do you think so? The recursion limit has no effect on the speed of your > script. It's just a number that the interpreter checks against. Yes, sorry. I was just about to explain that. The 'of course' in my post was silly. In MY program, the recursion limit is relevant for performance, because I use constructs of the following kind: def analyze(sentence): try: ... except RuntimeError: ... I.e. I try to apply certain recursive rules to a sentence. If this doesn't lead to any results (up to recursion limit N), then I skip the analysis. From __peter__ at web.de Thu Sep 30 07:54:07 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 13:54:07 +0200 Subject: gedit 'External Tools' plugin hashlib weirdness References: Message-ID: Joel Hedlund wrote: > I'm having a weird problem with the 'External Tools' plugin for gedit, > that seems to get weirder the more I dig into it. When I start gedit > by clicking a launcher (from the Ubuntu menu, panel or desktop) > everything is dandy and the 'External Tools' plugin works as expected. > When gedit is launched from the terminal, the 'External Tools' plugin > is greyed out in the plugin list and I get this traceback on stderr: > > $ gedit > Traceback (most recent call last): > File "/usr/lib/gedit-2/plugins/externaltools/__init__.py", line 24, > in > from manager import Manager > File "/usr/lib/gedit-2/plugins/externaltools/manager.py", line 27, > in > import hashlib > File "/usr/lib/python2.6/hashlib.py", line 136, in > md5 = __get_builtin_constructor('md5') > File "/usr/lib/python2.6/hashlib.py", line 63, in > __get_builtin_constructor > import _md5 > ImportError: No module named _md5 > > ** (gedit:8714): WARNING **: Error loading plugin 'External Tools' > > The same thing happens if I try to activate the plugin from a gedit > launched from the terminal (if it's already been deactivated from a > gedit launched from the menu). > > My analysis is that gedit tries to import the externaltools package, > which imports hashlib, which tries to import _hashlib but fails and > falls back to _md5 which also fails, which apparently /should not > happen/, or so google tells me. One of _hashlib and _md5 should always > exist. > > However, importing _hashlib in a python interpreter works just fine, > i.e: > > $ python -c 'import _hashlib' > > returns nothing. What also puzzles me is that I don't seem to have > _hashlib* anywhere on my system (am I supposed to?) and getting the > __file__ attribute off the module doesn't work, and help(_hashlib) > says FILE is (built-in). > >>>> import _hashlib >>>> _hashlib.__file__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute '__file__' > > Google drops vague hints that there may be a a virtualenv that one > might have to rebuild, but in that case I have no idea where to > begin. > > I've tried reinstalling the ubuntu packages gedit, gedit-common and > gedit-plugins, but to no avail. And the machine runs a fully updated > ubuntu karmic koala (10.4) that has survived numerous dist-upgrades, > if that's of any use to anybody. > > I'd appreciate any input on this, even if it's just new bushes to > whack for scaring the problem out into the light. You could add import sys print sys.executable at the top of /usr/lib/gedit-2/plugins/externaltools/__init__.py Maybe there's some confusion about what python interpreter should be used. Peter From __peter__ at web.de Thu Sep 30 08:10:38 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 14:10:38 +0200 Subject: sys.setrecursionlimit() and regular expressions References: Message-ID: Santiago Caracol wrote: > >> Why do you think so? The recursion limit has no effect on the speed of >> your script. It's just a number that the interpreter checks against. > > Yes, sorry. I was just about to explain that. The 'of course' in my > post was silly. > > In MY program, the recursion limit is relevant for performance, > because I use constructs of the following kind: > > def analyze(sentence): > try: > ... > except RuntimeError: > ... > > I.e. I try to apply certain recursive rules to a sentence. If this > doesn't lead to any results (up to recursion limit N), > then I skip the analysis. Here's a depth limitation decorator that you can apply selectively. In the example below you can have as many gamma() calls as the interpreter's recursion limit permits, but only a total of 10 calls of alpha() and beta(). import random class TooDeep(Exception): pass _limit = 10 def limited(f): def g(*args, **kw): global _limit if not _limit: raise TooDeep _limit -= 1 try: return f(*args, **kw) finally: _limit += 1 return g @limited def alpha(n): print "alpha", n beta(n+1) @limited def beta(n): print "beta", n gamma(n+1) def gamma(n): print "gamma", n random.choice([alpha, beta, gamma])(n+1) if __name__ == "__main__": try: alpha(0) except TooDeep as e: print e Peter From Antoon.Pardon at rece.vub.ac.be Thu Sep 30 08:10:43 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 30 Sep 2010 14:10:43 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: <20100930121043.GD2272@rcpc42.vub.ac.be> On Sun, Sep 26, 2010 at 03:20:18PM +0000, Grant Edwards wrote: > On 2010-09-26, Paul Rubin wrote: > > Steven D'Aprano writes: > >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > > > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > > Because > > 3 * "spam" == "spam" + "spam" + "spam" > > Just like > > 3 * 6 = 6 + 6 + 6 > > So now I suppose "+" for string concatenation is a bad thing. Well I find it an unfortunate choice. The problem is, that it is not that unusual to want some class to have the possibility of both addition and concatenation. But since we only one symbol for both operations, you will have to loose some consistency over this. -- Antoon Pardon From rustompmody at gmail.com Thu Sep 30 08:14:56 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 30 Sep 2010 17:44:56 +0530 Subject: PyRTF object model Message-ID: I am trying to use PyRTF. I gather that an RTF doc consists of a list of sections, a section consists of a list of paras, paras seem to be just text (not sure on that one) Some questions: When does one end one section and start another? How does one handle lists (as in numbered, bulleted etc)? From nick_keighley_nospam at hotmail.com Thu Sep 30 08:19:04 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 30 Sep 2010 05:19:04 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> On 27 Sep, 20:29, p... at informatimago.com (Pascal J. Bourguignon) wrote: > namekuseijin writes: > > Fact is: ?almost all user data from the external words comes into > > programs as strings. ?No typesystem or compiler handles this fact all > > that graceful... > > I would even go further. > > Types are only part of the story. ?You may distinguish between integers > and floating points, fine. ?But what about distinguishing between > floating points representing lengths and floating points representing > volumes? ?Worse, what about distinguishing and converting floating > points representing lengths expressed in feets and floating points > representing lengths expressed in meters. fair points > If you start with the mindset of static type checking, you will consider > that your types are checked and if the types at the interface of two > modules matches you'll think that everything's ok. ?And six months later > you Mars mission will crash. do you have any evidence that this is actually so? That people who program in statically typed languages actually are prone to this "well it compiles so it must be right" attitude? > On the other hand, with the dynamic typing mindset, you might even wrap > your values (of whatever numerical type) in a symbolic expression > mentionning the unit and perhaps other meta data, so that when the other > module receives it, it may notice (dynamically) that two values are not > of the same unit, but if compatible, it could (dynamically) convert into > the expected unit. ?Mission saved! they *may* do this but do they *actually* do it? My (limited) experience of dynamically typed languges is everynow and again you attempt to apply an operator to the wrong type of operand and kerblam! If your testing is inadaquate then it's inadaquate whatever the typiness of your language. From joel.hedlund at gmail.com Thu Sep 30 08:26:45 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 05:26:45 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: Message-ID: How do I catch output to stdout/stderr when launching from a launcher? I added this to /usr/lib/gedit-2/plugins/externaltools/__init__.py: import sys f = open('/tmp/eraseme.txt', 'w') print >> f, "The executable is %r." % sys.executable f.close() In both cases (launcher/termial) the contents of eraseme.txt are: The executable is '/usr/bin/python'. From tom.conneely at gmail.com Thu Sep 30 08:29:17 2010 From: tom.conneely at gmail.com (Tom Conneely) Date: Thu, 30 Sep 2010 05:29:17 -0700 (PDT) Subject: PyCObject & malloc creating memory leak References: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> <4bf06438-5c31-4809-89bb-c335289fffe9@a15g2000yqm.googlegroups.com> Message-ID: <08338e8a-28d3-46b9-b4a5-6502e7a9d0ea@z28g2000yqh.googlegroups.com> I'm posting this last message as I've found the source of my initial memory leak problem, unfortunately it was an embarrassingly basic mistake. In my defence I've got a horrible cold, but I'm just making excuses. I begin by mallocing the memory, which gives me a pointer "foo" to that memory: char *foo = PyMem_Malloc(1024 * sizeof(char)); then assign a value to it: foo = "foo"; of course what this actually does is change the pointer to point to a new memory address containing a constant "foo". Hence, when I free the memory in the PYCObject's destructor, the pointer is for the constant "foo", not the memory I initially allocated. I only posted this to help people searching, sorry for the noise. Tom Conneely From namekuseijin at gmail.com Thu Sep 30 08:35:20 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Thu, 30 Sep 2010 05:35:20 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Message-ID: <6784f34c-2948-408b-b2eb-4a3b171c5afe@k10g2000yqa.googlegroups.com> On 29 set, 11:04, w_a_x_man wrote: > On Sep 26, 9:24?am, p... at informatimago.com (Pascal J. Bourguignon) > wrote: > > > > > Xah Lee writes: > > > here's a interesting toy list processing problem. > > > > I have a list of lists, where each sublist is labelled by > > > a number. I need to collect together the contents of all sublists > > > sharing > > > the same label. So if I have the list > > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > > r) (5 s t)) > > > > where the first element of each sublist is the label, I need to > > > produce: > > > > output: > > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > > a Mathematica solution is here: > > >http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > > > R5RS Scheme lisp solution: > > >http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_... > > > by Sourav Mukherjee > > > > also, a Common Lisp solution can be found here: > > >http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1de... > > > It's too complex. Just write: > > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > > ? ? ? ? ? ? ? (2 o p) (4 q r) (5 s t)))) > > > ? (mapcar (lambda (class) (reduce (function append) class :key (function rest))) > > ? ? ? ? ? ?(com.informatimago.common-lisp.list:equivalence-classes list :key (function first))) > > > ? ?) > > > --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) > > > -- > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/ > > Ruby: > > [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, > 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], > [5, 's', 't']]. > group_by{|x| x.first}.values.map{|x| x.map{|y| y[1..-1]}.flatten} > > ? ? ==>[["s", "t"], ["a", "b"], ["c", "d", "i", "j"], > ?["e", "f", "k", "l", "o", "p"], > ?["g", "h"], ["m", "n", "q", "r"]] cool, it comes with order all fucked up. This is something I was criticized for before, though not all that important to most functional processing. Not the case here, though. here's a scheme version that is hopefully better than the given one: (define (dig in) (if (null? in) '() (let* ((n (first-of-first in)) (all-n (filter in (lambda (x) (eq? n (first x))))) (all-but-n (filter in (lambda (x) (not (eq? n (first x))))))) (pair (fold all-n (lambda (i o) (pair (second i) (pair (third i) o)))) (dig all-but-n))))) ; given these aliases to lisp n00bs (define pair cons) (define first car) (define rest cdr) (define first-of-first caar) (define second cadr) (define third caddr) ; and these well-known functions (non-tail-recursive for benefit of n00bs) (define (fold ls f) ; AKA reduce (if (null? ls) '() (f (first ls) (fold (rest ls) f)))) (define (filter ls f) (fold ls (lambda (i o) (if (f i) (pair i o) o)))) ; testing (let ((in '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t)))) (display (dig in)) (newline)) From nick_keighley_nospam at hotmail.com Thu Sep 30 08:36:17 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 30 Sep 2010 05:36:17 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: On 30 Sep, 11:14, TheFlyingDutchman wrote: > > > "in C I can have a function maximum(int a, int b) that will always > > > work. Never blow up, and never give an invalid answer. " > > > > Dynamic typed languages like Python fail in this case on "Never blows > > > up". > > > How do you define "Never blows up"? > > Never has execution halt. > > I think a key reason in the big rise in the popularity of interpreted > languages is that when execution halts, they normally give a call > stack and usually a good reason for why things couldn't continue. As > opposed to compiled languages which present you with a blank screen > and force you to - fire up a debugger, or much much worse, look at a > core dump - to try and discern all the information the interpreter > presents to you immediately. > > > > > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > > up, and of the worst kind since it passes silently. > > If I had to choose between "blow up" or "invalid answer" I would pick > "invalid answer". there are some application domains where neither option would be viewed as a satisfactory error handling strategy. Fly-by-wire, petro- chemicals, nuclear power generation. Hell you'd expect better than this from your phone! > In this example RG is passing a long literal greater than INT_MAX to a > function that takes an int and the compiler apparently didn't give a > warning about the change in value as it created the cast to an int, > even with the option -Wall (all warnings). I think it's legitmate to > consider that an option for a warning/error on this condition should > be available. As far the compiler generating code that checks for a > change in value at runtime when a number is cast to a smaller data > type, I think that's also a legitimate request for a C compiler option > (in addition to other runtime check options like array subscript out > of bounds). From joel.hedlund at gmail.com Thu Sep 30 08:37:52 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 05:37:52 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: Message-ID: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> FOUND IT! I added the line print >> f, '\n'.join(sorted(sys.path)) and diff:ed the files produced from terminal/launcher. When using the launcher, changes to PYTHONPATH done in ~/.bashrc are not picked up, and I apparently had an old reference to /usr/lib/ python2.4 sitting in there. Removed it, reloaded .bashrc, plugin now works. The question still remains why gnome disregards ~/.bashrc, but that's a whole other topic. Thanks a bunch, you guys are ever so helpful. From nhodgson at bigpond.net.au Thu Sep 30 08:41:14 2010 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Thu, 30 Sep 2010 22:41:14 +1000 Subject: will Gnome 3.0 kill pygtk? In-Reply-To: <4ca4693d$0$40283$4fafbaef@reader2.news.tin.it> References: <4ca4693d$0$40283$4fafbaef@reader2.news.tin.it> Message-ID: Tracubik: > i'm studying pygtk right now, am i wasting my time considering that my > preferred platform is linux/gnome? I expect the dynamic binding will be very similar to the current static binding but easier to keep up-to-date. There's already some use of dynamic binding in the recent PyGTK 2.22.0: http://www.daa.com.au/pipermail/pygtk/2010-September/019013.html Neil From joel.hedlund at gmail.com Thu Sep 30 08:48:59 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 05:48:59 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> Message-ID: <165a3586-8d0c-4d4e-930f-b8de8a62eb54@w19g2000yqb.googlegroups.com> I guess the moral of the story is don't always dist-upgrade. Reformat once in a while to remove old forgotten garbage. Clear the blood clots from your systems, so to say. From deets at web.de Thu Sep 30 08:54:39 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 30 Sep 2010 14:54:39 +0200 Subject: will Gnome 3.0 kill pygtk? References: <4ca4693d$0$40283$4fafbaef@reader2.news.tin.it> Message-ID: <87eicbo0hc.fsf@web.de> Tracubik writes: > Hi! > It seem that the new version of gnome 3.0 will dismiss pygtk support. > > link: > > [1] http://live.gnome.org/TwoPointNinetyone/ (search killing pygtk) > > [2] http://live.gnome.org/GnomeGoals/PythonIntrospectionPorting > > > i'm studying pygtk right now, am i wasting my time considering that my > preferred platform is linux/gnome? The important bit is that it will not ditch Python-support. I can't comment at the actual differences between pygtk and the upcoming reflection-based approach, but I doubt learning pygtk now is a waste. First of all, it will be quite a while until pygtk (and gnome 2.x) are really gone. And even if, the concepts stay the same, so unless pygtk adds an extra layer of abstraction (which AFAIK it doesn't), your knownledge is still usable - if not translatable one-to-one. Diez From wizzardx at gmail.com Thu Sep 30 09:08:08 2010 From: wizzardx at gmail.com (David) Date: Thu, 30 Sep 2010 15:08:08 +0200 Subject: Python becoming orphaned over ssh In-Reply-To: <4ca36e44$0$1584$742ec2ed@news.sonic.net> References: <4ca36e44$0$1584$742ec2ed@news.sonic.net> Message-ID: On Wed, Sep 29, 2010 at 6:49 PM, John Nagle wrote: > ? Python's signal handling for multithread and multiprocess programs > leaves something to be desired. > Thanks for the confirmation (that I'm not missing something obvious). I've reported a bug for this behavior in the Python issue tracker. In the meanwhile, I've made a workaround function called "check_call_and_monitor_ppids", that behaves like subprocess.check_call, except that it regularly checks if the parent pid "chain" (up to init process) changes during execution, and then terminates the subprocess and raises an exception. Actually I tried this before, and it didn't work. But strangely, it seems to work fine so long as I don't try to print any warning messages to stderr or stdout from the Python script (though, the called tool itself may print to stdout or stderr without problems). Quite peculiar... Anyway, I hope that one of the Python developers will fix this sometime. David. From solipsis at pitrou.net Thu Sep 30 09:08:56 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 30 Sep 2010 15:08:56 +0200 Subject: PyCObject & malloc creating memory leak In-Reply-To: <4bf06438-5c31-4809-89bb-c335289fffe9@a15g2000yqm.googlegroups.com> References: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> <4bf06438-5c31-4809-89bb-c335289fffe9@a15g2000yqm.googlegroups.com> Message-ID: <20100930150856.34fc1599@pitrou.net> On Thu, 30 Sep 2010 04:06:03 -0700 (PDT) Tom Conneely wrote: > Thanks for your reply, you've given me plenty to think about > > On Sep 29, 11:51?pm, Antoine Pitrou wrote: > > > > > My original plan was to have the data processing and data acquisition > > > functions running in separate processes, with a multiprocessing.Queue > > > for passing the raw data packets. The raw data is read in as a char*, > > > with a non constant length, hence I have allocated memory using > > > PyMem_Malloc and I am returning from the acquisition function a > > > PyCObject containing a pointer to this char* buffer, along with a > > > destructor. > > > > That sounds overkill, and I also wonder how you plan to pass that > > object in a multiprocessing Queue (which relies on objects being > > pickleable). Why don't you simply create a PyString object instead? > > Could you elaborate on why you feel this is overkill? Also, your right > about > passing the PyCObjects through a Queue, something which I hadn't > really > considered, so I've switched to using python strings as you > suggested, > an overhead I hoped to avoid but you can't win them all I suppose. Well, there should be no overhead. Actually, a string should be cheaper since: - the string contents are allocated inline with the PyObject header - while your PyCObject contents were allocated separately (two allocations rather than one) Regards Antoine. From bruce at futurewavedesigns.com Thu Sep 30 09:13:59 2010 From: bruce at futurewavedesigns.com (Bruce W.) Date: Thu, 30 Sep 2010 09:13:59 -0400 Subject: Clarification of notation In-Reply-To: References: <4CA3F6AD.3020603@futurewavedesigns.com> Message-ID: <4CA48D17.1030609@futurewavedesigns.com> So, this kind of notation would be different: args[0][2] verses args[[0][2]] the latter is multidimensional. Can you think of example of using this type of list? I don't know why this had me a bit confused. I've got to get into programming more... I had done more in the past. Bruce Chriebert wrote: > On Wed, Sep 29, 2010 at 7:32 PM, Bruce Whealton > wrote: > >> Hello all, >> I recently started learning python. I am a bit thrown by a certain >> notation that I see. I was watching a training course on lynda.com and this >> notation was not presented. For lists, when would you use what appears to >> be nested lists, like: >> [[], [], []] >> a list of lists? >> > > Lists are for working with a group of data. Sometimes each datum > happens to itself be a list; thus, one naturally ends up with a > list-of-lists. > > Say I have, for each school in my school district, a list of its > students' test scores. I want to compute each school's average score. > So I put all the lists of scores into a nested list. I then iterate > over the nested list, taking the average of each inner list of scores. > (Do the analogous thing at higher and higher levels of aggregation > (e.g. county, state, country) and you naturally get progressively more > nested lists.) > > >> Would you, and could you combine a dictionary with a list in this fashion? >> > > Yes, of course: > {'a' : [1,2,3]} > [{'a' : 1}, {'b' : 2}] > > Just note that lists can't be dictionary keys due to their mutability. > {[1,2,3] : "one two three"} # ERROR > > >> Next, from the documentation I see and this is just an example (this kind of >> notation is seen elsewhere in the documentation: >> >> str.count(sub[, start[, end]]) >> This particular example is from the string methods. >> > > >> I know that it would >> suggest that some of the arguments are optional, so perhaps if there are 2 >> items the first is the sub, and the second is start? Or did I read that >> backwards? >> > > No, you read it exactly correctly. The []s here indicate levels of > optional-ness and have nothing to do with the list datatype. > > Basically, if you want to pass an optional argument, you have to have > also specified any less-nested arguments (unless you use keyword > rather than positional arguments). > str.count(a) # sub = a > str.count(a, b) # sub = a, start = b > str.count(a, b, c) # sub = a, start = b, end = c > > Usually, it's straightforward left-to-right as you specify more > arguments (doing otherwise requires kludges or black magic). However, > there are rare exceptions, the most common one being range()/xrange(): > > range(...) > range([start,] stop[, step]) -> list of integers > > Thus: > range(a) # stop = a (*not* start = a, as would be normal) > range(a, b) # start = a, stop = b > range(a, b, c) # start = a, stop = b, step = c > > Cheers, > Chris > -- > http://blog.rebertia.com > > From pjb at invitado-174.medicalis.es Thu Sep 30 09:14:36 2010 From: pjb at invitado-174.medicalis.es (Pascal Bourguignon) Date: Thu, 30 Sep 2010 15:14:36 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: TheFlyingDutchman writes: > In this example RG is passing a long literal greater than INT_MAX to a > function that takes an int and the compiler apparently didn't give a > warning about the change in value as it created the cast to an int, > even with the option -Wall (all warnings). I think it's legitmate to > consider that an option for a warning/error on this condition should > be available. As far the compiler generating code that checks for a > change in value at runtime when a number is cast to a smaller data > type, I think that's also a legitimate request for a C compiler option > (in addition to other runtime check options like array subscript out > of bounds). I think that it's a legitimate request, in this age and day, for a C programmer to require that it be NOT an option to a C compiler not to give any error for this and similar cases. (And we should just kill all the programs that don't pass this check, which I'm afraid would be a big number, which I understand, is the reason why C compilers don't change). -- __Pascal Bourguignon__ http://www.informatimago.com From eric.brunel at pragmadev.nospam.com Thu Sep 30 09:30:29 2010 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Thu, 30 Sep 2010 15:30:29 +0200 Subject: PyRTF object model References: Message-ID: In article , Rustom Mody wrote: > I am trying to use PyRTF. > > I gather that an RTF doc consists of a list of sections, a section > consists of a list of paras, > paras seem to be just text (not sure on that one) They also include a style, not only text. > Some questions: > > When does one end one section and start another? You don't 'end a section. You just create a new one and append it to your document's sections: my_document = PyRTF.Document() my_section1 = PyRTF.Section() my_document.Sections.append(my_section1) my_section2 = PyRTF.Section() my_document.Sections.append(my_section2) > How does one handle lists (as in numbered, bulleted etc)? Not sure on this one. I've had to do it, but could handle it via regular paragraph style properties and insert the bullets or numbers explicitely, so I did it just like that. For example, your can create a PyRTF.ParagraphPropertySet with the options left_indent to 1133 twips = 2cm, first_line_indent to -567 twips = -1cm and set a tab at 1cm with the option: tabs=[PyRTF.TabPropertySet(width=567)] Then you create a PyRTF.ParagraphStyle using this PyRTF.ParagraphPropertySet and pass it as the first argument when you create your PyRTF.Paragraph. Then, you just insert tour bullet or number in the paragraph explicitely, followed by a tab. There might be a better way to do it. BTW, as you might have noticed, the documentation for PyRTF is quite minimal to say the least, so the only way to figure out what can be done is by reading the PyRTF source code? HTH -Eric - From namekuseijin at gmail.com Thu Sep 30 09:32:32 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Thu, 30 Sep 2010 06:32:32 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> <6784f34c-2948-408b-b2eb-4a3b171c5afe@k10g2000yqa.googlegroups.com> Message-ID: On 30 set, 09:35, namekuseijin wrote: > On 29 set, 11:04, w_a_x_man wrote: > > > > > On Sep 26, 9:24?am, p... at informatimago.com (Pascal J. Bourguignon) > > wrote: > > > > Xah Lee writes: > > > > here's a interesting toy list processing problem. > > > > > I have a list of lists, where each sublist is labelled by > > > > a number. I need to collect together the contents of all sublists > > > > sharing > > > > the same label. So if I have the list > > > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > > > r) (5 s t)) > > > > > where the first element of each sublist is the label, I need to > > > > produce: > > > > > output: > > > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > > > a Mathematica solution is here: > > > >http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > > > > R5RS Scheme lisp solution: > > > >http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_... > > > > by Sourav Mukherjee > > > > > also, a Common Lisp solution can be found here: > > > >http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1de... > > > > It's too complex. Just write: > > > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > > > ? ? ? ? ? ? ? (2 o p) (4 q r) (5 s t)))) > > > > ? (mapcar (lambda (class) (reduce (function append) class :key (function rest))) > > > ? ? ? ? ? ?(com.informatimago.common-lisp.list:equivalence-classes list :key (function first))) > > > > ? ?) > > > > --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) > > > > -- > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/ > > > Ruby: > > > [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, > > 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], > > [5, 's', 't']]. > > group_by{|x| x.first}.values.map{|x| x.map{|y| y[1..-1]}.flatten} > > > ? ? ==>[["s", "t"], ["a", "b"], ["c", "d", "i", "j"], > > ?["e", "f", "k", "l", "o", "p"], > > ?["g", "h"], ["m", "n", "q", "r"]] > > cool, it comes with order all fucked up. ?This is something I was > criticized for before, though not all that important to most > functional processing. ?Not the case here, though. > > here's a scheme version that is hopefully better than the given one: (define (dig in) ? (if (null? in) '() ? ? (let* ((n ? ? ? ? (first-of-first in)) ? ? ? ? ? ?(all-n ? ? (filter in (lambda (x) ? ? ?(eq? n (first x))))) ? ? ? ? ? ?(all-but-n (filter in (lambda (x) (not (eq? n (first x))))))) ? ? ? ?(pair ? ? ? ? ? (fold all-n ? ? ? ? ? ? ?(lambda (i o) (pair (second i) (pair (third i) o)))) ? ? ? ? ? (dig all-but-n))))) ; given these aliases to lisp n00bs (define pair cons) (define first car) (define rest cdr) (define first-of-first caar) (define second cadr) (define third caddr) ; and these well-known functions?(non-tail-recursive for benefit of n00bs) (define (fold ls f) ; AKA reduce ? (if (null? ls) '() ? ? ? (f (first ls) (fold (rest ls) f)))) (define (filter ls f) ? (fold ls (lambda (i o) (if (f i) (pair i o) o)))) ; testing (let ((in '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) ? ? ? ? ? ? (2 o p) (4 q r) (5 s t)))) ? (display (dig in)) ? (newline)) ;frakkin text editor... From __peter__ at web.de Thu Sep 30 09:40:33 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 15:40:33 +0200 Subject: gedit 'External Tools' plugin hashlib weirdness References: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> Message-ID: Joel Hedlund wrote: > FOUND IT! Heureka! > I added the line > > print >> f, '\n'.join(sorted(sys.path)) > > and diff:ed the files produced from terminal/launcher. > > When using the launcher, changes to PYTHONPATH done in ~/.bashrc are > not picked up, and I apparently had an old reference to /usr/lib/ > python2.4 sitting in there. Removed it, reloaded .bashrc, plugin now > works. I'm surprised that /usr/lib/python2.4 doesn't appear in the traceback. > The question still remains why gnome disregards ~/.bashrc, but that's > a whole other topic. Thanks a bunch, you guys are ever so helpful. I think the breakage you've experienced could be the answer. Peter From pjb at invitado-174.medicalis.es Thu Sep 30 09:57:58 2010 From: pjb at invitado-174.medicalis.es (Pascal Bourguignon) Date: Thu, 30 Sep 2010 15:57:58 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> Message-ID: Nick Keighley writes: > On 27 Sep, 20:29, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> If you start with the mindset of static type checking, you will consider >> that your types are checked and if the types at the interface of two >> modules matches you'll think that everything's ok. ?And six months later >> you Mars mission will crash. > > do you have any evidence that this is actually so? That people who > program in statically typed languages actually are prone to this "well > it compiles so it must be right" attitude? Yes, I can witness that it's in the mind set. Well, the problem being always the same, the time pressures coming from the sales people (who can sell products of which the first line of specifications has not been written yet, much less of code), it's always a battle to explain that once the code is written, there is still a lot of time needed to run tests and debug it. I've even technical managers, who should know better, expecting that we write bug-free code in the first place (when we didn't even have a specification to begin with!). >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. ?Mission saved! > > they *may* do this but do they *actually* do it? My (limited) > experience of dynamically typed languges is everynow and again you > attempt to apply an operator to the wrong type of operand and kerblam! > If your testing is inadaquate then it's inadaquate whatever the > typiness of your language. Unfortunately, a lot of programmers in dynamic programming languages have been formed with static programming languages bring with them their old mindset. Moreover, when the syntax of the newer dynamic programming languages is explicitely designed similar to an older static programming language, in order to attract these programmers toward the better technologies, this does not help changing the mindset either. Unfortunately, you can write FORTRAN code in any programming language. But my point is that at least with dynamic programming languages, there's an alternative mindset and it is easier to implement such a scheme than with static programming languages. In Lisp, which stresses the symbolic computing part (S-expr are Symbolic Expressions), it is almost trivial to implement. -- __Pascal Bourguignon__ http://www.informatimago.com From exarkun at twistedmatrix.com Thu Sep 30 10:01:09 2010 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Thu, 30 Sep 2010 07:01:09 -0700 (PDT) Subject: Python becoming orphaned over ssh References: <4ca36e44$0$1584$742ec2ed@news.sonic.net> Message-ID: <91cdb1f0-5db1-4566-9899-386a7f06104d@y31g2000vbt.googlegroups.com> On Sep 30, 9:08?am, David wrote: > On Wed, Sep 29, 2010 at 6:49 PM, John Nagle wrote: > > ? Python's signal handling for multithread and multiprocess programs > > leaves something to be desired. > > Thanks for the confirmation (that I'm not missing something obvious). > > I've reported a bug for this behavior in the Python issue tracker. > > In the meanwhile, I've made a workaround function called > "check_call_and_monitor_ppids", that behaves like > subprocess.check_call, except that it regularly checks if the parent > pid "chain" (up to init process) changes during execution, and then > terminates the subprocess and raises an exception. > > Actually I tried this before, and it didn't work. But strangely, it > seems to work fine so long as I don't try to print any warning > messages to stderr or stdout from the Python script (though, the > called tool itself may print to stdout or stderr without problems). > Quite peculiar... > > Anyway, I hope that one of the Python developers will fix this sometime. > > David. Python ignores SIGPIPE by default. The default SIGPIPE behavior is to exit. This is sort of what people on POSIX expect. If you're talking to another process over a pipe and that process goes away, and then you write to the pipe, you get a SIGPIPE and you exit (of course, if it takes you 20 minutes before you do another write, then it's 20 minutes before you exit). But with SIGPIPE ignored, a Python process won't do exactly this. Instead, you'll get an exception from the write. If you don't handle the exception, then it'll propagate to the top-level and you'll exit. Just like with a "normal" process. Except you also get the option to doing something other than exiting. Pretty nice. But signal dispositions are inherited by child processes. So you run ping from your short Python program, and it inherits SIGPIPE being ignored. And it's written in C, not Python, so when it writes to the pipe, there's no exception. So ping never gets any indication that it should exit. No Python writes ever happen in this scenario. The SSH supplied stdout is shared with the ping process, which writes to it directly. You can fix this by resetting the signal disposition of SIGPIPE for the ping process: #!/usr/bin/python import signal def reset(): signal.signal(signal.SIGPIPE, signal.SIG_DFL) from subprocess import check_call check_call(['ping', 'www.google.com'], preexec_fn=reset) Very likely the subprocess module should be resetting the disposition of signals that Python itself has fiddled with (and resetting any other unusual state that the child is going to inherit, but nothing else comes immediately to mind). From emile at fenx.com Thu Sep 30 10:02:40 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 Sep 2010 07:02:40 -0700 Subject: sequence multiplied by -1 In-Reply-To: <20100930121043.GD2272@rcpc42.vub.ac.be> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> <20100930121043.GD2272@rcpc42.vub.ac.be> Message-ID: On 9/30/2010 5:10 AM Antoon Pardon said... > On Sun, Sep 26, 2010 at 03:20:18PM +0000, Grant Edwards wrote: >> On 2010-09-26, Paul Rubin wrote: >>> Steven D'Aprano writes: >>>> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", >> >>> Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? >> >> Because >> >> 3 * "spam" == "spam" + "spam" + "spam" >> >> Just like >> >> 3 * 6 = 6 + 6 + 6 >> >> So now I suppose "+" for string concatenation is a bad thing. > > Well I find it an unfortunate choice. The problem is, that it is not that > unusual to want some class to have the possibility of both addition and > concatenation. But since we only one symbol for both operations, you will > have to loose some consistency over this. > Which is actually a good thing for a class that wants to have both concatenation and addition -- which would it do with only one symbol? Emile From emile at fenx.com Thu Sep 30 10:05:06 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 Sep 2010 07:05:06 -0700 Subject: if the else short form In-Reply-To: <1xZoo.1781$Fk6.1722@newsfe13.ams2> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <20100929114701.110c18b5@geekmail.INVALID> <1xZoo.1781$Fk6.1722@newsfe13.ams2> Message-ID: On 9/30/2010 3:21 AM Sion Arrowsmith said... > Andreas Waldenburger wrote: >> >> [ ... ] >> Boolean values behave like the values 0 and 1, respectively, in >> almost all contexts, the exception being that when converted to a >> string, the strings "False" or "True" are returned, respectively. > > Hmm. So the original problem of: > > button = gtk.Button(("False,", "True,")[fill==True]) > > could also rewritten as: > > button = gtk.Button(str(bool(fill))+",") > I think I'd prefer button = gtk.Button("%s," % bool(fill)) Emile From exarkun at twistedmatrix.com Thu Sep 30 10:14:42 2010 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Thu, 30 Sep 2010 07:14:42 -0700 (PDT) Subject: Determine sockets in use by python References: <4CA37FDA.3080605@digipen.edu> Message-ID: On Sep 29, 4:08?pm, Jim Mellander wrote: > > On Wed, Sep 29, 2010 at 11:05 AM, Gary Herron wrote: > > On 09/29/2010 09:50 AM, Jim Mellander wrote: > > >> Hi: > > >> I'm a newbie to python, although not to programming. ?Briefly, I am > >> using a binding to an external library used for communication in a > >> client-server context, with the server in python. ?Typically, I would > >> set this up with event callbacks, and then enter a select loop, which, > >> most the time idles and processes input events when the socket shows > >> activity, kinda like: > > >> while True: > >> ? ? socket.select((my_socket),(),()) > >> ? ? process_event() > > >> Unfortunately, the API does not expose the socket to the script level, > >> and the developer recommends a busy loop: > > >> while True: > >> ? ? sleep(1) > >> ? ? process_event() > > >> which I hope to avoid, for many reasons. ?If the socket can be exposed > >> to the script level, then the problem would be solved. > > >> Failing that, it would be nice to be able to pythonically determine > >> the sockets in use and select on those. ?Does anyone have any > >> suggestions on how to proceed? > > >> Thanks in advance > > > It's certain that any answer to this will depend on which operating system > > you are using. ?So do tell: What OS? > > Hi Gary: > > Certainly not windows.... ?I'm developing on OS/X but for production > probably Linux and FreeBSD > > (I'm hoping for something a bit more portable than running 'lsof' and > parsing the output, but appreciate any/all advice) > Linux has /proc/self/fd and OS X has /dev/fd. Those both suppose you have some way of determining which file descriptor corresponds to the socket or sockets that the library is using, of course. Vastly better would be to convince the author to expose that information via a real API. Jean-Paul From brandon.harris at reelfx.com Thu Sep 30 10:21:16 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 30 Sep 2010 09:21:16 -0500 Subject: eval string Message-ID: <4CA49CDC.7010609@reelfx.com> Needing to pass a string command into a third party program and having issues creating a string to do what I need. here's what I have so far. eval('import sys; sys.stderr.write(\'\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n\');') Traceback (most recent call last): File "", line 1, in File "", line 1 sys.stderr.write(' ^ SyntaxError: EOL while scanning string literal so I've changed it up every way I can think and I get other errors. eval('import sys; sys.stderr.write("\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n");') Traceback (most recent call last): File "", line 1, in File "", line 1 import sys; sys.stderr.write(" ^ SyntaxError: invalid syntax Brandon L. Harris From zzbbaadd at aol.com Thu Sep 30 10:24:39 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 07:24:39 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: > > > If I had to choose between "blow up" or "invalid answer" I would pick > > "invalid answer". > > there are some application domains where neither option would be > viewed as a satisfactory error handling strategy. Fly-by-wire, petro- > chemicals, nuclear power generation. Hell you'd expect better than > this from your phone! > I wasn't speaking generally, just in the case of which of only two choices RG's code should be referred to - "blowing up" or "giving an invalid answer". I think error handling in personal computer and website software has improved over the years but there is still some room for improvement as you will still get error messages that don't tell you something you can relay to tech support more than that an error occurred or that some operation can't be performed. But I worked with programmers doing in-house software who were incredibly turned off by exception handling in C++. I thought that meant that they preferred to return and check error codes from functions as they had done in C, and for some of them it did seem to mean that. But for others it seemed that they didn't want to anticipate errors at all ("that file is always gonna be there!"). I read a Java book by Deitel and Deitel and they pointed out what might have lead to that attitude - the homework and test solutions in college usually didn't require much if any error handling - the student could assume files were present, data was all there and in the format expected, user input was valid and complete, etc. From davea at ieee.org Thu Sep 30 10:37:33 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 30 Sep 2010 10:37:33 -0400 Subject: Clarification of notation In-Reply-To: <4CA48D17.1030609@futurewavedesigns.com> References: <4CA3F6AD.3020603@futurewavedesigns.com> <4CA48D17.1030609@futurewavedesigns.com> Message-ID: <4CA4A0AD.2060103@ieee.org> On 2:59 PM, Bruce W. wrote: > So, this kind of notation would be different: > args[0][2] > verses args[[0][2]] > the latter is multidimensional. Can you think of example of using > this type of list? > I don't know why this had me a bit confused. I've got to get into > programming more... I had done more in the past. > Bruce > > The data in a multidimensional list (list of lists) would look like: [ [3,5], [4,2,99] ] But a reference to it would be args[1][2] DaveA From __peter__ at web.de Thu Sep 30 10:46:11 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 16:46:11 +0200 Subject: eval string References: Message-ID: Brandon Harris wrote: > Needing to pass a string command into a third party program and having > issues creating a string to do what I need. > > here's what I have so far. > > eval('import sys; > sys.stderr.write(\'\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!! \nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n\');') > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > sys.stderr.write(' > ^ > SyntaxError: EOL while scanning string literal > > > so I've changed it up every way I can think and I get other errors. > > eval('import sys; > sys.stderr.write("\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!! \nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n");') > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > import sys; sys.stderr.write(" > ^ > SyntaxError: invalid syntax > > > Brandon L. Harris Python discriminates between statements and expressions. eval() can only deal with expressions, but 'import whatever' is a statement. Try exec 'import sys\nsys.stderr.write("completed!\n")' instead. From thomas at jollybox.de Thu Sep 30 10:50:02 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 30 Sep 2010 16:50:02 +0200 Subject: eval string In-Reply-To: <4CA49CDC.7010609@reelfx.com> References: <4CA49CDC.7010609@reelfx.com> Message-ID: <201009301650.03412.thomas@jollybox.de> On Thursday 30 September 2010, it occurred to Brandon Harris to exclaim: > Needing to pass a string command into a third party program and having > issues creating a string to do what I need. > > here's what I have so far. > > eval('import sys; > sys.stderr.write(\'\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nComplete > d!!!\nCompleted!!!\nCompleted!!!\n\n\n\');') > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > sys.stderr.write(' Neither ' nor " can delimit a multiline string literal. You need triplets. > ^ > SyntaxError: EOL while scanning string literal > > > so I've changed it up every way I can think and I get other errors. > > eval('import sys; > sys.stderr.write("\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted > !!!\nCompleted!!!\nCompleted!!!\n\n\n");') > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > import sys; sys.stderr.write(" > ^ > SyntaxError: invalid syntax > > > Brandon L. Harris From nick_keighley_nospam at hotmail.com Thu Sep 30 11:02:29 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 30 Sep 2010 08:02:29 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: <04f34901-8978-4b94-9ff6-40295de6084d@d25g2000yqc.googlegroups.com> On 30 Sep, 15:24, TheFlyingDutchman wrote: > > > If I had to choose between "blow up" or "invalid answer" I would pick > > > "invalid answer". > > > there are some application domains where neither option would be > > viewed as a satisfactory error handling strategy. Fly-by-wire, petro- > > chemicals, nuclear power generation. Hell you'd expect better than > > this from your phone! > > I wasn't speaking generally, just in the case of which of only two > choices RG's code should be referred to - "blowing up" or "giving an > invalid answer". I think I'd prefer termination if those were my only choices. What's the rest of the program going to do with the wrong result? When the program finally gives up the cause is lost in the mists of time, and those are hard to debug! > I think error handling in personal computer and website software has > improved over the years but there is still some room for improvement > as you will still get error messages that don't tell you something you > can relay to tech support more than that an error occurred or that > some operation can't be performed. > > But I worked with programmers doing in-house software who were > incredibly turned off by exception handling in C++. I thought that > meant that they preferred to return and check error codes from > functions as they had done in C, and for some of them it did seem to > mean that. But for others it seemed that they didn't want to > anticipate errors at all ("that file is always gonna be there!"). that was one of the reasons I liked exceptions. If my library threw an exception then the caller *had* to do something about it. Even to ignore it he had to write some code. > I > read a Java book by Deitel and Deitel and they pointed out what might > have lead to that attitude - the homework and test solutions in > college usually didn't require much if any error handling - the > student could assume files were present, data was all there and in the > format expected, user input was valid and complete, etc. plausible. Going from beginner to I probably steadily increased the pessimism of my code. The file might not be there. That other team might send us syntactically invalid commands. Even if it can't go wrong it will go wrong. Fortunately my collage stuff included some OS kernal stuff. There anything that can go wrong will go wrong. From __peter__ at web.de Thu Sep 30 11:09:21 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 17:09:21 +0200 Subject: eval string References: Message-ID: Peter Otten wrote: > exec 'import sys\nsys.stderr.write("completed!\n")' Oops, you need to escape the backslashes for newlines inside quotes inside quotes: >>> exec 'import sys\nsys.stderr.write("completed!\\n")' completed! Peter From tfb at tfeb.org Thu Sep 30 11:13:43 2010 From: tfb at tfeb.org (Tim Bradshaw) Date: Thu, 30 Sep 2010 16:13:43 +0100 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: On 2010-09-30 13:36:17 +0100, Nick Keighley said: > there are some application domains where neither option would be > viewed as a satisfactory error handling strategy. Fly-by-wire, petro- > chemicals, nuclear power generation. Hell you'd expect better than > this from your phone! People always give these kind of scenarios, but actually there are far more mundane ones. In my day job I'm a sysadmin and I spend a bunch of time writing code (typically what would nowadays be called "scripts" rather than programs, but there's no real difference) which does things of the form for every machine in do where is fairly often "modify critical system configuration file". Programs like that have some absolute, non-negotiable requirements: - they must never fail silently; - they must check everything they do however unlikely it seems that it would failm because they will come across systems which have almost arbitrary misconfiguration. - they should be idempotent if possible; - if they come across something odd they either need to handle it, or put things back the way they were and back out; - if they absolutely can not put things back, they need to report this very clearly and carefully preserve any detriitus in such a way that a human can pick up the bits; - whatever they do they need to report in a completely parsable way what happened (success, failure, already done, backed out, not backed out, and so on). These are quite mundane everyday things, but the consequences of getting them wrong can be quite nasty (the worst ones being "the machines will still run, but won't boot"). From drobinow at gmail.com Thu Sep 30 11:16:31 2010 From: drobinow at gmail.com (David Robinow) Date: Thu, 30 Sep 2010 11:16:31 -0400 Subject: PyRTF object model In-Reply-To: References: Message-ID: On Thu, Sep 30, 2010 at 8:14 AM, Rustom Mody wrote: > I am trying to use PyRTF. > > I gather that an RTF doc consists of a list of sections, a section > consists of a list of paras, > paras seem to be just text (not sure on that one) > > Some questions: > > When does one end one section and start another? > How does one handle lists (as in numbered, bulleted etc)? You might find the RTF specification helpful. One source is: http://msdn.microsoft.com/en-us/library/aa140277%28office.10%29.aspx From kst-u at mib.org Thu Sep 30 11:26:38 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 08:26:38 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: RG writes: [...] > You can't have it both ways. Either I am calling it incorrectly, in > which case I should get a compiler error, or I am calling it correctly, > and I should get the right answer. That I got neither does in fact > falsify the claim. The only way out of this is to say that > maximum(8589934592, 1) returning 1 is in fact "correct", in which case > we'll just have to agree to disagree. You are calling maximum() incorrectly, but you are doing so in a way that the compiler is not required to diagnose. If you want to say that the fact that the compiler is not required to diagnose the error is a flaw in the C language, I won't argue with you. It's just not a flaw in the maximum() function. If I write: const double pi = 22.0/7.0; printf("pi = %f\n", pi); then I suppose I'm calling printf() incorrectly, but I wouldn't expect my compiler to warn me about it. If you're arguing that int maximum(int a, int b) { return a > b ? a : b; } is flawed because it's too easy to call it incorrectly, you're effectively arguing that it's not possible to write correct code in C at all. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From hidura at gmail.com Thu Sep 30 11:33:01 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 30 Sep 2010 15:33:01 +0000 Subject: Problems with wsgi Python3 Message-ID: <0016362840cc20212c04917bcb34@google.com> Hello list, i had seriously troubles with the connection between a form and the wsgi, i' ve made an application on Python3 and was running perfectly but when i try to use the to pass the data this can't be see on the server, so what is your recommendation?, i am open to all the ideas less leave to Python2 i can't all the project was write on Python3, i was looking into the PEP 444 proposal too. Here is the code what i used to take the data: print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])).decode())) and here it's what the os.environ.item() prints to me: ('LESSOPEN', '|/usr/bin/lesspipe.sh %s') ('SSH_CLIENT', '190.94.122.180 38415 22') ('CVS_RSH', 'ssh') ('LOGNAME', 'hidura') ('INPUTRC', '/etc/inputrc') ('HOME', '/home/hidura') ('PATH', '/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin:/home/hidura/bin') ('LD_LIBRARY_PATH', '/home/hidura/webapps/karinapp/apache2/lib') ('LANG', 'en_US.UTF-8') ('TERM', 'xterm') ('SHELL', '/bin/bash') ('SHLVL', '3') ('G_BROKEN_FILENAMES', '1') ('HISTSIZE', '1000') ('_', '/home/hidura/webapps/karinapp/apache2/bin/httpd.worker') ('SSH_CONNECTION', '190.94.122.180 38415 174.121.79.178 22') ('SSH_TTY', '/dev/pts/5') ('HOSTNAME', 'web152.webfaction.com') ('PWD', '/home/hidura') ('MAIL', '/var/spool/mail/hidura') ('LS_COLORS', 'no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:') -----------------------------110550484811701713451664404475--\r Thanks, i am desperate. -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Thu Sep 30 11:54:48 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 15:54:48 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, Lie Ryan wrote: > On 09/30/10 16:09, TheFlyingDutchman wrote: >> Dynamic typed languages like Python fail in this case on "Never blows >> up". > How do you define "Never blows up"? I would say "blow up" would be "raise an exception". > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > up, and of the worst kind since it passes silently. So run your compiler with a decent set of warning levels, and watch as you are magically warned that you're passing an object of the wrong type. On any given system, one or the other is true: 1. The constant 8589934592 is of type int, and the function will "work" -- will give that result. 2. The constant is not of type int, and the compiler will warn you about this if you ask. -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 deets at web.de Thu Sep 30 11:55:06 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 30 Sep 2010 17:55:06 +0200 Subject: Problems with wsgi Python3 References: Message-ID: <87aamzns4l.fsf@web.de> hidura at gmail.com writes: > Hello list, i had seriously troubles with the connection between a form and the > wsgi, i' ve made an application on Python3 and was running perfectly but when i > try to use the to pass the data this can't be see on the server, so what > is your recommendation?, i am open to all the ideas less leave to Python2 i > can't all the project was write on Python3, i was looking into the PEP 444 > proposal too. > > Here is the code what i used to take the data: > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(environ > ['CONTENT_LENGTH'])).decode())) What is the ouptut of this? What does import pprint pprint.pprint(environ) give you? > > and here it's what the os.environ.item() prints to me: That's irrelevant. The WSGI-environ is what is needed. Diez From usenet-nospam at seebs.net Thu Sep 30 11:55:48 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 15:55:48 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: On 2010-09-30, TheFlyingDutchman wrote: > even with the option -Wall (all warnings). For various historical reasons, "-Wall" has the semantics you might expect from an option named "-Wsome-common-warnings-but-not-others". -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 Sep 30 12:01:22 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:01:22 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: On 2010-09-30, RG wrote: > We lost some important context somewhere along the line: >> > > in C I can have a function maximum(int a, int b) that will always >> > > work. Never blow up, and never give an invalid answer. If someone >> > > tries to call it incorrectly it is a compile error. > Please take note of the second sentence. I did. That is entirely correct. > One way or another, this claim is plainly false. The point I was trying > to make is not so much that the claim is false (someone else was already > doing that), but that it can be demonstrated to be false without having > to rely on any run-time input. It is not at all obvious to me that it is, in fact, false. So far as I can tell, *if* the function is successfully called, then it will take two integers, compare them, and return the larger one. It will never return something which is not an integer. It will never raise an exception. It will never return a value which, if you try to treat it as an integer, raise an exception. Now, if you pass the wrong values to it, you will get wrong answers -- but that's your problem for passing it wrong values. I would understand an "invalid" answer to be one of the wrong category. For instance, if I have a function in Python that I expect to return a string, and it returns None, I have gotten an answer that is "invalid" -- it's not a string. -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 Sep 30 12:03:29 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:03:29 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: On 2010-09-30, Paul Rubin wrote: > int maximum(int a, int b); > > int foo() { > int (*barf)() = maximum; > return barf(3); > } > This compiles fine for me. Where is the cast? On the first line of code inside foo(). > Where is the error message? You chose to use a form that suppresses the error message. > Are you saying barf(3) doesn't call maximum? I would say that it is undefined whether or not it calls maximum, because you called a function through a function pointer of a different sort, which invoked undefined behavior. There exist real compiles on which code much like this will coredump without ever once trying to jump to the address of the maximum function, because the compiler caught your error. -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 Sep 30 12:04:35 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:04:35 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: On 2010-09-30, RG wrote: > You can't have it both ways. Either I am calling it incorrectly, in > which case I should get a compiler error, You get a warning if you ask for it. If you choose to run without all the type checking on, that's your 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 usenet-nospam at seebs.net Thu Sep 30 12:06:52 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:06:52 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> Message-ID: On 2010-09-30, Pascal Bourguignon wrote: > Nick Keighley writes: >> do you have any evidence that this is actually so? That people who >> program in statically typed languages actually are prone to this "well >> it compiles so it must be right" attitude? > Yes, I can witness that it's in the mind set. Huh. So here I am, programming in statically typed languages, and I have never in my life thought that things which compiled were necessarily right. Not even when I was an arrogant teenager. I guess I don't exist. *sob* > Well, the problem being always the same, the time pressures coming from > the sales people (who can sell products of which the first line of > specifications has not been written yet, much less of code), it's always > a battle to explain that once the code is written, there is still a lot > of time needed to run tests and debug it. At $dayjob, they give us months between feature complete and shipping, because they expect us to spend a lot of time testing, debugging, and cleaning up. But during that time we are explicitly not adding features... > But my point is that at least with dynamic programming languages, > there's an alternative mindset and it is easier to implement such > a scheme than with static programming languages. I think this grossly oversimplifies 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 rNOSPAMon at flownet.com Thu Sep 30 12:10:05 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 09:10:05 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > RG writes: > [...] > > You can't have it both ways. Either I am calling it incorrectly, in > > which case I should get a compiler error, or I am calling it correctly, > > and I should get the right answer. That I got neither does in fact > > falsify the claim. The only way out of this is to say that > > maximum(8589934592, 1) returning 1 is in fact "correct", in which case > > we'll just have to agree to disagree. > > You are calling maximum() incorrectly, but you are doing so in a way > that the compiler is not required to diagnose. Yes. I know. That was my whole point. There are ways to call a function incorrectly (more broadly, there are errors in code) that a C compiler is not required to diagnose. > If you want to say that the fact that the compiler is not required > to diagnose the error is a flaw in the C language, I won't > argue with you. I'm not even saying it's a flaw in the language. All I'm saying is that the original claim -- that any error in a C program will be caught by the compiler -- is false, and more specifically, that it can be demonstrated to be false without appeal to unknown run-time input. As an aside, this particular error *could* be caught (and in fact would be caught by other tools like lint), but there are errors that can not be caught by any static analysis, and that therefore one should not be lulled into a false sense of security by the fact that your code is written in a statically typed language and compiled without errors or warnings. That's all. > If I write: > > const double pi = 22.0/7.0; > printf("pi = %f\n", pi); > > then I suppose I'm calling printf() incorrectly, but I wouldn't > expect my compiler to warn me about it. > > If you're arguing that > > int maximum(int a, int b) { return a > b ? a : b; } > > is flawed because it's too easy to call it incorrectly, you're > effectively arguing that it's not possible to write correct > code in C at all. I would say that it is very, very hard to write correct code in C for any non-vacuous definition of "correct". That is the reason that core dumps and buffer overflows are so ubiquitous. I prefer Lisp or Python, where core dumps and buffer overflows are virtually nonexistent. One does get the occasional run-time error that might have been caught at compile time, but I much prefer that to a core dump or a security hole. One might hypothesize that the best of both worlds would be a dynamic language with a static analyzer layered on top. Such a thing does not exist. It makes an instructive exercise to try to figure out why. (For the record, I don't know the answer, but I've learned a lot through the process of pondering this conundrum.) rg From psilord at cs.wisc.edu Thu Sep 30 12:14:01 2010 From: psilord at cs.wisc.edu (Peter Keller) Date: Thu, 30 Sep 2010 16:14:01 +0000 (UTC) Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In comp.lang.lisp TheFlyingDutchman wrote: > >> >> More specifically, the claim made above: >> >> > in C I can have a function maximum(int a, int b) that will always >> > work. Never blow up, and never give an invalid answer. >> >> is false. ?And it is not necessary to invoke the vagaries of run-time >> input to demonstrate that it is false. >> > I don't think you demonstrated it is false. Any values larger than an > int get truncated before they ever get to maximum. The problem does > not lie with the maximum function. It correctly returns the maximum of > whatever two integers it is provided. Calling it with values that are > larger than an int, that get converted to an int _before_ maximum is > called, is an issue outside of maximum. After thinking for a bit. I believe I can demonstrate a situation where indeed maximum could return the wrong answer and it isn't due to being passed incorrect input. If, in maximum, after the entrance to the function call but right before the comparison, a signal handler gets invoked, walks the stack, swaps the two values for a and b, and returns back into maximum. Then maximum will do the wrong thing. Since control flow was always in a subgraph of the control flow graph through maximum, this would classify as a failure given your strict view. (As an aside, one can do the same thing with a debugger.) Blocking the signals around the comparison and assignment of the result to a temporary variable that you will return won't fix it. This is because (in C) you must have a sequence point after the unblocking of the signals and before the assignment of a temporary variable holding the result to the return register, where, in fact, another signal could arrive and again corrupt the results. Depending upon the optimzation values of the compiler, it may or may not adjust the ordering semantics of the assignment to the return register in relation to the call to unblock the signals. The assignment of a result to a return register is not defined to be something in C, and can happen anywhere. But the C statements you used to write it must adhere to sequence evaluation. Since the signal handler could do anything, including completely replacing the text segments and/r loaded libraries of the code or move the PC to an arbitrary palce, I don't think you can "fix" this problem. Ever. If you think this is a pedantic case which never happens in practice, I'm the maintainer of a well-known user space checkpointing system where these types of problems have to be thought about deeply because they happen. In addition, there are other modes of error injection: in compute clusters with very high density memory that is not ECC, you can actually calculate the probability that a bit will flip at an address in memory due to cosmic rays. That probability is disturbingly high. Just an idle search online produced this article: http://news.cnet.com/8301-30685_3-10370026-264.html which mentions some statistics. Think 1 billion hours is a lot and "it'll never happen"? There are 8760 hours in a year. So, you'd only need 114,156 computers in a cluster running for one year before amassing 1 billion hours of computation. That isn't a big number for large financial companies, google, etc, etc, etc to own. As a fun statistic, the BlueGene/P supercomputer can have 884,736 processors with associated memory modules. According to the math in the article, one BlueGene/P should see a max of ~600,000 memory errors per year. Sure, you might not think any of this is a problem, because your home desktop always produces the right answer when balancing your checkbook, but it is a matter of perception of scale. Lots of large clusters and data movement houses go to great length to ensure data integrity. Injecting wrong data 4 hours into a 6 month long workflow running on thousands of computers really upsets the hell out of people. I've run into physicists who simply run their buggy software over and over and over again on the same data and do statistical analysis on the results. They've come to the realization that they can't find/fix/verify all the bugs in their code, so they assume they are there and write systems which try to be mathematically robust to the nature of the beast. It is cheaper to wait for 1000 runs of a program to be computed on a cluster than to spend human time debugging a difficult bug in the code. So, mathematically, maximum can't fail inside of itself, realistically while executing on a physical machine, you bet it'll fail. :) -pete From rNOSPAMon at flownet.com Thu Sep 30 12:32:08 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 09:32:08 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Seebs wrote: > On 2010-09-30, Lie Ryan wrote: > > On 09/30/10 16:09, TheFlyingDutchman wrote: > >> Dynamic typed languages like Python fail in this case on "Never blows > >> up". > > > How do you define "Never blows up"? > > I would say "blow up" would be "raise an exception". > > > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > > up, and of the worst kind since it passes silently. > > So run your compiler with a decent set of warning levels, and watch as > you are magically warned that you're passing an object of the wrong type. My code compiles with no warnings under gcc -Wall. > On any given system, one or the other is true: > > 1. The constant 8589934592 is of type int, and the function will > "work" -- will give that result. > 2. The constant is not of type int, and the compiler will warn you about > this if you ask. It would be nice if this were true, but my example clearly demonstrates that it is not. And if your response is to say that I should have used lint, then my response to that will be that because of the halting problem, for any static analyzer that you present, I can construct a program that either contains an error that either your analyzer will not catch, or for which it will generate a false positive. It just so happens that constructing such examples for standard C is very easy. rg From rNOSPAMon at flownet.com Thu Sep 30 12:36:22 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 09:36:22 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: In article , Seebs wrote: > On 2010-09-30, RG wrote: > > You can't have it both ways. Either I am calling it incorrectly, in > > which case I should get a compiler error, > > You get a warning if you ask for it. If you choose to run without all > the type checking on, that's your problem. My example compiles with no warnings under gcc -Wall. Yes, I know I could have used lint. But that misses the point. For any static analyzer, because of the halting problem, I can construct a program that either contains an error that the analyzer will not catch, or for which the analyzer will produce a false positive. rg From dsrtegle at gmail.com Thu Sep 30 12:38:05 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Thu, 30 Sep 2010 09:38:05 -0700 (PDT) Subject: Please help: pylint does not work with Emacs23 on Windows Message-ID: <66da9bf4-3c1c-4aad-96ef-0c9fee798e90@a4g2000prm.googlegroups.com> Hi, I am trying to use Pylint with Emacs on Windows XP. My Emacs version is EmacsW32 23.1, pylint is 0.21.3 with Python 2.5. After easy_install pylint, I added the code block below to Emacs init file, copied form Emacs Wiki. (when (load "flymake" t) (defun flymake-pylint-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "epylint" (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pylint-init))) When I invoke the flymake-mode on a .py file, I can see the flymake starting the syntax check, the mode status changed to flymake*, and then goes back to flymake after several seconds. But no error is reported, and no syntax error highlighting. I tried to use pylint in command line, and it works with command "pylint test.py", reporting syntax errors on the same file. I even tried to clear out my .emacs file, but it doesn't help. Could someone help me on this? Thanks a lot. From clp2 at rebertia.com Thu Sep 30 12:39:08 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 30 Sep 2010 09:39:08 -0700 Subject: install 3.1 In-Reply-To: References: Message-ID: > On Thu, Sep 30, 2010 at 4:16 PM, Chris Rebert wrote: >> On Thu, Sep 30, 2010 at 2:02 AM, roronron wrote: >> > My python installed but the gui gives me syntax error on any code I type >> > or paste in. Newbie needs help. >> >> Post the full, exact text of the error message. >> See also: http://www.catb.org/esr/faqs/smart-questions.html On Thu, Sep 30, 2010 at 2:57 AM, ronald brown wrote: >>>> print 'Hello, world!' > SyntaxError: invalid syntax >>>> > Installed 3 times. Used uninstall in program files and control panel. > Followed directions on video for 3.1 Read the fine docs: http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function Python 3 has several backward-incompatible syntax changes. One of them is that the print statement was removed and replaced with a print() function. Regards, Chris From usenet-nospam at seebs.net Thu Sep 30 12:49:16 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:49:16 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, RG wrote: > My code compiles with no warnings under gcc -Wall. That's nice. gcc -Wall uses only a small subset of warnings that fit the usual expectations of C code that's trying to work on common architectures. >> 2. The constant is not of type int, and the compiler will warn you about >> this if you ask. > It would be nice if this were true, but my example clearly demonstrates > that it is not. No, it doesn't, because you didn't ask for the relevant kind of warnings. > And if your response is to say that I should have used > lint, then my response to that will be that because of the halting > problem, for any static analyzer that you present, I can construct a > program that either contains an error that either your analyzer will not > catch, or for which it will generate a false positive. It just so > happens that constructing such examples for standard C is very easy. I'm not sure that that's actually a halting problem case. The thing about static typing is that we don't actually HAVE to solve the halting problem; we only have look at the types of the components, all of which are knowable at compile time, and we can tell you whether there's any unsafe conversions. And that's the magic of static typing: It is not a false positive to warn you that "2L" is not of type int. There are things which would be a false positive in trying to determine whether something will be out of range in a runtime expression, but which are not false positives in a statically typed 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 dsrtegle at gmail.com Thu Sep 30 12:50:37 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Thu, 30 Sep 2010 09:50:37 -0700 (PDT) Subject: Please help: pylint does not work with Emacs23 on Windows References: <66da9bf4-3c1c-4aad-96ef-0c9fee798e90@a4g2000prm.googlegroups.com> Message-ID: <10208d80-559d-4c4d-8583-42b074dc1e15@h40g2000pro.googlegroups.com> On Sep 30, 9:38?am, Dsrt Egle wrote: > Hi, > > I am trying to use Pylint with Emacs on Windows XP. My Emacs version > is EmacsW32 23.1, pylint is 0.21.3 with Python 2.5. After easy_install > pylint, I added the code block below to Emacs init file, copied form > Emacs Wiki. > > ? ? (when (load "flymake" t) > ? ? ? (defun flymake-pylint-init () > ? ? ? ? (let* ((temp-file (flymake-init-create-temp-buffer-copy > ? ? ? ? ? ? ? ? ? ? ? ? ? ?'flymake-create-temp-inplace)) > ? ? ? ? ? ?(local-file (file-relative-name > ? ? ? ? ? ? ? ? ? ? ? ? temp-file > ? ? ? ? ? ? ? ? ? ? ? ? (file-name-directory buffer-file-name)))) > ? ? ? ? ? (list "epylint" (list local-file)))) > > ? ? ? (add-to-list 'flymake-allowed-file-name-masks > ? ? ? ? ? ? ? ?'("\\.py\\'" flymake-pylint-init))) > > When I invoke the flymake-mode on a .py file, I can see the flymake > starting the syntax check, the mode status changed to flymake*, and > then goes back to flymake after several seconds. But no error is > reported, and no syntax error highlighting. > > I tried to use pylint in command line, and it works with command > "pylint test.py", reporting syntax errors on the same file. > > I even tried to clear out my .emacs file, but it doesn't help. > > Could someone help me on this? Thanks a lot. Question Update: I tried the following at command line prompt with "pylint" and "epylint". Does this mean that epylint has a problem? C:\Projects>pylint test_lib.py No config file found, using default configuration ************* Module test_lib E: 13: invalid syntax C:\Projects>epylint test_lib.py 'test_lib.py':1: [F] No module named 'test_lib.py' C:\Projects>epylint Traceback (most recent call last): File "C:\Python25\Scripts\epylint", line 5, in pkg_resources.run_script('pylint==0.21.3', 'epylint') File "C:\Python25\Lib\site-packages\pkg_resources.py", line 489, in run_script self.require(requires)[0].run_script(script_name, ns) File "C:\Python25\Lib\site-packages\pkg_resources.py", line 1207, in run_script execfile(script_filename, namespace, namespace) File "c:\python25\lib\site-packages\pylint-0.21.3-py2.5.egg\EGG- INFO\scripts\epylint", line 3, in epylint.Run() File "c:\python25\lib\site-packages\pylint-0.21.3-py2.5.egg \pylint\epylint.py", line 93, in Run lint(sys.argv[1]) IndexError: list index out of range From no.email at please.post Thu Sep 30 13:07:12 2010 From: no.email at please.post (kj) Date: Thu, 30 Sep 2010 17:07:12 +0000 (UTC) Subject: namespace hacking question Message-ID: This is a recurrent situation: I want to initialize a whole bunch of local variables in a uniform way, but after initialization, I need to do different things with the various variables. What I end up doing is using a dict: d = dict() for v in ('spam', 'ham', 'eggs'): d[v] = init(v) foo(d['spam']) bar(d['ham']) baz(d['eggs']) This is fine, but I'd like to get rid of the tedium of typing all those extra d['...']s. I.e., what I would *like* to do is something closer to this: d = locals() for v in ('spam', 'ham', 'eggs'): d[v] = init(v) foo(spam) bar(ham) baz(eggs) ...but this results in errors like "NameError: global name 'spam' is not defined". But the problem is deeper than the fact that the error above would suggest, because even this fails: spam = ham = eggs = None d = locals() for v in ('spam', 'ham', 'eggs'): d[v] = init(v) foo(spam) # calls foo(None) bar(ham) # calls bar(None) baz(eggs) # calls baz(None) In other words, setting the value of locals()['x'] does not set the value of the local variable x. I also tried a hack using eval: for v in ('spam', 'ham', 'eggs'): eval "%s = init('%s')" % (v, v) but the "=" sign in the eval string resulted in a "SyntaxError: invalid syntax". Is there any way to use a loop to set a whole bunch of local variables (and later refer to these variables by their individual names)? TIA! kj From usenot at geekmail.INVALID Thu Sep 30 13:22:31 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 30 Sep 2010 13:22:31 -0400 Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: <20100930132231.6f51b2a6@geekmail.INVALID> On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) "bruno.desthuilliers at gmail.com" wrote: > On 29 sep, 19:20, Seebs wrote: > > On 2010-09-29, Tracubik wrote: > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > Oh, what a nasty idiom. > > > > Well, it's not very different from dict-based dispatch , which is the > core of OO polymorphic dispatch in quite a few dynamic OOPLs. > > Anyway, it's a common Python idiom and one that's not specially hard > to grasp so I don't see any legibility problem here. But it does violate the "explicit is better than implicit" tenet, don't you think? /W -- INVALID? DE! From usenot at geekmail.INVALID Thu Sep 30 13:30:00 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 30 Sep 2010 13:30:00 -0400 Subject: install 3.1 References: Message-ID: <20100930133000.5bd85f16@geekmail.INVALID> On Thu, 30 Sep 2010 09:39:08 -0700 Chris Rebert wrote: > On Thu, Sep 30, 2010 at 2:57 AM, ronald brown > wrote: > >>>> print 'Hello, world!' > > SyntaxError: invalid syntax > >>>> > > Installed 3 times. Used uninstall in program files and control > > panel. Followed directions on video for 3.1 > > Read the fine docs: > http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function > Python 3 has several backward-incompatible syntax changes. One of them > is that the print statement was removed and replaced with a print() > function. > Sort of serious proposal here: Would it make sense to display a big, fat warning during the install process (and possibly on the first few invocations of the interpreter) to the effect that "If you're starting to learn Python, make sure you're using a Python 3 tutorial!". This seems to throw a lot of people, and I don't see it going away too soon. So maybe this might help? /W -- INVALID? DE! From bruno.desthuilliers at gmail.com Thu Sep 30 13:36:49 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 30 Sep 2010 10:36:49 -0700 (PDT) Subject: namespace hacking question References: Message-ID: <14b5bdd0-f3a6-498a-8b1f-a52b3fd49ca9@j18g2000yqd.googlegroups.com> On 30 sep, 19:07, kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(d['spam']) > bar(d['ham']) > baz(d['eggs']) > > This is fine, but I'd like to get rid of the tedium of typing all > those extra d['...']s. > > I.e., what I would *like* to do is something closer to this: > > d = locals() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(spam) > bar(ham) > baz(eggs) > > ...but this results in errors like "NameError: global name 'spam' is > not defined". > > But the problem is deeper than the fact that the error above would > suggest, because even this fails: > > spam = ham = eggs = None > d = locals() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) The local namespace is not implemented as a dict - locals() only returns a dict representation of it, so updating this dict has no effect on the local namespace. This is documented FWIW. > > I also tried a hack using eval: > > for v in ('spam', 'ham', 'eggs'): > ? ? eval "%s = init('%s')" % (v, v) > > but the "=" sign in the eval string resulted in a "SyntaxError: > invalid syntax". eval only accepts expressions. You'd need exec here - but that's a bit ugly. From python at mrabarnett.plus.com Thu Sep 30 13:40:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Sep 2010 18:40:23 +0100 Subject: namespace hacking question In-Reply-To: References: Message-ID: <4CA4CB87.2050605@mrabarnett.plus.com> On 30/09/2010 18:07, kj wrote: > > > > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', 'ham', 'eggs'): > d[v] = init(v) > > foo(d['spam']) > bar(d['ham']) > baz(d['eggs']) > > > > This is fine, but I'd like to get rid of the tedium of typing all > those extra d['...']s. > > I.e., what I would *like* to do is something closer to this: > > d = locals() > for v in ('spam', 'ham', 'eggs'): > d[v] = init(v) > > foo(spam) > bar(ham) > baz(eggs) > > ...but this results in errors like "NameError: global name 'spam' is > not defined". > > But the problem is deeper than the fact that the error above would > suggest, because even this fails: > > spam = ham = eggs = None > d = locals() > for v in ('spam', 'ham', 'eggs'): > d[v] = init(v) > > foo(spam) # calls foo(None) > bar(ham) # calls bar(None) > baz(eggs) # calls baz(None) > > > In other words, setting the value of locals()['x'] does not set > the value of the local variable x. > > I also tried a hack using eval: > > for v in ('spam', 'ham', 'eggs'): > eval "%s = init('%s')" % (v, v) > > but the "=" sign in the eval string resulted in a "SyntaxError: > invalid syntax". > > Is there any way to use a loop to set a whole bunch of local > variables (and later refer to these variables by their individual > names)? > The handling of local variables in CPython is optimised, so changing locals() won't have any effect, as you discovered. An alternative is to create a namespace in an instance of a class and then add attributes to it: class Namespace(object): pass n = Namespace() for v in ('spam', 'ham', 'eggs'): setattr(n, v, init(v)) foo(n.spam) bar(n.ham) baz(n.eggs) From cousinstanley at gmail.com Thu Sep 30 13:43:49 2010 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 30 Sep 2010 17:43:49 +0000 (UTC) Subject: problem in Gasp ! References: Message-ID: n.a.s wrote: > I want to ask about graphics using Gasp .Attached is exercise 10 > (houses at night) > > if i call the draw_house function once it will work properly ,but more than > one call,windows and doors disappear from some houses . > > Any one can advice? A working version that runs using Python2.6 under Debian 6 Squeeze can be found at .... http://csphx.net/python/house.tar.bz A screenshot of the result is included in that archive .... http://csphx.net/image/houses_10.png -- Stanley C. Kitching Human Being Phoenix, Arizona From Scott at ergy.com Thu Sep 30 13:56:48 2010 From: Scott at ergy.com (Scott L. Burson) Date: Thu, 30 Sep 2010 10:56:48 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <8gik9tFq44U4@mid.individual.net> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <8gik9tFq44U4@mid.individual.net> Message-ID: Ian Collins wrote: > On 09/30/10 05:57 PM, RG wrote: >> >> I'm not saying one should not use compile-time tools, only that one >> should not rely on them. "Compiling without errors" is not -- and >> cannot ever be -- be a synonym for "bug-free." > > We is why we all have run time tools called unit tests, don't we? > My post that kicked off this thread was not cross-posted, so many of the participants may not have seen it. Here it is again, for your convenience: --------------------- This might have been mentioned here before, but I just came across it: a 2003 essay by Bruce Eckel on how reliable systems can get built in dynamically-typed languages. It echoes things we've all said here, but I think it's interesting because it describes a conversion experience: Eckel started out in the strong-typing camp and was won over. https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk -- Scott From rNOSPAMon at flownet.com Thu Sep 30 14:01:29 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 11:01:29 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Seebs wrote: > And that's the magic of static typing: It is not a false positive to > warn you that "2L" is not of type int. We'll have to agree to disagree about that. The numerical value 2 can safely be represented as an int, so I would consider this a false positive. rg From Scott at ergy.com Thu Sep 30 14:06:18 2010 From: Scott at ergy.com (Scott L. Burson) Date: Thu, 30 Sep 2010 11:06:18 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <87k4m4nnqk.fsf@kuiper.lan.informatimago.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <87k4m4nnqk.fsf@kuiper.lan.informatimago.com> Message-ID: Pascal J. Bourguignon wrote: > Squeamizh writes: > >> In short, static typing doesn't solve all conceivable problems. >> >> We are all aware that there is no perfect software development process >> or tool set. I'm interested in minimizing the number of problems I >> run into during development, and the number of bugs that are in the >> finished product. My opinion is that static typed languages are >> better at this for large projects, for the reasons I stated in my >> previous post. Here's a post I wrote earlier, before the conversation got cross-posted. To me, this is the essence of the matter. ----------------------- Norbert_Paul wrote: > > OK, but sometimes it is handy to have the possibility to make compile-time > assertions which prevent you from committing easily avoidable simple > mistakes. Agreed. I actually don't see this issue in black and white terms; I've written lots of Lisp, and I've written lots of code in statically typed languages, and they all have advantages and disadvantages. In the end it all comes back to my time: how much time does it take me to ship a debugged system? Working in Lisp, sometimes I don't get immediate feedback from the compiler that I've done something stupid, but this is generally counterbalanced by the ease of interactive testing, that frequently allows me to run a new piece of code several times in the time it would have taken me to do a compile-and-link in, say, C++. So while I agree with you that compiler warnings are sometimes handy, and there are occasions, working in Lisp, that I would like to have more of them(*), it really doesn't happen to me very often that the lack of one is more than a minor problem. (*) Lisp compilers generally do warn about some things, like passing the wrong number of arguments to a function, or inconsistent spelling of the name of a local variable. In my experience, these warnings cover a substantial fraction of the stupid mistakes I actually make. -- Scott From kst-u at mib.org Thu Sep 30 14:09:44 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 11:09:44 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: Seebs writes: > On 2010-09-30, Paul Rubin wrote: >> int maximum(int a, int b); >> >> int foo() { >> int (*barf)() = maximum; >> return barf(3); >> } > >> This compiles fine for me. Where is the cast? > > On the first line of code inside foo(). Look again; there's no cast in foo(). That first line declare barf as an object of type "pointer to function returning int", or more precisely, "pointer to function with an unspecified but fixed number and type of parameters returning int" (i.e., an old-style non-prototype declaration, still legal but deprecated in both C90 and C99). It then initializes it to point to the "maximum" function. I *think* the types are sufficiently "compatible" (not necessarily using that word the same way the standard does) for the initialization to be valid and well defined. I might check the standard later. It would have been better to use a prototype (for those of you in groups other than comp.lang.c, that's a function declaration that specifies the types of any parameters): int (*barf)(int, int) = maximum; IMHO it's better to use prototypes consistently than to figure out the rules for interactions between prototyped vs. non-prototyped function declarations. [...] -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From no.email at nospam.invalid Thu Sep 30 14:11:45 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 11:11:45 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: <7xr5gbxfry.fsf@ruckus.brouhaha.com> RG writes: > Yes, I know I could have used lint. But that misses the point. For any > static analyzer, because of the halting problem, I can construct a > program that either contains an error that the analyzer will not catch, > or for which the analyzer will produce a false positive. Can you describe any plausible real-world programs where the effort of complicated static is justified, and for which the halting problem gets in the way of analysis? By "real world", I meanI wouldn't consider searching for counterexamples to the Collatz conjecture to qualify as sufficiently real-world and sufficiently complex for fancy static analysis. And even if it did, the static analyzer could deliver a partial result, like "this function either returns a counterexample to the Collatz conjecture or else it doesn't return". D. Turner wrote a famous paper arguing something like the above, saying basically that Turing completeness of programming languages is overrated: http://www.jucs.org/jucs_10_7/total_functional_programming The main example of a sensible program that can't be written in a non-complete language is an interpreter for a Turing-complete language. But presumably a high-assurance application should never contain such a thing, since the interpreted programs themselves then wouldn't have static assurance. From pjb at informatimago.com Thu Sep 30 14:21:30 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 20:21:30 +0200 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: <8762xnnlcl.fsf@kuiper.lan.informatimago.com> RG writes: > One might hypothesize that the best of both worlds would be a dynamic > language with a static analyzer layered on top. Such a thing does not > exist. It makes an instructive exercise to try to figure out why. (For > the record, I don't know the answer, but I've learned a lot through the > process of pondering this conundrum.) There are static analysis tools for Common Lisp: http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/tools/lint/0.html or lisp in general. For example PHENARETE is in the category of static analysis tools. One could regret that they're not more developed, but I guess this only proves the success of using dynamic programming languages: if there were a real need for these tools, along with a good ROI, they would be more developed. In the meantime, several test frameworks are developed. -- __Pascal Bourguignon__ http://www.informatimago.com/ From pjb at informatimago.com Thu Sep 30 14:23:50 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 20:23:50 +0200 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: <871v8bnl8p.fsf@kuiper.lan.informatimago.com> RG writes: > In article , > Seebs wrote: > >> On 2010-09-30, RG wrote: >> > You can't have it both ways. Either I am calling it incorrectly, in >> > which case I should get a compiler error, >> >> You get a warning if you ask for it. If you choose to run without all >> the type checking on, that's your problem. > > My example compiles with no warnings under gcc -Wall. IIRC, -Wall is not reall ALL. Try with: gcc -Wall -Wextra -Werror I would still argue that should be the default, and if really there was a need, there could be options to disable some warning, or to have some errors be warnings... -- __Pascal Bourguignon__ http://www.informatimago.com/ From kst-u at mib.org Thu Sep 30 14:25:03 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 11:25:03 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: RG writes: > In article , > Keith Thompson wrote: >> RG writes: >> [...] >> > You can't have it both ways. Either I am calling it incorrectly, in >> > which case I should get a compiler error, or I am calling it correctly, >> > and I should get the right answer. That I got neither does in fact >> > falsify the claim. The only way out of this is to say that >> > maximum(8589934592, 1) returning 1 is in fact "correct", in which case >> > we'll just have to agree to disagree. >> >> You are calling maximum() incorrectly, but you are doing so in a way >> that the compiler is not required to diagnose. > > Yes. I know. That was my whole point. There are ways to call a > function incorrectly (more broadly, there are errors in code) that a C > compiler is not required to diagnose. Of course. >> If you want to say that the fact that the compiler is not required >> to diagnose the error is a flaw in the C language, I won't >> argue with you. > > I'm not even saying it's a flaw in the language. All I'm saying is that > the original claim -- that any error in a C program will be caught by > the compiler -- is false, and more specifically, that it can be > demonstrated to be false without appeal to unknown run-time input. Did someone *really* claim that "any error in a C program will be caught by the compiler"? If so, I must have missed that. It's certainly not true; code that compiles cleanly can be riddled with errors. That's true in any language, but more so in C than in some others. > As an aside, this particular error *could* be caught (and in fact would > be caught by other tools like lint), but there are errors that can not > be caught by any static analysis, and that therefore one should not be > lulled into a false sense of security by the fact that your code is > written in a statically typed language and compiled without errors or > warnings. That's all. I don't believe anyone has said otherwise. >> If I write: >> >> const double pi = 22.0/7.0; >> printf("pi = %f\n", pi); >> >> then I suppose I'm calling printf() incorrectly, but I wouldn't >> expect my compiler to warn me about it. >> >> If you're arguing that >> >> int maximum(int a, int b) { return a > b ? a : b; } >> >> is flawed because it's too easy to call it incorrectly, you're >> effectively arguing that it's not possible to write correct >> code in C at all. > > I would say that it is very, very hard to write correct code in C for > any non-vacuous definition of "correct". That is the reason that core > dumps and buffer overflows are so ubiquitous. I prefer Lisp or Python, > where core dumps and buffer overflows are virtually nonexistent. One > does get the occasional run-time error that might have been caught at > compile time, but I much prefer that to a core dump or a security hole. I would say that it can certainly be difficult to write correct code in C, but I don't believe it's nearly as hard as you think it is. It requires more discipline than some other languages, and it can require some detailed knowledge of the language itself, particularly what it defines and what it doesn't. And it's not always worth the effort if another language can do the job as well or better. > One might hypothesize that the best of both worlds would be a dynamic > language with a static analyzer layered on top. Such a thing does not > exist. It makes an instructive exercise to try to figure out why. (For > the record, I don't know the answer, but I've learned a lot through the > process of pondering this conundrum.) -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From pjb at informatimago.com Thu Sep 30 14:37:22 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 20:37:22 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: <87wrq3m61p.fsf@kuiper.lan.informatimago.com> TheFlyingDutchman writes: >> >> > "in C I can have a function maximum(int a, int b) that will always >> > work. Never blow up, and never give an invalid answer. " >> >> > Dynamic typed languages like Python fail in this case on "Never blows >> > up". >> >> How do you define "Never blows up"? > > Never has execution halt. > > I think a key reason in the big rise in the popularity of interpreted > languages This is a false conception. Whether the execution of a program is done by a processor of the programming language, or a processor of another programming language (and therefore requiring a translation phase), is a notion is NOT a characteristic of programming language, but only of execution environments. 1- There are C interpreters CINT - http://root.cern.ch/root/Cint.html EiC - http://eic.sourceforge.net/ Ch - http://www.softintegration.com 2- All the current Common Lisp implementations have compilers, 3- Most current Common Lisp implementations actually compile to native code (ie they chose to translate to programming languages that are implemented by Intel, AMD or Motorola. (Notice that these programming languages are NOT implemented in hardware, but in software, called micro-code, stored on the real hardware inside the micro-processors); some choose to translate to C and call an external C compiler to eventually translate to "native" code). 4- Actually, there is NO current Common Lisp implementation having only an interpreter. On the contrary, most of the don't have any interpreter (but all of them have a REPL, this is an orthogonal concept). 5- Even the first LISP implementation made in 1959 had a compiler. 6- I know less the situation for the other dynamic programming language, but for example, if CPython weren't a compiler, you should know that CLPython is a compiler (it's an implementation of Python written in Common Lisp, which translates Python into Common Lisp and compiles it). > is that when execution halts, they normally give a call > stack and usually a good reason for why things couldn't continue. As > opposed to compiled languages which present you with a blank screen > and force you to - fire up a debugger, or much much worse, look at a > core dump - to try and discern all the information the interpreter > presents to you immediately. Theorically, a compiler for a static programming language has even more information about the program, so it should be able to produce even better backtrace in case of problem... -- __Pascal Bourguignon__ http://www.informatimago.com/ From hidura at gmail.com Thu Sep 30 14:38:05 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 30 Sep 2010 18:38:05 +0000 Subject: Problems with wsgi Python3 In-Reply-To: <67044A5A-FEE5-4AFE-8CA7-78DBD0B19687@web.de> Message-ID: <90e6ba4765e1fbc29904917e6033@google.com> Sorry, for the last mail, here it's what you asked: {'CONTENT_LENGTH': '61', [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; boundary=---------------------------8905735096173894531259794847', [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite', [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': [Thu Sep 30 13:35:07 2010] [error] 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': [Thu Sep 30 13:35:07 2010] [error] 'close', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': [Thu Sep 30 13:35:07 2010] [error] 'http://hidura.webfactional.com/?md=btdump', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': [Thu Sep 30 13:35:07 2010] [error] '58742', [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': [Thu Sep 30 13:35:07 2010] [error] 'POST', [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': [Thu Sep 30 13:35:07 2010] [error] '[no address given]', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': [Thu Sep 30 13:35:07 2010] [error] '80', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 Python/3.1', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': [Thu Sep 30 13:35:07 2010] [error] 'application', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': [Thu Sep 30 13:35:07 2010] [error] '0', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': [Thu Sep 30 13:35:07 2010] [error] '51543', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': [Thu Sep 30 13:35:07 2010] [error] '1', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': [Thu Sep 30 13:35:07 2010] [error] (3, 3), [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': [Thu Sep 30 13:35:07 2010] [error] <_io.TextIOWrapper encoding='utf-8'>, [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': [Thu Sep 30 13:35:07 2010] [error] , [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': [Thu Sep 30 13:35:07 2010] [error] , [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': [Thu Sep 30 13:35:07 2010] [error] False, [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': [Thu Sep 30 13:35:07 2010] [error] True, [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': [Thu Sep 30 13:35:07 2010] [error] False, [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': [Thu Sep 30 13:35:07 2010] [error] 'http', [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': [Thu Sep 30 13:35:07 2010] [error] (1, 1)} On Sep 30, 2010 1:56pm, "Diez B. Roggisch" wrote: > *sigh* > AGAIN, please do *not* reply to me personally. Reply to the ML or NG you > are posting in. I'm beginning to believe that it's a waste of time to > answer you since you seem not able to follow even the most simple of > advice and rules. > And read the answers you get thoroughly, you did not give all the > information I asked you for. > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > The output is: > > > > -----------------------------110550484811701713451664404475--\r > > > > No more i don 't know what that means or what do with this. > > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: > > > hidura at gmail.com writes: > > > > > > > > > > > > > Hello list, i had seriously troubles with the connection between a > form and the > > > > > > > wsgi, i' ve made an application on Python3 and was running > perfectly but when i > > > > > > > try to use the to pass the data this can't be see on the server, so > what > > > > > > > is your recommendation?, i am open to all the ideas less leave to > Python2 i > > > > > > > can't all the project was write on Python3, i was looking into the > PEP 444 > > > > > > > proposal too. > > > > > > > > > > > > > > Here is the code what i used to take the data: > > > > > > > > > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(environ > > > > > > > ['CONTENT_LENGTH'])).decode())) > > > > > > > > > > > > What is the ouptut of this? What does > > > > > > > > > > > > import pprint > > > > > > pprint.pprint(environ) > > > > > > > > > > > > give you? > > > > > > > > > > > > > > > > > > > > > > > > > > and here it's what the os.environ.item() prints to me: > > > > > > > > > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > > > > > > > > > Diez > > > > > > -- > > > > > > http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Thu Sep 30 14:41:59 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 30 Sep 2010 19:41:59 +0100 Subject: namespace hacking question References: Message-ID: <87mxqzkr9k.fsf@gmail.com> MRAB writes: > On 30/09/2010 18:07, kj wrote: >> >> >> >> This is a recurrent situation: I want to initialize a whole bunch >> of local variables in a uniform way, but after initialization, I >> need to do different things with the various variables. >> >> What I end up doing is using a dict: >> >> d = dict() >> for v in ('spam', 'ham', 'eggs'): >> d[v] = init(v) >> >> foo(d['spam']) >> bar(d['ham']) >> baz(d['eggs']) >> >> >> >> This is fine, but I'd like to get rid of the tedium of typing all >> those extra d['...']s. >> >> I.e., what I would *like* to do is something closer to this: >> >> d = locals() >> for v in ('spam', 'ham', 'eggs'): >> d[v] = init(v) >> >> foo(spam) >> bar(ham) >> baz(eggs) >> >> ...but this results in errors like "NameError: global name 'spam' is >> not defined". >> >> But the problem is deeper than the fact that the error above would >> suggest, because even this fails: >> >> spam = ham = eggs = None >> d = locals() >> for v in ('spam', 'ham', 'eggs'): >> d[v] = init(v) >> >> foo(spam) # calls foo(None) >> bar(ham) # calls bar(None) >> baz(eggs) # calls baz(None) >> >> >> In other words, setting the value of locals()['x'] does not set >> the value of the local variable x. >> >> I also tried a hack using eval: >> >> for v in ('spam', 'ham', 'eggs'): >> eval "%s = init('%s')" % (v, v) >> >> but the "=" sign in the eval string resulted in a "SyntaxError: >> invalid syntax". >> >> Is there any way to use a loop to set a whole bunch of local >> variables (and later refer to these variables by their individual >> names)? >> > The handling of local variables in CPython is optimised, so changing > locals() won't have any effect, as you discovered. > > An alternative is to create a namespace in an instance of a class and > then add attributes to it: > > class Namespace(object): > pass > > n = Namespace() > for v in ('spam', 'ham', 'eggs'): > setattr(n, v, init(v)) > > foo(n.spam) > bar(n.ham) > baz(n.eggs) Note that "exec" can be used: >>> def init(name): ... return "init " + name ... >>> def foo(): ... for name in "bar", "baz": ... exec "%s = init(name)" % name ... print bar ... print baz ... >>> foo() init bar init baz Not that I can think of a reason to do this :) -- Arnaud From Peter.Bienstman at UGent.be Thu Sep 30 14:47:00 2010 From: Peter.Bienstman at UGent.be (pbienst) Date: Thu, 30 Sep 2010 11:47:00 -0700 (PDT) Subject: C API: Getting PyObject by name Message-ID: <3ed9a977-b77f-4f2a-b62c-bae97e2f3339@x42g2000yqx.googlegroups.com> Hi, I'm embedding Python in a C app. Say I do the following: PyRun_SimpleString("a = 1") Is there then a way to get access to the PyObject corresponding to a, only making use in C of the fact that it's called "a"? I've searched through the API docs, but I couldn't really find what I was looking for. Any help most appreciated! Peter From usenet-nospam at seebs.net Thu Sep 30 15:17:39 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 19:17:39 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, RG wrote: > In article , > Seebs wrote: >> And that's the magic of static typing: It is not a false positive to >> warn you that "2L" is not of type int. > We'll have to agree to disagree about that. No, we won't. It's the *definition* of static typing. Static typing is there to give you some guarantees at the expense of not being able to express some things without special extra effort. That's why it's static. > The numerical value 2 can > safely be represented as an int, so I would consider this a false > positive. That's nice for you, I guess. The point of static typing is that it makes it possible to ensure that the values that reach a function are in fact of the correct type -- at the cost of not being able to rely on free runtime conversions. If you want to write safe conversions, you can do that. If you don't bother to do that, you end up with errors -- by definition. -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 Sep 30 15:21:58 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 19:21:58 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: On 2010-09-30, Keith Thompson wrote: > Seebs writes: >> On 2010-09-30, Paul Rubin wrote: >>> int maximum(int a, int b); >>> int foo() { >>> int (*barf)() = maximum; >>> return barf(3); >>> } > That first line declare barf as an object of type "pointer to > function returning int", or more precisely, "pointer to function with > an unspecified but fixed number and type of parameters returning int" > (i.e., an old-style non-prototype declaration, still legal but > deprecated in both C90 and C99). It then initializes it to point > to the "maximum" function. I *think* the types are sufficiently > "compatible" (not necessarily using that word the same way the > standard does) for the initialization to be valid and well defined. > I might check the standard later. Hmm. You have a point. It's clearly a conversion from one type to another. > IMHO it's better to use prototypes consistently than to figure out the > rules for interactions between prototyped vs. non-prototyped function > declarations. Yes. It's clearly undefined behavior to call a function through a pointer to a different type, or to call a function with the wrong number of arguments. I am pretty sure at least one compiler catches 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 thomas at jollybox.de Thu Sep 30 15:24:32 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 30 Sep 2010 21:24:32 +0200 Subject: C API: Getting PyObject by name In-Reply-To: <3ed9a977-b77f-4f2a-b62c-bae97e2f3339@x42g2000yqx.googlegroups.com> References: <3ed9a977-b77f-4f2a-b62c-bae97e2f3339@x42g2000yqx.googlegroups.com> Message-ID: <201009302124.32894.thomas@jollybox.de> On Thursday 30 September 2010, it occurred to pbienst to exclaim: > Hi, > > I'm embedding Python in a C app. > > Say I do the following: > > PyRun_SimpleString("a = 1") > > Is there then a way to get access to the PyObject corresponding to a, > only making use in C of the fact that it's called "a"? > > I've searched through the API docs, but I couldn't really find what I > was looking for. No. Not as such. But you could use PyRun_String, or PyRun_StringFlags. You could then access the globals object, but I ask you, why would you want to bind the object to a name in the first place? Use the fact that PyRun_String returns a reference to the result of an expression! From ian-news at hotmail.com Thu Sep 30 15:29:06 2010 From: ian-news at hotmail.com (Ian Collins) Date: Fri, 01 Oct 2010 08:29:06 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> Message-ID: <8gk6o2Fc8aU2@mid.individual.net> On 10/ 1/10 02:57 AM, Pascal Bourguignon wrote: > Nick Keighley writes: > >> On 27 Sep, 20:29, p... at informatimago.com (Pascal J. Bourguignon) >> wrote: >>> If you start with the mindset of static type checking, you will consider >>> that your types are checked and if the types at the interface of two >>> modules matches you'll think that everything's ok. And six months later >>> you Mars mission will crash. >> >> do you have any evidence that this is actually so? That people who >> program in statically typed languages actually are prone to this "well >> it compiles so it must be right" attitude? > > Yes, I can witness that it's in the mind set. > > Well, the problem being always the same, the time pressures coming from > the sales people (who can sell products of which the first line of > specifications has not been written yet, much less of code), it's always > a battle to explain that once the code is written, there is still a lot > of time needed to run tests and debug it. I've even technical managers, > who should know better, expecting that we write bug-free code in the > first place (when we didn't even have a specification to begin with!). Which is why agile practices such as TDD have an edge. If it compiles *and* passes all its tests, it must be right. -- Ian Collins From jmellander at lbl.gov Thu Sep 30 15:32:45 2010 From: jmellander at lbl.gov (Jim Mellander) Date: Thu, 30 Sep 2010 12:32:45 -0700 Subject: Determine sockets in use by python In-Reply-To: References: <4CA37FDA.3080605@digipen.edu> Message-ID: Thanks, I realized that even if I found out relevant info on the socket, I would probably need to use ctypes to provide a low level interface to select, as the socket wouldn't be a python socket object, unless there is some way to promote a c socket to a python socket object. Appreciate the info, folks. On Thu, Sep 30, 2010 at 7:14 AM, Jean-Paul Calderone wrote: > On Sep 29, 4:08?pm, Jim Mellander wrote: >> >> On Wed, Sep 29, 2010 at 11:05 AM, Gary Herron wrote: >> > On 09/29/2010 09:50 AM, Jim Mellander wrote: >> >> >> Hi: >> >> >> I'm a newbie to python, although not to programming. ?Briefly, I am >> >> using a binding to an external library used for communication in a >> >> client-server context, with the server in python. ?Typically, I would >> >> set this up with event callbacks, and then enter a select loop, which, >> >> most the time idles and processes input events when the socket shows >> >> activity, kinda like: >> >> >> while True: >> >> ? ? socket.select((my_socket),(),()) >> >> ? ? process_event() >> >> >> Unfortunately, the API does not expose the socket to the script level, >> >> and the developer recommends a busy loop: >> >> >> while True: >> >> ? ? sleep(1) >> >> ? ? process_event() >> >> >> which I hope to avoid, for many reasons. ?If the socket can be exposed >> >> to the script level, then the problem would be solved. >> >> >> Failing that, it would be nice to be able to pythonically determine >> >> the sockets in use and select on those. ?Does anyone have any >> >> suggestions on how to proceed? >> >> >> Thanks in advance >> >> > It's certain that any answer to this will depend on which operating system >> > you are using. ?So do tell: What OS? >> >> Hi Gary: >> >> Certainly not windows.... ?I'm developing on OS/X but for production >> probably Linux and FreeBSD >> >> (I'm hoping for something a bit more portable than running 'lsof' and >> parsing the output, but appreciate any/all advice) >> > > Linux has /proc/self/fd and OS X has /dev/fd. ?Those both suppose you > have some way of determining which file descriptor corresponds to the > socket or sockets that the library is using, of course. ?Vastly better > would be to convince the author to expose that information via a real > API. > > Jean-Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From ian-news at hotmail.com Thu Sep 30 15:35:56 2010 From: ian-news at hotmail.com (Ian Collins) Date: Fri, 01 Oct 2010 08:35:56 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: <8gk74sFc8aU3@mid.individual.net> On 10/ 1/10 08:21 AM, Seebs wrote: > On 2010-09-30, Keith Thompson wrote: > >> IMHO it's better to use prototypes consistently than to figure out the >> rules for interactions between prototyped vs. non-prototyped function >> declarations. > > Yes. It's clearly undefined behavior to call a function through a > pointer to a different type, or to call a function with the wrong number > of arguments. I am pretty sure at least one compiler catches this. Any C++ compiler will refuse to accept it. C isn't really a strongly typed language and having to support archaic non-prototyped function declarations makes thorough type checking extremely difficult if not impossible. -- Ian Collins From hidura at gmail.com Thu Sep 30 15:41:58 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 30 Sep 2010 19:41:58 +0000 Subject: Problems with wsgi Python3 In-Reply-To: <90e6ba4765e1fbc29904917e6033@google.com> Message-ID: <90e6ba4fc20672903204917f4555@google.com> What mean this -----------------------------743346150198628700241600224--\r? On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > Sorry, for the last mail, here it's what you asked: > {'CONTENT_LENGTH': '61', > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > boundary=---------------------------8905735096173894531259794847', > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite', > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > [Thu Sep 30 13:35:07 2010] > [error] 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > [Thu Sep 30 13:35:07 2010] [error] 'close', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > [Thu Sep 30 13:35:07 2010] > [error] 'http://hidura.webfactional.com/?md=btdump', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux x86_64; > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > [Thu Sep 30 13:35:07 2010] [error] '58742', > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > [Thu Sep 30 13:35:07 2010] [error] 'POST', > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > [Thu Sep 30 13:35:07 2010] > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > [Thu Sep 30 13:35:07 2010] [error] '80', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 > Python/3.1', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > [Thu Sep 30 13:35:07 2010] [error] 'application', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > [Thu Sep 30 13:35:07 2010] [error] '0', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > [Thu Sep 30 13:35:07 2010] [error] '51543', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > [Thu Sep 30 13:35:07 2010] [error] '1', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > [Thu Sep 30 13:35:07 2010] [error] , > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > [Thu Sep 30 13:35:07 2010] [error] , > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > [Thu Sep 30 13:35:07 2010] [error] , > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > [Thu Sep 30 13:35:07 2010] [error] False, > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > [Thu Sep 30 13:35:07 2010] [error] True, > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > [Thu Sep 30 13:35:07 2010] [error] False, > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > [Thu Sep 30 13:35:07 2010] [error] 'http', > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > > > > > > *sigh* > > > > > > > > AGAIN, please do *not* reply to me personally. Reply to the ML or NG > you are posting in. I'm beginning to believe that it's a waste of time to > answer you since you seem not able to follow even the most simple of > advice and rules. > > > > > > > > And read the answers you get thoroughly, you did not give all the > information I asked you for. > > > > > > > > > > > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > > > > > > > > The output is: > > > > > > > > > > -----------------------------110550484811701713451664404475--\r > > > > > > > > > > No more i don 't know what that means or what do with this. > > > > > > > > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: > > > > > > hidura at gmail.com writes: > > > > > > > > > > > > > > > > > > > > > > > > > Hello list, i had seriously troubles with the connection between > a form and the > > > > > > > > > > > > > wsgi, i' ve made an application on Python3 and was running > perfectly but when i > > > > > > > > > > > > > try to use the to pass the data this can't be see on the server, > so what > > > > > > > > > > > > > is your recommendation?, i am open to all the ideas less leave to > Python2 i > > > > > > > > > > > > > can't all the project was write on Python3, i was looking into > the PEP 444 > > > > > > > > > > > > > proposal too. > > > > > > > > > > > > > > > > > > > > > > > > > > Here is the code what i used to take the data: > > > > > > > > > > > > > > > > > > > > > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(environ > > > > > > > > > > > > > ['CONTENT_LENGTH'])).decode())) > > > > > > > > > > > > > > > > > > > > > > > > What is the ouptut of this? What does > > > > > > > > > > > > > > > > > > > > > > > > import pprint > > > > > > > > > > > > pprint.pprint(environ) > > > > > > > > > > > > > > > > > > > > > > > > give you? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > and here it's what the os.environ.item() prints to me: > > > > > > > > > > > > > > > > > > > > > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > > > > > > > > > > > > > > > > > > > > > Diez > > > > > > > > > > > > -- > > > > > > > > > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From exarkun at twistedmatrix.com Thu Sep 30 15:44:13 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Thu, 30 Sep 2010 19:44:13 -0000 Subject: Determine sockets in use by python In-Reply-To: References: <4CA37FDA.3080605@digipen.edu> Message-ID: <20100930194413.2022.131818072.divmod.xquotient.60@localhost.localdomain> On 07:32 pm, jmellander at lbl.gov wrote: >Thanks, I realized that even if I found out relevant info on the >socket, I would probably need to use ctypes to provide a low level >interface to select, as the socket wouldn't be a python socket object, >unless there is some way to promote a c socket to a python socket >object. > >Appreciate the info, folks. There are a few options to help with that part of it: * select() works with integer file descriptors * socket.socket.fromfd gives you a socket object from an integer file descriptor * os.read and os.write let you read and write directly on file descriptors (although it sounds like you might not need this) Jean-Paul >On Thu, Sep 30, 2010 at 7:14 AM, Jean-Paul Calderone > wrote: >>On Sep 29, 4:08?pm, Jim Mellander wrote: >>> >>>On Wed, Sep 29, 2010 at 11:05 AM, Gary Herron >>>wrote: >>> > On 09/29/2010 09:50 AM, Jim Mellander wrote: >>> >>> >> Hi: >>> >>> >> I'm a newbie to python, although not to programming. ?Briefly, I >>>am >>> >> using a binding to an external library used for communication in a >>> >> client-server context, with the server in python. ?Typically, I >>>would >>> >> set this up with event callbacks, and then enter a select loop, >>>which, >>> >> most the time idles and processes input events when the socket >>>shows >>> >> activity, kinda like: >>> >>> >> while True: >>> >> ? ? socket.select((my_socket),(),()) >>> >> ? ? process_event() >>> >>> >> Unfortunately, the API does not expose the socket to the script >>>level, >>> >> and the developer recommends a busy loop: >>> >>> >> while True: >>> >> ? ? sleep(1) >>> >> ? ? process_event() >>> >>> >> which I hope to avoid, for many reasons. ?If the socket can be >>>exposed >>> >> to the script level, then the problem would be solved. >>> >>> >> Failing that, it would be nice to be able to pythonically >>>determine >>> >> the sockets in use and select on those. ?Does anyone have any >>> >> suggestions on how to proceed? >>> >>> >> Thanks in advance >>> >>> > It's certain that any answer to this will depend on which operating >>>system >>> > you are using. ?So do tell: What OS? >>> >>>Hi Gary: >>> >>>Certainly not windows.... ?I'm developing on OS/X but for production >>>probably Linux and FreeBSD >>> >>>(I'm hoping for something a bit more portable than running 'lsof' and >>>parsing the output, but appreciate any/all advice) >> >>Linux has /proc/self/fd and OS X has /dev/fd. ?Those both suppose you >>have some way of determining which file descriptor corresponds to the >>socket or sockets that the library is using, of course. ?Vastly better >>would be to convince the author to expose that information via a real >>API. >> >>Jean-Paul >>-- >>http://mail.python.org/mailman/listinfo/python-list > From rNOSPAMon at flownet.com Thu Sep 30 15:45:46 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 12:45:46 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: In article <7xr5gbxfry.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > RG writes: > > Yes, I know I could have used lint. But that misses the point. For any > > static analyzer, because of the halting problem, I can construct a > > program that either contains an error that the analyzer will not catch, > > or for which the analyzer will produce a false positive. > > Can you describe any plausible real-world programs where the effort of > complicated static is justified, and for which the halting problem gets > in the way of analysis? By "real world", I meanI wouldn't consider > searching for counterexamples to the Collatz conjecture to qualify as > sufficiently real-world and sufficiently complex for fancy static > analysis. And even if it did, the static analyzer could deliver a > partial result, like "this function either returns a counterexample to > the Collatz conjecture or else it doesn't return". > > D. Turner wrote a famous paper arguing something like the above, saying > basically that Turing completeness of programming languages is > overrated: > > http://www.jucs.org/jucs_10_7/total_functional_programming > > The main example of a sensible program that can't be written in a > non-complete language is an interpreter for a Turing-complete language. > But presumably a high-assurance application should never contain such a > thing, since the interpreted programs themselves then wouldn't have > static assurance. There are only two possibilities: either you have a finite-state machine, or you have a Turning machine. (Well, OK, you could have a pushdown automaton, but there are no programming languages that model a PDA. Well, OK, there's Forth, but AFAIK there are no static type checkers for Forth. Besides, who uses Forth? ;-) If you have a finite state machine everything is trivial. If you have a Turing machine everything is generally impossible. This is an oversimplification but not far from the fundamental underlying truth. My favorite practical example is the square root function. The standard C library defines a square root function on floats (actually on doubles), which is to say, over a finite-state model with 2^64 states. The model is not well defined over half of that range (negative numbers), which the static type checker cannot catch because there is no such thing as an unsigned double. But the fun doesn't stop there. Doubles >= 0.0 are not the only thing one might reasonably want to take a square root of, and indeed C++ overloads sqrt to work on complex and valarray types in addition to floats of various lengths (though you still have to manually keep track of whether or not the argument to sqrt might be a negative real). But what if I want an exact integer square root? Or a square root of a data type that represents irrational numbers not as floating point approximations but as exact symbolic representations? I haven't worked out the details, but I'd be surprised if none of these variations turned out to be Turing complete. The Turner paper is right on point: there's a fundamental distinction between the (known) finite and the (potentially) infinite. In my experience most of the cool interesting stuff has been found in the latter domain, and trying to shoehorn the latter into the former is more trouble then it's worth. rg From jadill33 at gmail.com Thu Sep 30 15:48:51 2010 From: jadill33 at gmail.com (ImpalerCore) Date: Thu, 30 Sep 2010 12:48:51 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> On Sep 29, 9:01?pm, RG wrote: > [ron at mighty:~]$ cat foo.c > #include > > int maximum(int a, int b) { return a > b ? a : b; } > > int main() { > ? long x = 8589934592; > ? printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > ? return 0;} > > [ron at mighty:~]$ gcc -Wall foo.c > [ron at mighty:~]$ ./a.out > Max of 8589934592 and 1 is 1 In the context of procedural programming, there is always an implicit contract between the function and its client. If you're going to fool around sending cleverly crafted garbage into the input of 'maximum' due to C conversion rules, why do you expect the 'maximum' function to be responsible for producing the correct response to an ill-formed question? What alternative behavior of 'maximum' would you prefer to see, that the C language auto-promote the function arguments and return type to type long based on the type of arguments provided to the 'maximum' function? You either learn to play in the sandbox that C provides, splinters and all, or you find another sandbox. Best regards, John D. From kst-u at mib.org Thu Sep 30 15:52:08 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 12:52:08 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: RG writes: > In article , > Seebs wrote: > >> On 2010-09-30, Lie Ryan wrote: >> > On 09/30/10 16:09, TheFlyingDutchman wrote: >> >> Dynamic typed languages like Python fail in this case on "Never blows >> >> up". >> >> > How do you define "Never blows up"? >> >> I would say "blow up" would be "raise an exception". >> >> > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow >> > up, and of the worst kind since it passes silently. >> >> So run your compiler with a decent set of warning levels, and watch as >> you are magically warned that you're passing an object of the wrong type. > > My code compiles with no warnings under gcc -Wall. Conclusion: "-Wall" is not "a decent set of warning levels" in this context, in spite of the name. (If you want to complain that the name "-Wall" is misleading, I won't disagree, but it's a gcc issue, not a C issue.) With "-Wconversion", I get: c.c: In function 'main': c.c:7: warning: passing argument 1 of 'maximum' with different width due to prototype [...] >> On any given system, one or the other is true: >> >> 1. The constant 8589934592 is of type int, and the function will >> "work" -- will give that result. >> 2. The constant is not of type int, and the compiler will warn you about >> this if you ask. > > It would be nice if this were true, but my example clearly demonstrates > that it is not. And if your response is to say that I should have used > lint, then my response to that will be that because of the halting > problem, for any static analyzer that you present, I can construct a > program that either contains an error that either your analyzer will not > catch, or for which it will generate a false positive. It just so > happens that constructing such examples for standard C is very easy. And yet you have not managed to do it. It seems to me that the line between errors that a sufficiently clever compiler could or should warn you about, and errors that compilers cannot reasonably be expected to detect, is a very fuzzy one. A fairly clear example of the latter is: const double pi = 2.71828182845904523526; To a human reader, it's obviously either a mistake or deliberate obfuscation, but I'm not sure I'd *want* my compiler to warn me about it just because I named the object "pi" rather than "e". (And if I called it "x", even an intelligent human wouldn't know that it's wrong.) -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From rNOSPAMon at flownet.com Thu Sep 30 15:52:58 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 12:52:58 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> Message-ID: In article <0390e2b4-fa28-49b3-a867-39be6d66828f at w19g2000yqb.googlegroups.com>, ImpalerCore wrote: > On Sep 29, 9:01?pm, RG wrote: > > > > > [ron at mighty:~]$ cat foo.c > > #include > > > > int maximum(int a, int b) { return a > b ? a : b; } > > > > int main() { > > ? long x = 8589934592; > > ? printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > > ? return 0;} > > > > [ron at mighty:~]$ gcc -Wall foo.c > > [ron at mighty:~]$ ./a.out > > Max of 8589934592 and 1 is 1 > > In the context of procedural programming, there is always an implicit > contract between the function and its client. If you're going to fool > around sending cleverly crafted garbage into the input of 'maximum' > due to C conversion rules, why do you expect the 'maximum' function to > be responsible for producing the correct response to an ill-formed > question? What alternative behavior of 'maximum' would you prefer to > see, that the C language auto-promote the function arguments and > return type to type long based on the type of arguments provided to > the 'maximum' function? > > You either learn to play in the sandbox that C provides, splinters and > all, or you find another sandbox. > > Best regards, > John D. You're missing a lot of context. I'm not trying to criticize C, just to refute a false claim that was made about it. rg From rNOSPAMon at flownet.com Thu Sep 30 15:56:58 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 12:56:58 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Seebs wrote: > On 2010-09-30, RG wrote: > > In article , > > Seebs wrote: > >> And that's the magic of static typing: It is not a false positive to > >> warn you that "2L" is not of type int. > > > We'll have to agree to disagree about that. > > No, we won't. It's the *definition* of static typing. Static typing > is there to give you some guarantees at the expense of not being able > to express some things without special extra effort. That's why it's > static. I don't want to quibble over terminology. Whatever label you choose to put on it ("false positive", "not being able to express some things without special extra effort") I consider it a deficiency. The costs are greater than the benefits. Reasonable people can (and obviously do) disagree. rg From thomas at jollybox.de Thu Sep 30 16:02:47 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 30 Sep 2010 22:02:47 +0200 Subject: Problems with wsgi Python3 In-Reply-To: <90e6ba4fc20672903204917f4555@google.com> References: <90e6ba4fc20672903204917f4555@google.com> Message-ID: <201009302202.47714.thomas@jollybox.de> On Thursday 30 September 2010, it occurred to hidura at gmail.com to exclaim: > What mean this > -----------------------------743346150198628700241600224--\r? it looks like a MIME boundary. In this context most likely from a multipart/form-data transmission. > > On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > > Sorry, for the last mail, here it's what you asked: > > > > {'CONTENT_LENGTH': '61', > > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > > boundary=---------------------------8905735096173894531259794847', > > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > > [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite', > > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > > [Thu Sep 30 13:35:07 2010] > > [error] > > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', [Thu > > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > > [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > > [Thu Sep 30 13:35:07 2010] [error] 'close', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > > [Thu Sep 30 13:35:07 2010] > > [error] 'http://hidura.webfactional.com/?md=btdump', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux x86_64; > > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > > [Thu Sep 30 13:35:07 2010] [error] '58742', > > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > > [Thu Sep 30 13:35:07 2010] [error] 'POST', > > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > > [Thu Sep 30 13:35:07 2010] > > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > > [Thu Sep 30 13:35:07 2010] [error] '80', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 > > Python/3.1', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > > [Thu Sep 30 13:35:07 2010] [error] 'application', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > > [Thu Sep 30 13:35:07 2010] [error] '0', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > > [Thu Sep 30 13:35:07 2010] [error] '51543', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > > [Thu Sep 30 13:35:07 2010] [error] '1', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > > [Thu Sep 30 13:35:07 2010] [error] , > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > > [Thu Sep 30 13:35:07 2010] [error] , > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > > [Thu Sep 30 13:35:07 2010] [error] , > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > > [Thu Sep 30 13:35:07 2010] [error] False, > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > > [Thu Sep 30 13:35:07 2010] [error] True, > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > > [Thu Sep 30 13:35:07 2010] [error] False, > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > > [Thu Sep 30 13:35:07 2010] [error] 'http', > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > > > > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > > > *sigh* > > > > > > > > > > > > AGAIN, please do *not* reply to me personally. Reply to the ML or NG > > > > you are posting in. I'm beginning to believe that it's a waste of time to > > answer you since you seem not able to follow even the most simple of > > advice and rules. > > > > > And read the answers you get thoroughly, you did not give all the > > > > information I asked you for. > > > > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > > > The output is: > > > > > > > > > > > > > > > > -----------------------------110550484811701713451664404475--\r > > > > > > > > > > > > > > > > No more i don 't know what that means or what do with this. > > > > > > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: > > > > > hidura at gmail.com writes: > > > > > > Hello list, i had seriously troubles with the connection between > > > > a form and the > > > > > > > > wsgi, i' ve made an application on Python3 and was running > > > > perfectly but when i > > > > > > > > try to use the to pass the data this can't be see on the server, > > > > so what > > > > > > > > is your recommendation?, i am open to all the ideas less leave to > > > > Python2 i > > > > > > > > can't all the project was write on Python3, i was looking into > > > > the PEP 444 > > > > > > > > proposal too. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Here is the code what i used to take the data: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro > > > > > > n > > > > > > > > > > > > > > > > > > > > > > > > ['CONTENT_LENGTH'])).decode())) > > > > > > > > > > What is the ouptut of this? What does > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > import pprint > > > > > > > > > > > > > > > > > > > > pprint.pprint(environ) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > give you? > > > > > > > > > > > and here it's what the os.environ.item() prints to me: > > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Diez > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > > > > > > > > > http://mail.python.org/mailman/listinfo/python-list From gene.ressler at gmail.com Thu Sep 30 16:06:53 2010 From: gene.ressler at gmail.com (Gene) Date: Thu, 30 Sep 2010 13:06:53 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: On Sep 30, 3:45?pm, RG wrote: > In article <7xr5gbxfry.... at ruckus.brouhaha.com>, > ?Paul Rubin wrote: > > > > > > > RG writes: > > > Yes, I know I could have used lint. ?But that misses the point. ?For any > > > static analyzer, because of the halting problem, I can construct a > > > program that either contains an error that the analyzer will not catch, > > > or for which the analyzer will produce a false positive. > > > Can you describe any plausible real-world programs where the effort of > > complicated static is justified, and for which the halting problem gets > > in the way of analysis? ?By "real world", I meanI wouldn't consider > > searching for counterexamples to the Collatz conjecture to qualify as > > sufficiently real-world and sufficiently complex for fancy static > > analysis. ?And even if it did, the static analyzer could deliver a > > partial result, like "this function either returns a counterexample to > > the Collatz conjecture or else it doesn't return". ? > > > D. Turner wrote a famous paper arguing something like the above, saying > > basically that Turing completeness of programming languages is > > overrated: > > > ?http://www.jucs.org/jucs_10_7/total_functional_programming > > > The main example of a sensible program that can't be written in a > > non-complete language is an interpreter for a Turing-complete language. > > But presumably a high-assurance application should never contain such a > > thing, since the interpreted programs themselves then wouldn't have > > static assurance. > > There are only two possibilities: either you have a finite-state > machine, or you have a Turning machine. ?(Well, OK, you could have a > pushdown automaton, but there are no programming languages that model a > PDA. ?Well, OK, there's Forth, but AFAIK there are no static type > checkers for Forth. ?Besides, who uses Forth? ;-) > > If you have a finite state machine everything is trivial. ?If you have a > Turing machine everything is generally impossible. ?This is an > oversimplification but not far from the fundamental underlying truth. > > My favorite practical example is the square root function. ?The standard > C library defines a square root function on floats (actually on > doubles), which is to say, over a finite-state model with 2^64 states. ? > The model is not well defined over half of that range (negative > numbers), which the static type checker cannot catch because there is no > such thing as an unsigned double. > > But the fun doesn't stop there. ?Doubles >= 0.0 are not the only thing > one might reasonably want to take a square root of, and indeed C++ > overloads sqrt to work on complex and valarray types in addition to > floats of various lengths (though you still have to manually keep track > of whether or not the argument to sqrt might be a negative real). ?But > what if I want an exact integer square root? ?Or a square root of a data > type that represents irrational numbers not as floating point > approximations but as exact symbolic representations? ?I haven't worked > out the details, but I'd be surprised if none of these variations turned > out to be Turing complete. > > The Turner paper is right on point: there's a fundamental distinction > between the (known) finite and the (potentially) infinite. ?In my > experience most of the cool interesting stuff has been found in the > latter domain, and trying to shoehorn the latter into the former is more > trouble then it's worth. > The FA or TM dichotomy is more painful to contemplate than you say. Making appropriate simplifications for input, any modern computer is a FA with 2^(a few trillion) states. Consequently, the gestalt of computer science seems to be to take it on faith that at some very large number of states, the FA behavior makes a transition to TM behavior for all possible practical purposes (and I mean all). So what is it--really--that's trivial to analyze? And what is impossible? I'm sorry this is drifting OT and will stop here. From rNOSPAMon at flownet.com Thu Sep 30 16:14:18 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 13:14:18 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Keith Thompson wrote: > RG writes: > > In article , > > Seebs wrote: > > > >> On 2010-09-30, Lie Ryan wrote: > >> > On 09/30/10 16:09, TheFlyingDutchman wrote: > >> >> Dynamic typed languages like Python fail in this case on "Never blows > >> >> up". > >> > >> > How do you define "Never blows up"? > >> > >> I would say "blow up" would be "raise an exception". > >> > >> > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > >> > up, and of the worst kind since it passes silently. > >> > >> So run your compiler with a decent set of warning levels, and watch as > >> you are magically warned that you're passing an object of the wrong type. > > > > My code compiles with no warnings under gcc -Wall. > > Conclusion: "-Wall" is not "a decent set of warning levels" in this > context, in spite of the name. (If you want to complain that the > name "-Wall" is misleading, I won't disagree, but it's a gcc issue, > not a C issue.) > > With "-Wconversion", I get: > > c.c: In function 'main': > c.c:7: warning: passing argument 1 of 'maximum' with different width due to > prototype > > [...] That gives (what I would consider to be) false positives, e.g.: [ron at mighty:~]$ cat foo.c void foo(long x) {} int main() { foo(1); } [ron at mighty:~]$ gcc -Wconversion foo.c foo.c: In function ?main?: foo.c:4: warning: passing argument 1 of ?foo? with different width due to prototype > >> On any given system, one or the other is true: > >> > >> 1. The constant 8589934592 is of type int, and the function will > >> "work" -- will give that result. > >> 2. The constant is not of type int, and the compiler will warn you about > >> this if you ask. > > > > It would be nice if this were true, but my example clearly demonstrates > > that it is not. And if your response is to say that I should have used > > lint, then my response to that will be that because of the halting > > problem, for any static analyzer that you present, I can construct a > > program that either contains an error that either your analyzer will not > > catch, or for which it will generate a false positive. It just so > > happens that constructing such examples for standard C is very easy. > > And yet you have not managed to do it. Actually I have. Twice now. Remember, the claim is not that the compiler will fail to warn. It's trivial to never fail to warn simply by always warning. The claim is that the compiler with *either* fail to warn *or* generate false positives. So you have to choose your compiler (and flags) first, and then I get to construct my example. If my example has *either* an error that the compiler doesn't catch *or* a non-error that it does catch then I win. Want to try another round? rg From pjb at informatimago.com Thu Sep 30 16:17:45 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 22:17:45 +0200 Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: <87mxqzm1ee.fsf@kuiper.lan.informatimago.com> RG writes: >> The main example of a sensible program that can't be written in a >> non-complete language is an interpreter for a Turing-complete language. >> But presumably a high-assurance application should never contain such a >> thing, since the interpreted programs themselves then wouldn't have >> static assurance. > > There are only two possibilities: either you have a finite-state > machine, or you have a Turning machine. (Well, OK, you could have a > pushdown automaton, but there are no programming languages that model a > PDA. Well, OK, there's Forth, but AFAIK there are no static type > checkers for Forth. Besides, who uses Forth? ;-) > > If you have a finite state machine everything is trivial. If you have a > Turing machine everything is generally impossible. This is an > oversimplification but not far from the fundamental underlying truth. All our computers are FSA: they don't have infinite memory. Even if we developed a robot able to crunch stellar matter and use it as memory, it would still NOT be a Turing Machine, since the universe is finite, has finite matter and energy. Therefore it's trivial. (Indeed, the answer is 42). Now the problem is rather our minds. We use the notion of mathematical infinite, and of Turing Machines vs. DFA, because beyond a certain size, a DFA is not manageable any more by our little minds, and also, computationnaly. While it's finite, computing its most of its properties will require more time than the universe (which is also limited in time). So we need another conceptualization to reduce the complexity of big DFAs. Turing Machines are much simplier, they just slip the complexity under the infinite tape (which conceptually is rather simple, as long as you don't try to reach the end of the tape, or you don't try to use it to weave an infinite rug... -- __Pascal Bourguignon__ http://www.informatimago.com/ From pjb at informatimago.com Thu Sep 30 16:20:20 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 22:20:20 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> Message-ID: <87iq1nm1a3.fsf@kuiper.lan.informatimago.com> Ian Collins writes: > On 10/ 1/10 02:57 AM, Pascal Bourguignon wrote: >> Nick Keighley writes: >> >>> On 27 Sep, 20:29, p... at informatimago.com (Pascal J. Bourguignon) >>> wrote: >>>> If you start with the mindset of static type checking, you will consider >>>> that your types are checked and if the types at the interface of two >>>> modules matches you'll think that everything's ok. And six months later >>>> you Mars mission will crash. >>> >>> do you have any evidence that this is actually so? That people who >>> program in statically typed languages actually are prone to this "well >>> it compiles so it must be right" attitude? >> >> Yes, I can witness that it's in the mind set. >> >> Well, the problem being always the same, the time pressures coming from >> the sales people (who can sell products of which the first line of >> specifications has not been written yet, much less of code), it's always >> a battle to explain that once the code is written, there is still a lot >> of time needed to run tests and debug it. I've even technical managers, >> who should know better, expecting that we write bug-free code in the >> first place (when we didn't even have a specification to begin with!). > > Which is why agile practices such as TDD have an edge. If it compiles > *and* passes all its tests, it must be right. Well, at least it passes the test. I would like to see a peer reviewed proof that the program is correct ;-) But indeed tests are required in any case. -- __Pascal Bourguignon__ http://www.informatimago.com/ From no.email at nospam.invalid Thu Sep 30 16:21:45 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 13:21:45 -0700 Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: <7xtyl7oucm.fsf@ruckus.brouhaha.com> RG writes: > There are only two possibilities: either you have a finite-state > machine, or you have a Turning machine. (Well, OK, you could have a > pushdown automaton, but there are no programming languages that model a > PDA. The point is that the halting problem for general Turing machines is undecidable, but there is a subset of the Turing machines, in which the halting problem is decidable. And it turns out that the decidable subset is substantial enough to write almost every program anyone usually wants to write in practice. > Well, OK, there's Forth, but AFAIK there are no static type > checkers for Forth. http://home.vrweb.de/stephan.becher/forth/ but anyway, Forth is Turing-complete. > If you have a finite state machine everything is trivial. If you have a > Turing machine everything is generally impossible. This is an > oversimplification but not far from the fundamental underlying truth. I'm sorry, but I don't think you understand the actual situation enough to be making pronouncements like that. The stuff about finite-state machines isn't even slightly relevant. > The Turner paper is right on point: there's a fundamental distinction > between the (known) finite and the (potentially) infinite. In my > experience most of the cool interesting stuff has been found in the > latter domain, and trying to shoehorn the latter into the former is more > trouble then it's worth. The point of the Turner paper is that you can design a language with separate types for finite data (like arrays) and "infinite" data (like an endless stream of requests going into a server). Such a language can restrict you to writing provably halting programs on the finite data, and provably non-halting programs on the infinite data. That is, the language doesn't let you write infinite loops on finite data or break out of infinite loops on infinite data (you can only shut down your server by "unplugging the computer", e.g. by killing the process externally). The claim is that these two classes of programs are enough for most purposes. The third possible class, the programs like the Collatz searcher where you can't tell by static analysis whether the program halts, just isn't that important. The paper argues that by giving up the ability to express those undecidable programs, a language can gain other advantages that make up for the loss of Turing-completeness most of the time. I don't think anyone has suggested languages like that are a great idea for everyday programming, but obviously there can be metholodogies that use such approaches for special purposes. From pjb at informatimago.com Thu Sep 30 16:25:56 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 22:25:56 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: <87eicbm10r.fsf@kuiper.lan.informatimago.com> Keith Thompson writes: > const double pi = 2.71828182845904523526; > > To a human reader, it's obviously either a mistake or deliberate > obfuscation, but I'm not sure I'd *want* my compiler to warn me > about it just because I named the object "pi" rather than "e". > (And if I called it "x", even an intelligent human wouldn't know > that it's wrong.) Well, you see, I think it would be perfectly nice from a compiler to provide a warning if you gave that value to a variable named pi. On the other hand, I'd expect an error where gcc only gives warning (I usually compile with -Werror, but that should be the default). -- __Pascal Bourguignon__ http://www.informatimago.com/ From kst-u at mib.org Thu Sep 30 16:34:44 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 13:34:44 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: Seebs writes: > On 2010-09-30, Keith Thompson wrote: >> Seebs writes: >>> On 2010-09-30, Paul Rubin wrote: >>>> int maximum(int a, int b); > >>>> int foo() { >>>> int (*barf)() = maximum; >>>> return barf(3); >>>> } > >> That first line declare barf as an object of type "pointer to >> function returning int", or more precisely, "pointer to function with >> an unspecified but fixed number and type of parameters returning int" >> (i.e., an old-style non-prototype declaration, still legal but >> deprecated in both C90 and C99). It then initializes it to point >> to the "maximum" function. I *think* the types are sufficiently >> "compatible" (not necessarily using that word the same way the >> standard does) for the initialization to be valid and well defined. >> I might check the standard later. > > Hmm. You have a point. It's clearly a conversion from one type > to another. If I'm reading 6.7.5.3p15 correctly, the types int (*)() and int (*)(int, int) are compatible, so the declaration and initialization of barf is perfectly legal, and a call bar(3, 4) would also be legal and would return 4. I actually didn't notice on my initial reading that the call is passing the wrong number of arguments. Since the type of barf doesn't specify the number or types of the arguments, no diagnostic is required, but the behavior is undefined. >> IMHO it's better to use prototypes consistently than to figure out the >> rules for interactions between prototyped vs. non-prototyped function >> declarations. > > Yes. It's clearly undefined behavior to call a function through a > pointer to a different type, or to call a function with the wrong number > of arguments. I am pretty sure at least one compiler catches this. The former is not a problem here; the type of barf is compatible with the type of a pointer to maximum. The latter is the problem, and a sufficiently clever compiler can warn about it. Note that you could do something silly like this: int one_param(int a); int two_params(int a, int b); int (*barf)(); if (some_condition) { barf = one_param; } else { barf = two_params; } if (some_other_condition) { barf(1); } else { barf(2, 3); } No constraint violations, and no undefined behavior as long as some_condition and some_other_condition have the same value. The best a compiler can do (unless it knows about the conditions) is warn you that something *might* go wrong. For programmers, the solution is simple: *Don't do that!*. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From no.email at nospam.invalid Thu Sep 30 16:36:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 13:36:40 -0700 Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: <7xpqvvotnr.fsf@ruckus.brouhaha.com> RG writes: > I don't want to quibble over terminology. Whatever label you choose to > put on it ("false positive", "not being able to express some things > without special extra effort") I consider it a deficiency. The costs > are greater than the benefits. Reasonable people can (and obviously do) > disagree. Chris Smith's essay "What To Know Before Debating Type Systems" discusses the question basically that way, without taking either side. It's well worth reading: http://web.archive.org/web/20080822101209/http://www.pphsg.org/cdsmith/types.html From deets at web.de Thu Sep 30 16:55:13 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 30 Sep 2010 22:55:13 +0200 Subject: Problems with wsgi Python3 References: <90e6ba4fc20672903204917f4555@google.com> Message-ID: Thomas Jollans writes: > On Thursday 30 September 2010, it occurred to hidura at gmail.com to exclaim: >> What mean this >> -----------------------------743346150198628700241600224--\r? > > it looks like a MIME boundary. In this context most likely from a > multipart/form-data transmission. yep, as one can see in the headers below. Additonally, it looks to me as if the form you are submitting is empty. The content-length of just 61 matches barely the boundary. Use something like pdict = cgi.parse_header(environ["CONTENT_TYPE"])[1] cgi.parse_multipart(environ["wsgi.input"], pdict) to properly parse the request. But then of course actually upload something. Diez > >> >> On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: >> > Sorry, for the last mail, here it's what you asked: >> > >> > {'CONTENT_LENGTH': '61', >> > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': >> > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; >> > boundary=---------------------------8905735096173894531259794847', >> > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': >> > [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite', >> > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': >> > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': >> > [Thu Sep 30 13:35:07 2010] >> > [error] >> > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', [Thu >> > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': >> > [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': >> > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': >> > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': >> > [Thu Sep 30 13:35:07 2010] [error] 'close', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': >> > [Thu Sep 30 13:35:07 2010] >> > [error] 'http://hidura.webfactional.com/?md=btdump', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': >> > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux x86_64; >> > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': >> > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', >> > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': >> > [Thu Sep 30 13:35:07 2010] [error] '58742', >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': >> > [Thu Sep 30 13:35:07 2010] [error] 'POST', >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': >> > [Thu Sep 30 13:35:07 2010] >> > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': >> > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': >> > [Thu Sep 30 13:35:07 2010] [error] '80', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': >> > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 >> > Python/3.1', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': >> > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': >> > [Thu Sep 30 13:35:07 2010] [error] 'application', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': >> > [Thu Sep 30 13:35:07 2010] [error] '0', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': >> > [Thu Sep 30 13:35:07 2010] [error] '51543', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': >> > [Thu Sep 30 13:35:07 2010] [error] '1', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': >> > [Thu Sep 30 13:35:07 2010] [error] (3, 3), >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': >> > [Thu Sep 30 13:35:07 2010] [error] , >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': >> > [Thu Sep 30 13:35:07 2010] [error] , >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': >> > [Thu Sep 30 13:35:07 2010] [error] , >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': >> > [Thu Sep 30 13:35:07 2010] [error] False, >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': >> > [Thu Sep 30 13:35:07 2010] [error] True, >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': >> > [Thu Sep 30 13:35:07 2010] [error] False, >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': >> > [Thu Sep 30 13:35:07 2010] [error] 'http', >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': >> > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} >> > >> > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: >> > > *sigh* >> > > >> > > >> > > >> > > AGAIN, please do *not* reply to me personally. Reply to the ML or NG >> > >> > you are posting in. I'm beginning to believe that it's a waste of time to >> > answer you since you seem not able to follow even the most simple of >> > advice and rules. >> > >> > > And read the answers you get thoroughly, you did not give all the >> > >> > information I asked you for. >> > >> > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: >> > > > The output is: >> > > > >> > > > >> > > > >> > > > -----------------------------110550484811701713451664404475--\r >> > > > >> > > > >> > > > >> > > > No more i don 't know what that means or what do with this. >> > > > >> > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: >> > > > > hidura at gmail.com writes: >> > > > > > Hello list, i had seriously troubles with the connection between >> > >> > a form and the >> > >> > > > > > wsgi, i' ve made an application on Python3 and was running >> > >> > perfectly but when i >> > >> > > > > > try to use the to pass the data this can't be see on the server, >> > >> > so what >> > >> > > > > > is your recommendation?, i am open to all the ideas less leave to >> > >> > Python2 i >> > >> > > > > > can't all the project was write on Python3, i was looking into >> > >> > the PEP 444 >> > >> > > > > > proposal too. >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > Here is the code what i used to take the data: >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro >> > > > > > n >> > > > > > >> > > > > > >> > > > > > >> > > > > > ['CONTENT_LENGTH'])).decode())) >> > > > > >> > > > > What is the ouptut of this? What does >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > import pprint >> > > > > >> > > > > >> > > > > >> > > > > pprint.pprint(environ) >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > give you? >> > > > > >> > > > > > and here it's what the os.environ.item() prints to me: >> > > > > That's irrelevant. The WSGI-environ is what is needed. >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > Diez >> > > > > >> > > > > >> > > > > >> > > > > -- >> > > > > >> > > > > >> > > > > >> > > > > http://mail.python.org/mailman/listinfo/python-list From kst-u at mib.org Thu Sep 30 17:02:06 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 14:02:06 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> Message-ID: RG writes: [...] > You're missing a lot of context. I'm not trying to criticize C, just to > refute a false claim that was made about it. Can you cite the article that made this false claim, and exactly what the false claim was? -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From dsrtegle at gmail.com Thu Sep 30 17:06:14 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Thu, 30 Sep 2010 14:06:14 -0700 (PDT) Subject: Pyflakes and IPython does not work for Emacs on Windows? References: Message-ID: On Sep 24, 4:53?pm, David Robinow wrote: > On Fri, Sep 24, 2010 at 4:59 PM,DsrtEgle wrote: > > ... > > I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el > > only works for Linux? > > There don't appear to be a lot of ipython.el users on Windows. > You may have better look on an emacs list since there appear to be > some configuration issues. > Doeshttps://bugs.launchpad.net/ipython/+bug/290228? ? help at all? Hi David, This fix seems not working for me. I am using IPython 0.10, Python 2.5, and EmacsW32 23.1. When I invoke python-shell in Emacs, IPython crashes with the following long debugging information: ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (14, 0)) --------------------------------------------------------------------------- TypeError Python 2.5.2: C: \Python25\python.exe Thu Sep 30 14:00:08 2010 A problem occured executing Python code. Here is the sequence of function calls leading up to the error, with the most recent (innermost) call last. c:\Python25\Scripts\ipython-script.py in () 1 2 3 4 5 6 7 ----> 8 global load_entry_point = 9 #!C:\Python25\python.exe 10 # EASY-INSTALL-ENTRY-SCRIPT: 'ipython==0.10','console_scripts','ipython' 11 __requires__ = 'ipython==0.10' 12 import sys 13 from pkg_resources import load_entry_point 14 15 sys.exit( 16 load_entry_point('ipython==0.10', 'console_scripts', 'ipython')() 17 ) 18 19 20 21 22 23 24 25 26 27 28 29 30 31 C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\ipapi.pyc in launch_new_instance(user_ns=None, shellclass=None) 541 542 def check_hotname(self,name): 543 if name in self.hotnames: 544 self.debug_stack( "HotName '%s' caught" % name) 545 546 547 def launch_new_instance(user_ns = None,shellclass = None): 548 """ Make and start a new ipython instance. 549 550 This can be called even without having an already initialized 551 ipython session running. 552 553 This is also used as the egg entry point for the 'ipython' script. 554 555 """ --> 556 ses = make_session(user_ns,shellclass) 557 ses.mainloop() 558 559 560 def make_user_ns(user_ns = None): 561 """Return a valid user interactive namespace. 562 563 This builds a dict with the minimal information needed to operate as a 564 valid IPython user namespace, which you can pass to the various embedding 565 classes in ipython. 566 567 This API is currently deprecated. Use ipapi.make_user_namespaces() instead 568 to make both the local and global namespace objects simultaneously. 569 570 :Parameters: 571 user_ns : dict-like, optional C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\ipapi.pyc in make_session(user_ns=None, shellclass=None) 669 670 def make_session(user_ns = None, shellclass = None): 671 """Makes, but does not launch an IPython session. 672 673 Later on you can call obj.mainloop() on the returned object. 674 675 Inputs: 676 677 - user_ns(None): a dict to be used as the user's namespace with initial 678 data. 679 680 WARNING: This should *not* be run when a session exists already.""" 681 682 import IPython.Shell 683 if shellclass is None: --> 684 return IPython.Shell.start(user_ns) 685 return shellclass(user_ns = user_ns) 686 687 688 689 690 691 692 693 694 695 696 697 698 699 C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\Shell.pyc in start(user_ns=None) 1226 th_mode = special_opts.pop() 1227 except KeyError: 1228 th_mode = 'tkthread' 1229 return th_shell[th_mode] 1230 1231 1232 # This is the one which should be called by external code. 1233 def start(user_ns = None): 1234 """Return a running shell instance, dealing with threading options. 1235 1236 This is a factory function which will instantiate the proper IPython shell 1237 based on the user's threading choice. Such a selector is needed because 1238 different GUI toolkits require different thread handling details.""" 1239 1240 shell = _select_shell(sys.argv) -> 1241 return shell(user_ns = user_ns) 1242 1243 # Some aliases for backwards compatibility 1244 IPythonShell = IPShell 1245 IPythonShellEmbed = IPShellEmbed 1246 #************************ End of file *************************** 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\Shell.pyc in __init__(self=, argv=None, user_ns=None, user_global_ns=None, debug=1, shell_class=) 58 # Default timeout for waiting for multithreaded shells (in seconds) 59 GUI_TIMEOUT = 10 60 61 #----------------------------------------------------------------------------- 62 # This class is trivial now, but I want to have it in to publish a clean 63 # interface. Later when the internals are reorganized, code that uses this 64 # shouldn't have to change. 65 66 class IPShell: 67 """Create an IPython instance.""" 68 69 def __init__(self,argv=None,user_ns=None,user_global_ns=None, 70 debug=1,shell_class=InteractiveShell): 71 self.IP = make_IPython(argv,user_ns=user_ns, 72 user_global_ns=user_global_ns, ---> 73 debug=debug,shell_class=shell_class) global that = undefined global gets = undefined global prepended = undefined global to = undefined global all = undefined global calls = undefined global so = undefined global header = undefined global used = undefined 74 75 def mainloop(self,sys_exit=0,banner=None): 76 self.IP.mainloop(banner) 77 if sys_exit: 78 sys.exit() 79 80 #----------------------------------------------------------------------------- 81 def kill_embedded(self,parameter_s=''): 82 """%kill_embedded : deactivate for good the current embedded IPython. 83 84 This function (after asking for confirmation) sets an internal flag so that 85 an embedded IPython will never activate again. This is useful to 86 permanently disable a shell that is being called inside a loop: once you've 87 figured out what you needed from it, you may then kill it and the program 88 will then continue to run without the interactive shell interfering again. C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython \ipmaker.pyc in make_IPython(argv=[r'c:\Python25\Scripts\ipython- script.py', '-i'], user_ns=None, user_global_ns=None, debug=1, rc_override=None, shell_class=, embedded=False, **kw={}) 755 IP_rc.banner = 0 756 if IP_rc.banner: 757 BANN_P = IP.BANNER_PARTS 758 else: 759 BANN_P = [] 760 761 if IP_rc.profile: BANN_P.append('IPython profile: %s\n' % IP_rc.profile) 762 763 # add message log (possibly empty) 764 if msg.summary: BANN_P.append(msg.summary) 765 # Final banner is a string 766 IP.BANNER = '\n'.join(BANN_P) 767 768 # Finalize the IPython instance. This assumes the rc structure is fully 769 # in place. --> 770 IP.post_config_initialization() 771 772 return IP 773 #************************ end of file ************************** 774 775 776 777 778 779 780 781 782 783 784 785 C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\iplib.pyc in post_config_initialization(self=) 847 This is called after the configuration files have been processed to 848 'finalize' the initialization.""" 849 850 rc = self.rc 851 852 # Object inspector 853 self.inspector = OInspect.Inspector(OInspect.InspectColors, 854 PyColorize.ANSICodeColors, 855 'NoColor', 856 rc.object_info_string_level) 857 858 self.rl_next_input = None 859 self.rl_do_indent = False 860 # Load readline proper 861 if rc.readline: --> 862 self.init_readline() 863 864 # local shortcut, this is used a LOT 865 self.log = self.logger.log 866 867 # Initialize cache, set in/out prompts and printing system 868 self.outputcache = CachedOutput(self, 869 rc.cache_size, 870 rc.pprint, 871 input_sep = rc.separate_in, 872 output_sep = rc.separate_out, 873 output_sep2 = rc.separate_out2, 874 ps1 = rc.prompt_in1, 875 ps2 = rc.prompt_in2, 876 ps_out = rc.prompt_out, 877 pad_left = rc.prompts_pad_left) C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\iplib.pyc in init_readline(self=) 1476 if not readline.uses_libedit: 1477 for rlcommand in self.rc.readline_parse_and_bind: 1478 #print "loading rl:",rlcommand # dbg 1479 readline.parse_and_bind(rlcommand) 1480 1481 # Remove some chars from the delimiters list. If we encounter 1482 # unicode chars, discard them. 1483 delims = readline.get_completer_delims().encode("ascii", "ignore") 1484 delims = delims.translate(string._idmap, 1485 self.rc.readline_remove_delims) 1486 readline.set_completer_delims(delims) 1487 # otherwise we end up with a monster history after a while: 1488 readline.set_history_length(1000) 1489 try: 1490 #print '*** Reading readline history' # dbg -> 1491 readline.read_history_file(self.histfile) 1492 except IOError: 1493 pass # It doesn't exist yet. 1494 1495 atexit.register(self.atexit_operations) 1496 del atexit 1497 1498 # Configure auto-indent for all platforms 1499 self.set_autoindent(self.rc.autoindent) 1500 1501 def ask_yes_no(self,prompt,default=True): 1502 if self.rc.quiet: 1503 return True 1504 return ask_yes_no(prompt,default) 1505 1506 def new_main_mod(self,ns=None): C:\Python25\lib\site-packages\pyreadline\rlmain.pyc in read_history_file(self=, filename=u'C:\\Home\\_ipython\\history') 168 169 def set_history_length(self, length): 170 '''Set the number of lines to save in the history file. 171 172 write_history_file() uses this value to truncate the history file 173 when saving. Negative values imply unlimited history file size. 174 ''' 175 self._history.set_history_length(length) 176 177 def clear_history(self): 178 '''Clear readline history''' 179 self._history.clear_history() 180 181 def read_history_file(self, filename=None): 182 '''Load a readline history file. The default filename is ~/.history.''' --> 183 self._history.read_history_file(filename) 184 185 def write_history_file(self, filename=None): 186 '''Save a readline history file. The default filename is ~/.history.''' 187 self._history.write_history_file(filename) 188 189 #Completer functions 190 191 def set_completer(self, function=None): 192 '''Set or remove the completer function. 193 194 If function is specified, it will be used as the new completer 195 function; if omitted or None, any completer function already 196 installed is removed. The completer function is called as 197 function(text, state), for state in 0, 1, 2, ..., until it returns a 198 non-string value. It should return the next possible completion C:\Python25\lib\site-packages\pyreadline\lineeditor\history.pyc in read_history_file(self=, filename=u'C:\\Home\\_ipython\\history') 55 56 history_length=property(get_history_length,set_history_length) 57 history_cursor=property(get_history_cursor,set_history_cursor) 58 59 def clear_history(self): 60 '''Clear readline history.''' 61 self.history[:] = [] 62 self.history_cursor = 0 63 64 def read_history_file(self, filename=None): 65 '''Load a readline history file.''' 66 if filename is None: 67 filename=self.history_filename 68 try: 69 for line in open(filename, 'r'): ---> 70 self.add_history(lineobj.ReadLineTextBuffer(ensure_unicode(line.rstrip()))) global n = undefined global Xd = undefined global S = undefined global NR = undefined global i = undefined global R2 = undefined global R = undefined global t = undefined global history_search_forwardt = undefined global history_search_backwardt = undefined global joinR2 = undefined global maxR = undefined global mint = undefined global IndexError = undefined global RX = undefined global partialt = undefined global hcstartt = undefined global hct = undefined global ht = undefined global result = undefined global s = undefined global C = undefined global Python25 = undefined global lib = undefined global site = undefined global packages = undefined global pyreadline = global lineeditor = undefined global history.pyt = undefined global _search = undefined global I = undefined global c = undefined global d = undefined global Search = undefined global forward = undefined global through = undefined global the = undefined global history = undefined global string = global of = undefined global characters = undefined global between = undefined global start = undefined global current = undefined line = 'import sys\n' global point.This = undefined global a = undefined global non = undefined global incremental = undefined global search.By = undefined global default = undefined global this = undefined global command = undefined global unbound.i = undefined global Rj = undefined global Re = undefined global q = undefined global history.pyR_ = undefined global backward = undefined global Rk = undefined global history.pyR = undefined global N = undefined global propertyR = undefined global R4 = undefined global R5 = undefined global R7 = undefined global R8 = undefined global RC = undefined global RD = undefined global R_ = undefined global s.t = undefined Press enter to exit: global __main__t = undefined global aaaat = undefined global aabat = undefined global aacat = undefined global akcat = undefined global bbbt = undefined global ako = undefined global ret = undefined global operatorRS = undefined global sysR = undefined global pyreadline.unicode_helperR = undefined global modulesR = undefined global exceptionst = undefined global ExceptionR = undefined global pyreadline.loggerR = undefined global FalseR9 = undefined global objectR = undefined global RLR = undefined global history.pys = undefined global module = undefined 71 except IOError: 72 self.history = [] 73 self.history_cursor = 0 74 75 def write_history_file(self, filename=None): 76 '''Save a readline history file.''' 77 if filename is None: 78 filename=self.history_filename 79 fp = open(filename, 'wb') 80 for line in self.history[-self.history_length:]: 81 fp.write(ensure_str(line.get_line_text())) 82 fp.write('\n') 83 fp.close() 84 85 C:\Python25\lib\site-packages\pyreadline\unicode_helper.pyc in ensure_unicode(text='import sys') 5 # Distributed under the terms of the BSD License. The full license is in 6 # the file COPYING, distributed as part of this software. 7 #***************************************************************************** 8 import sys 9 10 try: 11 pyreadline_codepage=sys.stdout.encoding 12 except AttributeError: #This error occurs when pdb imports readline and doctest has replaced 13 #stdout with stdout collector 14 pyreadline_codepage="ascii" #assume ascii codepage 15 16 17 def ensure_unicode(text): 18 """helper to ensure that text passed to WriteConsoleW is unicode""" 19 if isinstance(text, str): ---> 20 return text.decode(pyreadline_codepage, "replace") 21 return text 22 23 def ensure_str(text): 24 """Convert unicode to str using pyreadline_codepage""" 25 if isinstance(text, unicode): 26 return text.encode(pyreadline_codepage, "replace") 27 return text 28 29 30 31 32 33 34 35 TypeError: decode() argument 1 must be string, not None ********************************************************************** Oops, IPython crashed. We do our best to make it stable, but... A crash report was automatically generated with the following information: - A verbatim copy of the crash traceback. - A copy of your input history during this session. - Data on your current IPython configuration. It was left in the file named: 'C:\Home\_ipython\IPython_crash_report.txt' If you can email this file to the developers, the information in it will help them in understanding and correcting the problem. You can mail it to: Fernando Perez at fperez.net at gmail.com with the subject 'IPython Crash Report'. If you want to do it now, the following command will work (under Unix): mail -s 'IPython Crash Report' fperez.net at gmail.com < C:\Home\_ipython \IPython_crash_report.txt To ensure accurate tracking of this issue, please file a report about it at: https://bugs.launchpad.net/ipython/+filebug From usenet-nospam at seebs.net Thu Sep 30 17:24:31 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 21:24:31 GMT Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, RG wrote: > I don't want to quibble over terminology. May I suggest that, if you don't want to use words and terminology precisely, perhaps computer programming is not for you? > Whatever label you choose to > put on it ("false positive", "not being able to express some things > without special extra effort") I consider it a deficiency. Oh, it definitely is a deficiency. However, the deficiency is that you have to do extra work to get data safely in, and you have to figure out for yourself how you want to handle things if, say, you have a value which is not of the right type, and you want to make it be of the right type, but it may not be possible to do so. It is, however, entirely possible to write a function which returns the maximum of its two inputs, 100% reliably, in C. > The costs are greater than the benefits. Reasonable people can > (and obviously do) disagree. I tend to think it depends on what I'm trying to do, and why I'm trying to do it. There are plenty of tasks for which I prefer C's semantics to those of most scripting languages -- and others for which I prefer scripting language semantics. In practice, I have dozens to hundreds of times more problems with scripting languages where something ends up being of the wrong type (or more precisely, not of any of the types which can be used in that context) than I have, say, overflow problems in C. On the other hand, it's usually much easier to catch them and deal with 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 no.email at nospam.invalid Thu Sep 30 17:25:36 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 14:25:36 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> <785d0d80-c4ec-4e02-94ff-fe18dc4a7ddd@e34g2000prn.googlegroups.com> Message-ID: <7xhbh6q5yn.fsf@ruckus.brouhaha.com> TheFlyingDutchman writes: > With Tiny C on my system, your code does not cause maximum to give an > incorrect value, or to blow up: > > int maximum(int a, int b) > { > printf("entering maximum %d %d\n",a,b); > if ( a > b ) > return a; > else > return b; > } What did printf show as "b" when you ran it? If that code worked at all, it was by accident. Try changing the name "maximum" to "minimum" and change the ">" to "<", compile the same program, and see if you still get a correct value. From usenet-nospam at seebs.net Thu Sep 30 17:27:03 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 21:27:03 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> Message-ID: On 2010-09-30, Ian Collins wrote: > Which is why agile practices such as TDD have an edge. If it compiles > *and* passes all its tests, it must be right. So far as I know, that actually just means that the test suite is insufficient. :) Based on my experience thus far, anyway, I am pretty sure it's essentially not what happens that the tests and code are both correct, and it is usually the case either that the tests fail or that there are not enough tests. -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 joel.hedlund at gmail.com Thu Sep 30 17:30:43 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 14:30:43 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> Message-ID: <2b3740e5-b798-4275-b505-b68da470e18b@i5g2000yqe.googlegroups.com> On Sep 30, 3:40?pm, Peter Otten <__pete... at web.de> wrote: > I'm surprised that /usr/lib/python2.4 doesn't appear in the traceback. That certainly would have been useful, wouldn't it? From usenet-nospam at seebs.net Thu Sep 30 17:31:23 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 21:31:23 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, RG wrote: > That gives (what I would consider to be) false positives, e.g.: > [ron at mighty:~]$ cat foo.c > void foo(long x) {} > int main() { foo(1); } > [ron at mighty:~]$ gcc -Wconversion foo.c > foo.c: In function ???main???: > foo.c:4: warning: passing argument 1 of ???foo??? with different width due > to prototype But it's *not* a false positive. The compiler is not claiming that the conversion couldn't be done -- it's just telling you that there is a change of type going on. If you don't want that message, it is certainly possible to write code which won't get it, and which will reliably work everywhere. > So you have to choose your compiler > (and flags) first, and then I get to construct my example. If my > example has *either* an error that the compiler doesn't catch *or* a > non-error that it does catch then I win. Those goal posts are sorta red shifted at this point. You're redefining "error" and "non-error" so as to demand that a statically typed language offer you the same semantics of errors and non-errors that dynamically typed languages have. That's cheating, though. The claim is about C, not about what people who are expecting a dynamically typed language would like C to be like. -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-news at hotmail.com Thu Sep 30 17:44:10 2010 From: ian-news at hotmail.com (Ian Collins) Date: Fri, 01 Oct 2010 10:44:10 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> Message-ID: <8gkelaFc8aU4@mid.individual.net> On 10/ 1/10 10:27 AM, Seebs wrote: > On 2010-09-30, Ian Collins wrote: >> Which is why agile practices such as TDD have an edge. If it compiles >> *and* passes all its tests, it must be right. > > So far as I know, that actually just means that the test suite is > insufficient. :) > > Based on my experience thus far, anyway, I am pretty sure it's essentially > not what happens that the tests and code are both correct, and it is usually > the case either that the tests fail or that there are not enough tests. Which is why we write the tests first. The only code written is written to pass a test. Reviewing tests is a lot easier than reviewing the code while working out what is is supposed to do. -- Ian Collins From vend82 at virgilio.it Thu Sep 30 18:02:30 2010 From: vend82 at virgilio.it (Vend) Date: Thu, 30 Sep 2010 15:02:30 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: On 30 Set, 01:47, RG wrote: > In article , > ?Keith Thompson wrote: > > > > > RG writes: > > > In article > > > <07f75df3-778d-4e3d-8aa0-fbd4bd108... at k22g2000prb.googlegroups.com>, > > > ?Squeamizh wrote: > > >> On Sep 29, 3:02?pm, RG wrote: > > [...] > > >> > This is a red herring. ?You don't have to invoke run-time input to > > >> > demonstrate bugs in a statically typed language that are not caught by > > >> > the compiler. ?For example: > > > >> > [ron at mighty:~]$ cat foo.c > > >> > #include > > > >> > int maximum(int a, int b) { > > >> > ? return (a > b ? a : b); > > > >> > } > > > >> > int foo(int x) { return 9223372036854775807+x; } > > > >> > int main () { > > >> > ? printf("%d\n", maximum(foo(1), 1)); > > >> > ? return 0;} > > > >> > [ron at mighty:~]$ gcc -Wall foo.c > > >> > [ron at mighty:~]$ ./a.out > > >> > 1 > > > >> > Even simple arithmetic is Turing-complete, so catching all type-related > > >> > errors at compile time would entail solving the halting problem. > > > >> > rg > > > >> In short, static typing doesn't solve all conceivable problems. > > > > More specifically, the claim made above: > > > >> in C I can have a function maximum(int a, int b) that will always > > >> work. Never blow up, and never give an invalid answer. > > > > is false. ?And it is not necessary to invoke the vagaries of run-time > > > input to demonstrate that it is false. > > > But the above maximum() function does exactly that. ?The program's > > behavior happens to be undefined or implementation-defined for reasons > > unrelated to the maximum() function. > > > Depending on the range of type int on the given system, either the > > behavior of the addition in foo() is undefined (because it overflows), > > or the implicit conversion of the result to int either yields an > > implementation-defined result or (in C99) raises an > > implementation-defined signal; the latter can lead to undefined > > behavior. > > > Since 9223372036854775807 is 2**63-1, what *typically* happens is that > > the addition yields the value 0, but the C language doesn't require that > > particular result. ?You then call maximum with arguments 0 and 1, and > > it quite correctly returns 1. > > This all hinges on what you consider to be "a function maximum(int a, > int b) that ... always work[s] ... [and] never give[s] an invalid > answer." ?But if you don't consider an incorrect answer (according to > the rules of arithmetic) to be an invalid answer then the claim becomes > vacuous. ?You could simply ignore the arguments and return 0, and that > would meet the criteria. But in your own example the function maximum() does give the correct answer, therefore your point doesn't stand. From vend82 at virgilio.it Thu Sep 30 18:07:20 2010 From: vend82 at virgilio.it (Vend) Date: Thu, 30 Sep 2010 15:07:20 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <40e338f5-eff8-42ca-bbfa-3117c109b918@f25g2000yqc.googlegroups.com> On 30 Set, 03:01, RG wrote: > In article , > ?Keith Thompson wrote: > > > > > RG writes: > > > In article , > > > ?Keith Thompson wrote: > > > >> RG writes: > > >> > In article > > >> > <07f75df3-778d-4e3d-8aa0-fbd4bd108... at k22g2000prb.googlegroups.com>, > > >> > ?Squeamizh wrote: > > >> >> On Sep 29, 3:02?pm, RG wrote: > > >> [...] > > >> >> > This is a red herring. ?You don't have to invoke run-time input to > > >> >> > demonstrate bugs in a statically typed language that are not caught > > >> >> > by > > >> >> > the compiler. ?For example: > > > >> >> > [ron at mighty:~]$ cat foo.c > > >> >> > #include > > > >> >> > int maximum(int a, int b) { > > >> >> > ? return (a > b ? a : b); > > > >> >> > } > > > >> >> > int foo(int x) { return 9223372036854775807+x; } > > > >> >> > int main () { > > >> >> > ? printf("%d\n", maximum(foo(1), 1)); > > >> >> > ? return 0;} > > > >> >> > [ron at mighty:~]$ gcc -Wall foo.c > > >> >> > [ron at mighty:~]$ ./a.out > > >> >> > 1 > > > >> >> > Even simple arithmetic is Turing-complete, so catching all > > >> >> > type-related > > >> >> > errors at compile time would entail solving the halting problem. > > > >> >> > rg > > > >> >> In short, static typing doesn't solve all conceivable problems. > > > >> > More specifically, the claim made above: > > > >> >> in C I can have a function maximum(int a, int b) that will always > > >> >> work. Never blow up, and never give an invalid answer. > > > >> > is false. ?And it is not necessary to invoke the vagaries of run-time > > >> > input to demonstrate that it is false. > > > >> But the above maximum() function does exactly that. ?The program's > > >> behavior happens to be undefined or implementation-defined for reasons > > >> unrelated to the maximum() function. > > > >> Depending on the range of type int on the given system, either the > > >> behavior of the addition in foo() is undefined (because it overflows), > > >> or the implicit conversion of the result to int either yields an > > >> implementation-defined result or (in C99) raises an > > >> implementation-defined signal; the latter can lead to undefined > > >> behavior. > > > >> Since 9223372036854775807 is 2**63-1, what *typically* happens is that > > >> the addition yields the value 0, but the C language doesn't require that > > >> particular result. ?You then call maximum with arguments 0 and 1, and > > >> it quite correctly returns 1. > > > > This all hinges on what you consider to be "a function maximum(int a, > > > int b) that ... always work[s] ... [and] never give[s] an invalid > > > answer." > > > int maximum(int a, int b) { return a > b ? a : b; } > > > > ? ? ? ? ? But if you don't consider an incorrect answer (according to > > > the rules of arithmetic) to be an invalid answer then the claim becomes > > > vacuous. ?You could simply ignore the arguments and return 0, and that > > > would meet the criteria. > > > I don't believe it's possible in any language to write a maximum() > > function that returns a correct result *when given incorrect argument > > values*. > > > The program (assuming a typical implementation) calls maximum() with > > arguments 0 and 1. ?maximum() returns 1. ?It works. ?The problem > > is elsewhere in the program. > > That the problem is "elsewhere in the program" ought to be small > comfort. ?But very well, try this instead: > > [ron at mighty:~]$ cat foo.c > #include > > int maximum(int a, int b) { return a > b ? a : b; } > > int main() { > ? long x = 8589934592; > ? printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > ? return 0;} > > [ron at mighty:~]$ gcc -Wall foo.c > [ron at mighty:~]$ ./a.out > Max of 8589934592 and 1 is 1 So the incorrect behavior happens in a case where C doesn't enforce strict typing rules. From hidura at gmail.com Thu Sep 30 18:16:29 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 30 Sep 2010 22:16:29 +0000 Subject: Problems with wsgi Python3 In-Reply-To: Message-ID: <90e6ba4fc5720cce4a0491816e70@google.com> I still receive nothing, here it's the code of the form maybe there it's the problem: On Sep 30, 2010 4:55pm, "Diez B. Roggisch" wrote: > Thomas Jollans thomas at jollybox.de> writes: > > On Thursday 30 September 2010, it occurred to hidura at gmail.com to > exclaim: > >> What mean this > >> -----------------------------743346150198628700241600224--\r? > > > > it looks like a MIME boundary. In this context most likely from a > > multipart/form-data transmission. > yep, as one can see in the headers below. > Additonally, it looks to me as if the form you are submitting is > empty. The content-length of just 61 matches barely the boundary. > Use something like > pdict = cgi.parse_header(environ["CONTENT_TYPE"])[1] > cgi.parse_multipart(environ["wsgi.input"], pdict) > to properly parse the request. But then of course actually upload > something. > Diez > > > >> > >> On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > >> > Sorry, for the last mail, here it's what you asked: > >> > > >> > {'CONTENT_LENGTH': '61', > >> > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > >> > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > >> > boundary=---------------------------8905735096173894531259794847', > >> > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > >> > [Thu Sep 30 13:35:07 2010] > [error] '/home/hidura/webapps/karinapp/Suite', > >> > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > >> > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > >> > [Thu Sep 30 13:35:07 2010] > >> > [error] > >> > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', > [Thu > >> > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > >> > [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > >> > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > >> > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > >> > [Thu Sep 30 13:35:07 2010] [error] 'close', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > >> > [Thu Sep 30 13:35:07 2010] > >> > [error] 'http://hidura.webfactional.com/?md=btdump', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > >> > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux > x86_64; > >> > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) > Firefox/3.6.10', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > >> > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > >> > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > >> > [Thu Sep 30 13:35:07 2010] [error] '58742', > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > >> > [Thu Sep 30 13:35:07 2010] [error] 'POST', > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > >> > [Thu Sep 30 13:35:07 2010] > >> > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > >> > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > >> > [Thu Sep 30 13:35:07 2010] [error] '80', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > >> > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 > >> > Python/3.1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > >> > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > >> > [Thu Sep 30 13:35:07 2010] [error] 'application', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > >> > [Thu Sep 30 13:35:07 2010] [error] '0', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > >> > [Thu Sep 30 13:35:07 2010] [error] '51543', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > >> > [Thu Sep 30 13:35:07 2010] [error] '1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > >> > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > >> > [Thu Sep 30 13:35:07 2010] [error] , > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > >> > [Thu Sep 30 13:35:07 2010] [error] , > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > >> > [Thu Sep 30 13:35:07 2010] [error] , > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > >> > [Thu Sep 30 13:35:07 2010] [error] False, > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > >> > [Thu Sep 30 13:35:07 2010] [error] True, > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > >> > [Thu Sep 30 13:35:07 2010] [error] False, > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > >> > [Thu Sep 30 13:35:07 2010] [error] 'http', > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > >> > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > >> > > >> > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > >> > > *sigh* > >> > > > >> > > > >> > > > >> > > AGAIN, please do *not* reply to me personally. Reply to the ML or > NG > >> > > >> > you are posting in. I'm beginning to believe that it's a waste of > time to > >> > answer you since you seem not able to follow even the most simple of > >> > advice and rules. > >> > > >> > > And read the answers you get thoroughly, you did not give all the > >> > > >> > information I asked you for. > >> > > >> > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > >> > > > The output is: > >> > > > > >> > > > > >> > > > > >> > > > -----------------------------110550484811701713451664404475--\r > >> > > > > >> > > > > >> > > > > >> > > > No more i don 't know what that means or what do with this. > >> > > > > >> > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: > >> > > > > hidura at gmail.com writes: > >> > > > > > Hello list, i had seriously troubles with the connection > between > >> > > >> > a form and the > >> > > >> > > > > > wsgi, i' ve made an application on Python3 and was running > >> > > >> > perfectly but when i > >> > > >> > > > > > try to use the to pass the data this can't be see on the > server, > >> > > >> > so what > >> > > >> > > > > > is your recommendation?, i am open to all the ideas less > leave to > >> > > >> > Python2 i > >> > > >> > > > > > can't all the project was write on Python3, i was looking > into > >> > > >> > the PEP 444 > >> > > >> > > > > > proposal too. > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > Here is the code what i used to take the data: > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro > >> > > > > > n > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > ['CONTENT_LENGTH'])).decode())) > >> > > > > > >> > > > > What is the ouptut of this? What does > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > import pprint > >> > > > > > >> > > > > > >> > > > > > >> > > > > pprint.pprint(environ) > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > give you? > >> > > > > > >> > > > > > and here it's what the os.environ.item() prints to me: > >> > > > > That's irrelevant. The WSGI-environ is what is needed. > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > Diez > >> > > > > > >> > > > > > >> > > > > > >> > > > > -- > >> > > > > > >> > > > > > >> > > > > > >> > > > > http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Thu Sep 30 20:49:37 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 30 Sep 2010 17:49:37 -0700 (PDT) Subject: namespace hacking question References: Message-ID: <195b129b-4fbb-4091-8ed5-d4b1bef00d2b@e34g2000prn.googlegroups.com> kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(d['spam']) > bar(d['ham']) > baz(d['eggs']) > > This is fine, but I'd like to get rid of the tedium of typing all > those extra d['...']s. Here's an approach that uses a decorator. It requires strings to be passed, so it's not an exact fit for your requirement, but it's very straightforward: d = dict( spam = 1, ham = 2, eggs = 3 ) def argdispatch(func): def _wrapper(*args): args = [d[k] for k in args if k in d] return func(*args) return _wrapper @argdispatch def foo(x): print x @argdispatch def bar(x): print x*2 >>> foo('spam') 1 >>> bar('spam') 2 >>> With a good editor, it should even take care of one of the quotes for you ;) From tekion at gmail.com Thu Sep 30 21:54:00 2010 From: tekion at gmail.com (tekion) Date: Thu, 30 Sep 2010 18:54:00 -0700 (PDT) Subject: Having problem with subclass Message-ID: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> All, I have file name A.py with a class name Aclass. I have a file name B.py with sub class of Aclass, like import A class Bclass(Aclass) ...rest of code When I test it, calling B.py, I am getting: class Bclas(Aclass): NameError: name 'Aclass' is not defined When I move Bclass to A.py, it works. Is there some restriction in python that sub classing a class has be in the same file as the class you're are sub classing? Thanks. From don at geddis.org Thu Sep 30 21:57:27 2010 From: don at geddis.org (Don Geddis) Date: Thu, 30 Sep 2010 18:57:27 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> Message-ID: <87tyl63cag.fsf@mail.geddis.org> Keith Thompson wrote on Thu, 30 Sep 2010: > RG writes: >> You're missing a lot of context. I'm not trying to criticize C, just to >> refute a false claim that was made about it. > Can you cite the article that made this false claim, and exactly what > the false claim was? http://groups.google.com/group/comp.lang.lisp/msg/431925448da59481 Message-ID: <0497e39d-6bd1-429d-a86f-f4c89babe1a4 at u31g2000pru.googlegroups.com> From: TheFlyingDutchman Newsgroups: comp.lang.lisp [...] in C I can have a function maximum(int a, int b) that will always work. Never blow up, and never give an invalid answer. If someone tries to call it incorrectly it is a compile error. [...] _______________________________________________________________________________ Don Geddis http://don.geddis.org/ don at geddis.org From clp2 at rebertia.com Thu Sep 30 22:08:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 30 Sep 2010 19:08:33 -0700 Subject: Having problem with subclass In-Reply-To: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> References: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> Message-ID: On Thu, Sep 30, 2010 at 6:54 PM, tekion wrote: > All, > I have file name A.py with a class name Aclass. I have a file name > B.py with sub class of Aclass, like > import A > class Bclass(Aclass) > ...rest of code > When I test it, calling B.py, I am getting: > > class Bclas(Aclass): > NameError: name 'Aclass' is not defined > > When I move ?Bclass to A.py, it works. ?Is there some restriction in > python that sub classing a class has be in the same file as the class > you're are sub classing? Thanks. "import A" *only* imports the name "A" into B's namespace; names within A.py are not directly imported and can only be referenced using the dot operator on A (i.e. "A.Aclass"). "from A import *" takes all the names defined in A.py and imports them into B's namespace (which is apparently what you expected "import A" to do), but this is frowned upon as it can pollute B's namespace. You should probably either do "from A import Aclass" (i.e. explicitly specifying which names from A you want), or instead refer to Aclass in B.py using "A.Aclass" (i.e. "class Bclass(A.Aclass)"). Cheers, Chris -- http://blog.rebertia.com From brucep at wn.com.au Thu Sep 30 22:09:14 2010 From: brucep at wn.com.au (Bruce Pearson) Date: Fri, 01 Oct 2010 10:09:14 +0800 Subject: Having problem with subclass In-Reply-To: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> References: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> Message-ID: <4CA542CA.8060604@wn.com.au> Try: import A class Bclass(A.Aclass) ...rest of code On 1/10/2010 9:54 AM, tekion wrote: > All, > I have file name A.py with a class name Aclass. I have a file name > B.py with sub class of Aclass, like > import A > class Bclass(Aclass) > ...rest of code > When I test it, calling B.py, I am getting: > > class Bclas(Aclass): > NameError: name 'Aclass' is not defined > > When I move Bclass to A.py, it works. Is there some restriction in > python that sub classing a class has be in the same file as the class > you're are sub classing? Thanks. From gcontsubodh at gmail.com Thu Sep 30 22:12:06 2010 From: gcontsubodh at gmail.com (Geo_subodh) Date: Thu, 30 Sep 2010 19:12:06 -0700 (PDT) Subject: discussion Message-ID: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> please send me the simple python code that uses input number greater than3 digits(>3 digits) and checks whether the number is palindrome or not. From python.list at tim.thechases.com Thu Sep 30 22:14:16 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 30 Sep 2010 21:14:16 -0500 Subject: Having problem with subclass In-Reply-To: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> References: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> Message-ID: <4CA543F8.1060600@tim.thechases.com> On 09/30/10 20:54, tekion wrote: > All, > I have file name A.py with a class name Aclass. I have a file name > B.py with sub class of Aclass, like > import A > class Bclass(Aclass) > ...rest of code > When I test it, calling B.py, I am getting: > > class Bclas(Aclass): > NameError: name 'Aclass' is not defined > > When I move Bclass to A.py, it works. Is there some restriction in > python that sub classing a class has be in the same file as the class > you're are sub classing? This is pretty straight-forward name-spacing. You can use class Bclass(A.Aclass): ... or from A import Aclass class Bclass(Aclass): ... But in your code as it currently stands, the module "A" is the only thing in scope, not "Aclass", so you have to either bring Aclass into scope, or qualify it. -tkc From roy at panix.com Thu Sep 30 22:15:54 2010 From: roy at panix.com (Roy Smith) Date: Thu, 30 Sep 2010 22:15:54 -0400 Subject: discussion References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: In article <31a08825-bb72-4e9f-8710-a39fe2bc9216 at u31g2000pru.googlegroups.com>, Geo_subodh wrote: > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and checks whether the number is palindrome > or not. What class is this for? From usenet-nospam at seebs.net Thu Sep 30 22:28:41 2010 From: usenet-nospam at seebs.net (Seebs) Date: 01 Oct 2010 02:28:41 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: On 2010-10-01, Don Geddis wrote: > in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. If someone > tries to call it incorrectly it is a compile error. I would agree that the third sentence is arguably wrong, simply because there's no such thing (outside #error) of a mandate to stop compiling. However, my understanding was that the dispute was over the second sentence, and that's certainly correct. The obvious simple maximum() in C will not raise an exception nor return something which isn't an int in any program which is not on its face invalid in the call. This is by definite contrast with several of the interpreted languages, where a function or subroutine like that cannot specify that its argument must be some kind of integer. -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 Sep 30 22:30:35 2010 From: nagle at animats.com (John Nagle) Date: Thu, 30 Sep 2010 19:30:35 -0700 Subject: discussion In-Reply-To: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: <4ca547ed$0$1647$742ec2ed@news.sonic.net> On 9/30/2010 7:12 PM, Geo_subodh wrote: > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and checks whether the number is palindrome > or not. def ispalin(s) : s = str(s) n = len(s) / 2 return(s[:n] == s[::-1][:n]) Please use a message subject that describes the content of the message. John Nagle From clp2 at rebertia.com Thu Sep 30 22:30:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 30 Sep 2010 19:30:41 -0700 Subject: discussion In-Reply-To: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: On Thu, Sep 30, 2010 at 7:12 PM, Geo_subodh wrote: > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and ?checks whether the number is palindrome > or not. Do your own homework; it's not like you're even paying us (not that we would have the moral turpitude to be accessories to academic misconduct anyway). If you're having trouble, ask a *specific question* rather than childishly saying "PLZ SEND ME THE CODE!". Cheers, Chris -- Relevant, Entertaining, and Groan-inducing!: http://plzsendmethecode.blogspot.com/ From no.email at nospam.invalid Thu Sep 30 22:49:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 19:49:15 -0700 Subject: discussion References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> <4ca547ed$0$1647$742ec2ed@news.sonic.net> Message-ID: <7xd3rupqz8.fsf@ruckus.brouhaha.com> John Nagle writes: > def ispalin(s) : > s = str(s) > n = len(s) / 2 > return(s[:n] == s[::-1][:n]) def ispalin(s): return (s == "You betcha!") ;-) From hidura at gmail.com Thu Sep 30 23:56:46 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Fri, 01 Oct 2010 03:56:46 +0000 Subject: Problems with wsgi Python3 In-Reply-To: <90e6ba4fc5720cce4a0491816e70@google.com> Message-ID: <90e6ba53b492f430e40491862e7a@google.com> Ppl, thankyou Diez and Thomas for your answers i did it, but it present me a problem with the solution what you give me Thomas this is the code: ValueError: Invalid boundary in multipart form: '' On Sep 30, 2010 6:16pm, hidura at gmail.com wrote: > I still receive nothing, here it's the code of the form maybe there it's > the problem: > On Sep 30, 2010 4:55pm, "Diez B. Roggisch" deets at web.de> wrote: > > Thomas Jollans thomas at jollybox.de> writes: > > > > > > > > > On Thursday 30 September 2010, it occurred to hidura at gmail.com to > exclaim: > > > > >> What mean this > > > > >> -----------------------------743346150198628700241600224--\r? > > > > > > > > > > it looks like a MIME boundary. In this context most likely from a > > > > > multipart/form-data transmission. > > > > > > > > yep, as one can see in the headers below. > > > > > > > > Additonally, it looks to me as if the form you are submitting is > > > > empty. The content-length of just 61 matches barely the boundary. > > > > > > > > Use something like > > > > > > > > pdict = cgi.parse_header(environ["CONTENT_TYPE"])[1] > > > > cgi.parse_multipart(environ["wsgi.input"], pdict) > > > > > > > > to properly parse the request. But then of course actually upload > > > > something. > > > > > > > > Diez > > > > > > > > > > > > > > > > > >> > > > > >> On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > > > > >> > Sorry, for the last mail, here it's what you asked: > > > > >> > > > > > >> > {'CONTENT_LENGTH': '61', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > > > > >> > boundary=---------------------------8905735096173894531259794847', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > > > > >> > [Thu Sep 30 13:35:07 2010] > [error] '/home/hidura/webapps/karinapp/Suite', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > >> > [error] > > > > >> > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', > [Thu > > > > >> > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > > > > >> > [Thu Sep 30 13:35:07 2010] > [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'close', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > >> > [error] 'http://hidura.webfactional.com/?md=btdump', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux > x86_64; > > > > >> > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) > Firefox/3.6.10', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '58742', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'POST', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > >> > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '80', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) > mod_wsgi/3.3 > > > > >> > Python/3.1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com| > /gate.py', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'application', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '0', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '51543', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] False, > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] True, > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] False, > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'http', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > > > > >> > > > > > >> > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > > > > >> > > *sigh* > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > AGAIN, please do *not* reply to me personally. Reply to the ML > or NG > > > > >> > > > > > >> > you are posting in. I'm beginning to believe that it's a waste of > time to > > > > >> > answer you since you seem not able to follow even the most simple > of > > > > >> > advice and rules. > > > > >> > > > > > >> > > And read the answers you get thoroughly, you did not give all the > > > > >> > > > > > >> > information I asked you for. > > > > >> > > > > > >> > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > > > >> > > > The output is: > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > -----------------------------110550484811701713451664404475--\r > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > No more i don 't know what that means or what do with this. > > > > >> > > > > > > > >> > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> > wrote: > > > > >> > > > > hidura at gmail.com writes: > > > > >> > > > > > Hello list, i had seriously troubles with the connection > between > > > > >> > > > > > >> > a form and the > > > > >> > > > > > >> > > > > > wsgi, i' ve made an application on Python3 and was running > > > > >> > > > > > >> > perfectly but when i > > > > >> > > > > > >> > > > > > try to use the to pass the data this can't be see on the > server, > > > > >> > > > > > >> > so what > > > > >> > > > > > >> > > > > > is your recommendation?, i am open to all the ideas less > leave to > > > > >> > > > > > >> > Python2 i > > > > >> > > > > > >> > > > > > can't all the project was write on Python3, i was looking > into > > > > >> > > > > > >> > the PEP 444 > > > > >> > > > > > >> > > > > > proposal too. > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > Here is the code what i used to take the data: > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro > > > > >> > > > > > n > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > ['CONTENT_LENGTH'])).decode())) > > > > >> > > > > > > > > >> > > > > What is the ouptut of this? What does > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > import pprint > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > pprint.pprint(environ) > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > give you? > > > > >> > > > > > > > > >> > > > > > and here it's what the os.environ.item() prints to me: > > > > >> > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > Diez > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > -- > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > http://mail.python.org/mailman/listinfo/python-list > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Sep 1 00:30:33 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 31 Aug 2010 21:30:33 -0700 Subject: Source code for itertools References: <9aa266f0-be9b-4c9a-bfbd-6cdfc86ad2c8@t20g2000yqa.googlegroups.com> <7xmxs3sdt2.fsf@ruckus.brouhaha.com> Message-ID: vsoler wrote: >On 31 ago, 04:42, Paul Rubin wrote: >> vsoler writes: >> > I was expecting an itertools.py file, but I don't see it in your list. >> >> ./python3.1-3.1.2+20100829/Modules/itertoolsmodule.c >> >> looks promising. ?Lots of stdlib modules are written in C for speed or >> access to system facilities. > >Lawrence, Paul, > >You seem to be running a utility I am not familiar with. Perhaps this >is because I am using Windows, and most likely you are not. > >How could I have found the answer in a windows environment? Did you take the time to understand what he did? It's not that hard to figure out. He fetched the Python source code, unpacked it, then search for filenames that contained the string "itertools." The equivalent in Windows, after unpacking the source archive, would have been: dir /s *itertools* -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From contact at xavierho.com Wed Sep 1 01:14:31 2010 From: contact at xavierho.com (Xavier Ho) Date: Wed, 1 Sep 2010 15:14:31 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: On 1 September 2010 12:00, Alban Nona wrote: > @Xavier: ShaDoW, WorldPositionPoint (which is the same thing as > WordPointCloud passe) :) > Aha! That's what I was missing. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From enleverLesX_XXmcX at XmclavXeauX.com.invalid Wed Sep 1 02:23:00 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Wed, 01 Sep 2010 08:23:00 +0200 Subject: Installing Python as Scripting Language in IIS References: <125c518f-d418-4f3f-ae8f-4f0fdcae00df@y12g2000prb.googlegroups.com> Message-ID: <4c7df147$0$10226$ba4acef3@reader.news.orange.fr> Hi! You must register Python as ActiveScripting's language. See : C:\Python26\Lib\site-packages\win32comext\axscript @-salutations -- Michel Claveau From enleverLesX_XXmcX at XmclavXeauX.com.invalid Wed Sep 1 02:24:46 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Wed, 01 Sep 2010 08:24:46 +0200 Subject: Installing Python as Scripting Language in IIS References: <125c518f-d418-4f3f-ae8f-4f0fdcae00df@y12g2000prb.googlegroups.com> Message-ID: <4c7df1b2$0$10212$ba4acef3@reader.news.orange.fr> Re ! More details: C:\Python26\Lib\site-packages\win32comext\axscript\Demos\client\ie\demo.htm @+ -- Michel Claveau From no.email at nospam.invalid Wed Sep 1 02:42:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 31 Aug 2010 23:42:15 -0700 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <878w3ogpvq.fsf@benfinney.id.au> Message-ID: <7xvd6qufqw.fsf@ruckus.brouhaha.com> Terry Reedy writes: > Does anyone seriously think that an implementation should be rejected > as an implementation if it intellegently did seq[n] lookups in > log2(n)/31 time units for all n (as humans would do), instead of > stupidly taking 1 time unit for all n < 2**31 and rejecting all larger > values (as 32-bit CPython does)? Er, how can one handle n > 2**31 at all, in 32-bit CPython? >> Dicts that were not O(1) for access with non-pathological hashing? > > You would actually be unhappy if small dicts ran even faster than they > do now (while large dicts ran the same)? Not me! Not sure what you are referring to by that. I'd actually be ok with using O(log(n)) dicts to eliminate the O(n) behavior of the hash-based implementation on adverse input sets. > Similarly, books say that O(n*logn) sorting is 'better' that O(n**2) > sorting. However, Tim Peters verified that the opposite is true for > real times for small n, and hence the current list.sort smartly uses a > fast O(n**2) algorithm for small lists (len < 64) and small runs in > larger lists. Rejecting list.sort for this reason would be stupid. That algorithm is still O(n log n) since the n**2 behavior up to some constant n is effectively an additive constant that asymptotically is within the specified big-O. 64 actually sounds suspiciously large for the cutover, but I'm sure Tim tuned it carefully. From no.email at nospam.invalid Wed Sep 1 02:48:00 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 31 Aug 2010 23:48:00 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> Message-ID: <7xr5heufhb.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > And yet Java code, for example, doesn?t have a reputation for greater > reliability compared to, say code written in Ada or C++, or even C. What is > the Java runtime written in? C. Why not use Java, if there is no speed > penalty in doing so? The Java runtime (such as the garbage collector) needs untyped pointers and can't be written in Java. It might be possible to write a type-safe GC in something like ATS, which has extremely precise types, but that is almost alien technology by comparison to writing in C. Java has considerably greater reputation for reliability than C or C++. Ada is a different story, but Ada programs (because of the application area Ada is used in) tend not to use a lot of dynamic memory allocation in the first place. A little googling shows there are GC extensions available for Ada, though I don't know if they are used much. From no.email at nospam.invalid Wed Sep 1 02:58:58 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 31 Aug 2010 23:58:58 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> Message-ID: <7xmxs2uez1.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > Whereas garbage collection will happen at some indeterminate time long after > the last access to the object, when it very likely will no longer be in the > cache, and have to be brought back in just to be freed, GC's for large systems generally don't free (or even examine) individual garbage objects. They copy the live objects to a new contiguous heap without ever touching the garbage, and then they release the old heap. That has the effect of improving locality, since the new heap is compacted and has no dead objects. The algorithms are generational (they do frequent gc's on recently-created objects and less frequent ones on older objects), so "minor" gc operations are on regions that fit in cache, while "major" ones might have cache misses but are infrequent. Non-compacting reference counting (or simple mark/sweep gc) has much worse fragmentation and consequently worse cache locality than copying-style gc. From stefan_ml at behnel.de Wed Sep 1 03:06:00 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Sep 2010 09:06:00 +0200 Subject: Optimising literals away In-Reply-To: <4C7D79EE.8010402@mrabarnett.plus.com> References: <69a8fbbc-5f45-491a-adf3-2fb5a4d79660@s9g2000yqd.googlegroups.com> <4C7D79EE.8010402@mrabarnett.plus.com> Message-ID: MRAB, 31.08.2010 23:53: > On 31/08/2010 21:18, Terry Reedy wrote: >> On 8/31/2010 12:33 PM, Aleksey wrote: >>> On Aug 30, 10:38 pm, Tobias Weber wrote: >>>> Hi, >>>> whenever I type an "object literal" I'm unsure what optimisation >>>> will do >>>> to it. >> >> Optimizations are generally implentation dependent. CPython currently >> creates numbers, strings, and tuple literals just once. Mutable literals >> must be created each time as they may be bound and saved. >> >>>> def m(arg): >>>> if arg& set([1,2,3]): >> >> set() is a function call, not a literal. When m is called, who knows >> what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, >> which is much faster as it avoids creating and deleting a list. On my >> machine, .35 versus .88 usec. Even then, it must be calculated each time >> because sets are mutable and could be returned to the calling code. >> > There's still the possibility of some optimisation. If the resulting > set is never stored anywhere (bound to a name, for example) then it > could be created once. When the expression is evaluated there could be > a check so see whether 'set' is bound to the built-in class, and, if it > is, then just use the pre-created set. Cython applies this kind of optimistic optimisation in a couple of other cases and I can affirm that it often makes sense to do that. However, drawback here: the set takes up space while not being used (not a huge problem if literals are expected to be small), and the global lookup of "set" still has to be done to determine if it *is* the builtin set type. After that, however, the savings should be considerable. Another possibility: always cache the set and create a copy on access. Copying a set avoids the entire eval loop overhead and runs in a C loop instead, using cached item instances with (most likely) cached hash values. So even that will most likely be much faster than the spelled-out code above. Stefan From no.email at nospam.invalid Wed Sep 1 03:14:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 01 Sep 2010 00:14:32 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <4c78e7a5$0$28655$c3e8da3@news.astraweb.com> <4c7a2c3b$0$22941$e4fe514c@news.xs4all.nl> <7xhbidndc6.fsf@ruckus.brouhaha.com> <8e15pqFn89U1@mid.individual.net> <7xmxs4uzjl.fsf@ruckus.brouhaha.com> Message-ID: <7xiq2que93.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: >> Refcounting is susceptable to the same pauses for reasons already >> discussed. > > Doesn?t seem to happen in the real world, though. def f(n): from time import time a = [1] * n t0 = time() del a t1 = time() return t1 - t0 for i in range(9): print i, f(10**i) on my system prints: 0 2.86102294922e-06 1 2.14576721191e-06 2 3.09944152832e-06 3 1.00135803223e-05 4 0.000104904174805 5 0.00098991394043 6 0.00413608551025 7 0.037693977356 8 0.362598896027 Looks pretty linear as n gets large. 0.36 seconds (the last line) is a noticable pause. From nkaunda at yahoo.com Wed Sep 1 03:29:05 2010 From: nkaunda at yahoo.com (Nally Kaunda-Bukenya) Date: Wed, 1 Sep 2010 00:29:05 -0700 (PDT) Subject: Newby Needs Help with Python code Message-ID: <861505.20099.qm@web33506.mail.mud.yahoo.com> ? Dear Python experts, I hope someone can help me. I am new to Python and trying to achive the following: 1)????? I would like to populate the Tot_Ouf_Area field with total area of each unique outfall_id (code attempted below,but Tot_Ouf_Area not populating) 2)????? I would also like to get the user input of Rv ( each landuse type will have a specific Rv value). For example the program should ask the user for Rv value of Low Density Residential (user enters 0.4 in example below and that value must be stored in the Rv field), and so on as shown in the 2nd table below? Below is my original table (comma-delimited) "OBJECTID","OUTFALL_ID","LANDUSE","AREA_ACRES","Rv","Tot_Outf_Area" 16,"ALD06001","High Density Residential",6.860922,0.000000,0.000000 15,"ALD06001","General Commercial",7.520816,0.000000,0.000000 14,"ALD05002","Low Density Residential",7.255491,0.000000,0.000000 13,"ALD05002","Forest",37.090473,0.000000,0.000000 12,"ALD05001","Low Density Residential",16.904560,0.000000,0.000000 11,"ALD05001","Forest",84.971686,0.000000,0.000000 10,"ALD04002","Urban Open",1.478677,0.000000,0.000000 9,"ALD04002","Transportation",0.491887,0.000000,0.000000 8,"ALD04002","Low Density Residential",25.259720,0.000000,0.000000 7,"ALD04002","Forest",0.355659,0.000000,0.000000 6,"ALD04001","Recreational",0.013240,0.000000,0.000000 5,"ALD04001","Low Density Residential",34.440130,0.000000,0.000000 4,"ALD04001","Forest",10.229973,0.000000,0.000000 3,"ALD03002","Low Density Residential",23.191538,0.000000,0.000000 2,"ALD03002","Forest",1.853920,0.000000,0.000000 1,"ALD03001","Low Density Residential",6.828130,0.000000,0.000000 21,"ALD06001","Water.dgn",0.013951,0.000000,0.000000 20,"ALD06001","Urban Open",10.382900,0.000000,0.000000 19,"ALD06001","Transportation",2.064454,0.000000,0.000000 18,"ALD06001","Recreational",0.011007,0.000000,0.000000 17,"ALD06001","Low Density Residential",0.752509,0.000000,0.000000 ? Below is my desired output table (comma delimited): "OBJECTID","OUTFALL_ID","LANDUSE","AREA_ACRES","Rv","Tot_Outf_Area" 16,"ALD06001","High Density Residential",6.860922,0.000000,27.606562 15,"ALD06001","General Commercial",7.520816,0.000000,27.606562 14,"ALD05002","Low Density Residential",7.255491,0.400000,44.345966 13,"ALD05002","Forest",37.090473,0.300000,44.345966 11,"ALD05001","Forest",84.971686,0.300000,101.876247 12,"ALD05001","Low Density Residential",16.904560,0.400000,101.876247 10,"ALD04002","Urban Open",1.478677,0.000000,27.585945 9,"ALD04002","Transportation",0.491887,0.000000,27.585945 8,"ALD04002","Low Density Residential",25.259720,0.400000,27.585945 7,"ALD04002","Forest",0.355659,0.300000,27.585945 6,"ALD04001","Recreational",0.013240,0.000000,44.683345 5,"ALD04001","Low Density Residential",34.440130,0.400000,44.683345 4,"ALD04001","Forest",10.229973,0.300000,44.683345 3,"ALD03002","Low Density Residential",23.191538,0.400000,25.045460 2,"ALD03002","Forest",1.853920,0.300000,25.045460 1,"ALD03001","Low Density Residential",6.828130,0.400000,6.828130 21,"ALD06001","Water.dgn",0.013951,0.000000,27.606562 20,"ALD06001","Urban Open",10.382900,0.000000,27.606562 19,"ALD06001","Transportation",2.064454,0.000000,27.606562 18,"ALD06001","Recreational",0.011007,0.000000,27.606562 17,"ALD06001","Low Density Residential",0.752509,0.400000,27.606562 Below is my code so far for updating rows with total area (Tot_Ouf_Area): ? #THE PROGRAM: import arcgisscripting gp=arcgisscripting.create() gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb" fc = "Outfalls_ND" try: ??? # Set the field to create a list of unique values??? ??????? fieldname = "OUTFALL_ID" ??????? ??? # Open a Search Cursor to identify all unique values ??????? cur = gp.UpdateCursor(fc) ??????? row = cur.Next() ??????? # Set a list variable to hold all unique values ??????? L = [] ??????? # Using a while loop, cursor through all records and append unique ??????? #values to the list variable ??????? while row <> None: ??????????? value = row.GetValue(fieldname) ??????????? if value not in L: ??????????????? L.append(value) ??????????? row = cur.Next() ??????????? row.SetValue(Tot_Outf_Area, sum(row.AREA_ACRES)) #total area of each outfall=sum of all area 4 each unique outfallid ??????????? cur.UpdateRow(row) #to commit changes ??????????? row=cur.Next() ??????????? print row.Tot_Outf_Area ??????? # Sort the list variable ??????? L.sort() ??????? # If a value in the list variable is blank, remove it from the list variable ??????? #to filter out diffuse outfalls ??????? if ' ' in L: ??????????? L.remove(' ') except: ??? # If an error occurred while running a tool, print the messages ??? print gp.GetMessages() ? #Please Help!!! #Esther -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at merton.oxon.org Wed Sep 1 07:28:37 2010 From: rami.chowdhury at merton.oxon.org (Rami Chowdhury) Date: Wed, 1 Sep 2010 17:28:37 +0600 Subject: Newby Needs Help with Python code In-Reply-To: <861505.20099.qm@web33506.mail.mud.yahoo.com> References: <861505.20099.qm@web33506.mail.mud.yahoo.com> Message-ID: Hi Esther, On Wed, Sep 1, 2010 at 13:29, Nally Kaunda-Bukenya wrote: > #THE PROGRAM: > import arcgisscripting > gp=arcgisscripting.create() > gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb" > fc = "Outfalls_ND" > > try: > ??? # Set the field to create a list of unique values > ??????? fieldname = "OUTFALL_ID" > > ??? # Open a Search Cursor to identify all unique values > ??????? cur = gp.UpdateCursor(fc) > ??????? row = cur.Next() > > ??????? # Set a list variable to hold all unique values > ??????? L = [] > > ??????? # Using a while loop, cursor through all records and append unique > ??????? #values to the list variable > ??????? while row <> None: > ??????????? value = row.GetValue(fieldname) > ??????????? if value not in L: > ??????????????? L.append(value) > ??????????? row = cur.Next() > ??????????? row.SetValue(Tot_Outf_Area, sum(row.AREA_ACRES)) #total area of > each outfall=sum of all area 4 each unique outfallid > ??????????? cur.UpdateRow(row) #to commit changes > ??????????? row=cur.Next() > ??????????? print row.Tot_Outf_Area > ??????? # Sort the list variable > ??????? L.sort() > > ??????? # If a value in the list variable is blank, remove it from the list > variable > ??????? #to filter out diffuse outfalls > ??????? if ' ' in L: > ??????????? L.remove(' ') > > except: > ??? # If an error occurred while running a tool, print the messages > ??? print gp.GetMessages() Have you tried running this code? I suspect it won't work at all -- and because you are catching all possible exceptions in your try...except, you won't even know why. Here are the things that I'd suggest, just from glancing over the code: - Remove the try...except for now. Getting an exception, and understanding why it occurred and how best to deal with it, is IMHO very helpful when prototyping and debugging. - Take another look at your while loop. I don't know ArcGIS, so I don't know if the UpdateCursor object supports the iterator protocol, but the normal Python way of looping through all rows would be a for loop: for row in cur: # code For example, you are calling cur.Next() twice inside the loop -- is that what you want? Hope that helps, Rami > > > > #Please Help!!! > > #Esther > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From luke.leighton at gmail.com Wed Sep 1 08:36:26 2010 From: luke.leighton at gmail.com (lkcl) Date: Wed, 1 Sep 2010 05:36:26 -0700 (PDT) Subject: fairly urgent request: paid python (or other) work required Message-ID: i apologise for having to contact so many people but this is fairly urgent, and i'm running out of time and options. i'm a free software programmer, and i need some paid work - preferably python - fairly urgently, so that i can pay for food and keep paying rent, and so that my family doesn't get deported or have to leave the country. i really would not be doing this unless it was absolutely, absolutely essential that i get money. so that both i and the list are not unnecessarily spammed, please don't reply with recommendations of "where to get jobs", unless they are guaranteed to result in immediate work and money. if you have need of a highly skilled and experienced python-preferring free-software-preferring software engineer, please simply contact me, and tell me what you need doing: there's no need for you to read the rest of this message. so that people are not offended by me asking on such a high-volume list for work, here are some questions and answers: Q: who are you? A: luke leighton. free sofware developer, free software project leader, and "unusual cross-project mash-up-er" (meaning: i spot the value of joining one or more bits of disparate "stuff" to make something that's more powerful than its components). Q: where's your CV? A: executive version of CV is at http://lkcl.net/exec_cv.txt - please don't ask for a proprietary microsoft word version, as a refusal and referral to the "sylvester response" often offends. Q: what can you do? A: python programming, c programming, web development, networking, cryptography, reverse-engineering, IT security, etc. etc. preferably involving free software. Q: what do you need? A: money to pay rent and food. at the ABSOLUTE MINIMUM, i need as little as ?1500 per month to pay everything, and have been earning approx ?800 per month for the past year. a ?5000 inheritance last year which i was not expecting has delayed eviction and bankruptcy for me and my family, and deportation for my partner and 17 month old daughter (marie is here in the UK on a FLR/M visa) Q: why are you asking here? A: because it's urgent that i get money really really soon; my family members are refusing to assist, and the few friends that i have do not have any spare money to lend. Q: why here and not "monster jobs" or "python-jobs list" or the various "recruitment agencies"? A: those are full-time employment positions, which i have been frequently applying for and get rejected for various reasons, and i'm running out of time and money. further interviews cost money, and do not result in guaranteed work. i need work - and money - _now_. Q: why here and not "peopleperhour.com"? A: if you've ever bid on peopleperhour.com you will know that you are bidding against "offshore" contrators and even being undercut by 1st world country bidders who, insanely, appear to be happy to do work for as little as ?2 / hour. Q: why are you getting rejected from interviews? A: that's complex. a) i simply don't interview well. people with the classic symptoms of asperger's just don't. b) my daughter is 17 months old. when i go away for as little as 3 days, which i've done three times now, she is extremely upset both when i am away and when i return. i think what would happen if i was doing some sort of full- time job, away from home, and... i can't do it. subconsciously that affects how i react when speaking to interviewers. Q: why do you not go "get a job at tesco's" or "drive a truck"? A: tescos and HGV driving etc. pay around ?12 per hour. ?12 per hour after tax comes down to about ?8 to ?9 per hour. ?9 per hour requires 35 hours per week to earn as little as ?1500. 35 hours per week is effectively full-time, and means that a) my programming and software engineering skills are utterly, utterly wasted b) my daughter gets extremely upset because i won't be at home. so you get the gist, and thank you for putting up with me needing to take this action. l. From see.my.homepage at gmail.com Wed Sep 1 08:37:10 2010 From: see.my.homepage at gmail.com (Maciej Sobczak) Date: Wed, 1 Sep 2010 05:37:10 -0700 (PDT) Subject: YAMI4 v. 1.1.0 - messaging solution for distributed systems Message-ID: I am pleased to announce that the new version of YAMI4, 1.1.0, has been just released and is available for download. http://www.inspirel.com/yami4/ This new version extends the coverage of supported programming languages with a completely new Python3 module, which allows full integration of built-in dictionary objects as message payloads. Thanks to this level of language integration, the API is very easy to learn and natural in use. Please check code examples in the src/python/examples directory to see complete client-server systems. The users of other programming languages will also benefit from the ability to transmit raw binary messages, which in addition to support high-performance scenarios can be used as a hook for custom serialization routines. The API of the whole library was also extended a bit to allow better control of automatic reconnection and to ensure low jitter in communication involving many receivers even in case of partial system failure. Last but not least, a number of fixes and improvements have been introduced - please see the changelog.txt file, which is part of the whole package, for a detailed description of all improvements. -- Maciej Sobczak * http://www.inspirel.com From victorsubervi at gmail.com Wed Sep 1 09:00:03 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 1 Sep 2010 09:00:03 -0400 Subject: Reversing a List Message-ID: Hi; I have this code: cursor.execute('describe products;') cols = [item[0] for item in cursor] cols = cols.reverse() cols.append('Delete') cols = cols.reverse() Unfortunately, the list doesn't reverse. If I print cols after the first reverse(), it prints None. Please advise. Also, is there a way to append to the front of the list directly? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From bussiere at gmail.com Wed Sep 1 09:02:51 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Wed, 1 Sep 2010 15:02:51 +0200 Subject: [Pickle]dirty problem 3 lines In-Reply-To: <4C7DC74D.6060702@mrabarnett.plus.com> References: <4C7DC74D.6060702@mrabarnett.plus.com> Message-ID: it's just as it seems : i want to know how does ti works to get back an object from a string in python : pickle.loads("""b'\x80\x03]q\x00(K\x00K\x01e.'""") #doesn't work Google Fan boy On Wed, Sep 1, 2010 at 5:23 AM, MRAB wrote: > On 01/09/2010 03:33, bussiere bussiere wrote: >> >> i know it's dirty, i know i should use json but i want to know, it's >> quiet late here : >> import pickle >> dump = """b'\x80\x03]q\x00(K\x00K\x01e.'""" >> print(pickle.loads(dump)) >> >> how can i get back my object from this string ? >> the string is : ?b'\x80\x03]q\x00(K\x00K\x01e.' >> and i'am using python3 >> help will be appreciated i'am chewing on this for a long time now. > > Well, pickle.loads(b'\x80\x03]q\x00(K\x00K\x01e.') works. > > That, of course, is not the same as """b'\x80\x03]q\x00(K\x00K\x01e.'""". > > Do you mean r"""b'\x80\x03]q\x00(K\x00K\x01e.'"""? > > (It's also late here, well, actually, so late it's early... Time to > sleep. :-)) > -- > http://mail.python.org/mailman/listinfo/python-list > From matt at scotweb.co.uk Wed Sep 1 09:15:54 2010 From: matt at scotweb.co.uk (Matt Saxton) Date: Wed, 1 Sep 2010 14:15:54 +0100 Subject: Reversing a List In-Reply-To: References: Message-ID: <20100901141554.a8d606f0.matt@scotweb.co.uk> On Wed, 1 Sep 2010 09:00:03 -0400 Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('describe products;') > cols = [item[0] for item in cursor] > cols = cols.reverse() > cols.append('Delete') > cols = cols.reverse() > > Unfortunately, the list doesn't reverse. If I print cols after the first > reverse(), it prints None. Please advise. The reverse() method modifies the list in place, but returns None, so just use >>> cols.reverse() rather than >>> cols = cols.reverse() > Also, is there a way to append to > the front of the list directly? > TIA, > beno The insert() method can do this, i.e. >>> cols.insert(0, 'Delete') -- Matt Saxton From shashank.sunny.singh at gmail.com Wed Sep 1 09:17:34 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Wed, 1 Sep 2010 18:47:34 +0530 Subject: Reversing a List In-Reply-To: References: Message-ID: reverse reverses in-place >>> l = [1, 2, 3] >>> r = l.reverse() >>> r is None True >>> l [3, 2, 1] >>> On Wed, Sep 1, 2010 at 6:30 PM, Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('describe products;') > cols = [item[0] for item in cursor] > cols = cols.reverse() > cols.append('Delete') > cols = cols.reverse() > > Unfortunately, the list doesn't reverse. If I print cols after the first > reverse(), it prints None. Please advise. Also, is there a way to append to > the front of the list directly? > TIA, > beno > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Sep 1 09:21:17 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 1 Sep 2010 09:21:17 -0400 Subject: Reversing a List In-Reply-To: References: Message-ID: On Wed, Sep 1, 2010 at 9:17 AM, Shashank Singh < shashank.sunny.singh at gmail.com> wrote: > reverse reverses in-place > > >>> l = [1, 2, 3] > >>> r = l.reverse() > >>> r is None > True > >>> l > [3, 2, 1] > >>> > Ah. Thanks! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert at spenarnc.xs4all.nl Wed Sep 1 09:22:52 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 Sep 2010 13:22:52 GMT Subject: Fibonacci: How to think recursively References: <890665ce-4df5-4a6d-b18b-9170d743bd55@a36g2000yqc.googlegroups.com> Message-ID: In article , Mel wrote: >Baba wrote: > >> Level: beginner >> >> I would like to know how to approach the following Fibonacci problem: >> How may rabbits do i have after n months? >> >> I'm not looking for the code as i could Google that very easily. I'm >> looking for a hint to put me on the right track to solve this myself >> without looking it up. >> >> my brainstorming so far brought me to a stand still as i can't seem to >> imagine a recursive way to code this: >> >> my attempted rough code: >> >> def fibonacci(n): >> # base case: >> result = fibonacci (n-1) + fibonacci (n-2) >>>> this will end up in a mess as it will create overlapping recursions > >I don't think this is the base case. The base case would be one or more >values of `n` that you already know the fibonacci number for. Your >recursive function can just test for those and return the right answer right >away. The the expression you've coded contains a good way to handle the >non-base cases. There's no such problem as "overlapping recursions". [Didn't you mean: I don't understand what you mean by overlapping recursions? You're right about the base case, so clearly the OP uses some confusing terminology.] I see a problem with overlapping recursions. Unless automatic memoizing is one, they are unduely inefficient, as each call splits into two calls. If one insists on recursion (untested code, just for the idea.). def fib2( n ): ' return #rabbits last year, #rabbits before last ' if n ==1 : return (1,1) else penult, ult = fib2( n-1 ) return ( ult, ult+penult) def fub( n ): return fib2(n)[1] Try fib and fub for largish numbers (>1000) and you'll feel the problem. > > Mel. > Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From lie.1296 at gmail.com Wed Sep 1 09:25:13 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 01 Sep 2010 23:25:13 +1000 Subject: Optimising literals away In-Reply-To: References: <69a8fbbc-5f45-491a-adf3-2fb5a4d79660@s9g2000yqd.googlegroups.com> <4C7D79EE.8010402@mrabarnett.plus.com> Message-ID: <4c7e3ef6$1@dnews.tpgi.com.au> On 09/01/10 17:06, Stefan Behnel wrote: > MRAB, 31.08.2010 23:53: >> On 31/08/2010 21:18, Terry Reedy wrote: >>> On 8/31/2010 12:33 PM, Aleksey wrote: >>>> On Aug 30, 10:38 pm, Tobias Weber wrote: >>>>> Hi, >>>>> whenever I type an "object literal" I'm unsure what optimisation >>>>> will do >>>>> to it. >>> >>> Optimizations are generally implentation dependent. CPython currently >>> creates numbers, strings, and tuple literals just once. Mutable literals >>> must be created each time as they may be bound and saved. >>> >>>>> def m(arg): >>>>> if arg& set([1,2,3]): >>> >>> set() is a function call, not a literal. When m is called, who knows >>> what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, >>> which is much faster as it avoids creating and deleting a list. On my >>> machine, .35 versus .88 usec. Even then, it must be calculated each time >>> because sets are mutable and could be returned to the calling code. >>> >> There's still the possibility of some optimisation. If the resulting >> set is never stored anywhere (bound to a name, for example) then it >> could be created once. When the expression is evaluated there could be >> a check so see whether 'set' is bound to the built-in class, and, if it >> is, then just use the pre-created set. What if the set is mutated by the function? That will modify the global cache of the set; one way to prevent mutation is to use frozenset, but from the back of my mind, I think there was a discussion that rejects set literals producing a frozen set instead of regular set. > Cython applies this kind of optimistic optimisation in a couple of other > cases and I can affirm that it often makes sense to do that. However, > drawback here: the set takes up space while not being used (not a huge > problem if literals are expected to be small), and the global lookup of > "set" still has to be done to determine if it *is* the builtin set type. > After that, however, the savings should be considerable. > > Another possibility: always cache the set and create a copy on access. > Copying a set avoids the entire eval loop overhead and runs in a C loop > instead, using cached item instances with (most likely) cached hash > values. So even that will most likely be much faster than the > spelled-out code above. I think that these kind of optimizations would probably be out-of-character for CPython, which values implementation simplicity above small increase in speed. Sets are not that much used and optimizing this particular case seems to be prone to create many subtle issues (especially with multithreading). In other word, these optimizations makes sense for Python implementations that are heavily geared for speed (e.g. Unladen Swallow, Stackless Python, PyPy[1], Cython); but probably may only have a minuscule chance of being implemented in CPython. [1] yes, their goal was to be faster than CPython (and faster than the speed of photon in vacuum), though AFAICT they have yet to succeed. From anand.shashwat at gmail.com Wed Sep 1 09:26:36 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 1 Sep 2010 18:56:36 +0530 Subject: Reversing a List In-Reply-To: <20100901141554.a8d606f0.matt@scotweb.co.uk> References: <20100901141554.a8d606f0.matt@scotweb.co.uk> Message-ID: On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton wrote: > On Wed, 1 Sep 2010 09:00:03 -0400 > Victor Subervi wrote: > > > Hi; > > I have this code: > > > > cursor.execute('describe products;') > > cols = [item[0] for item in cursor] > > cols = cols.reverse() > > cols.append('Delete') > > cols = cols.reverse() > > > > Unfortunately, the list doesn't reverse. If I print cols after the first > > reverse(), it prints None. Please advise. > > The reverse() method modifies the list in place, but returns None, so just > use > >>> cols.reverse() > > rather than > >>> cols = cols.reverse() > Alternatively you can do \, >>>cols = reversed(cols) > > > Also, is there a way to append to > > the front of the list directly? > > TIA, > > beno > > The insert() method can do this, i.e. > >>> cols.insert(0, 'Delete') > > -- > Matt Saxton > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Sep 1 09:30:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Sep 2010 15:30:21 +0200 Subject: Performance: sets vs dicts. In-Reply-To: <4c7e43ef$1@dnews.tpgi.com.au> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <878w3ogpvq.fsf@benfinney.id.au> <4c7e43ef$1@dnews.tpgi.com.au> Message-ID: Lie Ryan, 01.09.2010 15:46: > On 09/01/10 00:09, Aahz wrote: >> However, I think there are some rock-bottom basic guarantees we can make >> regardless of implementation. Does anyone seriously think that an >> implementation would be accepted that had anything other than O(1) for >> index access into tuples and lists? Dicts that were not O(1) for access >> with non-pathological hashing? That we would accept sets having O() >> performance worse than dicts? >> >> I suggest that we should agree on these guarantees and document them in >> the core. > > While I think documenting them would be great for all programmers that > care about practical and theoretical execution speed; I think including > these implementation details in core documentation as a "guarantee" > would be a bad idea for the reasons Terry outlined. > > One way of resolving that is by having two documentations (or two > separate sections in the documentation) for: > - Python -- the language -- documenting Python as an abstract language, > this is the documentation which can be shared across all Python > implementations. This will also be the specification for Python Language > which other implementations will be measured to. > - CPython -- the Python interpreter -- documents implementation details > and performance metrics. It should be properly noted that these are not > part of the language per se. This will be the playground for CPython > experts that need to fine tune their applications to the last drop of > blood and don't mind their application going nuts with the next release > of CPython. I disagree. I think putting the "obvious" guarantees right into the normal documentation will actually make programmers aware that there *are* different implementations (and differences between implementations), simply because it wouldn't just say "O(1)" but "the CPython implementation of this method has an algorithmic complexity of O(1), other Python implementations are known to perform alike at the time of this writing". Maybe without the last half of the sentence if we really don't know how other implementations work here, or if we expect that there may well be a reason they may choose to behave different, but in most cases, it shouldn't be hard to make that complete statement. After all, we basically know what other implementations there are, and we also know that they tend to match the algorithmic complexities at least for the major builtin types. It seems quite clear to me as a developer that the set of builtin types and "collections" types was chosen in order to cover a certain set of algorithmic complexities and not just arbitrary interfaces. Stefan From davea at ieee.org Wed Sep 1 09:35:53 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 01 Sep 2010 09:35:53 -0400 Subject: Reversing a List In-Reply-To: References: Message-ID: <4C7E56B9.6070408@ieee.org> Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('describe products;') > cols = [item[0] for item in cursor] > cols = cols.reverse() > cols.append('Delete') > cols = cols.reverse() > > Unfortunately, the list doesn't reverse. If I print cols after the first > reverse(), it prints None. Please advise. Also, is there a way to append to > the front of the list directly? > TIA, > beno > > The reverse() method reverses that cols object just fine, in place. Unfortunately, you immediately assign it a new value of None. Just remove the cols= and it'll work fine. If you want to understand the problem better, read up on reverse() and reversed(). They're very different. In answer to your second question, you could combine the last three lines as: cols.insert('Delete', 0) DaveA From cutebhavanaa at gmail.com Wed Sep 1 09:41:09 2010 From: cutebhavanaa at gmail.com (sexy girl) Date: Wed, 1 Sep 2010 06:41:09 -0700 (PDT) Subject: ***SEX IN COLLEGE HOT AND SEXY VIDEOS*** Message-ID: <5d5f018b-1da1-40c8-9d9b-e0848c53b85d@y32g2000prc.googlegroups.com> http://cute-actress-images.blogspot.com/ http://cute-sexy-images.blogspot.com/ http://actress.0jet.com http://factson-globalwarming.blogspot.com/ http://mysteries-that-threats.blogspot.com/ http://healthtips.06fr.com http://actress.0jet.com http://dailyscience.youblog.net http://jobs4all.menblogs.net http://healthtips.06fr.com http://dailyscience.youblog.net http://jobs4all.menblogs.net http://schoolsuniversities.web-day.net http://cute-actress-images.blogspot.com/ http://science-vs-technology.blogspot.com/ http://my-jobs-4-u.blogspot.com/ http://cute-sexy-images.blogspot.com/ From lie.1296 at gmail.com Wed Sep 1 09:46:26 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 01 Sep 2010 23:46:26 +1000 Subject: Performance: sets vs dicts. In-Reply-To: References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <878w3ogpvq.fsf@benfinney.id.au> Message-ID: <4c7e43ef$1@dnews.tpgi.com.au> On 09/01/10 00:09, Aahz wrote: > In article , > Jerry Hill wrote: >> On Mon, Aug 30, 2010 at 7:42 PM, Aahz wrote: >>> >>> Possibly; IMO, people should not need to run timeit to determine basic >>> algorithmic speed for standard Python datatypes. >> >> http://wiki.python.org/moin/TimeComplexity takes a stab at it. IIRC, >> last time this came up, there was some resistance to making promises >> about time complexity in the official docs, since that would make >> those numbers part of the language, and thus binding on other >> implementations. > > I'm thoroughly aware of that page and updated it yesterday to make it > easier to find. ;-) > > However, I think there are some rock-bottom basic guarantees we can make > regardless of implementation. Does anyone seriously think that an > implementation would be accepted that had anything other than O(1) for > index access into tuples and lists? Dicts that were not O(1) for access > with non-pathological hashing? That we would accept sets having O() > performance worse than dicts? > > I suggest that we should agree on these guarantees and document them in > the core. While I think documenting them would be great for all programmers that care about practical and theoretical execution speed; I think including these implementation details in core documentation as a "guarantee" would be a bad idea for the reasons Terry outlined. One way of resolving that is by having two documentations (or two separate sections in the documentation) for: - Python -- the language -- documenting Python as an abstract language, this is the documentation which can be shared across all Python implementations. This will also be the specification for Python Language which other implementations will be measured to. - CPython -- the Python interpreter -- documents implementation details and performance metrics. It should be properly noted that these are not part of the language per se. This will be the playground for CPython experts that need to fine tune their applications to the last drop of blood and don't mind their application going nuts with the next release of CPython. From albert at spenarnc.xs4all.nl Wed Sep 1 09:46:32 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 Sep 2010 13:46:32 GMT Subject: Saving (unusual) linux filenames References: Message-ID: In article , Grant Edwards wrote: >On 2010-08-31, MRAB wrote: >> On 31/08/2010 17:58, Grant Edwards wrote: >>> On 2010-08-31, MRAB wrote: >>>> On 31/08/2010 15:49, AmFreak at web.de wrote: >>>>> Hi, >>>>> >>>>> i have a script that reads and writes linux paths in a file. I save the >>>>> path (as unicode) with 2 other variables. I save them seperated by "," >>>>> and the "packets" by newlines. So my file looks like this: >>>>> path1, var1A, var1B >>>>> path2, var2A, var2B >>>>> path3, var3A, var3B >>>>> .... >>>>> >>>>> this works for "normal" paths but as soon as i have a path that does >>>>> include a "," it breaks. The problem now is that (afaik) linux allows >>>>> every char (aside from "/" and null) to be used in filenames. The only >>>>> solution i can think of is using null as a seperator, but there have to >>>>> a cleaner version ? >>>> >>>> You could use a tab character '\t' instead. >>> >>> That just breaks with a different set of filenames. >>> >> How many filenames contain control characters? > >How many filenames contain ","? Not many, but the OP wants his >program to be bulletproof. Can't fault him for that. As appending ",v" is the convention for rcs / cvs archives, I would say: a lot. Enough to guarantee that all my backup tar's contain at least a few. > >If I had a nickle for every Unix program or shell-script that failed >when a filename had a space it it.... I'd rather have it fail for spaces than for comma's. > >> Surely that's a bad idea. > >Of course it's a bad idea. That doesn't stop people from doing it. > >-- >Grant Edwards grant.b.edwards Yow! ! Now I understand > at advanced MICROBIOLOGY and > gmail.com th' new TAX REFORM laws!! -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From ben+python at benfinney.id.au Wed Sep 1 10:10:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 02 Sep 2010 00:10:27 +1000 Subject: fairly urgent request: paid python (or other) work required References: Message-ID: <87r5hdftbg.fsf@benfinney.id.au> lkcl writes: > i apologise for having to contact so many people but this is fairly > urgent, and i'm running out of time and options. [?] I sympathise with your situation; work for skilled practicioners is scarce in many places right now. For that reason, many people are likely to be in your position. For the sake of keeping this forum habitable, I have to point out to anyone reading: It's not cool to post requests for work here. There are, as you noted, other appropriate forums for that, of which this is not one. I wish you success in finding gainful work, but all readers should please note that this is *not* the place to look for it. -- \ ?Sittin' on the fence, that's a dangerous course / You can even | `\ catch a bullet from the peace-keeping force? ?Dire Straits, | _o__) _Once Upon A Time In The West_ | Ben Finney From neilc at norwich.edu Wed Sep 1 10:19:07 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 1 Sep 2010 14:19:07 GMT Subject: Fibonacci: How to think recursively References: <890665ce-4df5-4a6d-b18b-9170d743bd55@a36g2000yqc.googlegroups.com> Message-ID: <8e75mqFbtuU1@mid.individual.net> On 2010-09-01, Albert van der Horst wrote: > [Didn't you mean: I don't understand what you mean by > overlapping recursions? You're right about the base case, so > clearly the OP uses some confusing terminology.] > > I see a problem with overlapping recursions. Unless automatic > memoizing is one, they are unduely inefficient, as each call > splits into two calls. > > If one insists on recursion (untested code, just for the idea.). > > def fib2( n ): > ' return #rabbits last year, #rabbits before last ' > if n ==1 : > return (1,1) > else > penult, ult = fib2( n-1 ) > return ( ult, ult+penult) > > def fub( n ): > return fib2(n)[1] > > Try fib and fub for largish numbers (>1000) and you'll feel the > problem. There are standard tricks for converting a recursive iteration into a tail-recursive one. It's usually done by adding the necessary parameters, e.g.: def fibr(n): def fib_helper(fibminus2, fibminus1, i, n): if i == n: return fibminus2 + fibminus1 else: return fib_helper(fibminus1, fibminus1 + fibminus2, i+1, n) if n < 2: return 1 else: return fib_helper(1, 1, 2, n) Once you've got a tail-recursive solution, you can usually convert it to loop iteration for languages like Python that favor them. The need for a temporary messed me up. def fibi(n): if n < 2: return 1 else: fibminus2 = 1 fibminus1 = 1 i = 2 while i < n: fibminus2, fibminus1 = fibminus1, fibminus2 + fibminus1 i += 1 return fibminus2 + fibminus1 It's interesting that the loop iterative solution is, for me, harder to think up without doing the tail-recursive one first. -- Neil Cerutti From python.koda at gmail.com Wed Sep 1 10:47:49 2010 From: python.koda at gmail.com (Alban Nona) Date: Wed, 1 Sep 2010 10:47:49 -0400 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: Hello, So I figure out this night how to create automatically varibales via vars(), the script seems to work, exept that where it should give me a list like : [ELM004_DIF,ELM004_SPC,ELM004_RFL,ELM004_SSS, ELM004_REFR, ELM004_ALB, etc...] it gave me just one entry in my list, and the last one [ELM004_WPP] Any Ideas why that please ? http://pastebin.com/7CDbVgdD 2010/9/1 Xavier Ho > On 1 September 2010 12:00, Alban Nona wrote: > >> @Xavier: ShaDoW, WorldPositionPoint (which is the same thing as >> WordPointCloud passe) :) >> > > Aha! That's what I was missing. > > Cheers, > Xav > -------------- next part -------------- An HTML attachment was scrubbed... URL: From contact at xavierho.com Wed Sep 1 11:05:12 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 2 Sep 2010 01:05:12 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: On 2 September 2010 00:47, Alban Nona wrote: > Hello, > > So I figure out this night how to create automatically varibales via > vars(), the script seems to work, exept that where it should give me a list > like : > [ELM004_DIF,ELM004_SPC,ELM004_RFL,ELM004_SSS, ELM004_REFR, ELM004_ALB, > etc...] it gave me just one entry in my list, and the last one [ELM004_WPP] > Any Ideas why that please ? > > http://pastebin.com/7CDbVgdD Some comments: 1) Avoid overwriting global functions like list as a variable name. If you do that, you won't be able to use list() later in your code, and nor can anyone else who imports your code. 2) I'm a bit iffy about automatic variable generations. Why not just use a dictionary? What do others on comp.lang.python think? 3) I'm getting an error from your code, and it doesn't match with what you seem to get: # output ELM004_DIF ELM004_SPC ELM004_RFL ELM004_SSS ELM004_REFR ELM004_ALB ELM004_AMB ELM004_NRM ELM004_MVE ELM004_DPF ELM004_SDW ELM004_MAT ELM004_WPP Traceback (most recent call last): File "Test.py", line 33, in print ELM001 NameError: name 'ELM001' is not defined Did you get any compiler errors? I'm using Python 2.7 Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.koda at gmail.com Wed Sep 1 11:11:31 2010 From: python.koda at gmail.com (Alban Nona) Date: Wed, 1 Sep 2010 11:11:31 -0400 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: Hello, seems to have the same error with python. In fact I was coding within nuke, a 2d compositing software (not the best) unfortunately, I dont see how I can use dictionnary to do what I would like to do. 2010/9/1 Xavier Ho > On 2 September 2010 00:47, Alban Nona wrote: > >> Hello, >> >> So I figure out this night how to create automatically varibales via >> vars(), the script seems to work, exept that where it should give me a list >> like : >> [ELM004_DIF,ELM004_SPC,ELM004_RFL,ELM004_SSS, ELM004_REFR, ELM004_ALB, >> etc...] it gave me just one entry in my list, and the last one [ELM004_WPP] >> Any Ideas why that please ? >> >> http://pastebin.com/7CDbVgdD > > > Some comments: > > 1) Avoid overwriting global functions like list as a variable name. If you > do that, you won't be able to use list() later in your code, and nor can > anyone else who imports your code. > 2) I'm a bit iffy about automatic variable generations. Why not just use a > dictionary? What do others on comp.lang.python think? > 3) I'm getting an error from your code, and it doesn't match with what you > seem to get: > > # output > > ELM004_DIF > ELM004_SPC > ELM004_RFL > ELM004_SSS > ELM004_REFR > ELM004_ALB > ELM004_AMB > ELM004_NRM > ELM004_MVE > ELM004_DPF > ELM004_SDW > ELM004_MAT > ELM004_WPP > Traceback (most recent call last): > File "Test.py", line 33, in > print ELM001 > NameError: name 'ELM001' is not defined > > Did you get any compiler errors? I'm using Python 2.7 > > Cheers, > Xav > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lkcl at lkcl.net Wed Sep 1 11:14:41 2010 From: lkcl at lkcl.net (Luke Kenneth Casson Leighton) Date: Wed, 1 Sep 2010 16:14:41 +0100 Subject: [ANN] git peer-to-peer bittorrent experiment: first milestone reached Message-ID: http://gitorious.org/python-libbittorrent/pybtlib this is to let people know that a first milestone has been reached in an experiment to combine git with a file-sharing protocol, thus making it possible to use git for truly distributed software development and other file-revision-management operations (such as transparently turning git-configured ikiwiki and moinmoin wikis into peer-to-peer ones). the milestone reached is to transfer git commit "pack objects", as if they were ordinary files, over a bittorrent network, and have them "unpacked" at the far end. the significance of being able to transfer git commit pack objects is that this is the core of the "git fetch" command. the core of this experiment comprises a python-based VFS layer, providing alternatives to os.listdir, os.path.exists, open and so on - sufficient to make an interesting experiment itself by combining that VFS layer with e.g. python-fuse. the bittornado library, also available at the above URL, has been modified to take a VFS module as an argument to all operations, such that it would be conceivable to share maildir mailboxes, mailing list archives, .tar.gz archives, .deb and .rpm archives and so on, as if they were files and directories within a file-sharing network. as the core code has only existed for under three days, and is only 400 lines long, there are rough edges: * all existing commit objects are unpacked at startup time and are stored in-memory (!). this is done so as to avoid significant modification of the bittorrent library, which will be required. * all transferred commit objects are again stored in-memory before being unpacked. so, killing the client will lose all transfers received up to that point. on the roadmap: * make things efficient! requires modification of the bittornado library. * create some documentation! * explore how to make git use this code as a new URI type so that it will be possible to just do "git pull" * explore how to use PGP/GPG to sign commits(?) or perhaps just tags(?) in order to allow commits to be pulled only from trusted parties. * share all branches and tags as well as just refs/heads/* * make "git push" re-create the .torrent (make_torrent.py) and work out how to notify seeders of a new HEAD (name the torrent after the HEAD ref, and just create a new one rather than delete the old?) so there is quite a bit to do, with the priority being on making a new URI type and a new "git-remote-{URI}" command, so that this becomes actually useable rather than just an experiment, and the project can be self-hosting as a truly distributed peer-to-peer development effort. if anyone would like to assist, you only have to ask and (ironically) i will happily grant access to the gitorious-hosted repository. if anyone would like to sponsor this project, that would be very timely, as if i don't get some money soon i will be unable to pay for food and rent. l. From aahz at pythoncraft.com Wed Sep 1 11:40:37 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Sep 2010 08:40:37 -0700 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: In article , Jerry Hill wrote: >On Tue, Aug 31, 2010 at 10:09 AM, Aahz wrote: >> >> I suggest that we should agree on these guarantees and document them in >> the core. > >I can't get to the online python-dev archives from work (stupid >filter!) so I can't give you a link to the archives, but the original >thread that resulted in the creation of that wiki page was started on >March 9th, 2008 and was titled "Complexity documentation request". http://mail.python.org/pipermail/python-dev/2008-March/077499.html >At the time, opposition to formally documenting this seemed pretty >widespread, including from yourself and Guido. You've obviously >changed your mind on the subject, so maybe it's something that would >be worth revisiting, assuming someone wants to write the doc change. Looking back at that thread, it's less that I've changed my mind as that I've gotten a bit more nuanced. I still think that making a full set of algorithmic guarantees is a Bad Idea, but I think that any implementation that doesn't have O(1) for list element access is fundamentally broken, and we should probably document that somewhere. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From stefan_ml at behnel.de Wed Sep 1 11:55:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Sep 2010 17:55:48 +0200 Subject: [ANN] git peer-to-peer bittorrent experiment: first milestone reached In-Reply-To: References: Message-ID: Luke Kenneth Casson Leighton, 01.09.2010 17:14: > this is to let people know that a first milestone has been reached in > an experiment to combine git with a file-sharing protocol, thus making > it possible to use git for truly distributed software development Basically, BitTorrent only works well when there are enough people who share a common interest at the same time. Why would you think that is the case for software development, and what minimum project size would you consider reasonable to make this tool a valid choice? If you're more like targeting in-house development, it could become a little boring to be the first who arrives in the morning ... Stefan From stefan_ml at behnel.de Wed Sep 1 11:57:43 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Sep 2010 17:57:43 +0200 Subject: Performance: sets vs dicts. In-Reply-To: References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: Aahz, 01.09.2010 17:40: > I still think that making a full set of > algorithmic guarantees is a Bad Idea, but I think that any implementation > that doesn't have O(1) for list element access is fundamentally broken, > and we should probably document that somewhere. +1 Stefan From ron.eggler at gmail.com Wed Sep 1 11:58:43 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 1 Sep 2010 08:58:43 -0700 (PDT) Subject: DeprecationWarning Message-ID: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Hi There, I would like to create an scp handle and download a file from a client. I have following code: import sys, os, paramiko,time from attachment import SCPClient transport = paramiko.Transport((prgIP, 22)) try: transport.connect(username='root', password=prgPass) except IOError: print "Transport connect timed out" writelog(" Transport connect timed out. \n") sys.exit() scp = SCPClient(transport) writelog("Succesfully created scp transport handle to get P-file \n") # Create '/tmp/autokernel' if it does not exist. if not os.access('./PRGfiles', os.F_OK): os.mkdir('./PRGfiles') try: scp.get("/usr/share/NovaxTSP/P0086_2003.xml","./PRGfiles/ P0086_2003.xml") writelog("succesfully downloaded P-file \n") except IOError: writelog("Downloading P-file failed. \n") but what i'm getting is this and no file is downloaded...: /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 chan.send('\x01'+e.message) 09/01/2010 08:53:56 : Downloading P-file failed. What does that mean and how do i resolve this? Thank you! Ron From ipatrol6010 at yahoo.com Wed Sep 1 12:01:39 2010 From: ipatrol6010 at yahoo.com (ipatrol6010 at yahoo.com) Date: Wed, 1 Sep 2010 12:01:39 -0400 Subject: Better multiprocessing and data persistance with C level serialisation Message-ID: I was thinking about this for a while. Owing to a lack of forking or START/STOP signals, all process interchange in CPython requires serialisation, usually pickling. But what if that could be done within the interpreter core instead of by the script, creating a complete internal representation that can then be read by the child interpreter. Any comments/ideas/suggestions? From contact at xavierho.com Wed Sep 1 12:37:03 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 2 Sep 2010 02:37:03 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: On 2 September 2010 01:11, Alban Nona wrote: > Hello, > > seems to have the same error with python. > In fact I was coding within nuke, a 2d compositing software (not the best) > unfortunately, I dont see how I can use dictionnary to do what I would like > to do. > Hello Alban, The reason it's printing only the ELM004 elements is because the variable, first, is 'ELM004' when your code goes to line 29. I noticed you're using variables created from the for loop out of its block as well. Personally I wouldn't recommend it as good practice. There are ways around it. Could you explain briefly what you want to achieve with this program? What's the desired sample output? Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.koda at gmail.com Wed Sep 1 12:49:57 2010 From: python.koda at gmail.com (Alban Nona) Date: Wed, 1 Sep 2010 12:49:57 -0400 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: Hello Xavier, Thank you :) Well what Iam trying to generate is that kind of result: listn1=['ELM001_DIF', 'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT', 'ELM001_WPP'] listn2 = ['ELM002_DIF', 'ELM002_SPC', 'ELM002_RFL', 'ELM002_SSS', 'ELM002_REFR', 'ELM002_ALB', 'ELM002_AMB', 'ELM002_NRM', 'ELM002_MVE', 'ELM002_DPF', 'ELM002_SDW', 'ELM002_MAT', 'ELM002_WPP'] etc... The thing is, the first list will be generated automatically. (so there will be unknow versions of ELM00x....) that why Im trying to figure out how to genere variable and list in an automatic way. Can you tell me if its not clear please ? :P my english still need improvement when Im trying to explain scripting things. 2010/9/1 Xavier Ho > On 2 September 2010 01:11, Alban Nona wrote: > >> Hello, >> >> seems to have the same error with python. >> In fact I was coding within nuke, a 2d compositing software (not the best) >> unfortunately, I dont see how I can use dictionnary to do what I would >> like to do. >> > > Hello Alban, > > The reason it's printing only the ELM004 elements is because the variable, > first, is 'ELM004' when your code goes to line 29. > > I noticed you're using variables created from the for loop out of its block > as well. Personally I wouldn't recommend it as good practice. There are ways > around it. > > Could you explain briefly what you want to achieve with this program? > What's the desired sample output? > > Cheers, > Xav > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.koda at gmail.com Wed Sep 1 12:49:57 2010 From: python.koda at gmail.com (Alban Nona) Date: Wed, 1 Sep 2010 12:49:57 -0400 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: Hello Xavier, Thank you :) Well what Iam trying to generate is that kind of result: listn1=['ELM001_DIF', 'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT', 'ELM001_WPP'] listn2 = ['ELM002_DIF', 'ELM002_SPC', 'ELM002_RFL', 'ELM002_SSS', 'ELM002_REFR', 'ELM002_ALB', 'ELM002_AMB', 'ELM002_NRM', 'ELM002_MVE', 'ELM002_DPF', 'ELM002_SDW', 'ELM002_MAT', 'ELM002_WPP'] etc... The thing is, the first list will be generated automatically. (so there will be unknow versions of ELM00x....) that why Im trying to figure out how to genere variable and list in an automatic way. Can you tell me if its not clear please ? :P my english still need improvement when Im trying to explain scripting things. 2010/9/1 Xavier Ho > On 2 September 2010 01:11, Alban Nona wrote: > >> Hello, >> >> seems to have the same error with python. >> In fact I was coding within nuke, a 2d compositing software (not the best) >> unfortunately, I dont see how I can use dictionnary to do what I would >> like to do. >> > > Hello Alban, > > The reason it's printing only the ELM004 elements is because the variable, > first, is 'ELM004' when your code goes to line 29. > > I noticed you're using variables created from the for loop out of its block > as well. Personally I wouldn't recommend it as good practice. There are ways > around it. > > Could you explain briefly what you want to achieve with this program? > What's the desired sample output? > > Cheers, > Xav > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Sep 1 12:52:09 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Sep 2010 18:52:09 +0200 Subject: Newby Needs Help with Python code References: <861505.20099.qm@web33506.mail.mud.yahoo.com> Message-ID: Nally Kaunda-Bukenya wrote: > I hope someone can help me. I am new to Python and trying to achive the > following: > 1) I would like to populate the Tot_Ouf_Area field with total area of > each unique outfall_id (code attempted below,but Tot_Ouf_Area not > populating) > 2) I would also like to get the user input of Rv ( each > landuse type will have a specific Rv value). For example the program > should ask the user for Rv value of Low Density Residential (user enters > 0.4 in example below and that value must be stored in the Rv field), and > so on as shown in the 2nd table below? I don't know arcgis, so the following is just guesswork. I iterate over the Outfalls_ND table twice, the first time to calculate the sums per OUTFALL_ID and put them into a dict. With the second pass the Tot_Outf_Area column is updated import arcgisscripting def rows(cur): while True: row = cur.Next() if row is None: break yield row gp = arcgisscripting.create() gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb" TABLE = "Outfalls_ND" GROUP = "OUTFALL_ID" SUM = "AREA_ACRES" TOTAL = "Tot_Outf_Area" aggregate = {} cur = gp.UpdateCursor(TABLE) for row in rows(cur): group = row.GetValue(GROUP) amount = row.GetValue(SUM) aggregate[group] = aggregate.get(group, 0.0) + amount cur = gp.UpdateCursor(TABLE) for row in rows(cur): group = row.GetValue(GROUP) row.SetValue(TOTAL, aggregate[group]) cur.UpdateRow(row) As this is written into the blue it is unlikely that it runs successfully without changes. Just try and report back the results. Peter From ron.eggler at gmail.com Wed Sep 1 12:56:18 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 1 Sep 2010 09:56:18 -0700 (PDT) Subject: scp with paramiko Message-ID: <8bfa00e7-2ae5-42a3-bb45-fcdb491d70e4@x18g2000pro.googlegroups.com> Hi There, I want to download a file from a client using paramiko. I found plenty of ressources using google on how to send a file but none that would describe how to download files from a client. Help would be appreciated! Thanks a lot! Ron From python at mrabarnett.plus.com Wed Sep 1 12:59:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Sep 2010 17:59:49 +0100 Subject: Optimising literals away In-Reply-To: <4c7e3ef6$1@dnews.tpgi.com.au> References: <69a8fbbc-5f45-491a-adf3-2fb5a4d79660@s9g2000yqd.googlegroups.com> <4C7D79EE.8010402@mrabarnett.plus.com> <4c7e3ef6$1@dnews.tpgi.com.au> Message-ID: <4C7E8685.4090408@mrabarnett.plus.com> On 01/09/2010 14:25, Lie Ryan wrote: > On 09/01/10 17:06, Stefan Behnel wrote: >> MRAB, 31.08.2010 23:53: >>> On 31/08/2010 21:18, Terry Reedy wrote: >>>> On 8/31/2010 12:33 PM, Aleksey wrote: >>>>> On Aug 30, 10:38 pm, Tobias Weber wrote: >>>>>> Hi, >>>>>> whenever I type an "object literal" I'm unsure what optimisation >>>>>> will do >>>>>> to it. >>>> >>>> Optimizations are generally implentation dependent. CPython currently >>>> creates numbers, strings, and tuple literals just once. Mutable literals >>>> must be created each time as they may be bound and saved. >>>> >>>>>> def m(arg): >>>>>> if arg& set([1,2,3]): >>>> >>>> set() is a function call, not a literal. When m is called, who knows >>>> what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, >>>> which is much faster as it avoids creating and deleting a list. On my >>>> machine, .35 versus .88 usec. Even then, it must be calculated each time >>>> because sets are mutable and could be returned to the calling code. >>>> >>> There's still the possibility of some optimisation. If the resulting >>> set is never stored anywhere (bound to a name, for example) then it >>> could be created once. When the expression is evaluated there could be >>> a check so see whether 'set' is bound to the built-in class, and, if it >>> is, then just use the pre-created set. > > What if the set is mutated by the function? That will modify the global > cache of the set; one way to prevent mutation is to use frozenset, but > from the back of my mind, I think there was a discussion that rejects > set literals producing a frozen set instead of regular set. > [snip] I was talking about a use case like the example code, where the set is created, checked, and then discarded. From hennebry at web.cs.ndsu.nodak.edu Wed Sep 1 13:03:43 2010 From: hennebry at web.cs.ndsu.nodak.edu (Mike) Date: Wed, 1 Sep 2010 10:03:43 -0700 (PDT) Subject: Windows vs. file.read Message-ID: I have a ppm file that python 2.5 on Windows XP cannot read completely. Python on linux can read the file with no problem Python on Windows can read similar files. I've placed test code and data here: http://www.cs.ndsu.nodak.edu/~hennebry/ppm_test.zip Within the directory ppm_test, type python ppm_test.py The chunk size commentary occurs only if file.read cannot read enough bytes. The commentary only occurs for the last file. Any ideas? Any ideas that don't require getting rid of Windows? It's not my option. From contact at xavierho.com Wed Sep 1 13:18:13 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 2 Sep 2010 03:18:13 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: On 2 September 2010 02:49, Alban Nona wrote: > Well what Iam trying to generate is that kind of result: > > listn1=['ELM001_DIF', 'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', > 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', > 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT', 'ELM001_WPP'] > > listn2 = ['ELM002_DIF', 'ELM002_SPC', 'ELM002_RFL', 'ELM002_SSS', > 'ELM002_REFR', 'ELM002_ALB', 'ELM002_AMB', 'ELM002_NRM', 'ELM002_MVE', > 'ELM002_DPF', 'ELM002_SDW', 'ELM002_MAT', 'ELM002_WPP'] > > etc... > Have a look at http://www.ideone.com/zlBeB . I took some liberty and renamed some of your variables. I wanted to show you what I (personally) think as good practices in python, from naming conventions to how to use the list and dictionary, and so on. Also, 4-spaces indent. I noticed you have 5 for some reason, but that's none of my business now. I hope my comments explain what they do, and why they are that way. > The thing is, the first list will be generated automatically. (so there > will be unknow versions of ELM00x....) > that why Im trying to figure out how to genere variable and list in an > automatic way. > Yes, that's totally possible. See range() (and xrange(), possibly) in the Python API. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Sep 1 13:22:29 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Sep 2010 18:22:29 +0100 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: <4C7E8BD5.3010300@mrabarnett.plus.com> On 01/09/2010 17:49, Alban Nona wrote: > Hello Xavier, > > Thank you :) > > Well what Iam trying to generate is that kind of result: > > listn1=['ELM001_DIF', 'ELM001_SPC', 'ELM001_RFL', 'ELM001_SSS', > 'ELM001_REFR', 'ELM001_ALB', 'ELM001_AMB', 'ELM001_NRM', 'ELM001_MVE', > 'ELM001_DPF', 'ELM001_SDW', 'ELM001_MAT', 'ELM001_WPP'] > > listn2 = ['ELM002_DIF', 'ELM002_SPC', 'ELM002_RFL', 'ELM002_SSS', > 'ELM002_REFR', 'ELM002_ALB', 'ELM002_AMB', 'ELM002_NRM', 'ELM002_MVE', > 'ELM002_DPF', 'ELM002_SDW', 'ELM002_MAT', 'ELM002_WPP'] > > etc... > > The thing is, the first list will be generated automatically. (so there > will be unknow versions of ELM00x....) > that why Im trying to figure out how to genere variable and list in an > automatic way. > > Can you tell me if its not clear please ? :P > my english still need improvement when Im trying to explain scripting > things. > [snip] Create a dict in which the key is the "ELEM" part and the value is a list of those entries which begin with that "ELEM" part. For example, if the entry is 'ELEM001_DIF' then the key is 'ELEM001', which is the first 7 characters of entry, or entry[ : 7]. Something like this: elem_dict = {} for entry in list_of_entries: key = entry[ : 7] if key in elem_dict: elem_dict[key].append(entry) else: elem_dict[key] = [entry] From hennebry at web.cs.ndsu.nodak.edu Wed Sep 1 13:31:27 2010 From: hennebry at web.cs.ndsu.nodak.edu (Mike) Date: Wed, 1 Sep 2010 10:31:27 -0700 (PDT) Subject: Fibonacci: How to think recursively References: <890665ce-4df5-4a6d-b18b-9170d743bd55@a36g2000yqc.googlegroups.com> <8e75mqFbtuU1@mid.individual.net> Message-ID: The most straightforward method would be to apply the formula directly. Loop on j computing Fj along the way if n<=1 : return n Fold=0 Fnew=1 for j in range(2,n) : Fold, Fnew = Fnew, Fold+Fnew return Fnew Even simpler: return round(((1+sqrt(5.))/2)**n/sqrt(5.)) From python at mrabarnett.plus.com Wed Sep 1 13:31:50 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Sep 2010 18:31:50 +0100 Subject: Windows vs. file.read In-Reply-To: References: Message-ID: <4C7E8E06.5000202@mrabarnett.plus.com> On 01/09/2010 18:03, Mike wrote: > I have a ppm file that python 2.5 on Windows XP cannot read > completely. > Python on linux can read the file with no problem > Python on Windows can read similar files. > I've placed test code and data here: > http://www.cs.ndsu.nodak.edu/~hennebry/ppm_test.zip > Within the directory ppm_test, type > python ppm_test.py > The chunk size commentary occurs only if file.read cannot read enough > bytes. > The commentary only occurs for the last file. > Any ideas? > Any ideas that don't require getting rid of Windows? > It's not my option. You should open the files in binary mode, not text mode, ie file(path, "rb"). Text mode is the default. Not a problem on *nix because the line ending is newline. From drobinow at gmail.com Wed Sep 1 13:34:06 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 1 Sep 2010 13:34:06 -0400 Subject: Windows vs. file.read In-Reply-To: References: Message-ID: On Wed, Sep 1, 2010 at 1:03 PM, Mike wrote: > I have a ppm file that python 2.5 on Windows XP cannot read > completely. > Python on linux can read the file with no problem > Python on Windows can read similar files. > I've placed test code and data here: > http://www.cs.ndsu.nodak.edu/~hennebry/ppm_test.zip > Within the directory ppm_test, type > python ppm_test.py > The chunk size commentary occurs only if file.read cannot read enough > bytes. > The commentary only occurs for the last file. > Any ideas? > Any ideas that don't require getting rid of Windows? > It's not my option. Open the files in binary mode. i.e., x=Ppm(file("ff48x32.ppm",'rb')) x=Ppm(file("bw48x32.ppm",'rb')) x=Ppm(file("bisonfootball.ppm",'rb')) You were just lucky on the first two files. From a_jtim at bellsouth.net Wed Sep 1 13:46:50 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Wed, 1 Sep 2010 10:46:50 -0700 (PDT) Subject: parsing string into dict Message-ID: Hi, I have a set of strings that are *basically* comma separated, but with the exception that if a comma occur insides curly braces it is not a delimiter. Here's an example: [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] I'd like to parse that into a dictionary (note that 'continued' gets the value 'true'): {'code':'one', 'caption':'{My Analysis for \textbf{t}, Version 1}','continued':'true'} I know and love pyparsing, but for this particular code I need to rely only on the standard library (I'm running 2.7). Here's what I've got, and it works. I wonder if there's a simpler way? thanks, --Tim Arnold The 'line' is like my example above but it comes in without the ending bracket, so I append one on the 6th line. def parse_options(line): options = dict() if not line: return options active = ['[','=',',','{','}',']'] line += ']' key = '' word = '' inner = 0 for c in list(line): if c in active: if c == '{': inner +=1 elif c == '}': inner -=1 if inner: word += c else: if c == '=': (key,word) = (word,'') options[key.strip()] = True elif c in [',', ']']: if not key: options[word.strip()] = True else: options[key.strip()] = word.strip() (key,word) = (False, '') else: word += c return options From sarvilive at gmail.com Wed Sep 1 13:49:39 2010 From: sarvilive at gmail.com (sarvi) Date: Wed, 1 Sep 2010 10:49:39 -0700 (PDT) Subject: PyPy and RPython Message-ID: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Is there a plan to adopt PyPy and RPython under the python foundation in attempt to standardize both. I have been watching PyPy and RPython evolve over the years. PyPy seems to have momentum and is rapidly gaining followers and performance. PyPy JIT and performance would be a good thing for the Python Community And it seems to be well ahead of Unladen Swallow in performance and in a position to improve quite a bit. Secondly I have always fantasized of never having to write C code yet get its compiled performance. With RPython(a strict subset of Python), I can actually compile it to C/Machine code These 2 seem like spectacular advantages for Python to pickup on. And all this by just showing the PyPy and the Python foundation's support and direction to adopt them. Yet I see this forum relatively quite on PyPy or Rpython ? Any reasons??? Sarvi From hennebry at web.cs.ndsu.nodak.edu Wed Sep 1 13:58:05 2010 From: hennebry at web.cs.ndsu.nodak.edu (Mike) Date: Wed, 1 Sep 2010 10:58:05 -0700 (PDT) Subject: Windows vs. file.read References: Message-ID: On Sep 1, 12:31?pm, MRAB wrote: > You should open the files in binary mode, not text mode, ie file(path, > "rb"). Text mode is the default. Not a problem on *nix because the line > ending is newline. Thanks. That was it. From contact at xavierho.com Wed Sep 1 14:12:02 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 2 Sep 2010 04:12:02 +1000 Subject: Dumb Stupid Question About List and String In-Reply-To: References: <4C7D5B3F.5070102@mrabarnett.plus.com> Message-ID: 2010/9/2 Alban Nona > Hello Xavier, working great ! thank you very much ! :p > Do you know by any chance if dictionnary can be sorted asthis: > Look at the sorted() global function in the Python API. ;] Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From cappy2112 at gmail.com Wed Sep 1 15:18:18 2010 From: cappy2112 at gmail.com (Cappy2112) Date: Wed, 1 Sep 2010 12:18:18 -0700 (PDT) Subject: Installation problem: Python 2.6.6 (32-Bit) on Windows 7 (32-Bit) Message-ID: <0781783a-b182-455f-8522-ed5a37db6e14@o7g2000prg.googlegroups.com> Has anyone else had problems running the msi for Python 2.6.6 on Windows 7 Professional? If I don't check "Compile .py to byte code", the installer completes without error. Checking "Compile .py to byte code" causes the following to be displayed "There is a problem with the windows installer package. A program run as part of setup did not complete as expected" 1. I have GB of disk space available. 2. I have admin privileges 3. The MD5 checksum of the downloaded installer matches the MD5 checksum on python.org 4. Run As Adminsitrator is not available when I Shift-Right Click (probably because my login already has admin privileges) I'm also having a similar issue with the PythonWin32 extensions installer on the same machine. From vicente.soler at gmail.com Wed Sep 1 15:29:52 2010 From: vicente.soler at gmail.com (vsoler) Date: Wed, 1 Sep 2010 12:29:52 -0700 (PDT) Subject: Source code for itertools References: <9aa266f0-be9b-4c9a-bfbd-6cdfc86ad2c8@t20g2000yqa.googlegroups.com> <7xmxs3sdt2.fsf@ruckus.brouhaha.com> Message-ID: On 31 ago, 05:33, Rolando Espinoza La Fuente wrote: > On Mon, Aug 30, 2010 at 11:06 PM, vsoler wrote: > > On 31 ago, 04:42, Paul Rubin wrote: > >> vsoler writes: > >> > I was expecting an itertools.py file, but I don't see it in your list. > >> >> ./python3.1-3.1.2+20100829/Modules/itertoolsmodule.c > > >> looks promising. ?Lots of stdlib modules are written in C for speed or > >> access to system facilities. > > > Lawrence, Paul, > > > You seem to be running a utility I am not familiar with. Perhaps this > > is because I am using Windows, and most likely you are not. > > > How could I have found the answer in a windows environment? > > Hard question. They are using standard unix utilities. > > But you can find the source file of a python module within python: > > >>> import itertools > >>> print(itertools.__file__) > > /usr/lib/python2.6/lib-dynload/itertools.so > > Yours should point to a windows path. If the file ends with a ".py", > you can open the file > with any editor. If ends with ".so" or something else ?likely is a > compiled module in C > and you should search in the source distribution, not the binary distribution. > > Hope it helps. > > Regards, > > Rolando Espinoza La fuentewww.insophia.com Thank you Rolando for your contribution. Followinf your piece of advice I got: >>> import itertools >>> print(itertools.__file__) Traceback (most recent call last): File "", line 1, in print(itertools.__file__) AttributeError: 'module' object has no attribute '__file__' >>> So, I undestand that the module is written in C. Vicente Soler From vicente.soler at gmail.com Wed Sep 1 15:30:40 2010 From: vicente.soler at gmail.com (vsoler) Date: Wed, 1 Sep 2010 12:30:40 -0700 (PDT) Subject: Source code for itertools References: <9aa266f0-be9b-4c9a-bfbd-6cdfc86ad2c8@t20g2000yqa.googlegroups.com> <7xmxs3sdt2.fsf@ruckus.brouhaha.com> Message-ID: <331028b7-29a3-4a6b-893e-c0f1f77a6f03@k10g2000yqa.googlegroups.com> On 1 sep, 06:30, Tim Roberts wrote: > vsoler wrote: > >On 31 ago, 04:42, Paul Rubin wrote: > >> vsoler writes: > >> > I was expecting an itertools.py file, but I don't see it in your list. > >> >> ./python3.1-3.1.2+20100829/Modules/itertoolsmodule.c > > >> looks promising. ?Lots of stdlib modules are written in C for speed or > >> access to system facilities. > > >Lawrence, Paul, > > >You seem to be running a utility I am not familiar with. Perhaps this > >is because I am using Windows, and most likely you are not. > > >How could I have found the answer in a windows environment? > > Did you take the time to understand what he did? ?It's not that hard to > figure out. ?He fetched the Python source code, unpacked it, then search > for filenames that contained the string "itertools." > > The equivalent in Windows, after unpacking the source archive, would have > been: > ? ? dir /s *itertools* > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Thank you Tim, understood!!! From kr4uzi at googlemail.com Wed Sep 1 16:14:51 2010 From: kr4uzi at googlemail.com (Markus Kraus) Date: Wed, 1 Sep 2010 13:14:51 -0700 (PDT) Subject: C++ - Python API Message-ID: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Hi guys i worked on this for severl days (or even weeks?!) now, but im nearly finished with it: A complete C++ to Python API which allows you to use python as a scripting language for your C++ projects. Simple example: --- python code --- def greet( player ): print( "Hello player " + player.getName() + " !" ) ------ --- c++ code --- class CPlayer { REGISTER_CLASS( CPlayer, CLASS_METHOD("getName", GetName) ) private: string m_Name; public: CPlayer( string nName ) { m_Name = nName; INITIALIZE("player"); } string GetName( ) { return m_Name; } }; ------ If you call the python function (look into the example in the project to see how to do this) this results in ( assume you have CPlayer("myPlayerName") ) "Hello player myPlayerName!". So the feature overview: For C++ classes: - "translating" it into a python object - complete reflexion (attributes and methods) of the c++ instance - call c++ methods nearly directly from python - method-overloading (native python doesnt support it (!)) Modules: - the API allowes to create hardcoded python modules without having any knowledge about the python C-API - Adding attributes to the module (long/char*/PyObject*) General: -runs on any platform and doenst need an installed python -runs in multithreaded environments (requires python > 2.3) -support for python 3.x -no need of any python C-API knowledge (maybe for coding modules but then only 2 or 3 functions) -the project is a VC2010 one and there is also an example module + class If there is any interest in testing this or using this for your own project, please post; in that case i'll release it now instead of finishing the inheritance support before releasing it (this may take a few days though). From arnodel at googlemail.com Wed Sep 1 16:20:07 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 01 Sep 2010 21:20:07 +0100 Subject: parsing string into dict References: Message-ID: Tim Arnold writes: > Hi, > I have a set of strings that are *basically* comma separated, but with > the exception that if a comma occur insides curly braces it is not a > delimiter. Here's an example: > > [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] > > I'd like to parse that into a dictionary (note that 'continued' gets > the value 'true'): > {'code':'one', 'caption':'{My Analysis for \textbf{t}, Version > 1}','continued':'true'} > > I know and love pyparsing, but for this particular code I need to rely > only on the standard library (I'm running 2.7). Here's what I've got, > and it works. I wonder if there's a simpler way? > thanks, > --Tim Arnold > FWIW, here's how I would do it: def parse_key(s, start): pos = start while s[pos] not in ",=]": pos += 1 return s[start:pos].strip(), pos def parse_value(s, start): pos, nesting = start, 0 while nesting or s[pos] not in ",]": nesting += {"{":1, "}":-1}.get(s[pos], 0) pos += 1 return s[start:pos].strip(), pos def parse_options(s): options, pos = {}, 0 while s[pos] != "]": key, pos = parse_key(s, pos + 1) if s[pos] == "=": value, pos = parse_value(s, pos + 1) else: value = 'true' options[key] = value return options test = "[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued]" >>> parse_options(test) {'caption': '{My Analysis for \textbf{t}, Version 1}', 'code': 'one', 'continued': True} -- Arnaud From tjreedy at udel.edu Wed Sep 1 16:22:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Sep 2010 16:22:56 -0400 Subject: Performance: sets vs dicts. In-Reply-To: References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: On 9/1/2010 11:40 AM, Aahz wrote: > I think that any implementation > that doesn't have O(1) for list element access is fundamentally broken, Whereas I think that that claim is fundamentally broken in multiple ways. > and we should probably document that somewhere. I agree that *current* algorithmic behavior of parts of CPython on typical *current* hardware should be documented not just 'somewhere' (which I understand it is, in the Wiki) but in a CPython doc included in the doc set distributed with each release. Perhaps someone or some group could write a HowTo on Programming with CPython's Builtin Classes that would describe both the implementation and performance and also the implications for coding style. In particular, it could compare CPython's array lists and tuples to singly linked lists (which are easily created in Python also). But such a document, after stating that array access may be thought of as constant time on current hardware to a useful first approximation, should also state that repeated seqeuntial accessess may be *much* faster than repeated random accessess. People in the high-performance computing community are quite aware of this difference between simplified lies and messy truth. Because of this, array algorithms are (should be) written differently in Fortran and C because Fortran stores arrays by columns and C by rows and because it is usually much faster to access the next item than one far away. -- Terry Jan Reedy From thomas at jollybox.de Wed Sep 1 16:29:42 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 1 Sep 2010 22:29:42 +0200 Subject: C++ - Python API In-Reply-To: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: <201009012229.43096.thomas@jollybox.de> On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: > So the feature overview: First, the obligatory things you don't want to hear: Have you had a look at similar efforts? A while ago, Aahz posted something very similar on this very list. You should be able to find it in any of the archives without too much trouble. The most prominent example of this is obviously Boost.Python. > For C++ classes: > - "translating" it into a python object How do you handle memory management ? > - complete reflexion (attributes and methods) of the c++ instance > - call c++ methods nearly directly from python > - method-overloading (native python doesnt support it (!)) > > Modules: > - the API allowes to create hardcoded python modules without having > any knowledge about the python C-API > - Adding attributes to the module (long/char*/PyObject*) char*... Unicode? Somewhere? wchar_t* maybe, or std::wstring? No? Also -- double? (I'm just being pedantic now, at least double should be trivial to add) > > General: > -runs on any platform and doenst need an installed python Which platforms did you test it on? Which compilers did you test? Are you sure your C++ is portable? > -runs in multithreaded environments (requires python > 2.3) How do you deal with the GIL? How do you handle calling to Python from multiple C++ threads? > -support for python 3.x > -no need of any python C-API knowledge (maybe for coding modules but > then only 2 or 3 functions) > -the project is a VC2010 one and there is also an example module + > class Again, have you tested other compilers? > If there is any interest in testing this or using this for your own > project, please post; in that case i'll release it now instead of > finishing the inheritance support before releasing it (this may take a > few days though). Just publish a bitbucket or github repository ;-) From arnodel at googlemail.com Wed Sep 1 16:46:12 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 01 Sep 2010 21:46:12 +0100 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: Terry Reedy writes: > On 9/1/2010 11:40 AM, Aahz wrote: >> I think that any implementation >> that doesn't have O(1) for list element access is fundamentally broken, > > Whereas I think that that claim is fundamentally broken in multiple ways. > >> and we should probably document that somewhere. > > I agree that *current* algorithmic behavior of parts of CPython on > typical *current* hardware should be documented not just 'somewhere' > (which I understand it is, in the Wiki) but in a CPython doc included > in the doc set distributed with each release. > > Perhaps someone or some group could write a HowTo on Programming with > CPython's Builtin Classes that would describe both the implementation > and performance and also the implications for coding style. In > particular, it could compare CPython's array lists and tuples to > singly linked lists (which are easily created in Python also). > > But such a document, after stating that array access may be thought of > as constant time on current hardware to a useful first approximation, > should also state that repeated seqeuntial accessess may be *much* > faster than repeated random accessess. People in the high-performance > computing community are quite aware of this difference between > simplified lies and messy truth. Because of this, array algorithms are > (should be) written differently in Fortran and C because Fortran > stores arrays by columns and C by rows and because it is usually much > faster to access the next item than one far away. I don't understand what you're trying to say. Aahz didn't claim that random list element access was constant time, he said it was O(1) (and that it should be part of the Python spec that it is). -- Arnaud From kr4uzi at googlemail.com Wed Sep 1 16:49:19 2010 From: kr4uzi at googlemail.com (Markus Kraus) Date: Wed, 1 Sep 2010 13:49:19 -0700 (PDT) Subject: C++ - Python API References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: <0ea3a6ee-b78d-4d82-88e8-4e7aaf3c9bd7@h19g2000yqb.googlegroups.com> Thanks for the answer On 1 Sep., 22:29, Thomas Jollans wrote: > On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: > > > So the feature overview: > > First, the obligatory things you don't want to hear: Have you had a look at > similar efforts? A while ago, Aahz posted something very similar on this very > list. You should be able to find it in any of the archives without too much > trouble. > The most prominent example of this is obviously Boost.Python. I searched in Aahz posts but i didn't find anything related. About Boost.Python: I worked with it but (for me) it seems more like if it's meant to create pyd modules. > > For C++ classes: > > - "translating" it into a python object > > How do you handle memory management ? As long as the c++ instanze itself exists, the python object is existing too. If you delete the c++ instanze the python one is also deleted (in a multithreaded environment you'll get a "This object has already been deleted" error). > > - complete reflexion (attributes and methods) of the c++ instance > > - call c++ methods nearly directly from python > > - method-overloading (native python doesnt support it (!)) > > > Modules: > > - the API allowes to create hardcoded python modules without having > > any knowledge about the python C-API > > - Adding attributes to the module (long/char*/PyObject*) > > char*... > Unicode? Somewhere? wchar_t* maybe, or std::wstring? No? Also -- double? (I'm > just being pedantic now, at least double should be trivial to add) I haven't worked too much on this yet but ill add support for all common c++ types. > > General: > > -runs on any platform and doenst need an installed python > > Which platforms did you test it on? Which compilers did you test? Are you sure > your C++ is portable? My C++ code is not platform dependent so it should (haven't tested it yet) be portable. > > -runs in multithreaded environments (requires python > 2.3) > > How do you deal with the GIL? > How do you handle calling to Python from multiple C++ threads? Since python 2.3 there are the function PyGILState_Ensure and PyGILState_Release functions which do the whole GIL stuff for you :). > > -support for python 3.x > > -no need of any python C-API knowledge (maybe for coding modules but > > then only 2 or 3 functions) > > -the project is a VC2010 one and there is also an example module + > > class > > Again, have you tested other compilers? Dont have the ability for it (could need a linux guy who knows how to create a makefile). > > If there is any interest in testing this or using this for your own > > project, please post; in that case i'll release it now instead of > > finishing the inheritance support before releasing it (this may take a > > few days though). > > Just publish a bitbucket or github repository ;-) Ill set up a googlecode site :P From tjreedy at udel.edu Wed Sep 1 16:54:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Sep 2010 16:54:09 -0400 Subject: Performance: sets vs dicts. In-Reply-To: <7xvd6qufqw.fsf@ruckus.brouhaha.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <878w3ogpvq.fsf@benfinney.id.au> <7xvd6qufqw.fsf@ruckus.brouhaha.com> Message-ID: On 9/1/2010 2:42 AM, Paul Rubin wrote: > Terry Reedy writes: >> Does anyone seriously think that an implementation should be rejected >> as an implementation if it intellegently did seq[n] lookups in >> log2(n)/31 time units for all n (as humans would do), instead of >> stupidly taking 1 time unit for all n< 2**31 and rejecting all larger >> values (as 32-bit CPython does)? > > Er, how can one handle n> 2**31 at all, in 32-bit CPython? I am not sure of what you mean by 'handle'. Ints (longs in 2.x) are not limited, but indexes are. 2**31 and bigger are summarily rejected as impossibly too large, even though they might not actually be so these days. >>> s=b'' >>> s[1] Traceback (most recent call last): File "", line 1, in s[1] IndexError: index out of range >>> s[2**32] Traceback (most recent call last): File "", line 1, in s[2**32] IndexError: cannot fit 'int' into an index-sized integer As far as I know, this is undocumented. In any case, this means that if it were possible to create a byte array longer than 2**31 on an otherwise loaded 32-bit linux machine with 2**32 memory, then indexing the end elements would not be possible, which is to say, O(1) would jump to O(INF). I do not have such a machine to test whether big = open('2.01.gigabytes', 'rb').read() executes or raises an exception. Array size limits are also not documented. -- Terry Jan Reedy From stef.mientki at gmail.com Wed Sep 1 17:32:57 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 01 Sep 2010 23:32:57 +0200 Subject: what is this kind of string: b'string' ? Message-ID: <4C7EC689.6040508@gmail.com> in winpdb I see strings like this: >>>a = b'string' >>>a 'string' >>> type(a) what's the "b" doing in front of the string ? thanks, Stef Mientki From robert.kern at gmail.com Wed Sep 1 17:39:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 01 Sep 2010 16:39:29 -0500 Subject: what is this kind of string: b'string' ? In-Reply-To: <4C7EC689.6040508@gmail.com> References: <4C7EC689.6040508@gmail.com> Message-ID: On 9/1/10 4:32 PM, Stef Mientki wrote: > in winpdb I see strings like this: > >>>> a = b'string' >>>> a > 'string' >>>> type(a) > > > what's the "b" doing in front of the string ? http://docs.python.org/py3k/library/stdtypes.html#bytes-and-byte-array-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 john at castleamber.com Wed Sep 1 17:40:59 2010 From: john at castleamber.com (John Bokma) Date: Wed, 01 Sep 2010 16:40:59 -0500 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: <87iq2pcfbo.fsf@castleamber.com> Arnaud Delobelle writes: > Terry Reedy writes: > >> On 9/1/2010 11:40 AM, Aahz wrote: >>> I think that any implementation >>> that doesn't have O(1) for list element access is fundamentally broken, >> >> Whereas I think that that claim is fundamentally broken in multiple ways. >> >>> and we should probably document that somewhere. >> >> I agree that *current* algorithmic behavior of parts of CPython on >> typical *current* hardware should be documented not just 'somewhere' >> (which I understand it is, in the Wiki) but in a CPython doc included >> in the doc set distributed with each release. >> >> Perhaps someone or some group could write a HowTo on Programming with >> CPython's Builtin Classes that would describe both the implementation >> and performance and also the implications for coding style. In >> particular, it could compare CPython's array lists and tuples to >> singly linked lists (which are easily created in Python also). >> >> But such a document, after stating that array access may be thought of >> as constant time on current hardware to a useful first approximation, >> should also state that repeated seqeuntial accessess may be *much* >> faster than repeated random accessess. People in the high-performance >> computing community are quite aware of this difference between >> simplified lies and messy truth. Because of this, array algorithms are >> (should be) written differently in Fortran and C because Fortran >> stores arrays by columns and C by rows and because it is usually much >> faster to access the next item than one far away. > > I don't understand what you're trying to say. Aahz didn't claim that > random list element access was constant time, he said it was O(1) (and > that it should be part of the Python spec that it is). Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, 2nd edition. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From pauljefferson at gmail.com Wed Sep 1 17:52:43 2010 From: pauljefferson at gmail.com (Paul Jefferson) Date: Wed, 1 Sep 2010 22:52:43 +0100 Subject: Email Previews Message-ID: Hello, I'm currently trying to write a quick script that takes email message objects and generates quick snippet previews (like the iPhone does when you are in the menu) but I'm struggling. I was just wondering before I started to put a lot of work in this if there were any existing scripts out there that did it, as it seems a bit pointless spending a lot of time reinventing the wheel if something already exists. Thanks for your help, Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Wed Sep 1 18:30:06 2010 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 01 Sep 2010 15:30:06 -0700 Subject: what is this kind of string: b'string' ? In-Reply-To: <4C7EC689.6040508@gmail.com> References: <4C7EC689.6040508@gmail.com> Message-ID: <4C7ED3EE.4050908@islandtraining.com> On 09/01/2010 02:32 PM, Stef Mientki wrote: > in winpdb I see strings like this: > > >>>> a = b'string' >>>> a >>>> > 'string' > >>>> type(a) >>>> > > > what's the "b" doing in front of the string ? > > thanks, > Stef Mientki > In Python2 the b is meaningless (but allowed for compatibility and future-proofing purposes), while in Python 3 it creates a byte array (or byte string or technically an object of type bytes) rather than a string (of unicode). Python2 >>> type(b'abc') >>> type('abc') Python3: >>> type(b'abc') >>> type('abc') From robert.kern at gmail.com Wed Sep 1 18:30:31 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 01 Sep 2010 17:30:31 -0500 Subject: Performance: sets vs dicts. In-Reply-To: <87iq2pcfbo.fsf@castleamber.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> Message-ID: On 9/1/10 4:40 PM, John Bokma wrote: > Arnaud Delobelle writes: > >> Terry Reedy writes: >>> But such a document, after stating that array access may be thought of >>> as constant time on current hardware to a useful first approximation, >>> should also state that repeated seqeuntial accessess may be *much* >>> faster than repeated random accessess. People in the high-performance >>> computing community are quite aware of this difference between >>> simplified lies and messy truth. Because of this, array algorithms are >>> (should be) written differently in Fortran and C because Fortran >>> stores arrays by columns and C by rows and because it is usually much >>> faster to access the next item than one far away. >> >> I don't understand what you're trying to say. Aahz didn't claim that >> random list element access was constant time, he said it was O(1) (and >> that it should be part of the Python spec that it is). > > Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, > 2nd edition. While we often use the term "constant time" to as a synonym for O(1) complexity of an algorithm, Arnaud and Terry are using the term here to mean "an implementation takes roughly the same amount of wall-clock time every time". -- 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 at rcn.com Wed Sep 1 18:51:33 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 1 Sep 2010 15:51:33 -0700 (PDT) Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> Message-ID: <7a38148b-79e9-40ce-9700-2c0d1c9b3ee4@a4g2000prm.googlegroups.com> On Aug 30, 6:03?am, a... at pythoncraft.com (Aahz) wrote: > That reminds me: one co-worker (who really should have known better ;-) > had the impression that sets were O(N) rather than O(1). ?Although > writing that off as a brain-fart seems appropriate, it's also the case > that the docs don't really make that clear, it's implied from requiring > elements to be hashable. ?Do you agree that there should be a comment? There probably ought to be a HOWTO or FAQ entry on algorithmic complexity that covers classes and functions where the algorithms are interesting. That will concentrate the knowledge in one place where performance is a main theme and where the various alternatives can be compared and contrasted. I think most users of sets rarely read the docs for sets. The few lines in the tutorial are enough so that most folks "just get it" and don't read more detail unless they attempting something exotic. Our docs have gotten somewhat voluminous, so it's unlikely that adding that particular needle to the haystack would have cured your colleague's "brain-fart" unless he had been focused on a single document talking about the performance characteristics of various data structures. Raymond Raymond From tjreedy at udel.edu Wed Sep 1 19:24:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Sep 2010 19:24:40 -0400 Subject: Performance: sets vs dicts. In-Reply-To: <87iq2pcfbo.fsf@castleamber.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> Message-ID: On 9/1/2010 5:40 PM, John Bokma wrote: > Arnaud Delobelle writes: > >> Terry Reedy writes: >> >>> On 9/1/2010 11:40 AM, Aahz wrote: >>>> I think that any implementation >>>> that doesn't have O(1) for list element access is fundamentally broken, >>> >>> Whereas I think that that claim is fundamentally broken in multiple ways. >>> >>>> and we should probably document that somewhere. >>> >>> I agree that *current* algorithmic behavior of parts of CPython on >>> typical *current* hardware should be documented not just 'somewhere' >>> (which I understand it is, in the Wiki) but in a CPython doc included >>> in the doc set distributed with each release. >>> >>> Perhaps someone or some group could write a HowTo on Programming with >>> CPython's Builtin Classes that would describe both the implementation >>> and performance and also the implications for coding style. In >>> particular, it could compare CPython's array lists and tuples to >>> singly linked lists (which are easily created in Python also). >>> >>> But such a document, after stating that array access may be thought of >>> as constant time on current hardware to a useful first approximation, >>> should also state that repeated seqeuntial accessess may be *much* >>> faster than repeated random accessess. People in the high-performance >>> computing community are quite aware of this difference between >>> simplified lies and messy truth. Because of this, array algorithms are >>> (should be) written differently in Fortran and C because Fortran >>> stores arrays by columns and C by rows and because it is usually much >>> faster to access the next item than one far away. >> >> I don't understand what you're trying to say. Most generally, that I view Python as an general algorithm language and not just as a VonNeuman machine programming language. More specifically, that O() claims can be inapplicable, confusing, misleading, incomplete, or false, especially when applied to real time and to real systems with finite limits. >> Aahz didn't claim that random list element access was constant time, >> he said it was O(1) (and >> that it should be part of the Python spec that it is). Yes, I switched, because 'constant time' is a comprehensible claim that can be refuted and because that is how some will interpret O(1) (see below for proof;-). If one takes O(1) to mean bounded, which I believe is the usual technical meaning, then all Python built-in sequence operations take bounded time because of the hard size limit. If sequences were not bounded in length, then access time would not be bounded either. My most specific point is that O(1), interpreted as more-or-less constant time across a range of problem sizes, can be either a virute or vice depending on whether the constancy is a result of speeding up large problems or slowing down small problems. I furthermore contend that Python sequences on current hardware exhibit both virtue and vice and that is would be absurd to reject a system that kept the virtue without the vice and that such absurdity should not be built into the language definition. My fourth point is that we can meet the reasonable goal of helping some people make better use of current Python/CPython on current hardware without big-O controversy and without screwing around with the language definition and locking out the future. > Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, > 2nd edition. -- Terry Jan Reedy From pmcnameeking at gmail.com Wed Sep 1 19:35:45 2010 From: pmcnameeking at gmail.com (patrick mcnameeking) Date: Wed, 1 Sep 2010 19:35:45 -0400 Subject: importing excel data into a python matrix? Message-ID: Hello list, I've been working with Python now for about a year using it primarily for scripting in the Puredata graphical programming environment. I'm working on a project where I have been given a 1000 by 1000 cell excel spreadsheet and I would like to be able to access the data using Python. Does anyone know of a way that I can do this? Thanks, Pat -- 'Given enough eyeballs, all bugs are shallow.' -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Wed Sep 1 19:43:02 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 1 Sep 2010 16:43:02 -0700 Subject: importing excel data into a python matrix? In-Reply-To: References: Message-ID: On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking wrote: > Hello list, > I've been working with Python now for about a year using it primarily for > scripting in the Puredata graphical programming environment. ?I'm working on > a project where I have been given a 1000 by 1000 cell excel spreadsheet and > I would like to be able to access the data using Python. ?Does anyone know > of a way that I can do this? > Thanks, > Pat http://tinyurl.com/2eqqjxv ;) Geremy Condra From clp2 at rebertia.com Wed Sep 1 19:45:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Sep 2010 16:45:39 -0700 Subject: importing excel data into a python matrix? In-Reply-To: References: Message-ID: On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking wrote: > Hello list, > I've been working with Python now for about a year using it primarily for > scripting in the Puredata graphical programming environment. ?I'm working on > a project where I have been given a 1000 by 1000 cell excel spreadsheet and > I would like to be able to access the data using Python. ?Does anyone know > of a way that I can do this? "xlrd 0.7.1 - Library for developers to extract data from Microsoft Excel (tm) spreadsheet files": http://pypi.python.org/pypi/xlrd If requiring the user to re-save the file as .CSV instead of .XLS is feasible, then you /can/ avoid the third-party dependency and use just the std lib instead: http://docs.python.org/library/csv.html Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Wed Sep 1 20:04:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Sep 2010 17:04:01 -0700 Subject: DeprecationWarning In-Reply-To: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> References: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Message-ID: On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: > Hi There, > > I would like to create an scp handle and download a file from a > client. I have following code: > but what i'm getting is this and no file is downloaded...: > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: > BaseException.message has been deprecated as of Python 2.6 > ?chan.send('\x01'+e.message) > 09/01/2010 08:53:56 : Downloading P-file failed. > > What does that mean and how do i resolve this? http://stackoverflow.com/questions/1272138/baseexception-message-deprecated-in-python-2-6 As the warning message says, line 243 of /opt/lampp/cgi-bin/attachment.py is the cause of the warning. However, that's only a warning (albeit probably about a small part of some error-raising code), not an error itself, so it's not the cause of the download failure. Printing out the IOError encountered would be the first step in debugging the download failure. Cheers, Chris -- http://blog.rebertia.com From john at castleamber.com Wed Sep 1 20:11:03 2010 From: john at castleamber.com (John Bokma) Date: Wed, 01 Sep 2010 19:11:03 -0500 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> Message-ID: <87aao1c8dk.fsf@castleamber.com> Terry Reedy writes: > On 9/1/2010 5:40 PM, John Bokma wrote: [..] > Yes, I switched, because 'constant time' is a comprehensible claim > that can be refuted and because that is how some will interpret O(1) > (see below for proof;-). You make it now sound alsof this interpretation is not correct or out of place. People who have bothered to read ItA will use O(1) and constant time interchangeably while talking of the order of growth of the running time algorithms and most of those are aware that 'big oh' hides a constant, and that in the real world a O(log n) algorithm can outperform an O(1) algorithm for small values of n. >> Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, >> 2nd edition. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Wed Sep 1 20:13:43 2010 From: john at castleamber.com (John Bokma) Date: Wed, 01 Sep 2010 19:13:43 -0500 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> Message-ID: <8762ypc894.fsf@castleamber.com> Robert Kern writes: > On 9/1/10 4:40 PM, John Bokma wrote: >> Arnaud Delobelle writes: >> >>> Terry Reedy writes: [...] >>> I don't understand what you're trying to say. Aahz didn't claim that >>> random list element access was constant time, he said it was O(1) (and >>> that it should be part of the Python spec that it is). >> >> Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, >> 2nd edition. > > While we often use the term "constant time" to as a synonym for O(1) > complexity of an algorithm, Arnaud and Terry are using the term here > to mean "an implementation takes roughly the same amount of wall-clock > time every time". Now that's confusing in a discussion that earlier on provided a link to a page using big O notation. At least for people following this partially, like I do. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From nkaunda at yahoo.com Wed Sep 1 20:50:40 2010 From: nkaunda at yahoo.com (Nally Kaunda-Bukenya) Date: Wed, 1 Sep 2010 17:50:40 -0700 (PDT) Subject: Python-list Digest, Vol 84, Issue 8 In-Reply-To: References: Message-ID: <363316.54542.qm@web33502.mail.mud.yahoo.com> Dear Peter, that did wonders!!?thanks so much for the code fix; I will check back with you later for the meaning of some functions you used. Many thanks?to all those good people who gave me pointers: Rami, Mathew, Bob,?? Best wishes for now:) ________________________________ From: "python-list-request at python.org" To: python-list at python.org Sent: Wed, September 1, 2010 11:52:02 AM Subject: Python-list Digest, Vol 84, Issue 8 Note: Forwarded message is attached. 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. DeprecationWarning (cerr) ? 2. Re: Performance: sets vs dicts. (Stefan Behnel) ? 3. Better multiprocessing and data persistance with C level ? ? ? serialisation (ipatrol6010 at yahoo.com) ? 4. Re: Dumb Stupid Question About List and String (Xavier Ho) ? 5. Re: Dumb Stupid Question About List and String (Alban Nona) ? 6. Re: Dumb Stupid Question About List and String (Alban Nona) ? 7. Re: Newby Needs Help with Python code (Peter Otten) -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ipatrol6010 at yahoo.com Wed Sep 1 20:59:50 2010 From: ipatrol6010 at yahoo.com (ipatrol6010 at yahoo.com) Date: Wed, 1 Sep 2010 20:59:50 -0400 Subject: Python libs on Windows ME Message-ID: <3A147D09-4B7E-41F3-A669-D20EA00D6489@yahoo.com> Damn Small Linux could work. If even that won't work, perhaps it's time to scrap your old fossil for parts and buy a modern computer. Even a netbook would probably be an improvement based on your situation. From dchichkov at gmail.com Wed Sep 1 21:08:25 2010 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Wed, 1 Sep 2010 18:08:25 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) Message-ID: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Given: a large list (10,000,000) of floating point numbers; Task: fastest python code that finds k (small, e.g. 10) smallest items, preferably with item indexes; Limitations: in python, using only standard libraries (numpy & scipy is Ok); I've tried several methods. With N = 10,000,000, K = 10 The fastest so far (without item indexes) was pure python implementation nsmallest_slott_bisect (using bisect/insert). And with indexes nargsmallest_numpy_argmin (argmin() in the numpy array k times). Anyone up to the challenge beating my code with some clever selection algorithm? Current Table: 1.66864395142 mins_heapq(items, n): 0.946580886841 nsmallest_slott_bisect(items, n): 1.38014793396 nargsmallest(items, n): 10.0732769966 sorted(items)[:n]: 3.17916202545 nargsmallest_numpy_argsort(items, n): 1.31794500351 nargsmallest_numpy_argmin(items, n): 2.37499308586 nargsmallest_numpy_array_argsort(items, n): 0.524670124054 nargsmallest_numpy_array_argmin(items, n): 0.0525538921356 numpy argmin(items): 1892997 0.364673852921 min(items): 10.0000026786 Code: ---------------- import heapq from random import randint, random import time from bisect import insort from itertools import islice from operator import itemgetter def mins_heapq(items, n): nlesser_items = heapq.nsmallest(n, items) return nlesser_items def nsmallest_slott_bisect(iterable, n, insort=insort): it = iter(iterable) mins = sorted(islice(it, n)) for el in it: if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates insort(mins, el) mins.pop() return mins def nargsmallest(iterable, n, insort=insort): it = enumerate(iterable) mins = sorted(islice(it, n), key = itemgetter(1)) loser = mins[-1][1] # largest of smallest for el in it: if el[1] <= loser: # NOTE: equal sign is to preserve dupl mins.append(el) mins.sort(key = itemgetter(1)) mins.pop() loser = mins[-1][1] return mins def nargsmallest_numpy_argsort(iter, k): distances = N.asarray(iter) return [(i, distances[i]) for i in distances.argsort()[0:k]] def nargsmallest_numpy_array_argsort(array, k): return [(i, array[i]) for i in array.argsort()[0:k]] def nargsmallest_numpy_argmin(iter, k): distances = N.asarray(iter) mins = [] def nargsmallest_numpy_array_argmin(distances, k): mins = [] for i in xrange(k): j = distances.argmin() mins.append((j, distances[j])) distances[j] = float('inf') return mins test_data = [randint(10, 50) + random() for i in range(10000000)] K = 10 init = time.time() mins = mins_heapq(test_data, K) print time.time() - init, 'mins_heapq(items, n):', mins[:2] init = time.time() mins = nsmallest_slott_bisect(test_data, K) print time.time() - init, 'nsmallest_slott_bisect(items, n):', mins[: 2] init = time.time() mins = nargsmallest(test_data, K) print time.time() - init, 'nargsmallest(items, n):', mins[:2] init = time.time() mins = sorted(test_data)[:K] print time.time() - init, 'sorted(items)[:n]:', time.time() - init, mins[:2] import numpy as N init = time.time() mins = nargsmallest_numpy_argsort(test_data, K) print time.time() - init, 'nargsmallest_numpy_argsort(items, n):', mins[:2] init = time.time() mins = nargsmallest_numpy_argmin(test_data, K) print time.time() - init, 'nargsmallest_numpy_argmin(items, n):', mins[:2] print init = time.time() mins = array.argmin() print time.time() - init, 'numpy argmin(items):', mins init = time.time() mins = min(test_data) print time.time() - init, 'min(items):', mins From rasjidw at gmail.com Wed Sep 1 21:10:04 2010 From: rasjidw at gmail.com (Rasjid Wilcox) Date: Thu, 2 Sep 2010 11:10:04 +1000 Subject: Private variables Message-ID: Hi all, I am aware the private variables are generally done via convention (leading underscore), but I came across a technique in Douglas Crockford's book "Javascript: The Good Parts" for creating private variables in Javascript, and I'd thought I'd see how it translated to Python. Here is my attempt. def get_config(_cache=[]): private = {} private['a'] = 1 private['b'] = 2 if not _cache: class Config(object): @property def a(self): return private['a'] @property def b(self): return private['b'] config = Config() _cache.append(config) else: config = _cache[0] return config >>> c = get_config() >>> c.a 1 >>> c.b 2 >>> c.a = 10 Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute >>> dir(c) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b'] >>> d = get_config() >>> d is c True I'm not really asking 'is it a good idea' but just 'does this work'? It seems to work to me, and is certainly 'good enough' in the sense that it should be impossible to accidentally change the variables of c. But is it possible to change the value of c.a or c.b with standard python, without resorting to ctypes level manipulation? Cheers, Rasjid. From benjamin at python.org Wed Sep 1 21:49:40 2010 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 2 Sep 2010 01:49:40 +0000 (UTC) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Message-ID: sarvi gmail.com> writes: > > > Is there a plan to adopt PyPy and RPython under the python foundation > in attempt to standardize both. There is not. > > Secondly I have always fantasized of never having to write C code yet > get its compiled performance. > With RPython(a strict subset of Python), I can actually compile it to > C/Machine code RPython is not supposed to be a general purpose language. As a PyPy developer myself, I can testify that it is no fun. > > Yet I see this forum relatively quite on PyPy or Rpython ? Any > reasons??? You should post to the PyPy list instead. (See pypy.org) From ryan at rfk.id.au Wed Sep 1 22:06:52 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 02 Sep 2010 12:06:52 +1000 Subject: Private variables In-Reply-To: References: Message-ID: <1283393212.2136.4.camel@durian> On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: > Hi all, > > I am aware the private variables are generally done via convention > (leading underscore), but I came across a technique in Douglas > Crockford's book "Javascript: The Good Parts" for creating private > variables in Javascript, and I'd thought I'd see how it translated to > Python. Here is my attempt. > > def get_config(_cache=[]): > private = {} > private['a'] = 1 > private['b'] = 2 > if not _cache: > class Config(object): > @property > def a(self): > return private['a'] > @property > def b(self): > return private['b'] > config = Config() > _cache.append(config) > else: > config = _cache[0] > return config > > >>> c = get_config() > >>> c.a > 1 > >>> c.b > 2 > >>> c.a = 10 > Traceback (most recent call last): > File "", line 1, in > AttributeError: can't set attribute > >>> dir(c) > ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', > '__getattribute__', '__hash__', '__init__', '__module__', '__new__', > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', > '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b'] > >>> d = get_config() > >>> d is c > True > > I'm not really asking 'is it a good idea' but just 'does this work'? > It seems to work to me, and is certainly 'good enough' in the sense > that it should be impossible to accidentally change the variables of > c. > > But is it possible to change the value of c.a or c.b with standard > python, without resorting to ctypes level manipulation? It's not easy, but it can be done by introspecting the property object you created and munging the closed-over dictionary object: >>> c = get_config() >>> c.a 1 >>> c.__class__.__dict__['a'].fget.func_closure[0].cell_contents['a'] = 7 >>> c.a 7 >>> Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ryan at rfk.id.au Wed Sep 1 22:22:21 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 02 Sep 2010 12:22:21 +1000 Subject: Private variables In-Reply-To: <1283393212.2136.4.camel@durian> References: <1283393212.2136.4.camel@durian> Message-ID: <1283394141.2136.5.camel@durian> On Thu, 2010-09-02 at 12:06 +1000, Ryan Kelly wrote: > On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: > > Hi all, > > > > I am aware the private variables are generally done via convention > > (leading underscore), but I came across a technique in Douglas > > Crockford's book "Javascript: The Good Parts" for creating private > > variables in Javascript, and I'd thought I'd see how it translated to > > Python. Here is my attempt. > > > > def get_config(_cache=[]): > > private = {} > > private['a'] = 1 > > private['b'] = 2 > > if not _cache: > > class Config(object): > > @property > > def a(self): > > return private['a'] > > @property > > def b(self): > > return private['b'] > > config = Config() > > _cache.append(config) > > else: > > config = _cache[0] > > return config > > > > >>> c = get_config() > > >>> c.a > > 1 > > >>> c.b > > 2 > > >>> c.a = 10 > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: can't set attribute > > >>> dir(c) > > ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', > > '__getattribute__', '__hash__', '__init__', '__module__', '__new__', > > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', > > '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b'] > > >>> d = get_config() > > >>> d is c > > True > > > > I'm not really asking 'is it a good idea' but just 'does this work'? > > It seems to work to me, and is certainly 'good enough' in the sense > > that it should be impossible to accidentally change the variables of > > c. > > > > But is it possible to change the value of c.a or c.b with standard > > python, without resorting to ctypes level manipulation? > > It's not easy, but it can be done by introspecting the property object > you created and munging the closed-over dictionary object: > > >>> c = get_config() > >>> c.a > 1 > >>> c.__class__.__dict__['a'].fget.func_closure[0].cell_contents['a'] = 7 > >>> c.a > 7 > >>> Heh, and of course I miss the even more obvious trick of just clobbering the property with something else: >>> c.a 1 >>> setattr(c.__class__,"a",7) >>> c.a 7 >>> Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From nikos.the.gr33k at gmail.com Wed Sep 1 22:30:30 2010 From: nikos.the.gr33k at gmail.com (Nik the Greek) Date: Wed, 1 Sep 2010 19:30:30 -0700 (PDT) Subject: Problem checking an existing browser cookie References: <14868a50-f20d-49bb-8ed6-2c290619d2af@a36g2000yqc.googlegroups.com> <8fe0540e-1818-4891-b165-f6731e918e6d@v41g2000yqv.googlegroups.com> <3ff780f9-1b6e-45ef-a530-0726eacb6064@g17g2000yqe.googlegroups.com> <809138c7-4ec3-404e-8863-dddb214c4100@s15g2000yqm.googlegroups.com> Message-ID: <5e88e97d-8d9b-4215-bad8-49d202522442@z7g2000yqg.googlegroups.com> On 31 ???, 11:07, Nik the Greek wrote: > On 30 ???, 20:50, MRAB wrote: > > > > > > > > > > > On 30/08/2010 18:16, Nik the Greek wrote: > > > > On 30 ???, 19:41, MRAB ?wrote: > > >> On 30/08/2010 04:33, Nik the Greek wrote: > > > >>> On 30 ???, 06:12, MRAB ? ?wrote: > > > >>>> This part: > > > >>>> ? ? ? ?( not mycookie or mycookie.value != 'nikos' ) > > > >>>> is false but this part: > > > >>>> ? ? ? ?re.search( r'(msn|yandex|13448|spider|crawl)', host ) is None > > > >>>> is true because host doesn't contain any of those substrings. > > > >>> So, the if code does executed because one of the condition is true? > > > >>> How should i write it? > > > >>> I cannot think clearly on this at all. > > > >>> I just wan to tell it to get executed ?ONLY IF > > > >>> the cookie values is not 'nikos' > > > >>> or ( don't knwo if i have to use and or 'or' here) > > > >>> host does not contain any of the substrings. > > > >>> What am i doign wrong?! > > > >> It might be clearer if you reverse the condition and say: > > > >> ? ? ? me_visiting = ... > > >> ? ? ? if not me_visiting: > > >> ? ? ? ? ? ... > > > > I don't understand what are you trying to say > > > > Please provide a full example. > > > > You mean i should try it like this? > > > > unless ( visitor and visitor.value == 'nikos' ) or re.search( r'(msn| > > > yandex|13448|spider|crawl)', host ) not None: > > > > But isnt it the same thing like the if? > > > My point is that the logic might be clearer to you if you think first > > about how you know when you _are_ the visitor. > > Well my idea was to set a cookie on my browser with the name visitor > and a value of "nikos" and then check each time that cooki. if value > is "nikos" then dont count! > > I could also pass an extra url string likehttp://webville.gr?show=nikos > and check that but i dont like the idea very much of giving an extra > string each time i want to visit my webpage. > So form the 2 solution mentioned the 1st one is better but cant come > into action for some reason. > > Aprt form those too solution i cant think of anyhting else that would > identify me and filter me out of the actual guest of my website. > > I'm all ears if you can think of something else. Is there any other way for the webpage to identify me and filter me out except checking a cookie or attach an extra url string to the address bar? From wuwei23 at gmail.com Wed Sep 1 22:47:10 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 1 Sep 2010 19:47:10 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Message-ID: On Sep 2, 3:49?am, sarvi wrote: > Yet I see this forum relatively quite on PyPy or Rpython ? ?Any > reasons??? For me, it's two major ones: 1. PyPy only recently hit a stability/performance point that makes it worth checking out, 2. Using non-pure-python modules wasn't straightforward (at least when I last looked) However, I've always felt the PyPy project was far more promising than Unladen Swallow. From rurpy at yahoo.com Wed Sep 1 22:57:16 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Wed, 1 Sep 2010 19:57:16 -0700 (PDT) Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <7a38148b-79e9-40ce-9700-2c0d1c9b3ee4@a4g2000prm.googlegroups.com> Message-ID: <4a3665a0-fc7f-425a-878e-6f8dcc5ed319@y11g2000yqm.googlegroups.com> On 09/01/2010 04:51 PM, Raymond Hettinger wrote: > On Aug 30, 6:03 am, a... at pythoncraft.com (Aahz) wrote: >> That reminds me: one co-worker (who really should have known better ;-) >> had the impression that sets were O(N) rather than O(1). Although >> writing that off as a brain-fart seems appropriate, it's also the case >> that the docs don't really make that clear, it's implied from requiring >> elements to be hashable. Do you agree that there should be a comment? > > There probably ought to be a HOWTO or FAQ entry on algorithmic > complexity > that covers classes and functions where the algorithms are > interesting. > That will concentrate the knowledge in one place where performance is > a > main theme and where the various alternatives can be compared and > contrasted. > I think most users of sets rarely read the docs for sets. The few lines > in the tutorial are enough so that most folks "just get it" and don't read > more detail unless they attempting something exotic. I think that attitude is very dangerous. There is a long history in this world of one group of people presuming what another group of people does or does not do or think. This seems to be a characteristic of human beings and is often used to promote one's own ideology. And even if you have hard evidence for what you say, why should 60% of people who don't read docs justify providing poor quality docs to the 40% that do? So while you may "think" most people rarely read the docs for basic language features and objects (I presume you don't mean to restrict your statement to only sets), I and most people I know *do* read them. And when read them I expect them, as any good reference documentation does, to completely and accurately describe the behavior of the item I am reading about. If big-O performance is deemed an intrinsic behavior of an (operation of) an object, it should be described in the documentation for that object. Your use of the word "exotic" is also suspect. I learned long ago to always click the "advanced options" box on dialogs because most developers/- designers really don't have a clue about what users need access to. > Our docs have gotten > somewhat voluminous, No they haven't (relative to what they attempt to describe). The biggest problem with the docs is that they are too terse. They often appear to have been written by people playing a game of "who can describe X in the minimum number of words that can still be defended as correct." While that may be fun, good docs are produced by considering how to describe something to the reader, completely and accurately, as effectively as possible. The test is not how few words were used, but how quickly the reader can understand the object or find the information being sought about the object. > so it's unlikely that adding that particular > needle to the haystack would have cured your colleague's "brain-fart" > unless he had been focused on a single document talking about the > performance > characteristics of various data structures. I don't know the colleague any more that you so I feel comfortable saying that having it very likely *would* have cured that brain-fart. That is, he or she very likely would have needed to check some behavior of sets at some point and would have either noted the big-O characteristics in passing, or would have noted that such information was available, and would have returned to the documentation when the need for that information arose. The reference description of sets is the *one* canonical place to look for information about sets. There are people who don't read documentation, but one has to be very careful not use the existence of such people as an excuse to justify sub-standard documentation. So I think relegating algorithmic complexity information to some remote document far from the description of the object it pertains to, is exactly the wrong approach. This is not to say that a performance HOWTO or FAQ in addition to the reference manual would not be good. From astan.chee at al.com.au Wed Sep 1 23:12:07 2010 From: astan.chee at al.com.au (Astan Chee) Date: Thu, 2 Sep 2010 13:12:07 +1000 Subject: killing all subprocess childrens Message-ID: <4C7F1607.8040308@al.com.au> Hi, I have a piece of code that looks like this: import subprocess retcode = subprocess.call(["java","test","string"]) print "Exited with retcode " + str(retcode) What I'm trying to do (and wondering if its possible) is to make sure that any children (and any descendants) of this process is killed when the main java process is killed (or dies). How do I do this in windows, linux and OSX? Thanks Astan From clp2 at rebertia.com Wed Sep 1 23:24:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Sep 2010 20:24:02 -0700 Subject: killing all subprocess childrens In-Reply-To: <4C7F1607.8040308@al.com.au> References: <4C7F1607.8040308@al.com.au> Message-ID: On Wed, Sep 1, 2010 at 8:12 PM, Astan Chee wrote: > Hi, > I have a piece of code that looks like this: > > import subprocess > retcode = subprocess.call(["java","test","string"]) > print "Exited with retcode " + str(retcode) > > What I'm trying to do (and wondering if its possible) is to make sure that > any children (and any descendants) of this process is killed when the main > java process is killed (or dies). > How do I do this in windows, linux and OSX? Something /roughly/ like: import os import psutil # http://code.google.com/p/psutil/ # your piece of code goes here myself = os.getpid() for proc in psutil.process_iter(): if proc.ppid == myself: proc.kill() Cheers, Chris -- http://blog.rebertia.com From astan.chee at al.com.au Wed Sep 1 23:30:40 2010 From: astan.chee at al.com.au (Astan Chee) Date: Thu, 2 Sep 2010 13:30:40 +1000 Subject: killing all subprocess childrens In-Reply-To: References: <4C7F1607.8040308@al.com.au> Message-ID: <4C7F1A60.6080000@al.com.au> Chris Rebert wrote: > import os > import psutil # http://code.google.com/p/psutil/ > > # your piece of code goes here > > myself = os.getpid() > for proc in psutil.process_iter(): > Is there a way to do this without psutil or installing any external modules or doing it from python2.5? Just wondering. Thanks again > if proc.ppid == myself: > proc.kill() > > Cheers, > Chris > -- > http://blog.rebertia.com > From rasjidw at gmail.com Wed Sep 1 23:59:44 2010 From: rasjidw at gmail.com (Rasjid Wilcox) Date: Thu, 2 Sep 2010 13:59:44 +1000 Subject: Private variables In-Reply-To: <1283394141.2136.5.camel@durian> References: <1283393212.2136.4.camel@durian> <1283394141.2136.5.camel@durian> Message-ID: On 2 September 2010 12:22, Ryan Kelly wrote: > On Thu, 2010-09-02 at 12:06 +1000, Ryan Kelly wrote: >> On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: >> > Hi all, >> > >> > I am aware the private variables are generally done via convention >> > (leading underscore), but I came across a technique in Douglas >> > Crockford's book "Javascript: The Good Parts" for creating private >> > variables in Javascript, and I'd thought I'd see how it translated to >> > Python. Here is my attempt. >> > >> > def get_config(_cache=[]): >> > ? ? private = {} >> > ? ? private['a'] = 1 >> > ? ? private['b'] = 2 >> > ? ? if not _cache: >> > ? ? ? ? class Config(object): >> > ? ? ? ? ? ? @property >> > ? ? ? ? ? ? def a(self): >> > ? ? ? ? ? ? ? ? return private['a'] >> > ? ? ? ? ? ? @property >> > ? ? ? ? ? ? def b(self): >> > ? ? ? ? ? ? ? ? return private['b'] >> > ? ? ? ? config = Config() >> > ? ? ? ? _cache.append(config) >> > ? ? else: >> > ? ? ? ? config = _cache[0] >> > ? ? return config >> > >> > >>> c = get_config() >> > >>> c.a >> > 1 >> > >>> c.b >> > 2 >> > >>> c.a = 10 >> > Traceback (most recent call last): >> > ? File "", line 1, in >> > AttributeError: can't set attribute >> > >>> dir(c) >> > ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', >> > '__getattribute__', '__hash__', '__init__', '__module__', '__new__', >> > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', >> > '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'b'] >> > >>> d = get_config() >> > >>> d is c >> > True >> > >> > I'm not really asking 'is it a good idea' but just 'does this work'? >> > It seems to work to me, and is certainly 'good enough' in the sense >> > that it should be impossible to accidentally change the variables of >> > c. >> > >> > But is it possible to change the value of c.a or c.b with standard >> > python, without resorting to ctypes level manipulation? >> >> It's not easy, but it can be done by introspecting the property object >> you created and munging the closed-over dictionary object: >> >> ? ?>>> c = get_config() >> ? ?>>> c.a >> ? ?1 >> ? ?>>> c.__class__.__dict__['a'].fget.func_closure[0].cell_contents['a'] = 7 >> ? ?>>> c.a >> ? ?7 Ah! That is what I was looking for. > Heh, and of course I miss the even more obvious trick of just clobbering > the property with something else: > > >>> c.a > 1 > >>> setattr(c.__class__,"a",7) > >>> c.a > 7 Well, that is just cheating! :-) Anyway, thanks for that. I still think it is 'good enough' for those cases where private variables are 'required'. In both cases one has to go out of ones way to modify the attribute. OTOH, I guess it depends on what the use case is. If it is for storing a secret password that no other part of the system should have access to, then perhaps not 'good enough' at all. Cheers, Rasjid. From sarvilive at gmail.com Thu Sep 2 01:06:38 2010 From: sarvilive at gmail.com (sarvi) Date: Wed, 1 Sep 2010 22:06:38 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Message-ID: <3a854a6c-648b-43c6-b7f4-e7b0d849274b@x18g2000pro.googlegroups.com> On Sep 1, 6:49?pm, Benjamin Peterson wrote: > sarvi gmail.com> writes: > > Secondly I have always fantasized of never having to write C code yet > > get its compiled performance. > > With RPython(a strict subset of Python), I can actually compile it to > > C/Machine code > > RPython is not supposed to be a general purpose language. As a PyPy developer > myself, I can testify that it is no fun. Can be worse than than writing C/C++ Compared to Java, having the interpreter during development is huge I actually think yall at PyPy are hugely underestimating RPython. http://olliwang.com/2009/12/20/aes-implementation-in-rpython/ http://alexgaynor.net/2010/may/15/pypy-future-python/ Look at all the alternatives we have. Cython? Shedskin? I'll take PyPy anyday instead of them We make performance tradeoffs all the the time. Look at Mercurial. 90% python and 5% C Wouldn't you rather this be 90% Python and 5% RPython ??? Add to the possibility of writing Python extension module in RPython. You could be winning a whole group of developer mindshare. > > > > > Yet I see this forum relatively quite on PyPy or Rpython ? ?Any > > reasons??? > > You should post to the PyPy list instead. (See pypy.org) I tried. got bounced. Just subscribed. Will try again. Sarvi From wuwei23 at gmail.com Thu Sep 2 01:32:05 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 1 Sep 2010 22:32:05 -0700 (PDT) Subject: dirty problem 3 lines References: <4C7DC74D.6060702@mrabarnett.plus.com> Message-ID: <928816d6-e72f-4faf-882b-756fd185ce4c@w15g2000pro.googlegroups.com> bussiere bussiere wrote: > it's just as it seems : > i want to know how does ti works to get back an object from a string in python : > pickle.loads("""b'\x80\x03]q\x00(K\x00K\x01e.'""") #doesn't work Repeating the question without providing any further information doesn't really help. This is a byte string: b'\x80\x03]q\x00(K\x00K\x01e.' As MRAB points out, you can unpickle a byte string directly. This is a doc string: """note the triplet of double quotes""" What you have is a doc string that appears to contain a byte string: """b'\x80\x03]q\x00(K\x00K\x01e.'""" So the question for you is: what is putting the byte string inside of a doc string? If you can stop that from happening, then you'll have a byte string you can directly unpickle. Now, if you _don't_ have control over whatever is handing you the dump string, then you can just use string manipulation to reproduce the byte string: >>> dump = """b'\x80\x03]q\x00(K\x00K\x01e.'""" >>> badump = dump[2:-1].encode()[1:] >>> pickle.loads(badump) [0, 1] So: - dump[2:-1] strips off string representation of the byte string (b'...') - .encode() turns it into an actual byte string - [1:] strips a unicode blank from the start of the byte string (not entirely sure how that gets there...) After that it should be fine to unpickle. From nagle at animats.com Thu Sep 2 02:08:05 2010 From: nagle at animats.com (John Nagle) Date: Wed, 01 Sep 2010 23:08:05 -0700 Subject: Queue cleanup In-Reply-To: <7xmxs436qe.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <4c78f210$0$28655$c3e8da3@news.astraweb.com> <7xd3t0orah.fsf@ruckus.brouhaha.com> <4c7b279d$0$28650$c3e8da3@news.astraweb.com> <7xmxs436qe.fsf@ruckus.brouhaha.com> Message-ID: <4c7f3f43$0$1624$742ec2ed@news.sonic.net> On 8/30/2010 12:22 AM, Paul Rubin wrote: > I guess that is how the so-called smart pointers in the Boost C++ > template library work. I haven't used them so I don't have personal > experience with how convenient or reliable they are, or what kinds of > constraints they imposed on programming style. I've always felt a bit > suspicious of them though, and I seem to remember Alex Martelli (I hope > he shows up here again someday) advising against using them. "Smart pointers" in C++ have never quite worked right. They almost work. But there always seems to be something that needs access to a raw C pointer, which breaks the abstraction. The mold keeps creeping through the wallpaper. Also, since they are a bolt-on at the macro level in C++, reference count updates aren't optimized and hoisted out of loops. (They aren't in CPython either, but there have been reference counted systems that optimize out most reference count updates.) John Nagle From gallium.arsenide at gmail.com Thu Sep 2 02:32:23 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Wed, 1 Sep 2010 23:32:23 -0700 (PDT) Subject: importing excel data into a python matrix? References: Message-ID: <04da2ca7-092c-4a81-81a4-07636429408d@z7g2000yqg.googlegroups.com> On Sep 1, 7:45?pm, Chris Rebert wrote: > On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking > > wrote: > >?I'm working on a project where I have been given > > a 1000 by 1000 cell excel spreadsheet and I would > > like to be able to access the data using Python. > >?Does anyone know of a way that I can do this? > > "xlrd 0.7.1 - Library for developers to extract data from Microsoft > Excel (tm) spreadsheet files":http://pypi.python.org/pypi/xlrd While I heartily recommend xlrd, it only works with "traditional" Excel files (extension .xls, not .xlsx). If the data really is 1000 columns wide, it must be in the new (Excel 2007 or later) format, because the old only supported up to 256 columns. The most promising-looking Python package to handle .xlsx files is openpyxl. There are also a couple of older .xlsx readers (openpyxl can write as well). I have not tried any of these. John From stefan_ml at behnel.de Thu Sep 2 02:36:32 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 02 Sep 2010 08:36:32 +0200 Subject: PyPy and RPython In-Reply-To: <3a854a6c-648b-43c6-b7f4-e7b0d849274b@x18g2000pro.googlegroups.com> References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <3a854a6c-648b-43c6-b7f4-e7b0d849274b@x18g2000pro.googlegroups.com> Message-ID: sarvi, 02.09.2010 07:06: > Look at all the alternatives we have. Cython? Shedskin? > I'll take PyPy anyday instead of them Fell free to do so, but don't forget that the choice of a language always depends on the specific requirements at hand. Cython has proven its applicability in a couple of large projects, for example. And it has a lot more third party libraries available than both PyPy and Shedskin together: all Python libraries, pure Python and CPython binary extensions, as well as tons of code written in Cython, C, C++, Fortran, and then some. And you don't have to give up one bit of CPython compatibility to use all of that. That alone counts as a pretty huge advantage to some people. Stefan From nagle at animats.com Thu Sep 2 02:39:57 2010 From: nagle at animats.com (John Nagle) Date: Wed, 01 Sep 2010 23:39:57 -0700 Subject: PyPy and RPython In-Reply-To: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> Message-ID: <4c7f46bb$0$1663$742ec2ed@news.sonic.net> On 9/1/2010 10:49 AM, sarvi wrote: > > Is there a plan to adopt PyPy and RPython under the python foundation > in attempt to standardize both. > > I have been watching PyPy and RPython evolve over the years. > > PyPy seems to have momentum and is rapidly gaining followers and > performance. > > PyPy JIT and performance would be a good thing for the Python > Community > And it seems to be well ahead of Unladen Swallow in performance and in > a position to improve quite a bit. > > > Secondly I have always fantasized of never having to write C code yet > get its compiled performance. > With RPython(a strict subset of Python), I can actually compile it to > C/Machine code > > > These 2 seem like spectacular advantages for Python to pickup on. > And all this by just showing the PyPy and the Python foundation's > support and direction to adopt them. > > > Yet I see this forum relatively quiet on PyPy or Rpython ? Any > reasons??? > > Sarvi The winner on performance, by a huge margin, is Shed Skin, the optimizing type-inferring compiler for a restricted subset of Python. PyPy and Unladen Swallow have run into the problem that if you want to keep some of the less useful dynamic semantics of Python, the heavy-duty optimizations become extremely difficult. However, if we defined a High Performance Python language, with some restrictions, the problem becomes much easier. The necessary restrictions are roughly this: -- Functions, once defined, cannot be redefined. (Inlining and redefinition do not play well together.) -- Variables are implicitly typed for the base types: integer, float, bool, and everything else. The compiler figures this out automatically. (Shed Skin does this now.) -- Unless a class uses a "setattr" function or has a __setattr__ method, its entire list of attributes is known at compile time. (In other words, you can't patch in new attributes from outside the class unless the class indicates it supports that. You can subclass, of course.) -- Mutable objects (other than some form of synchronized object) cannot be shared between threads. This is the key step in getting rid of the Global Interpreter Lock. -- "eval" must be restricted to the form that has a list of the variables it can access. -- Import after startup probably won't work. Those are the essential restrictions. With those, Python could go 20x to 60x faster than CPython. The failures of PyPy and Unladen Swallow to get any significant performance gains over CPython demonstrate the futility of trying to make the current language go fast. Reference counts aren't a huge issue. With some static analysis, most reference count updates can be optimized out. (As for how this is done, the key issue is to determine whether each function "keeps" a reference to each parameter. For any function which does not, that parameter doesn't have to have reference count updates within the function. Most math library functions have this property. You do have to analyze the entire program globally, though.) John Nagle From arnodel at googlemail.com Thu Sep 2 02:43:27 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 02 Sep 2010 07:43:27 +0100 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: Dmitry Chichkov writes: > Given: a large list (10,000,000) of floating point numbers; > Task: fastest python code that finds k (small, e.g. 10) smallest > items, preferably with item indexes; > Limitations: in python, using only standard libraries (numpy & scipy > is Ok); > > I've tried several methods. With N = 10,000,000, K = 10 The fastest so > far (without item indexes) was pure python implementation > nsmallest_slott_bisect (using bisect/insert). And with indexes > nargsmallest_numpy_argmin (argmin() in the numpy array k times). > > Anyone up to the challenge beating my code with some clever selection > algorithm? > > Current Table: > 1.66864395142 mins_heapq(items, n): > 0.946580886841 nsmallest_slott_bisect(items, n): > 1.38014793396 nargsmallest(items, n): > 10.0732769966 sorted(items)[:n]: > 3.17916202545 nargsmallest_numpy_argsort(items, n): > 1.31794500351 nargsmallest_numpy_argmin(items, n): > 2.37499308586 nargsmallest_numpy_array_argsort(items, n): > 0.524670124054 nargsmallest_numpy_array_argmin(items, n): > > 0.0525538921356 numpy argmin(items): 1892997 > 0.364673852921 min(items): 10.0000026786 I think without numpy, nsmallest_slott_bisect is almost optimal. There is a slight improvement: 1.33862709999 nsmallest_slott_bisect(items, n): [10.000011643188717, 10.000017791492528] 0.883894920349 nsmallest_slott_bisect2(items, n): [10.000011643188717, 10.000017791492528] ==== code ==== from bisect import insort from itertools import islice def nsmallest_slott_bisect(iterable, n, insort=insort): it = iter(iterable) mins = sorted(islice(it, n)) for el in it: if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates insort(mins, el) mins.pop() return mins def nsmallest_slott_bisect2(iterable, n, insort=insort): it = iter(iterable) mins = sorted(islice(it, n)) maxmin = mins[-1] for el in it: if el <= maxmin: #NOTE: equal sign is to preserve duplicates insort(mins, el) mins.pop() maxmin = mins[-1] return mins import time from random import randint, random test_data = [randint(10, 50) + random() for i in range(10000000)] K = 10 init = time.time() mins = nsmallest_slott_bisect(test_data, K) print time.time() - init, 'nsmallest_slott_bisect(items, n):', mins[: 2] init = time.time() mins = nsmallest_slott_bisect2(test_data, K) print time.time() - init, 'nsmallest_slott_bisect2(items, n):', mins[: 2] -- Arnaud From swapnil.st at gmail.com Thu Sep 2 02:57:21 2010 From: swapnil.st at gmail.com (swapnil) Date: Wed, 1 Sep 2010 23:57:21 -0700 (PDT) Subject: python path separator Message-ID: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> I could not find any documentation for variables os.path.sep and os.path.altsep. Although the first is pretty straightforward can anyone explain the purpose of the second variable? Is it even useful? According to issue http://bugs.python.org/issue709428, os.path.altsep was 'None' till a long time and it didn't bother anyone? From __peter__ at web.de Thu Sep 2 02:59:59 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 08:59:59 +0200 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: Dmitry Chichkov wrote: > Given: a large list (10,000,000) of floating point numbers; > Task: fastest python code that finds k (small, e.g. 10) smallest > items, preferably with item indexes; > Limitations: in python, using only standard libraries (numpy & scipy > is Ok); > > I've tried several methods. With N = 10,000,000, K = 10 The fastest so > far (without item indexes) was pure python implementation > nsmallest_slott_bisect (using bisect/insert). And with indexes > nargsmallest_numpy_argmin (argmin() in the numpy array k times). > > Anyone up to the challenge beating my code with some clever selection > algorithm? If you don't care about stability, i. e. whether nlargest(2, [1, 2, 2.0]) returns [1, 2] or [1, 2.0], use _heapq.nlargest() directly $ python nsmallest_perf2.py nsmallest --> 0.142784833908 nsmallest_slott_bisect --> 0.19291305542 $ cat nsmallest_perf2.py from random import randint, random import time from bisect import insort from itertools import islice import _heapq _funcs = [] def timeit(f): _funcs.append(f) def time_all(*args): funcs = _funcs width = max(len(f.__name__) for f in funcs) prev = None for f in funcs: start = time.time() result = f(*args) end = time.time() print "%-*s --> %10s" % (width, f.__name__, end - start) if prev is None: prev = result else: assert prev == result timeit(_heapq.nsmallest) @timeit def nsmallest_slott_bisect(n, iterable, insort=insort): it = iter(iterable) mins = sorted(islice(it, n)) for el in it: if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates insort(mins, el) mins.pop() return mins test_data = [randint(10, 50) + random() for i in range(10**6)] K = 10 time_all(K, test_data) Peter From __peter__ at web.de Thu Sep 2 03:18:06 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 09:18:06 +0200 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: Dmitry Chichkov wrote: > Code: A lot of the following doesn't run or returns incorrect results. To give but one example: > def nargsmallest_numpy_argmin(iter, k): > distances = N.asarray(iter) > mins = [] Could you please provide an up-to-date version? Peter PS: for an easy way to ensure consistency see timeit/time_all in my previous post. From vlastimil.brom at gmail.com Thu Sep 2 03:25:23 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 2 Sep 2010 09:25:23 +0200 Subject: python path separator In-Reply-To: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> References: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> Message-ID: 2010/9/2 swapnil : > I could not find any documentation for variables os.path.sep and > os.path.altsep. Although the first is pretty straightforward can > anyone explain the purpose of the second variable? Is it even useful? > According to issue http://bugs.python.org/issue709428, os.path.altsep > was 'None' till a long time and it didn't bother anyone? > -- > http://mail.python.org/mailman/listinfo/python-list > see http://docs.python.org/library/os.html#os.sep http://docs.python.org/library/os.html#os.altsep On windows it returns a slash >>> os.altsep '/' which is often easier to use (i.e. if I understand correctly, in most usual cases the forward slash should probably just work on most of the recent OSes). vbr From anand.sadasivam at gmail.com Thu Sep 2 03:29:41 2010 From: anand.sadasivam at gmail.com (Anand Sadasivam) Date: Thu, 2 Sep 2010 12:59:41 +0530 Subject: Is python is the safest language ... Message-ID: Hi All, Is python is the safest language is my question. I feel its good language, but however java has good occupancy. About four years back I did few python programs and worked with some of add-on product over ZOPE and Plone. The suggestion to me is mostly welcome. Regards, -- Anand.S anand.sadasivam at gmail.com asadasiv at gmail.com +91 99025 38904 -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at googlemail.com Thu Sep 2 03:47:57 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 2 Sep 2010 00:47:57 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: <1c854f03-f2fd-4bc2-acda-d6791561e2cc@f25g2000yqc.googlegroups.com> On Sep 2, 7:59?am, Peter Otten <__pete... at web.de> wrote: > Dmitry Chichkov wrote: > > Given: a large list (10,000,000) of floating point numbers; > > Task: fastest python code that finds k (small, e.g. 10) smallest > > items, preferably with item indexes; > > Limitations: in python, using only standard libraries (numpy & scipy > > is Ok); > > > I've tried several methods. With N = 10,000,000, K = 10 The fastest so > > far (without item indexes) was pure python implementation > > nsmallest_slott_bisect (using bisect/insert). And with indexes > > nargsmallest_numpy_argmin (argmin() in the numpy array k times). > > > Anyone up to the challenge beating my code with some clever selection > > algorithm? > > If you don't care about stability, i. e. whether nlargest(2, [1, 2, 2.0]) > returns [1, 2] or [1, 2.0], use > > _heapq.nlargest() directly > > $ python nsmallest_perf2.py > nsmallest ? ? ? ? ? ? ?--> 0.142784833908 > nsmallest_slott_bisect --> 0.19291305542 > $ cat nsmallest_perf2.py > from random import randint, random > import time > from bisect ? ?import insort > from itertools import islice > import _heapq > > _funcs = [] > def timeit(f): > ? ? _funcs.append(f) > > def time_all(*args): > ? ? funcs = _funcs > ? ? width = max(len(f.__name__) for f in funcs) > ? ? prev = None > ? ? for f in funcs: > ? ? ? ? start = time.time() > ? ? ? ? result = f(*args) > ? ? ? ? end = time.time() > ? ? ? ? print "%-*s --> %10s" % (width, f.__name__, end - start) > ? ? ? ? if prev is None: > ? ? ? ? ? ? prev = result > ? ? ? ? else: > ? ? ? ? ? ? assert prev == result > > timeit(_heapq.nsmallest) > > @timeit > def nsmallest_slott_bisect(n, iterable, insort=insort): > ? ? it ? = iter(iterable) > ? ? mins = sorted(islice(it, n)) > ? ? for el in it: > ? ? ? ? if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates > ? ? ? ? ? ? insort(mins, el) > ? ? ? ? ? ? mins.pop() > ? ? return mins > > test_data = [randint(10, 50) + random() for i in range(10**6)] > K = 10 > > time_all(K, test_data) > > Peter I get: 1.46s for _heapq.nsmallest 0.85s for nsmallest_slott_bisect2 (version I posted) I am a bit surprised that mine is so slow compared with yours. I'll do more tests later! -- Arnaud From ldo at geek-central.gen.new_zealand Thu Sep 2 03:49:23 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 02 Sep 2010 19:49:23 +1200 Subject: Windows vs. file.read References: Message-ID: In message , MRAB wrote: > You should open the files in binary mode, not text mode, ie file(path, > "rb"). Text mode is the default. Not a problem on *nix because the line > ending is newline. We used to pride ourselves on not having to worry about text versus binary I/O modes on *nix, but I?m beginning to think the reality is we have to adopt it. To start with, it means we can automatically handle different newline conventions with text files originating on different systems. From clp2 at rebertia.com Thu Sep 2 04:00:00 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 2 Sep 2010 01:00:00 -0700 Subject: Is python is the safest language ... In-Reply-To: References: Message-ID: On Thu, Sep 2, 2010 at 12:29 AM, Anand Sadasivam wrote: > Hi All, > > Is python is the safest language is my question. I feel its good language, > but however java has good occupancy. About four years back I did few python > programs and worked with some of add-on product over ZOPE and Plone. The question is vague. "Safest" in what sense? Type safety? Long-term viability? Difficulty in the programmer shooting themself in the foot? Cheers, Chris -- http://blog.rebertia.com From sschwarzer at sschwarzer.net Thu Sep 2 04:06:50 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Thu, 02 Sep 2010 10:06:50 +0200 Subject: Is there a Python equivalent to Perl's File::Listing::parse_dir In-Reply-To: <4c62ead3$0$1587$742ec2ed@news.sonic.net> References: <4c62ead3$0$1587$742ec2ed@news.sonic.net> Message-ID: <4C7F5B1A.3000905@sschwarzer.net> Hi John, On 2010-08-11 20:24, John Nagle wrote: > Perl has a function which will take a remote directory page, in > the form that most web sites return for a file directory, and > parse it into a useful form: > > http://www.xav.com/perl/site/lib/File/Listing.html > > This is especially useful for FTP sites. > > Is there a Python equivalent of this? I'm converting some > old Perl code. > > Even the Python FTP module doesn't have a directory parser. I saw this posting only now. I hope it's not too late to point you to ftputil, http://ftputil.sschwarzer.net . :-) As the name implies, it's FTP-only for now, though. If you have any questions regarding the library, please ask. Stefan From fetchinson at googlemail.com Thu Sep 2 04:12:23 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 2 Sep 2010 10:12:23 +0200 Subject: fairly urgent request: paid python (or other) work required In-Reply-To: References: Message-ID: On 9/1/10, lkcl wrote: > i apologise for having to contact so many people but this is fairly > urgent, and i'm running out of time and options. i'm a free software > programmer, and i need some paid work - preferably python - fairly > urgently, so that i can pay for food and keep paying rent, and so that > my family doesn't get deported or have to leave the country. > > i really would not be doing this unless it was absolutely, absolutely > essential that i get money. > > so that both i and the list are not unnecessarily spammed, please > don't reply with recommendations of "where to get jobs", unless they > are guaranteed to result in immediate work and money. > > if you have need of a highly skilled and experienced python-preferring > free-software-preferring software engineer, please simply contact me, > and tell me what you need doing: there's no need for you to read the > rest of this message. > > so that people are not offended by me asking on such a high-volume > list for work, here are some questions and answers: > > Q: who are you? > A: luke leighton. free sofware developer, free software project > leader, and "unusual cross-project mash-up-er" (meaning: i spot the > value of joining one or more bits of disparate "stuff" to make > something that's more powerful than its components). > > Q: where's your CV? > A: executive version of CV is at http://lkcl.net/exec_cv.txt - please > don't ask for a proprietary microsoft word version, as a refusal and > referral to the "sylvester response" often offends. > > Q: what can you do? > A: python programming, c programming, web development, networking, > cryptography, reverse-engineering, IT security, etc. etc. preferably > involving free software. > > Q: what do you need? > A: money to pay rent and food. at the ABSOLUTE MINIMUM, i need as > little as ?1500 per month to pay everything, and have been earning > approx ?800 per month for the past year. a ?5000 inheritance last > year which i was not expecting has delayed eviction and bankruptcy for > me and my family, and deportation for my partner and 17 month old > daughter (marie is here in the UK on a FLR/M visa) > > Q: why are you asking here? > A: because it's urgent that i get money really really soon; my family > members are refusing to assist, and the few friends that i have do not > have any spare money to lend. > > Q: why here and not "monster jobs" or "python-jobs list" or the > various "recruitment agencies"? > A: those are full-time employment positions, which i have been > frequently applying for and get rejected for various reasons, and i'm > running out of time and money. further interviews cost money, and do > not result in guaranteed work. i need work - and money - _now_. > > Q: why here and not "peopleperhour.com"? > A: if you've ever bid on peopleperhour.com you will know that you are > bidding against "offshore" contrators and even being undercut by 1st > world country bidders who, insanely, appear to be happy to do work for > as little as ?2 / hour. > > Q: why are you getting rejected from interviews? > A: that's complex. a) i simply don't interview well. people with the > classic symptoms of asperger's just don't. b) my daughter is 17 months > old. when i go away for as little as 3 days, which i've done three > times now, she is extremely upset both when i am away and when i > return. i think what would happen if i was doing some sort of full- > time job, away from home, and... i can't do it. subconsciously that > affects how i react when speaking to interviewers. > > Q: why do you not go "get a job at tesco's" or "drive a truck"? > A: tescos and HGV driving etc. pay around ?12 per hour. ?12 per hour > after tax comes down to about ?8 to ?9 per hour. ?9 per hour requires > 35 hours per week to earn as little as ?1500. 35 hours per week is > effectively full-time, and means that a) my programming and software > engineering skills are utterly, utterly wasted b) my daughter gets > extremely upset because i won't be at home. > > so you get the gist, and thank you for putting up with me needing to > take this action. For the sake of your family, I'd recommend taking the following paragraphs off your cv: """ If you require someone whom you do NOT want to take the initiative to assess all aspects of the required work and beyond; if you require someone who will "stay in the box", do NOT contact me. """ """ The speed at which I acquire new knowledge and be able to integrate and recommend new ideas tends to make insecure people feel frightened and threatened. """ """ Pet Hates: - "peer to peer networking" [peer equals neanderthal...] - "microsoft marketing machine" [FUD at its best...] - "restrictive anti-competitive business practices" - "information-restricive laws" [DMCA etc.] - Unreliable systems that cannot be made to do the job you really needed done yesterday... """ I'd also recommend updating the links on your cv, these ones do not work at all: http://www.well.com/~lkcl http://dcerpc.net/person/index.xvl?acct=person:lkcl http://www.watfordcleaningsupplies.co.uk https://secure.digimask.com/ http://dcerpc.net And this one is outdated: http://sourceforge.net/projects/python/ HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From no.email at nospam.invalid Thu Sep 2 04:16:54 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Sep 2010 01:16:54 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> Message-ID: <7x8w3kimq1.fsf@ruckus.brouhaha.com> Dennis Lee Bieber writes: >> GC's for large systems ... copy the live objects to a new contiguous heap > That sounds suspiciously like the original Macintosh OS, with its > "handles"... IE, double-indirection. Nah, a double indirection on every access would be a terrible performance hit. The classic approach is when you move an object to the new heap, you leave a tagged forwarding pointer at its former location the old heap, giving the its location in the new heap. Then as you move other objects, you dereference the pointers in them to see whether they point to moved or unmoved objects, and relocate any unmoved ones. A more complete explanation is here: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-33.html#%_sec_5.3.2 From __peter__ at web.de Thu Sep 2 04:17:30 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 10:17:30 +0200 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> <1c854f03-f2fd-4bc2-acda-d6791561e2cc@f25g2000yqc.googlegroups.com> Message-ID: Arnaud Delobelle wrote: > I get: > > 1.46s for _heapq.nsmallest > 0.85s for nsmallest_slott_bisect2 (version I posted) > > I am a bit surprised that mine is so slow compared with yours. I'll > do more tests later! Strange. I see a significant difference only for python3 (on 64bit Linux) $ python3 nsmallest_perf3.py 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] pick the 10 smallest items out of 5000000 nsmallest --> 0.310983181 nsmallest_slott_bisect --> 1.02625894547 nsmallest_slott_bisect2 --> 0.612951040268 $ python nsmallest_perf3.py 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] pick the 10 smallest items out of 5000000 nsmallest --> 0.743387937546 nsmallest_slott_bisect --> 0.961116075516 nsmallest_slott_bisect2 --> 0.746085882187 Peter From sarvilive at gmail.com Thu Sep 2 04:29:54 2010 From: sarvilive at gmail.com (sarvi) Date: Thu, 2 Sep 2010 01:29:54 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> Message-ID: When I think about it these restrictions below seem a very reasonable tradeoff for performance. And I can use this for just the modules/sections that are performance critical. Essentially, the PyPy interpreter can have a restricted mode that enforces these restriction. This will help write such RPython code that can then be compiled into C/ASM using the PyPy Compiler which as I understand can do this today. If Shedskin generated C++ code is faster than PyPy generate C++ code. Isn't that just another reason why PyPy and Shedskin should be joining forces. Wouldn't we want PyPy generated C code to be just as fast as Shedskin's Afterall thats how the PyPy compiler is built, right? and we do want that to be fast too? Sarvi On Sep 1, 11:39?pm, John Nagle wrote: > On 9/1/2010 10:49 AM, sarvi wrote: > > > > > > > > > Is there a plan to adopt PyPy and RPython under the python foundation > > in attempt to standardize both. > > > I have been watching PyPy and RPython evolve over the years. > > > PyPy seems to have momentum and is rapidly gaining followers and > > performance. > > > PyPy JIT and performance would be a good thing for the Python > > Community > > And it seems to be well ahead of Unladen Swallow in performance and in > > a position to improve quite a bit. > > > Secondly I have always fantasized of never having to write C code yet > > get its compiled performance. > > With RPython(a strict subset of Python), I can actually compile it to > > C/Machine code > > > These 2 seem like spectacular advantages for Python to pickup on. > > And all this by just showing the PyPy and the Python foundation's > > support and direction to adopt them. > > > Yet I see this forum relatively quiet on PyPy or Rpython ? ?Any > > reasons??? > > > Sarvi > > ? ? ?The winner on performance, by a huge margin, is Shed Skin, > the optimizing type-inferring compiler for a restricted subset > of Python. ?PyPy and Unladen Swallow have run into the problem > that if you want to keep some of the less useful dynamic semantics > of Python, the heavy-duty optimizations become extremely difficult. > > ? ? ?However, if we defined a High Performance Python language, with > some restrictions, the problem becomes much easier. ?The necessary > restrictions are roughly this: > > -- Functions, once defined, cannot be redefined. > ? ? (Inlining and redefinition do not play well > ? ? together.) > > -- Variables are implicitly typed for the base types: > ? ? integer, float, bool, and everything else. ?The > ? ? compiler figures this out automatically. > ? ? (Shed Skin does this now.) > > -- Unless a class uses a "setattr" function or has > ? ? a __setattr__ method, its entire list of attributes is > ? ? known at compile time. > ? ? (In other words, you can't patch in new attributes > ? ? from outside the class unless the class indicates > ? ? it supports that. ?You can subclass, of course.) > > -- Mutable objects (other than some form of synchronized > ? ? object) cannot be shared between threads. ?This is the > ? ? key step in getting rid of the Global Interpreter Lock. > > -- "eval" must be restricted to the form that has a list of > ? ? the variables it can access. > > -- Import after startup probably won't work. > > Those are the essential restrictions. ?With those, Python > could go 20x to 60x faster than CPython. ?The failures > of PyPy and Unladen Swallow to get any significant > performance gains over CPython demonstrate the futility > of trying to make the current language go fast. > > Reference counts aren't a huge issue. ?With some static > analysis, most reference count updates can be optimized out. > (As for how this is done, the key issue is to determine whether > each function "keeps" a reference to each parameter. ?For > any function which does not, that parameter doesn't have > to have reference count updates within the function. > Most math library functions have this property. > You do have to analyze the entire program globally, though.) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle From dchichkov at gmail.com Thu Sep 2 04:47:58 2010 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Thu, 2 Sep 2010 01:47:58 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: Uh. I'm sorry about the confusion. Last three items are just O(N) baselines. Python min(), Numpy argmin(), Numpy asarray(). I'll update the code. Thanks! > A lot of the following doesn't run or returns incorrect results. > To give but one example: > > > def nargsmallest_numpy_argmin(iter, k): > > ? ? distances = N.asarray(iter) > > ? ? mins = [] > > Could you please provide an up-to-date version? > > Peter > > PS: for an easy way to ensure consistency see timeit/time_all in my previous > post. From dchichkov at gmail.com Thu Sep 2 05:20:14 2010 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Thu, 2 Sep 2010 02:20:14 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: <96c70ee2-2662-499e-afbf-a90f7f85cec4@k1g2000prl.googlegroups.com> By the way, improving n-ARG-smallest (that returns indexes as well as values) is actually more desirable than just regular n-smallest: == Result == 1.38639092445 nargsmallest 3.1569879055 nargsmallest_numpy_argsort 1.29344892502 nargsmallest_numpy_argmin Note that numpy array constructor eats around 0.789. == Code == from operator import itemgetter from random import randint, random from itertools import islice from time import time def nargsmallest(iterable, n): it = enumerate(iterable) mins = sorted(islice(it, n), key = itemgetter(1)) loser = mins[-1][1] # largest of smallest for el in it: if el[1] <= loser: # NOTE: preserve dups mins.append(el) mins.sort(key = itemgetter(1)) mins.pop() loser = mins[-1][1] return mins def nargsmallest_numpy_argsort(iter, k): distances = N.asarray(iter) return [(i, distances[i]) for i in distances.argsort()[0:k]] def nargsmallest_numpy_argmin(iter, k): mins = [] distances = N.asarray(iter) for i in xrange(k): j = distances.argmin() mins.append((j, distances[j])) distances[j] = float('inf') return mins test_data = [randint(10, 50) + random() for i in range(10000000)] K = 10 init = time() mins = nargsmallest(test_data, K) print time() - init, 'nargsmallest:', mins[:2] import numpy as N init = time() mins = nargsmallest_numpy_argsort(test_data, K) print time() - init, 'nargsmallest_numpy_argsort:', mins[:2] init = time() mins = nargsmallest_numpy_argmin(test_data, K) print time() - init, 'nargsmallest_numpy_argmin:', mins[:2] From mahaboobnisha at gmail.com Thu Sep 2 06:00:52 2010 From: mahaboobnisha at gmail.com (roshini begum) Date: Thu, 2 Sep 2010 03:00:52 -0700 (PDT) Subject: comp.lang.python Message-ID: www.127760.blogspot.com From michael at perfect-kreim.de Thu Sep 2 06:02:40 2010 From: michael at perfect-kreim.de (Michael Kreim) Date: Thu, 02 Sep 2010 12:02:40 +0200 Subject: Speed-up for loops Message-ID: <4C7F7640.1010102@perfect-kreim.de> Hi, I was comparing the speed of a simple loop program between Matlab and Python. My Codes: $ cat addition.py imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a $ cat addition.m imax = 1e9; a = 0; for i=0:imax-1 a = a + 10; end disp(a); exit; The results look like this: $ /usr/bin/time --verbose python addition.py 10000000000 Command being timed: "python addition.py" User time (seconds): 107.30 System time (seconds): 0.08 Percent of CPU this job got: 97% Elapsed (wall clock) time (h:mm:ss or m:ss): 1:50.09 [...] $ /usr/bin/time --verbose matlab -nodesktop -nosplash -r "addition" [...] 1.0000e+10 Command being timed: "matlab -nodesktop -nosplash -r addition" User time (seconds): 7.65 System time (seconds): 0.18 Percent of CPU this job got: 94% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.25 [...] Unfortunately my Python Code was much slower and I do not understand why. Are there any ways to speed up the for/xrange loop? Or do I have to live with the fact that Matlab beats Python in this example? Thanks a lot for your answers. With best regards, Michael From swapnil.st at gmail.com Thu Sep 2 06:22:27 2010 From: swapnil.st at gmail.com (swapnil) Date: Thu, 2 Sep 2010 03:22:27 -0700 (PDT) Subject: python path separator References: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> Message-ID: On Sep 2, 12:25?pm, Vlastimil Brom wrote: > 2010/9/2 swapnil :> I could not find any documentation for variables os.path.sep and > > os.path.altsep. Although the first is pretty straightforward can > > anyone explain the purpose of the second variable? Is it even useful? > > According to issuehttp://bugs.python.org/issue709428, os.path.altsep > > was 'None' till a long time and it didn't bother anyone? > > -- > >http://mail.python.org/mailman/listinfo/python-list > > seehttp://docs.python.org/library/os.html#os.sephttp://docs.python.org/library/os.html#os.altsep > > On windows it returns a slash>>> os.altsep > > '/' > which is often easier to use (i.e. if I understand correctly, in most > usual cases the forward slash should probably just work on most of the > recent OSes). > > ? ?vbr Thanks for help From magguru.chinnamnaidu at gmail.com Thu Sep 2 06:33:04 2010 From: magguru.chinnamnaidu at gmail.com (paypal cash) Date: Thu, 2 Sep 2010 03:33:04 -0700 (PDT) Subject: I GOT $5000 FROM PAYPAL BY SIMPLE HACK. Message-ID: I GOT $5000 FROM PAYPAL BY SIMPLE HACK At http://happyandeasy.co.cc Due to high security risks, i have hidden the PayPal Form link in an image. in that website On RIGHT SIDE Below search box , click on image and enter your PAYPAL id And Your name. From __peter__ at web.de Thu Sep 2 06:36:51 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 12:36:51 +0200 Subject: Speed-up for loops References: Message-ID: Michael Kreim wrote: > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Are there any ways to speed up the for/xrange loop? Move it into a function; this turns a and i into local variables. def f(): imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a f() > Or do I have to live with the fact that Matlab beats Python in this > example? I think so. From bussiere at gmail.com Thu Sep 2 06:49:30 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Thu, 2 Sep 2010 12:49:30 +0200 Subject: dirty problem 3 lines In-Reply-To: <928816d6-e72f-4faf-882b-756fd185ce4c@w15g2000pro.googlegroups.com> References: <4C7DC74D.6060702@mrabarnett.plus.com> <928816d6-e72f-4faf-882b-756fd185ce4c@w15g2000pro.googlegroups.com> Message-ID: It seems to work perfectly thanks a lot Bussiere Google Fan boy On Thu, Sep 2, 2010 at 7:32 AM, alex23 wrote: > bussiere bussiere wrote: >> it's just as it seems : >> i want to know how does ti works to get back an object from a string in python : >> pickle.loads("""b'\x80\x03]q\x00(K\x00K\x01e.'""") #doesn't work > > Repeating the question without providing any further information > doesn't really help. > > This is a byte string: b'\x80\x03]q\x00(K\x00K\x01e.' > As MRAB points out, you can unpickle a byte string directly. > > This is a doc string: """note the triplet of double quotes""" > What you have is a doc string that appears to contain a byte string: > """b'\x80\x03]q\x00(K\x00K\x01e.'""" > > So the question for you is: what is putting the byte string inside of > a doc string? If you can stop that from happening, then you'll have a > byte string you can directly unpickle. > > Now, if you _don't_ have control over whatever is handing you the dump > string, then you can just use string manipulation to reproduce the > byte string: > >>>> dump = """b'\x80\x03]q\x00(K\x00K\x01e.'""" >>>> badump = dump[2:-1].encode()[1:] >>>> pickle.loads(badump) > [0, 1] > > So: > ?- dump[2:-1] strips off string representation of the byte string > (b'...') > ?- .encode() turns it into an actual byte string > ?- [1:] strips a unicode blank from the start of the byte string (not > entirely sure how that gets there...) > > After that it should be fine to unpickle. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From michael at perfect-kreim.de Thu Sep 2 07:16:08 2010 From: michael at perfect-kreim.de (Michael Kreim) Date: Thu, 02 Sep 2010 13:16:08 +0200 Subject: Speed-up for loops In-Reply-To: References: Message-ID: <4C7F8778.5030509@perfect-kreim.de> Peter Otten wrote: > Move it into a function; this turns a and i into local variables. > > def f(): > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > f() Wow. It is still slower than Matlab, but your suggestion speeds up the code by ca 50%. But I do not understand why the change of a global to a local variable gives such a big difference. $ cat addition.py imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a $ cat additionOtten.py def f(): imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a f() $ /usr/bin/time --verbose python addition.py 10000000000 Command being timed: "python addition.py" User time (seconds): 110.52 System time (seconds): 0.01 Percent of CPU this job got: 98% Elapsed (wall clock) time (h:mm:ss or m:ss): 1:52.76 [...] $ /usr/bin/time --verbose python additionOtten.py 10000000000 Command being timed: "python additionOtten.py" User time (seconds): 56.38 System time (seconds): 0.00 Percent of CPU this job got: 99% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:56.64 [...] From __peter__ at web.de Thu Sep 2 07:43:11 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 13:43:11 +0200 Subject: Speed-up for loops References: Message-ID: Michael Kreim wrote: > Peter Otten wrote: >> Move it into a function; this turns a and i into local variables. >> >> def f(): >> imax = 1000000000 >> a = 0 >> for i in xrange(imax): >> a = a + 10 >> print a >> f() > > Wow. It is still slower than Matlab, but your suggestion speeds up the > code by ca 50%. > But I do not understand why the change of a global to a local variable > gives such a big difference. Basically the local namespace is a C array where accessing an item is just pointer arithmetic while the global namespace is a Python dictionary. There may be optimisations for the latter. If you can read C have a look at the LOAD/STORE_FAST and LOAD/STORE_GLOBAL implementations for the gory details: http://svn.python.org/view/python/trunk/Python/ceval.c?view=markup Peter From ndbecker2 at gmail.com Thu Sep 2 07:45:16 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 02 Sep 2010 07:45:16 -0400 Subject: argparse list Message-ID: I'm interested in using argparse to parse a string formatted as: my_prog --option1=1,10,37 That is, a list of comma delimited values. I guess nargs almost does it, but expects options to be space-delimited. What would be the easiest approach? From __peter__ at web.de Thu Sep 2 07:58:15 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 13:58:15 +0200 Subject: argparse list References: Message-ID: Neal Becker wrote: > I'm interested in using argparse to parse a string formatted as: > > my_prog --option1=1,10,37 > > That is, a list of comma delimited values. I guess nargs almost does it, > but expects options to be space-delimited. > > What would be the easiest approach? >>> import argparse >>> def csv(value): ... return map(int, value.split(",")) ... >>> p = argparse.ArgumentParser() >>> p.add_argument("--option1", type=csv) and None >>> p.parse_args(["--option1=1,10,37"]) Namespace(option1=[1, 10, 37]) >>> _.option1[0] 1 Peter From ndbecker2 at gmail.com Thu Sep 2 08:26:35 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 02 Sep 2010 08:26:35 -0400 Subject: argparse list References: Message-ID: Peter Otten wrote: >>>> import argparse >>>> def csv(value): > ... return map(int, value.split(",")) > ... >>>> p = argparse.ArgumentParser() >>>> p.add_argument("--option1", type=csv) and None >>>> p.parse_args(["--option1=1,10,37"]) Thanks! But, why the 'and None'? From tom.h.miller at gmail.com Thu Sep 2 08:31:28 2010 From: tom.h.miller at gmail.com (Tom Miller) Date: Thu, 2 Sep 2010 08:31:28 -0400 Subject: Safely decoding user input Message-ID: Hello everyone, Before I pose my question, I should mention that I'm still pretty unfamiliar with proper terminology for string encoding, so I might get some of it wrong. Please bear with me. I'm writing a program that accepts arguments from the command line. Some of my users are using Windows with a non-unicode locale setting and characters outside of the ascii set. So something like $ program --option ultimately results in "UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-3: invalid data" My questions: 1) Is it safe to immediately decode all strings in sys.argv[] with something like sys.argv = [string.decode(sys.stdin.encoding) for string in sys.argv]? 2) Can something similar be done to anything returned by raw_input()? Thanks, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Sep 2 08:34:21 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 14:34:21 +0200 Subject: argparse list References: Message-ID: Neal Becker wrote: > Peter Otten wrote: > >>>>> import argparse >>>>> def csv(value): >> ... return map(int, value.split(",")) >> ... >>>>> p = argparse.ArgumentParser() >>>>> p.add_argument("--option1", type=csv) and None >>>>> p.parse_args(["--option1=1,10,37"]) > > Thanks! But, why the 'and None'? To hide the result of p.add_argument(). >>> "irrelevant junk" 'irrelevant junk' >>> "irrelevant junk" and None >>> I'm not going to do it again ;) Peter From alekseymv at gmail.com Thu Sep 2 08:42:55 2010 From: alekseymv at gmail.com (Aleksey) Date: Thu, 2 Sep 2010 05:42:55 -0700 (PDT) Subject: parsing string into dict References: Message-ID: <7fee17a9-6417-457b-a8cc-5de65028440f@f6g2000yqa.googlegroups.com> On Sep 2, 12:46?am, Tim Arnold wrote: > Hi, > I have a set of strings that are *basically* comma separated, but with > the exception that if a comma occur insides curly braces it is not a > delimiter. ?Here's an example: > > [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] > > I'd like to parse that into a dictionary (note that 'continued' gets > the value 'true'): > {'code':'one', 'caption':'{My Analysis for \textbf{t}, Version > 1}','continued':'true'} > > I know and love pyparsing, but for this particular code I need to rely > only on the standard library (I'm running 2.7). Here's what I've got, > and it works. I wonder if there's a simpler way? > thanks, > --Tim Arnold > > The 'line' is like my example above but it comes in without the ending > bracket, so I append one on the 6th line. > You can use regular expression (also you not need adding ending bracket): import re patt = re.compile(ur'\[code=(?P\w+),\scaption=(?P\{.+\}) (?P,\scontinued)?\]?') def parse_options(s): g=patt.match(s).groupdict() return {'caption' : g['CAPTION'], 'code' : g['CODE'], 'continued' : g['CONTINUED'] and True or False} Test is next: >>> s=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued]' >>> s1=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}]' >>> s2=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued' >>> s3=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}' >>> parse_options(s) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': True} >>> parse_options(s1) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': False} >>> parse_options(s2) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': True} >>> parse_options(s3) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': False} >>> From alekseymv at gmail.com Thu Sep 2 08:43:16 2010 From: alekseymv at gmail.com (Aleksey) Date: Thu, 2 Sep 2010 05:43:16 -0700 (PDT) Subject: parsing string into dict References: Message-ID: <43144686-cbc3-4816-8d49-1ead2217223e@u6g2000yqh.googlegroups.com> On Sep 2, 12:46?am, Tim Arnold wrote: > Hi, > I have a set of strings that are *basically* comma separated, but with > the exception that if a comma occur insides curly braces it is not a > delimiter. ?Here's an example: > > [code=one, caption={My Analysis for \textbf{t}, Version 1}, continued] > > I'd like to parse that into a dictionary (note that 'continued' gets > the value 'true'): > {'code':'one', 'caption':'{My Analysis for \textbf{t}, Version > 1}','continued':'true'} > > I know and love pyparsing, but for this particular code I need to rely > only on the standard library (I'm running 2.7). Here's what I've got, > and it works. I wonder if there's a simpler way? > thanks, > --Tim Arnold > > The 'line' is like my example above but it comes in without the ending > bracket, so I append one on the 6th line. > You can use regular expression (also you not need adding ending bracket): import re patt = re.compile(ur'\[code=(?P\w+),\scaption=(?P\{.+\}) (?P,\scontinued)?\]?') def parse_options(s): g=patt.match(s).groupdict() return {'caption' : g['CAPTION'], 'code' : g['CODE'], 'continued' : g['CONTINUED'] and True or False} Test is next: >>> s=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued]' >>> s1=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}]' >>> s2=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}, continued' >>> s3=u'[code=one, caption={My Analysis for \textbf{t}, Version 1}' >>> parse_options(s) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': True} >>> parse_options(s1) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': False} >>> parse_options(s2) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': True} >>> parse_options(s3) {'caption': u'{My Analysis for \textbf{t}, Version 1}', 'code': u'one', 'continued': False} >>> From tim.wintle at teamrubber.com Thu Sep 2 08:55:16 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 02 Sep 2010 13:55:16 +0100 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <1283432116.14252.37.camel@tim-laptop> On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: > Hi, > > I was comparing the speed of a simple loop program between Matlab and > Python. > Unfortunately my Python Code was much slower and I do not understand why. The main reason is that, under the hood, cpython does something like this (in psudo-code) itterator = xrange(imax) while 1: next_attribute = itterator.next try: i = next_attribute() except: break a = a + 10 where C (and I'm assuming matlab) does this: while 1: i = i + 1 if (i > imax): break a = a + 10 And the function call in the python is fairly expensive on it's own. Plus it has to do all the standard interpreter stuff for memory management and deciding when to give up the GIL etc. > Are there any ways to speed up the for/xrange loop? leaving it in python, no. (well, "range" is faster in 2.x, but once you get some cache misses due to increased memory usage it's much slower) avoiding iteration by using list comprehensions can help a lot though as it avoids most of the function calls. If you really need to optimise it then you can convert that module to cython by adding a cdef, and then compile it: cdef int i for i in xrange(imax): a = a + 10 print a or you can write it in C it'll run a lot faster. From bauketilma at gmail.com Thu Sep 2 09:08:18 2010 From: bauketilma at gmail.com (Duim) Date: Thu, 2 Sep 2010 06:08:18 -0700 (PDT) Subject: profiling qt programs Message-ID: I'm trying to get a qt program a little faster by looking at the most expensive functions. To find out which functions are most important I wanted to profile the application using cProfile module. Unfortunately this runs through the complete code in 1 go without waiting until all threads (or in whatever way QT is running), are finished. Is there a way to globally profile all running python functions? I saw in this mail http://old.nabble.com/cProfile-and-threads-td29458757.html mention of a profile.enable()/disable() function. Or is this "wishful thinking/mailing"? From stefan_ml at behnel.de Thu Sep 2 09:25:10 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 02 Sep 2010 15:25:10 +0200 Subject: Speed-up for loops In-Reply-To: <1283432116.14252.37.camel@tim-laptop> References: <4C7F7640.1010102@perfect-kreim.de> <1283432116.14252.37.camel@tim-laptop> Message-ID: Tim Wintle, 02.09.2010 14:55: > If you really need to optimise it then you can convert that module to > cython by adding a cdef, and then compile it: > > cdef int i > for i in xrange(imax): > a = a + 10 > print a > > or you can write it in C it'll run a lot faster. Just to get the context right here: a C implementation won't run even a tad faster than the obvious Cython version, but both will run "a lot faster" than the Python version. Plus, if Cython knows that the imax value is small enough, it'll infer "int" for the "i" variable automatically, so you won't need the "cdef" annotation. It won't automatically do that for "a", though, as that might break Python's unlimited integer semantics if "imax" and/or "a" are large enough. Stefan From wherespythonmonks at gmail.com Thu Sep 2 09:48:41 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 2 Sep 2010 09:48:41 -0400 Subject: first non-null element in a list, otherwise None Message-ID: This should be trivial: I am looking to extract the first non-None element in a list, and "None" otherwise. Here's one implementation: >>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) >>> print x 1 I thought maybe a generator expression would be better, to prevent iterating over the whole list: >>> x = ( x for x in [None,1,2] if x is not None ).next() >>> print x 1 However, the generator expression throws if the list is entirely None. With list comprehensions, a solution is: >>> x = ([ x for x in [None,1,2] if x is not None ] + [ None ] )[0] But this can be expensive memory wise. Is there a way to concatenate generator expressions? More importantly, Is there a better way? (In one line?) Thanks, W From __peter__ at web.de Thu Sep 2 09:57:59 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 15:57:59 +0200 Subject: first non-null element in a list, otherwise None References: Message-ID: wheres pythonmonks wrote: > I am looking to extract the first non-None element in a list, and > "None" otherwise. Here's one implementation: > >>>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) >>>> print x > 1 > > I thought maybe a generator expression would be better, to prevent > iterating over the whole list: > >>>> x = ( x for x in [None,1,2] if x is not None ).next() >>>> print x > 1 > > However, the generator expression throws if the list is entirely None. The next() builtin (new in Python 2.6) allows you to provide a default: >>> next((item for item in [None, None, "found"] if item is not None), "no match") 'found' >>> next((item for item in [None, None, None] if item is not None), "no match") 'no match' > With list comprehensions, a solution is: > >>>> x = ([ x for x in [None,1,2] if x is not None ] + [ None ] )[0] > > But this can be expensive memory wise. Is there a way to concatenate > generator expressions? itertools.chain() Peter From hniksic at xemacs.org Thu Sep 2 10:03:01 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 02 Sep 2010 16:03:01 +0200 Subject: Speed-up for loops References: Message-ID: <87wrr4gs4q.fsf@busola.homelinux.net> Michael Kreim writes: > Are there any ways to speed up the for/xrange loop? > Or do I have to live with the fact that Matlab beats Python in this > example? To a point, yes. However, there are things you can do to make your Python code go faster. One has been pointed out by Peter. Another is that Python treats numbers as regular heap objects, so creating a bunch of unneeded integers by xrange slows things down (despite allocation of integer objects being heavily optimized). For this reason, you may want to change xrange(1000000000) to itertools.repeat(None, 1000000000). $ python -m timeit -s 'from itertools import repeat' 'for _ in repeat(None, 100000): pass' 1000 loops, best of 3: 1.71 msec per loop $ python -m timeit -s 'from itertools import repeat' 'for _ in xrange(100000): pass' 100 loops, best of 3: 2.43 msec per loop From michele.simionato at gmail.com Thu Sep 2 10:11:27 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 2 Sep 2010 07:11:27 -0700 (PDT) Subject: argparse list References: Message-ID: On Sep 2, 1:45?pm, Neal Becker wrote: > I'm interested in using argparse to parse a string formatted as: > > my_prog --option1=1,10,37 > > That is, a list of comma delimited values. ?I guess nargs almost does it, > but expects options to be space-delimited. > > What would be the easiest approach? In plac (http://pypi.python.org/pypi/plac) you would write the following: import plac @plac.annotations( option1=('option with comma separated values', 'option', 'o', lambda x: x.split(','))) def main(option1): print option1 if __name__ == '__main__': plac.call(main) From wherespythonmonks at gmail.com Thu Sep 2 10:11:32 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 2 Sep 2010 10:11:32 -0400 Subject: first non-null element in a list, otherwise None In-Reply-To: References: Message-ID: Peter wrote: >> But this can be expensive memory wise. ?Is there a way to concatenate >> generator expressions? > > itertools.chain() > Aha! import itertools >>> x = itertools.chain( (x for x in [None,None] if x is not None), [ None ] ).next() >>> print x None >>> x = itertools.chain( (x for x in [None,7] if x is not None), [ None ] ).next() >>> print x 7 >>> W From r.koebler at yahoo.de Thu Sep 2 10:13:39 2010 From: r.koebler at yahoo.de (Roland Koebler) Date: Thu, 2 Sep 2010 16:13:39 +0200 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <20100902141339.GA31040@localhost> Hi, > Are there any ways to speed up the for/xrange loop? You can use psyco. The following example should be about 4-times as fast as your example: import psyco psyco.full() def f(): imax = 1000000000 a = 0 for i in xrange(imax): a += 10 print a f() regards, Roland From arnodel at googlemail.com Thu Sep 2 11:01:34 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 2 Sep 2010 08:01:34 -0700 (PDT) Subject: first non-null element in a list, otherwise None References: Message-ID: <2971a79a-82ae-49b7-b3ab-71396e39231d@t2g2000yqe.googlegroups.com> On Sep 2, 2:48?pm, wheres pythonmonks wrote: > This should be trivial: > > I am looking to extract the first non-None element in a list, and > "None" otherwise. ?Here's one implementation: > > >>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) > >>> print x > > 1 > > I thought maybe a generator expression would be better, to prevent > iterating over the whole list: > > >>> x = ( x for x in [None,1,2] if x is not None ).next() > >>> print x > > 1 > > However, the generator expression throws if the list is entirely None. > > With list comprehensions, a solution is: > > >>> x = ([ x for x in [None,1,2] if x is not None ] + [ None ] )[0] > > But this can be expensive memory wise. ?Is there a way to concatenate > generator expressions? > > More importantly, > > Is there a better way? ?(In one line?) > > Thanks, > > W Just for fun: >>> print min([None, 2, None, None, 1], key=lambda x: x is None) 2 >>> print min([None, None, None], key=lambda x: x is None) None Looks clever but: min([], key=lambda x: x is None) throws an exception. -- Arnaud From ian at ianhobson.co.uk Thu Sep 2 11:22:04 2010 From: ian at ianhobson.co.uk (Ian Hobson) Date: Thu, 02 Sep 2010 16:22:04 +0100 Subject: Help needed with Windows Service in Python Message-ID: <4C7FC11C.7030904@ianhobson.co.uk> Hi All, I am attempting to create a Windows Service in Python. I have the framework (from Mark Hammond and Andy Robinason's book) running - see below. It starts fine - but it will not stop. :( net stop "Python Service" and using the services GUI both leave the services showing it as "stopping" I guess this means SvcStop is called but it is not enough to get it out of the machine. Does anyone know why not? Python 2.7 with win32 extensions, sunning on Windows 7. Many thanks Ian the (complete) source code is #!/usr/bin/env python # coding=utf8 # service.py = testing services and Named pipes # import win32serviceutil import win32service import win32event class PythonService(win32serviceutil.ServiceFramework): _svc_name_ = "Python Service" _svc_display_name_ = "Test Service in Python" def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self,args) self.hWaitStop = win32event.CreateEvent(None,0,0,None) def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) wind32event.SetEvent(self.hWaitStop) def SvcDoRun(self): win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) if __name__ == '__main__': win32serviceutil.HandleCommandLine(PythonService) From grflanagan at gmail.com Thu Sep 2 11:28:39 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 02 Sep 2010 16:28:39 +0100 Subject: first non-null element in a list, otherwise None In-Reply-To: References: Message-ID: wheres pythonmonks wrote: > This should be trivial: > > > I am looking to extract the first non-None element in a list, and > "None" otherwise. Here's one implementation: > >>>> x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) >>>> print x > 1 > > I thought maybe a generator expression would be better, to prevent > iterating over the whole list: > >>>> x = ( x for x in [None,1,2] if x is not None ).next() >>>> print x > 1 > > However, the generator expression throws if the list is entirely None. > > With list comprehensions, a solution is: > >>>> x = ([ x for x in [None,1,2] if x is not None ] + [ None ] )[0] > > But this can be expensive memory wise. Is there a way to concatenate > generator expressions? > > More importantly, > > Is there a better way? (In one line?) > > Thanks, > > W itertools.dropwhile(lambda x: x is None, inlist + [0]).next() or None From nobody at nowhere.com Thu Sep 2 11:52:00 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Sep 2010 16:52:00 +0100 Subject: killing all subprocess childrens References: Message-ID: On Thu, 02 Sep 2010 13:12:07 +1000, Astan Chee wrote: > I have a piece of code that looks like this: > > import subprocess > retcode = subprocess.call(["java","test","string"]) > print "Exited with retcode " + str(retcode) > > What I'm trying to do (and wondering if its possible) is to make sure > that any children (and any descendants) of this process is killed when > the main java process is killed (or dies). > How do I do this in windows, linux and OSX? I don't think that you can do it reliably on any of those platforms. Consider: A spawns B, B spawns C, C spawns D, B and C terminate. There is no information available to tie D to A. A knows that it spawned B, and D's PPID is C, but C no longer exists so you can't tell that B spawned C. Process groups won't help, as subprocess.Popen() doesn't put the child into a new process group, so all of its descendents will share the PGID of the Python process and any children spawned from it. Even it did use a new process group, the descendents might have different process groups (quite likely if the initial child is a shell script, as the shell executes each "command" in a new process group). If you avoid the subprocess module and use os.fork(), the child can create a new session by fork()ing again, and having the grandchild call os.setsid(). All descendents will share this session unless they explicitly create a new session (and you probably shouldn't be killing any descendents which explicitly create a new session). Another option is if to create the child with std{in,out,err} set to a descriptor created for that specific child. Descendents inherit their descriptors unless explicitly changed. The same applies to the CWD, and (by convention) the environment. On Linux, you can discover a process' descriptors, cwd and environment via the /proc filesystem. From nobody at nowhere.com Thu Sep 2 11:57:08 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Sep 2010 16:57:08 +0100 Subject: python path separator References: <41143c07-4600-4806-8b01-7b816bafe68a@m17g2000prl.googlegroups.com> Message-ID: On Wed, 01 Sep 2010 23:57:21 -0700, swapnil wrote: > I could not find any documentation for variables os.path.sep and > os.path.altsep. Although the first is pretty straightforward can > anyone explain the purpose of the second variable? Is it even useful? The purpose is so that you can do e.g.: if c == os.path.sep or c == os.path.altsep: ... On Windows, both '\' and '/' are directory separators; you shouldn't rely upon a particular one being used, but should check for either. From nobody at nowhere.com Thu Sep 2 12:05:25 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Sep 2010 17:05:25 +0100 Subject: Speed-up for loops References: Message-ID: On Thu, 02 Sep 2010 12:02:40 +0200, Michael Kreim wrote: > I was comparing the speed of a simple loop program between Matlab and > Python. > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Are there any ways to speed up the for/xrange loop? Sure; the above can be reduced to just: print imax * 10 ;) More seriously, if you're comparing against Matlab, you should look at NumPy. If there's a reasonably direct approach using NumPy, it will be much quicker than a Python "for" loop (in a sense, NumPy is a library of useful "for" loops implemented in C). Even a fairly indirect NumPy approach is often quicker than pure Python. From darcy at druid.net Thu Sep 2 12:06:03 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 2 Sep 2010 12:06:03 -0400 Subject: Customizing cgitb Message-ID: <20100902120603.4f56b8d5.darcy@druid.net> I have a small problem with the cgitb module. I know that I can basically write my own version but it seems kind of silly to rewrite something that does 99% what I want. Here is an excerpt from the output of an exception. 1520 (current_job['job_id'], job['_SELECT_'])) 1521 1522 elif job['_ACTION_'].startswith('queue_'): 1523 action = job['_ACTION_'][6:] 1524 if action == 'mod': job = {'_PARENTDIR_': '', '__BAD_DATA__': [], '_REMOTE...orage('npq7', '5')]), '_REMOTE_HOST_': 'unknown'} ].startswith undefined My problem is that the "job =" line is abridging the value. I need to see all of the variables in the dictionary. Is there any way I can wrap cgitb and get the behaviour I want or do I have to write my own method for sys.excepthook? -- 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 mrabarnett.plus.com Thu Sep 2 12:15:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Sep 2010 17:15:24 +0100 Subject: Windows vs. file.read In-Reply-To: References: Message-ID: <4C7FCD9C.9020901@mrabarnett.plus.com> On 02/09/2010 08:49, Lawrence D'Oliveiro wrote: > In message, MRAB > wrote: > >> You should open the files in binary mode, not text mode, ie file(path, >> "rb"). Text mode is the default. Not a problem on *nix because the line >> ending is newline. > > We used to pride ourselves on not having to worry about text versus binary > I/O modes on *nix, but I?m beginning to think the reality is we have to > adopt it. > > To start with, it means we can automatically handle different newline > conventions with text files originating on different systems. In Python 3 the difference is important because binary mode works with bytes and text mode works with strings, plus the file encoding and line endings. From __peter__ at web.de Thu Sep 2 13:02:35 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 19:02:35 +0200 Subject: Customizing cgitb References: Message-ID: D'Arcy J.M. Cain wrote: > I have a small problem with the cgitb module. I know that I can > basically write my own version but it seems kind of silly to rewrite > something that does 99% what I want. Here is an excerpt from the > output of an exception. > > 1520 (current_job['job_id'], job['_SELECT_'])) > 1521 > 1522 elif job['_ACTION_'].startswith('queue_'): > 1523 action = job['_ACTION_'][6:] > 1524 if action == 'mod': > job = {'_PARENTDIR_': '', '__BAD_DATA__': [], '_REMOTE...orage('npq7', > '5')]), '_REMOTE_HOST_': 'unknown'} ].startswith undefined > > My problem is that the "job =" line is abridging the value. I need to > see all of the variables in the dictionary. Is there any way I can > wrap cgitb and get the behaviour I want or do I have to write my own > method for sys.excepthook? You could try to monkey-patch pydoc: import pydoc def cram(text, maxlen): return text pydoc.cram = cram Peter From 71david at libero.it Thu Sep 2 13:03:51 2010 From: 71david at libero.it (David) Date: Thu, 2 Sep 2010 19:03:51 +0200 Subject: Help needed with Windows Service in Python References: Message-ID: Il Thu, 02 Sep 2010 16:22:04 +0100, Ian Hobson ha scritto: > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) You may try to give a WaitHint parameter to ReportServiceStatus call, otherwise the Service Manager will expect the service is stopped istantly. self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 1000) David From tim.wintle at teamrubber.com Thu Sep 2 13:05:47 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 02 Sep 2010 18:05:47 +0100 Subject: Speed-up for loops In-Reply-To: <20100902141339.GA31040@localhost> References: <4C7F7640.1010102@perfect-kreim.de> <20100902141339.GA31040@localhost> Message-ID: <1283447147.17916.1.camel@tim-laptop> On Thu, 2010-09-02 at 16:13 +0200, Roland Koebler wrote: > Hi, > > > Are there any ways to speed up the for/xrange loop? > You can use psyco. Assuming you've got a 32-bit machine. From vs at it.uu.se Thu Sep 2 13:12:54 2010 From: vs at it.uu.se (Virgil Stokes) Date: Thu, 02 Sep 2010 19:12:54 +0200 Subject: Financial time series data Message-ID: <4C7FDB16.9020208@it.uu.se> Has anyone written code or worked with Python software for downloading financial time series data (e.g. from Yahoo financial)? If yes, would you please contact me. --Thanks, V. Stokes From darcy at druid.net Thu Sep 2 13:30:45 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 2 Sep 2010 13:30:45 -0400 Subject: Customizing cgitb In-Reply-To: References: Message-ID: <20100902133045.c8b944fb.darcy@druid.net> On Thu, 02 Sep 2010 19:02:35 +0200 Peter Otten <__peter__ at web.de> wrote: > You could try to monkey-patch pydoc: I suppose so. Not a comfortable solution of course. It's bad enough when you get too familiar with the internals of a module but even worse when you need to get familiar with the internals of modules imported by a module. I'll give it a shot though. > import pydoc > def cram(text, maxlen): > return text > pydoc.cram = cram Or... import pydoc pydoc.cram = lambda text,maxlen: text Thanks. -- 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 pbloom at crystald.com Thu Sep 2 14:12:50 2010 From: pbloom at crystald.com (Philip Bloom) Date: Thu, 2 Sep 2010 11:12:50 -0700 Subject: Speed-up for loops In-Reply-To: References: Message-ID: <2DEFEB25B65B1D4C962D79E3CCBAFC7F09C03467@mpkexc01.eidos.com> Uh. Try: Imax=1000000000 a=0 i=0 While(i I was comparing the speed of a simple loop program between Matlab and > Python. > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Are there any ways to speed up the for/xrange loop? Sure; the above can be reduced to just: print imax * 10 ;) More seriously, if you're comparing against Matlab, you should look at NumPy. If there's a reasonably direct approach using NumPy, it will be much quicker than a Python "for" loop (in a sense, NumPy is a library of useful "for" loops implemented in C). Even a fairly indirect NumPy approach is often quicker than pure Python. -- http://mail.python.org/mailman/listinfo/python-list ______________________________________________________________________ This email has been scanned by the MessageLabs ______________________________________________________________________ ______________________________________________________________________ This email has been scanned by the MessageLabs ______________________________________________________________________ From ipatrol6010 at yahoo.com Thu Sep 2 14:13:51 2010 From: ipatrol6010 at yahoo.com (ipatrol6010 at yahoo.com) Date: Thu, 2 Sep 2010 14:13:51 -0400 Subject: Help needed with Windows Service in Python Message-ID: Well for one, if you're writing with pywin32, you certainly don't need the shbang line. #! /usr/bin/env is purely a POSIX thing. From hidura at gmail.com Thu Sep 2 14:15:06 2010 From: hidura at gmail.com (Hidura) Date: Thu, 2 Sep 2010 15:15:06 -0300 Subject: Financial time series data In-Reply-To: <4C7FDB16.9020208@it.uu.se> References: <4C7FDB16.9020208@it.uu.se> Message-ID: But what kind of data you want to download?, because the financial time it's basicly html code and you can work very well with a parser 2010/9/2, Virgil Stokes : > Has anyone written code or worked with Python software for downloading > financial time series data (e.g. from Yahoo financial)? If yes, would you > please contact me. > > --Thanks, > V. Stokes > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From ipatrol6010 at yahoo.com Thu Sep 2 14:21:23 2010 From: ipatrol6010 at yahoo.com (ipatrol6010 at yahoo.com) Date: Thu, 2 Sep 2010 14:21:23 -0400 Subject: Windows vs. file.read Message-ID: Correct in that regard. In Python 3.x, strings are by default considered UTF-8. Wheras ASCII isn't a problem because it's fixed-width, UTF-8 will give you a different character depending on the last byte value. Therefore handling any kind of data that is not UTF-8 will need you to open it with 'b' and uses bytes instead of str (literals with b'some value'). Just an FYI. From victorsubervi at gmail.com Thu Sep 2 14:34:46 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 2 Sep 2010 14:34:46 -0400 Subject: MySQL Problem Message-ID: Hi; I have this code: print 'select * from spreadsheets s join products p on p.Item=s.Item join productsCategories pc on p.ID=pc.ProductsID join categories c on pc.CategoryID=c.ID where s.Client="%s" order by c.Category, c.Parent' % (client,) cursor.execute('select * from spreadsheets s join products p on p.Item=s.Item join productsCategories pc on p.ID=pc.ProductsID join categories c on pc.CategoryID=c.ID where s.Client=%s order by c.Category, c.Parent', (client,)) tmp = cursor.fetchall() print tmp Now, when I run the print of the mysql command in the mysql interpreter, it gives me the following data: mysql> select * from spreadsheets s join products p on p.Item=s.Item join productsCategories pc on p.ID=pc.ProductsID join categories c on pc.CategoryID=c.ID where s.Client='Lincoln_Properties' order by c.Category, c.Parent; +-----+--------------------+-------+------------+--------+------+-----+------------+------------------------------------------------------+---------+-------+-----+------------+------------+----+-------------------+----------------------+ | ID | Client | Multi | Item | Markup | Temp | ID | Item | Description | UOM | Cost | ID | ProductsID | CategoryID | ID | Category | Parent | +-----+--------------------+-------+------------+--------+------+-----+------------+------------------------------------------------------+---------+-------+-----+------------+------------+----+-------------------+----------------------+ | 163 | Lincoln_Properties | 0 | 5349513 | 53.22 | NULL | 39 | 5349513 | 24833RNH 24" x 33 " 8 Mic Natural Can Liners | 1000/CS | 25.63 | 39 | 39 | 23 | 23 | Can Liners | Bags | | 156 | Lincoln_Properties | 0 | 5349520 | 30.00 | NULL | 31 | 5349520 | Can Liners Coreless 45 gal Clear | 250/CS | 28.69 | 31 | 31 | 23 | 23 | Can Liners | Bags | | 161 | Lincoln_Properties | 0 | 40x48Green | 99.32 | NULL | 37 | 40x48Green | Green Can Liners | 1000/cs | 17.56 | 37 | 37 | 23 | 23 | Can Liners | Bags | | 160 | Lincoln_Properties | 0 | 24x33Green | 60.04 | NULL | 36 | 24x33Green | Green Can Liners | 1000/CS | 20.27 | 36 | 36 | 23 | 23 | Can Liners | Bags | | 162 | Lincoln_Properties | 0 | 5349518 | 26.02 | NULL | 38 | 5349518 | 28048VNR01 40" x 48" HI-D | 250/CS | 25.63 | 38 | 38 | 1 | 1 | Facility Supplies | BASE | | 152 | Lincoln_Properties | 0 | 4440120 | 72.44 | NULL | 35 | 4440120 | 91315 Pearlescent White Lotion Gallon Soap | 4/CS | 17.85 | 35 | 35 | 67 | 67 | Liquid Hand | Soap | | 609 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | 343 | 2030572 | Americo 20" Beige Floor Pad | 5/cs | 15.88 | 335 | 343 | 49 | 49 | Mats | Restaurant Paper/Pla | | 159 | Lincoln_Properties | 0 | 2028071 | 20.00 | NULL | 34 | 2028071 | 25025088 77 Sanisac Liner | 500/CS | 14.88 | 34 | 34 | 34 | 34 | Tampons | Bathroom Paper | | 158 | Lincoln_Properties | 0 | 2062866 | 33.31 | NULL | 33 | 2062866 | 7410 1/2 Fold Seat Cover | 3000/CS | 35.81 | 33 | 33 | 35 | 35 | Toilet Seat Cover | Bathroom Paper | | 155 | Lincoln_Properties | 0 | 5380447 | 30.00 | NULL | 30 | 5380447 | Scottfold Foldedd Towel 1-Ply White | 4375/CS | 35.00 | 30 | 30 | 33 | 33 | Toilet Tissue | Bathroom Paper | | 154 | Lincoln_Properties | 0 | 5207270 | 7.01 | NULL | 29 | 5207270 | Standard Roll Bath Tissue 2-Ply White | 80/CS | 43.50 | 29 | 29 | 33 | 33 | Toilet Tissue | Bathroom Paper | | 164 | Lincoln_Properties | 0 | 5207269 | 20.00 | NULL | 28 | 5207269 | 17713-00 Kleenex Cottonelle 2-Ply Toilet Tissue | 60/CS | 35.50 | 28 | 28 | 33 | 33 | Toilet Tissue | Bathroom Paper | | 157 | Lincoln_Properties | 0 | 5217344 | 17.49 | NULL | 32 | 5217344 | 1900-60 Kleenex Scottfold White Towel | 2400/CS | 26.81 | 32 | 32 | 32 | 32 | Towels | Bathroom Paper | +-----+--------------------+-------+------------+--------+------+-----+------------+------------------------------------------------------+---------+-------+-----+------------+------------+----+-------------------+----------------------+ 13 rows in set (0.00 sec) You will notice there is this data therein: | 609 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | 343 | 2030572 | Americo 20" Beige Floor Pad | 5/cs | 15.88 | 335 | 343 | 49 | 49 | Mats | Restaurant Paper/Pla | That particular item does *not* show up when I print tmp! That is, for some reason running the command through python *omits* this one data!! The only difference is that a flag in spreadsheets (Temp) is set to 1. Why on earth doesn't it work in python?? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From hobson42 at gmaiil.com Thu Sep 2 14:45:01 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 02 Sep 2010 19:45:01 +0100 Subject: Help needed with Windows Service in Python In-Reply-To: References: Message-ID: <4C7FF0AD.1030203@gmaiil.com> On 02/09/2010 18:03, David wrote: > Il Thu, 02 Sep 2010 16:22:04 +0100, Ian Hobson ha scritto: > >> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > You may try to give a WaitHint parameter to ReportServiceStatus call, > otherwise the Service Manager will expect the service is stopped istantly. > > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 1000) > > > David Thanks David. Sadly that makes no difference. From victorsubervi at gmail.com Thu Sep 2 14:51:04 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 2 Sep 2010 14:51:04 -0400 Subject: Reversing a List In-Reply-To: References: <20100901141554.a8d606f0.matt@scotweb.co.uk> Message-ID: On Wed, Sep 1, 2010 at 9:26 AM, Shashwat Anand wrote: > > > On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton wrote: > >> On Wed, 1 Sep 2010 09:00:03 -0400 >> Victor Subervi wrote: >> >> > Hi; >> > I have this code: >> > >> > cursor.execute('describe products;') >> > cols = [item[0] for item in cursor] >> > cols = cols.reverse() >> > cols.append('Delete') >> > cols = cols.reverse() >> > >> > Unfortunately, the list doesn't reverse. If I print cols after the first >> > reverse(), it prints None. Please advise. >> >> The reverse() method modifies the list in place, but returns None, so just >> use >> >>> cols.reverse() >> >> rather than >> >>> cols = cols.reverse() >> > > Alternatively you can do \, > > >>>cols = reversed(cols) > Thanks again, all beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From hobson42 at gmaiil.com Thu Sep 2 15:02:24 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 02 Sep 2010 20:02:24 +0100 Subject: MySQL Problem In-Reply-To: References: Message-ID: <4C7FF4C0.1010503@gmaiil.com> On 02/09/2010 19:34, Victor Subervi wrote: > for some reason running the command through python *omits* this one > data!! The only difference is that a flag in spreadsheets (Temp) is > set to 1. Why on earth doesn't it work in python?? Some ideas to follow up. (These are only guesses). 1) One of the enum type fields contains an invalid value (perhaps a value removed from the column definition). 2) The second id field (products.id?) appears to be very large. I wonder what would happen if it was larger than the auto-increment value? 3) A field in the one of the rows in the missing data contains bytes that are invalid in the character encoding you are using in python. 4) The python field type used for some column in the missing row, contains a value that cannot be held in the python variable assigned. Regards Ian From ekozlowski1 at gmail.com Thu Sep 2 15:06:48 2010 From: ekozlowski1 at gmail.com (Edward Kozlowski) Date: Thu, 2 Sep 2010 12:06:48 -0700 (PDT) Subject: Help needed with Windows Service in Python References: Message-ID: On Sep 2, 10:22?am, Ian Hobson wrote: > Hi All, > > I am attempting to create a Windows Service in Python. > > I have the framework (from Mark Hammond and Andy Robinason's book) > running - see below. It starts fine - but it will not stop. :( > > net stop "Python Service" > > and using the services GUI both leave the services showing it as "stopping" > > I guess this means SvcStop is called but it is not enough to get it out > of the machine. > > Does anyone know why not? > > Python 2.7 with win32 extensions, sunning on Windows 7. > > Many thanks > > Ian > > the (complete) source code is > #!/usr/bin/env python > # coding=utf8 > # ? service.py ?= testing services and Named pipes > # > import win32serviceutil > import win32service > import win32event > class PythonService(win32serviceutil.ServiceFramework): > ? ?_svc_name_ = "Python Service" > ? ?_svc_display_name_ = "Test Service in Python" > ? ?def __init__(self, args): > ? ? ?win32serviceutil.ServiceFramework.__init__(self,args) > ? ? ?self.hWaitStop = win32event.CreateEvent(None,0,0,None) > ? ?def SvcStop(self): > ? ? ?self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > ? ? ?wind32event.SetEvent(self.hWaitStop) > ? ?def SvcDoRun(self): > ? ? ?win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) > if __name__ == '__main__': > ? ?win32serviceutil.HandleCommandLine(PythonService) Looks to me like there may be a typo in your code. You probably meant win32event.SetEvent(self.hWaitStop), not wind32event. Regards, -Edward Kozlowski From __peter__ at web.de Thu Sep 2 15:13:24 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Sep 2010 21:13:24 +0200 Subject: Speed-up for loops References: Message-ID: Philip Bloom wrote: > Uh. > Try: > Imax=1000000000 > a=0 > i=0 > While(i a= a+10 > i=i+1 > print a > I suspect you will find it is way faster than using range or xrange for > large numbers and map far more closely in the final result to what you > are doing on matlab's side. At least last I checked, xrange and range > both involve iterating through an array, which is much slower in all > cases than just doing an int vs int compare (which is what your matlab > is doing). How did you check? $ python -m timeit "for i in xrange(1000000): pass" 10 loops, best of 3: 47.5 msec per loop $ python -m timeit "i = 0" "while i < 1000000: i += 1" 10 loops, best of 3: 152 msec per loop $ So an empty while loop takes about three times as long as the equivalent for loop. Also: """ class xrange(object) | xrange([start,] stop[, step]) -> xrange object | | Like range(), but instead of returning a list, returns an object that | generates the numbers in the range on demand. For looping, this is | slightly faster than range() and more memory efficient. """ Peter From thomas at jollybox.de Thu Sep 2 15:30:56 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 2 Sep 2010 21:30:56 +0200 Subject: Windows vs. file.read In-Reply-To: References: Message-ID: <201009022130.56813.thomas@jollybox.de> On Thursday 02 September 2010, it occurred to ipatrol6010 at yahoo.com to exclaim: > Correct in that regard. In Python 3.x, strings are by default considered > UTF-8. Wheras ASCII isn't a problem because it's fixed-width, UTF-8 will > give you a different character depending on the last byte value. Therefore > handling any kind of data that is not UTF-8 will need you to open it with > 'b' and uses bytes instead of str (literals with b'some value'). Except if it's text of a known encoding, in which case you just open it with that encoding. From hobson42 at gmaiil.com Thu Sep 2 15:38:35 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 02 Sep 2010 20:38:35 +0100 Subject: Help needed with Windows Service in Python In-Reply-To: References: Message-ID: <4C7FFD3B.9060904@gmaiil.com> On 02/09/2010 20:06, Edward Kozlowski wrote: > On Sep 2, 10:22 am, Ian Hobson wrote: >> Hi All, >> >> I am attempting to create a Windows Service in Python. >> >> I have the framework (from Mark Hammond and Andy Robinason's book) >> running - see below. It starts fine - but it will not stop. :( >> >> net stop "Python Service" >> >> and using the services GUI both leave the services showing it as "stopping" >> >> I guess this means SvcStop is called but it is not enough to get it out >> of the machine. >> >> Does anyone know why not? >> >> Python 2.7 with win32 extensions, sunning on Windows 7. >> >> Many thanks >> >> Ian >> >> the (complete) source code is >> #!/usr/bin/env python >> # coding=utf8 >> # service.py = testing services and Named pipes >> # >> import win32serviceutil >> import win32service >> import win32event >> class PythonService(win32serviceutil.ServiceFramework): >> _svc_name_ = "Python Service" >> _svc_display_name_ = "Test Service in Python" >> def __init__(self, args): >> win32serviceutil.ServiceFramework.__init__(self,args) >> self.hWaitStop = win32event.CreateEvent(None,0,0,None) >> def SvcStop(self): >> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) >> wind32event.SetEvent(self.hWaitStop) >> def SvcDoRun(self): >> win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) >> if __name__ == '__main__': >> win32serviceutil.HandleCommandLine(PythonService) > Looks to me like there may be a typo in your code. > > You probably meant win32event.SetEvent(self.hWaitStop), not > wind32event. > > Regards, > -Edward Kozlowski A huge big thank you Edward. That was the problem. Regards Ian From ekozlowski1 at gmail.com Thu Sep 2 15:55:19 2010 From: ekozlowski1 at gmail.com (Edward Kozlowski) Date: Thu, 2 Sep 2010 12:55:19 -0700 (PDT) Subject: Help needed with Windows Service in Python References: Message-ID: <288bf7ad-9251-40d7-9270-e938170a8ed0@x25g2000yqj.googlegroups.com> On Sep 2, 2:38?pm, Ian wrote: > ? On 02/09/2010 20:06, Edward Kozlowski wrote: > > > > > On Sep 2, 10:22 am, Ian Hobson ?wrote: > >> Hi All, > > >> I am attempting to create a Windows Service in Python. > > >> I have the framework (from Mark Hammond and Andy Robinason's book) > >> running - see below. It starts fine - but it will not stop. :( > > >> net stop "Python Service" > > >> and using the services GUI both leave the services showing it as "stopping" > > >> I guess this means SvcStop is called but it is not enough to get it out > >> of the machine. > > >> Does anyone know why not? > > >> Python 2.7 with win32 extensions, sunning on Windows 7. > > >> Many thanks > > >> Ian > > >> the (complete) source code is > >> #!/usr/bin/env python > >> # coding=utf8 > >> # ? service.py ?= testing services and Named pipes > >> # > >> import win32serviceutil > >> import win32service > >> import win32event > >> class PythonService(win32serviceutil.ServiceFramework): > >> ? ? _svc_name_ = "Python Service" > >> ? ? _svc_display_name_ = "Test Service in Python" > >> ? ? def __init__(self, args): > >> ? ? ? win32serviceutil.ServiceFramework.__init__(self,args) > >> ? ? ? self.hWaitStop = win32event.CreateEvent(None,0,0,None) > >> ? ? def SvcStop(self): > >> ? ? ? self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > >> ? ? ? wind32event.SetEvent(self.hWaitStop) > >> ? ? def SvcDoRun(self): > >> ? ? ? win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) > >> if __name__ == '__main__': > >> ? ? win32serviceutil.HandleCommandLine(PythonService) > > Looks to me like there may be a typo in your code. > > > You probably meant win32event.SetEvent(self.hWaitStop), not > > wind32event. > > > Regards, > > -Edward Kozlowski > > A huge big thank you Edward. ?That was the problem. > > Regards > > Ian You're most welcome. If you're looking at running services in Windows using Python, one other hangup I ran into was that my services would freeze for no reason. At Pycon '09, I learned that there were buffers for stdout and stderr that were filling. I wish I could remember who gave the talk that included the jewel of knowledge, because I'd love to give credit where it's due... After I redirected stdout and stderr to files, my problems with the services freezing went away. Regards, -Edward Kozlowski From aahz at pythoncraft.com Thu Sep 2 15:58:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Sep 2010 12:58:49 -0700 Subject: killing all subprocess childrens References: <4C7F1607.8040308@al.com.au> Message-ID: In article , Astan Chee wrote: >Chris Rebert wrote: >> >> import os >> import psutil # http://code.google.com/p/psutil/ >> >> # your piece of code goes here >> >> myself = os.getpid() >> for proc in psutil.process_iter(): > >Is there a way to do this without psutil or installing any external >modules or doing it from python2.5? Lightly edited code I wrote yesterday: cmd = ['ps', '-eo', 'pid,ppid'] output = Popen(cmd, stdout=PIPE).communicate()[0] output = output.split('\n')[1:] # skip the header for row in output: if not row: continue child_pid, parent_pid = row.split() if parent_pid == str(pid): child_pid = int(child_pid) os.kill(child_pid, signal.SIGUSR1) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From pavlovevidence at gmail.com Thu Sep 2 16:01:40 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 2 Sep 2010 13:01:40 -0700 (PDT) Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <60511c27-1995-4deb-beb0-4fb47773b40d@i13g2000yqd.googlegroups.com> On Sep 2, 5:55?am, Tim Wintle wrote: > On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: > > Hi, > > > I was comparing the speed of a simple loop program between Matlab and > > Python. > > Unfortunately my Python Code was much slower and I do not understand why. > > The main reason is that, under the hood, cpython does something like > this (in psudo-code) > > itterator = xrange(imax) > while 1: > ? next_attribute = itterator.next > ? try: > ? ? i = next_attribute() > ? except: > ? ? break > ? a = a + 10 > > where C (and I'm assuming matlab) does this: > > while 1: > ? i = i + 1 > ? if (i > imax): > ? ? break > ? a = a + 10 Not really. Someone already posted timings of the while-loop version in Python and it's much slower than the for loop. The iterator stuff is a minor overhead. The real reason is simple and boring: many languages optimize loops like this, Python doesn't. Matlab has a hundred paid engineers who's job is to optimize it, and its focus is mathematics, so of course they're going to pull out every stop to get simple loops like the above as fast as possible. > And the function call in the python is fairly expensive on it's own. > Plus it has to do all the standard interpreter stuff for memory > management and deciding when to give up the GIL etc. Matlab has all that stuff too (it's memory management is much, much worse than Python's, in fact, but memory management usually doesn't play into tight loop timings). > > Are there any ways to speed up the for/xrange loop? > > leaving it in python, no. (well, "range" is faster in 2.x, but once you > get some cache misses due to increased memory usage it's much slower) > > avoiding iteration by using list comprehensions can help a lot though as > it avoids most of the function calls. List comprehensions use iteration and don't avoid function calls relative to equivalent for-loops. I think the main reason they're a little faster is they can use tighter bytecode. > If you really need to optimise it then you can convert that module to > cython by adding a cdef, and then compile it: > > cdef int i > for i in xrange(imax): > ? ? ?a = a + 10 > print a > > or you can write it in C it'll run a lot faster. numpy is terrific when you can use it, and I've found that it can do a lot more than most people expect. The hard part is figuring out how. In particular, numpy will trounce Matlab's performance for large amounts of data, because of the aforementioned memory management problem. Carl Banks From raoulbia at gmail.com Thu Sep 2 16:37:01 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 2 Sep 2010 13:37:01 -0700 (PDT) Subject: bisection method: Simulating a retirement fund Message-ID: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> level: beginner exercise source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset4.pdf Problem 4 Can my code be optimised? I think my approach is correct but i am hesitant about the initial max value. def nestEgVariable(salary, save, preRetireGrowthRates): SavingsRecord = [] fund = 0 depositPerYear = salary * save * 0.01 for i in preRetireGrowthRates: fund = fund * (1 + 0.01 * i) + depositPerYear SavingsRecord += [fund,] startingPot = SavingsRecord[-1] return startingPot def expenseCalculator(postRetireGrowthRates,fundsize,epsilon,yearsOfretirement ): low = 0 high = fundsize guess = (low + high) /2 while abs(guess * yearsOfretirement - fundsize) > epsilon: if guess * yearsOfretirement > fundsize : high = guess else: low = guess guess = (low + high) /2 return guess def findMaxExpenses(salary,save,preRetireGrowthRates, postRetireGrowthRates,epsilon): yearsOfretirement = len(postRetireGrowthRates) fundsize = nestEgVariable(salary, save, preRetireGrowthRates) for growthRate in postRetireGrowthRates: expenses = expenseCalculator(postRetireGrowthRates, fundsize ,epsilon,yearsOfretirement ) fundsize = (fundsize * (1 + 0.01 * growthRate)) - expenses print 'fundsize', fundsize print 'expenses', expenses yearsOfretirement -=1 return fundsize findMaxExpenses(10000,10,[3, 4, 5, 0, 3],[10, 5, 0, 5, 1],0.01) thanks Baba From tjreedy at udel.edu Thu Sep 2 16:47:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Sep 2010 16:47:16 -0400 Subject: Performance: sets vs dicts. In-Reply-To: <4a3665a0-fc7f-425a-878e-6f8dcc5ed319@y11g2000yqm.googlegroups.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <7a38148b-79e9-40ce-9700-2c0d1c9b3ee4@a4g2000prm.googlegroups.com> <4a3665a0-fc7f-425a-878e-6f8dcc5ed319@y11g2000yqm.googlegroups.com> Message-ID: On 9/1/2010 10:57 PM, rurpy at yahoo.com wrote: > So while you may "think" most people rarely read > the docs for basic language features and objects > (I presume you don't mean to restrict your statement > to only sets), I and most people I know *do* read > them. And when read them I expect them, as any good > reference documentation does, to completely and > accurately describe the behavior of the item I am > reading about. If big-O performance is deemed an > intrinsic behavior of an (operation of) an object, > it should be described in the documentation for > that object. However, big-O performance is intentionally NOT so deemed. And I have and would continue to argue that it should not be, for multiple reasons. Performance is a feature of implementations, and I think they should be documented. > This is not to say that a performance HOWTO or FAQ > in addition to the reference manual would not be good. I have writing a draft of such for CPython on my personal todo list. -- Terry Jan Reedy From nagle at animats.com Thu Sep 2 17:07:38 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Sep 2010 14:07:38 -0700 Subject: Obscure MySQLdb question - duplicating a database handle Message-ID: <4c801218$0$1622$742ec2ed@news.sonic.net> I have a system which does error logging to its database: db = MySQLdb.connect(...) # get database connection ... errorlog(db, "Message") The problem is that I want errorlog to commit its message to the table used for error logging, but don't want to commit whatever the caller was doing - that may well revert. MySQL doesn't support nested transactions, so that won't help. At the many points errorlog is called, only the database handle is available, not the params used for "connect". Is there something like UNIX "dup" for database connections in MySQLdb, or can I get the connection parameters (username, password, database, etc.) from the "db" object? John Nagle From nagle at animats.com Thu Sep 2 17:19:01 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Sep 2010 14:19:01 -0700 Subject: PyPy and RPython In-Reply-To: References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> Message-ID: <4c8014c2$0$1602$742ec2ed@news.sonic.net> On 9/2/2010 1:29 AM, sarvi wrote: > When I think about it these restrictions below seem a very reasonable > tradeoff for performance. Yes. > And I can use this for just the modules/sections that are performance > critical. Not quite. Neither Shed Skin nor RPython let you call from restricted code to unrestricted code. That tends to happen implicitly as objects are passed around. It's the global analysis that makes this work; when you call something, you need to know more about it than how to call it. John Nagle From tjreedy at udel.edu Thu Sep 2 17:55:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Sep 2010 17:55:59 -0400 Subject: Performance: sets vs dicts. In-Reply-To: <87aao1c8dk.fsf@castleamber.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> <87aao1c8dk.fsf@castleamber.com> Message-ID: On 9/1/2010 8:11 PM, John Bokma wrote: > Terry Reedy writes: > >> On 9/1/2010 5:40 PM, John Bokma wrote: > > [..] > >> Yes, I switched, because 'constant time' is a comprehensible claim >> that can be refuted and because that is how some will interpret O(1) >> (see below for proof;-). > > You make it now sound as if this interpretation is not correct or out of > place. Saying that an interpretation is comprehensible and common is hardly a putdown ;-). It simply is not unique. I also said that the other interpretation is not coherent for size-limited problems. However, if you mean 'constant', whatever you mean by that, why not say so? Here is the technical definition given in https://secure.wikimedia.org/wikipedia/en/wiki/Big_O_notation I assure you that it is the standard one invented by a mathematiciam over a century ago and used by mathematicians ever since. It was popularized in computer science by Donald Knuth in 1976 and used in The Art of Computer Programming. It is related to the definition of limits. ''' Formal definition Let f(x) and g(x) be two functions defined on some subset of the real numbers. One writes f(x)=O(g(x))\mbox{ as }x\to\infty\, if and only if, for sufficiently large values of x, f(x) is at most a constant multiplied by g(x) in absolute value. That is, f(x) = O(g(x)) if and only if there exists a positive real number M and a real number x0 such that |f(x)| \le \; M |g(x)|\mbox{ for all }x>x_0. ''' For g(x) == 1, this reduces to |f(x)| < M for some M (and large x), which is to say, f(x) is bounded (at least for large x). Hmmm. By that definition, 1/x is O(1). Let x0 be anything but 0 and M = 1/x0. Some might find that disturbing. But it is the nature of the notation, as with limit notation, that is says *nothing* about the behavior of f for small x. > People who have bothered to read ItA will use O(1) and constant > time interchangeably while talking of the order of growth of the running > time algorithms People who have bothered to read the Bidle will use terms the way they are used in the Bible. So what? In other words, I do not regard ItA as scripture in the way you seem to. (I presume you mean the Cormen, etal book. I partially read a library copy over 20 years ago but never bothered to buy a copy. I see it is now into its third edition.) If they disagree with Knuth and most others (which I would not claim without seeing their actual text) then so much the worse for them. > and most of those are aware that 'big oh' hides a > constant, and that in the real world a O(log n) algorithm can outperform > an O(1) algorithm for small values of n. Right. And if 'small values of n' include all possible values, then rejecting a particular O(log n) algorithm as 'unacceptable' relative to all O(1) algorithms is pretty absurd. >>> Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, >>> 2nd edition. Given that the Wikipedia article references that section also, I wonder if it really disagrees with the definition above. -- Terry Jan Reedy From nkaunda at yahoo.com Thu Sep 2 18:01:10 2010 From: nkaunda at yahoo.com (Nally Kaunda-Bukenya) Date: Thu, 2 Sep 2010 15:01:10 -0700 (PDT) Subject: Sum of product-please help Message-ID: <500917.93744.qm@web33502.mail.mud.yahoo.com> Dear all, kindly help me with this code; This script? is supposed to calculate Rvi for each row by first summing the product of #fields (Ai*Rv) and dividing by another field (Tot) such that? Rvi=sum(Ai*Rv)/Tot. First it's acting like I need another parenthesis and it doesn't seem to work at all. i even imported the math module, but not sure if a need it. Please advice, your help is highly appreciated.? Please see the code below: import arcpy, math arcpy.Workspace = "C:\\data\\basins.mdb" fc = "wshed" sum = 0 ??????? # Create the update cursor and advance the cursor to the first row cur = arcpy.UpdateCursor(fc) row = cur.Next() # Perform the update and move to the next row as long as there are #? rows left for row: ??? row.GetValue(Rvi) = sum(row.Ai*row.Rv)/row.ATot ??? cur.UpdateRow(row) ??? row = cur.Next() # Delete the cursors to remove any data locks del row, cur? -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Sep 2 18:10:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Sep 2010 23:10:42 +0100 Subject: bisection method: Simulating a retirement fund In-Reply-To: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> References: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> Message-ID: <4C8020E2.9040803@mrabarnett.plus.com> On 02/09/2010 21:37, Baba wrote: > level: beginner > > exercise source: > http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset4.pdf > > Problem 4 > > Can my code be optimised? > I think my approach is correct but i am hesitant about the initial max > value. > > def nestEgVariable(salary, save, preRetireGrowthRates): > SavingsRecord = [] > fund = 0 > depositPerYear = salary * save * 0.01 > for i in preRetireGrowthRates: > fund = fund * (1 + 0.01 * i) + depositPerYear > SavingsRecord += [fund,] > startingPot = SavingsRecord[-1] > return startingPot > Why are you saving 'fund' in SavingsRecord if you're returning just the last and discarding others? Basically you're returning the final value of fund. > > def > expenseCalculator(postRetireGrowthRates,fundsize,epsilon,yearsOfretirement ): > low = 0 > high = fundsize > guess = (low + high) /2 > while abs(guess * yearsOfretirement - fundsize)> epsilon: > if guess * yearsOfretirement> fundsize : > high = guess > else: low = guess > guess = (low + high) /2 > return guess > When performing this type of 'search' make sure that the interval (high - low) reduces at every step. If, for example: low + 1 == high then: guess == (low + (low + 1)) / 2 == (low * 2 + 1) / 2 == low (integer division) and if the 'if' condition happens to be false then the value of 'low' won't change for the next iteration, leading to an infinite loop. > > def findMaxExpenses(salary,save,preRetireGrowthRates, > postRetireGrowthRates,epsilon): > yearsOfretirement = len(postRetireGrowthRates) > fundsize = nestEgVariable(salary, save, preRetireGrowthRates) > for growthRate in postRetireGrowthRates: > expenses = expenseCalculator(postRetireGrowthRates, > > fundsize ,epsilon,yearsOfretirement ) > fundsize = (fundsize * (1 + 0.01 * growthRate)) - expenses > print 'fundsize', fundsize > print 'expenses', expenses > yearsOfretirement -=1 > return fundsize > > > > findMaxExpenses(10000,10,[3, 4, 5, 0, 3],[10, 5, 0, 5, 1],0.01) > From tjreedy at udel.edu Thu Sep 2 18:14:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Sep 2010 18:14:42 -0400 Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) In-Reply-To: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: On 9/1/2010 9:08 PM, Dmitry Chichkov wrote: > Given: a large list (10,000,000) of floating point numbers; > Task: fastest python code that finds k (small, e.g. 10) smallest > items, preferably with item indexes; > Limitations: in python, using only standard libraries (numpy& scipy > is Ok); > > I've tried several methods. With N = 10,000,000, K = 10 The fastest so > far (without item indexes) was pure python implementation > nsmallest_slott_bisect (using bisect/insert). And with indexes > nargsmallest_numpy_argmin (argmin() in the numpy array k times). > > Anyone up to the challenge beating my code with some clever selection > algorithm? > > Current Table: > 1.66864395142 mins_heapq(items, n): > 0.946580886841 nsmallest_slott_bisect(items, n): > 1.38014793396 nargsmallest(items, n): > 10.0732769966 sorted(items)[:n]: > 3.17916202545 nargsmallest_numpy_argsort(items, n): > 1.31794500351 nargsmallest_numpy_argmin(items, n): > 2.37499308586 nargsmallest_numpy_array_argsort(items, n): > 0.524670124054 nargsmallest_numpy_array_argmin(items, n): > > 0.0525538921356 numpy argmin(items): 1892997 > 0.364673852921 min(items): 10.0000026786 Your problem is underspecified;-). Detailed timing comparisons are only valid for a particular Python version running under a particular OS on particular hardware. So, to actually run a contest, you would have to specify a version and OS and offer to run entries on your machine, with as much else as possible turned off, or else enlist a neutral judge to do so. And the timing method should also be specified. -- Terry Jan Reedy From python at mrabarnett.plus.com Thu Sep 2 18:16:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Sep 2010 23:16:43 +0100 Subject: Sum of product-please help In-Reply-To: <500917.93744.qm@web33502.mail.mud.yahoo.com> References: <500917.93744.qm@web33502.mail.mud.yahoo.com> Message-ID: <4C80224B.4010300@mrabarnett.plus.com> On 02/09/2010 23:01, Nally Kaunda-Bukenya wrote: > Dear all, kindly help me with this code; > This script is supposed to calculate Rvi for each row by first summing > the product of #fields (Ai*Rv) and dividing by another field (Tot) such > that Rvi=sum(Ai*Rv)/Tot. First it's acting like I need another > parenthesis and it doesn't seem to work at all. i even imported the math > module, but not sure if a need it. Please advice, your help is highly > appreciated. Please see the code below: > import arcpy, math > arcpy.Workspace = "C:\\data\\basins.mdb" > fc = "wshed" > sum = 0 > It looks like you're using 'sum' as a variable. Bad idea. That hides the 'sum' function which you need later. > # Create the update cursor and advance the cursor to the first row > cur = arcpy.UpdateCursor(fc) > row = cur.Next() > # Perform the update and move to the next row as long as there are > # rows left > for row: Syntax error. It's: for variable in iterator: ... > row.GetValue(Rvi) = sum(row.Ai*row.Rv)/row.ATot Assign to the result of row.GetValue(Rvi)? Is that right? I don't know arcpy, but somehow that doesn't look right to me. > cur.UpdateRow(row) > row = cur.Next() > # Delete the cursors to remove any data locks > del row, cur > From tjreedy at udel.edu Thu Sep 2 18:20:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Sep 2010 18:20:27 -0400 Subject: Speed-up for loops In-Reply-To: <1283432116.14252.37.camel@tim-laptop> References: <4C7F7640.1010102@perfect-kreim.de> <1283432116.14252.37.camel@tim-laptop> Message-ID: On 9/2/2010 8:55 AM, Tim Wintle wrote: > On Thu, 2010-09-02 at 12:02 +0200, Michael Kreim wrote: >> Hi, >> >> I was comparing the speed of a simple loop program between Matlab and >> Python. > >> Unfortunately my Python Code was much slower and I do not understand why. > > The main reason is that, under the hood, cpython does something like > this (in psudo-code) > > itterator = xrange(imax) > while 1: > next_attribute = itterator.next > try: > i = next_attribute() > except: > break > a = a + 10 > > where C (and I'm assuming matlab) does this: > > while 1: > i = i + 1 > if (i> imax): > break > a = a + 10 Which is to say, 'for' in python is not the same as 'for' in C/matlab and the latter is what Michael should use in a fair comparison. Otherwise, apples and oranges. -- Terry Jan Reedy From clp2 at rebertia.com Thu Sep 2 18:24:17 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 2 Sep 2010 15:24:17 -0700 Subject: killing all subprocess childrens In-Reply-To: References: <4C7F1607.8040308@al.com.au> Message-ID: On Thu, Sep 2, 2010 at 12:58 PM, Aahz wrote: > In article , > Astan Chee ? wrote: >>Chris Rebert wrote: >>> >>> import os >>> import psutil # http://code.google.com/p/psutil/ >>> >>> # your piece of code goes here >>> >>> myself = os.getpid() >>> for proc in psutil.process_iter(): >> >>Is there a way to do this without psutil or installing any external >>modules or doing it from python2.5? > > Lightly edited code I wrote yesterday: > > ? ? ? ?cmd = ['ps', '-eo', 'pid,ppid'] > ? ? ? ?output = Popen(cmd, stdout=PIPE).communicate()[0] > ? ? ? ?output = output.split('\n')[1:] ?# skip the header > ? ? ? ?for row in output: > ? ? ? ? ? ?if not row: > ? ? ? ? ? ? ? ?continue > ? ? ? ? ? ?child_pid, parent_pid = row.split() > ? ? ? ? ? ?if parent_pid == str(pid): > ? ? ? ? ? ? ? ?child_pid = int(child_pid) > ? ? ? ? ? ? ? ?os.kill(child_pid, signal.SIGUSR1) Although this doesn't meet the OP's Windows-compatibility requirement. Cheers, Chris From raoulbia at gmail.com Thu Sep 2 18:25:11 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 2 Sep 2010 15:25:11 -0700 (PDT) Subject: Fibonacci: returning a selection of the series References: <87d3t1qo34.fsf@dpt-info.u-strasbg.fr> Message-ID: <2479aafa-231f-4741-b88e-46fa340756b4@y11g2000yqm.googlegroups.com> On Aug 29, 7:18?pm, Alain Ketterlin wrote: > In general, if you have a program that produces something just to > remove/ignore it five lines later, you have a problem. In your case: > > 1) are you sure you need to append to list(*) at every iteration? When > do you *really* need to? And... > > 2) your loop runs up to n (the index of the fib number), but you want to > stop on some fib number value (not index). > > So, why not pass start and end to i_fib, and use them where appropriate? > Hi Alain Thank you for your (pragmatic) suggestions! Based on your input i was able to considerably optimise my approach: def fib_range(start, end): fib_1 = 0 fib_2 = 1 range = [] while fib_2 < end: fib_1, fib_2 = fib_2, fib_1 + fib_2 if fib_2 >= start and fib_2 <= end: range.append(fib_2) return range print fib_range(4,76) Thanks Baba From john at castleamber.com Thu Sep 2 18:35:07 2010 From: john at castleamber.com (John Bokma) Date: Thu, 02 Sep 2010 17:35:07 -0500 Subject: Obscure MySQLdb question - duplicating a database handle References: <4c801218$0$1622$742ec2ed@news.sonic.net> Message-ID: <87pqwv93l0.fsf@castleamber.com> John Nagle writes: > I have a system which does error logging to its database: > > db = MySQLdb.connect(...) # get database connection > ... > errorlog(db, "Message") > > The problem is that I want errorlog to commit its message to > the table used for error logging, but don't want to commit > whatever the caller was doing - that may well revert. > > MySQL doesn't support nested transactions, so that won't help. > At the many points errorlog is called, only the database > handle is available, not the params used for "connect". > > Is there something like UNIX "dup" for database connections > in MySQLdb, or can I get the connection parameters (username, > password, database, etc.) from the "db" object? Maybe I am not clear anymore (long day), but why not make 2 db connections? It might even be better since you can give each one its own user and hence, privileges. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From ron.eggler at gmail.com Thu Sep 2 19:19:45 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 2 Sep 2010 16:19:45 -0700 (PDT) Subject: DeprecationWarning References: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Message-ID: On Sep 1, 5:04?pm, Chris Rebert wrote: > On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: > > Hi There, > > > I would like to create an scp handle and download a file from a > > client. I have following code: > > > but what i'm getting is this and no file is downloaded...: > > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: > > BaseException.message has been deprecated as of Python 2.6 > > ?chan.send('\x01'+e.message) > > 09/01/2010 08:53:56 : Downloading P-file failed. > > > What does that mean and how do i resolve this? > > http://stackoverflow.com/questions/1272138/baseexception-message-depr... > As the warning message says, line 243 of > /opt/lampp/cgi-bin/attachment.py is the cause of the warning. > > However, that's only a warning (albeit probably about a small part of > some error-raising code), not an error itself, so it's not the cause > of the download failure. > Printing out the IOError encountered would be the first step in > debugging the download failure. > > Cheers, > Chris > --http://blog.rebertia.com Hi Chris, Thanks for getting back! I get an "I/O error(2): No such file or directory" error even tho the file i'm trying to copy at /usr/share/NovaxTSP/P0086_2003.xml is present, an "ls /usr/share/NovaxTSP/P0086_2003.xml" on the target is succesful... :( What am i doing wrong? Thanks, Ron From dchichkov at gmail.com Thu Sep 2 19:21:38 2010 From: dchichkov at gmail.com (Dmitry Chichkov) Date: Thu, 2 Sep 2010 16:21:38 -0700 (PDT) Subject: Selecting k smallest or largest elements from a large list in python; (benchmarking) References: <80d81937-f206-4f92-b897-f406ba80b7ef@k17g2000prf.googlegroups.com> Message-ID: <59daca25-3154-4b12-9299-0976bd37c2a9@u6g2000yqh.googlegroups.com> Yes, you are right of course. But it is not really a contest. And if you could improve algorithm or implementation on "your Python version running under your OS on your hardware" it may as well improve performance for other people under other OS's. On Sep 2, 3:14?pm, Terry Reedy wrote: > On 9/1/2010 9:08 PM, Dmitry Chichkov wrote: > > > Your problem is underspecified;-). > Detailed timing comparisons are only valid for a particular Python > version running under a particular OS on particular hardware. So, to > actually run a contest, you would have to specify a version and OS and > offer to run entries on your machine, with as much else as possible > turned off, or else enlist a neutral judge to do so. And the timing > method should also be specified. > > -- > Terry Jan Reedy From clp2 at rebertia.com Thu Sep 2 19:25:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 2 Sep 2010 16:25:39 -0700 Subject: DeprecationWarning In-Reply-To: References: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Message-ID: On Thu, Sep 2, 2010 at 4:19 PM, cerr wrote: > On Sep 1, 5:04?pm, Chris Rebert wrote: >> On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: >> > Hi There, >> >> > I would like to create an scp handle and download a file from a >> > client. I have following code: >> >> > but what i'm getting is this and no file is downloaded...: >> > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: >> > BaseException.message has been deprecated as of Python 2.6 >> > ?chan.send('\x01'+e.message) >> > 09/01/2010 08:53:56 : Downloading P-file failed. >> >> > What does that mean and how do i resolve this? >> >> http://stackoverflow.com/questions/1272138/baseexception-message-depr... >> As the warning message says, line 243 of >> /opt/lampp/cgi-bin/attachment.py is the cause of the warning. >> >> However, that's only a warning (albeit probably about a small part of >> some error-raising code), not an error itself, so it's not the cause >> of the download failure. >> Printing out the IOError encountered would be the first step in >> debugging the download failure. >> >> Cheers, >> Chris > > Hi Chris, > > Thanks for getting back! > I get an "I/O error(2): No such file or directory" error even tho the > file i'm trying to copy at /usr/share/NovaxTSP/P0086_2003.xml is > present, an "ls /usr/share/NovaxTSP/P0086_2003.xml" on the target is > succesful... :( What am i doing wrong? Asking on the Paramiko mailinglist might be more fruitful: http://www.lag.net/mailman/listinfo/paramiko Cheers, Chris From vs at it.uu.se Thu Sep 2 19:56:47 2010 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 03 Sep 2010 01:56:47 +0200 Subject: Financial time series data In-Reply-To: References: <4C7FDB16.9020208@it.uu.se> Message-ID: <4C8039BF.5080407@it.uu.se> On 09/02/2010 08:15 PM, Hidura wrote: > But what kind of data you want to download?, because the financial > time it's basicly html code and you can work very well with a parser > > 2010/9/2, Virgil Stokes: > >> Has anyone written code or worked with Python software for downloading >> financial time series data (e.g. from Yahoo financial)? If yes, would you >> please contact me. >> >> --Thanks, >> V. Stokes >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > Here is a snippet of python code that I am trying to use for downloading financial data; but, I do not understand why it returns information from the second HTML page. import urllib2 ''' I am trying to read each row of the table at: http://finance.yahoo.com/q/cp?s=^GSPC ''' ticker = [] url = urllib2.urlopen("http://download.finance.yahoo.com/d/quotes.csv?s=@%5EGSPC&f=sl1d1t1c1ohgv&e=.csv&h=PAGE".replace('PAGE', str(0))) data = url.read() Note, it does get all 50 rows of the first page; but, why does it also get the first row of the "next" HTML page? --V From skippy.hammond at gmail.com Thu Sep 2 20:38:30 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 03 Sep 2010 10:38:30 +1000 Subject: Help needed with Windows Service in Python In-Reply-To: <4C7FC11C.7030904@ianhobson.co.uk> References: <4C7FC11C.7030904@ianhobson.co.uk> Message-ID: <4C804386.90304@gmail.com> On 3/09/2010 1:22 AM, Ian Hobson wrote: > Hi All, > > I am attempting to create a Windows Service in Python. > > I have the framework (from Mark Hammond and Andy Robinason's book) > running - see below. It starts fine - but it will not stop. :( > > net stop "Python Service" > > and using the services GUI both leave the services showing it as "stopping" > > I guess this means SvcStop is called but it is not enough to get it out > of the machine. > > Does anyone know why not? I expect that the Windows Event Log might have some clues, as would attempting to use it in "debug" mode. > def SvcStop(self): > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > wind32event.SetEvent(self.hWaitStop) Note the typo in the line above... Mark From python at mrabarnett.plus.com Thu Sep 2 20:50:26 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 03 Sep 2010 01:50:26 +0100 Subject: Financial time series data In-Reply-To: <4C8039BF.5080407@it.uu.se> References: <4C7FDB16.9020208@it.uu.se> <4C8039BF.5080407@it.uu.se> Message-ID: <4C804652.6020501@mrabarnett.plus.com> On 03/09/2010 00:56, Virgil Stokes wrote: > On 09/02/2010 08:15 PM, Hidura wrote: >> But what kind of data you want to download?, because the financial >> time it's basicly html code and you can work very well with a parser >> >> 2010/9/2, Virgil Stokes: >>> Has anyone written code or worked with Python software for downloading >>> financial time series data (e.g. from Yahoo financial)? If yes, would >>> you >>> please contact me. >>> >>> --Thanks, >>> V. Stokes >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> > Here is a snippet of python code that I am trying to use for downloading > financial data; but, I do not understand why it returns information from > the second HTML page. > > import urllib2 > ''' > I am trying to read each row of the table at: > http://finance.yahoo.com/q/cp?s=^GSPC > ''' > ticker = [] > url = > urllib2.urlopen("http://download.finance.yahoo.com/d/quotes.csv?s=@%5EGSPC&f=sl1d1t1c1ohgv&e=.csv&h=PAGE".replace('PAGE', > str(0))) > data = url.read() > > Note, it does get all 50 rows of the first page; but, why does it also > get the first row of the "next" HTML page? > Did you try downloading from a browser? That also returns an extra row. Looks like an idiosyncrasy of the site. From hidura at gmail.com Thu Sep 2 20:55:12 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Fri, 03 Sep 2010 00:55:12 +0000 Subject: Financial time series data In-Reply-To: <4C8039BF.5080407@it.uu.se> Message-ID: <0016e656b74e0e26ea048f5062e1@google.com> I've tried to see the page and the code GSPC it's wrong i has used ^DJI, and when you download the page code use a xml parser localize the table element and read it. I can't access from the browser to the next page it doesn't appear as a link. El , Virgil Stokes escribi?: > On 09/02/2010 08:15 PM, Hidura wrote: > But what kind of data you want to download?, because the financial > time it's basicly html code and you can work very well with a parser > 2010/9/2, Virgil Stokesvs at it.uu.se>: > Has anyone written code or worked with Python software for downloading > financial time series data (eg from Yahoo financial)? If yes, would you > please contact me. > --Thanks, > V. Stokes > -- > http://mail.python.org/mailman/listinfo/python-list > Here is a snippet of python code that I am trying to use for downloading > financial data; but, I do not understand why it returns information from > the second HTML page. > import urllib2 > ''' > I am trying to read each row of the table at: > http://finance.yahoo.com/q/cp?s=^GSPC > ''' > ticker = [] > url = > urllib2.urlopen("http://download.finance.yahoo.com/d/quotes.csv?s=@%5EGSPC&f=sl1d1t1c1ohgv&e=.csv&h=PAGE".replace('PAGE', > str(0))) > data = url.read() > Note, it does get all 50 rows of the first page; but, why does it also > get the first row of the "next" HTML page? > --V -------------- next part -------------- An HTML attachment was scrubbed... URL: From ron.eggler at gmail.com Thu Sep 2 21:39:07 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 2 Sep 2010 18:39:07 -0700 (PDT) Subject: DeprecationWarning References: <28e40ad3-25f9-4fb3-ad5b-3ea3fa934bf6@w15g2000pro.googlegroups.com> Message-ID: <916e2640-82ee-4ea6-a010-5a872da105c4@t20g2000yqa.googlegroups.com> On Sep 2, 4:25?pm, Chris Rebert wrote: > On Thu, Sep 2, 2010 at 4:19 PM, cerr wrote: > > On Sep 1, 5:04?pm, Chris Rebert wrote: > >> On Wed, Sep 1, 2010 at 8:58 AM, cerr wrote: > >> > Hi There, > > >> > I would like to create an scp handle and download a file from a > >> > client. I have following code: > >> > >> > but what i'm getting is this and no file is downloaded...: > >> > /opt/lampp/cgi-bin/attachment.py:243: DeprecationWarning: > >> > BaseException.message has been deprecated as of Python 2.6 > >> > ?chan.send('\x01'+e.message) > >> > 09/01/2010 08:53:56 : Downloading P-file failed. > > >> > What does that mean and how do i resolve this? > > >>http://stackoverflow.com/questions/1272138/baseexception-message-depr... > >> As the warning message says, line 243 of > >> /opt/lampp/cgi-bin/attachment.py is the cause of the warning. > > >> However, that's only a warning (albeit probably about a small part of > >> some error-raising code), not an error itself, so it's not the cause > >> of the download failure. > >> Printing out the IOError encountered would be the first step in > >> debugging the download failure. > > >> Cheers, > >> Chris > > > Hi Chris, > > > Thanks for getting back! > > I get an "I/O error(2): No such file or directory" error even tho the > > file i'm trying to copy at /usr/share/NovaxTSP/P0086_2003.xml is > > present, an "ls /usr/share/NovaxTSP/P0086_2003.xml" on the target is > > succesful... :( What am i doing wrong? > > Asking on the Paramiko mailinglist might be more fruitful:http://www.lag.net/mailman/listinfo/paramiko Yep, thanks. I guess I try my luck there then. Thanks! Ron From ldo at geek-central.gen.new_zealand Thu Sep 2 22:25:31 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 03 Sep 2010 14:25:31 +1200 Subject: Windows vs. file.read References: Message-ID: In message , MRAB wrote: > On 02/09/2010 08:49, Lawrence D'Oliveiro wrote: >> In message, MRAB >> wrote: >> >>> You should open the files in binary mode, not text mode, ie file(path, >>> "rb"). Text mode is the default. Not a problem on *nix because the line >>> ending is newline. >> >> We used to pride ourselves on not having to worry about text versus >> binary I/O modes on *nix, but I?m beginning to think the reality is we >> have to adopt it. >> >> To start with, it means we can automatically handle different newline >> conventions with text files originating on different systems. > > In Python 3 the difference is important because binary mode works with > bytes and text mode works with strings, plus the file encoding and line > endings. Yeah, that seems like a reasonable approach?make you decide up-front what exactly is the sort of file content you?re dealing with. From nagle at animats.com Fri Sep 3 00:22:12 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Sep 2010 21:22:12 -0700 Subject: Does MySQLdb rollback on control-C? Maybe not. Message-ID: <4c8077f1$0$1628$742ec2ed@news.sonic.net> I would expect MySQLdb to rollback on a control-C, but it doesn't seem to have done so. I have a program which does a thousand or so INSERT operations in one transaction on an InnoDB table. I kill it with a control-C on Windows, and it aborts. But it looks like some of the INSERT operations took place. Here's the abort, from the middle of an INSERT operation. Filing index item already in database under another date: edgar/data/1455650/0000950123-10-062814.txt Traceback (most recent call last): .... File "C:\projects\sitetruth\edgar\edgarfilingindex.py", line 93, in dbinsert cursor.execute(sql, values) # do the insert File "C:\python26\lib\site-packages\MySQLdb\cursors.py", line 166, in execute self.errorhandler(self, exc, value) File "C:\python26\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue KeyboardInterrupt Terminate batch job (Y/N)? y Checking with the manual MySQL client, looking at the table before and after the run, the table did change when the program ran. Not good. The INSERT looks like this: INSERT INTO edgarfilingindex (cik, company_name, form_type, date_filed, file_name, date_indexed, confidence) VALUES (%s,%s,%s,%s,%s,%s,%s) SHOW CREATE TABLE returns this: CREATE TABLE `edgarfilingindex` ( ... ) ENGINE=InnoDB DEFAULT CHARSET=utf8 so it's definitely an InnoDB table. I have print statements at all commit calls, and there don't seem to be any unwanted commits happening. I'm not doing anything that forces a commit, like RENAME or ALTER or CREATE; it's just simple INSERT operations. I'm not doing an explicit START TRANSACTION, but I shouldn't have to. I put a SHOW VARIABLES LIKE "autocommit" in the program, and it comes back with ("autocommit", "OFF"). So that's not the problem. I even did an explicit START TRANSACTION at the beginning of the update, and it doesn't help. Something is broken. Python 2.6, MySQLdb 1.2.2-py2.6, MySQL 5.1.47-com, Windows 7. John Nagle From sarvilive at gmail.com Fri Sep 3 01:30:59 2010 From: sarvilive at gmail.com (sarvi) Date: Thu, 2 Sep 2010 22:30:59 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> <4c8014c2$0$1602$742ec2ed@news.sonic.net> Message-ID: <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> On Sep 2, 2:19?pm, John Nagle wrote: > On 9/2/2010 1:29 AM, sarvi wrote: > > > When I think about it these restrictions below seem a very reasonable > > tradeoff for performance. > > ? ? Yes. > > > And I can use this for just the modules/sections that are performance > > critical. > > ? ? Not quite. ?Neither Shed Skin nor RPython let you call from > restricted code to unrestricted code. ?That tends to happen > implicitly as objects are passed around. ?It's the global > analysis that makes this work; when you call something, you > need to know more about it than how to call it. It should technically be possible to allow Python to call a module written in RPython? It should also compile RPython to a python module.so right? Sarvi > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle From arnodel at googlemail.com Fri Sep 3 02:17:27 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 03 Sep 2010 07:17:27 +0100 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> <87aao1c8dk.fsf@castleamber.com> Message-ID: Terry Reedy writes: > On 9/1/2010 8:11 PM, John Bokma wrote: [...] >>>> Uhm, O(1) /is/ constant time, see page 45 of Introduction to Algorithms, >>>> 2nd edition. > > Given that the Wikipedia article references that section also, I > wonder if it really disagrees with the definition above. In simple terms, O(1) is *bounded* time. This is not the same as constant, even though it is true that the misleading expression "constant time" is widely used. I emphasized the difference as you seemed to say that describing list element access as O(1) was misleading because for example accessing contiguous elements would be significantly faster that accessing distant ones. This may or may not be the case, but it remains true that this time is bounded and this is what O(1) really means. -- Arnaud From melodybelena at gmail.com Fri Sep 3 02:36:11 2010 From: melodybelena at gmail.com (shai garcia) Date: Fri, 03 Sep 2010 06:36:11 GMT Subject: python database Message-ID: <2010932369usenet@eggheadcafe.com> can you pls help me to make a database program in python? It is a Quiz system which is database driven. The program has a choices which add question, edit, delete, list, take a quiz, quiz results, and exit. in take a quiz choice,questions should be randomly displayed and the result and name of the examinee should be saved as well as the date and time taken. pls help..tnx.Godbless Submitted via EggHeadCafe - Software Developer Portal of Choice Book Review: Excel 2010 - The Missing Manual [OReilly] http://www.eggheadcafe.com/tutorials/aspnet/7d211741-221d-46c7-b9c3-d34bf84568be/book-review-excel-2010--the-missing-manual-oreilly.aspx From melodybelena at gmail.com Fri Sep 3 02:38:55 2010 From: melodybelena at gmail.com (shai garcia) Date: Fri, 03 Sep 2010 06:38:55 GMT Subject: python database Message-ID: <20109323853usenet@eggheadcafe.com> can you pls help me to make a database program in python? It is a Quiz system which is database driven. The program has a choices which add question, edit, delete, list, take a quiz, quiz results, and exit. in take a quiz choice,questions should be randomly displayed and the result and name of the examinee should be saved as well as the date and time taken. pls help..tnx.Godbless Submitted via EggHeadCafe - Software Developer Portal of Choice Kentico CMS for ASP.NET Sites http://www.eggheadcafe.com/tutorials/aspnet/ee551a85-2206-446e-bc7d-c978f60ec671/kentico-cms-for-aspnet-sites.aspx From ldo at geek-central.gen.new_zealand Fri Sep 3 02:39:06 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 03 Sep 2010 18:39:06 +1200 Subject: Obscure MySQLdb question - duplicating a database handle References: <4c801218$0$1622$742ec2ed@news.sonic.net> Message-ID: In message <4c801218$0$1622$742ec2ed at news.sonic.net>, John Nagle wrote: > The problem is that I want errorlog to commit its message to > the table used for error logging, but don't want to commit > whatever the caller was doing - that may well revert. Any particular reason you?re using a database table for logging? It?s usually easier to write to text files for this purpose. From ldo at geek-central.gen.new_zealand Fri Sep 3 02:45:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 03 Sep 2010 18:45:44 +1200 Subject: killing all subprocess childrens References: Message-ID: In message , Astan Chee wrote: > What I'm trying to do (and wondering if its possible) is to make sure > that any children (and any descendants) of this process is killed when > the main java process is killed (or dies). > How do I do this in windows, linux and OSX? A linux-specific solution could be implemented in terms of cgroups . I can?t see any way to automatically ensure all descendants are killed, but the parent can at least scan the cgroup when the immediate child exits, and kill every leftover process it finds. From eckhardt at satorlaser.com Fri Sep 3 02:52:07 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 03 Sep 2010 08:52:07 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: Tim Wintle wrote: > [..] under the hood, cpython does something like this (in psudo-code) > > itterator = xrange(imax) > while 1: > next_attribute = itterator.next > try: > i = next_attribute() > except: > break > a = a + 10 There is one thing that strikes me here: The code claims that each iteration there is a lookup of the 'next' field in the iterator. I would expect that this is looked up once before the loop only. Can you confirm that or am I misinterpreting your intention here? Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From stefan_ml at behnel.de Fri Sep 3 02:56:23 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Sep 2010 08:56:23 +0200 Subject: PyPy and RPython In-Reply-To: <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> <4c8014c2$0$1602$742ec2ed@news.sonic.net> <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> Message-ID: sarvi, 03.09.2010 07:30: > It should technically be possible to allow Python to call a module > written in RPython? What's "Python" here? CPython? Then likely yes. I don't see a benefit, though. > It should also compile RPython to a python module.so right? Why (and how) would CPython do that? If you want a binary extension module for CPython, you can try to push the RPython module through Cython. However, in that case, you wouldn't be restricted to RPython in the first place. Stefan From ben+python at benfinney.id.au Fri Sep 3 02:59:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 03 Sep 2010 16:59:40 +1000 Subject: python database References: <2010932369usenet@eggheadcafe.com> Message-ID: <87eidbfh2b.fsf@benfinney.id.au> shai garcia writes: > can you pls help me to make a database program in python? Thank you for your interest in Python, and I hope you will have much success as you learn about it. Your best way of using this forum to help you is to ask *specific* questions about problems as you go along. Do your research of the documentation for Python , the Python Package Index , the Python Wiki and so on; then start. Having started, work through the problems that come along as you go, and come here to ask about problems in *your* work, showing the code which confuses you and explaining the resources you've already researched. This will be much more instructive for you, and a much better use of the time of the volunteers here. > Submitted via [something that spews adverts on the end of messages] Please don't use these advertising services to post your messages. Instead, post them using a normal mail service that won't advertise at us. -- \ ?The difference between a moral man and a man of honor is that | `\ the latter regrets a discreditable act, even when it has worked | _o__) and he has not been caught.? ?Henry L. Mencken | Ben Finney From nagle at animats.com Fri Sep 3 02:59:57 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Sep 2010 23:59:57 -0700 Subject: PyPy and RPython In-Reply-To: <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> <4c8014c2$0$1602$742ec2ed@news.sonic.net> <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> Message-ID: <4c809cea$0$1614$742ec2ed@news.sonic.net> On 9/2/2010 10:30 PM, sarvi wrote: > On Sep 2, 2:19 pm, John Nagle wrote: >> On 9/2/2010 1:29 AM, sarvi wrote: >> >>> When I think about it these restrictions below seem a very reasonable >>> tradeoff for performance. >> >> Yes. >> >>> And I can use this for just the modules/sections that are performance >>> critical. >> >> Not quite. Neither Shed Skin nor RPython let you call from >> restricted code to unrestricted code. That tends to happen >> implicitly as objects are passed around. It's the global >> analysis that makes this work; when you call something, you >> need to know more about it than how to call it. > > It should technically be possible to allow Python to call a module > written in RPython? The problem is that, in a language where everything is an object, everything you call calls you back. The basic performance problem with CPython comes from the fact that it uses the worst-case code for almost everything. Avoiding that requires global analysis to detect the places where the code clearly isn't doing anything weird and simpler code can be used. Again, look at Shed Skin, which represents considerable progress made by one guy. With more resources, that could be a very good system. John Nagle From stefan_ml at behnel.de Fri Sep 3 03:00:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Sep 2010 09:00:13 +0200 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: Ulrich Eckhardt, 03.09.2010 08:52: > Tim Wintle wrote: >> [..] under the hood, cpython does something like this (in psudo-code) >> >> itterator = xrange(imax) >> while 1: >> next_attribute = itterator.next >> try: >> i = next_attribute() >> except: >> break >> a = a + 10 > > There is one thing that strikes me here: The code claims that each iteration > there is a lookup of the 'next' field in the iterator. I would expect that > this is looked up once before the loop only. > > Can you confirm that or am I misinterpreting your intention here? It needs to do that. Nothing keeps you from redefining "next" in each call. That's even a well known way to implement state machines. However, as usual, the details are a bit different in CPython, which has a C level slot for the "next" method. So the lookup isn't as heavy as it looks. Stefan From lucaberto at libero.it Fri Sep 3 03:58:12 2010 From: lucaberto at libero.it (luca72) Date: Fri, 3 Sep 2010 00:58:12 -0700 (PDT) Subject: pyqt unhandled RuntimeError \"no access to protected functions or signals for objects not created from Python Message-ID: <66fb86ba-5632-4a85-9762-38e17273e86d@x42g2000yqx.googlegroups.com> Hello i have also write to pyqt mailing list but maybe you can help me to solve this question: I have write a tcpserver but wheni try to read by the signal readyRead() e get the error this the part of the program: def nuova_connessione(self): print 'Nuova connessione' self.nuovo_socket = self.mio_server.nextPendingConnection() print self.nuovo_socket self.connect(self.nuovo_socket, QtCore.SIGNAL("connected()"), self. connessione) self.connect(self.nuovo_socket, QtCore.SIGNAL("readyRead()"), self. leggo_risposta) self.connect(self.nuovo_socket, QtCore.SIGNAL("disconnected"), self. sconnesso) self.connect(self.nuovo_socket, QtCore.SIGNAL("error(Qtcore. QAbsatctSocket::SocketError)"), self.server_errore) def leggo_risposta(self): cosa_leggo = self.nuovo_socket.readData(self.nuovo_socket. bytesAvailable()) can you help me Thanks From raoulbia at gmail.com Fri Sep 3 04:06:14 2010 From: raoulbia at gmail.com (Baba) Date: Fri, 3 Sep 2010 01:06:14 -0700 (PDT) Subject: bisection method: Simulating a retirement fund References: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> Message-ID: On Sep 2, 11:10?pm, MRAB wrote: > > Why are you saving 'fund' in SavingsRecord if you're returning just the > last and discarding others? Basically you're returning the final value > of fund. Hi MRAB ok i agree that this is not be ideal. I should shorten this to ONLY return SavingsRecord[-1] > When performing this type of 'search' make sure that the interval (high > - low) reduces at every step. > (integer division) and if the 'if' condition happens to be false > then the value of 'low' won't change for the next iteration, leading to an infinite loop. If you look at the output you will see that the interval DOES seem to reduce at each interval as expenses and fundsize reduce gradually. The computation does not lead to an infinite loop. tnx Baba From sarvilive at gmail.com Fri Sep 3 05:07:27 2010 From: sarvilive at gmail.com (sarvi) Date: Fri, 3 Sep 2010 02:07:27 -0700 (PDT) Subject: PyPy and RPython References: <09e2c33d-9b04-47b1-843c-41bd888ab3a3@u6g2000yqh.googlegroups.com> <4c7f46bb$0$1663$742ec2ed@news.sonic.net> <4c8014c2$0$1602$742ec2ed@news.sonic.net> <62e6d410-5657-48db-a66b-3e5d2c2800a7@k17g2000prf.googlegroups.com> <4c809cea$0$1614$742ec2ed@news.sonic.net> Message-ID: <88614c5d-cd11-4f92-a871-57f4eaaefd75@i4g2000prf.googlegroups.com> Well then, wouldn't it make sense for PyPy to use Shedskin and its definition of Restricted Python? I have heard repeatedly that PyPy RPython is very difficult to use. Then why isn't PyPy using Shedskin to compile its PyPy-Jit? Sarvi On Sep 2, 11:59?pm, John Nagle wrote: > On 9/2/2010 10:30 PM, sarvi wrote: > > > > > > > On Sep 2, 2:19 pm, John Nagle ?wrote: > >> On 9/2/2010 1:29 AM, sarvi wrote: > > >>> When I think about it these restrictions below seem a very reasonable > >>> tradeoff for performance. > > >> ? ? ?Yes. > > >>> And I can use this for just the modules/sections that are performance > >>> critical. > > >> ? ? ?Not quite. ?Neither Shed Skin nor RPython let you call from > >> restricted code to unrestricted code. ?That tends to happen > >> implicitly as objects are passed around. ?It's the global > >> analysis that makes this work; when you call something, you > >> need to know more about it than how to call it. > > > It should technically be possible to allow Python to call a module > > written in RPython? > > ? ? The problem is that, in a language where everything is an object, > everything you call calls you back. > > ? ? The basic performance problem with CPython comes from the fact > that it uses the worst-case code for almost everything. ?Avoiding > that requires global analysis to detect the places where the code > clearly isn't doing anything weird and simpler code can be used. > Again, look at Shed Skin, which represents considerable progress > made by one guy. With more resources, that could be a very > good system. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle From michael at perfect-kreim.de Fri Sep 3 05:21:36 2010 From: michael at perfect-kreim.de (Michael Kreim) Date: Fri, 03 Sep 2010 11:21:36 +0200 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <4C80BE20.2010804@perfect-kreim.de> Hi, thanks a lot for your answers. I learn a lot and I like to sum up your suggestions and show you the results of the time command on my machine: Original code by me: imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a => runs (wall clock time): 1:55.14 Peter Otten suggested to put the code into a function: def f(): imax = 1000000000 a = 0 for i in xrange(imax): a = a + 10 print a f() => runs (wall clock time): 0:47.69 Tim Wintle and Philip Bloom posted some code using a while loop: imax = 1000000000 a = 0 i = 0 while 1: i = i + 1 if (i > imax): break a = a + 10 print a => runs (wall clock time): 3:28.05 imax = 1000000000 a = 0 i = 0 while(i runs (wall clock time): 3:27.74 Hrvoje Niksic suggested the usage of itertools: from itertools import repeat imax = 1000000000 a = 0 for i in repeat(None, imax): a = a + 10 print a => runs (wall clock time): 1:58.25 I wrote a code combining these: def f(): from itertools import repeat imax = 1000000000 a = 0 for i in repeat(None, imax): a = a + 10 print a f() => runs (wall clock time): 0:43.08 Then Roland Koebler suggested psyco but I am sitting on a 64bit machine and so I could not test it (although it looks promising). An anonymous Nobody suggested to use Numpy. I did not do this, because I am very very new to Numpy and I did not figure out a Numpy specific way to do this. Maybe a Numpy expert has something for me? So finally I followed the recommendation of Tim Wintle to use cython. I did not know this before, but I figured out the following: additionWintle2.pyx: def addition(): cdef long imax = 1000000000 cdef long a = 0 cdef long i for i in xrange(imax): a = a + 10 print a setup.py: from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [Extension("additionWintle2", ["additionWintle2.pyx"])] setup( name = 'Cython test', cmdclass = {'build_ext': build_ext}, ext_modules = ext_modules ) $ python setup.py build_ext --inplace run.py: from additionWintle2 import addition addition() running build_ext => runs (wall clock time): 0:00.04 And to compare this. I wrote something similar in Matlab and C++ (although some authors, pointed out that it is not that easy to compare "for" loops in these three languages): addition.cpp #include using namespace std; int main() { long imax = 1e9; long a = 0; long i; for(i=0; i < imax; i++) { a = a + 10; } cout << a << endl; return 0; } => Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.32 addition.m imax = 1e9; a = 0; for i=0:imax-1 a = a + 10; end disp(a); exit; => Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.39 With best regards, Michael From jc.lopes at gmail.com Fri Sep 3 05:35:10 2010 From: jc.lopes at gmail.com (jc.lopes) Date: Fri, 3 Sep 2010 02:35:10 -0700 (PDT) Subject: Where do I report a bug to the pythonware PIL Message-ID: <82e8e2d1-e86f-4b61-8902-7a51f55942d6@u6g2000yqh.googlegroups.com> Does anyone knows what is the proper way to submit a bug report to pythonware PIL? thanks JC Lopes From stefan_ml at behnel.de Fri Sep 3 05:39:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Sep 2010 11:39:21 +0200 Subject: Speed-up for loops In-Reply-To: <4C80BE20.2010804@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> <4C80BE20.2010804@perfect-kreim.de> Message-ID: Michael Kreim, 03.09.2010 11:21: > So finally I followed the recommendation of Tim Wintle to use cython. I > did not know this before, but I figured out the following: > additionWintle2.pyx: > > def addition(): > cdef long imax = 1000000000 > cdef long a = 0 > cdef long i > for i in xrange(imax): > a = a + 10 > print a > > => runs (wall clock time): 0:00.04 Note that this isn't the "real" runtime. If you look up the binary code that the C compiler spits out, you'll most likely find the final result for "a" written down as a literal that gets returned from the function. C compilers do these things to benchmarks these days. Stefan From vgnulinux at gmail.com Fri Sep 3 06:30:08 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Fri, 3 Sep 2010 16:00:08 +0530 Subject: Python for embedded systems development Message-ID: Hi, Is there anyone using python for embedded systems development ? I have no idea where to start with. Google was of little help. Will appreciate if someone could guide me on "from where to start". Regards Vgnu -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Fri Sep 3 07:12:00 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 03 Sep 2010 13:12:00 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <871v9bjd33.fsf@busola.homelinux.net> Ulrich Eckhardt writes: > Tim Wintle wrote: >> [..] under the hood, cpython does something like this (in psudo-code) >> >> itterator = xrange(imax) >> while 1: >> next_attribute = itterator.next >> try: >> i = next_attribute() >> except: >> break >> a = a + 10 > > There is one thing that strikes me here: The code claims that each > iteration there is a lookup of the 'next' field in the iterator. I > would expect that this is looked up once before the loop only. It is looked up every time, but the lookup is efficient because "next" is one of the special methods that have a slot in the C struct that defines a Python type. A closer code would be something like: next_function = iterator->ob_type->tp_next; ...which is as fast as it gets. CPython implements this in Python/ceval.c, just look for FOR_ITER. From python at bdurham.com Fri Sep 3 07:24:13 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 03 Sep 2010 07:24:13 -0400 Subject: Speed-up for loops In-Reply-To: <4C80BE20.2010804@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> <4C80BE20.2010804@perfect-kreim.de> Message-ID: <1283513053.20882.1393180723@webmail.messagingengine.com> Michael, Thanks for summarizing and sharing your results. Very interesting. Regards, Malcolm From vs at it.uu.se Fri Sep 3 07:29:21 2010 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 03 Sep 2010 13:29:21 +0200 Subject: Financial time series data Message-ID: <4C80DC11.50504@it.uu.se> A more direct question on accessing stock information from Yahoo. First, use your browser to go to: http://finance.yahoo.com/q/cp?s=%5EGSPC+Components Now, you see the first 50 rows of a 500 row table of information on S&P 500 index. You can LM click on 1 -50 of 500 |First|Previous|Next|Last below the table to position to any of the 10 pages. I would like to use Python to do the following. *Loop on each of the 10 pages and for each page extract information for each row --- How can this be accomplished automatically in Python?* Let's take the first page (as shown by default). It is easy to see the link to the data for "A" is http://finance.yahoo.com/q?s=A. That is, I can just move my cursor over the "A" and I see this URL in the message at the bottom of my browser (Explorer 8). If I LM click on "A" then I will go to this link --- Do this! You should now see a table which shows information on this stock and *this is the information that I would like to extract*. I would like to do this for all 500 stocks without the need to enter the symbols for them (e.g. "A", "AA", etc.). It seems clear that this should be possible since all the symbols are in the first column of each of the 50 tables --- but it is not at all clear how to extract these automatically in Python. Hopefully, you understand my problem. Again, I would like Python to cycle through these 10 pages and extract this information for each symbol in this table. --V -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Sep 3 08:21:55 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 3 Sep 2010 08:21:55 -0400 Subject: MySQL Problem In-Reply-To: <4C7FF4C0.1010503@gmaiil.com> References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: On Thu, Sep 2, 2010 at 3:02 PM, Ian wrote: > On 02/09/2010 19:34, Victor Subervi wrote: > >> for some reason running the command through python *omits* this one data!! >> The only difference is that a flag in spreadsheets (Temp) is set to 1. Why >> on earth doesn't it work in python?? >> > Some ideas to follow up. (These are only guesses). > > 1) One of the enum type fields contains an invalid value (perhaps a value > removed from the column definition). > There are no enum type fields. > > 2) The second id field (products.id?) appears to be very large. I wonder > what would happen if it was larger than the auto-increment value? > It's not an ID field. It doesn't auto_increment. > > 3) A field in the one of the rows in the missing data contains bytes that > are invalid in the character encoding you are using in python. > I changed the only bytes I thought might affect it. Furthermore, I successfully added the blasted data to that field so it would show up in the spreadsheet through another form. More on that later. > > 4) The python field type used for some column in the missing row, contains > a value that cannot be held in the python variable assigned. > If that were so, none of the data would show up. Please look at this comparison: FIELD BAD DATA GOOD DATA ID 609 161 Client Lincoln_Properties Lincoln_Properties Multi 0 0 Item 2030572 40x48Green Markup 0.00 99.32 Temp 1 Null ID 343 37 Item 2030572 40x48Green Description Americo 20" Beige Floor Pad Green Can Liners UOM 5/cs 1000/cs Cost 15.88 17.56 ID 335 37 ProductsID 343 37 CategoryID 49 23 ID 49 23 Category Mats Can Liners Parent Restaurant Paper/Pla Bags I have changed the value of Temp to Null and Markup to 11.11 to see if that would somehow make a difference. It didn't. Then I used my TTW form for adding data "regularly" to spreadsheets and it worked. The form I'm testing enables the client to add data himself. The code is the same in both cases: "regular" cursor.execute('insert into spreadsheets values (Null, %s, 0, %s, 0, Null)', (client, prod)) "special" cursor.execute('insert into spreadsheets values (Null, %s, 0, %s, 0, Null)', (client, product[1])) I checked permissions and changed ownership to make the two scripts identical. Again, the data gets entered into MySQL correctly...it just doesn't show up with the rest of the data in the TTW form!! Why?? TIA, beno > > Regards > > Ian > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nanjundi at gmail.com Fri Sep 3 09:07:38 2010 From: nanjundi at gmail.com (Nanjundi) Date: Fri, 3 Sep 2010 06:07:38 -0700 (PDT) Subject: Financial time series data References: Message-ID: On Sep 2, 1:12?pm, Virgil Stokes wrote: > ? Has anyone written code or worked with Python software for downloading > financial time series data (e.g. from Yahoo financial)? If yes, ?would you > please contact me. > > --Thanks, > V. Stokes matplotlib has a finance module you can refer to. (matplotlib.finance.fetch_historical_yahoo) see the example: http://matplotlib.sourceforge.net/examples/pylab_examples/finance_work2.html From mrmakent at cox.net Fri Sep 3 09:21:27 2010 From: mrmakent at cox.net (Mike Kent) Date: Fri, 3 Sep 2010 06:21:27 -0700 (PDT) Subject: python database References: <2010932369usenet@eggheadcafe.com> Message-ID: <40f41e67-9da0-41da-ab55-eb5bed596856@k1g2000prl.googlegroups.com> On Sep 3, 2:36?am, shai garcia wrote: > can you pls help me to make a database program in python? It's better if you do your homework yourself. You learn more that way. Now, if you have a specific question about some detail of your assignment, and can show us that you've really tried to do the work yourself, that's another matter. From arts.richard at gmail.com Fri Sep 3 09:25:45 2010 From: arts.richard at gmail.com (Richard Arts) Date: Fri, 3 Sep 2010 15:25:45 +0200 Subject: MySQL Problem In-Reply-To: References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: These are also mere suggestions. The statements you use in your print statement and the one you use to feed the cursor differ slightly. The latter is missing quotes around your search criterium. Isn't it possible to fetch results row by row and see if the missing row is in the set? That way you can get a better feeling about the nature of the error. > cursor.execute('insert into spreadsheets values (Null, %s, 0, %s, 0, Null)', (client, prod)) Out of curiosity, why would you want to insert null values in id fields? That's a disaster waiting to happen. Regards, Richard From tim.wintle at teamrubber.com Fri Sep 3 09:26:48 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 03 Sep 2010 14:26:48 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <1283520408.3209.126.camel@tim-laptop> On Fri, 2010-09-03 at 08:52 +0200, Ulrich Eckhardt wrote: > Tim Wintle wrote: > > [..] under the hood, cpython does something like this (in psudo-code) > > > > itterator = xrange(imax) > > while 1: > > next_attribute = itterator.next > > try: > > i = next_attribute() > > except: > > break > > a = a + 10 > > There is one thing that strikes me here: The code claims that each iteration > there is a lookup of the 'next' field in the iterator. I would expect that > this is looked up once before the loop only. > > Can you confirm that or am I misinterpreting your intention here? As Stefan and Hrvoje have posted, there is a lookup - but in 2.4 and above it's straight off the C structure and compiled efficiently. (I've been looking at 2.3's source recently and had forgotten the optimisation) Tim From victorsubervi at gmail.com Fri Sep 3 09:29:29 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 3 Sep 2010 09:29:29 -0400 Subject: MySQL Problem In-Reply-To: References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: This is an addendum to my last post. Please observe the following: mysql> select * from spreadsheets where Temp=1; +-----+--------------------+-------+---------+--------+------+ | ID | Client | Multi | Item | Markup | Temp | +-----+--------------------+-------+---------+--------+------+ | 611 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | | 621 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | +-----+--------------------+-------+---------+--------+------+ 2 rows in set (0.00 sec) mysql> describe spreadsheets; +--------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+------------------+------+-----+---------+----------------+ | ID | int(11) unsigned | NO | PRI | NULL | auto_increment | | Client | varchar(40) | YES | | NULL | | | Multi | tinyint(1) | YES | | NULL | | | Item | varchar(40) | YES | | NULL | | | Markup | float(6,2) | YES | | NULL | | | Temp | tinyint(1) | YES | | NULL | | +--------+------------------+------+-----+---------+----------------+ 6 rows in set (0.00 sec) Yet from my script: cursor.execute('select * from spreadsheets where Temp=1') print cursor.fetchall() print nothing but an empty set: () Why?? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Sep 3 09:37:15 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 3 Sep 2010 09:37:15 -0400 Subject: MySQL Problem In-Reply-To: References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: On Fri, Sep 3, 2010 at 9:25 AM, Richard Arts wrote: > These are also mere suggestions. > > The statements you use in your print statement and the one you use to > feed the cursor differ slightly. The latter is missing quotes around > your search criterium. > > Isn't it possible to fetch results row by row and see if the missing > row is in the set? That way you can get a better feeling about the > nature of the error. > Well, I just tried, out of curiosity, inserting 0 instead of 1 and guess what? It shows up. So by simply changing that my problem is solved...but I sure as heck would like to know why! > > > cursor.execute('insert into spreadsheets values (Null, %s, 0, %s, 0, > Null)', (client, prod)) > > Out of curiosity, why would you want to insert null values in id > fields? That's a disaster waiting to happen. > Hardly. This is the standard way of inserting into auto_increment fields. That triggers the auto_increment! That makes it much easier to insert the correct value of the field. beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthra.norell at bluewin.ch Fri Sep 3 09:45:36 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 03 Sep 2010 15:45:36 +0200 Subject: Financial time series data In-Reply-To: <4C80DC11.50504@it.uu.se> References: <4C80DC11.50504@it.uu.se> Message-ID: <1283521536.2364.139.camel@hatchbox-one> On Fri, 2010-09-03 at 13:29 +0200, Virgil Stokes wrote: > A more direct question on accessing stock information from Yahoo. > > First, use your browser to go to: http://finance.yahoo.com/q/cp?s=% > 5EGSPC+Components > > Now, you see the first 50 rows of a 500 row table of information on > S&P 500 index. You can LM click on > > 1 -50 of 500 |First|Previous|Next|Last > > below the table to position to any of the 10 pages. > > I would like to use Python to do the following. > > Loop on each of the 10 pages and for each page extract information for > each row --- How can this be accomplished automatically in Python? > > Let's take the first page (as shown by default). It is easy to see the > link to the data for "A" is http://finance.yahoo.com/q?s=A. That is, I > can just move > my cursor over the "A" and I see this URL in the message at the bottom > of my browser (Explorer 8). If I LM click on "A" then I will go to > this > link --- Do this! > > You should now see a table which shows information on this stock and > this is the information that I would like to extract. I would like to > do this for all 500 stocks without the need to enter the symbols for > them (e.g. "A", "AA", etc.). It seems clear that this should be > possible since all the symbols are in the first column of each of the > 50 tables --- but it is not at all clear how to extract these > automatically in Python. > > Hopefully, you understand my problem. Again, I would like Python to > cycle through these 10 pages and extract this information for each > symbol in this table. > > --V > > > Here's a quick hack to get the SP500 symbols from the visual page with the index letters. From this collection you can then order fifty at a time from the download facility. (If you get a better idea from Yahoo, you'll post it of course.) def get_SP500_symbols (): import urllib symbols = [] url = 'http://finance.yahoo.com/q/cp?s=^GSPC&alpha=%c' for c in [chr(n) for n in range (ord ('A'), ord ('Z') + 1)]: print url % c f = urllib.urlopen (url % c) html = f.readlines () f.close () for line in html: if line.lstrip ().startswith (' Hi I am new to python and have installed python 3.1.2. I have began using IDLE and like it very good. But when an IDLE window is active. There is a thick black frame around the white text field. Is there some way I can get rid of this frame? The frame is very distracting when I write. Kristoffer From alex at moreati.org.uk Fri Sep 3 11:14:21 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Fri, 3 Sep 2010 08:14:21 -0700 (PDT) Subject: Where do I report a bug to the pythonware PIL References: <82e8e2d1-e86f-4b61-8902-7a51f55942d6@u6g2000yqh.googlegroups.com> Message-ID: On Sep 3, 10:35?am, "jc.lopes" wrote: > Does anyone knows what is the proper way to submit a bug report to > pythonware PIL? > > thanks > JC Lopes The Python Image SIG list http://mail.python.org/mailman/listinfo/image-sig "Free Support: If you don't have a support contract, please send your question to the Python Image SIG mailing list. The same applies for bug reports and patches." -- http://www.pythonware.com/products/pil/ They don't appear to have a dedicated mailing list or public bug tracker. From lucaberto at libero.it Fri Sep 3 11:16:34 2010 From: lucaberto at libero.it (luca72) Date: Fri, 3 Sep 2010 08:16:34 -0700 (PDT) Subject: pyqt signals Message-ID: Hello i have write this but i not able to connect the emit of the class Socket to the Form class, can you help me? class Socket(QtNetwork.QTcpSocket): def __init__(self, parent=None): super(Socket, self).__init__(parent) self.connect(self, QtCore.SIGNAL("readyRead()"), self.leggi_richiesta) def leggi_richiesta(self): messaggio = self.readData(self.bytesAvailable()) print 'dati_letti = ', messaggio self.emit(QtCore.SIGNAL("messaggio"), messaggio) print 'segnale emesso' class Form(QWidget, Ui_Form): """ Class documentation goes here. """ def __init__(self, parent = None): """ Constructor """ connesso_in_arr =False self.coda = False QWidget.__init__(self, parent) self.setupUi(self) self.dati = False self.lu = TcpServer() self.lu self.connect(Socket(self), QtCore.SIGNAL('messaggio'), self.leggo_risposta) def leggo_risposta(self, messaggio): self.plainTextEdit_2.appendPlainText(messaggio) Thanks Luca From robert.kern at gmail.com Fri Sep 3 11:17:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 03 Sep 2010 10:17:32 -0500 Subject: Where do I report a bug to the pythonware PIL In-Reply-To: <82e8e2d1-e86f-4b61-8902-7a51f55942d6@u6g2000yqh.googlegroups.com> References: <82e8e2d1-e86f-4b61-8902-7a51f55942d6@u6g2000yqh.googlegroups.com> Message-ID: On 9/3/10 4:35 AM, jc.lopes wrote: > Does anyone knows what is the proper way to submit a bug report to > pythonware PIL? http://mail.python.org/mailman/listinfo/image-sig -- 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 rurpy at yahoo.com Fri Sep 3 11:54:52 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 3 Sep 2010 08:54:52 -0700 (PDT) Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <7a38148b-79e9-40ce-9700-2c0d1c9b3ee4@a4g2000prm.googlegroups.com> <4a3665a0-fc7f-425a-878e-6f8dcc5ed319@y11g2000yqm.googlegroups.com> Message-ID: <3647e26e-8734-42cf-af14-84d1fea78ddc@m35g2000prn.googlegroups.com> On 09/02/2010 02:47 PM, Terry Reedy wrote: > On 9/1/2010 10:57 PM, rurpy at yahoo.com wrote: > >> So while you may "think" most people rarely read >> the docs for basic language features and objects >> (I presume you don't mean to restrict your statement >> to only sets), I and most people I know *do* read >> them. And when read them I expect them, as any good >> reference documentation does, to completely and >> accurately describe the behavior of the item I am >> reading about. If big-O performance is deemed an >> intrinsic behavior of an (operation of) an object, >> it should be described in the documentation for >> that object. > > However, big-O performance is intentionally NOT so deemed. The discussion, as I understood it, was about whether or not it *should* be so deemed. > And I have > and would continue to argue that it should not be, for multiple reasons. Yes, you have. And others have argued the opposite. Personally, I did not find your arguments very convincing, particularly that it would be misleading or that the limits necessarily imposed by a real implementation somehow invalidates the usefulness of O() documentation. But I acknowledged that there was not universal agreement that O() behavior should be documented in the the reference docs by qualifying my statement with the word "if". But mostly my comments were directed towards some of the side comments in Raymond's post I thought should not pass unchallenged. I think that some of the attitudes expressed (and shared by others) are likely the direct cause of many of the faults I find in the currrent documentation. From john at castleamber.com Fri Sep 3 13:08:02 2010 From: john at castleamber.com (John Bokma) Date: Fri, 03 Sep 2010 12:08:02 -0500 Subject: Performance: sets vs dicts. References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> <87aao1c8dk.fsf@castleamber.com> Message-ID: <87sk1q21sd.fsf@castleamber.com> Terry Reedy writes: > On 9/1/2010 8:11 PM, John Bokma wrote: [...] > Right. And if 'small values of n' include all possible values, then > rejecting a particular O(log n) algorithm as 'unacceptable' relative > to all O(1) algorithms is pretty absurd. I have little time, but want to reply to this one: anyone using big-Oh and claiming that an O(log n) algorithm is 'unacceptable' relative to all O(1) algorithms has no clue what he/she is talking about. big-Oh says something about the order of /growth/ of the running time of an algorithm. And since 1 is a constant O(1) means that the order of /growth/ of the running time is constant (independend of the input size. Since "the growth of the running time is constant" is quite a mouth full, it's often shortened to 'constant time' since from the context it's clear what's being meant. But this doesn't mean that if the algorithm gets an input size of 100000 versus 1 that it takes the same number of seconds for the latter to process. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From python at mrabarnett.plus.com Fri Sep 3 13:12:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 03 Sep 2010 18:12:49 +0100 Subject: bisection method: Simulating a retirement fund In-Reply-To: References: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> Message-ID: <4C812C91.80308@mrabarnett.plus.com> On 03/09/2010 09:06, Baba wrote: > On Sep 2, 11:10 pm, MRAB wrote: >> >> Why are you saving 'fund' in SavingsRecord if you're returning just the >> last and discarding others? Basically you're returning the final value >> of fund. > > Hi MRAB > > ok i agree that this is not be ideal. I should shorten this to ONLY > return SavingsRecord[-1] > > >> When performing this type of 'search' make sure that the interval (high >> - low) reduces at every step.> (integer division) and if the 'if' condition happens to be false >> then the value of 'low' won't change for the next iteration, leading to an infinite loop. > > > If you look at the output you will see that the interval DOES seem to > reduce at each interval as expenses and fundsize reduce gradually. The > computation does not lead to an infinite loop. > It doesn't in that particular case, but it might in some other cases. From anthra.norell at bluewin.ch Fri Sep 3 13:48:13 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 03 Sep 2010 19:48:13 +0200 Subject: Financial time series data In-Reply-To: <4C810AA1.7060700@it.uu.se> References: <4C80DC11.50504@it.uu.se> <1283521536.2364.139.camel@hatchbox-one> <4C810AA1.7060700@it.uu.se> Message-ID: <1283536093.2894.12.camel@hatchbox-one> On Fri, 2010-09-03 at 16:48 +0200, Virgil Stokes wrote: > On 03-Sep-2010 15:45, Frederic Rentsch wrote: > > On Fri, 2010-09-03 at 13:29 +0200, Virgil Stokes wrote: > >> A more direct question on accessing stock information from Yahoo. > >> > >> First, use your browser to go to: http://finance.yahoo.com/q/cp?s=% > >> 5EGSPC+Components > >> > >> Now, you see the first 50 rows of a 500 row table of information on > >> S&P 500 index. You can LM click on > >> > >> 1 -50 of 500 |First|Previous|Next|Last > >> > >> below the table to position to any of the 10 pages. > >> > >> I would like to use Python to do the following. > >> > >> Loop on each of the 10 pages and for each page extract information for > >> each row --- How can this be accomplished automatically in Python? > >> > >> Let's take the first page (as shown by default). It is easy to see the > >> link to the data for "A" is http://finance.yahoo.com/q?s=A. That is, I > >> can just move > >> my cursor over the "A" and I see this URL in the message at the bottom > >> of my browser (Explorer 8). If I LM click on "A" then I will go to > >> this > >> link --- Do this! > >> > >> You should now see a table which shows information on this stock and > >> this is the information that I would like to extract. I would like to > >> do this for all 500 stocks without the need to enter the symbols for > >> them (e.g. "A", "AA", etc.). It seems clear that this should be > >> possible since all the symbols are in the first column of each of the > >> 50 tables --- but it is not at all clear how to extract these > >> automatically in Python. > >> > >> Hopefully, you understand my problem. Again, I would like Python to > >> cycle through these 10 pages and extract this information for each > >> symbol in this table. > >> > >> --V > >> > >> > >> > > Here's a quick hack to get the SP500 symbols from the visual page with > > the index letters. From this collection you can then order fifty at a > > time from the download facility. (If you get a better idea from Yahoo, > > you'll post it of course.) > > > > > > > > def get_SP500_symbols (): > > import urllib > > symbols = [] > > url = 'http://finance.yahoo.com/q/cp?s=^GSPC&alpha=%c' > > for c in [chr(n) for n in range (ord ('A'), ord ('Z') + 1)]: > > print url % c > > f = urllib.urlopen (url % c) > > html = f.readlines () > > f.close () > > for line in html: > > if line.lstrip ().startswith (' > line_split = line.split (':') > > s = [item.strip ().upper () for item in line_split [5].replace ('"', > > '').split (',')] > > symbols.extend (s [:-3]) > > > > return symbols > > # Not quite 500 (!?) > > > > > > Frederic > > > > > > > I made a few modifications --- very minor. But, I believe that it is a little > faster. > > import urllib2 > > def get_SP500_symbolsX (): > symbols = [] > for page in range(0,9): > url = 'http://finance.yahoo.com/q/cp?s=%5EGSPC&c='+str(page) > print url > f = urllib2.urlopen (url) > html = f.readlines () > f.close () > for line in html: > if line.lstrip ().startswith (' line_split = line.split (':') > s = [item.strip ().upper () for item in line_split [5].replace > ('"','').split (',')] > symbols.extend (s [:-3]) > > return symbols > # Not quite 500 -- which is correct (for example p. 2 has only 49 symbols!) > # Actually the S&P 500 as shown does not contain 500 stocks (symbols) > > > symbols = get_SP500_symbolsX() > pass Oh, yes, and there's no use reading lines to the end once the symbols are in the bag. The symbol-line-finder conditional section should end with "break". And do let us know if you get an answer from Yahoo. Hacks like this are unreliable. They fail almost certainly the next time a page gets redesigned, which can be any time. Frederic From alistair.calder at gmail.com Fri Sep 3 13:52:01 2010 From: alistair.calder at gmail.com (alistair) Date: Fri, 3 Sep 2010 10:52:01 -0700 (PDT) Subject: New to python - parse data into Google Charts Message-ID: <42b45d97-b475-4bd8-b386-9c6db73316f9@f20g2000pro.googlegroups.com> I'm new to python and my programming years are a ways behind me, so I was looking for some help in parsing a file into a chart using the Google Charts API. The file is simply a text file containing: Date, Total Accesses, Unique Accesses. I'd like date across the bottom, access numbers on the vertical axis and lines for the amounts. I'm not even really sure how to get started if someone wants to give me some pointers or throw together a short example, I would greatly appreciate it. Here is a sample of the data: 2010-08-01, 2324, 1800 2010-08-02, 3832, 2857 2010-08-03, 7916, 4875 2010-08-04, 7004, 4247 2010-08-05, 6392, 4026 2010-08-06, 5396, 3513 2010-08-07, 3238, 2285 2010-08-08, 3579, 2588 2010-08-09, 7710, 4867 2010-08-10, 6662, 4123 2010-08-11, 6524, 4045 2010-08-12, 6438, 3965 2010-08-13, 5472, 3543 2010-08-14, 3059, 2193 2010-08-15, 3255, 2379 2010-08-16, 7149, 4482 2010-08-17, 6727, 4247 2010-08-18, 6989, 4328 2010-08-19, 6738, 4192 2010-08-20, 5929, 3816 2010-08-21, 3245, 2302 2010-08-22, 4091, 2900 2010-08-23, 8237, 4857 2010-08-24, 7895, 4575 2010-08-25, 7788, 4564 2010-08-26, 7616, 4527 2010-08-27, 6671, 4159 2010-08-28, 3595, 2484 2010-08-29, 4377, 2991 2010-08-30, 9238, 5427 2010-08-31, 9274, 5406 From robert.kern at gmail.com Fri Sep 3 14:05:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 03 Sep 2010 13:05:22 -0500 Subject: Performance: sets vs dicts. In-Reply-To: <87sk1q21sd.fsf@castleamber.com> References: <4c7ab135$0$1591$742ec2ed@news.sonic.net> <87iq2pcfbo.fsf@castleamber.com> <87aao1c8dk.fsf@castleamber.com> <87sk1q21sd.fsf@castleamber.com> Message-ID: On 9/3/10 12:08 PM, John Bokma wrote: > Terry Reedy writes: > >> On 9/1/2010 8:11 PM, John Bokma wrote: > > [...] > >> Right. And if 'small values of n' include all possible values, then >> rejecting a particular O(log n) algorithm as 'unacceptable' relative >> to all O(1) algorithms is pretty absurd. > > I have little time, but want to reply to this one: anyone using big-Oh > and claiming that an O(log n) algorithm is 'unacceptable' relative to > all O(1) algorithms has no clue what he/she is talking about. > > big-Oh says something about the order of /growth/ of the running time of > an algorithm. And since 1 is a constant O(1) means that the order of > /growth/ of the running time is constant (independend of the input > size. That's an ambiguous wording that is likely to confuse people. It seems like you are saying that the O() behavior is the order of the first derivative of the running time as a function of some interesting parameter of the problem, which it is not. O() notation *describes* the growth, but it *is not* the order of the growth itself. -- 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 pavlovevidence at gmail.com Fri Sep 3 14:28:07 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 3 Sep 2010 11:28:07 -0700 (PDT) Subject: bisection method: Simulating a retirement fund References: <395c5c8d-feb3-46a4-bb3b-cb4652c0bde3@e14g2000yqe.googlegroups.com> Message-ID: On Sep 2, 1:37?pm, Baba wrote: > level: beginner In this economy, simulating the value of retirement funds with bisection is easy. Look: def retirement_fund_value(n_years,initial_value): for i in xrange(n_years): value /= 2 # <- bisect value of fund return value Carl Banks From nfdisco at gmail.com Fri Sep 3 15:35:48 2010 From: nfdisco at gmail.com (ernest) Date: Fri, 3 Sep 2010 12:35:48 -0700 (PDT) Subject: what should __iter__ return? Message-ID: Hi, What is better: def __iter__(self): for i in len(self): yield self[i] or def __iter__(self): return iter([self[i] for i in range(len(self))]) The first one, I would say is more correct, however what if in a middle of an iteration the object changes in length? Then, the iterator will fail with IndexError (if items have been removed), or it will fail to iterate over the whole sequence (if items have been added). What do you think? Cheers. Ernest From mrmakent at cox.net Fri Sep 3 15:41:39 2010 From: mrmakent at cox.net (Mike Kent) Date: Fri, 3 Sep 2010 12:41:39 -0700 (PDT) Subject: Does MySQLdb rollback on control-C? Maybe not. References: <4c8077f1$0$1628$742ec2ed@news.sonic.net> Message-ID: On Sep 3, 12:22?am, John Nagle wrote: > ? ? I would expect MySQLdb to rollback on a control-C, but it doesn't > seem to have done so. ? > Something is broken. I wouldn't expect it to, I'd expect to roll back on an exception, or commit if not. Perhaps this will help you. I use it in production code. ## # This is a transaction context manager. It will ensure that the code in # the context block will be executed inside a transaction. If any exception # occurs, the transaction will be rolled back, and the exception reraised. # If no exception occurs, the transaction will be committed. # db is a database connection object. from contextlib import contextmanager @contextmanager def transaction(db): db.begin() try: yield None except: db.rollback() raise else: db.commit() From mrmakent at cox.net Fri Sep 3 15:51:26 2010 From: mrmakent at cox.net (Mike Kent) Date: Fri, 3 Sep 2010 12:51:26 -0700 (PDT) Subject: New to python - parse data into Google Charts References: <42b45d97-b475-4bd8-b386-9c6db73316f9@f20g2000pro.googlegroups.com> Message-ID: <9222c04c-3f7f-4d36-afde-ec9dc5dfa740@i17g2000vbq.googlegroups.com> On Sep 3, 1:52?pm, alistair wrote: > I'm new to python and my programming years are a ways behind me, so I > was looking for some help in parsing a file into a chart using the > Google Charts API. > Try this: http://pygooglechart.slowchop.com/ From hobson42 at gmaiil.com Fri Sep 3 15:54:08 2010 From: hobson42 at gmaiil.com (Ian) Date: Fri, 03 Sep 2010 20:54:08 +0100 Subject: MySQL Problem In-Reply-To: References: <4C7FF4C0.1010503@gmaiil.com> Message-ID: <4C815260.5090904@gmaiil.com> On 03/09/2010 14:29, Victor Subervi wrote: > This is an addendum to my last post. Please observe the following: > > mysql> select * from spreadsheets where Temp=1; > +-----+--------------------+-------+---------+--------+------+ > | ID | Client | Multi | Item | Markup | Temp | > +-----+--------------------+-------+---------+--------+------+ > | 611 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | > | 621 | Lincoln_Properties | 0 | 2030572 | 0.00 | 1 | > +-----+--------------------+-------+---------+--------+------+ > 2 rows in set (0.00 sec) > > mysql> describe spreadsheets; > +--------+------------------+------+-----+---------+----------------+ > | Field | Type | Null | Key | Default | Extra | > +--------+------------------+------+-----+---------+----------------+ > | ID | int(11) unsigned | NO | PRI | NULL | auto_increment | > | Client | varchar(40) | YES | | NULL | | > | Multi | tinyint(1) | YES | | NULL | | > | Item | varchar(40) | YES | | NULL | | > | Markup | float(6,2) | YES | | NULL | | > | Temp | tinyint(1) | YES | | NULL | | > +--------+------------------+------+-----+---------+----------------+ > 6 rows in set (0.00 sec) > > Yet from my script: > > cursor.execute('select * from spreadsheets where Temp=1') > print cursor.fetchall() > > print nothing but an empty set: () Why?? > TIA, > beno Hi Victor Find out exactly what character encoding are you using for each of the following places when using MySQL client. The MySQL installation The database definition The table definition The Field definition The Link between Python and MySQL The Python source / The Msql Client. And then find out what encoding is being forced/used by the code you have written in Python in each of the above situations? You may have to go to the source of the library routine to find this out. What I suspect may be happening is this. Say you have a field containing a character/code point that is in UTF-8 but not in the ISO-8859-1 set. If such a field was written using UTF-8 throughout, but then read using ISO-8859-1 or similar then the read will generate an error. That error may be being ignored or suppressed causing the code to drop your data rows. IIRC, MySQL calls UTF-8 by the (incorrect) name of utf-8. My recommendation is for you to use UTF-8 for everything. UTF-8 can store any character in any language(1), is really efficient for English text, and acceptable for other languages. Performance it excellent, because it involves no encoding/decoding as the data moves between disk, MySQL link or Python. (1) There are some minor human languages that cannot be encoded - usually because no written form has yet been devised or the code points have not been agreed. These languages will not be met in practise. Regards Ian From nobody at nowhere.com Fri Sep 3 15:54:45 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 03 Sep 2010 20:54:45 +0100 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: On Fri, 03 Sep 2010 11:21:36 +0200, Michael Kreim wrote: > An anonymous Nobody suggested to use Numpy. I did not do this, because I > am very very new to Numpy and I did not figure out a Numpy specific way > to do this. Maybe a Numpy expert has something for me? The problem with giving examples is that your original example is too contrived. Taken literally, it can be optimised to print imax * 10 A less contrived example would actually do something within the loop, in order to justify the existence of the loop. NumPy provides predefined loops which correspond to map, reduce, accumulate and zip, for all of the standard arithmetic operators and common mathematical functions. E.g. if your loop was: a = 0 for i in xrange(imax): a += i**2 print a the NumPy version would be: print numpy.sum(numpy.arange(imax)**2) The arange() function is similar to range() but generates an array. The ** operator is implemented for arrays; sum() sums the elements of the array. The main downside is that the intermediate array(s) must be constructed in memory, which rules out its use for very long sequences. From thomas at jollybox.de Fri Sep 3 15:58:38 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 3 Sep 2010 21:58:38 +0200 Subject: what should __iter__ return? In-Reply-To: References: Message-ID: <201009032158.39479.thomas@jollybox.de> On Friday 03 September 2010, it occurred to ernest to exclaim: > Hi, > > What is better: > > def __iter__(self): > for i in len(self): > yield self[i] > > or > > def __iter__(self): > return iter([self[i] for i in range(len(self))]) > > The first one, I would say is more correct, > however what if in a middle of an iteration > the object changes in length? Then, the > iterator will fail with IndexError (if items > have been removed), or it will fail to iterate > over the whole sequence (if items have > been added). > > What do you think? Hmm. Modifying an object while iterating over it isn't a great idea, ever: >>> L = [1,2,3,4] >>> i = iter(L) >>> next(i) 1 >>> next(i) 2 >>> del L[0] >>> next(i) 4 You second version is wasteful. It creates a copy of the object just for iteration. I don't think that's something you should be doing. If you want "correct" behaviour as with lists, you might want something like this: def __iter__(self): class _Iter: def __init__(it): it.i = -1 def __next__(it): it.i += 1 try: return self[it.i] except IndexError: raise StopIteration return _Iter() > > Cheers. > Ernest From python at mrabarnett.plus.com Fri Sep 3 16:02:35 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 03 Sep 2010 21:02:35 +0100 Subject: what should __iter__ return? In-Reply-To: References: Message-ID: <4C81545B.3060708@mrabarnett.plus.com> On 03/09/2010 20:35, ernest wrote: > Hi, > > What is better: > > def __iter__(self): > for i in len(self): > yield self[i] > > or > > def __iter__(self): > return iter([self[i] for i in range(len(self))]) > > The first one, I would say is more correct, > however what if in a middle of an iteration > the object changes in length? Then, the > iterator will fail with IndexError (if items > have been removed), or it will fail to iterate > over the whole sequence (if items have > been added). > > What do you think? > I'd say the first one is less correct because you can't iterate over an int. :-) From bartc at freeuk.com Fri Sep 3 16:17:44 2010 From: bartc at freeuk.com (BartC) Date: Fri, 3 Sep 2010 21:17:44 +0100 Subject: Speed-up for loops In-Reply-To: References: Message-ID: "Michael Kreim" wrote in message news:mailman.362.1283422325.29448.python-list at python.org... > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > Unfortunately my Python Code was much slower and I do not understand why. > > Are there any ways to speed up the for/xrange loop? > Or do I have to live with the fact that Matlab beats Python in this > example? I'm not sure the Python developers were interested in getting fast loops. For-loops which iterate between two numbers are amongst the easiest things to make fast in a language. Yet originally you had to use: for i in range(N): which (if I understood correctly) actually created a list of N objects, populated it with the values 0, 1, 2...N-1 (presumably using a more sensible loop), then iterated between the values of the list! So Python had the distinction of being one of the slowest languages in which to do nothing (ie. running an empty loop). -- Bartc From stefan_ml at behnel.de Fri Sep 3 16:31:40 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Sep 2010 22:31:40 +0200 Subject: Speed-up for loops In-Reply-To: References: Message-ID: BartC, 03.09.2010 22:17: > for i in range(N): > > which (if I understood correctly) actually created a list of N objects, > populated it with the values 0, 1, 2...N-1 (presumably using a more > sensible loop), then iterated between the values of the list! I guess what applies here is "special cases aren't special enough to break the rules". The performance is good enough in most cases, it only hurts when the range is large and the loop body is small in comparison, such as in the most obvious stupid benchmarks. Also, xrange() is a pretty old addition the the language and now replaces range() in Python 3. Stefan From gavin.das1 at gmail.com Fri Sep 3 17:27:35 2010 From: gavin.das1 at gmail.com (Gavin) Date: Fri, 3 Sep 2010 14:27:35 -0700 (PDT) Subject: Date Parsing Question Message-ID: Hi, I'm using the python-dateutil package : http://labix.org/python-dateutil to parse a set of randomly formatted strings into dates. Because the formats are varied, I can't use time.strptime() because I don't know what the format is upfront. python-dateutil seems to work very well if everything is in English, however, it does not seem to work for other languages and the documentation does not seem to have any information about locale support. Here's an example showing my problem: Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from dateutil.parser import * >>> import datetime >>> import time >>> date_string1 = time.strftime("%Y-%B-%d %H:%M:%S",(2010,10,3,1,1,1,1,1,1)) >>> print date_string1 2010-October-03 01:01:01 >>> parse(date_string1) datetime.datetime(2010, 10, 3, 1, 1, 1) everything is ok so far, now retry with a date in german: >>> import locale >>> locale.setlocale(locale.LC_ALL, "german") 'German_Germany.1252' >>> locale.getlocale() ('de_DE', 'cp1252') >>> date_string1 = time.strftime("%Y-%B-%d %H:%M:%S",(2010,10,3,1,1,1,1,1,1)) >>> print date_string1 2010-Oktober-03 01:01:01 >>> parse(date_string1) Traceback (most recent call last): File "", line 1, in NameError: name 'date_string' is not defined >>> parse(date_string1) Traceback (most recent call last): File "", line 1, in File "c:\python26\lib\site-packages\python_dateutil-1.5-py2.6.egg \dateutil\parser.py", line 697, in parse return DEFAULTPARSER.parse(timestr, **kwargs) File "c:\python26\lib\site-packages\python_dateutil-1.5-py2.6.egg \dateutil\parser.py", line 303, in parse raise ValueError, "unknown string format" ValueError: unknown string format Am I out of luck with this package? Just wondering if anyone has used this to work with non-english dates. I'm also open to other ideas to handle this. Appreciate the assistance, Gavin From hobson42 at gmaiil.com Fri Sep 3 17:27:52 2010 From: hobson42 at gmaiil.com (Ian) Date: Fri, 03 Sep 2010 22:27:52 +0100 Subject: Help needed with Windows Service in Python In-Reply-To: <4C804386.90304@gmail.com> References: <4C7FC11C.7030904@ianhobson.co.uk> <4C804386.90304@gmail.com> Message-ID: <4C816858.9050105@gmaiil.com> On 03/09/2010 01:38, Mark Hammond wrote: > I expect that the Windows Event Log might have some clues, as would > attempting to use it in "debug" mode. Thanks Mark. The error log holds the trackback - it identified the line with the typo. Now the typo is fixed, the service starts and stops properly. Regards Ian From hobson42 at gmaiil.com Fri Sep 3 17:31:45 2010 From: hobson42 at gmaiil.com (Ian) Date: Fri, 03 Sep 2010 22:31:45 +0100 Subject: Help needed with Windows Service in Python In-Reply-To: <288bf7ad-9251-40d7-9270-e938170a8ed0@x25g2000yqj.googlegroups.com> References: <288bf7ad-9251-40d7-9270-e938170a8ed0@x25g2000yqj.googlegroups.com> Message-ID: <4C816941.1020408@gmaiil.com> On 02/09/2010 20:55, Edward Kozlowski wrote: > On Sep 2, 2:38 pm, Ian wrote: >> On 02/09/2010 20:06, Edward Kozlowski wrote: >> >> >> >>> On Sep 2, 10:22 am, Ian Hobson wrote: >>>> Hi All, >>>> I am attempting to create a Windows Service in Python. >>>> I have the framework (from Mark Hammond and Andy Robinason's book) >>>> running - see below. It starts fine - but it will not stop. :( >>>> net stop "Python Service" >>>> and using the services GUI both leave the services showing it as "stopping" >>>> I guess this means SvcStop is called but it is not enough to get it out >>>> of the machine. >>>> Does anyone know why not? >>>> Python 2.7 with win32 extensions, sunning on Windows 7. >>>> Many thanks >>>> Ian >>>> the (complete) source code is >>>> #!/usr/bin/env python >>>> # coding=utf8 >>>> # service.py = testing services and Named pipes >>>> # >>>> import win32serviceutil >>>> import win32service >>>> import win32event >>>> class PythonService(win32serviceutil.ServiceFramework): >>>> _svc_name_ = "Python Service" >>>> _svc_display_name_ = "Test Service in Python" >>>> def __init__(self, args): >>>> win32serviceutil.ServiceFramework.__init__(self,args) >>>> self.hWaitStop = win32event.CreateEvent(None,0,0,None) >>>> def SvcStop(self): >>>> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) >>>> wind32event.SetEvent(self.hWaitStop) >>>> def SvcDoRun(self): >>>> win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) >>>> if __name__ == '__main__': >>>> win32serviceutil.HandleCommandLine(PythonService) >>> Looks to me like there may be a typo in your code. >>> You probably meant win32event.SetEvent(self.hWaitStop), not >>> wind32event. >>> Regards, >>> -Edward Kozlowski >> A huge big thank you Edward. That was the problem. >> >> Regards >> >> Ian > You're most welcome. > > If you're looking at running services in Windows using Python, one > other hangup I ran into was that my services would freeze for no > reason. At Pycon '09, I learned that there were buffers for stdout > and stderr that were filling. I wish I could remember who gave the > talk that included the jewel of knowledge, because I'd love to give > credit where it's due... > > After I redirected stdout and stderr to files, my problems with the > services freezing went away. > > Regards, > -Edward Kozlowski Hi Edward, Thanks for the heads up. That is really worth knowing. Ian From nagle at animats.com Fri Sep 3 17:34:10 2010 From: nagle at animats.com (John Nagle) Date: Fri, 03 Sep 2010 14:34:10 -0700 Subject: Does MySQLdb rollback on control-C? Maybe not. In-Reply-To: References: <4c8077f1$0$1628$742ec2ed@news.sonic.net> Message-ID: <4c8169ce$0$1655$742ec2ed@news.sonic.net> On 9/3/2010 12:41 PM, Mike Kent wrote: > On Sep 3, 12:22 am, John Nagle wrote: >> I would expect MySQLdb to rollback on a control-C, but it doesn't >> seem to have done so. > >> Something is broken. > > I wouldn't expect it to, I'd expect to roll back on an exception, or > commit if not. MySQL does rollback properly on connection failure or program exit. It turns out I had a commit on that database handle in logging code. John Nagle From kkf628 at gmail.com Fri Sep 3 18:16:07 2010 From: kkf628 at gmail.com (=?ISO-8859-1?Q?Kristoffer_F=F8llesdal?=) Date: Fri, 3 Sep 2010 15:16:07 -0700 (PDT) Subject: IDLE / Black frame on Mac References: <3677b256-0eab-4912-b87b-d7327341fd36@x20g2000pro.googlegroups.com> Message-ID: *Forgot to tell that I am using a Mac with Snow Leopard. From db3l.net at gmail.com Fri Sep 3 18:41:45 2010 From: db3l.net at gmail.com (David Bolen) Date: Fri, 03 Sep 2010 18:41:45 -0400 Subject: Date Parsing Question References: Message-ID: Gavin writes: > python-dateutil seems to work very well if everything is in English, > however, it does not seem to work for other languages and the > documentation does not seem to have any information about locale > support. Probably because I don't think there is much built in. You'll want to supply your own parserinfo to the parse function. I haven't had to parse non-english localized date strings myself yet, but yes, the default parserinfo used by the module is in English. Looks like the docs don't get into it too much, but if you review the parser.py source in the package you can see the default parserinfo definition. I would think defining your own (or subclass of the default) and replacing the WEEKDAYS and MONTHS values would work (you can get localized lists directly from the calendar module) and maybe adding to the jump table if you want to parser longer phrases. At a first glance, the lexer within the module does seem like there may be some possible issues with more esoteric encodings or unicode, but just something to stay aware of. If you already have a i18n/l10n setup in your application (or need to have finer grained control than a global locale setting), you could instead override the lookup methods, though there's a bit more work to do since the initial lookup tables will probably need to be created in each of the locales you may wish to switch between. -- David From alistair.calder at gmail.com Fri Sep 3 18:45:34 2010 From: alistair.calder at gmail.com (alistair) Date: Fri, 3 Sep 2010 15:45:34 -0700 (PDT) Subject: New to python - parse data into Google Charts References: <42b45d97-b475-4bd8-b386-9c6db73316f9@f20g2000pro.googlegroups.com> <9222c04c-3f7f-4d36-afde-ec9dc5dfa740@i17g2000vbq.googlegroups.com> Message-ID: <5d59fb9a-e34e-4027-a562-b96526dc2761@w15g2000pro.googlegroups.com> On Sep 3, 12:51?pm, Mike Kent wrote: > On Sep 3, 1:52?pm, alistair wrote: > > > I'm new to python and my programming years are a ways behind me, so I > > was looking for some help in parsing a file into a chart using the > > Google Charts API. > > Try this:http://pygooglechart.slowchop.com/ Thanks for that. I guess I should have noted that I am new enough that I'm not even really sure how I would go about using this. From ldo at geek-central.gen.new_zealand Fri Sep 3 19:02:18 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 04 Sep 2010 11:02:18 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> Message-ID: In message <7xvd6sv0n4.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: >>> AddrObj = PyTuple_GetItem(TheBufferInfo, 0); >>> LenObj = PyTuple_GetItem(TheBufferInfo, 1); >>> >>> the first PyTuple_GetItem succeeds and the second one fails. >> >> Admittedly, I did take a shortcut here: array.buffer_info returns a tuple >> of two items, so I?m not expecting one GetItem to succeed and the other >> to fail. > > FromArray is a parameter to the function, with no type check to make > sure it's really an array. In fact your code allows for the possibility > that it doesn't support the buffer_info operation (if I understand the > purpose of the null return check after the PyObject_CallMethod) which > means it's prepared for the argument to -not- be an array. That reinforces my point, about how easy it was to check the correctness of the code. In this case one simple fix, like this diff --git a/spuhelper.c b/spuhelper.c index 83fd4eb..2ba8197 100644 --- a/spuhelper.c +++ b/spuhelper.c @@ -151,10 +151,12 @@ static void GetBufferInfo if (TheBufferInfo == 0) break; AddrObj = PyTuple_GetItem(TheBufferInfo, 0); - LenObj = PyTuple_GetItem(TheBufferInfo, 1); if (PyErr_Occurred()) break; Py_INCREF(AddrObj); + LenObj = PyTuple_GetItem(TheBufferInfo, 1); + if (PyErr_Occurred()) + break; Py_INCREF(LenObj); *addr = PyInt_AsUnsignedLongMask(AddrObj); *len = PyInt_AsUnsignedLongMask(LenObj); would render the code watertight. See how easy it is? From ldo at geek-central.gen.new_zealand Fri Sep 3 19:05:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 04 Sep 2010 11:05:03 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <4c78e7a5$0$28655$c3e8da3@news.astraweb.com> <4c7a2c3b$0$22941$e4fe514c@news.xs4all.nl> <7xhbidndc6.fsf@ruckus.brouhaha.com> <8e15pqFn89U1@mid.individual.net> <7xmxs4uzjl.fsf@ruckus.brouhaha.com> <7xiq2que93.fsf@ruckus.brouhaha.com> Message-ID: In message <7xiq2que93.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: >> >>> Refcounting is susceptable to the same pauses for reasons already >>> discussed. >> >> Doesn?t seem to happen in the real world, though. > > def f(n): > from time import time > a = [1] * n > t0 = time() > del a > t1 = time() > return t1 - t0 > > for i in range(9): > print i, f(10**i) > > > on my system prints: > > 0 2.86102294922e-06 > 1 2.14576721191e-06 > 2 3.09944152832e-06 > 3 1.00135803223e-05 > 4 0.000104904174805 > 5 0.00098991394043 > 6 0.00413608551025 > 7 0.037693977356 > 8 0.362598896027 > > Looks pretty linear as n gets large. 0.36 seconds (the last line) is a > noticable pause. Which just proves the point. You had to deliberately set up the situation to make that happen. And it remains just as easy to pinpoint where it is happening, so you can control it. With a garbage collector, you don?t have that control. Even if you try to avoid freeing a single large structure at once, it?s still liable to batch up a lot of small objects to free at once, so the problem can still happen. From ldo at geek-central.gen.new_zealand Fri Sep 3 19:31:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 04 Sep 2010 11:31:26 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> Message-ID: In message <7xmxs2uez1.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: > >> Whereas garbage collection will happen at some indeterminate time long >> after the last access to the object, when it very likely will no longer >> be in the cache, and have to be brought back in just to be freed, > > GC's for large systems generally don't free (or even examine) individual > garbage objects. They copy the live objects to a new contiguous heap > without ever touching the garbage, and then they release the old heap. And suddenly you?ve doubled the memory requirements. And on top of that, since you?re moving the valid objects into different memory, you?re forcing cache misses on all of them as well. This is the continuing problem with garbage collection: all the attempts to make it cheaper just end up moving the costs somewhere else. From ldo at geek-central.gen.new_zealand Fri Sep 3 19:33:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 04 Sep 2010 11:33:08 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> Message-ID: In message <7xr5heufhb.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Java has considerably greater reputation for reliability than C or C++. Wonder why Sun?s licence explicitly forbade its use in danger-critical areas like nuclear power plants and the like, then? > Ada is a different story, but Ada programs (because of the application > area Ada is used in) tend not to use a lot of dynamic memory allocation > in the first place. A little googling shows there are GC extensions > available for Ada, though I don't know if they are used much. Let?s put it this way: the life-support system on the International Space Station is written in Ada. Would you trust your life to code written in Java? From no.email at nospam.invalid Fri Sep 3 22:21:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 03 Sep 2010 19:21:42 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> Message-ID: <7xbp8el03t.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: >> Java has considerably greater reputation for reliability than C or C++. > > Wonder why Sun?s licence explicitly forbade its use in danger-critical > areas like nuclear power plants and the like, then? Probably because Sun lawyers demanded it. Is there a Sun C or C++ compiler with a license that doesn't have that restriction? Even if there is, it just means those languages are so unreliable that the lawyers felt confident that any meltdown could be blamed on a bug in the user's rather than the compiler ;-). > Let?s put it this way: the life-support system on the International Space > Station is written in Ada. Would you trust your life to code written in > Java? The scary thing is I don't know whether I'm already doing that. Life support systems have hard real-time requirements (Ada's forte) but I'd expect lots of military decision-support systems are written in Java. Maybe one of them will raise a false alert and somebody will launch a war. From chinnamma5463 at gmail.com Fri Sep 3 22:26:30 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:26:30 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: The Amazing Google Adsense Program is now towering like a Colossus in the Internet. It has helped approximately smart Internet Marketers to get on to enormous amounts of while by the same calculate it is appealing to annotation with the intention of many extra Internet Marketers and Internet Home-Based Business Entrepreneurs are receiving their initially shell out check from Google Adsense very than the foremost connect curriculum. visit http://www.adsensesubstitutes.com/ for more details. From chinnamma5463 at gmail.com Fri Sep 3 22:27:45 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:27:45 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: <81955314-2a1c-479e-89c6-d0922a3b0c28@q40g2000prg.googlegroups.com> If you control a website and wish to promote it for money at home, therefore the Google AdSense syllabus is inescapable merely in support of you. It has befall a bonus in support of a luck of sites whether they are small or sizeable or form. Taking part in information, this has befall such a all the rage tool with the purpose of a number of web designers control making websites solely in support of the intent of AdSense. visit http://www.adsensesubstitutes.com/adsense-program.htm From chinnamma5463 at gmail.com Fri Sep 3 22:29:25 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:29:25 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: It's an untoward information with the purpose of many AdSense users are getting their accounts terminated by the time they've complete nothing unsuitable. Considering the money individual can promote to from operational AdSense employment, the loss of one's bank account can be a real blow. Especially if the holder doesn't know why their bank account is being revoked! visit http://www.adsensesubstitutes.com/adsense-clicks.htm From chinnamma5463 at gmail.com Fri Sep 3 22:30:08 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:30:08 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: <0e653e52-8a82-4f76-829a-2b2a94b5b1ce@a4g2000prm.googlegroups.com> Google is arguably the majority all the rage website on the internet. With Google's AdSense syllabus, Google allows you to earn money by iplacing ads on your website. The majority of Google's revenue comes from advertising. Search engines forever control ads with the purpose of are tagged by the given keywords with the purpose of you enter, and the ads appear along with the search results visit http://www.adsensesubstitutes.com/adsense-earn-money.htm From chinnamma5463 at gmail.com Fri Sep 3 22:31:37 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:31:37 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: <301ca28a-026d-42fc-ba57-95d10d1d97a6@p22g2000pre.googlegroups.com> On the wild frontiers of the internet, in attendance are hundreds or thousands of prospectors, all striving to clash with the after that sizeable smash into. One of the majority all the rage methods of mining in support of internet gold is to employment Google AdSense. visit http://www.adsensesubstitutes.com/adsense-making-money.htm From chinnamma5463 at gmail.com Fri Sep 3 22:32:17 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:32:17 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: I'm pretty certain with the purpose of we all can promote to this allegation - "I know quite a luck approaching AdSense". This of track will be authentic in a convinced context. For illustration what time you are conversation to an recluse, someone who doesn't apply AdSense to his or her website, so therefore all right, you will know quite a luck approaching AdSense. But on a level singing sports ground sat after that to any more AdSense extreme, might you promote to the same allegation? visit http://www.adsensesubstitutes.com/Adsense-help.htm From chinnamma5463 at gmail.com Fri Sep 3 22:33:10 2010 From: chinnamma5463 at gmail.com (chinnamma) Date: Fri, 3 Sep 2010 19:33:10 -0700 (PDT) Subject: Google Adsense Earnings, google adsense tips Message-ID: <8fe7292d-7ae1-4092-b9e8-c7649fa1faa6@l38g2000pro.googlegroups.com> Recently I found I had a a small amount of websites I had basically abandoned, Mostly as the products had befall with a reduction of desirable and were Veto longer worth the effort of promoting. I unfaltering more exactly than Accede to the sites simply sit in attendance price me hosting money - I Be supposed to try to optimize the sites in support of Google AdSense and see to it that if I Might promote to a few profits from the sites next to all. visit http://www.adsensesubstitutes.com/adSense-tutorial.htm From python at mrabarnett.plus.com Fri Sep 3 22:46:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Sep 2010 03:46:08 +0100 Subject: Queue cleanup In-Reply-To: <7xbp8el03t.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> <7xbp8el03t.fsf@ruckus.brouhaha.com> Message-ID: <4C81B2F0.8070807@mrabarnett.plus.com> On 04/09/2010 03:21, Paul Rubin wrote: > Lawrence D'Oliveiro writes: >>> Java has considerably greater reputation for reliability than C or C++. >> >> Wonder why Sun?s licence explicitly forbade its use in danger-critical >> areas like nuclear power plants and the like, then? > > Probably because Sun lawyers demanded it. Is there a Sun C or C++ > compiler with a license that doesn't have that restriction? Even if > there is, it just means those languages are so unreliable that the > lawyers felt confident that any meltdown could be blamed on a bug in the > user's rather than the compiler ;-). > >> Let?s put it this way: the life-support system on the International Space >> Station is written in Ada. Would you trust your life to code written in >> Java? > > The scary thing is I don't know whether I'm already doing that. Life > support systems have hard real-time requirements (Ada's forte) but I'd > expect lots of military decision-support systems are written in Java. > Maybe one of them will raise a false alert and somebody will launch a > war. I thought it was just that if it wasn't explicitly forbidden then someone might try to use it and then sue if something went wrong, even though common sense would have said that it was a bad idea in the first place! :-) From no.email at nospam.invalid Fri Sep 3 22:59:17 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 03 Sep 2010 19:59:17 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> Message-ID: <7x7hj2kyd6.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: >> GC's for large systems generally don't free (or even examine) individual >> garbage objects. They copy the live objects to a new contiguous heap >> without ever touching the garbage, and then they release the old heap. > > And suddenly you?ve doubled the memory requirements. And on top of that, > since you?re moving the valid objects into different memory, you?re forcing > cache misses on all of them as well. A minimal naive implementation indeed doubles the memory requirements, but from a Python perspective where every integer takes something like 24 bytes already, even that doesn't seem so terrible. More sophisticated implementations use multiple small heaps or other tricks. It still costs something in memory footprint, but less than the minimal implementation's 2x cost. The new heap is filled sequentially so accesses to it will have good locality. You do have to jump around within the old heap, but again, with generational schemes, in the more frequent collections, the old heap fits entirely in cache. For example, GHC's minor heap size is 256kB. For major collections, GHC switches (or used to) from copying to a mark/compact scheme once the amount of live data in the heap goes over some amount, giving the best of both worlds. It's also the case that programs with very large memory consumption tend to use most of the memory for large arrays that don't contain pointers (think of a database server with a huge cache). That means the gc doesn't really have to think about all that much of the memory. > This is the continuing problem with garbage collection: all the attempts to > make it cheaper just end up moving the costs somewhere else. Same thing with manual allocation. That moves the costs off the computer and onto the programmer. Not good, most of the time. Really, I'm no gc expert, but the stuff you're saying about gc is quite ill-informed. You might want to check out some current literature. From nad at acm.org Fri Sep 3 23:19:09 2010 From: nad at acm.org (Ned Deily) Date: Fri, 03 Sep 2010 20:19:09 -0700 Subject: IDLE / Black frame on Mac References: <3677b256-0eab-4912-b87b-d7327341fd36@x20g2000pro.googlegroups.com> Message-ID: In article , Kristoffer Follesdal wrote: > *Forgot to tell that I am using a Mac with Snow Leopard. Which version of Python 3.1.2? From the python.org installer? MacPorts? Built from source - if so, which version of Tk? -- Ned Deily, nad at acm.org From trent at snakebite.org Sat Sep 4 02:21:42 2010 From: trent at snakebite.org (Trent Nelson) Date: Sat, 4 Sep 2010 02:21:42 -0400 Subject: Financial time series data In-Reply-To: <4C80DC11.50504@it.uu.se> References: <4C80DC11.50504@it.uu.se> Message-ID: <4C81E576.8080803@snakebite.org> On 03-Sep-10 7:29 AM, Virgil Stokes wrote: > A more direct question on accessing stock information from Yahoo. > > First, use your browser to go to: > http://finance.yahoo.com/q/cp?s=%5EGSPC+Components > > Now, you see the first 50 rows of a 500 row table of information on S&P > 500 index. You can LM click on > > 1 -50 of 500 |First|Previous|Next|Last > > below the table to position to any of the 10 pages. > > I would like to use Python to do the following. > > *Loop on each of the 10 pages and for each page extract information for > each row --- How can this be accomplished automatically in Python?* > > Let's take the first page (as shown by default). It is easy to see the > link to the data for "A" is http://finance.yahoo.com/q?s=A. That is, I > can just move > my cursor over the "A" and I see this URL in the message at the bottom > of my browser (Explorer 8). If I LM click on "A" then I will go to this > link --- Do this! > > You should now see a table which shows information on this stock and > *this is the information that I would like to extract*. I would like to > do this for all 500 stocks without the need to enter the symbols for > them (e.g. "A", "AA", etc.). It seems clear that this should be possible > since all the symbols are in the first column of each of the 50 tables > --- but it is not at all clear how to extract these automatically in > Python. > > Hopefully, you understand my problem. Again, I would like Python to > cycle through these 10 pages and extract this information for each > symbol in this table. > > --V You want the 'get_historical_prices' method of the (beautifully elegant) 'ystockquote.py': http://www.goldb.org/ystockquote.html. Just specify start date and end date and wallah, you get an array of historical price data for any symbol you pass in. I used this module with great success to download ten years of historical data for every symbol I've ever traded. Regards, Trent. From trent at snakebite.org Sat Sep 4 02:24:11 2010 From: trent at snakebite.org (Trent Nelson) Date: Sat, 4 Sep 2010 02:24:11 -0400 Subject: Financial time series data In-Reply-To: <1283536093.2894.12.camel@hatchbox-one> References: <4C80DC11.50504@it.uu.se> <1283521536.2364.139.camel@hatchbox-one> <4C810AA1.7060700@it.uu.se> <1283536093.2894.12.camel@hatchbox-one> Message-ID: <4C81E60B.9090900@snakebite.org> On 03-Sep-10 1:48 PM, Frederic Rentsch wrote: > And do let us know if you get an answer from Yahoo. Hacks like this > are unreliable. They fail almost certainly the next time a page gets > redesigned, which can be any time. Indeed -- see my other post (regarding ystockquote.py). There's a CSV HTTP API that should be used if you want to obtain any Yahoo! Finance data programmatically. Trent. From no.email at nospam.invalid Sat Sep 4 04:50:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Sep 2010 01:50:07 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> Message-ID: <7xeid9dha8.fsf@ruckus.brouhaha.com> Dennis Lee Bieber writes: > Not to mention having to ensure that one finds ALL the references to > the object so that they can be updated to the new address! Somehow I > don't see a C compiler being smart enough to find intermediary pointer We're not talking about C compilers, which can cast any value at all into pointers. Languages designed for garbage collection are normally type-safe and gc is a well-understood problem, though (like compilers) the higher-performing ones are complicated. But, nothing in principle stops anyone from implementing Python with such methods. From anthra.norell at bluewin.ch Sat Sep 4 05:14:24 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Sat, 04 Sep 2010 11:14:24 +0200 Subject: Financial time series data In-Reply-To: <4C813761.8020500@it.uu.se> References: <4C813761.8020500@it.uu.se> Message-ID: <1283591664.2345.27.camel@hatchbox-one> On Fri, 2010-09-03 at 19:58 +0200, Virgil Stokes wrote: > import urllib2 > import re > > def get_SP500_symbolsX (): > symbols = [] > lsttradestr = re.compile('Last Trade:') > k = 0 > for page in range(10): > url = 'http://finance.yahoo.com/q/cp?s=%5EGSPC&c='+str(page) > print url > f = urllib2.urlopen (url) > html = f.readlines () > f.close () > for line in html: > if line.lstrip ().startswith (' line_split = line.split (':') > s = [item.strip ().upper () for item in line_split [5].replace > ('"','').split (',')] > for symb in s: > url = "http://finance.yahoo.com/q?s="+symb > f = urllib2.urlopen(url) > html = f.readlines() > f.close() > > for line in html: > if lsttradestr.search(line): > k += 1 > print 'k = %3d (%s)' %(k,symb) > # Here is where I will extract the numerical values and place > # .... > # them in an approrpriate file > symbols.extend (s [:-3]) > > return symbols > # Not quite 500 -- which is correct (for example p. 2 has only 49 symbols!) > # Actually the S&P 500 as shown does not contain 500 stocks (symbols) > > > symbols = get_SP500_symbolsX() > pass > > And thanks for your help Frederic --- Have a good day! :-) > > --V Good going! You get the idea. Here's my try for a cleaned-up version that makes the best use of the facility and takes only fifteen seconds to complete (on my machine). You may want to look at historical quotes too. Trent Nelson seems to have a ready-made solution for this. --------------------------- import urllib2 import re def get_current_SP500_quotes_from_Yahoo (): symbol_reader = re.compile ('([a-z-.]+,)+[a-z-.]+') # Make sure you include all characters that may show up in symbols, csv_data = '' for page in range (10): url = 'http://finance.yahoo.com/q/cp?s=%5EGSPC&c=' + str (page) print url f = urllib2.urlopen (url) html = f.readlines () f.close () for line in html: if line.lstrip ().startswith (' Message-ID: <689931a1-1c49-478d-bacf-3f42f4dd42b9@13g2000prf.googlegroups.com> I write some object for Taiwan Stock ... http://github.com/toomore/goristock But still dev ... On Sep 3, 1:12?am, Virgil Stokes wrote: > ? Has anyone written code or worked with Python software for downloading > financial time series data (e.g. from Yahoo financial)? If yes, ?would you > please contact me. > > --Thanks, > V. Stokes From kkf628 at gmail.com Sat Sep 4 05:26:18 2010 From: kkf628 at gmail.com (=?ISO-8859-1?Q?Kristoffer_F=F8llesdal?=) Date: Sat, 4 Sep 2010 02:26:18 -0700 (PDT) Subject: IDLE / Black frame on Mac References: <3677b256-0eab-4912-b87b-d7327341fd36@x20g2000pro.googlegroups.com> Message-ID: <2d0cc097-4064-47e2-a609-f1c9f9f13ee2@l20g2000yqm.googlegroups.com> On Sep 4, 5:19?am, Ned Deily wrote: > In article > , > ?Kristoffer Follesdal wrote: > > > *Forgot to tell that I am using a Mac with Snow Leopard. > > Which version of Python 3.1.2? ?From the python.org installer? ? > MacPorts? ?Built from source - if so, which version of Tk? > > -- > ?Ned Deily, > ?n... at acm.org I used the installer from python.org. Tk version 8.4. From mohammad.rahmani at gmail.com Sat Sep 4 07:25:18 2010 From: mohammad.rahmani at gmail.com (atronoush) Date: Sat, 4 Sep 2010 04:25:18 -0700 (PDT) Subject: pyla: python little algorithms Message-ID: <0c7993e3-f115-440b-97d8-3db39b6bf6f9@x25g2000yqj.googlegroups.com> Dear all, pyla stands for Python Little Algorithm is a project in pure Python and includes simple, easy to use, yet powerful libraries for - 2D/3D plotting using Gnuplot - Matrix/Vector operations - ODE solvers - Optimization and nonlinear algebraic equation solvers - ... Homepage: pyla home is: http://pyla.codeplex.com pyla documentation is on Tiddlywiki (www.tiddlywiki.org) a lightweight and portable wiki. Current Status: Currently the gplot library with status alpha has been released, other libraries is planned to be released bi-monthly. Contribution: We welcome all kind of contribution to this project. pyla is free, and open source.. All the best Mohammad Rahmani Chem Eng Dep Amirkabir Uni of Tech From aahz at pythoncraft.com Sat Sep 4 08:26:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Sep 2010 05:26:16 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> <7x7hj2kyd6.fsf@ruckus.brouhaha.com> Message-ID: [gc] In article <7x7hj2kyd6.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > >A minimal naive implementation indeed doubles the memory requirements, >but from a Python perspective where every integer takes something like >24 bytes already, even that doesn't seem so terrible. Many people still use 32-bit Python -- an int is twelve bytes there. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From aahz at pythoncraft.com Sat Sep 4 09:10:32 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Sep 2010 06:10:32 -0700 Subject: String substitution VS proper mysql escaping References: <4C6BA2C4.4000309@gmail.com> Message-ID: In article , =?UTF-8?B?zp3Or866zr/Pgg==?= wrote: > >After all () used to define tuples and [] usedd to define lists. Why >commas? No, "()" does *not* define tuples, except for the empty tuple. The comma defines tuples, with parentheses simply used for visual effect: >>> 1, 2, 3 (1, 2, 3) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From whatsjacksemail at gmail.com Sat Sep 4 09:36:38 2010 From: whatsjacksemail at gmail.com (Jack Keegan) Date: Sat, 4 Sep 2010 14:36:38 +0100 Subject: State Machines in Python Message-ID: Hi girls & guys, Just joined the group. I'm new to Python but been picking it up pretty easy. I love it! I'm hoping to use it to make a controlling application for an experiment. Basically I want to use it to interface with some data acquisition (DAQ) hardware to accept incoming signals and respond sending signals to the outputs. I'm looking for an efficient State Machine algorithm as I need the timing to be as good as possible. As there is no switch statement in Python, I've been looking around for a good implementation. Most of the algorithms I've come across seem to be based on parsing applications. I'd like something more suited to my needs. I'd like to avoid excessive use of 'if-elif-else' statements as each would have to be checked to find the right conditions which would have an time overhead involved. I have seen an implementation of the switch using dictionaries but someone had commented that creating and throwing away dictionaries also comes at a cost. I was wondering if any of you could advise or point me in the right direction. Any help would be greatly appreciated. Thanks, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Sat Sep 4 09:49:53 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Sep 2010 09:49:53 -0400 Subject: State Machines in Python In-Reply-To: References: Message-ID: <20100904094953.a084b648.darcy@druid.net> On Sat, 4 Sep 2010 14:36:38 +0100 Jack Keegan wrote: > Just joined the group. I'm new to Python but been picking it up pretty easy. Welcome aboard. > As there is no switch statement in Python, I've been looking around for a > good implementation. Most of the algorithms I've come across seem to be There's no switch statement because there's no real need for one. Check out the following sample code and see if it gives you some ideas. #! /usr/bin/env python # -*- coding: utf-8 -*- # Sample state machine import sys data = dict(counter = 0, flag = False) def state1(d): d['counter'] += 1 print "In state 1, counter = %(counter)d" % d if d['flag']: sys.exit(0) return state2 def state2(d): d['counter'] += 1 print "In state 2, counter = %(counter)d" % d return state3 def state3(d): d['counter'] += 1 d['flag'] = True print "In state 3, counter = %(counter)d" % d return state1 state = state1 while True: state = state(data) -- 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 stefan_ml at behnel.de Sat Sep 4 10:41:46 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Sep 2010 16:41:46 +0200 Subject: State Machines in Python In-Reply-To: References: Message-ID: Jack Keegan, 04.09.2010 15:36: > Hi girls& guys, > > Just joined the group. I'm new to Python but been picking it up pretty easy. > I love it! Welcome to the group. > I'm hoping to use it to make a controlling application for an > experiment. Basically I want to use it to interface with some data > acquisition (DAQ) hardware to accept incoming signals and respond sending > signals to the outputs. I'm looking for an efficient State Machine algorithm > as I need the timing to be as good as possible. > As there is no switch statement in Python, I've been looking around for a > good implementation. Most of the algorithms I've come across seem to be > based on parsing applications. I'd like something more suited to my needs. > I'd like to avoid excessive use of 'if-elif-else' statements as each would > have to be checked to find the right conditions which would have an time > overhead involved. I have seen an implementation of the switch using > dictionaries but someone had commented that creating and throwing away > dictionaries also comes at a cost. > I was wondering if any of you could advise or point me in the right > direction. Dictionaries are a common way to do it, and there are different recipes. A second way is a class that dispatches to its methods. A third (IMHO rather beautiful) way is coroutines: http://gnosis.cx/publish/programming/charming_python_b5.html http://www.dabeaz.com/coroutines/Coroutines.pdf However, you'll have to do some benchmarking if you care about performance. Dictionaries are fast and likely the fastest way to do it, but coroutines are a lot more versatile. Stackless Python might also be worth a look in this context, it's fast *and* versatile. You should also be aware that there are various event driven frameworks (like Twisted, eventlet and others) that make asynchronous event handling fast and easy, and that use much higher-level abstractions than pure state machines. Stefan From stef.mientki at gmail.com Sat Sep 4 12:26:17 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 04 Sep 2010 18:26:17 +0200 Subject: State Machines in Python In-Reply-To: References: Message-ID: <4C827329.4050706@gmail.com> On 04-09-2010 15:36, Jack Keegan wrote: > Hi girls & guys, > > Just joined the group. I'm new to Python but been picking it up pretty easy. I love it! I'm hoping > to use it to make a controlling application for an experiment. Basically I want to use it to > interface with some data acquisition (DAQ) hardware to accept incoming signals and respond sending > signals to the outputs. I'm looking for an efficient State Machine algorithm as I need the timing > to be as good as possible. What is as good as possible, 1 usec, 1 msec ? What operating system are you using ? Are you planning feedback ? For a comparison, I did a few years ago sampling in Python, with NI cards (they ensure time accuracy which can never be achieved in software), 50 kHz (divided over 1 to 8 channels), 32 bit, storage and graphical display, and processor activity was about 10%. Maybe you should also look at what those radio guys from gnu radio achive. cheers, Stef > As there is no switch statement in Python, I've been looking around for a good implementation. > Most of the algorithms I've come across seem to be based on parsing applications. I'd like > something more suited to my needs. I'd like to avoid excessive use of 'if-elif-else' statements as > each would have to be checked to find the right conditions which would have an time overhead > involved. I have seen an implementation of the switch using dictionaries but someone had commented > that creating and throwing away dictionaries also comes at a cost. > I was wondering if any of you could advise or point me in the right direction. > > Any help would be greatly appreciated. > > Thanks, > > Jack From martin at v.loewis.de Sat Sep 4 12:51:29 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 04 Sep 2010 18:51:29 +0200 Subject: Installation problem: Python 2.6.6 (32-Bit) on Windows 7 (32-Bit) In-Reply-To: <0781783a-b182-455f-8522-ed5a37db6e14@o7g2000prg.googlegroups.com> References: <0781783a-b182-455f-8522-ed5a37db6e14@o7g2000prg.googlegroups.com> Message-ID: <4C827911.1020705@v.loewis.de> Am 01.09.2010 21:18, schrieb Cappy2112: > Has anyone else had problems running the msi for Python 2.6.6 on > Windows 7 Professional? I specifically tested whether "compile .py" works before the release, and it worked fine on my machine. I suspect you have a source file on your disk that it tries to compile and it won't, because of a syntax error. Regards, Martin From martin at v.loewis.de Sat Sep 4 12:52:15 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 04 Sep 2010 18:52:15 +0200 Subject: what is this kind of string: b'string' ? In-Reply-To: References: Message-ID: <4C82793F.4040704@v.loewis.de> Am 01.09.2010 23:32, schrieb Stef Mientki: > in winpdb I see strings like this: > >>>> a = b'string' >>>> a > 'string' >>>> type(a) > > > what's the "b" doing in front of the string ? It's redundant. Regards, Martin From stefan_ml at behnel.de Sat Sep 4 13:27:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Sep 2010 19:27:34 +0200 Subject: what is this kind of string: b'string' ? In-Reply-To: <4C82793F.4040704@v.loewis.de> References: <4C82793F.4040704@v.loewis.de> Message-ID: Martin v. Loewis, 04.09.2010 18:52: > Am 01.09.2010 23:32, schrieb Stef Mientki: >> in winpdb I see strings like this: >> >> >>> a = b'string' >> >>> a >> 'string' >> >>> type(a) >> >> >> what's the "b" doing in front of the string ? > > It's redundant. Not completely. (I know that you know this, but to those who don't, your answer may be misleading.) If you use 2to3 to convert the above to Python 3 code, it will leave the 'b' in front of the string, so the resulting string literal will be a bytes string in Python 3. If you remove it, the string will become a unicode literal. Since the code is syntax compatible with Python 3, simply running it in a Python 3 interpreter will also show this behaviour. So it's redundant in Python 2, but it's no longer redundant when you plan to migrate the code to Python 3. Stefan From martin at v.loewis.de Sat Sep 4 13:35:24 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 04 Sep 2010 19:35:24 +0200 Subject: what is this kind of string: b'string' ? In-Reply-To: References: <4C82793F.4040704@v.loewis.de> Message-ID: <4C82835C.70008@v.loewis.de> Am 04.09.2010 19:27, schrieb Stefan Behnel: > Martin v. Loewis, 04.09.2010 18:52: >> Am 01.09.2010 23:32, schrieb Stef Mientki: >>> in winpdb I see strings like this: >>> >>> >>> a = b'string' >>> >>> a >>> 'string' >>> >>> type(a) >>> >>> >>> what's the "b" doing in front of the string ? >> >> It's redundant. > > Not completely. (I know that you know this, but to those who don't, your > answer may be misleading.) Actually, I didn't think of this (knowing something and being aware of it are different things ...) I personally don't use it in the 2to3 way, because it requires Python 2.6. For code that needs to go back further, I typically do b('string') with a custom b() function. That's less efficient, of course, since it causes a function call on evaluation. Thanks, Martin From roy at panix.com Sat Sep 4 13:58:00 2010 From: roy at panix.com (Roy Smith) Date: Sat, 04 Sep 2010 13:58:00 -0400 Subject: State Machines in Python References: Message-ID: In article , "D'Arcy J.M. Cain" wrote: > On Sat, 4 Sep 2010 14:36:38 +0100 > Jack Keegan wrote: > > Just joined the group. I'm new to Python but been picking it up pretty easy. > > Welcome aboard. > > > As there is no switch statement in Python, I've been looking around for a > > good implementation. Most of the algorithms I've come across seem to be > > There's no switch statement because there's no real need for one. > Check out the following sample code and see if it gives you some ideas. > > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > # Sample state machine > > import sys > > data = dict(counter = 0, flag = False) > > def state1(d): > d['counter'] += 1 > print "In state 1, counter = %(counter)d" % d > if d['flag']: sys.exit(0) > return state2 > > def state2(d): > d['counter'] += 1 > print "In state 2, counter = %(counter)d" % d > return state3 > > def state3(d): > d['counter'] += 1 > d['flag'] = True > print "In state 3, counter = %(counter)d" % d > return state1 > > state = state1 > while True: > state = state(data) This is the pattern I've always used. Simple and effective for any state machine which is small enough to code by hand. I generally have my state methods return (next_state, output) tuples, but that's a detail. From python at mrabarnett.plus.com Sat Sep 4 14:13:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Sep 2010 19:13:28 +0100 Subject: State Machines in Python In-Reply-To: References: Message-ID: <4C828C48.8050404@mrabarnett.plus.com> On 04/09/2010 18:58, Roy Smith wrote: > In article, > "D'Arcy J.M. Cain" wrote: > >> On Sat, 4 Sep 2010 14:36:38 +0100 >> Jack Keegan wrote: >>> Just joined the group. I'm new to Python but been picking it up pretty easy. >> >> Welcome aboard. >> >>> As there is no switch statement in Python, I've been looking around for a >>> good implementation. Most of the algorithms I've come across seem to be >> >> There's no switch statement because there's no real need for one. >> Check out the following sample code and see if it gives you some ideas. >> >> #! /usr/bin/env python >> # -*- coding: utf-8 -*- >> >> # Sample state machine >> >> import sys >> >> data = dict(counter = 0, flag = False) >> >> def state1(d): >> d['counter'] += 1 >> print "In state 1, counter = %(counter)d" % d >> if d['flag']: sys.exit(0) >> return state2 >> >> def state2(d): >> d['counter'] += 1 >> print "In state 2, counter = %(counter)d" % d >> return state3 >> >> def state3(d): >> d['counter'] += 1 >> d['flag'] = True >> print "In state 3, counter = %(counter)d" % d >> return state1 >> >> state = state1 >> while True: >> state = state(data) > > This is the pattern I've always used. Simple and effective for any > state machine which is small enough to code by hand. I generally have > my state methods return (next_state, output) tuples, but that's a detail. I suppose that if they are that similar then you could generate the code from a list or table of the states. From pramo4d at gmail.com Sat Sep 4 14:28:06 2010 From: pramo4d at gmail.com (Pramod) Date: Sat, 4 Sep 2010 11:28:06 -0700 (PDT) Subject: Error in Following python program Message-ID: <53ebbc6c-5624-4d74-9fa2-007895a8787e@m17g2000prl.googlegroups.com> #/usr/bin/python from numpy import matrix n=input('Enter matrix range') fr=open('mat.txt','r') print ('Enter elements into the matrix\n') a=matrix([[input()for j in range(n)] for i in range(n)]) for i in range(n): for j in range(n): print a[i][j] print '\n' When i run the above program the following error is Coming please Error is Enter matrix range3 Enter elements into the matrix 1 2 3 4 5 6 7 8 9 [[1 2 3]] Traceback (most recent call last): File "2.py", line 10, in print a[i][j] File "/usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py", line 265, in __getitem__ out = N.ndarray.__getitem__ please resolve my problem Thanks in advance ~ From darcy at druid.net Sat Sep 4 14:30:22 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Sep 2010 14:30:22 -0400 Subject: State Machines in Python In-Reply-To: References: Message-ID: <20100904143022.a8e855c0.darcy@druid.net> On Sat, 04 Sep 2010 13:58:00 -0400 Roy Smith wrote: > > while True: > > state = state(data) > > This is the pattern I've always used. Simple and effective for any > state machine which is small enough to code by hand. I generally have > my state methods return (next_state, output) tuples, but that's a detail. What is "output" for? Is it a string or something else? What do you do with it? Notice that I create a dictionary which is passed around so that states can pass whatever information back that they deem useful and any state can pick up whatever info it needs. for example, in my sample code every state uses the counter but only two states use the flag element. -- 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 Sat Sep 4 14:32:02 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Sep 2010 14:32:02 -0400 Subject: State Machines in Python In-Reply-To: <4C828C48.8050404@mrabarnett.plus.com> References: <4C828C48.8050404@mrabarnett.plus.com> Message-ID: <20100904143202.82382f0e.darcy@druid.net> On Sat, 04 Sep 2010 19:13:28 +0100 MRAB wrote: > I suppose that if they are that similar then you could generate the > code from a list or table of the states. They generally aren't as simple as the little example script that I cobbled together. -- 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 mrabarnett.plus.com Sat Sep 4 14:46:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Sep 2010 19:46:23 +0100 Subject: Error in Following python program In-Reply-To: <53ebbc6c-5624-4d74-9fa2-007895a8787e@m17g2000prl.googlegroups.com> References: <53ebbc6c-5624-4d74-9fa2-007895a8787e@m17g2000prl.googlegroups.com> Message-ID: <4C8293FF.7030300@mrabarnett.plus.com> On 04/09/2010 19:28, Pramod wrote: > #/usr/bin/python > from numpy import matrix > n=input('Enter matrix range') > fr=open('mat.txt','r') > print ('Enter elements into the matrix\n') > a=matrix([[input()for j in range(n)] for i in range(n)]) > for i in range(n): > for j in range(n): > print a[i][j] > print '\n' > > When i run the above program the following error is Coming please > Error is > Enter matrix range3 > Enter elements into the matrix > > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > [[1 2 3]] > Traceback (most recent call last): > File "2.py", line 10, in > print a[i][j] > File "/usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py", > line 265, in __getitem__ > out = N.ndarray.__getitem__ > > please resolve my problem Thanks in advance > ~ The matrix is 2-dimensional, which in numpy is means you need to write: a[i, i] not: a[i][j] and no, they're not the same! :-) From stefan_ml at behnel.de Sat Sep 4 14:46:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Sep 2010 20:46:54 +0200 Subject: State Machines in Python In-Reply-To: <20100904143022.a8e855c0.darcy@druid.net> References: <20100904143022.a8e855c0.darcy@druid.net> Message-ID: D'Arcy J.M. Cain, 04.09.2010 20:30: > On Sat, 04 Sep 2010 13:58:00 -0400 > Roy Smith wrote: >>> while True: >>> state = state(data) >> >> This is the pattern I've always used. Simple and effective for any >> state machine which is small enough to code by hand. I generally have >> my state methods return (next_state, output) tuples, but that's a detail. > > What is "output" for? Is it a string or something else? What do you > do with it? Notice that I create a dictionary which is passed around > so that states can pass whatever information back that they deem useful > and any state can pick up whatever info it needs. for example, in my > sample code every state uses the counter but only two states use the > flag element. I guess the idea is that each of the states can't arbitrarily modify the global status (dict) but is restricted to designating a next state and returning something. So you don't take the risk of introducing side effects somewhere because all state implementations are pure functions (at least as far as the state machine itself is concerned). Stefan From __peter__ at web.de Sat Sep 4 14:49:58 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 04 Sep 2010 20:49:58 +0200 Subject: Error in Following python program References: <53ebbc6c-5624-4d74-9fa2-007895a8787e@m17g2000prl.googlegroups.com> Message-ID: Pramod wrote: > #/usr/bin/python > from numpy import matrix > n=input('Enter matrix range') > fr=open('mat.txt','r') > print ('Enter elements into the matrix\n') > a=matrix([[input()for j in range(n)] for i in range(n)]) > for i in range(n): > for j in range(n): > print a[i][j] > print '\n' > > When i run the above program the following error is Coming please > Error is > Enter matrix range3 > Enter elements into the matrix > > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > [[1 2 3]] > Traceback (most recent call last): > File "2.py", line 10, in > print a[i][j] > File "/usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py", > line 265, in __getitem__ > out = N.ndarray.__getitem__ > > please resolve my problem Thanks in advance You can either use an array instead of a matrix and continue to access the elements like you did in your code >>> a = numpy.array([[1,2],[3,4]]) >>> a[1][1] 4 or continue to use the matrix and access its elements with a tuple >>> b = numpy.matrix([[1,2],[3,4]]) >>> b[1,1] 4 If you pass only one index you get another, smaller matrix: >>> b[1] matrix([[3, 4]]) Once you see this printed it should be clear that b[1][1] asks for the non- existent second row of the above matrix. Hence the error: >>> b[1][1] Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py", line 265, in __getitem__ out = N.ndarray.__getitem__(self, index) IndexError: index out of bounds By the way, these matrices are really strange beasts: >>> b[0][0] matrix([[1, 2]]) >>> b[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0] matrix([[1, 2]]) Peter From roy at panix.com Sat Sep 4 15:45:17 2010 From: roy at panix.com (Roy Smith) Date: Sat, 04 Sep 2010 15:45:17 -0400 Subject: State Machines in Python References: Message-ID: In article , "D'Arcy J.M. Cain" wrote: > On Sat, 04 Sep 2010 13:58:00 -0400 > Roy Smith wrote: > > > while True: > > > state = state(data) > > > > This is the pattern I've always used. Simple and effective for any > > state machine which is small enough to code by hand. I generally have > > my state methods return (next_state, output) tuples, but that's a detail. > > What is "output" for? Is it a string or something else? I've often used this pattern for parsing a text file and extracting interesting data. At various points during the input stream, you will have read an entire piece of data, and return it as the output of the state machine. Not every state will result in output being produced. As a trivial example, let's say I had a file format which stored network addresses in a deliberately silly style: -------------------- # This is a comment host = 10.2.3.4 port = 999 proto = TCP port = 1001 proto = TCP host = 192.168.1.1 status = ignore host = 1.2.3.4 port = 22 host = 127.0.0.1 proto = UDP port = 1001 host = 192.168.1.1 -------------------- I want to parse out (host, port, proto) triples, i.e. the state machine should produce the following output: (10.2.3.4, 9099, TCP) (192.168.1.1, 1001, TCP) (192.168.1.1, 1001, UDP) As the end of each data block is recognized, a 3-tuple would be returned. Other state transitions would return None as the output. Then, the main loop can be something like: state = start for line in input: next_state, output = state(line) if output: print output state = next_state I'm not saying it has to be done that way, just that I've found it a handy pattern for the stuff I've done. From no.email at nospam.invalid Sat Sep 4 16:02:37 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Sep 2010 13:02:37 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> Message-ID: <7xeid9gtuq.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > That reinforces my point, about how easy it was to check the correctness of > the code. In this case one simple fix, like this ... > would render the code watertight. See how easy it is? Well, no, it's irrelevant how easy it is to fix the issue after it's pointed out. What matters is how easy it was to create it in the first place. You posted a 30-line code sample as obviously free of memory leaks, but even a good programmer like you didn't notice that it had the potential for a nasty memory overwrite error after an unbalanced decref. Keep in mind that a memory leak usually just means the program can eventually bog down and stops working, but an overwrite error is often a security hole that can lead to total compromise of your entire computer. Now extrapolate that error rate from 30 lines to a program the size of Firefox (something like 5 MLOC), and you should see how fraught with danger that style of programming is. Even the most skilled and careful programmers are going to slip up once in a while. Part of the problem is C itself. No language can eliminate many complicated bugs without creating severe usability problems, but good languages (unlike C) can eliminate most "silly" bugs. I had a "dark night of the soul" after reading some of the bug-finding papers at http://www.stanford.edu/~engler/ and have been terrified of C ever since. I'm just always skeptical when anyone says they're sure any piece of C code is obviously bug-free. It's quite easy to get overconfident about it (as I've done myself more than once). I spent about 5 minutes reviewing your patched code (and the underlying implementations of the C API functions it calls) and didn't see any other issues, and the code is probably ok now, but I'd have to spend a lot more time tracing through the API layer before I could be really sure. Anyway, you should check your patch into github if you haven't. From nagle at animats.com Sat Sep 4 16:48:27 2010 From: nagle at animats.com (John Nagle) Date: Sat, 04 Sep 2010 13:48:27 -0700 Subject: Queue cleanup In-Reply-To: References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> Message-ID: <4c82b097$0$1661$742ec2ed@news.sonic.net> On 8/28/2010 5:42 AM, Aahz wrote: > In article<4c78572c$0$28655$c3e8da3 at news.astraweb.com>, > Steven D'Aprano wrote: >> On Fri, 27 Aug 2010 09:16:52 -0700, Aahz wrote: >>> In article, MRAB >>> wrote: >>>> >>>> An object will be available for garbage collection when nothing refers >>>> to it either directly or indirectly. If it's unreferenced then it will >>>> go away. >>> >>> This isn't actually garbage collection as most people think of it. >>> Refcounting semantics mean that objects get reaped as soon as nothing >>> points at them. OTOH, CPython does also have garbage collection to back >>> up refcounting so that when you have unreferenced object cycles they >>> don't stay around. >> >> I've repeatedly asked, both here and elsewhere, why reference counting >> isn't "real" garbage collection. Nobody has been able to give me a >> satisfactory answer. As far as I can tell, it's a bit of pretentiousness >> with no basis in objective fact. > > You'll notice that I was very careful to qualify my statement with "as > most people think of it". Also, because CPython has two different memory > management mechanisms, refcounting and cycle detection, and the module > that controls cycle detection is called "gc", I think it's simpler to > follow along with the Python docs -- and critically important to remind > people that there are in fact two different systems. Personally, I'd like to have reference counting only, an enforced prohibition on loops (backpointers must be weak pointers), RAII, and reliably ordered finalization. A big advantage of reference counting is that finalization happens in the thread that releases the object, and in the correct order. GC and finalization/destructors do not play well together at all. Microsoft once tried to get the hard cases to work right. See "managed C++". Not a happy story. John Nagle From noagbodjivictor at gmail.com Sat Sep 4 17:22:39 2010 From: noagbodjivictor at gmail.com (nvictor) Date: Sat, 4 Sep 2010 14:22:39 -0700 (PDT) Subject: the script is failing without a useful report Message-ID: <9f67347a-9419-49e5-93de-be3c214f4896@d8g2000yqf.googlegroups.com> hi all, need your help. i get a traceback that doesn't tell much about the actual error in my code: Traceback (most recent call last): File ".\eightqueens.py", line 32, in generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) File ".\eightqueens.py", line 17, in generate else: generate(n, x, col, up, down) here is the full source: def generate(n, x, col, up, down): for h in range(8): # place a queen if col[h] and up[n-h] and down[n+h]: x[n] = h col[h] = False up[n-h] = False down[n+h] = False n += 1 # 8 queen placed? if n == 8: print x else: generate(n, x, col, up, down) # displace a queen n -= 1 col[h] = True up[n-h] = True down[n+h] = True if __name__ == '__main__': n = 0 x = [None]*8 col = [True]*8 up = [True]*15 down = [True]*15 generate(n, x, col, up, down) thanks a lot in advance From python at mrabarnett.plus.com Sat Sep 4 18:22:01 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Sep 2010 23:22:01 +0100 Subject: the script is failing without a useful report In-Reply-To: <9f67347a-9419-49e5-93de-be3c214f4896@d8g2000yqf.googlegroups.com> References: <9f67347a-9419-49e5-93de-be3c214f4896@d8g2000yqf.googlegroups.com> Message-ID: <4C82C689.7080508@mrabarnett.plus.com> On 04/09/2010 22:22, nvictor wrote: > hi all, > > need your help. i get a traceback that doesn't tell much about the > actual error in my code: > > Traceback (most recent call last): > File ".\eightqueens.py", line 32, in > generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > File ".\eightqueens.py", line 17, in generate > else: generate(n, x, col, up, down) > > here is the full source: > > def generate(n, x, col, up, down): > for h in range(8): > # place a queen > if col[h] and up[n-h] and down[n+h]: > x[n] = h > col[h] = False > up[n-h] = False > down[n+h] = False > n += 1 > > # 8 queen placed? > if n == 8: print x > else: generate(n, x, col, up, down) > > # displace a queen > n -= 1 > col[h] = True > up[n-h] = True > down[n+h] = True > > > if __name__ == '__main__': > n = 0 > x = [None]*8 > col = [True]*8 > up = [True]*15 > down = [True]*15 > generate(n, x, col, up, down) > The traceback ends with: RuntimeError: maximum recursion depth exceeded I think what's happening is that if the 'if' condition just after the "# place a queen" comment is false then 'n' won't be incremented, and therefore 'generate' will call itself with the exactly same values which were passed in, resulting in infinite recursion (or at least until the limit is reached). From noagbodjivictor at gmail.com Sat Sep 4 18:28:13 2010 From: noagbodjivictor at gmail.com (nvictor) Date: Sat, 4 Sep 2010 15:28:13 -0700 (PDT) Subject: the script is failing without a useful report References: <9f67347a-9419-49e5-93de-be3c214f4896@d8g2000yqf.googlegroups.com> Message-ID: <79d6c5f9-86f8-4849-84b9-f2eaef8484b8@k10g2000yqa.googlegroups.com> thank you so much. From gabriele.lanaro at gmail.com Sat Sep 4 18:54:14 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Sun, 5 Sep 2010 00:54:14 +0200 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: Maybe for the simple sum you can just use the sum builtin: python -m timeit -s 'sum((10,)*10000)' 10000000 loops, best of 3: 0.0985 usec per loop About the loop in general it's a good practice to use list comprehension and generator expressions 2010/9/2 Michael Kreim > Hi, > > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 1000000000 > a = 0 > for i in xrange(imax): > a = a + 10 > print a > > $ cat addition.m > imax = 1e9; > a = 0; > for i=0:imax-1 > a = a + 10; > end > disp(a); > exit; > > The results look like this: > $ /usr/bin/time --verbose python addition.py > 10000000000 > Command being timed: "python addition.py" > User time (seconds): 107.30 > System time (seconds): 0.08 > Percent of CPU this job got: 97% > Elapsed (wall clock) time (h:mm:ss or m:ss): 1:50.09 > [...] > > $ /usr/bin/time --verbose matlab -nodesktop -nosplash -r "addition" > [...] > 1.0000e+10 > Command being timed: "matlab -nodesktop -nosplash -r addition" > User time (seconds): 7.65 > System time (seconds): 0.18 > Percent of CPU this job got: 94% > Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.25 > [...] > > Unfortunately my Python Code was much slower and I do not understand why. > > Are there any ways to speed up the for/xrange loop? > Or do I have to live with the fact that Matlab beats Python in this > example? > > Thanks a lot for your answers. > > With best regards, > > Michael > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jrmy.lnrd at gmail.com Sat Sep 4 19:04:35 2010 From: jrmy.lnrd at gmail.com (genxtech) Date: Sat, 4 Sep 2010 16:04:35 -0700 (PDT) Subject: Question about Reading Files Message-ID: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Hello. I am still really new to python and I have a project where I am trying to use the data files from another program and write a new program with new user interface and all. My first step was to open one of the files in 'rb' mode and print the contents, but I am unfamiliar with the format. Here is what was printed to the terminal: b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$ \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc \x00\x00\x0c\x19\x00\x00' I am using Python 3.1 on a Fedora 13 box if that makes any difference. Any advise on how to decode the data would be greatly appreciated. From jrmy.lnrd at gmail.com Sat Sep 4 19:13:44 2010 From: jrmy.lnrd at gmail.com (genxtech) Date: Sat, 4 Sep 2010 16:13:44 -0700 (PDT) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: I forgot to mention that the output was the first 100 bytes of the output From mats.rauhala at gmail.com Sat Sep 4 19:23:02 2010 From: mats.rauhala at gmail.com (Mats Rauhala) Date: Sat, 4 Sep 2010 23:23:02 +0000 (UTC) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: On 2010-09-04, genxtech wrote: > Hello. I am still really new to python and I have a project where I > am trying to use the data files from another program and write a new > program with new user interface and all. My first step was to open > one of the files in 'rb' mode and print the contents, but I am > unfamiliar with the format. Here is what was printed to the terminal: > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > Any advise on how to decode the data would be greatly appreciated. It's difficult to elaborate with only that information. What you have done now is opened a file in read binary mode (r = read, b = binary) and then tried to print it. Python has escaped the data as hex (\x01) and is basically a hex dump of the data file. For decoding the data, you either need to somehow figure out the format of the data and then decode it accordingly. If you're on unix box the 'file' command might be of help. If you're not on a unix box, you could check out how the file command tries to find the type of the file. The man page for magic [1] could be of help. Also see list of magic numbers [2] [1] http://linux.die.net/man/5/magic [2] http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html From python at mrabarnett.plus.com Sat Sep 4 20:03:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Sep 2010 01:03:05 +0100 Subject: Question about Reading Files In-Reply-To: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: <4C82DE39.2020208@mrabarnett.plus.com> On 05/09/2010 00:04, genxtech wrote: > Hello. I am still really new to python and I have a project where I > am trying to use the data files from another program and write a new > program with new user interface and all. My first step was to open > one of the files in 'rb' mode and print the contents, but I am > unfamiliar with the format. Here is what was printed to the terminal: > > b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f > \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y > \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$ > \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n > \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc > \x00\x00\x0c\x19\x00\x00' > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > Any advise on how to decode the data would be greatly appreciated. I googled and found this: http://stackoverflow.com/questions/2754751/what-file-format-contents-starts-with-ures which suggests "Universal Resource Editor (URE) that comes with the OS/2 Toolkit". From jrmy.lnrd at gmail.com Sat Sep 4 20:07:01 2010 From: jrmy.lnrd at gmail.com (genxtech) Date: Sat, 4 Sep 2010 17:07:01 -0700 (PDT) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: On Sep 4, 7:23?pm, Mats Rauhala wrote: > On 2010-09-04, genxtech wrote: > > > Hello. ?I am still really new to python and I have a project where I > > am trying to use the data files from another program and write a new > > program with new user interface and all. ?My first step was to open > > one of the files in 'rb' mode and print the contents, but I am > > unfamiliar with the format. ?Here is what was printed to the terminal: > > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > > Any advise on how to decode the data would be greatly appreciated. > > It's difficult to elaborate with only that information. What you have > done now is opened a file in read binary mode (r = read, b = binary) and > then tried to print it. Python has escaped the data as hex (\x01) and is > basically a hex dump of the data file. > > For decoding the data, you either need to somehow figure out the format > of the data and then decode it accordingly. If you're on unix box the > 'file' command might be of help. > > If you're not on a unix box, you could check out how the file command > tries to find the type of the file. The man page for magic [1] could be > of help. Also see list of magic numbers [2] > > [1]http://linux.die.net/man/5/magic > [2]http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html I am using Fedora 13. When I run the file command the response is that it is a 'data' file. If there are any tips on how to programatically figure out the format, I would greatly appreciate it. From ldo at geek-central.gen.new_zealand Sat Sep 4 21:41:38 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 05 Sep 2010 13:41:38 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> <7xbp8el03t.fsf@ruckus.brouhaha.com> Message-ID: In message , MRAB wrote: > Lawrence D'Oliveiro writes: >> >> Wonder why Sun?s licence explicitly forbade its use in danger-critical >> areas like nuclear power plants and the like, then? > > I thought it was just that if it wasn't explicitly forbidden then > someone might try to use it and then sue if something went wrong, even > though common sense would have said that it was a bad idea in the first > place! :-) But you?ll notice that Free Software comes with no such restrictions. In fact, it is contrary to commonly-accepted Free Software guidelines to impose any sort of restrictions on areas of use. From ldo at geek-central.gen.new_zealand Sat Sep 4 21:44:06 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 05 Sep 2010 13:44:06 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> Message-ID: In message <4c82b097$0$1661$742ec2ed at news.sonic.net>, John Nagle wrote: > Personally, I'd like to have reference counting only, an enforced > prohibition on loops (backpointers must be weak pointers), RAII, > and reliably ordered finalization. Is there a cheap way of checking at runtime for circular structures? > A big advantage of reference counting is that finalization happens > in the thread that releases the object, and in the correct order. > GC and finalization/destructors do not play well together at all. > Microsoft once tried to get the hard cases to work right. See > "managed C++". Not a happy story. Thank you for that. Another arrow for my anti-GC quiver. :) From ldo at geek-central.gen.new_zealand Sat Sep 4 22:33:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 05 Sep 2010 14:33:03 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> <7x7hj2kyd6.fsf@ruckus.brouhaha.com> Message-ID: In message <7x7hj2kyd6.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: > >> In message <7xmxs2uez1.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >> >>> GC's for large systems generally don't free (or even examine) individual >>> garbage objects. They copy the live objects to a new contiguous heap >>> without ever touching the garbage, and then they release the old heap. >> >> And suddenly you?ve doubled the memory requirements. And on top of that, >> since you?re moving the valid objects into different memory, you?re >> forcing cache misses on all of them as well. > > A minimal naive implementation indeed doubles the memory requirements, > but from a Python perspective where every integer takes something like > 24 bytes already, even that doesn't seem so terrible. Doubling 24 is less terrible than doubling 4 or 8?? You?re kidding, right? > More sophisticated implementations use multiple small heaps or other > tricks. More and more complications to patch up the idea. At some point, you have to admit there is something fundamentally flawed about the whole concept. > The new heap is filled sequentially so accesses to it will have good > locality. Unfortunately, that?s not how locality of reference works. It doesn?t matter whether the objects being accessed are close together in memory or far apart (not with modern fully-associative caches, anyway), what does matter is the frequency distribution of references, namely that the vast majority of references are to a tiny minority of objects. Your generational garbage collector completely breaks this assumption, by regularly forcing an access to every single object in the heap. Cache- thrashing, anyone? > It's also the case that programs with very large memory consumption tend > to use most of the memory for large arrays that don't contain pointers > (think of a database server with a huge cache). That means the gc > doesn't really have to think about all that much of the memory. But your generational garbage collector still has to copy those very large objects to the new heap, with all the cache-hostile consequences therefrom. By the way, isn?t this the opposite of the array-of-pointers example you were using earlier to try to cast reference-counting in a bad light? It seems to me a reference count would work very well for such a large, simple object. >> This is the continuing problem with garbage collection: all the attempts >> to make it cheaper just end up moving the costs somewhere else. > > Same thing with manual allocation. That moves the costs off the > computer and onto the programmer. Not good, most of the time. Unfortunately, your argument falls down. It is a truism that hardware costs continue to come down, while programmers remain expensive. As I said before, computing performance has improved by something like five orders of magnitude over the last half-century. This has rendered all kinds of techniques, like high-level languages, dynamic memory allocation, stacks, hardware floating-point, memory protection and so on, which were once considered controversial because of their expense, cheap enough to become commonplace. But not garbage collection. This is because of the asymmetric way in which hardware has become faster: the biggest improvements have been in the parts that were already the fastest to begin with (the CPU), while RAM speeds have improved much less, and backing-store speeds least of all. Hence the need for intermediate layers of cache to bridge the gap. But the effectiveness of that caching depends crucially on certain assumptions about the runtime behaviour of the programs: and garbage collection breaks those assumptions. > Really, I'm no gc expert, but the stuff you're saying about gc is quite > ill-informed. You might want to check out some current literature. You may want to enlighten yourself by meditating on this seeming paradox of modern computing hardware: memory is cheap, but accessing memory is expensive. From no.email at nospam.invalid Sat Sep 4 23:56:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Sep 2010 20:56:18 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <7xmxs2uez1.fsf@ruckus.brouhaha.com> <7x7hj2kyd6.fsf@ruckus.brouhaha.com> Message-ID: <7xk4n0c07x.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: >> A minimal naive implementation indeed doubles the memory requirements, >> but from a Python perspective where every integer takes something like >> 24 bytes already, even that doesn't seem so terrible. > > Doubling 24 is less terrible than doubling 4 or 8?? You?re kidding, right? No, it would be doubling 4 or 8 bytes. The extra overhead like the reference count would not be there to bloat up the integer like in Python. >> More sophisticated implementations use multiple small heaps or other tricks. > More and more complications to patch up the idea. At some point, you have to > admit there is something fundamentally flawed about the whole concept. Oh sheesh, that's silly. Every area of programming where performance matters is full of optimization tricks. Look at any serious database implementation for example. Or any compiler. Look at Python's implementation of dictionaries. Yeah, the optimizations add complexity to improve performance, sometimes even in heuristic ways that can fail. That doesn't mean the concepts are fundamentally flawed. GC is no different. >> The new heap is filled sequentially so accesses to it will have good >> locality. > what does matter is the frequency distribution of references, Sorry, just I meant during the gc operation itself. The gc's access pattern in the new heap is completely sequential as the gc just copies stuff to it linearly from from the old heap, bumping a pointer upwards. The access pattern when the user application is running is of course not predictable. > Your generational garbage collector completely breaks this assumption, by > regularly forcing an access to every single object in the heap. Cache- > thrashing, anyone? In the minor collections, the whole minor heap fits in cache, so there's no thrashing. The major collections can use a different strategy, or you can simply rely on their relative infrequency. Why do you speculate like this? If you run a GHC program with profiling active, it tells you exactly how much time is spent in minor gc and how much time is in major gc, and it's all generally pretty tolerable unless your program has bugs. (Unfortunately Haskell programs are notoriously susceptable to a certain type of bug that causes them to still give the right answers, but use much more memory than they should. The usual sign of that happening is high gc load). >> It's also the case that programs with very large memory consumption tend >> to use most of the memory for large arrays that don't contain pointers > But your generational garbage collector still has to copy those very large > objects to the new heap, with all the cache-hostile consequences therefrom. Not necessarily, depends on how you write the program and how the gc works. > By the way, isn?t this the opposite of the array-of-pointers example you > were using earlier to try to cast reference-counting in a bad light? I wasn't trying to cast reference counting in a bad light, I was pointing out that reference counting can experience pauses just like traditional gc approaches. Most programs including "soft" real time programs can tolerate an occasional pause. If your program is not one of those, and you need guaranteed upper bounds on pauses so you can't use traditional gc, switching from gc to reference counting won't save you. > It seems to me a reference count would work very well for such a > large, simple object. Mark/sweep would do it too. Some gc's use a hybrid approach, with mark/sweep for older or larger objects. > But not garbage collection. This is because of the asymmetric way in > which hardware has become faster:... the effectiveness of that > caching depends crucially on certain assumptions about the runtime > behaviour of the programs: and garbage collection breaks those > assumptions. ... > You may want to enlighten yourself by meditating on this seeming paradox of > modern computing hardware: memory is cheap, but accessing memory is > expensive. I'm interested in receiving enlightment if you've got some pointers into the research literature that back up your views. Right now it sounds like you're going by some intuitions you have that aren't backed up by evidence. Anyone who has performance-tuned a program knows that intuition can give reasonable starting points for experiments and measurements, but once the results start coming in, a lot of the intuitions end up invalidated. By now, there is enough experimental and theoretical literature about gc that opinions like yours, that don't seem to be grounded in any knowledge of that literature, are not very persuasive no matter how superficially attractive the raw intuition might be. Especially in your case, where you seem to have decided ahead of time what conclusion you want to reach and are looking for ways to justify it. From shivramsharan at gmail.com Sun Sep 5 00:29:49 2010 From: shivramsharan at gmail.com (shivram) Date: Sat, 4 Sep 2010 21:29:49 -0700 (PDT) Subject: Network and socket programming in python Message-ID: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> i want to learn network and socket programming but i would like to do this in python.Reason behind this is that python is very simple and the only language i know . anybody can suggest me which book should i pick. the book should have following specification-- 1)not tedious to follow 2)lots of example 3)starts with some networking stuff and then get into codes thanks in advance with regards. From nagle at animats.com Sun Sep 5 01:23:44 2010 From: nagle at animats.com (John Nagle) Date: Sat, 04 Sep 2010 22:23:44 -0700 Subject: Queue cleanup In-Reply-To: References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> Message-ID: <4c83295b$0$1665$742ec2ed@news.sonic.net> On 9/4/2010 6:44 PM, Lawrence D'Oliveiro wrote: > In message<4c82b097$0$1661$742ec2ed at news.sonic.net>, John Nagle wrote: > >> Personally, I'd like to have reference counting only, an enforced >> prohibition on loops (backpointers must be weak pointers), RAII, >> and reliably ordered finalization. > > Is there a cheap way of checking at runtime for circular structures? It's an interesting technical problem to design a system where circular references are detected immediately, at the moment of creation. However, Python already detects loops during garbage collection. If you set gc.set_debug(gc.DEBUG_SAVEALL) all the loops show up in "gc.garbage". >> A big advantage of reference counting is that finalization happens >> in the thread that releases the object, and in the correct order. >> GC and finalization/destructors do not play well together at all. >> Microsoft once tried to get the hard cases to work right. See >> "managed C++". Not a happy story. > > Thank you for that. Another arrow for my anti-GC quiver. :) Unoptimized reference counting, which is what CPython does, isn't all that great either. The four big bottlenecks in Python are boxed numbers, attribute lookups, reference count updates, and the GIL. John Nagle From jason.heeris at gmail.com Sun Sep 5 01:40:49 2010 From: jason.heeris at gmail.com (Jason) Date: Sat, 4 Sep 2010 22:40:49 -0700 (PDT) Subject: Subclassing by monkey-patching Message-ID: I'm attempting to implement a recursive directory monitor based on the GIO file monitor in PyGTK. My approach is basically to take the gio.FileMonitor returned by the method gio.File.monitor_directory(), connect to the "changed" signal, and add or remove monitors on create/ delete events for subdirectories. I'd really like to do this by subclassing gio.FileMonitor. But the problem I'm having is that it's never explicitly initialised in user code (but somewhere in gio.File.monitor_directory() ). So there's no point in just declaring a subclass ? where would I actually create an instance? Is there a way I can write the subclass but then somehow... extend an existing instance all at once rather than monkeypatch methods on one by one? So I could take an existing instance of a FileMonitor and make it an instance of my subclass? This would even allow me to override the gio.File.monitor_directory() method to take the monitor returned by the original method and decide whether to make it recursive based on a parameter passed to monitor_directory(). Cheers, Jason PS. Asked a similar question on the pygtk list a few days ago: http://www.daa.com.au/pipermail/pygtk/2010-September/018965.html From cournape at gmail.com Sun Sep 5 01:45:22 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 5 Sep 2010 14:45:22 +0900 Subject: Speed-up for loops In-Reply-To: <4C7F7640.1010102@perfect-kreim.de> References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: On Thu, Sep 2, 2010 at 7:02 PM, Michael Kreim wrote: > Hi, > > I was comparing the speed of a simple loop program between Matlab and > Python. > > My Codes: > $ cat addition.py > imax = 1000000000 > a = 0 > for i in xrange(imax): > ? ?a = a + 10 > print a > > $ cat addition.m > imax = 1e9; > a = 0; > for i=0:imax-1 > ? ?a = a + 10; > end > disp(a); > exit; > > The results look like this: > $ /usr/bin/time --verbose python addition.py > 10000000000 > ? ? ? ?Command being timed: "python addition.py" > ? ? ? ?User time (seconds): 107.30 > ? ? ? ?System time (seconds): 0.08 > ? ? ? ?Percent of CPU this job got: 97% > ? ? ? ?Elapsed (wall clock) time (h:mm:ss or m:ss): 1:50.09 > ? ? ? ?[...] > > $ /usr/bin/time --verbose matlab -nodesktop -nosplash -r "addition" > [...] > ? ?1.0000e+10 > ? ? ? ?Command being timed: "matlab -nodesktop -nosplash -r addition" > ? ? ? ?User time (seconds): 7.65 > ? ? ? ?System time (seconds): 0.18 > ? ? ? ?Percent of CPU this job got: 94% > ? ? ? ?Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.25 > ? ? ? ?[...] > > Unfortunately my Python Code was much slower and I do not understand why. Getting the above kind of code fast requires the interpreter to be clever enough so that it will use native machine operations on a int type instead of converting back and forth between internal representations. Matlab since version 6 I believe, has a JIT to do just that. There is no mature JIT-like implementation of python which will give you the same speed up for this exact case today. > Or do I have to live with the fact that Matlab beats Python in this example? Yes. Without a JIT, python cannot hope to get the same kind of speeds for this kind of examples. That being said, neither matlab nor matlab are especially good at doing what you do in your example - for this exact operation, doing it in C or other compiled languages will be at least one order of magnitude faster. Generally, you use matlab's vectorized operations, and in that case, numpy gives you similar performances (sometimes faster, sometimes slower, but in the same ballpark in general). cheers, David From no.email at nospam.invalid Sun Sep 5 02:51:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Sep 2010 23:51:03 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> <4c83295b$0$1665$742ec2ed@news.sonic.net> Message-ID: <7xd3ssbs4o.fsf@ruckus.brouhaha.com> John Nagle writes: > Unoptimized reference counting, which is what CPython does, isn't > all that great either. The four big bottlenecks in Python are boxed > numbers, attribute lookups, reference count updates, and the GIL. The performance hit of having to lock the refcounts before update has been the historical reason for keeping the GIL. The LOCK prefix takes something like 100 cycles on an x86. Is optimizing the refcount updates going to anywhere near make up for that? Python's "with" statement as an approach to RAII has seemed ok to me. I can't think of a time when I've really had to use a finalizer for something with dynamic extent. They've always seemed like a code smell to me. From arnodel at googlemail.com Sun Sep 5 03:23:42 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 05 Sep 2010 08:23:42 +0100 Subject: Subclassing by monkey-patching References: Message-ID: Jason writes: [...] > Is there a way I can write the subclass but then somehow... extend an > existing instance all at once rather than monkeypatch methods on one > by one? So I could take an existing instance of a FileMonitor and make > it an instance of my subclass? This would even allow me to override > the gio.File.monitor_directory() method to take the monitor returned > by the original method and decide whether to make it recursive based > on a parameter passed to monitor_directory(). There is a straightforward way: >>> class A(object): ... def __init__(self, x): ... self.x = x ... >>> class B(A): ... def x2(self): ... return self.x**2 ... >>> a = A(42) # Create an instance of A >>> a.__class__ = B # Change its class to B >>> a.x2() 1764 However, I've never really tried it so I don't know what ways it could break. HTH -- Arnaud From __peter__ at web.de Sun Sep 5 03:53:39 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Sep 2010 09:53:39 +0200 Subject: Subclassing by monkey-patching References: Message-ID: Arnaud Delobelle wrote: > Jason writes: > [...] >> Is there a way I can write the subclass but then somehow... extend an >> existing instance all at once rather than monkeypatch methods on one >> by one? So I could take an existing instance of a FileMonitor and make >> it an instance of my subclass? This would even allow me to override >> the gio.File.monitor_directory() method to take the monitor returned >> by the original method and decide whether to make it recursive based >> on a parameter passed to monitor_directory(). > > There is a straightforward way: > >>>> class A(object): > ... def __init__(self, x): > ... self.x = x > ... >>>> class B(A): > ... def x2(self): > ... return self.x**2 > ... >>>> a = A(42) # Create an instance of A >>>> a.__class__ = B # Change its class to B >>>> a.x2() > 1764 > > However, I've never really tried it so I don't know what ways it could > break. I think this is fine for classes written Python but won't work here: >>> m = gio.File(".").monitor_directory() >>> C = type(m) >>> class CC(C): ... def whatever(self): ... print 42 ... >>> m.__class__ = CC Traceback (most recent call last): File "", line 1, in TypeError: __class__ assignment: '__main__.GInotifyDirectoryMonitor' deallocator differs from 'CC' A possible alternative may be a class that wraps a FileMonitor instead of subclassing it. Peter From __peter__ at web.de Sun Sep 5 04:16:30 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Sep 2010 10:16:30 +0200 Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: genxtech wrote: > Hello. I am still really new to python and I have a project where I > am trying to use the data files from another program and write a new > program with new user interface and all. My first step was to open > one of the files in 'rb' mode and print the contents, but I am > unfamiliar with the format. Here is what was printed to the terminal: > > b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f > \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y > \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$ > \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n > \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc > \x00\x00\x0c\x19\x00\x00' > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > Any advise on how to decode the data would be greatly appreciated. What's the name of the file? What's the program that uses the file? If the source code is available, what library does that program use to read the file? Peter From nicholas.cole at gmail.com Sun Sep 5 04:49:00 2010 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 5 Sep 2010 09:49:00 +0100 Subject: Python 2.7 module path problems on OS X Message-ID: Dear List, I have a horrible feeling that this is in some way related to the new user installation directory in 2.7,or some problem with the framework built, but I'm having great trouble with the module search path on 2.7. I usually install modules to install_lib = ~/Library/Python/$py_version_short/site-packages I assumed that this would continue to work on 2.7. Unfortunately, it seems not to. The installation is fine, but sys.path only includes '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages' Whereas on 2.6 on my system the default is the more extensive: '/Users/nicholas/Library/Python/2.6/site-packages/docutils-0.5-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/py2app-0.4.3-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/macholib-1.2.1-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/modulegraph-0.7.3-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/altgraph-0.6.7-py2.6.egg', '/Users/nicholas/Library/Python/2.6/site-packages/bdist_mpkg-0.4.4-py2.6.egg', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Python/2.6/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode', '/Users/nicholas/Library/Python/2.6/site-packages' I'm sorry to ask such a trivial question on the list, but I'm used to python installations "Just working"! Can anyone suggest a good fix? Best wishes, Nicholas From jason.heeris at gmail.com Sun Sep 5 04:54:05 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 5 Sep 2010 01:54:05 -0700 (PDT) Subject: Subclassing by monkey-patching References: Message-ID: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> On Sep 5, 3:53?pm, Peter Otten <__pete... at web.de> wrote: > >>> m = gio.File(".").monitor_directory() > >>> C = type(m) 'C' will not necessarily be 'gio.FileMonitor' ? I think the internals of the GIO methods might further "subclass" it in some way depending on what underlying monitors are available. > A possible alternative may be a class that wraps a FileMonitor instead of > subclassing it. I've been avoiding this because it involves a lot of boilerplate: the signals needs to be replicated and passed through, same for all GObject properties, same for the usual methods. I'd basically have to re-write the entire class in Python, and then tack on my methods. Otherwise I have to write two sets of methods for anything that touches this wrapped object. Still, if it's the only way, sure. ? Jason From nad at acm.org Sun Sep 5 05:20:24 2010 From: nad at acm.org (Ned Deily) Date: Sun, 05 Sep 2010 02:20:24 -0700 Subject: Python 2.7 module path problems on OS X References: Message-ID: In article , Nicholas Cole wrote: > I have a horrible feeling that this is in some way related to the new > user installation directory in 2.7,or some problem with the framework > built, but I'm having great trouble with the module search path on > 2.7. > > I usually install modules to install_lib = > ~/Library/Python/$py_version_short/site-packages There are differences in defaults between different Python versions and instances of the same version as built by different providers. The pattern above is the default location for site-packages for Apple-supplied Pythons in recent versions of OS X, in particular the default /usr/bin/python2.6 in OS X 10.6 and /usr/bin/python2.5 in 10.5. >> I assumed that this would continue to work on 2.7. > > Unfortunately, it seems not to. The installation is fine, but sys.path > only includes > > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib- > scriptpackages', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', > '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages > ' OTOH, the Python instances installed by the python.org OS X installers (or ones built similarly) default to using the site-packages directory in the framework directory as shown in that last path. > Whereas on 2.6 on my system the default is the more extensive: > [...] > > I'm sorry to ask such a trivial question on the list, but I'm used to > python installations "Just working"! Can anyone suggest a good fix? I'm not sure why you think it is broken. The Apple 2.6 and the python.org 2.7 have different site-package directories in different locations. That is to be expected. The Apple-supplied Python comes with some additional packages pre-installed, like setuptools, PyObjC, and wx. But you would need to install new versions of these for 2.7 anyway. f you use "easy_install" (aka setuptools or Distribute), keep in mind that every instance of Python needs to have its own version. So, for 2.7, you should follow the installation instructions for either setuptools or Distribute and install a version for 2.7 using python2.7. Its easy_install command will be in the framework bin directory, /Library/Frameworks/Python.framework/Versions/2.7/bin, which is the default location for scripts to be installed. You should ensure that that directory appears on your shell PATH before /usr/bin (where the Apple-supplied easy_install is); if you used the default settings for the python.org installer, it will have attempted to modify your shell startup files, like .bash_profile, to do that for you. Then you can use that easy_install (also available as easy_install-2.7) to install whatever packages you need for 2.7. Or you can use pip. Or just manually installing using the package's setup.py script. All of them use the Python instance's version of Distutils and it will do the right thing for each instance as long as you don't try to influence things by using non-default settings or setting Python-related environment variables, like PYTHONPATH. -- Ned Deily, nad at acm.org From nicholas.cole at gmail.com Sun Sep 5 05:27:41 2010 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 5 Sep 2010 10:27:41 +0100 Subject: Python 2.7 module path problems on OS X In-Reply-To: References: Message-ID: On Sun, Sep 5, 2010 at 10:20 AM, Ned Deily wrote: > I'm not sure why you think it is broken. ?The Apple 2.6 and the > python.org 2.7 have different site-package directories in different > locations. ?That is to be expected. ?The Apple-supplied Python comes > with some additional packages pre-installed, like setuptools, PyObjC, > and wx. ?But you would need to install new versions of these for 2.7 > anyway. > Sorry. I wasn't clear. Of course I understand that each version of python needs its own additional packages, and I was expecting to re-install them. But I don't want to install system-wide -- I'd like to have my own, user-specific, site-packages. On previous versions of python, I've installed into ~/Library/Python/$py_version_short/site-packages under my home directory. In my recollection, this has worked in the past for python installed from python.org, but perhaps that recollection is wrong. At any rate, it doesn't work with python 2.7. Best wishes, Nicholas From mblume at socha.net Sun Sep 5 05:29:41 2010 From: mblume at socha.net (mblume) Date: 05 Sep 2010 09:29:41 GMT Subject: Network and socket programming in python References: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> Message-ID: <4c836305$0$4016$5402220f@news.sunrise.ch> Am Sat, 04 Sep 2010 21:29:49 -0700 schrieb shivram: > > i want to learn network and socket programming but i would like to do > this in python.Reason behind this is that python is very simple and the > only language i know . > anybody can suggest me which book should i pick. the book should have > following specification-- 1)not tedious to follow > 2)lots of example > 3)starts with some networking stuff and then get into codes > > thanks in advance with regards. > Ever heard of Google? "python network tutorial" / "python socket tutorial" should get you started. HTH. Martin From madhurrajn at gmail.com Sun Sep 5 06:05:54 2010 From: madhurrajn at gmail.com (Madhur) Date: Sun, 5 Sep 2010 03:05:54 -0700 (PDT) Subject: High CPU utilization with Pylab Message-ID: <34646c22-e7d5-47b5-9a8a-eaeb472fde0f@e14g2000yqe.googlegroups.com> I am trying to plot a runtime graph using pylab. But the very purpose of functionality is lost because of high CPU percentage hogged by plotting the graph. Here is the piece of code which I have written. def timerfunc(ulcm, dlcm): count=0 xaxis=[] yaxis=[] ion() while 1: xaxis.append(count) dr=(((dlcm.sum)/dlcm.timer)*8) dlcm.counter=0 yaxis.append(dr) dlcm.sum=0 h=plot(xaxis,yaxis,'b') draw() count=count+1 time.sleep(dlcm.timer/1000.0) if (count>100): xlim(count-100, count) Here is the function which plots the graph. Is there something which does not makes sense .? -Madhur From mats.rauhala at gmail.com Sun Sep 5 06:28:38 2010 From: mats.rauhala at gmail.com (Mats Rauhala) Date: Sun, 5 Sep 2010 10:28:38 +0000 (UTC) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: On 2010-09-05, genxtech wrote: > I am using Fedora 13. When I run the file command the response is > that it is a 'data' file. If there are any tips on how to > programatically figure out the format, I would greatly appreciate it. I tried python-magic from the fedora repositories, but was unable to get it working. However there was another project at github [1] which seems to be working, at least with python 2.6. An easy way to test whether it works is by unpacking it, going to the directory, opening the interactive shell and running 'import magic' and 'magic.from_file("testdata/test.pdf")' See help(magic) for more help [1] http://github.com/ahupp/python-magic From debatem1 at gmail.com Sun Sep 5 06:29:44 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 5 Sep 2010 03:29:44 -0700 Subject: Network and socket programming in python In-Reply-To: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> References: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> Message-ID: On Sat, Sep 4, 2010 at 9:29 PM, shivram wrote: > i want to learn network and socket programming but i would like to do > this in python.Reason behind this is that python is very simple and > the only language i know . > anybody can suggest me which book should i pick. > the book should have following specification-- > 1)not tedious to follow > 2)lots of example > 3)starts with some networking stuff and then get into codes > > thanks in advance with regards. "Foundations of Python Network Programming" by John Goerzen. Geremy Condra From 71david at libero.it Sun Sep 5 06:48:59 2010 From: 71david at libero.it (David) Date: Sun, 5 Sep 2010 12:48:59 +0200 Subject: High CPU utilization with Pylab References: <34646c22-e7d5-47b5-9a8a-eaeb472fde0f@e14g2000yqe.googlegroups.com> Message-ID: Il Sun, 5 Sep 2010 03:05:54 -0700 (PDT), Madhur ha scritto: > Is there something which does not makes sense .? 1. How, a computer, is supposed to handle your infinite loop? 2. Running ghraphs shuold be handled in totally different way: look at the "stripcharting" demo in this zip http://agni.phys.iit.edu/~kmcivor/wxmpl/downloads/wxmpl-1.3.1.zip From __peter__ at web.de Sun Sep 5 06:56:28 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Sep 2010 12:56:28 +0200 Subject: Subclassing by monkey-patching References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> Message-ID: Jason wrote: > On Sep 5, 3:53 pm, Peter Otten <__pete... at web.de> wrote: >> >>> m = gio.File(".").monitor_directory() >> >>> C = type(m) > > 'C' will not necessarily be 'gio.FileMonitor' ? I think the internals > of the GIO methods might further "subclass" it in some way depending > on what underlying monitors are available. That would only be relevant if it had worked, I think ;) >> A possible alternative may be a class that wraps a FileMonitor instead of >> subclassing it. > > I've been avoiding this because it involves a lot of boilerplate: the > signals needs to be replicated and passed through, same for all > GObject properties, same for the usual methods. I'd basically have to > re-write the entire class in Python, and then tack on my methods. > Otherwise I have to write two sets of methods for anything that > touches this wrapped object. > > Still, if it's the only way, sure. Does it have to be gio.FileMonitor? pyinotify can automatically add new subdirectories out of the box. Peter From bartc at freeuk.com Sun Sep 5 07:28:47 2010 From: bartc at freeuk.com (BartC) Date: Sun, 5 Sep 2010 12:28:47 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: "David Cournapeau" wrote in message news:mailman.455.1283665528.29448.python-list at python.org... > On Thu, Sep 2, 2010 at 7:02 PM, Michael Kreim > wrote: >> imax = 1000000000 >> a = 0 >> for i in xrange(imax): >> a = a + 10 >> print a >> Unfortunately my Python Code was much slower [than Matlab] and I do not >> understand why. > > Getting the above kind of code fast requires the interpreter to be > clever enough so that it will use native machine operations on a int > type instead of converting back and forth between internal > representations. Writing for i in xrange(1000000000) you'd think would give it a clue, but it makes no difference. > Matlab since version 6 I believe, has a JIT to do > just that. There is no mature JIT-like implementation of python which > will give you the same speed up for this exact case today. >> Or do I have to live with the fact that Matlab beats Python in this >> example? > > Yes. Without a JIT, python cannot hope to get the same kind of speeds > for this kind of examples. > > That being said, neither matlab nor matlab are especially good at > doing what you do in your example - for this exact operation, doing it > in C or other compiled languages will be at least one order of > magnitude faster. One order of magnitude (say 10-20x slower) wouldn't be so bad. That's what you might expect for a dynamically typed, interpreted language. But on my machine this code was more like 50-200x slower than C, for unaccelerated Python. > Generally, you use matlab's vectorized operations, > and in that case, numpy gives you similar performances (sometimes > faster, sometimes slower, but in the same ballpark in general). That would simply be delegating Python to a scripting language. It would be nice if you could directly code low-level algorithms in it without relying on accelerators, and not have to wait two and a half minutes (or whatever) for a simple test to complete. -- bartc From shivramsharan at gmail.com Sun Sep 5 07:57:36 2010 From: shivramsharan at gmail.com (simpu) Date: Sun, 5 Sep 2010 04:57:36 -0700 (PDT) Subject: Network and socket programming in python References: <29884fe6-39a5-4422-875f-770269a2d65f@l32g2000prn.googlegroups.com> Message-ID: <29f5a052-86e5-42d0-bdc2-5156c1f1e85c@13g2000prf.googlegroups.com> On Sep 5, 3:29?pm, geremy condra wrote: > On Sat, Sep 4, 2010 at 9:29 PM, shivram wrote: > > i want to learn network and socket programming but i would like to do > > this in python.Reason behind this is that python is very simple and > > the only language i know . > > anybody can suggest me which book should i pick. > > the book should have following specification-- > > 1)not tedious to follow > > 2)lots of example > > 3)starts with some networking stuff and then get into codes > > > thanks in advance with regards. > > "Foundations of Python Network Programming" by John Goerzen. > > Geremy Condra thank you so much for your concern From ctops.legal at gmail.com Sun Sep 5 08:44:16 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 05:44:16 -0700 (PDT) Subject: Python [repair_cycorder_mov.py] Message-ID: Trying to learn Python for a specific purpose to repair a quicktime file that's corrupted, is it even possible to create a proof-of- concept python script that generates a valid 'moov' atom from a corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to finalize file). [IMG]http://a.imageshack.us/img337/5503/cycorder.jpg[/IMG] By [URL=http://profile.imageshack.us/user/ctops].[/URL] [IMG]http://a.imageshack.us/img375/9254/finallm.jpg[/IMG] By [URL=http://profile.imageshack.us/user/ctops].[/URL]
From ctops.legal at gmail.com Sun Sep 5 08:51:53 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 05:51:53 -0700 (PDT) Subject: Python script for repairing .mov file Message-ID: <3d8ef7ff-772d-4580-9e18-30046a049b35@s9g2000yqd.googlegroups.com> Trying to learn Python for a specific purpose to repair a quicktime file that's corrupted, is it even possible to create a proof-of- concept python script that generates a valid 'moov' atom from a corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to finalize file). Mac--> http://a.imageshack.us/img337/5503/cycorder.jpg Windows--> http://a.imageshack.us/img375/9254/finallm.jpg Source sample Quicktime mov file 22mb; https://docs.google.com/leaf? id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2VlLTkxMTAtODVmZWM3NWNhNDBi&sort=name&? layout=list&num=50 Source thread; http://modmyi.com/forums/windows-specific-modding-discussion/587461-editing-mov-files-corrupt-cycorder-videos-8.html From ctops.legal at gmail.com Sun Sep 5 08:54:47 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 05:54:47 -0700 (PDT) Subject: Python script for repairing .mov file ? Message-ID: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> Trying to learn Python for a specific purpose to repair a quicktime file that's corrupted, is it even possible to create a proof-of- concept python script that generates a valid 'moov' atom from a corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to finalize file). Mac--> http://a.imageshack.us/img337/5503/cycorder.jpg Windows--> http://a.imageshack.us/img375/9254/finallm.jpg Source sample Quicktime mov file 22mb; https://docs.google.com/leaf?id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2VlLTkxMTAtODVmZWM3NWNhNDBi&sort=name&layout=list&num=50 Source thread; http://modmyi.com/forums/windows-specific-modding-discussion/587461-editing= -mov-files-corrupt-cycorder-videos-8.html From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 10:00:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 14:00:35 GMT Subject: Python [repair_cycorder_mov.py] References: Message-ID: <4c83a283$0$28657$c3e8da3@news.astraweb.com> On Sun, 05 Sep 2010 05:44:16 -0700, ctops.legal wrote: > Trying to learn Python for a specific purpose to repair a quicktime file > that's corrupted, is it even possible to create a proof-of- concept > python script that generates a valid 'moov' atom from a corrupt .mov > video ?, "file size 1.3gb" (Kodak camera failed to finalize file). Yes, Python is a Turing complete programming language. Anything you can do in any programming language, you can do in Python. By the way, there's no need to send three messages in 10 minutes asking the same question, and adding FORM METHOD links to your post will probably just get it flagged as spam by many people. -- Steven From agoretoy at gmail.com Sun Sep 5 10:09:07 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 5 Sep 2010 09:09:07 -0500 Subject: ssh browser? where? Message-ID: why not ssh browser traffic? why use SSL certificate authorities which can't be trusted in the first place? Is SSH not proven to be secure? To this day I have not seen ssh module for say Apache web server, why not? I understand this maybe wrong list to ask this question, but I love you guys so much at python and I think your smart... :) Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollybox.de Sun Sep 5 10:31:49 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 5 Sep 2010 16:31:49 +0200 Subject: ssh browser? where? In-Reply-To: References: Message-ID: <201009051631.50658.thomas@jollybox.de> On Sunday 05 September 2010, it occurred to alex goretoy to exclaim: > why not ssh browser traffic? why use SSL certificate authorities which > can't be trusted in the first place? > Is SSH not proven to be secure? > > To this day I have not seen ssh module for say Apache web server, why not? > > I understand this maybe wrong list to ask this question, but I love you > guys so much at python and I think your smart... :) Umn. Yes, wrong list. Still, SSH is "secure shell". Shell ? WWW. TLS/SSL is secure. Once you have an encrypted connection to the correct party, the information you send over that connection is just as illegible to the outsider as it'd be over an SSH connection. If you're connected to someone other than you think you are connected to, then all the encryption in the world won't help you. (man-in-the-middle attack) With SSH, this isn't that big a problem: you only connect to a machine over SSH if you have an account there. Since this tends to be a relatively small number of machines, it's relatively easy to manually check the server's key fingerprint. The authenticity of the server's key must be checked to prevent an attack, and the status quo with SSH is that the user does it, which is arguably the most secure model anyway. On the web, you might connect to any number of servers. Manually checking every single key would be a gargantuan and certainly not very rewarding task. THAT's where certificate authorities come in. They're a reasonable way to automatically check the validity of a server's key, so you don't have to. Now, in theory, you should verify the integrity of the certificate authorities yourself before trusting their judgement, but in practice, you leave that daunting task to your operating system and/or web browser vendor. There are a number of weak spots, but there are also rather strict audits going on all over the place. If we were to use SSH on the web, which is certainly not the point of SSH, we'd still need some kind of certificate authority to make the whole system workable. From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 11:00:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 15:00:32 GMT Subject: Speed-up for loops References: Message-ID: <4c83b08f$0$28657$c3e8da3@news.astraweb.com> On Fri, 03 Sep 2010 21:17:44 +0100, BartC wrote: > I'm not sure the Python developers were interested in getting fast > loops. > > For-loops which iterate between two numbers are amongst the easiest > things to make fast in a language. Yet originally you had to use: > > for i in range(N): I don't have any versions of Python prior to version 1.5, but as far back as that there was always a choice between creating a list with range() and a lazy iterator with xrange(). > which (if I understood correctly) actually created a list of N objects, > populated it with the values 0, 1, 2...N-1 (presumably using a more > sensible loop), then iterated between the values of the list! By "more sensible", do you mean "in C code"? If so, then you are correct. > So Python had the distinction of being one of the slowest languages in > which to do nothing (ie. running an empty loop). Nonsense. [steve at sylar ~]$ time python test.py real 0m3.441s user 0m2.969s sys 0m0.024s [steve at sylar ~]$ time perl test.pl real 0m3.490s user 0m2.722s sys 0m0.011s [steve at sylar ~]$ time ruby test.rb real 0m11.875s user 0m6.740s sys 0m3.995s The difference between an empty loop in Python and Perl is insignificant, and much faster than Ruby (at least the specific version of Ruby installed on my machine, 1.8.6). And if you want to see the code I ran: [steve at sylar ~]$ cat test.* # perl for ($i = 0; $i < 10_000_000; ++$i) { 1; } # python for i in xrange(10000000): 1 # ruby for i in 0...10000000 1 end Just for comparisons' sake: [steve at sylar ~]$ gpc empty_test.p [steve at sylar ~]$ time ./a.out real 0m0.106s user 0m0.070s sys 0m0.004s [steve at sylar ~]$ cat empty_test.p program main(input, output); var i: integer; begin for i := 0 to 10000000 do begin end; end. Of course, a real optimizing compiler would realise that the Pascal code did nothing at all, and compile it all away to an empty a.out file... -- Steven From agoretoy at gmail.com Sun Sep 5 11:02:39 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 5 Sep 2010 10:02:39 -0500 Subject: ssh browser? where? In-Reply-To: <201009051631.50658.thomas@jollybox.de> References: <201009051631.50658.thomas@jollybox.de> Message-ID: >>> If we were to use SSH on the web, which is certainly not the point of SSH, >>> we'd still need some kind of certificate authority to make the whole system >>> workable. Yeah, you are correct. I thought about that after having posted these questions. Even though it was SSH there still would be wiggle room for a mitm. I had a dream last night that my future employer was asking me what SSH was. lol I appreciate your response and making it clear as day. Still though, I think there maybe something for testing here. I personally verify and scope out my cert manually. Well for the sites I visit often. But I understand not everyone will be likely to do this. Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From almar.klein at gmail.com Sun Sep 5 11:07:46 2010 From: almar.klein at gmail.com (Almar Klein) Date: Sun, 5 Sep 2010 17:07:46 +0200 Subject: Python script for repairing .mov file ? In-Reply-To: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> References: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> Message-ID: On 5 September 2010 14:54, ctops.legal wrote: > Trying to learn Python for a specific purpose to repair a quicktime > file that's corrupted, is it even possible to create a proof-of- > concept python script that generates a valid 'moov' atom from a > corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to > finalize file). > Why would you use Python for this? Would ffmpeg or mencoder not be more suitable? Anyway, there's pymedia, but I have no experience with it. I'm not sure what I should see in the links. The "Soure thread" one is broken by the way (404 error). Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 11:15:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 15:15:49 GMT Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <4c83b425$0$28657$c3e8da3@news.astraweb.com> On Sun, 05 Sep 2010 12:28:47 +0100, BartC wrote: >> Getting the above kind of code fast requires the interpreter to be >> clever enough so that it will use native machine operations on a int >> type instead of converting back and forth between internal >> representations. > > Writing for i in xrange(1000000000) you'd think would give it a clue, > but it makes no difference. CPython takes a very conservative view towards runtime optimizations. Optimizations don't happen for free, you know, they have costs. Memory is one cost, but human time and effort is another. But if you want a JIT compiler, see Psycho, or try PyPy, which is very exciting and I hope will one day be ready to take over from CPython as the first choice for production use. [...] > One order of magnitude (say 10-20x slower) wouldn't be so bad. That's > what you might expect for a dynamically typed, interpreted language. > > But on my machine this code was more like 50-200x slower than C, for > unaccelerated Python. I'd say that 50-200 times slower than C is exactly what I'd expect from a dynamically typed language like Python without any fancy JIT tricks. Getting such a language to within an order of magnitude of C is quite an achievement. >> Generally, you use matlab's vectorized operations, and in that case, >> numpy gives you similar performances (sometimes faster, sometimes >> slower, but in the same ballpark in general). > > That would simply be delegating Python to a scripting language. That's sheer unadulterated nonsense. In any case, Python was designed as a glue language, specifically to be a high-level user-friendly language for gluing components written in C together. That's what Python *is* -- it provides a bunch of primitives, written in C (or Java, or dot-Net, pick whichever implementation you like) and manipulated in a friendly, safe language. Calling numpy for fast vectorized operations is *exactly* the right solution, if you need high-performance maths calculations. Use the right tool for the job, don't insist that your spanner should double as a screwdriver. > It would > be nice if you could directly code low-level algorithms in it without > relying on accelerators, and not have to wait two and a half minutes (or > whatever) for a simple test to complete. Yes, and it would be nice if my clothes washed and ironed themselves, but they don't. Somebody has to do the work. Are you volunteering to write the JIT compiler for CPython? Will you contribute to the PyPy project, or help maintain Psycho, or are you just bitching? The simple fact is that there are far more important things for Python developers to spend their time and effort on than optimizations like this. If such an optimization comes out of the PyPy project, I'll be cheering them on -- but it's a lot of effort for such a trivial gain. The example given by the Original Poster is contrived. Nobody sensibly writes an integer multiplication as a repeated addition like that, and any real code that would need to be put in a for loop is almost certainly going to be too complicated for the JIT compiler to benefit greatly. The loop overhead itself will almost certainly be overwhelmed by the work done in the loop: [steve at sylar ~]$ time python -c "a = 0 > for i in xrange(10000000): > a += 10 > " real 0m6.906s user 0m5.820s sys 0m0.022s which is about double the time for an empty loop of the same size. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 11:30:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 15:30:29 GMT Subject: doctest annoyance/puzzle Message-ID: <4c83b795$0$28657$c3e8da3@news.astraweb.com> I'm writing a "literate programming" document, example.txt, which mixes text and code in ReST format: This is my excellent module for making spam. It has one public function, ``make_spam``, which takes a single argument for how much spam to make: >>> from module import make_spam >>> make_spam(3) 'spam spam spam' If you ask for too little spam, you get a bonus: >>> make_spam(-3) 'spam spam spam GLORIOUS SPAM!!!' I run the doctests with: python2.6 -m doctest examples.txt and the first example passes, but the second fails with NameError: make_spam not defined. I have a work-around, I do an import at the start of *every* doctest block, but that's ugly. More complex (realistic) examples sometimes need setup code, which I'd like to survive from one block to the next: >>> it = iter(make_spam(5).split()) >>> next(it) 'spam' text goes here >>> next(it) 'spam' but of course that also fails. This surprises me, because doctests in functions or classes can mix descriptive text between tests without this problem. Am I doing something wrong, or is doctest fundamentally broken when executing tests in a text file? -- Steven From vicente.soler at gmail.com Sun Sep 5 12:00:23 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 5 Sep 2010 09:00:23 -0700 (PDT) Subject: personal firewall software is blocking the connection Message-ID: I'am getting this annoying message all the time when using IDLE. ... personal firewall software is blocking the connection When I am editing a source *.py file and I click on F5 (run) I get the above message. What can I do? I am using Norton Internet Security. I try to find if 127.0.0.1 is blocked, but I do not know where to look. Can anybody help? From vicente.soler at gmail.com Sun Sep 5 12:10:52 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 5 Sep 2010 09:10:52 -0700 (PDT) Subject: IDLE: personal firewall software is blocking the connection References: Message-ID: <90be5563-b7d5-41b0-8ceb-955c1b1b49fc@x42g2000yqx.googlegroups.com> On 5 sep, 18:00, vsoler wrote: > I'am getting this annoying message all the time when using IDLE. > > ... ?personal firewall software is blocking the connection > > When I am editing a source *.py file and I click on F5 (run) I get the > above message. > > What can I do? > > I am using Norton Internet Security. I try to find if 127.0.0.1 is > blocked, but I do not know where to look. > > Can anybody help? From marduk at letterboxes.org Sun Sep 5 12:23:24 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Sun, 05 Sep 2010 12:23:24 -0400 Subject: Python [repair_cycorder_mov.py] In-Reply-To: <4c83a283$0$28657$c3e8da3@news.astraweb.com> References: <4c83a283$0$28657$c3e8da3@news.astraweb.com> Message-ID: <1283703804.559960.0.camel@paska> On Sun, 2010-09-05 at 14:00 +0000, Steven D'Aprano wrote: > By the way, there's no need to send three messages in 10 minutes > asking > the same question, and adding FORM METHOD links to your post will > probably just get it flagged as spam by many people. Apparently it has, as I only got this response. From stefan_ml at behnel.de Sun Sep 5 12:27:46 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 05 Sep 2010 18:27:46 +0200 Subject: Speed-up for loops In-Reply-To: <4c83b08f$0$28657$c3e8da3@news.astraweb.com> References: <4c83b08f$0$28657$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano, 05.09.2010 17:00: > Of course, a real optimizing compiler would realise that the Pascal code > did nothing at all, and compile it all away to an empty a.out file... Which is just one of the reasons why this kind if "benchmark" provides no insight into anything that should have an impact on a programmer's daily job. Stefan From sschwarzer at sschwarzer.net Sun Sep 5 12:41:15 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 05 Sep 2010 18:41:15 +0200 Subject: doctest annoyance/puzzle In-Reply-To: <4c83b795$0$28657$c3e8da3@news.astraweb.com> References: <4c83b795$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C83C82B.5030108@sschwarzer.net> Hi Steven, On 2010-09-05 17:30, Steven D'Aprano wrote: > I run the doctests with: > > python2.6 -m doctest examples.txt > > and the first example passes, but the second fails with NameError: > make_spam not defined. I run my doctests by calling doctest.testfile(filename) for each file in a loop. This way, names and their associated objects survice from one code block to the next. I just read that the way you use doctest should behave the same, according to the documentation. In case of a text file I just tested, it does; all tests pass despite the text snippets between the code blocks. What do you get if you test your text file by explicitly calling doctest.testfile? Stefan From roy at panix.com Sun Sep 5 13:09:03 2010 From: roy at panix.com (Roy Smith) Date: Sun, 05 Sep 2010 13:09:03 -0400 Subject: Extracting item from list of tuples? Message-ID: I'm using httplib, and want to get the Location header from the response. The getheaders() method gives you back a list of (name, value) tuples. It would be a lot more convenient if it gave you back a dict, but it is what it is. Anyway, I came up with: location = [t[1] for t in headers if t[0] == 'location'][0] which works, but is getting on towards the cryptic end of things. Is there a better idiom for this? From bartc at freeuk.com Sun Sep 5 13:09:47 2010 From: bartc at freeuk.com (BartC) Date: Sun, 5 Sep 2010 18:09:47 +0100 Subject: Speed-up for loops In-Reply-To: <4c83b425$0$28657$c3e8da3@news.astraweb.com> References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c83b425$0$28657$c3e8da3 at news.astraweb.com... > On Sun, 05 Sep 2010 12:28:47 +0100, BartC wrote: >> It would >> be nice if you could directly code low-level algorithms in it without >> relying on accelerators, and not have to wait two and a half minutes (or >> whatever) for a simple test to complete. > > Yes, and it would be nice if my clothes washed and ironed themselves, but > they don't. > > Somebody has to do the work. Are you volunteering to write the JIT > compiler for CPython? Will you contribute to the PyPy project, or help > maintain Psycho, or are you just bitching? I've thought about it (writing an independent interpreter). But I don't know enough of the language, and a lot of it I don't understand (eg. OOP). Besides, I think the language itself deliberately makes it difficult to get it up to speed. Some of the reasons might be the ones set down here, in Chapter 2: http://codespeak.net/svn/user/antocuni/phd/thesis/thesis.pdf (Instead, I've confined my efforts to my own projects; the last interpreter I worked on did in fact get within a magnitude of C in performance, without using JIT or other fancy tricks.) > The simple fact is that there are far more important things for Python > developers to spend their time and effort on than optimizations like this. I don't know, there's seem to be an awful lot of effort going into addressing exactly this issue (eg. PyPy, Pscyo, Unladen Swallow, Shedskin....) > If such an optimization comes out of the PyPy project, I'll be cheering > them on -- but it's a lot of effort for such a trivial gain. > > The example given by the Original Poster is contrived. Nobody sensibly > writes an integer multiplication as a repeated addition like that, and > any real code that would need to be put in a for loop is almost certainly > going to be too complicated for the JIT compiler to benefit greatly. The > loop overhead itself will almost certainly be overwhelmed by the work > done in the loop: OK, you're saying there's no point in reducing the loop overhead, because the loop body is going to be even slower. All those compilers that offer loop unrolling are therefore wasting their time... -- Bartc From thomas at jollybox.de Sun Sep 5 13:14:44 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 5 Sep 2010 19:14:44 +0200 Subject: Extracting item from list of tuples? In-Reply-To: References: Message-ID: <201009051914.44213.thomas@jollybox.de> On Sunday 05 September 2010, it occurred to Roy Smith to exclaim: > I'm using httplib, and want to get the Location header from the > response. The getheaders() method gives you back a list of (name, > value) tuples. It would be a lot more convenient if it gave you back a > dict, but it is what it is. It may not be a dict, but you can always make it one: >>> L = [('a',1), ('b', 42), ('c', 0)] >>> dict(L) {'a': 1, 'c': 0, 'b': 42} >>> From philip at semanchuk.com Sun Sep 5 13:26:20 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 5 Sep 2010 13:26:20 -0400 Subject: Extracting item from list of tuples? In-Reply-To: References: Message-ID: <4453332A-820F-4890-95D7-443C3B2B8AD2@semanchuk.com> On Sep 5, 2010, at 1:09 PM, Roy Smith wrote: > I'm using httplib, and want to get the Location header from the > response. The getheaders() method gives you back a list of (name, > value) tuples. It would be a lot more convenient if it gave you > back a > dict, but it is what it is. > > Anyway, I came up with: > > location = [t[1] for t in headers if t[0] == 'location'][0] > > which works, but is getting on towards the cryptic end of things. Is > there a better idiom for this? Are you concerned about efficiency? If it's not important, being less terse would make it less cryptic: location = None for name, value in headers: if name == "location": location = value break If you prefer terse, IMHO this is less cryptic (but untested): location = [value for name, value in headers if name == 'location'] [0] Be careful if you decide to turn the list of tuples into a dictionary. HTTP headers can repeat and straightforward code to turn the (name, value) pairs into a dict could end up overwriting data. Cheers P From __peter__ at web.de Sun Sep 5 13:45:53 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Sep 2010 19:45:53 +0200 Subject: Extracting item from list of tuples? References: Message-ID: Philip Semanchuk wrote: > > On Sep 5, 2010, at 1:09 PM, Roy Smith wrote: > >> I'm using httplib, and want to get the Location header from the >> response. The getheaders() method gives you back a list of (name, >> value) tuples. It would be a lot more convenient if it gave you >> back a >> dict, but it is what it is. >> >> Anyway, I came up with: >> >> location = [t[1] for t in headers if t[0] == 'location'][0] >> >> which works, but is getting on towards the cryptic end of things. Is >> there a better idiom for this? > > Are you concerned about efficiency? If it's not important, being less > terse would make it less cryptic: > location = None > for name, value in headers: > if name == "location": > location = value > break This is actually more efficient because unlike Roy's (and your other solution) it doesn't build a list, and it doesn't waste cycles in the loop once the location is found. You can write it as a generator expression like so: location = next((value for name, value in headers if name == "location"), None) But just converting the headers to a dict is clearer and probably even faster because it moves the loop from Python to C. > If you prefer terse, IMHO this is less cryptic (but untested): > > location = [value for name, value in headers if name == 'location'] > [0] > > > Be careful if you decide to turn the list of tuples into a dictionary. > HTTP headers can repeat and straightforward code to turn the (name, > value) pairs into a dict could end up overwriting data. From nagle at animats.com Sun Sep 5 14:22:37 2010 From: nagle at animats.com (John Nagle) Date: Sun, 05 Sep 2010 11:22:37 -0700 Subject: Queue cleanup In-Reply-To: <7xd3ssbs4o.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> <4c83295b$0$1665$742ec2ed@news.sonic.net> <7xd3ssbs4o.fsf@ruckus.brouhaha.com> Message-ID: <4c83dfed$0$1662$742ec2ed@news.sonic.net> On 9/4/2010 11:51 PM, Paul Rubin wrote: > John Nagle writes: >> Unoptimized reference counting, which is what CPython does, isn't >> all that great either. The four big bottlenecks in Python are boxed >> numbers, attribute lookups, reference count updates, and the GIL. > > The performance hit of having to lock the refcounts before update has > been the historical reason for keeping the GIL. The LOCK prefix takes > something like 100 cycles on an x86. Is optimizing the refcount updates > going to anywhere near make up for that? I've argued for an approach in which only synchronized or immutable objects can be shared between threads. Then, only synchronized objects have refcounts. See "http://www.animats.com/papers/languages/pythonconcurrency.html" Guido doesn't like it. He doesn't like any "restrictions". So we're stuck dragging around the boat anchor. I'd hoped that the Unladen Swallow people might come up with some really clever solution, but they seem to be stuck. It's been almost a year since the last quarterly release. Maybe Google is putting their effort into Go. What's so striking is that Shed Skin can deliver 20x to 60x speedups over CPython, while PyPy and Unladen Swallow have trouble getting 1.5x. The question is how much one has to restrict the language to get a serious performance improvement. > Python's "with" statement as an approach to RAII has seemed ok to me. I > can't think of a time when I've really had to use a finalizer for > something with dynamic extent. They've always seemed like a code smell > to me. The problem appears when you have an object that owns something, like a window or a database connection. "With" is single-level. John Nagle From ctops.legal at gmail.com Sun Sep 5 14:28:03 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 11:28:03 -0700 (PDT) Subject: Python script for repairing .mov file ? References: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> Message-ID: <29fef8e4-3b90-47ca-9312-6d804556fdab@t2g2000yqe.googlegroups.com> On Sep 5, 8:54?am, "ctops.legal" wrote: > Trying to learn Python for a specific purpose to repair a quicktime > file that's corrupted, is it even ?possible to create a proof-of- > concept python script that generates a valid 'moov' atom from a > corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to > finalize file). > > Mac-->http://a.imageshack.us/img337/5503/cycorder.jpg > > Windows-->http://a.imageshack.us/img375/9254/finallm.jpg > > Source sample Quicktime mov file 22mb; > > https://docs.google.com/leaf?id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2VlLTkxMTAtODVmZWM3NWNhNDBi&hl=en > > Source thread;http://modmyi.com/forums/windows-specific-modding-discussion/587461-e... > -mov-files-corrupt-cycorder-videos-8.html From philip at semanchuk.com Sun Sep 5 14:30:52 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 5 Sep 2010 14:30:52 -0400 Subject: Extracting item from list of tuples? In-Reply-To: References: Message-ID: On Sep 5, 2010, at 1:45 PM, Peter Otten wrote: > Philip Semanchuk wrote: > >> >> On Sep 5, 2010, at 1:09 PM, Roy Smith wrote: >> >>> I'm using httplib, and want to get the Location header from the >>> response. The getheaders() method gives you back a list of (name, >>> value) tuples. It would be a lot more convenient if it gave you >>> back a >>> dict, but it is what it is. >>> >>> Anyway, I came up with: >>> >>> location = [t[1] for t in headers if t[0] == 'location'][0] >>> >>> which works, but is getting on towards the cryptic end of things. >>> Is >>> there a better idiom for this? >> >> Are you concerned about efficiency? If it's not important, being less >> terse would make it less cryptic: >> location = None >> for name, value in headers: >> if name == "location": >> location = value >> break > > This is actually more efficient because unlike Roy's (and your other > solution) it doesn't build a list, and it doesn't waste cycles in > the loop > once the location is found. Upon further reflection, though, I realize that my solution is not equivalent to the original. In the case of duplicated headers, the original would return the last value of the location header, my code would return the first. For the HTTP Location header this is only a theoretical problem because the HTTP spec doesn't provide for sending more than one. However if this code were made into a function for retrieving the value of an arbitrary header (as seems likely), one would have to decide how to handle repeating headers. Neither my code nor the original handle that possibility. Nor does a naive conversion into a dict, as I mentioned before. Cheers P > You can write it as a generator expression like > so: > > location = next((value for name, value in headers if name == > "location"), > None) > > But just converting the headers to a dict is clearer and probably even > faster because it moves the loop from Python to C. > >> If you prefer terse, IMHO this is less cryptic (but untested): >> >> location = [value for name, value in headers if name == >> 'location'] >> [0] >> >> >> Be careful if you decide to turn the list of tuples into a >> dictionary. >> HTTP headers can repeat and straightforward code to turn the (name, >> value) pairs into a dict could end up overwriting data. > > -- > http://mail.python.org/mailman/listinfo/python-list From ctops.legal at gmail.com Sun Sep 5 14:31:21 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Sun, 5 Sep 2010 11:31:21 -0700 (PDT) Subject: Python script for repairing .mov file ? References: <038924f2-a7a0-4384-9023-a77647c09179@u6g2000yqh.googlegroups.com> Message-ID: <0c453d2b-f055-423b-b032-0083e04ebc48@s9g2000yqd.googlegroups.com> On Sep 5, 8:54?am, "ctops.legal" wrote: > Trying to learn Python for a specific purpose to repair a quicktime > file that's corrupted, is it even ?possible to create a proof-of- > concept python script that generates a valid 'moov' atom from a > corrupt .mov video ?, "file size 1.3gb" (Kodak camera failed to > finalize file). > > Mac-->http://a.imageshack.us/img337/5503/cycorder.jpg > > Windows-->http://a.imageshack.us/img375/9254/finallm.jpg > > Source sample Quicktime mov file 22mb; > > https://docs.google.com/leaf?id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2Vl... > > Source thread;http://modmyi.com/forums/windows-specific-modding-discussion/587461-e... > -mov-files-corrupt-cycorder-videos-8.html GOOD Link for source mov file--> https://docs.google.com/uc?id=0B52sCu28BET8ZjlkNTcwODAtYjFmOC00M2VlLTkxMTAtODVmZWM3NWNhNDBi&export=download&hl=en From stefan_ml at behnel.de Sun Sep 5 14:50:55 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 05 Sep 2010 20:50:55 +0200 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: BartC, 05.09.2010 19:09: > I've thought about it (writing an independent interpreter). But I don't > know enough of the language, and a lot of it I don't understand (eg. > OOP). Besides, I think the language itself deliberately makes it > difficult to get it up to speed. Some of the reasons might be the ones > set down here, in Chapter 2: > > http://codespeak.net/svn/user/antocuni/phd/thesis/thesis.pdf Second sentence of the abstract: """ However, all the existing implementations prevent programmers from developing very efficient code. """ For an incorrect statement, that's a pretty bold one, even in the context given by the abstract. The author is lucky not to be an English native speaker, which explains some of the offensive wording in the intro. Also, I'm impressed by an accepted Ph.D. thesis that comes along with just a bit more than four pages of references, and that fails to reference basically everything that the Python ecosystem provides for fast computation. I wouldn't mind a "faster Python", but as long as Python continues to be a language that allows you to very quickly get to the point where you can benchmark and optimise your code, and as long as CPython then makes it easy to do that, I won't be the one jumping up and down for a small factor of "general" improvement, especially when it comes at the price of switching to a completely different runtime. After all, it's really hard to appreciate that a program can now wait 5% more often on I/O than before. Larger performance improvements are usually due to algorithmic changes (including data structure adaptations and caching), rarely due to changes in the interpreter, especially when it's as old and well optimised as CPython. I think the CPython interpreter does a really good job in providing a stable and predictable runtime environment and executing code in it, and the CPython ecosystem does a really good job in providing tools that make code run fast that needs to, be it due to efficient usage of I/O, CPU, memory, or whatever. I'm not trying to put down the achievements of the author of the cited thesis, not at all. I'm sure the results are interesting for some people and for some kinds of applications, just like the different Python implementations are interesting for some people and some applications. But an awful lot of existing apps won't benefit at all from a fast CLI based Python implementation, simply because it doesn't have access (or at least no efficient access) to many of the existing tools in the CPython ecosystem. >> The simple fact is that there are far more important things for Python >> developers to spend their time and effort on than optimizations like >> this. > > I don't know, there's seem to be an awful lot of effort going into > addressing exactly this issue (eg. PyPy, Pscyo, Unladen Swallow, > Shedskin....) Those are very different efforts that address very different issues. > All those compilers that offer loop unrolling are therefore wasting > their time... Sometimes they do, yes. Stefan From nad at acm.org Sun Sep 5 15:57:41 2010 From: nad at acm.org (Ned Deily) Date: Sun, 05 Sep 2010 12:57:41 -0700 Subject: Python 2.7 module path problems on OS X References: Message-ID: In article , Nicholas Cole wrote: > On Sun, Sep 5, 2010 at 10:20 AM, Ned Deily wrote: > > I'm not sure why you think it is broken. ?The Apple 2.6 and the > > python.org 2.7 have different site-package directories in different > > locations. ?That is to be expected. ?The Apple-supplied Python comes > > with some additional packages pre-installed, like setuptools, PyObjC, > > and wx. ?But you would need to install new versions of these for 2.7 > > anyway. > > > Sorry. I wasn't clear. Of course I understand that each version of > python needs its own additional packages, and I was expecting to > re-install them. But I don't want to install system-wide -- I'd like > to have my own, user-specific, site-packages. On previous versions of > python, I've installed into > ~/Library/Python/$py_version_short/site-packages under my home > directory. > > In my recollection, this has worked in the past for python installed > from python.org, but perhaps that recollection is wrong. At any rate, > it doesn't work with python 2.7. Ah, my apologies. I overlooked the "~/Library" part. So what you have been using is the setuptools Mac OS X "User" Installation configuration: (http://peak.telecommunity.com/DevCenter/EasyInstall#mac-os-x-user-instal lation). Yes, it seems an incompatibility has been introduced in 2.7 for OS X. There has been an on-going and as yet unresolved discussion on the python-dev list about the topic of user directory and config file locations so things will likely change and get more consistent in the future. But this particular problem is more immediate. I believe the problem here is that the default user directory path was changed between 2.6 and 2.7 from: ~/Library/Python/m.n/site-packages to ~/Library/Python/m.n/lib/python/site-packages I will track that down further and open an issue for it, if necessary. In the meantime, here's a little snippet that I think should work around the problem for the moment without requiring a change to your configuration files. (For simplicity of installation, it uses the Distribute fork of setuptools). The main point is to create a symlink between the old and new locations. Let me know if this works for you: $ cat .pydistutils.cfg [install] install_lib = ~/Library/Python/$py_version_short/site-packages install_scripts = ~/bin $ rm -r ~/Library/Python/2.7 # REMOVES ANY EXISTING LOCAL PACKAGES $ mkdir -p ~/Library/Python/2.7/lib/python/site-packages $ ( cd ~/Library/Python/2.7 ; ln -s lib/python/site-packages site-packages ) $ curl -s http://python-distribute.org/distribute_setup.py -o /tmp/distr.py $ python2.7 /tmp/distr.py Extracting in /var/folders/pD/pD-bOKKQHluYv0YkNWJhPE+++TI/-Tmp-/tmpF5sVf7 Now working in /var/folders/pD/pD-bOKKQHluYv0YkNWJhPE+++TI/-Tmp-/tmpF5sVf7/distribute-0. 6.14 Installing Distribute [...] $ ~/bin/easy_install easy_install easy_install-2.6 easy_install-2.7 $ ~/bin/easy_install-2.7 appscript [...] $ python2.7 -c "from appscript import *;print(app('Finder').version())" 10.5.8 $ ls -l ~/Library/Python/2.7 total 8 drwxr-x--- 3 nad staff 102 Sep 5 12:20 lib/ lrwxr-x--- 1 nad staff 24 Sep 5 12:20 site-packages@ -> lib/python/site-packages $ ls -L ~/Library/Python/2.7/site-packages appscript-0.21.1-py2.7-macosx-10.3-fat.egg/ easy-install.pth distribute-0.6.14-py2.7.egg/ setuptools.pth -- Ned Deily, nad at acm.org From speeze.pearson at gmail.com Sun Sep 5 16:19:46 2010 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Sun, 5 Sep 2010 13:19:46 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' Message-ID: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Hi! I'm writing a package with several files in it, and I've found that "isinstance" doesn't work the way I expect under certain circumstances. Short example: here are two files. # fileone.py import filetwo class AClass( object ): pass if __name__ == '__main__': a = AClass() filetwo.is_aclass( a ) # filetwo.py import fileone def is_aclass( a ): print "The argument is", ("" if isinstance(a, fileone.AClass) else "not"), "an instance of fileone.AClass" If you run fileone.py, it will tell you that "The argument is not an instance of fileone.AClass", which seems strange to me, given that the fileone module is the one that CREATES the object with its own AClass class. And if you replace "if __name__ == '__main__'" with "def main()", start Python, import fileone, and call fileone.main(), it tells you that the argument IS an instance of AClass. So, the module's name change to __main__ when you run it on its own... well, it looks like it puts all of the things defined in fileone in the __main__ namespace INSTEAD of in the fileone module's namespace, and then when filetwo imports fileone, the class is created again, this time as fileone.AClass, and though it's identical in function to __main__.AClass, one "is not" the other. Is this kind of doubled-back 'isinstance' inherently sinful? I mean, I could solve this problem by giving all of my classes "classname" attributes or something, but maybe it's just a sign that I shouldn't have to do this in the first place. From arnodel at googlemail.com Sun Sep 5 17:18:25 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 05 Sep 2010 22:18:25 +0100 Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: Spencer Pearson writes: > Hi! I'm writing a package with several files in it, and I've found > that "isinstance" doesn't work the way I expect under certain > circumstances. > > Short example: here are two files. > # fileone.py > import filetwo > > class AClass( object ): > pass > > if __name__ == '__main__': > a = AClass() > filetwo.is_aclass( a ) > > # filetwo.py > > import fileone > > def is_aclass( a ): > print "The argument is", ("" if isinstance(a, fileone.AClass) else > "not"), "an instance of fileone.AClass" > > > If you run fileone.py, it will tell you that "The argument is not an > instance of fileone.AClass", which seems strange to me, given that the > fileone module is the one that CREATES the object with its own AClass > class. And if you replace "if __name__ == '__main__'" with "def > main()", start Python, import fileone, and call fileone.main(), it > tells you that the argument IS an instance of AClass. > > So, the module's name change to __main__ when you run it on its own... > well, it looks like it puts all of the things defined in fileone in > the __main__ namespace INSTEAD of in the fileone module's namespace, > and then when filetwo imports fileone, the class is created again, > this time as fileone.AClass, and though it's identical in function to > __main__.AClass, one "is not" the other. > > Is this kind of doubled-back 'isinstance' inherently sinful? I mean, I > could solve this problem by giving all of my classes "classname" > attributes or something, but maybe it's just a sign that I shouldn't > have to do this in the first place. The behaviour is normal. I suppose you could do something like this (untested): # fileone.py if __name__ == '__main__': from fileone import * a = AClass() filetwo.is_aclass( a ) import sys; sys.exit() import filetwo class AClass( object ): pass -- Arnaud From raoulbia at gmail.com Sun Sep 5 17:47:33 2010 From: raoulbia at gmail.com (Baba) Date: Sun, 5 Sep 2010 14:47:33 -0700 (PDT) Subject: accessing a text file Message-ID: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> level: beginner how can i access the contents of a text file in Python? i would like to compare a string (word) with the content of a text file (word_list). i want to see if word is in word_list. let's assume the TXT file is stored in the same directory as the PY file. def is_valid_word(word, word_list) thanks Baba From nitinpawar432 at gmail.com Sun Sep 5 17:59:23 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Mon, 6 Sep 2010 03:29:23 +0530 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: may be something like this f = open ("file",r) data = f.read() f.close if word in data: print word, "is present in file" On Mon, Sep 6, 2010 at 3:17 AM, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Sun Sep 5 18:01:19 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 5 Sep 2010 18:01:19 -0400 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba > -- > http://mail.python.org/mailman/listinfo/python-list > Please do us a favor and at least try to figure things out on your own, rather than coming here every time you have a question. The very first result when you try searching "python read text file" is the section in the Python tutorial that explains how to do this. http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files From seth at sthrs.me Sun Sep 5 18:04:12 2010 From: seth at sthrs.me (Seth Rees) Date: Sun, 05 Sep 2010 17:04:12 -0500 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: On 09/05/10 16:47, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba f = open('text.txt') data = f.read() # You may want to convert it to a list data = data.split() # Returns true if word is in data, false otherwise word in data From python at mrabarnett.plus.com Sun Sep 5 18:05:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Sep 2010 23:05:12 +0100 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: <4C841418.4050903@mrabarnett.plus.com> On 05/09/2010 22:47, Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > That's a very basic question. I suggest you read a tutorial such as "Dive Into Python": http://diveintopython.org/toc/index.html > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > From alex.kapps at web.de Sun Sep 5 18:06:49 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Mon, 06 Sep 2010 00:06:49 +0200 Subject: accessing a text file In-Reply-To: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: <4C841479.7050404@web.de> Baba wrote: > level: beginner > > how can i access the contents of a text file in Python? > > i would like to compare a string (word) with the content of a text > file (word_list). i want to see if word is in word_list. let's assume > the TXT file is stored in the same directory as the PY file. > > def is_valid_word(word, word_list) > > > thanks > Baba Completely untested: def is_valid_word(word, filename): for line in open(filename): if word in line.split(): return True return False From bussiere at gmail.com Sun Sep 5 18:57:30 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Mon, 6 Sep 2010 00:57:30 +0200 Subject: include a file in a python program Message-ID: i've got a python.txt that contain python and it must stay as it (python.txt) how can i include it in my program ? import python.txt doesn't work is there a way : a) to make an include("python.txt") b) tell him to treat .txt as .py file that i can make an import python ? i'am using python3 Regards Bussiere fan of torchwood Google Fan boy From zhushazang at yahoo.com.br Sun Sep 5 19:00:10 2010 From: zhushazang at yahoo.com.br (Zhu Sha Zang) Date: Sun, 05 Sep 2010 20:00:10 -0300 Subject: accessing a text file In-Reply-To: <4C841479.7050404@web.de> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <4C841479.7050404@web.de> Message-ID: <4C8420FA.1070903@yahoo.com.br> Em 05-09-2010 19:06, Alexander Kapps escreveu: > Baba wrote: >> level: beginner >> >> how can i access the contents of a text file in Python? >> >> i would like to compare a string (word) with the content of a text >> file (word_list). i want to see if word is in word_list. let's assume >> the TXT file is stored in the same directory as the PY file. >> >> def is_valid_word(word, word_list) >> >> >> thanks >> Baba > > > Completely untested: > > def is_valid_word(word, filename): > for line in open(filename): > if word in line.split(): > return True > return False Damn, easy like C/C++/Java Thanks a lot! -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 19:06:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 23:06:29 GMT Subject: doctest annoyance/puzzle References: <4c83b795$0$28657$c3e8da3@news.astraweb.com> <4C83C82B.5030108@sschwarzer.net> Message-ID: <4c842275$0$28657$c3e8da3@news.astraweb.com> On Sun, 05 Sep 2010 18:41:15 +0200, Stefan Schwarzer wrote: > Hi Steven, > > On 2010-09-05 17:30, Steven D'Aprano wrote: >> I run the doctests with: >> >> python2.6 -m doctest examples.txt >> >> and the first example passes, but the second fails with NameError: >> make_spam not defined. > > I run my doctests by calling > > doctest.testfile(filename) > > for each file in a loop. This way, names and their associated objects > survice from one code block to the next. That's fine if you're calling it from Python, but I want a way to run the tests from the shell, and the advertised way to do that is by calling doctest.py as a script. The module calls testfile, so it should work. And now it's working for me. I have *no idea* what happened there... it wasn't working for me before, and now it is. Sorry for the noise :( -- Steven From pavlovevidence at gmail.com Sun Sep 5 19:09:12 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 5 Sep 2010 16:09:12 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: On Sep 5, 1:19?pm, Spencer Pearson wrote: > Hi! I'm writing a package with several files in it, and I've found > that "isinstance" doesn't work the way I expect under certain > circumstances. > > Short example: here are two files. > # fileone.py > import filetwo > > class AClass( object ): > ? pass > > if __name__ == '__main__': > ? a = AClass() > ? filetwo.is_aclass( a ) > > # filetwo.py > > import fileone > > def is_aclass( a ): > ? print "The argument is", ("" if isinstance(a, fileone.AClass) else > "not"), "an instance of fileone.AClass" > > If you run fileone.py, it will tell you that "The argument is not an > instance of fileone.AClass", which seems strange to me, given that the > fileone module is the one that CREATES the object with its own AClass > class. And if you replace "if __name__ == '__main__'" with "def > main()", start Python, import fileone, and call fileone.main(), it > tells you that the argument IS an instance of AClass. > > So, the module's name change to __main__ when you run it on its own... > well, it looks like it puts all of the things defined in fileone in > the __main__ namespace INSTEAD of in the fileone module's namespace, > and then when filetwo imports fileone, the class is created again, > this time as fileone.AClass, and though it's identical in function to > __main__.AClass, one "is not" the other. Correct. Python always treats the main script as a module called __main__. If you then try to import the main script file from another module, Python will actually import it again with whatever its usual name is. This is easily one of the most confusing and unfortunate aspects of Python. > Is this kind of doubled-back 'isinstance' inherently sinful? I mean, I > could solve this problem by giving all of my classes "classname" > attributes or something, but maybe it's just a sign that I shouldn't > have to do this in the first place. Even if there are better ways than isinstance, the weird behavior of __main__ shouldn't be the reason not to use it. My recommendation for most programmers is to treat Python files either as scripts (which you start Python interpreter with) or modules (which you import from within Python); never both. Store most functionality in modules and keep startup scripts small. If you do this, the weird semantics of __main__ is a moot point. If you want to be able to run a module as a script while avoiding side effects due to it being named __main__, the easiest thing to do is to put something like the following boilerplate at the top of the module (this causes the module to rename itself). import sys if __name__ == '__main__': is_main = True # since you're overwriting __name__ you'll need this later __name__ = 'foo' sys.modules['foo'] = sys.modules['__main__'] else: is_main = False All of this gets a lot more complicated when packages are involved. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 19:12:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 23:12:19 GMT Subject: include a file in a python program References: Message-ID: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> On Mon, 06 Sep 2010 00:57:30 +0200, bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it > (python.txt) Why? Is it against the law to change it? *wink* > how can i include it in my program ? > import python.txt doesn't work You could write a custom importer to handle it, but I can't help you with that. Try Google. > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? fp = open("python.txt") text = fp.read() fp.close() exec(text) But keep in mind that the contents of python.txt will be executed as if you had typed it yourself. If you don't trust the source with your life (or at least with the contents of your computer), don't execute it. -- Steven From roy at panix.com Sun Sep 5 19:14:52 2010 From: roy at panix.com (Roy Smith) Date: Sun, 05 Sep 2010 19:14:52 -0400 Subject: include a file in a python program References: Message-ID: In article , bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it (python.txt) > > how can i include it in my program ? > import python.txt doesn't work > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? > i'am using python3 The simple solution (at least for unix-ish systems) would be to make a symlink python.py -> python.txt. If you don't have the ability to do that externally, you could even have your python program create the symlink on the fly, import the module, then delete the symlink. The symlink could even be in /tmp. Another possible solution is to read the entire file into a string and then eval() the string. I'm assuming eval() still exists in python 3; does it? Yet another possibility (never tried this, but it seems reasonable) would be to compile() your text file (http://docs.python.org/py3k/library/functions.html#compile). Of course, it would be a lot easier if you just renamed the file, but I'll take it as a given that there are external forces which prevent you from doing that. From roy at panix.com Sun Sep 5 19:17:09 2010 From: roy at panix.com (Roy Smith) Date: Sun, 05 Sep 2010 19:17:09 -0400 Subject: include a file in a python program References: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> Message-ID: In article <4c8423d3$0$28657$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > fp = open("python.txt") > text = fp.read() > fp.close() > exec(text) > But keep in mind that the contents of python.txt will be executed as if > you had typed it yourself. If you don't trust the source with your life > (or at least with the contents of your computer), don't execute it. Well, this is true, but eval() or exec() isn't really exposing him to anything that import isn't. From python at mrabarnett.plus.com Sun Sep 5 19:27:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Sep 2010 00:27:13 +0100 Subject: include a file in a python program In-Reply-To: References: Message-ID: <4C842751.7090105@mrabarnett.plus.com> On 05/09/2010 23:57, bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it (python.txt) > > how can i include it in my program ? > import python.txt doesn't work > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? > i'am using python3 import imp python = imp.load_source("python", "python.txt") > Regards > Bussiere > fan of torchwood > Google Fan boy A fan of Torchwood and Google, but not Python? :-) From tjreedy at udel.edu Sun Sep 5 19:39:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Sep 2010 19:39:31 -0400 Subject: include a file in a python program In-Reply-To: References: Message-ID: On 9/5/2010 6:57 PM, bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it (python.txt) If you are working for someone who is such an idiot as to impose such a condition on you, you have our condolences. > how can i include it in my program ? > import python.txt doesn't work A file run directly as a script can be named anything. But as far as I know, imported code must be xxx.py, either in a directory or zipfile. > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? 1. Write a custom importer (hard, I have no idea how). 2. Copy the .txt file to .py, either before running the main program or within a custom import function. -- Terry Jan Reedy From tjreedy at udel.edu Sun Sep 5 19:41:39 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Sep 2010 19:41:39 -0400 Subject: include a file in a python program In-Reply-To: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> References: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 9/5/2010 7:12 PM, Steven D'Aprano wrote: > fp = open("python.txt") > text = fp.read() > fp.close() > exec(text) > > But keep in mind that the contents of python.txt will be executed as if > you had typed it yourself. If you don't trust the source with your life > (or at least with the contents of your computer), don't execute it. Also, this executes the code within the namespace of the calling code rather than within a fresh module namespace. That could be either better or worse. -- Terry Jan Reedy From steve at REMOVE-THIS-cybersource.com.au Sun Sep 5 19:45:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Sep 2010 23:45:25 GMT Subject: include a file in a python program References: Message-ID: <4c842b95$0$28657$c3e8da3@news.astraweb.com> On Mon, 06 Sep 2010 00:27:13 +0100, MRAB wrote: > import imp > python = imp.load_source("python", "python.txt") Nice! -- Steven From davea at ieee.org Sun Sep 5 20:07:32 2010 From: davea at ieee.org (Dave Angel) Date: Sun, 05 Sep 2010 20:07:32 -0400 Subject: Class changes in circular imports when __name__ == '__main__' In-Reply-To: References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: <4C8430C4.6000206@ieee.org> On 2:59 PM, Carl Banks wrote: > On Sep 5, 1:19 pm, Spencer Pearson wrote: >> Hi! I'm writing a package with several files in it, and I've found >> that "isinstance" doesn't work the way I expect under certain >> circumstances. >> >> Short example: here are two files. >> # fileone.py >> import filetwo >> >> class AClass( object ): >> pass >> >> if __name__ ='__main__': >> a =Class() >> filetwo.is_aclass( a ) >> >> # filetwo.py >> >> import fileone >> >> def is_aclass( a ): >> print "The argument is", ("" if isinstance(a, fileone.AClass) else >> "not"), "an instance of fileone.AClass" >> >> If you run fileone.py, it will tell you that "The argument is not an >> instance of fileone.AClass", which seems strange to me, given that the >> fileone module is the one that CREATES the object with its own AClass >> class. And if you replace "if __name__ ='__main__'" with "def >> main()", start Python, import fileone, and call fileone.main(), it >> tells you that the argument IS an instance of AClass. >> >> So, the module's name change to __main__ when you run it on its own... >> well, it looks like it puts all of the things defined in fileone in >> the __main__ namespace INSTEAD of in the fileone module's namespace, >> and then when filetwo imports fileone, the class is created again, >> this time as fileone.AClass, and though it's identical in function to >> __main__.AClass, one "is not" the other. > Correct. Python always treats the main script as a module called > __main__. If you then try to import the main script file from another > module, Python will actually import it again with whatever its usual > name is. > > This is easily one of the most confusing and unfortunate aspects of > Python. > > >> Is this kind of doubled-back 'isinstance' inherently sinful? I mean, I >> could solve this problem by giving all of my classes "classname" >> attributes or something, but maybe it's just a sign that I shouldn't >> have to do this in the first place. > Even if there are better ways than isinstance, the weird behavior of > __main__ shouldn't be the reason not to use it. > > My recommendation for most programmers is to treat Python files either > as scripts (which you start Python interpreter with) or modules (which > you import from within Python); never both. Store most functionality > in modules and keep startup scripts small. If you do this, the weird > semantics of __main__ is a moot point. > > If you want to be able to run a module as a script while avoiding side > effects due to it being named __main__, the easiest thing to do is to > put something like the following boilerplate at the top of the module > (this causes the module to rename itself). > > import sys > if __name__ ='__main__': > is_main =rue # since you're overwriting __name__ you'll need > this later > __name__ =foo' > sys.modules['foo'] =ys.modules['__main__'] > else: > is_main =alse > > > All of this gets a lot more complicated when packages are involved. > > > Carl Banks > Perhaps a better answer would be to import __main__ from the second module. But to my way of thinking, the answer should be to avoid ever having circular imports. This is just the most blatant of the problems that circular imports can cause. I don't know of any cases where circular dependencies are really necessary, but if one decides to use them, then two things should be done: 1) do almost nothing in top-level code in any module involved in such circular dependency. Top-level should have all of the imports, and none of the executable code. 2) do not ever involve the startup script in the loop. If necessary, make it two lines, importing,then calling the real mainline. DaveA From jason.heeris at gmail.com Sun Sep 5 20:57:10 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 5 Sep 2010 17:57:10 -0700 (PDT) Subject: Subclassing by monkey-patching References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> Message-ID: On Sep 5, 6:56?pm, Peter Otten <__pete... at web.de> wrote: > Does it have to be gio.FileMonitor? pyinotify can automatically add new > subdirectories out of the box. Well, since it's for a core part of the software, I'd like it to be cross platform ? not in the sense of Windows/Mac, but FreeBSD, Solaris, etc. But it's looking more and more like I should give up that particular goal. Cheers, Jason From jrmy.lnrd at gmail.com Sun Sep 5 21:06:44 2010 From: jrmy.lnrd at gmail.com (genxtech) Date: Sun, 5 Sep 2010 18:06:44 -0700 (PDT) Subject: Question about Reading Files References: <93fcfd2a-fa26-4e23-8a54-a84ea36b688e@s9g2000yqd.googlegroups.com> Message-ID: On Sep 5, 4:16?am, Peter Otten <__pete... at web.de> wrote: > genxtech wrote: > > Hello. ?I am still really new to python and I have a project where I > > am trying to use the data files from another program and write a new > > program with new user interface and all. ?My first step was to open > > one of the files in 'rb' mode and print the contents, but I am > > unfamiliar with the format. ?Here is what was printed to the terminal: > > > b'URES\x04\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f > > \x00\x00\x00\x03\t\x00c\x01\x00\x00\x0c#\x00\x00\x02\x1b\x00\x00\x00Y > > \x00\x00\x00\x08\x98"\x00\x00t\x00\x00\x00\x01\'\x01\x00\x00z$ > > \x00\x00\x04,\xa7\x00\x00\xa1%\x00\x00\x05\x0b\x00\x00\x00o$\x00\x00\n > > \x11\x00\x00\x00\xcd\xcc\x00\x00\x0b\xf8\x00\x00\x00\xde\xcc > > \x00\x00\x0c\x19\x00\x00' > > > I am using Python 3.1 on a Fedora 13 box if that makes any difference. > > Any advise on how to decode the data would be greatly appreciated. > > What's the name of the file? > What's the program that uses the file? > If the source code is available, what library does that program use to read > the file? > > Peter Unfortunately the source code isn't available, so I'm trying to figure out a way to get the format of the file on my own. From jason.heeris at gmail.com Sun Sep 5 22:29:31 2010 From: jason.heeris at gmail.com (Jason) Date: Sun, 5 Sep 2010 19:29:31 -0700 (PDT) Subject: Subclassing by monkey-patching References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> Message-ID: On Sep 6, 8:57?am, Jason wrote: > But it's looking more and more like I should give up > that particular goal. ...buuuuut on the other hand I just knocked together a pyinotify threaded watch system in about 50 lines. It's tempting to tell users of other platforms to write their own and submit a patch. Maybe this is all barking up the wrong tree. Cheers, Jason From pavlovevidence at gmail.com Sun Sep 5 23:15:20 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 5 Sep 2010 20:15:20 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: On Sep 5, 5:07?pm, Dave Angel wrote: > On 2:59 PM, Carl Banks wrote: > > All of this gets a lot more complicated when packages are involved. > > Perhaps a better answer would be to import __main__ from the second module. Then what if the module is imported from a different script? It'll try to import __main__ but get a different script than expected. > But to my way of thinking, the answer should be to avoid ever having > circular imports. ?This is just the most blatant of the problems that > circular imports can cause. > > I don't know of any cases where circular dependencies are really > necessary, but if one decides to use them, then two things should be done: I don't think they're ever necessary but sometimes it's convenient. This could be one of those cases. One of the less misguided reasons to invoke a module as a script is to run tests on the module. When you do that you might need to call an outside module to set up a test environment, and that module might happen to import the calling module. You could refactor the test to avoid the circular import, but that kind of defeats the convenience of stowing the test in the module. > 1) do almost nothing in top-level code in any module involved in such > circular dependency. ?Top-level should have all of the imports, and none > of the executable code. > 2) do not ever involve the startup script in the loop. ?If necessary, > make it two lines, importing,then calling the real mainline. All good advice for that situation. I would add that if you define a base class in one module and subclass in another, you want to keep those modules out of cycles. The problem with circular imports is that you don't usually know what order the modules will be imported, but you need to be sure the base class is defined when you subclass. (I learned that lesson the hard way, and I had to hack up an import hook to enforce that imports occurred in the correct order.) Carl Banks From antonyjeevaraj at rediffmail.com Mon Sep 6 00:26:33 2010 From: antonyjeevaraj at rediffmail.com (jameser) Date: Sun, 5 Sep 2010 21:26:33 -0700 (PDT) Subject: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV Message-ID: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV Generate $50 to $100 whenever you have a couple of hours free time to spare. You could make $50 or more in the next 2 hours. Starting right Now!Today! GET PAID TO: Take online surveys and make from $5 to $75, or more Participate in focus groups and make up to $150 an hour Take phone surveys and you can earn as much as $120 an hour Try new products (and keep the free products too) Preview new movie trailers for $4 to $25 an hour http://snipurl.com/11i6lw Earn from your free website Awesome earnings get paid for your honest work Join as a free member and get paid to your bank account To join the Network follow the link http://snipurl.com/11i6lw Get paid for your real work and earn awesome $$$$ From niklasro at gmail.com Mon Sep 6 03:50:29 2010 From: niklasro at gmail.com (Niklasro(.appspot)) Date: Mon, 6 Sep 2010 00:50:29 -0700 (PDT) Subject: include a file in a python program References: Message-ID: On Sep 5, 10:57?pm, bussiere bussiere wrote: > i've got a python.txt that contain python and it must stay as it (python.txt) > > how can i include it in my program ? > import python.txt doesn't work > is there a way : > a) to make an include("python.txt") > b) tell him to treat .txt as .py file that i can make an import python ? > i'am using python3 > Regards > Bussiere > fan of torchwood > Google Fan boy You can do it with tkinter to also enable GUI. From niklasro at gmail.com Mon Sep 6 03:52:12 2010 From: niklasro at gmail.com (Niklasro(.appspot)) Date: Mon, 6 Sep 2010 00:52:12 -0700 (PDT) Subject: Learning variable visibility Message-ID: Hi How do I declare a variable visibility across files? Will import name where name is name of the file do? Thanks for instructing Niklas Rosencrantz From niklasro at gmail.com Mon Sep 6 03:54:33 2010 From: niklasro at gmail.com (Niklasro) Date: Mon, 6 Sep 2010 00:54:33 -0700 (PDT) Subject: GUibuilder evaluation Message-ID: Hello Making a GUI, could you recommend tkinter or any other proposal? Thanks From raoulbia at gmail.com Mon Sep 6 03:55:28 2010 From: raoulbia at gmail.com (Baba) Date: Mon, 6 Sep 2010 00:55:28 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> On 6 sep, 00:01, Benjamin Kaplan wrote: > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > > level: beginner > > > how can i access the contents of a text file in Python? > > > i would like to compare a string (word) with the content of a text > > file (word_list). i want to see if word is in word_list. let's assume > > the TXT file is stored in the same directory as the PY file. > > > def is_valid_word(word, word_list) > > > thanks > > Baba > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Please do us a favor and at least try to figure things out on your > own, rather than coming here every time you have a question. The very > first result when you try searching "python read text file" is the > section in the Python tutorial that explains how to do this. > > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... Hi Benjamin I did find that page prior to posting the question but i still wanted to have a second opinion to complement that info so as to make things easier The first line of my post clearly states that i am a beginner. It's nice to provide links which can help answer the question but please be so polite and keep personal comments for yourself. To all other respondants: thank you for your kind instructions and directions. Thanks Baba From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 6 04:08:06 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 06 Sep 2010 10:08:06 +0200 Subject: Subclassing by monkey-patching In-Reply-To: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> Message-ID: <4c84a166$0$499$426a74cc@news.free.fr> Jason a ?crit : > On Sep 5, 3:53 pm, Peter Otten <__pete... at web.de> wrote: >>>>> m = gio.File(".").monitor_directory() >>>>> C = type(m) > > 'C' will not necessarily be 'gio.FileMonitor' ? I think the internals > of the GIO methods might further "subclass" it in some way depending > on what underlying monitors are available. > >> A possible alternative may be a class that wraps a FileMonitor instead of >> subclassing it. > > I've been avoiding this because it involves a lot of boilerplate: the > signals needs to be replicated and passed through, same for all > GObject properties, same for the usual methods. Python is not Java !-) http://docs.python.org/reference/datamodel.html#object.__getattr__ From raoulbia at gmail.com Mon Sep 6 04:10:28 2010 From: raoulbia at gmail.com (Baba) Date: Mon, 6 Sep 2010 01:10:28 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> Message-ID: <44cb0ed6-63ca-4c1a-8501-e284010993fa@v41g2000yqv.googlegroups.com> On 6 sep, 00:04, Seth Rees wrote: > On 09/05/10 16:47, Baba wrote: > > > level: beginner > > > how can i access the contents of a text file in Python? > > > i would like to compare a string (word) with the content of a text > > file (word_list). i want to see if word is in word_list. let's assume > > the TXT file is stored in the same directory as the PY file. > > > def is_valid_word(word, word_list) > > > thanks > > Baba > > ? ?f = open('text.txt') > ? ?data = f.read() > ? ?# You may want to convert it to a list > ? ?data = data.split() > ? ?# Returns true if word is in data, false otherwise > ? ?word in data Thanks Seth! From georg at python.org Mon Sep 6 04:22:17 2010 From: georg at python.org (Georg Brandl) Date: Mon, 06 Sep 2010 10:22:17 +0200 Subject: [RELEASED] Python 3.2 alpha 2 Message-ID: <4C84A4B9.2040406@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the second 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) iEYEARECAAYFAkyEpLkACgkQN9GcIYhpnLCzSwCdFyPz1dPEehJZmeW8wDltqkqe /ogAnim1J99qDpeLmcUDTf0YBh1W95vf =x+ee -----END PGP SIGNATURE----- From nicholas.cole at gmail.com Mon Sep 6 04:29:48 2010 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Mon, 6 Sep 2010 09:29:48 +0100 Subject: Python 2.7 module path problems on OS X In-Reply-To: References: Message-ID: On Sun, Sep 5, 2010 at 8:57 PM, Ned Deily wrote: > In article > , > ?Nicholas Cole wrote: > >> On Sun, Sep 5, 2010 at 10:20 AM, Ned Deily wrote: >> > I'm not sure why you think it is broken. ?The Apple 2.6 and the >> > python.org 2.7 have different site-package directories in different >> > locations. ?That is to be expected. ?The Apple-supplied Python comes >> > with some additional packages pre-installed, like setuptools, PyObjC, >> > and wx. ?But you would need to install new versions of these for 2.7 >> > anyway. >> > >> Sorry. I wasn't clear. ?Of course I understand that each version of >> python needs its own additional packages, and I was expecting to >> re-install them. ?But I don't want to install system-wide -- ?I'd like >> to have my own, user-specific, site-packages. ?On previous versions of >> python, I've ?installed into >> ~/Library/Python/$py_version_short/site-packages under my home >> directory. >> >> In my recollection, this has worked in the past for python installed >> from python.org, but perhaps that recollection is wrong. ?At any rate, >> it doesn't ?work with python 2.7. > > Ah, my apologies. ?I overlooked the "~/Library" part. ?So what you have > been using is the setuptools Mac OS X "User" Installation configuration: > (http://peak.telecommunity.com/DevCenter/EasyInstall#mac-os-x-user-instal > lation). ? Yes, it seems an incompatibility has been introduced in 2.7 > for OS X. ?There has been an on-going and as yet unresolved discussion > on the python-dev list about the topic of user directory and config file > locations so things will likely change and get more consistent in the > future. ?But this particular problem is more immediate. ?I believe the > problem here is that the default user directory path was changed between > 2.6 and 2.7 from: > > ? ?~/Library/Python/m.n/site-packages > > to > > ? ?~/Library/Python/m.n/lib/python/site-packages > > I will track that down further and open an issue for it, if necessary. > In the meantime, here's a little snippet that I think should work around > the problem for the moment without requiring a change to your > configuration files. ?(For simplicity of installation, it uses the > Distribute fork of setuptools). ?The main point is to create a symlink > between the old and new locations. Let me know if this works for you: Dear Ned, Thank you very much for your help and for the code snippet. I don't know enough about the background to open an issue myself, so I am grateful that you might take this on. Just to throw in my $0.02, I do think is important to be able to have a distutils configuration that works across versions (since so many of us have several versions installed for testing purposes), and so I do view this incompatibility is a bug! But thank you very much for solving my immediate problem. Best wishes, Nicholas From wbelguidoum at gmail.com Mon Sep 6 06:15:35 2010 From: wbelguidoum at gmail.com (wissem belguidoum) Date: Mon, 6 Sep 2010 03:15:35 -0700 (PDT) Subject: GUibuilder evaluation References: Message-ID: <4ec74e1e-91fd-4bec-954b-e6b9db468a91@t2g2000yqe.googlegroups.com> On 6 sep, 09:54, Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? > Thanks Hi, I am considering to learn Qt, which is a multi-platform widget liberary and a RAD IDE..., basically for C++ programing but there is a binding called PyQt for python. Good luck. From wbelguidoum at gmail.com Mon Sep 6 06:19:08 2010 From: wbelguidoum at gmail.com (wissem belguidoum) Date: Mon, 6 Sep 2010 03:19:08 -0700 (PDT) Subject: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV References: Message-ID: <7dac7c3d-ae61-4d7e-8f9c-f53e7d9a69d9@11g2000yqq.googlegroups.com> On 6 sep, 06:26, jameser wrote: > MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INV > > Generate $50 to $100 whenever you > have a couple of hours free time to spare. > You could make $50 or more in the next 2 hours. > Starting right Now!Today! > > GET PAID TO: > Take online surveys and make from $5 to $75, or more > Participate in focus groups and make up to $150 an hour > Take phone surveys and you can earn as much as $120 an hour > Try new products (and keep the free products too) > Preview new movie trailers for $4 to $25 an hour > > http://snipurl.com/11i6lw > > Earn from your free website > Awesome earnings get paid for your honest work > Join as a free member and get paid to your bank account > To join the Network follow the link > > http://snipurl.com/11i6lw > > Get paid for your real work and earn awesome $$$$ Is this a kind of trap to make an email database ? Reminder : this is a python programming language group. From bartc at freeuk.com Mon Sep 6 06:38:22 2010 From: bartc at freeuk.com (BartC) Date: Mon, 6 Sep 2010 11:38:22 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: "Stefan Behnel" wrote in message news:mailman.470.1283712666.29448.python-list at python.org... > BartC, 05.09.2010 19:09: >> All those compilers that offer loop unrolling are therefore wasting >> their time... > > Sometimes they do, yes. Modifying the OP's code a little: a = 0 for i in xrange(100000000): # 100 million a = a + 10 # add 10 or 100 print a Manually unrolling such a loop four times (ie. 4 copies of the body, and counting only to 25 million) increased the speed by between 16% and 47% (ie. runtime reducing by between 14% and 32%). This depended on whether I added +10 or +100 (ie. whether long integers are needed), whether it was inside or outside a function, and whether I was running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange' as a synonym for 'range'?) These are just some simple tests on my particular machine and implementations, but they bring up some points: (1) Loop unrolling does seem to have a benefit, when the loop body is small. (2) Integer arithmetic seems to go straight from 32-bits to long integers; why not use 64-bits before needing long integers? (3) Since the loop variable is never used, why not have a special loop statement that repeats code so many times? This can be very fast, since the loop counter need not be a Python object, and probably there would be no need for unrolling at all: repeat 100000000: # for example a = a + 10 -- Bartc From yoavglazner at gmail.com Mon Sep 6 06:40:23 2010 From: yoavglazner at gmail.com (Glazner) Date: Mon, 6 Sep 2010 03:40:23 -0700 (PDT) Subject: Subclassing by monkey-patching References: <1fc76d07-66ea-4e14-90ad-a21f5a5d2855@g6g2000pro.googlegroups.com> <4c84a166$0$499$426a74cc@news.free.fr> Message-ID: <1618881c-b5bb-404b-8a7b-2f40c22d2b98@g17g2000yqe.googlegroups.com> On Sep 6, 11:08?am, Bruno Desthuilliers wrote: > Jason a ?crit : > > > On Sep 5, 3:53 pm, Peter Otten <__pete... at web.de> wrote: > >>>>> m = gio.File(".").monitor_directory() > >>>>> C = type(m) > > > 'C' will not necessarily be 'gio.FileMonitor' ? I think the internals > > of the GIO methods might further "subclass" it in some way depending > > on what underlying monitors are available. > > >> A possible alternative may be a class that wraps a FileMonitor instead of > >> subclassing it. > > > I've been avoiding this because it involves a lot of boilerplate: the > > signals needs to be replicated and passed through, same for all > > GObject properties, same for the usual methods. > > Python is not Java !-)http://docs.python.org/reference/datamodel.html#object.__getattr__ Yep, thats what i do... def MySubclass(object): def __init__(self): self._ins = SomeObject() def __getattr__(self,name): return getattr(self._ins,name) From vgnulinux at gmail.com Mon Sep 6 07:02:56 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Mon, 6 Sep 2010 16:32:56 +0530 Subject: Embedded Systems development using Python Message-ID: Hi List, Can Python be used for embedded systems development ? If Yes can anyone point me to a tutorial/reference website which explains about this. Thanks and Regards Vgnu -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.fodrek at stuba.sk Mon Sep 6 07:11:10 2010 From: peter.fodrek at stuba.sk (Peter Fodrek) Date: Mon, 6 Sep 2010 13:11:10 +0200 Subject: Embedded Systems development using Python In-Reply-To: References: Message-ID: <201009061311.10248.peter.fodrek@stuba.sk> On Monday 06 September 2010 13:02:56 VGNU Linux wrote: > Hi List, > Can Python be used for embedded systems development ? It is hard to say yes or no. For hard Real-time systems or hard Real-time parts of complex system answer is no, in another type of embedded systems yes or maybe > If Yes can anyone point me to a tutorial/reference website which explains > about this. There are no tutorials to do so as I know. Peter From stefan_ml at behnel.de Mon Sep 6 07:20:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 06 Sep 2010 13:20:01 +0200 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: BartC, 06.09.2010 12:38: > why doesn't Python 3 just accept 'xrange' as a synonym for 'range'? Because Python 3 deliberately breaks backwards compatibility in order to clean up the language. > These are just some simple tests on my particular machine and > implementations, but they bring up some points: > > (1) Loop unrolling does seem to have a benefit, when the loop body is > small. Nobody said otherwise. However, "small" is a pretty weak characterisation here. And don't expect CPython to do it for you, because doing it automatically requires the ability to see that there are no side effects. It's a lot more costly to assure that than what you actually gain with the optimisation. As your example shows, doing this optimisation manually is pretty straight forward, so there isn't really a need to let the runtime do it for you. > (2) Integer arithmetic seems to go straight from 32-bits to long > integers; why not use 64-bits before needing long integers? You are making assumptions based on Python 2, I guess. Try Python 3.1 or later instead, where the int and long types are unified. Also, the implementation is a bit more complex than you appear to be thinking. Don't forget that it has received serious benchmarking based optimisations. > (3) Since the loop variable is never used, why not have a special loop > statement that repeats code so many times? Because special cases are not special enough to break the rules. As others have stated before, you can use itertools to reduce that part of the looping overhead, if it really hurts your concrete code. There also were lots of examples in this thread on different looping solutions and their performance differences. Any of them may fit your needs in a given situation. > This can be very fast, since > the loop counter need not be a Python object It still has to count, though. Stefan From stefan_ml at behnel.de Mon Sep 6 07:22:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 06 Sep 2010 13:22:58 +0200 Subject: Embedded Systems development using Python In-Reply-To: References: Message-ID: VGNU Linux, 06.09.2010 13:02: > Can Python be used for embedded systems development ? It can and has been. What kind of embedded system with what set of capabilities are you thinking about? TV sets? Mobile phones? Smart dust? Stefan From kushal.kumaran+python at gmail.com Mon Sep 6 07:49:33 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 6 Sep 2010 17:19:33 +0530 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: On Mon, Sep 6, 2010 at 4:08 PM, BartC wrote: > "Stefan Behnel" wrote in message > news:mailman.470.1283712666.29448.python-list at python.org... >> >> BartC, 05.09.2010 19:09: > >>> All those compilers that offer loop unrolling are therefore wasting >>> their time... >> >> Sometimes they do, yes. > > Modifying the OP's code a little: > > a = 0 > for i in xrange(100000000): ? ? ?# 100 million > ? ?a = a + 10 ? ? ? ? ? ? ? ? ?# add 10 or 100 > print a > > Manually unrolling such a loop four times (ie. 4 copies of the body, and > counting only to 25 million) increased the speed by between 16% and 47% (ie. > runtime reducing by between 14% and 32%). > > This depended on whether I added +10 or +100 (ie. whether long integers are > needed), whether it was inside or outside a function, and whether I was > running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange' as a > synonym for 'range'?) > > These are just some simple tests on my particular machine and > implementations, but they bring up some points: > > (1) Loop unrolling does seem to have a benefit, when the loop body is small. > > (2) Integer arithmetic seems to go straight from 32-bits to long integers; > why not use 64-bits before needing long integers? > On 64-bit systems, integer arithmetic will go from 64-bit native integers to long. Will using any emulated 64-bit type on a 32-bit system actually be better than the python long implementation? >From my 64-bit linux system: In [1]: n = 2 ** 40 In [2]: type(n) Out[2]: In [3]: n = 2 ** 80 In [4]: type(n) Out[4]: > (3) Since the loop variable is never used, why not have a special loop > statement that repeats code so many times? This can be very fast, since the > loop counter need not be a Python object, and probably there would be no > need for unrolling at all: > > repeat 100000000: ? ? ? ?# for example > ? a = a + 10 > -- regards, kushal From vgnulinux at gmail.com Mon Sep 6 07:52:09 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Mon, 6 Sep 2010 17:22:09 +0530 Subject: Embedded Systems development using Python In-Reply-To: References: Message-ID: Hi, A small device like a mobile but with only 2 major buttons, with GPS and GPRS capabilities. Can anyone tell me from where to start learning about this ? Regards Vivek On Mon, Sep 6, 2010 at 4:52 PM, Stefan Behnel wrote: > VGNU Linux, 06.09.2010 13:02: > > Can Python be used for embedded systems development ? >> > > It can and has been. > > What kind of embedded system with what set of capabilities are you thinking > about? TV sets? Mobile phones? Smart dust? > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Mon Sep 6 07:56:39 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Sep 2010 13:56:39 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: <20100906135639.61959ec3@pitrou.net> On Mon, 06 Sep 2010 13:20:01 +0200 Stefan Behnel wrote: > > > (2) Integer arithmetic seems to go straight from 32-bits to long > > integers; why not use 64-bits before needing long integers? > > You are making assumptions based on Python 2, I guess. Try Python 3.1 or > later instead, where the int and long types are unified. Also, the > implementation is a bit more complex than you appear to be thinking. Don't > forget that it has received serious benchmarking based optimisations. The optimizations are mainly related to big integer arithmetics, though. For small ints the main cost is interpretation and unboxing overhead as always. Regards Antoine. From joakim.hove at gmail.com Mon Sep 6 08:28:15 2010 From: joakim.hove at gmail.com (Joakim Hove) Date: Mon, 6 Sep 2010 05:28:15 -0700 (PDT) Subject: ctypes and garbage collection Message-ID: <7b7975ef-9948-463d-8eb3-77ba3097f68c@z28g2000yqh.googlegroups.com> Hello, I have used ctypes to wrap a C-library - it has been a really painless experience! The C-library instantiates a quite large "container-like" structure. There are then several functions to inspect the content of the container, get at items and free the whole thing: /* C - code */ c_container_type * c_container_alloc( const char * filename ); c_node_type * c_container_get_node( c_container_type * container , const char * node_id ); void c_container_free( c_container_type * container ); .... Observe that the c_container_get_node() function does _not_ allocate memory, it just returns a opaque handle to a node structure, still fully owned by the container structure. I have wrapped this with Python/ctypes roughly like this (severly trimmed pseudo code): class Container: def __init__(self , filename): self.c_ptr = c_container_alloc( filename ) def __del__( self ): c_container_free( self.c_ptr ) def get_node( self , node_id): Node( c_container_get_node( self , node_id )) class Node: def __init__( self , c_ptr ): self.c_ptr = c_ptr def __del__( self ): pass Now, a use scenario might be like this: 1. Instantiate a Container() instance. 2. Instantiate a Node() instance with the Container.get_node() function. 3. Forget about the Container instance and work happily with the Node instance. 4. Out of the blue comes the gc - and then? Will the Node instance be enough to protect the Container instance from beeing garbage collected? I thought maybe the get_node() function should have something like a incref() call, and the Node.__del__() function a corresponding decref()? Or ?? Regards Joakim Hove From bc at freeuk.com Mon Sep 6 08:32:46 2010 From: bc at freeuk.com (BartC) Date: Mon, 6 Sep 2010 13:32:46 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: "Stefan Behnel" wrote in message news:mailman.485.1283772019.29448.python-list at python.org... > BartC, 06.09.2010 12:38: >> (2) Integer arithmetic seems to go straight from 32-bits to long >> integers; why not use 64-bits before needing long integers? > > You are making assumptions based on Python 2, I guess. Try Python 3.1 or > later instead, where the int and long types are unified. Also, the > implementation is a bit more complex than you appear to be thinking. Don't > forget that it has received serious benchmarking based optimisations. That's true; wider arithmetic was less of an overhead in Python 3. This shows the effect of making several small optimisations which might otherwise be dismissed: with the +100 test, the Python 3 faster wider arithmetic, *plus* the 4x loop unrolling, resulted in an 85% speed increase compared with Python 2 using the original loop. Which is pretty good considering Python 3 is generally slower than '2'. >> This can be very fast, since >> the loop counter need not be a Python object > > It still has to count, though. That might be just a couple of machine instructions. Plus the bytecode overhead. -- Bartc From eckhardt at satorlaser.com Mon Sep 6 09:11:14 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 06 Sep 2010 15:11:14 +0200 Subject: ctypes and garbage collection References: <7b7975ef-9948-463d-8eb3-77ba3097f68c@z28g2000yqh.googlegroups.com> Message-ID: Joakim Hove wrote: > I have used ctypes to wrap a C-library > [...] > Observe that the c_container_get_node() function does _not_ allocate > memory, it just returns a opaque handle to a node structure, still > fully owned by the container structure. [...] > > class Container: > def __init__(self , filename): > self.c_ptr = c_container_alloc( filename ) > > def __del__( self ): > c_container_free( self.c_ptr ) > > def get_node( self , node_id): > Node( c_container_get_node( self , node_id )) > > > class Node: > def __init__( self , c_ptr ): > self.c_ptr = c_ptr > > def __del__( self ): > pass > > > Now, a use scenario might be like this: > > 1. Instantiate a Container() instance. > 2. Instantiate a Node() instance with the Container.get_node() > function. > 3. Forget about the Container instance and work happily with the Node > instance. > 4. Out of the blue comes the gc - and then? Will the Node instance be > enough to protect the Container instance from beeing garbage > collected? No. You should be able to even see that by logging calls to alloc/free of your library. > I thought maybe the get_node() function should have something like a > incref() call, and the Node.__del__() function a corresponding > decref()? Or ?? I'd add an "__owner" field to the node, initialised with the owning container instance. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From joakim.hove at gmail.com Mon Sep 6 09:22:22 2010 From: joakim.hove at gmail.com (Joakim Hove) Date: Mon, 6 Sep 2010 06:22:22 -0700 (PDT) Subject: ctypes and garbage collection References: <7b7975ef-9948-463d-8eb3-77ba3097f68c@z28g2000yqh.googlegroups.com> Message-ID: <95c2745a-637f-4e98-b6f2-d6a83d006d11@i5g2000yqe.googlegroups.com> > I'd add an "__owner" field to the node, initialised with the owning > container instance. I will - thank you! Joakim From solipsis at pitrou.net Mon Sep 6 09:30:51 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Sep 2010 15:30:51 +0200 Subject: Embedded Systems development using Python References: Message-ID: <20100906153051.2537c9d0@pitrou.net> On Mon, 6 Sep 2010 17:22:09 +0530 VGNU Linux wrote: > Hi, > > A small device like a mobile but with only 2 major buttons, with GPS and > GPRS capabilities. > Can anyone tell me from where to start learning about this ? Read the official docs for the C API: http://docs.python.org/extending/embedding.html http://docs.python.org/extending/index.html http://docs.python.org/c-api/ You'll probably need at least a 32-bit CPU and some non-negligible amount of RAM. If not, then you'll want to take a look at alternatve implementations of Python: http://wiki.python.org/moin/EmbeddedPython Regards Antoine. From denisg640 at gmail.com Mon Sep 6 09:47:19 2010 From: denisg640 at gmail.com (Denis Gomes) Date: Mon, 6 Sep 2010 09:47:19 -0400 Subject: GUibuilder evaluation In-Reply-To: <4ec74e1e-91fd-4bec-954b-e6b9db468a91@t2g2000yqe.googlegroups.com> References: <4ec74e1e-91fd-4bec-954b-e6b9db468a91@t2g2000yqe.googlegroups.com> Message-ID: Hello, There are really three you can choose from if you are serious about making GUI applications. PyQt as already suggested. wxPython and pyGTK. Tkinter is good in my opinion if you are making smaller gui based programs. PyQt has an extensive number of additional features, including networking, OpenGL, Multimedia, Database etc. It is used for the KDE desktop environment. PyQt has a very powerful Designer which you can used to generate python code very fast for complex guis. wxPython is only GUI centric, but it does have a host of widgets you can play with and pre-made examples you can use to speed up your programming. It also has a gui building called Boa Constructor which is functional but not in the same class as the qt designer (this is my opinion, try it). As for pyGTK, it is used for Gnome. I am not to familiar with it but it looks like a good gui toolkit as well. So my advice is to try all three and see which one you like the best and go from there. Denis On Mon, Sep 6, 2010 at 6:15 AM, wissem belguidoum wrote: > On 6 sep, 09:54, Niklasro wrote: > > Hello > > Making a GUI, could you recommend tkinter or any other proposal? > > Thanks > > Hi, > > I am considering to learn Qt, which is a multi-platform widget > liberary and a RAD IDE..., > basically for C++ programing but there is a binding called PyQt for > python. > > Good luck. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ctops.legal at gmail.com Mon Sep 6 09:49:14 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Mon, 6 Sep 2010 06:49:14 -0700 (PDT) Subject: Python [repair_cycorder_mov.py] References: <4c83a283$0$28657$c3e8da3@news.astraweb.com> Message-ID: <7b9d1b08-26a8-45f8-b429-7bc57d74b17f@11g2000yqq.googlegroups.com> On Sep 5, 12:23?pm, Albert Hopkins wrote: > On Sun, 2010-09-05 at 14:00 +0000, Steven D'Aprano wrote: > > By the way, there's no need to send three messages in 10 minutes > > asking > > the same question, and adding FORM METHOD links to your post will > > probably just get it flagged as spam by many people. > > Apparently it has, as I only got this response. Yea I guess I need to get my Forte Agent out and dust it off. From ian at ianhobson.co.uk Mon Sep 6 10:29:44 2010 From: ian at ianhobson.co.uk (Ian Hobson) Date: Mon, 06 Sep 2010 15:29:44 +0100 Subject: redirecting stdout and stderr for a windows service Message-ID: <4C84FAD8.6000108@ianhobson.co.uk> Hi all, I am trying to redirect stdout and stderr on a python windows service, so that the service will not stall after 256 chars is written, and so I can use print for simple debugging. I have the following 4 lines (copy/pasted) in the source of my code. if __name__ == '__main__': sys.stdout = sys.stderr = open("d:\logfile.txt", "a") print "Starting up" win32serviceutil.HandleCommandLine(PythonService) When I run them as a free standing program, logfile.txt is created the text placed in it, and it crashed on the last line - no permissions to create a service. (Micro-cluless has no sudo command in Win7. :( ) When I start the code as a service, it does not create the log file does not put anything in it, but the last line is executed and the service starts! There are no Events on the event log. When I stop the service, it stops. Still no log file. Still no events. I tried running the service with my account and not the system user. This gave me "run as service" permissions, but did not alter the results. What is happening? And how can I set up logging so that the service can simply restart, leaving the trackback in the log file for me to come to later. All help gratefully received. I've lost most of my remaining hair today on this one. Ian From sajuptpm at gmail.com Mon Sep 6 10:54:23 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Mon, 6 Sep 2010 07:54:23 -0700 (PDT) Subject: list of tuples with dynamic change in position Message-ID: I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)), (('y','x'),(3,0))] some functions using this list and fetch data using index l[0][1], l[1] [1] I need to change position of each values in the list and that dont affect fuctions which are using this list. I must have to use list of tuples. Have any way to do it using list of tuples. From thomas at jollybox.de Mon Sep 6 10:58:39 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Mon, 6 Sep 2010 16:58:39 +0200 Subject: accessing a text file In-Reply-To: <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> Message-ID: <201009061658.39729.thomas@jollybox.de> On Monday 06 September 2010, it occurred to Baba to exclaim: > On 6 sep, 00:01, Benjamin Kaplan wrote: > > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > > > level: beginner > > > > > > how can i access the contents of a text file in Python? > > > > > > i would like to compare a string (word) with the content of a text > > > file (word_list). i want to see if word is in word_list. let's assume > > > the TXT file is stored in the same directory as the PY file. > > > > > > def is_valid_word(word, word_list) > > > > > > thanks > > > Baba > > > -- > > > > > >http://mail.python.org/mailman/listinfo/python-list > > > > Please do us a favor and at least try to figure things out on your > > own, rather than coming here every time you have a question. The very > > first result when you try searching "python read text file" is the > > section in the Python tutorial that explains how to do this. > > > > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > Hi Benjamin > > I did find that page prior to posting the question but i still wanted > to have a second opinion to complement that info so as to make things > easier The first line of my post clearly states that i am a beginner. > It's nice to provide links which can help answer the question but > please be so polite and keep personal comments for yourself. > That is of course perfectly legitimate. It would however have been polite to state that in the question. Show us that you're doing your homework, and not just using the list as a cheap path to having to think less yourself. Phrasing your post as "I would like to compare a ... I found the open() function here: [link]. Is this what I should use of is there any other/better way?" makes a completely different impression. Also, keeping personal comments to one's self is just not how it works. On a list like this especially, answers along the lines of "That's the way to do what you were asking for, but are you sure the question went into the right direction? Have you thought of [...]?" can often be very helpful. > > To all other respondants: thank you for your kind instructions and > directions. > From sajuptpm at gmail.com Mon Sep 6 11:09:44 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Mon, 6 Sep 2010 08:09:44 -0700 (PDT) Subject: list of tuples with dynamic change in position References: Message-ID: I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)), (('y','x'),(3,0))] and postion of values in the tuple change dynamicaly. I need a way to access correct value even if change in position. From eckhardt at satorlaser.com Mon Sep 6 11:15:55 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 06 Sep 2010 17:15:55 +0200 Subject: list of tuples with dynamic change in position References: Message-ID: sajuptpm wrote: > I need to change position of each values in the list and that dont > affect fuctions which are using this list. So you want to change the list's content but you don't want anyone to be able to detect the difference? That doesn't make sense. > I must have to use list of tuples. > Have any way to do it using list of tuples. Why don't you explain what you want to achieve instead of asking for a solution that doesn't make sense? Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From eckhardt at satorlaser.com Mon Sep 6 11:17:46 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 06 Sep 2010 17:17:46 +0200 Subject: redirecting stdout and stderr for a windows service References: Message-ID: Ian Hobson wrote: > sys.stdout = sys.stderr = open("d:\logfile.txt", "a") "\l" is probably not what you want. Consider using "\\l" or r"\l" instead. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From invalid at invalid.invalid Mon Sep 6 11:24:38 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 6 Sep 2010 15:24:38 +0000 (UTC) Subject: Embedded Systems development using Python References: Message-ID: On 2010-09-06, Stefan Behnel wrote: > VGNU Linux, 06.09.2010 13:02: >> Can Python be used for embedded systems development ? > > It can and has been. > > What kind of embedded system with what set of capabilities are you thinking > about? TV sets? Mobile phones? Smart dust? [The OP never showed up on my sever for some reason] If you google for "deeply embedded python", you'll find some raterh old links: http://tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy http://groups.google.com/group/python-on-a-chip/web/list-of-small-python-implementations http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html A few years ago I used Python on a prototype for a bicycle computer with GPS, four buttons, and a small LCD screen. It was more or less comparable to a PDA with Linux running on an 200MHz XScale with something like 16MB of flash and 32MB of SDRAM. IIRC, that project used OpenEmbedded, and all I had to do was build the Python package that's already there in OE. I don't remember if I was using PySDL or PyQt for the UI -- I remember experimenting with both on desktop hosts at the time. I don't think that product ever saw daylight. There was just now way they could have competed with Garmin. -- Grant From grflanagan at gmail.com Mon Sep 6 11:40:17 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 06 Sep 2010 16:40:17 +0100 Subject: list of tuples with dynamic change in position In-Reply-To: References: Message-ID: sajuptpm wrote: > I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)), > (('y','x'),(3,0))] and postion of values in the tuple change > dynamicaly. I need a way to access correct value even if change in > position. from itertools import starmap, izip, imap list(imap(dict, starmap(izip, d))) [{'a': 9, 's': 5}, {'u': 9, 'w': 2}] From augdawg09 at gmail.com Mon Sep 6 11:48:29 2010 From: augdawg09 at gmail.com (aug dawg) Date: Mon, 6 Sep 2010 11:48:29 -0400 Subject: Arguments from the command line Message-ID: I've seen Python programs that can be activated from the command line. For example: hg This displays a list of commands for the Mercurial revision control system. But another command is this: hg commit "This is a commit name" Mercurial is written in Python. I know that commit is a function that commits to a repo, but what command does the program use in order to get the commit name, like "This is a commit name" (This would make a commit with "This is a commit name" as the commit name) -------------- next part -------------- An HTML attachment was scrubbed... URL: From raoulbia at gmail.com Mon Sep 6 11:53:53 2010 From: raoulbia at gmail.com (Baba) Date: Mon, 6 Sep 2010 08:53:53 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> Message-ID: On 6 sep, 16:58, Thomas Jollans wrote: > On Monday 06 September 2010, it occurred to Baba to exclaim: > > > > > On 6 sep, 00:01, Benjamin Kaplan wrote: > > > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > > > > level: beginner > > > > > how can i access the contents of a text file in Python? > > > > > i would like to compare a string (word) with the content of a text > > > > file (word_list). i want to see if word is in word_list. let's assume > > > > the TXT file is stored in the same directory as the PY file. > > > > > def is_valid_word(word, word_list) > > > > > thanks > > > > Baba > > > > -- > > > > >http://mail.python.org/mailman/listinfo/python-list > > > > Please do us a favor and at least try to figure things out on your > > > own, rather than coming here every time you have a question. The very > > > first result when you try searching "python read text file" is the > > > section in the Python tutorial that explains how to do this. > > > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > > Hi Benjamin > > > I did find that page prior to posting the question but i still wanted > > to have a second opinion to complement that info so as to make things > > easier The first line of my post clearly states that i am a beginner. > > It's nice to provide links which can help answer the question but > > please be so polite and keep personal comments for yourself. > > That is of course perfectly legitimate. It would however have been polite to > state that in the question. Show us that you're doing your homework, and not > just using the list as a cheap path to having to think less yourself. > > Phrasing your post as "I would like to compare a ... I found the open() > function here: [link]. Is this what I should use of is there any other/better > way?" makes a completely different impression. > > Also, keeping personal comments to one's self is just not how it works. On a > list like this especially, answers along the lines of "That's the way to do > what you were asking for, but are you sure the question went into the right > direction? Have you thought of [...]?" can often be very helpful. > > > > > To all other respondants: thank you for your kind instructions and > > directions. > > Thanks Thomas. Look up some of my questions this group and read through them and come back to tell me if a) i use this forum to learn without making any efforts myself or b) i use this forum to get started using the expertise of more knowledgeable programmers while at the same time particiapting. Anyway having this discussion is beside the point. Any Expert out there who thinks we beginners are some dumb idiots who are too stupid to think for themselves and are lucky to have a bunch of geniuses like you to help, get lost or make yourself a cup of tea but please give me a break from teaching me lessons... There's lots of nice people out there who are being awsemome by dedicating a bit of their time to some of our easy questions and it is them that i wish to send a BIG thanks! Much appreciated. I have made some good progress since starting to learn Python and this group has been great help! tnx Raoul From hugo.yoshi at gmail.com Mon Sep 6 12:08:27 2010 From: hugo.yoshi at gmail.com (Hugo Arts) Date: Mon, 6 Sep 2010 18:08:27 +0200 Subject: [Tutor] Arguments from the command line In-Reply-To: References: Message-ID: On Mon, Sep 6, 2010 at 5:48 PM, aug dawg wrote: > I've seen Python programs that can be activated from the command line. For > example: > hg > > This displays a list of commands for the Mercurial revision control system. > But another command is this: > hg commit "This is a commit name" > Mercurial is written in Python. I know that commit is a function that > commits to a repo, but what command does the program use in order to get the > commit name, like "This is a commit name" (This would make a commit with > "This is a commit name" as the commit name) > sys.argv is a list of all arguments from the command line. However, you'll rarely deal with it directly, there's various modules that deal with handling arguments. I believe the current one is argparse: http://docs.python.org/library/argparse.html#module-argparse Hugo From breamoreboy at yahoo.co.uk Mon Sep 6 12:08:32 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Sep 2010 17:08:32 +0100 Subject: Arguments from the command line In-Reply-To: References: Message-ID: On 06/09/2010 16:48, aug dawg wrote: > I've seen Python programs that can be activated from the command line. For > example: > > hg > > This displays a list of commands for the Mercurial revision control system. > But another command is this: > > hg commit "This is a commit name" > > Mercurial is written in Python. I know that commit is a function that > commits to a repo, but what command does the program use in order to get the > commit name, like "This is a commit name" (This would make a commit with > "This is a commit name" as the commit name) > > See sys.argv at http://docs.python.org/library/sys.html Cheers. Mark Lawrence. From aahz at pythoncraft.com Mon Sep 6 12:14:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Sep 2010 09:14:01 -0700 Subject: Iterative vs. Recursive coding References: <71e72427-7604-4286-b119-08ba669e9240@f42g2000yqn.googlegroups.com> <4c6dcbc5$0$11111$c3e8da3@news.astraweb.com> <4c6e9de9$0$23142$426a74cc@news.free.fr> Message-ID: In article <4c6e9de9$0$23142$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: >Steven D'Aprano a ??crit : >> On Thu, 19 Aug 2010 22:00:16 +0000, Martin Gregorie wrote: >>> >>> Recursion can be quite a trick to get your mind round at first >> >> Really? Do people actually find the *concept* of recursion to be tricky? > >I onced worked in a shop (Win32 desktop / accouting applications mainly) >where I was the only guy that could actually understand recursion. FWIW, >I also was the only guy around that understood "hairy" (lol) concepts >like callback functions, FSM, polymorphism, hashtables, linked lists, >ADTs, algorithm complexity etc... To some extent, the question here is the definition of "understand" being used. It probably would be reasonable to say that I have only a cookbook level understanding of recursion, and the same would apply to callback functions, FSM, linked lists, and so on. (I mostly think I do really understand polymorphism and hashtables.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From debatem1 at gmail.com Mon Sep 6 12:14:41 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 6 Sep 2010 09:14:41 -0700 Subject: accessing a text file In-Reply-To: References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> Message-ID: On Mon, Sep 6, 2010 at 8:53 AM, Baba wrote: > On 6 sep, 16:58, Thomas Jollans wrote: >> On Monday 06 September 2010, it occurred to Baba to exclaim: >> >> >> >> > On 6 sep, 00:01, Benjamin Kaplan wrote: >> > > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: >> > > > level: beginner >> >> > > > how can i access the contents of a text file in Python? >> >> > > > i would like to compare a string (word) with the content of a text >> > > > file (word_list). i want to see if word is in word_list. let's assume >> > > > the TXT file is stored in the same directory as the PY file. >> >> > > > def is_valid_word(word, word_list) >> >> > > > thanks >> > > > Baba >> > > > -- >> >> > > >http://mail.python.org/mailman/listinfo/python-list >> >> > > Please do us a favor and at least try to figure things out on your >> > > own, rather than coming here every time you have a question. The very >> > > first result when you try searching "python read text file" is the >> > > section in the Python tutorial that explains how to do this. >> >> > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >> >> > Hi Benjamin >> >> > I did find that page prior to posting the question but i still wanted >> > to have a second opinion to complement that info so as to make things >> > easier The first line of my post clearly states that i am a beginner. >> > It's nice to provide links which can help answer the question but >> > please be so polite and keep personal comments for yourself. >> >> That is of course perfectly legitimate. It would however have been polite to >> state that in the question. Show us that you're doing your homework, and not >> just using the list as a cheap path to having to think less yourself. >> >> Phrasing your post as "I would like to compare a ... I found the open() >> function here: [link]. Is this what I should use of is there any other/better >> way?" makes a completely different impression. >> >> Also, keeping personal comments to one's self is just not how it works. On a >> list like this especially, answers along the lines of "That's the way to do >> what you were asking for, but are you sure the question went into the right >> direction? Have you thought of [...]?" can often be very helpful. >> >> >> >> > To all other respondants: thank you for your kind instructions and >> > directions. >> >> > > Thanks Thomas. Look up some of my questions ?this group and read > through them and come back to tell me if a) i use this forum to learn > without making any efforts myself Just a quick point- when you ask someone for help, it's considered impolite to tell them what to do. I'd also point out that you gave no indication that you'd worked on this at all before posting it. In that regard, Thomas's concern seems completely justified to me. > or b) i use this forum to get > started using the expertise of more knowledgeable programmers while at > the same time particiapting. Again, Thomas's concern seems justified to me. Things would probably go more smoothly if you gave a better indication of what you had done so far on the problem in the future. > Anyway having this discussion is beside > the point. Any Expert out there who thinks we beginners are some dumb > idiots who are too stupid to think for themselves and are lucky to > have a bunch of geniuses like you to help, get lost or make yourself a > cup of tea but please give me a break from teaching me lessons... I don't think all beginners are idiots, or even most of them- but this isn't the right attitude to be taking. Both Thomas and myself thought that this was inappropriate enough to mention it, and if two people spoke up you can bet a lot more were thinking it quietly. My suggestion would be to moderate your approach and demonstrate what you've done so far (if only to increase the signal-to-noise ratio as your problems become more challenging) when posting. I'd also refrain from telling people to get lost; it doesn't make people happy to help you, you know? Geremy Condra From aahz at pythoncraft.com Mon Sep 6 12:17:32 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Sep 2010 09:17:32 -0700 Subject: Iterative vs. Recursive coding References: <71e72427-7604-4286-b119-08ba669e9240@f42g2000yqn.googlegroups.com> <4c6f966e$0$28653$c3e8da3@news.astraweb.com> <4c70344a$0$1659$742ec2ed@news.sonic.net> Message-ID: In article <4c70344a$0$1659$742ec2ed at news.sonic.net>, John Nagle wrote: > > Realistically, recursion isn't that important in Python. It's >there if you need it, and sometimes useful, but generally not used >much without good reason. In some functional languages, recursion >is routinely used in place of iteration, but Python isn't built for >that. In Python, most of the use cases for trivial recursion >are better handled with iteration or generators. Depends how you define "important". It's certainly a critical feature for Python that you *can* use recursion; it's usually the simplest way of walking a tree structure (such as a directory tree). Python would be an extraordinarily limited language if recursion were not available. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From bgailer at gmail.com Mon Sep 6 12:20:12 2010 From: bgailer at gmail.com (bob gailer) Date: Mon, 06 Sep 2010 12:20:12 -0400 Subject: [Tutor] Arguments from the command line In-Reply-To: References: Message-ID: <4C8514BC.7080106@gmail.com> On 9/6/2010 11:48 AM, aug dawg wrote: > I've seen Python programs that can be activated from the command line. > For example: > > hg > > This displays a list of commands for the Mercurial revision control > system. But another command is this: > > hg commit "This is a commit name" > > Mercurial is written in Python. I know that commit is a function that > commits to a repo, but what command does the program use in order to > get the commit name, like "This is a commit name" (This would make a > commit with "This is a commit name" as the commit name) hg.py: import sys print sys.argv $hg commit "This is a commit name" ['C:\\hg.py', 'commit', 'This is a commit name'] -- Bob Gailer 919-636-4239 Chapel Hill NC From raoulbia at gmail.com Mon Sep 6 12:29:15 2010 From: raoulbia at gmail.com (Baba) Date: Mon, 6 Sep 2010 09:29:15 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> Message-ID: <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> On 6 sep, 18:14, geremy condra wrote: > On Mon, Sep 6, 2010 at 8:53 AM, Baba wrote: > > On 6 sep, 16:58, Thomas Jollans wrote: > >> On Monday 06 September 2010, it occurred to Baba to exclaim: > > >> > On 6 sep, 00:01, Benjamin Kaplan wrote: > >> > > On Sun, Sep 5, 2010 at 5:47 PM, Baba wrote: > >> > > > level: beginner > > >> > > > how can i access the contents of a text file in Python? > > >> > > > i would like to compare a string (word) with the content of a text > >> > > > file (word_list). i want to see if word is in word_list. let's assume > >> > > > the TXT file is stored in the same directory as the PY file. > > >> > > > def is_valid_word(word, word_list) > > >> > > > thanks > >> > > > Baba > >> > > > -- > > >> > > >http://mail.python.org/mailman/listinfo/python-list > > >> > > Please do us a favor and at least try to figure things out on your > >> > > own, rather than coming here every time you have a question. The very > >> > > first result when you try searching "python read text file" is the > >> > > section in the Python tutorial that explains how to do this. > > >> > >http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > >> > Hi Benjamin > > >> > I did find that page prior to posting the question but i still wanted > >> > to have a second opinion to complement that info so as to make things > >> > easier The first line of my post clearly states that i am a beginner. > >> > It's nice to provide links which can help answer the question but > >> > please be so polite and keep personal comments for yourself. > > >> That is of course perfectly legitimate. It would however have been polite to > >> state that in the question. Show us that you're doing your homework, and not > >> just using the list as a cheap path to having to think less yourself. > > >> Phrasing your post as "I would like to compare a ... I found the open() > >> function here: [link]. Is this what I should use of is there any other/better > >> way?" makes a completely different impression. > > >> Also, keeping personal comments to one's self is just not how it works. On a > >> list like this especially, answers along the lines of "That's the way to do > >> what you were asking for, but are you sure the question went into the right > >> direction? Have you thought of [...]?" can often be very helpful. > > >> > To all other respondants: thank you for your kind instructions and > >> > directions. > > > Thanks Thomas. Look up some of my questions ?this group and read > > through them and come back to tell me if a) i use this forum to learn > > without making any efforts myself > > Just a quick point- when you ask someone for help, it's considered > impolite to tell them what to do. > > I'd also point out that you gave no indication that you'd worked on > this at all before posting it. In that regard, Thomas's concern seems > completely justified to me. > > > or b) i use this forum to get > > started using the expertise of more knowledgeable programmers while at > > the same time particiapting. > > Again, Thomas's concern seems justified to me. Things would probably > go more smoothly if you gave a better indication of what you had done > so far on the problem in the future. > > > Anyway having this discussion is beside > > the point. Any Expert out there who thinks we beginners are some dumb > > idiots who are too stupid to think for themselves and are lucky to > > have a bunch of geniuses like you to help, get lost or make yourself a > > cup of tea but please give me a break from teaching me lessons... > > I don't think all beginners are idiots, or even most of them- but this > isn't the right attitude to be taking. Both Thomas and myself thought > that this was inappropriate enough to mention it, and if two people > spoke up you can bet a lot more were thinking it quietly. My > suggestion would be to moderate your approach and demonstrate what > you've done so far (if only to increase the signal-to-noise ratio as > your problems become more challenging) when posting. I'd also refrain > from telling people to get lost; it doesn't make people happy to help > you, you know? > > Geremy Condra Thanks Jeremy, i will take your advice on board! Noone likes to be taught lessons i think so it is only normal that i reacted. If i had received a friendly response from Benjamin (as opposed to "Please do us a favor and at least try to figure things out on your own") making me aware of the etiquette that my post should also show that i have researched my question somehow and if his tone would have been mannered then we would not be having this discussion now. Ok now i need to go back to actual Pythoon learning, i'm getting distracted. Kind regards, Baba From user at example.net Mon Sep 6 12:31:20 2010 From: user at example.net (J.O. Aho) Date: Mon, 06 Sep 2010 18:31:20 +0200 Subject: GUibuilder evaluation In-Reply-To: References: Message-ID: <8ekjapFu3oU2@mid.individual.net> Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? QT Designer from Nokia, I can run my GUI programs both on my desktop and on my cellphone without modifications. -- //Aho From sal_lopez at me.com Mon Sep 6 12:55:03 2010 From: sal_lopez at me.com (Sal Lopez) Date: Mon, 06 Sep 2010 09:55:03 -0700 Subject: using modules Message-ID: The following code runs OK under 3.1: @filename=cats_and_dogs.py #!/usr/bin/python def make_sound(animal): print(animal + ' says ' + sounds[animal]) sounds = { "cat": "meow", "dog": "woof" } for i in sounds.keys(): make_sound(i) # output: # dog says woof # cat says meow When I move the def to it's own file to create a module, it barfs: @filename= cats_and_dogs.py #!/usr/bin/python import defs sounds = { "cat": "meow", "dog": "woof" } for i in sounds.keys(): defs.make_sound(i) @filename=defs.py def make_sound(animal): print(animal + ' says ' + sounds[animal]) Traceback (most recent call last): File "./cats_and_dogs.py", line 11, in defs.make_sound(i) File "defs.py", line 4, in make_sound print(animal + ' says ' + sounds[animal]) NameError: global name 'sounds' is not defined I thought that importing the function(s) made them local to the main program? Any assistance is appreciated. From tinnews at isbd.co.uk Mon Sep 6 13:18:34 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Mon, 6 Sep 2010 18:18:34 +0100 Subject: filecmp.cmp() doesn't seem to do what it says in the documentation Message-ID: I'm using filecmp.cmp() to compare some files (surprise!). The documentation says:- Unless shallow is given and is false, files with identical os.stat() signatures are taken to be equal. I'm not setting shallow explicitly so it's True, thus the function should be comparing the os.stat() results. However this doesn't seem to be the case as even if I touch one of the files to change it's access/modification date filecmp.cmp() still returns True. Here is an example:- chris$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import filecmp >>> print filecmp.cmp("/media/disk/DCIM/103_FUJI/DSCF3084.JPG", "/home/chris/pictures/2010/4/24dscf3084.jpg") True >>> chris$ ls -l /media/disk/DCIM/103_FUJI/DSCF3084.JPG /home/chris/pictures/2010/4/24dscf3084.jpg -rwxr-xr-x 1 chris chris 1783277 2010-09-06 17:36 /home/chris/pictures/2010/4/24dscf3084.jpg -rwxr-xr-x 1 chris root 1783277 2010-09-06 17:53 /media/disk/DCIM/103_FUJI/DSCF3084.JPG chris$ The file modification times are different, surely filecmp.cmp() should be returning false. I actually think the way it's working makes more sense as I don't care if the modification time has changed if the files are exactly the same length still. -- Chris Green From python at mrabarnett.plus.com Mon Sep 6 13:24:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Sep 2010 18:24:23 +0100 Subject: [RELEASED] Python 3.2 alpha 2 In-Reply-To: <4C84A4B9.2040406@python.org> References: <4C84A4B9.2040406@python.org> Message-ID: <4C8523C7.5090309@mrabarnett.plus.com> On 06/09/2010 09:22, Georg Brandl wrote: [snip] > 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/ > I did notice the spelling mistake "dynmaic" at: http://docs.python.org/dev/whatsnew/3.2.html From alan.gauld at btinternet.com Mon Sep 6 13:45:04 2010 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 6 Sep 2010 18:45:04 +0100 Subject: Arguments from the command line References: Message-ID: "aug dawg" wrote > Mercurial is written in Python. I know that commit is a function > that > commits to a repo, but what command does the program use in order to > get the > commit name, like "This is a commit name" (This would make a commit > with > "This is a commit name" as the commit name) Take a look at the Talking to the User topic in my tutorial which has a section on reading command line arguments. Interestingly, most of the queries I get on that section are from GUI users who don't understand the concept of command line arguments! :-) -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ From cmpython at gmail.com Mon Sep 6 13:52:02 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Sep 2010 10:52:02 -0700 (PDT) Subject: GUibuilder evaluation References: Message-ID: On Sep 6, 3:54?am, Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? > Thanks Your message referred to a GUI *builder*, whereas tkinter is a GUI *toolkit* (that is, a collection of widgets). A builder is an application that allows you to make GUI apps more I assume you want to choose a GUI toolkit. If you search the archive of this list or Google generally (like "GUI toolkits Python") you will have many minutes of reading material for you to check out. From chardster at gmail.com Mon Sep 6 14:17:34 2010 From: chardster at gmail.com (Richard Thomas) Date: Mon, 6 Sep 2010 11:17:34 -0700 (PDT) Subject: using modules References: Message-ID: On Sep 6, 5:55?pm, Sal Lopez wrote: > The following code runs OK under 3.1: > > @filename=cats_and_dogs.py > > #!/usr/bin/python > > def make_sound(animal): > ? ? print(animal + ' says ' + sounds[animal]) > > sounds = { "cat": "meow", "dog": "woof" } > > for i in sounds.keys(): > ? ? make_sound(i) > > # output: > # dog says woof > # cat says meow > > When I move the def to it's own file to create a module, it barfs: > > @filename= cats_and_dogs.py > #!/usr/bin/python > > import defs > > sounds = { "cat": "meow", "dog": "woof" } > > for i in sounds.keys(): > ? ? defs.make_sound(i) > > @filename=defs.py > def make_sound(animal): > ? ? print(animal + ' says ' + sounds[animal]) > > Traceback (most recent call last): > File "./cats_and_dogs.py", line 11, in > defs.make_sound(i) > File "defs.py", line 4, in make_sound > print(animal + ' says ' + sounds[animal]) > NameError: global name 'sounds' is not defined > > I thought that importing the function(s) made them local to the main program? Any assistance is appreciated. ? ? ? ? ? ? ? The make_sound function has two scopes in which to resolve the name 'sounds' the first is its local scope i.e. the scope of things defined in the function itself but that just contains 'animal'. The second is its global scope which is another name for its module's namespace. In this case that's the namespace of the 'defs' module. The namespace of the main module (the module that you ran), is separate. You could do this: import defs defs.sounds = {'cat': 'meow', ... } Or even: #defs.py sounds = {} #main.py import defs defs.sounds.update({'cat': 'meow', ... }) Regards, Richard. From tjreedy at udel.edu Mon Sep 6 14:27:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Sep 2010 14:27:25 -0400 Subject: filecmp.cmp() doesn't seem to do what it says in the documentation In-Reply-To: References: Message-ID: On 9/6/2010 1:18 PM, tinnews at isbd.co.uk wrote: > I'm using filecmp.cmp() to compare some files (surprise!). > > The documentation says:- > Unless shallow is given and is false, files with identical > os.stat() signatures are taken to be equal. Reword and read carefully: if shallow == True and signatures are identical, then files are taken to be equal. Here is the corresponding code from Lib/filecmp.py: if shallow and s1 == s2: return True Does not say the result for non-identical signatures ;-). > I'm not setting shallow explicitly so it's True, thus the function > should be comparing the os.stat() results. However this doesn't seem > to be the case as even if I touch one of the files to change it's > access/modification date filecmp.cmp() still returns True. Because it goes on to actually compare the files, and they are equal. ... result = _cache.get((f1, f2)) if result and (s1, s2) == result[:2]: return result[2] outcome = _do_cmp(f1, f2) _cache[f1, f2] = s1, s2, outcome return outcome Most of the stdlib files in Python are quite readable. I recommend it when you have questions. -- Terry Jan Reedy From no.email at nospam.invalid Mon Sep 6 14:31:11 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 06 Sep 2010 11:31:11 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <4c82b097$0$1661$742ec2ed@news.sonic.net> <4c83295b$0$1665$742ec2ed@news.sonic.net> <7xd3ssbs4o.fsf@ruckus.brouhaha.com> <4c83dfed$0$1662$742ec2ed@news.sonic.net> Message-ID: <7xk4myd8r4.fsf@ruckus.brouhaha.com> John Nagle writes: > I've argued for an approach in which only synchronized or immutable > objects can be shared between threads. Then, only synchronized objects > have refcounts. See > "http://www.animats.com/papers/languages/pythonconcurrency.html" I'm going to have to read this carefully, but my first reaction is that doing it right would take substantial changes to the language, to the point where it wouldn't really be Python any more. More generally, if you want to program in Erlang, why not use Erlang for that? > I can't think of a time when I've really had to use a finalizer for > something with dynamic extent. They've always seemed like a code > smell to me. The problem appears when you have an object that owns something, like a window or a database connection. "With" is single-level. But expecting such an object to be gc'd seems like a code smell in its own right. I once implemented something like that in a Lisp system, and it was just disconcerting as hell to see windows on the screen blink out of existence unpredictably. The issue is maybe your function returns and you expect the window to vanish, but something somewhere has saved another temporary reference to it so it doesn't go away til later. If you want something with external semantics (like a window or file handle) to be released at a particular time, the program should do that explicitly. Don't use a finalizer that you expect storage reclamation to invoke. There is just too little control in a Python program over the creation of references. From egrefen at gmail.com Mon Sep 6 15:01:27 2010 From: egrefen at gmail.com (Edward Grefenstette) Date: Mon, 6 Sep 2010 12:01:27 -0700 (PDT) Subject: Database problems Message-ID: <869189cf-7439-43ce-9bf1-fb1f4cbf0c5f@n3g2000yqb.googlegroups.com> Dear Pythonistas, For a project I'm working on, I need to store fairly large dictionaries (several million keys) in some form (obviously not in memory). The obvious course of action was to use a database of some sort. The operation is pretty simple, a function is handed a generator that gives it keys and values, and it maps the keys to the values in a non- relational database (simples!). I wrote some code implementing this using anydbm (which used dbhash on my system), and it worked fine for about a million entries, but then crashed raising a DBPageNotFoundError. I did a little digging around and couldn't figure out what was causing this or how to fix it. I then quickly swapped anydbm for good ol' fashioned dbm which uses gdbm, and it ran even faster a little longer, but after a million entries or so it raised the ever-so-unhelpful "gdbm fatal: write error". I then threw caution to the winds and tried simply using cPickle's dump in the hope of obtaining some data persistence, but it crashed fairly early with a "IOError: [Errno 122] Disk quota exceeded". Now the question is: is it something wrong with these dbms? Can they not deal with very large sets of data? If not, is there a more optimal tool for my needs? Or is the problem unrelated and has something to do with my lab computer? Best, Edward From tjreedy at udel.edu Mon Sep 6 15:08:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Sep 2010 15:08:05 -0400 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 9/6/2010 7:20 AM, Stefan Behnel wrote: > BartC, 06.09.2010 12:38: >> (3) Since the loop variable is never used, why not have a special loop >> statement that repeats code so many times? There sort-of is, just slightly more general. > Because special cases are not special enough to break the rules. As > others have stated before, you can use itertools to reduce that part of > the looping overhead, if it really hurts your concrete code. I ran the following test: >>> from itertools import repeat >>> n = 10**8 >>> for dummy in repeat(None,n): pass # 7 sec >>> for dummy in range(n): pass # 11 sec Times are for my older machine, subjectively counted. The difference is subjectively clear. Both functions count in C. I presume the difference is the cost of creating and deleting unneeded Python int objects. This difference is the reason the timeit module uses itertools.repeat for the inner loop that repeats the code to be timed. -- Terry Jan Reedy From benjamin.kaplan at case.edu Mon Sep 6 15:12:53 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 6 Sep 2010 15:12:53 -0400 Subject: Database problems In-Reply-To: <869189cf-7439-43ce-9bf1-fb1f4cbf0c5f@n3g2000yqb.googlegroups.com> References: <869189cf-7439-43ce-9bf1-fb1f4cbf0c5f@n3g2000yqb.googlegroups.com> Message-ID: On Mon, Sep 6, 2010 at 3:01 PM, Edward Grefenstette wrote: > Dear Pythonistas, > > For a project I'm working on, I need to store fairly large > dictionaries (several million keys) in some form (obviously not in > memory). The obvious course of action was to use a database of some > sort. > > The operation is pretty simple, a function is handed a generator that > gives it keys and values, and it maps the keys to the values in a non- > relational database (simples!). > > I wrote some code implementing this using anydbm (which used dbhash on > my system), and it worked fine for about a million entries, but then > crashed raising a DBPageNotFoundError. I did a little digging around > and couldn't figure out what was causing this or how to fix it. > > I then quickly swapped anydbm for good ol' fashioned dbm which uses > gdbm, and it ran even faster a little longer, but after a million > entries or so it raised the ever-so-unhelpful "gdbm fatal: write > error". > > I then threw caution to the winds and tried simply using cPickle's > dump in the hope of obtaining some data persistence, but it crashed > fairly early with a "IOError: [Errno 122] Disk quota exceeded". > > Now the question is: is it something wrong with these dbms? Can they > not deal with very large sets of data? If not, is there a more optimal > tool for my needs? Or is the problem unrelated and has something to do > with my lab computer? > > Best, > Edward > -- Just as a guess, I'd say that you have a disk quota that you're hitting with your several million key dbm. You might want to talk to the lab administrator about raising the quota. From cmpython at gmail.com Mon Sep 6 15:15:58 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Sep 2010 12:15:58 -0700 (PDT) Subject: GUibuilder evaluation References: Message-ID: <2963f85b-3bbf-46e5-9eee-758ee71a4f21@l6g2000yqb.googlegroups.com> On Sep 6, 3:54?am, Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? > Thanks Your message referred to a GUI *builder*, whereas tkinter is a GUI *toolkit* (that is, a collection of widgets). A builder is an application that allows one to make GUI apps more I assume you want to choose a GUI toolkit. If you search the archive of this list or Google generally (like "GUI toolkits Python") you will have many minutes of reading material for you to check out. From usernet at ilthio.net Mon Sep 6 15:16:18 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 6 Sep 2010 19:16:18 +0000 (UTC) Subject: Database problems References: <869189cf-7439-43ce-9bf1-fb1f4cbf0c5f@n3g2000yqb.googlegroups.com> Message-ID: On 2010-09-06, Edward Grefenstette wrote: > I then threw caution to the winds and tried simply using cPickle's > dump in the hope of obtaining some data persistence, but it crashed > fairly early with a "IOError: [Errno 122] Disk quota exceeded". The error is telling you that you have attempted to write the file; but, in the process you exceeded your disk quota (the space you are allowed to use) and the operating system would not permit you to finish the file. > Now the question is: is it something wrong with these dbms? Can they > not deal with very large sets of data? If not, is there a more optimal > tool for my needs? Or is the problem unrelated and has something to do > with my lab computer? The problem is that you are attempting to use more disk space then you are permitted to use on your account (at least for the selected filesystem). Possible solutions are to save the data somewhere else where you have a greater quota, delete some other files from your account to make room for the new file, or talk to whoever administrates the systems and see if they will add enough space to your quota to permit you to write this large file. From cmpython at gmail.com Mon Sep 6 15:18:05 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Sep 2010 12:18:05 -0700 (PDT) Subject: GUibuilder evaluation References: Message-ID: On Sep 6, 3:54?am, Niklasro wrote: > Hello > Making a GUI, could you recommend tkinter or any other proposal? > Thanks Your message referred to a GUI *builder*, whereas tkinter is a GUI *toolkit* (that is, a collection of widgets). A GUI builder is an application that allows one to make GUI apps more easily. I assume you mean a GUI toolkit. If you search the archive of this list or Google generally (like "GUI toolkits Python") you will have many minutes of reading material for you to evaluate which toolkit you'd like to try. From tjreedy at udel.edu Mon Sep 6 15:21:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Sep 2010 15:21:55 -0400 Subject: using modules In-Reply-To: References: Message-ID: On 9/6/2010 12:55 PM, Sal Lopez wrote: > The following code runs OK under 3.1: > > @filename=cats_and_dogs.py > > #!/usr/bin/python > > def make_sound(animal): > print(animal + ' says ' + sounds[animal]) > > sounds = { "cat": "meow", "dog": "woof" } > > for i in sounds.keys(): > make_sound(i) > > # output: > # dog says woof > # cat says meow > > When I move the def to it's own file to create a module, it barfs: > > @filename= cats_and_dogs.py > #!/usr/bin/python > > import defs > > sounds = { "cat": "meow", "dog": "woof" } > > for i in sounds.keys(): > defs.make_sound(i) > > @filename=defs.py > def make_sound(animal): > print(animal + ' says ' + sounds[animal]) > > Traceback (most recent call last): > File "./cats_and_dogs.py", line 11, in > defs.make_sound(i) > File "defs.py", line 4, in make_sound > print(animal + ' says ' + sounds[animal]) > NameError: global name 'sounds' is not defined > > > I thought that importing the function(s) made them local to the main program? Any assistance is appreciated. Python code execute within the context of the builtin namespace, a module namespace (misleadingly called 'globals'), a local namespace (the same as the module namespace for top-level code), and for nested functions, intermediate namespaces. "import defs" binds the name 'defs' to the module object. Code in the defs module still executes within the defs context where it is defined. This is lexical name resolution. The same is still true if you import the function with "from defs import make_sound". What you were expecting is dynamic name resolution, where names are resolved within the calling context rather than the definition context. I believe this is dynamic scoping. This has been tried in other languages. For more, try https://secure.wikimedia.org/wikipedia/en/wiki/Dynamic_scoping -- Terry Jan Reedy From tinnews at isbd.co.uk Mon Sep 6 16:11:18 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Mon, 6 Sep 2010 21:11:18 +0100 Subject: filecmp.cmp() doesn't seem to do what it says in the documentation References: Message-ID: <6gufl7-c9g.ln1@chris.zbmc.eu> Terry Reedy wrote: > On 9/6/2010 1:18 PM, tinnews at isbd.co.uk wrote: > > I'm using filecmp.cmp() to compare some files (surprise!). > > > > The documentation says:- > > Unless shallow is given and is false, files with identical > > os.stat() signatures are taken to be equal. > > Reword and read carefully: if shallow == True and signatures are > identical, then files are taken to be equal. > > Here is the corresponding code from Lib/filecmp.py: > if shallow and s1 == s2: > return True > > Does not say the result for non-identical signatures ;-). > > > I'm not setting shallow explicitly so it's True, thus the function > > should be comparing the os.stat() results. However this doesn't seem > > to be the case as even if I touch one of the files to change it's > > access/modification date filecmp.cmp() still returns True. > > Because it goes on to actually compare the files, and they are equal. > > ... > result = _cache.get((f1, f2)) > if result and (s1, s2) == result[:2]: > return result[2] > outcome = _do_cmp(f1, f2) > _cache[f1, f2] = s1, s2, outcome > return outcome > > Most of the stdlib files in Python are quite readable. I recommend it > when you have questions. > Well I still don't think it's what the documentation says, it would be much better if it told you that 'if the os.stat() signatures are not identical then the file contents are actually compared'. The implication to me when I read the documentation was that if shallow was True and the os.stat() signatures were not identical then False would be returned. Where does it say otehrwise? -- Chris Green From kyosohma at gmail.com Mon Sep 6 16:16:58 2010 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 6 Sep 2010 13:16:58 -0700 (PDT) Subject: The PSF Blog Gets a Transfusion! Message-ID: The Python Software Foundation?s Blog staff has been recently expanded by a new set of top-notch bloggers to bring you the latest in PSF news, ranging from the scintillating projects that the PSF has its fingers in to the mundane, but necessary board minutes. Don?t despair if you hate reading blogs! The blog also has a handy RSS feed and a mailing list! You can take your pick of these delivery methods by visiting the blog, at http://pyfound.blogspot.com/ From hobson42 at gmaiil.com Mon Sep 6 17:33:50 2010 From: hobson42 at gmaiil.com (Ian) Date: Mon, 06 Sep 2010 22:33:50 +0100 Subject: redirecting stdout and stderr for a windows service In-Reply-To: <4C84FAD8.6000108@ianhobson.co.uk> References: <4C84FAD8.6000108@ianhobson.co.uk> Message-ID: <4C855E3E.9090109@gmaiil.com> On 06/09/2010 15:29, Ian Hobson wrote: > Hi all, > Forget this. The problem is that it is a Windows Service, so it is not initialised in the normal way. PythonService.exe loads other code (named __main__) that loads the service proper, so the if test was never true! Regards Ian From shahama23 at hotmail.com Mon Sep 6 17:42:23 2010 From: shahama23 at hotmail.com (shahama23) Date: Mon, 6 Sep 2010 14:42:23 -0700 (PDT) Subject: YOU MUST KNOW THIS MAN Message-ID: <3ac1efd3-febe-4e48-ab97-fcf2593776f2@b34g2000yqm.googlegroups.com> In The Name Of Allaah, Most Gracious, Most Merciful YOU MUST KNOW THIS MAN MUHAMMAD (May peace and blessings of God Almighty be upon him) You may be an atheist or an agnostic; or you may belong to anyone of the religious denominations that exist in the world today. You may be a Communist or a believer in democracy and freedom. No matter what you are, and no matter what your religious and political beliefs, personal and social habits happen to be - YOU MUST STILL KNOW THIS MAN! He was by far the most remarkable man that ever set foot on this earth. He preached a religion, founded a state, built a nation, laid down a moral code, initiated numberless social and political reforms, established a dynamic and powerful society to practice and represent his teachings, and completely revolutionized the worlds of human thought and action for all times to come. HIS NAME IS MUHAMMAD, peace and blessings of Almighty God be upon him and he accomplished all these wonders in the unbelievably short span of twenty-three years. Muhammad, peace and blessings of God Almighty be upon him was born in Arabia on the 20th of August, in the year 570 of the Christian era, and when he died after 63 years, the whole of the Arabian Peninsula had changed from paganism and idol-worship to the worship of One God; from tribal quarrels and wars to national solidarity and cohesion; from drunkenness and debauchery to sobriety and piety; from lawlessness and anarchy to disciplined living; from utter moral bankruptcy to the highest standards of moral excellence. Human history has never known such a complete transformation of a people or a place before or since! The Encyclopedia Britannica calls him "the most successful of all religious personalities of the world". Bernard Shaw said about him that if Muhammad were alive today he would succeed in solving all those problems which threaten to destroy human civilization in our times. Thomas Carlysle was simply amazed as to how one man, single- handedly, could weld warring tribes and wandering Bedouins into a most powerful and civilized nation in less than two decades. Napoleon and Gandhi never tired of dreaming of a society along the lines established by this man in Arabia fourteen centuries ago. Indeed no other human being ever accomplished so much, in such diverse fields of human thought and behavior, in so limited a space of time, as did Muhammad, peace and blessings of God Almighty be upon him. He was a religious teacher, a social reformer, a moral guide, a political thinker, a military genius, an administrative colossus, a faithful friend, a wonderful companion, a devoted husband, a loving father - all in one. No other man in history ever excelled or equaled him in any of these difficult departments of life. The world has had its share of great personalities. But these were one sided figures who distinguished themselves in but one or two fields such as religious thought or military leadership. None of the other great leaders of the world ever combined in himself so many different qualities to such an amazing level of perfection as did Muhammad, peace and blessings of God Almighty be upon him. The lives and teachings of other great personalities of the world are shrouded in the mist of time. There is so much speculation about the time and the place of their birth, the mode and style of their life, the nature and detail of their teachings and the degree and measure of their success or failure that it is impossible for humanity today to reconstruct accurately and precisely the lives and teachings of those men. Not so this man Muhammad, peace and blessings of God Almighty be upon him. Not only was he born in the fullest blaze of recorded history, but every detail of his private and public life, of his actions and utterances, has been accurately documented and faithfully preserved to our day. The authenticity of the information so preserved is vouched for not only by faithful followers but also by unbiased critics and open-minded scholars. At the level of ideas there is no system of thought and belief-secular or religious, social or political-which could surpass or equal ISLAAM- the system which Muhammad peace and blessings of God Almighty be upon him propounded. In a fast changing world, while other systems have undergone profound transformations, Islaam alone has remained above all change and mutation, and retained its original form for the past 1400 years. What is more, the positive changes that are taking place in the world of human thought and behavior, truly and consistently reflect the healthy influence of Islam in these areas. Further, it is not given to the best of thinkers to put their ideas completely into practice, and to see the seeds of their labors grow and bear fruit, in their own lifetime. Except of course, Muhammad, peace and blessings of God Almighty be upon him, who not only preached the most wonderful ideas but also successfully translated each one of them into practice in his own lifetime. At the time of his death his teachings were not mere precepts and ideas straining for fulfillment, but had become the very core of the life of tens of thousands of perfectly trained individuals, each one of whom was a marvelous personification of everything that Muhammad peace and blessings of God Almighty be upon him taught and stood for. At what other time or place and in relation to what other political, social, religious system, philosophy or ideology-did the world ever witness such a perfectly amazing phenomenon? Indeed no other system or ideology secular or religious, social or political, ancient or modern - could ever claim the distinction of having been put into practice in its fullness and entirety EVEN ONCE in this world, either before or after the death of its founder. Except of course ISLAAM, the ideology preached by Muhammad, peace and blessings of God Almighty be upon him which was established as a complete way of life by the teacher himself, before he departed from this world. History bears testimony to this fact and the greatest skeptics have no option but to concede this point. In spite of these amazing achievements and in spite of the countless absolutely convincing and authentic miracles performed by him and the phenomenal success which crowned his efforts, he did not for a moment claim to be God or God's incarnation or Son - but only a human being who was chosen and ordained by God to be a teacher of truth to man kind and a complete model and pattern for their actions. He was nothing more or less than a human being. But he was a man with a noble and exalted mission-and his unique mission was to unite humanity on the worship of ONE AND ONLY GOD and to teach them the way to honest and upright living in accordance with the laws and commands of God. He always described himself as A MESSENGER AND SERVANT OF GOD, and so indeed every single action and movement of his proclaimed him to be. A world which has not hesitated to raise to Divinity individuals whose very lives and missions have been lost in legend and who historically speaking did not accomplish half as much-or even one tenth-as was accomplished by Muhammad, peace and blessings of God Almighty be upon him should stop to take serious note of this remarkable man's claim to be God's messenger to mankind. Today after the lapse of some 1400 years the life and teachings of Prophet Muhammad, peace and blessings of God Almighty be upon him, have survived without the slightest loss, alteration or interpolation. Today they offer the same undying hope for treating mankind's many ills which they did when Prophet Muhammad, peace and blessings of God Almighty be upon him, was alive. This is our honest claim and this is the inescapable conclusion forced upon us by a critical and unbiased study of history. The least YOU should do as a thinking, sensitive, concerned human being is to stop for one brief moment and ask yourself: Could it be that these statements, extraordinary and revolutionary as they sound, are really true? Supposing they really are true, and you did not know this man Muhammad, peace and blessings of God Almighty be upon him or hear about his teachings? Or did not know him well and intimately enough to be able to benefit from his guidance and example? Isn't it time you responded to this tremendous challenge and made some effort to know him? It will not cost you anything but it may well prove to be the beginning of a completely new era in your life. Come, let us make a new discovery of the life of this wonderful man Muhammad, peace and blessings of God Almighty be upon him the like of whom never walked on this earth, and whose example and teachings can change YOUR LIFE and OUR WORLD for the better. May God shower His choicest blessings upon him! And this link will help you more to know more about this man http://mohammad.islamway.com/ From ben+python at benfinney.id.au Mon Sep 6 19:36:52 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 09:36:52 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> Message-ID: <87wrqyculn.fsf@benfinney.id.au> Baba writes: > Thanks Jeremy, i will take your advice on board! Noone likes to be > taught lessons i think so it is only normal that i reacted. Please reconsider this response. Many of us use this forum precisely because we *do* like to be taught lessons. If you don't want to be taught lessons, this is not the forum to use. > If i had received a friendly response from Benjamin (as opposed to > "Please do us a favor and at least try to figure things out on your > own") Again, please reconsider your perception of the messages you received. Those messages are polite; they're even explicit about how you can improve your future messages. They are polite enough to regard you as a person who can improve. We value respect for people here, and that's what you've been shown consistently. But respect for opinions, or for delicacy about learning, is not welcome here. In other words, we treat people as adults by default. I hope you'll continue to participate in that spirit. -- \ ?I was gratified to be able to answer promptly and I did. I | `\ said I didn't know.? ?Mark Twain, _Life on the Mississippi_ | _o__) | Ben Finney From pavlovevidence at gmail.com Mon Sep 6 19:40:07 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 6 Sep 2010 16:40:07 -0700 (PDT) Subject: filecmp.cmp() doesn't seem to do what it says in the documentation References: <6gufl7-c9g.ln1@chris.zbmc.eu> Message-ID: <08e5d3b1-355d-463e-80d0-0916a3fdb6a6@13g2000prf.googlegroups.com> On Sep 6, 1:11?pm, tinn... at isbd.co.uk wrote: > Terry Reedy wrote: > > On 9/6/2010 1:18 PM, tinn... at isbd.co.uk wrote: > > > I'm using filecmp.cmp() to compare some files (surprise!). > > > > The documentation says:- > > > ? ? ?Unless shallow is given and is false, files with identical > > > ? ? ?os.stat() signatures are taken to be equal. > > > Reword and read carefully: if shallow == True and signatures are > > identical, then files are taken to be equal. > > > Here is the corresponding code from Lib/filecmp.py: > > ? ? ?if shallow and s1 == s2: > > ? ? ? ? ?return True > > > Does not say the result for non-identical signatures ;-). > > > > I'm not setting shallow explicitly so it's True, thus the function > > > should be comparing the os.stat() results. ?However this doesn't seem > > > to be the case as even if I touch one of the files to change it's > > > access/modification date filecmp.cmp() still returns True. > > > Because it goes on to actually compare the files, and they are equal. > > > ... > > ? ? ?result = _cache.get((f1, f2)) > > ? ? ?if result and (s1, s2) == result[:2]: > > ? ? ? ? ?return result[2] > > ? ? ?outcome = _do_cmp(f1, f2) > > ? ? ?_cache[f1, f2] = s1, s2, outcome > > ? ? ?return outcome > > > Most of the stdlib files in Python are quite readable. I recommend it > > when you have questions. > > Well I still don't think it's what the documentation says, it would be > much better if it told you that 'if the os.stat() signatures are not > identical then the file contents are actually compared'. ?The > implication to me when I read the documentation was that if shallow > was True and the os.stat() signatures were not identical then False > would be returned. ?Where does it say otehrwise? To me, "comparing files" means to compare the contents and nothing else, so when documentation says "Compare the files named f1 and f2" I think it has that covered. I understand the os.stat comparison to be a (non-foolproof) optimization. Anyway, if you just want to compare the os.stat parameters you should just use os.stat. os.stat(filename1) == os.stat(filename2) Then if you want, you can write a function to compare only the stats you are interested in. def mystatcmp(filename1,filename2): s1 = os.stat(filename1) s2 = os.stat(filename2) return s1.st_size == s2.st_size and s1.st_mtime == s2.st_mtime Carl Banks From davea at ieee.org Mon Sep 6 19:44:17 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 06 Sep 2010 19:44:17 -0400 Subject: Class changes in circular imports when __name__ == '__main__' In-Reply-To: References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: <4C857CD1.50604@ieee.org> On 2:59 PM, Carl Banks wrote: > On Sep 5, 5:07 pm, Dave Angel wrote: >> On 2:59 PM, Carl Banks wrote: >>> All of this gets a lot more complicated when packages are involved. >> Perhaps a better answer would be to import __main__ from the second module. > Then what if the module is imported from a different script? It'll > try to import __main__ but get a different script than expected. > > Then the module needs to adjust its expectations. The point is it should never try to import the script by name. DaveA From ben+python at benfinney.id.au Mon Sep 6 20:18:24 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 10:18:24 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> Message-ID: <87sk1mcsof.fsf@benfinney.id.au> Ben Finney writes: > We value respect for people here, and that's what you've been shown > consistently. But respect for opinions, or for delicacy about > learning, is not welcome here. Sloppy wording, I apologise. This should say ?? is not respect for a person?. > In other words, we treat people as adults by default. I hope you'll > continue to participate in that spirit. This is the main thrust of the message. -- \ ?What if the Hokey Pokey IS what it's all about?? ?anonymous | `\ | _o__) | Ben Finney From cuneyt.ertal at gmail.com Mon Sep 6 20:37:33 2010 From: cuneyt.ertal at gmail.com (ceycey) Date: Mon, 6 Sep 2010 17:37:33 -0700 (PDT) Subject: Minimum and Maximum of a list containing floating point numbers Message-ID: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', '9.0601']. What I want to do is to find minimum and maximum number in this list. I used min function, s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', '9.0601'] print min(s) print max(s) these gives me 1.181 9.0601 maximum value is wrong. It must be 10.24. I know why max function gives wrong number. Because max function processed elements of list as strings. How can I convert the elements of list to float so max function finds the correct answer. I hope I can explain my problem. Cuneyt. From contact at xavierho.com Mon Sep 6 20:44:21 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 7 Sep 2010 10:44:21 +1000 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: On 7 September 2010 10:37, ceycey wrote: > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. > How can I convert the elements > of list to float so max function finds the correct answer. > >>> input = ['3.4225', '7.7284', '10.24'] >>> [float(x) for x in input] [3.4225, 7.7284, 10.24] HTH, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Sep 6 20:56:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Sep 2010 01:56:58 +0100 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: <4C858DDA.2090103@mrabarnett.plus.com> On 07/09/2010 01:44, Xavier Ho wrote: > On 7 September 2010 10:37, ceycey > wrote: > > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. > > How can I convert the elements > of list to float so max function finds the correct answer. > > > >>> input = ['3.4225', '7.7284', '10.24'] > >>> [float(x) for x in input] > [3.4225, 7.7284, 10.24] > If you wanted to find the maximum value without converting the list to numbers you could do this: >>> input = ['3.4225', '7.7284', '10.24'] >>> max(input, key=float) '10.24' Incidentally, there's a builtin function called 'input' so using it as a variable name is a discouraged! :-) From python.list at tim.thechases.com Mon Sep 6 21:00:39 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 06 Sep 2010 20:00:39 -0500 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: <4C858EB7.3020802@tim.thechases.com> On 09/06/10 19:37, ceycey wrote: > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. What I want to do is to find minimum and maximum number in > this list. > > I used min function, > > print min(s) > print max(s) > > these gives me > > 1.181 > 9.0601 > > maximum value is wrong. It must be 10.24. > > I know why max function gives wrong number. Because max function > processed elements of list as strings. How can I convert the elements > of list to float so max function finds the correct answer. You can use min(float(v) for v in s) max(float(v) for v in s) to return the floating-point number, or in Python2.5+ you can use min(s, key=float) max(s, key=float) to get the string source. If you need the source string in pre-2.5, you'd have to do something like min((float(v), v) for v in s)[1] # 2.4 min([(float(v), v) for v in s])[1] # 2.3 or earlier and guard against empty input lists. -tkc From ben+python at benfinney.id.au Mon Sep 6 21:00:45 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 11:00:45 +1000 Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: <87fwxmcqpu.fsf@benfinney.id.au> ceycey writes: > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. What I want to do is to find minimum and maximum number in > this list. As you correctly describe later, there aren't any numbers in that list; only strings. > How can I convert the elements of list to float so max function finds > the correct answer. If you're going to use the list of float objects, you can convert them all with a list comprehension. >>> numbers_as_str = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', ... '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', ... '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', ... '9.0601'] >>> numbers_as_float = [float(x) for x in numbers_as_str] >>> print min(numbers_as_float), max(numbers_as_float) 1.1881 10.24 -- \ ?As scarce as truth is, the supply has always been in excess of | `\ the demand.? ?Josh Billings | _o__) | Ben Finney From marduk at letterboxes.org Mon Sep 6 21:01:29 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Mon, 06 Sep 2010 21:01:29 -0400 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> Message-ID: <1283821289.467035.8.camel@paska> On Mon, 2010-09-06 at 17:37 -0700, ceycey wrote: > I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689', > '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601', > '9.0601']. What I want to do is to find minimum and maximum number in > this list. > > I used min function, > > s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', > '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', > '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', > '9.0601', '9.0601'] > > print min(s) > print max(s) > > these gives me > > 1.181 > 9.0601 > > maximum value is wrong. It must be 10.24. You are not comparing a list of floats but a list of strings. > I know why max function gives wrong number. Because max function > processed elements of list as strings. How can I convert the elements > of list to float so max function finds the correct answer. min/max in these cases are returning strings as well. So the fact remains that the max function is not giving you a number at all, but a string, and as such is correct. String comparison is not identical to numerical comparison. But to answer your question: >>> s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881', ... '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', ... '1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', ... '9.0601', '9.0601'] >>> [type(x) for x in s] [, , , , , , , , , , , , , , , , , , , ] >>> type(max(s)) >>> t = [float(x) for x in s] >>> [type(x) for x in t] [, , , , , , , , , , , , , , , , , , , ] >>> min(t) 1.1880999999999999 >>> max(t) 10.24 >>> type(max(s)) >>> type(max(t)) From steve-REMOVE-THIS at cybersource.com.au Mon Sep 6 22:31:17 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 07 Sep 2010 02:31:17 GMT Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> Message-ID: <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: > If you're going to use the list of float objects, you can convert them > all with a list comprehension. [...] > >>> numbers_as_float = [float(x) for x in numbers_as_str] That's awfully verbose. A map is simpler: numbers_as_float = map(float, numbers_as_str) -- Steven From ben+python at benfinney.id.au Mon Sep 6 22:40:57 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 12:40:57 +1000 Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> Message-ID: <87bp8acm2u.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: > > > If you're going to use the list of float objects, you can convert them > > all with a list comprehension. > [...] > > >>> numbers_as_float = [float(x) for x in numbers_as_str] > > That's awfully verbose. A map is simpler: > > numbers_as_float = map(float, numbers_as_str) I'll pay ?verbose?, but not ?awfully?. There is little difference in verbosity between your example and mine. Further, I don't see my example as excessive, which I assume your ?awfully? entails. -- \ ?I call him Governor Bush because that's the only political | `\ office he's ever held legally.? ?George Carlin, 2008 | _o__) | Ben Finney From steve-REMOVE-THIS at cybersource.com.au Mon Sep 6 23:14:06 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 07 Sep 2010 03:14:06 GMT Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c85adfe$0$11115$c3e8da3@news.astraweb.com> On Mon, 06 Sep 2010 11:38:22 +0100, BartC wrote: > Modifying the OP's code a little: > > a = 0 > for i in xrange(100000000): # 100 million > a = a + 10 # add 10 or 100 > print a > > Manually unrolling such a loop four times (ie. 4 copies of the body, and > counting only to 25 million) increased the speed by between 16% and 47% > (ie. runtime reducing by between 14% and 32%). Or you could *really* optimize it, as well as simplifying the code, by writing: n = 100000000 a = 10*n and doing a single multiplication rather than pointless repeated addition. (I assume that the number of loops is meant to be a variable rather than a constant, otherwise a = 1000000000 would be the correct optimization.) Of course, if 10 (or 100) is not a constant but is just standing in for something which varies each iteration: for i in xrange(100000000): a = a + f(i) then unrolling the loop is even less useful. The overhead of the loop itself is likely to be trivial compared to the cost of calling f() 100 million times -- the added complexity to shave 3 seconds off a four minute calculation simply isn't worth it. Besides, loop unrolling really only is valuable for small loops, otherwise the overhead caused by the increased code size makes it a pessimation rather than an optimization. It's very easy for any gains to be lost due to increased cache misses, time needed to copy the code into memory, etc. http://en.wikipedia.org/wiki/Loop_unwinding There's a lot of subtlety in optimization, and what counts as an optimization for low-level operations, and what is an optimization for high-level languages like Python, are rarely the same. > This depended on whether I added +10 or +100 (ie. whether long integers > are needed), whether it was inside or outside a function, and whether I > was running Python 2 or 3 (BTW why doesn't Python 3 just accept 'xrange' > as a synonym for 'range'?) Why should it? But if you want it, you can do it: xrange = range There, that wasn't hard, was it? > These are just some simple tests on my particular machine and > implementations, but they bring up some points: > > (1) Loop unrolling does seem to have a benefit, when the loop body is > small. > > (2) Integer arithmetic seems to go straight from 32-bits to long > integers; why not use 64-bits before needing long integers? Why? That adds 50% more code, 50% more testing, 50% more places for bugs to hide, 50% more effort required to maintain it, for something which *at best* will be a trivial optimization which at best is of interest to a small minority of Python coders. There's already code to deal with 32 bit its, code to deal with longints, and code to deal with shifting transparently from one to the other. Adding code to deal with 64 bit ints doesn't happen for free. Besides, if you care about the difference between 32 and 64 bit ints, chances are you don't want Python blithely swapping from one to the other when you least expect it. So you'll be using a library that gives you access to whichever ints you want, probably implemented natively rather than as objects. Sounds rather like numpy really :) http://docs.scipy.org/doc/numpy/user/basics.types.html > (3) Since the loop variable is never used, why not have a special loop > statement that repeats code so many times? This can be very fast, since > the loop counter need not be a Python object, and probably there would > be no need for unrolling at all: > > repeat 100000000: # for example > a = a + 10 Because now both the parser and all Python coders need to care about one more reserved word, all so that one Python program in ten thousand can save 0.1 ms occasionally. Optimizations don't happen for free. If the optimization doesn't carry it's own weight, it's a pessimation. To me, it's more important to be able to be able to use repeat as a name: connect_to_server("localhost", repeat=10) than to save a millisecond or so. Besides, if repeat were to become syntax, then I'd MUCH rather have it used for repeat...until (or repeat...while) loops, to avoid the anti- pattern of: x = f() while not condition(x): x = f(x) which would be better as: repeat: x = f() until condition(x) -- Steven From phlip2005 at gmail.com Mon Sep 6 23:48:08 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 6 Sep 2010 20:48:08 -0700 (PDT) Subject: The Samurai Principle Message-ID: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Pythonistas: The "Samurai Principle" says to return victorious, or not at all. This is why django.db wisely throws an exception, instead of simply returning None, if it encounters a "record not found". I illustrated the value of that concept, here: http://c2.com/cgi/wiki?SamuraiPrinciple From steve-REMOVE-THIS at cybersource.com.au Mon Sep 6 23:50:41 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 07 Sep 2010 03:50:41 GMT Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> <87bp8acm2u.fsf@benfinney.id.au> Message-ID: <4c85b691$0$11115$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 12:40:57 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: >> >> > If you're going to use the list of float objects, you can convert >> > them all with a list comprehension. >> [...] >> > >>> numbers_as_float = [float(x) for x in numbers_as_str] >> >> That's awfully verbose. A map is simpler: >> >> numbers_as_float = map(float, numbers_as_str) > > I'll pay ?verbose?, but not ?awfully?. There is little difference in > verbosity between your example and mine. Further, I don't see my example > as excessive, which I assume your ?awfully? entails. Sorry, verbose is not the word I want... I don't know what word I *actually* want, so let me explain. Instead of thinking about a single transformation "change a list of strings to a list of floats", the list comp form forces you to think about the individual list items and the mechanics of looping, and reduces lists to a second-class data type: we can operate on ints without caring about individual bits, but we can't operate on lists without caring about individual list items. Why do I need to care about individual items? The list comp even gives them a name, "x" in your example, even though that name isn't used anywhere else. Why do I need to specify that walking the list must be done from left-to-right rather than whatever order the compiler thinks best, or even in parallel? Answer: I don't, and shouldn't need to. With map, such internal details of how the transformation is performed is hidden. I shouldn't need to specify *how* to convert a list of strings to a list of floats. While a list comp is less verbose than a for-loop, which is less again than a while-loop, they all specify how to do the transformation, which is mental overhead I shouldn't need to care about. Of course, list comps are so seductively easy, and functional programming so conceptually different from what many people are used to, that such over-specification is an awfully easy trap to fall into. I'm sure my own code is filled with similar examples where I use a list comp where a map is more suitable. -- Steven From laicheng_kwan at innomedia.com.sg Tue Sep 7 00:06:47 2010 From: laicheng_kwan at innomedia.com.sg (Kwan Lai Cheng) Date: Tue, 7 Sep 2010 12:06:47 +0800 Subject: Bit fields in python? Message-ID: Hi, I'm trying to rewrite a c program in python & encountered several problems. I have some data structures in my c program like below: typedef struct { unsigned short size; unsigned short reserved:8; unsigned short var_a1:2; unsigned short var_a2:2; unsigned short var_a3:2; unsigned short var_a4:2; unsigned int var_a5; }structa; typedef struct { unsigned short size; unsigned char reserved:4; unsigned char var_b1:1; unsigned char var_b2:1; unsigned char var_b3:1; unsigned char var_b4:1; structa var_structa; }structb; I tried to code the above in python but only got this far: class StructA(object): def __init__(self, size=0) self.size = size class StructB(object): def __init__(self, size=0) Any equivalent for c data structures & bit fields in python? And how do I define var_structa (in structb) in python? Regards, Kwan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue Sep 7 00:20:43 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Sep 2010 14:20:43 +1000 Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> <87bp8acm2u.fsf@benfinney.id.au> <4c85b691$0$11115$c3e8da3@news.astraweb.com> Message-ID: <8739tmchgk.fsf@benfinney.id.au> Steven D'Aprano writes: > Of course, list comps are so seductively easy, and functional > programming so conceptually different from what many people are used > to, that such over-specification is an awfully easy trap to fall into. > I'm sure my own code is filled with similar examples where I use a > list comp where a map is more suitable. Right. I find list comprehensions and generator expressions easy both to write and to read. So I prefer them, and often don't consider more function-based approaches. I don't think my code (nor my examples) suffer much as a result. -- \ ?Rightful liberty is unobstructed action, according to our | `\ will, within limits drawn around us by the equal rights of | _o__) others.? ?Thomas Jefferson | Ben Finney From kurianmthayil at gmail.com Tue Sep 7 00:27:28 2010 From: kurianmthayil at gmail.com (Kurian Thayil) Date: Tue, 7 Sep 2010 09:57:28 +0530 Subject: mail sending -- smtplib Message-ID: Hi All, I am a newbie in python. Just 2-3 days old wanting to learn this amazing programming language. I was trying to send mails using smtplib module, so did some google and found a code snippet. The mail gets sent, but doesn't come in the right format when a for-loop is introduced (Not MIME standard?). Without the for-loop the script works fine. Can anyone advice? * #!/usr/bin/env python import smtplib for i in range(1,5): print "I is ",i fromaddr='kurianmthayil at gmail.com' toaddr='kurianmthayil at gmail.com' print toaddr mssg="""From: Kurian Thayil To: Kurian Thayil MIME-Version: 1.0 Content-type: text/html Subject: 12345 -- Reloaded :) Hey dude.. how are you????



Regards,

Kurian """ print "message is ",mssg smail=smtplib.SMTP('smtp.gmail.com',587) smail.ehlo() smail.starttls() smail.ehlo() smail.login(fromaddr,'***********') smail.sendmail(fromaddr,toaddr,mssg) print "Over" * Regards, Kurian Thayil. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Tue Sep 7 01:08:22 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 6 Sep 2010 22:08:22 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> Message-ID: <39c85ff7-f1bb-47ad-95b3-bcb9ce9c0c5b@i4g2000prf.googlegroups.com> On Sep 6, 4:44?pm, Dave Angel wrote: > On 2:59 PM, Carl Banks wrote:> On Sep 5, 5:07 pm, Dave Angel ?wrote: > >> On 2:59 PM, Carl Banks wrote: > >>> All of this gets a lot more complicated when packages are involved. > >> Perhaps a better answer would be to import __main__ from the second module. > > Then what if the module is imported from a different script? ?It'll > > try to import __main__ but get a different script than expected. > > Then the module needs to adjust its expectations. No, it shouldn't. It shouldn't have any expectations at all, because importing __main__ and expecting to get a particular module is a foolish thing to do. There are a bunch of reasons why __main__ might not be the original script. Example: running the profiler on it. > The point is it > should never try to import the script by name. Importing __main__ directly is worse than the problem it's trying to solve. And "never" is too strong a word. I already in this thread gave a solution whereby the script can be imported by name safely, by renaming itself and assigning itself an item in sys.modules. When you do that, you can import the main script by name. Carl Banks From ragmanme at gmail.com Tue Sep 7 01:19:46 2010 From: ragmanme at gmail.com (Ryan George) Date: Mon, 6 Sep 2010 22:19:46 -0700 (PDT) Subject: How to determine if a Python script is being run right after startup on Windows Message-ID: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> Hello! I'm a newbie to Python (literally just started last Saturday), and I coded a program that selects a random wallpaper from a directory and swaps it with your current one (Windows only.) What I'm looking to do is have it start up with Windows and automatically swap the wallpapers. This part I have already coded, and as far as I know, it should work. However, I want the user to be able to access the GUI after this initial running of the program. The way it is set up now, enabling "Start Up Mode" will cause the program to cycle the wallpapers and then immediately exit. My question is this: is there any way I can determine if the program is being run directly after a startup on a Windows machine? Thanks, Ryan From steve-REMOVE-THIS at cybersource.com.au Tue Sep 7 01:57:30 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 07 Sep 2010 05:57:30 GMT Subject: How to determine if a Python script is being run right after startup on Windows References: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> Message-ID: <4c85d44a$0$28651$c3e8da3@news.astraweb.com> On Mon, 06 Sep 2010 22:19:46 -0700, Ryan George wrote: > My question is this: is there any way I can determine if the program is > being run directly after a startup on a Windows machine? How would you, a human being, determine if the program was being run directly after startup? What counts as "directly"? Within 10 seconds? Before any other program with a GUI? Before *any* other program, including background processes? Before the Windows desktop loads? You also said: "What I'm looking to do is have it start up with Windows and automatically swap the wallpapers. This part I have already coded, and as far as I know, it should work." As far as you know, it SHOULD work? How about trying it and finding out? In any case, it sounds to me that what you need is two programs, one which automatically sets the wallpaper at startup, and a second that is a GUI. -- Steven From sajuptpm at gmail.com Tue Sep 7 02:42:27 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Mon, 6 Sep 2010 23:42:27 -0700 (PDT) Subject: list of tuples with dynamic change in position References: Message-ID: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> More details I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), ((cpu_util,mem_util),(disk_util))] ie, l = [((30,50),(70)), ((50,20),(20))] l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and disk_util desc suppose i changed order that is l = [((mem_util,cpu_util), (disk_util)), ((mem_util,cpu_util),(disk_util))] So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], x[1][0])) # sorting cpu_util asc and disk_util desc I want to use same (common) sort code, that must work even if i changed tuple order. From stefan_ml at behnel.de Tue Sep 7 02:55:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 07 Sep 2010 08:55:54 +0200 Subject: Bit fields in python? In-Reply-To: References: Message-ID: Kwan Lai Cheng, 07.09.2010 06:06: > I'm trying to rewrite a c program in python& encountered several problems. I have some data structures in my c program like below: > > typedef struct > { > unsigned short size; > > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsigned short var_a3:2; > unsigned short var_a4:2; > > unsigned int var_a5; > }structa; > > typedef struct > { > unsigned short size; > > unsigned char reserved:4; > unsigned char var_b1:1; > unsigned char var_b2:1; > unsigned char var_b3:1; > unsigned char var_b4:1; > > structa var_structa; > }structb; > > I tried to code the above in python but only got this far: > > class StructA(object): > def __init__(self, size=0) > self.size = size > > class StructB(object): > def __init__(self, size=0) > > Any equivalent for c data structures& bit fields in python? If you can tell us what these structs are being used for in the original C code, we might be able to point you to a suitable way to implement the same thing efficiently in Python. Stefan From __peter__ at web.de Tue Sep 7 03:16:30 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 09:16:30 +0200 Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> Message-ID: sajuptpm wrote: > More details > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > ((cpu_util,mem_util),(disk_util))] > ie, l = [((30,50),(70)), ((50,20),(20))] > > l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and > disk_util desc > > suppose i changed order that is l = [((mem_util,cpu_util), > (disk_util)), ((mem_util,cpu_util),(disk_util))] > So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], > x[1][0])) # sorting cpu_util asc and disk_util desc > > > I want to use same (common) sort code, that must work even if i > changed tuple order. Use namedtuples: from collections import namedtuple Pair = namedtuple("Pair", "pair disk_util") A = namedtuple("A", "cpu_util mem_util") B = namedtuple("B", "mem_util cpu_util") # you can safely omit this step for class_ in A, B, Pair: del class_.__repr__ items = [((30,50), 70), ((50,20),20)] a = [Pair(A(x, y), z) for (x, y), z in items] b = [Pair(B(y, x), z) for (x, y), z in items] def sort(items): items.sort(key=lambda x: x.pair.mem_util, reverse=True) items.sort(key=lambda x: x.pair.cpu_util) sort(a) print a sort(b) print b Peter From grflanagan at gmail.com Tue Sep 7 03:47:48 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Tue, 7 Sep 2010 00:47:48 -0700 (PDT) Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> Message-ID: <00f05409-3b64-4d8a-a5c4-92d22e7ba0c1@m1g2000yqo.googlegroups.com> On 7 Sep, 07:42, sajuptpm wrote: > More details > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > ((cpu_util,mem_util),(disk_util))] > ie, l = [((30,50),(70)), ((50,20),(20))] > > l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and > disk_util desc > > suppose i changed order that is l = [((mem_util,cpu_util), > (disk_util)), ((mem_util,cpu_util),(disk_util))] > So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], > x[1][0])) # sorting cpu_util asc and disk_util desc > > I want to use same (common) sort code, that must work even if i > changed tuple order. If you have a sort function that works just leave it as it is and rearrange your data before passing it to the sort function. Eg. ---------------------------------- d1 = [ ((30,50),(90,)), ((30,50),(70,)), ((50,20),(20,)), ((20,20),(50,)), ((20,20),(60,)), ((20,20),(10,)), ] d2 = [ ((50,30),(90,)), ((50,30),(70,)), ((20,50),(20,)), ((20,20),(50,)), ((20,20),(60,)), ((20,20),(10,)), ] def _sort_the_tuples(iterable): #print list(iterable) return sorted(iterable, key=lambda t: (-t[0][0], t[1][0])) def sort_the_tuples(iterable, rearrange=lambda X: X): return _sort_the_tuples(rearrange(t) for t in iterable) assert sort_the_tuples(d1) == \ sort_the_tuples(d2, lambda X: ((X[0][1], X[0][0]), (X[1][0],))) -------------------------------- The point of my previous response was to deal with a list of dictionaries and sort by attribute rather than index, but whatever works. Regards From ragmanme at gmail.com Tue Sep 7 04:10:14 2010 From: ragmanme at gmail.com (Ryan George) Date: Tue, 7 Sep 2010 01:10:14 -0700 (PDT) Subject: How to determine if a Python script is being run right after startup on Windows References: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> <4c85d44a$0$28651$c3e8da3@news.astraweb.com> Message-ID: Hello Stephen, Thanks for the prompt response! >How would you, a human being, determine if the program was being run directly after startup? I'm not going to claim that I am a computer systems expert; I don't know a whole lot about what goes on in the Windows start up. I know services and programs are started, Internet connections are made, and connections to devices on your computer are tested. However, these are all things that could happen at any time (programs: obviously; Internet could disconnect; unplugging or plugging in a mouse, for example). That's why I came here. Maybe someone knew something I didn't. I know you're trying to get me to come to my own conclusion of my own accord, but I have been attacking this problem for 8 hours. If the answer was within my knowledge, I believe would have discovered it by now. >What counts as "directly"? Within 10 seconds? Before any other program with a GUI? Before *any* other program, including background processes? Before the Windows desktop loads? Maybe I should have made my purpose clearer. What I want the program to do is perform its normal function (ie: swap your wallpaper with a random one from a given directory) automatically after Windows completely starts up, and then exit so as not to remain in memory. With this new information, the answer to all of these questions should be obvious. Since it depends on calls to the Windows API, this program should be one of the last things to start, if not THE last thing. >As far as you know, it SHOULD work? How about trying it and finding out? Again, I probably should have been clearer. This functionality DOES work. The program will swap the wallpapers, then exit. The only thing I haven't tested is if it will work at start up, which would have required a reboot of my computer, something I really didn't want to have to do. I was in the process of coding other, more critical features with around 20 different tabs opened in Firefox, as well as participating communications with someone who was designing a logo for me. I will be testing it next time I boot my computer. >In any case, it sounds to me that what you need is two programs, one which automatically sets the wallpaper at startup, and a second that is a GUI. Yes, that is an option. However, my previous wallpaper cycler was able to do what I am describing without two separate programs and I have just discovered how. It was a switch on the executable that isn't present when you try to run the program normally. This was probably the first thing I should have looked into and I don't know why I did not. As long as I can pass variables through a command line when executing a Python script, I see no reason why this shouldn't work. This technically isn't the system letting the program know that it is running after a start up, but rather a user telling a program that "I am running you after a start up." Little bit of a different approach, but hey, whatever works right? From eckhardt at satorlaser.com Tue Sep 7 04:16:33 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Tue, 07 Sep 2010 10:16:33 +0200 Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> Message-ID: <109hl7-ao8.ln1@satorlaser.homedns.org> sajuptpm wrote: > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > ((cpu_util,mem_util),(disk_util))] > ie, l = [((30,50),(70)), ((50,20),(20))] > > l.sort(key=lambda x:(-x[0][0], x[1][0])) > # sorting cpu_util asc and disk_util desc One thing here: Without knowing what special meaning the indices have, this code is impossible to understand. In my opinion, that code should rather be l.sort(key=lambda x: (-x.cpu_util, x.disk_util)) You could then save the comment, which btw may or may not describe the actual code. > suppose i changed order that is l = [((mem_util,cpu_util), > (disk_util)), ((mem_util,cpu_util),(disk_util))] > So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], > x[1][0])) # sorting cpu_util asc and disk_util desc > > I want to use same (common) sort code, that must work even if i > changed tuple order. You don't have to use a lambda function. You can as well define the sorting order in the same place of your code where you define the order inside the elements, that way you would only have to adjust the sorting in one place. Otherwise, you will have to embed the order of the tuple inside the tuple or the containing list. One approach would be to have a dictionary (which has no order), or you use a separate type instead: class record(object): pass r = record() r.cpu_util = 12 r.disk_util = 42 l.append(r) However, this basically all boils down to either "don't use the sorting (dict)" or "keep records sorted", so it doesn't really answer your question. However, I'm afraid there is no answer to your question as it stands. Maybe I could help you better if you explained why the order changes etc, because normally I don't deal with data that has such a volatile meaning, I rather normalize it on input and then use it in the same way afterwards. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Tue Sep 7 04:36:56 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 10:36:56 +0200 Subject: Newby Needs Help with Python code References: <861505.20099.qm@web33506.mail.mud.yahoo.com> Message-ID: Nally Kaunda-Bukenya wrote: > I am very sorry to bother you, but I need help understanding the code that > you assisted me with. It does exactly what I needed done, I can't thank > you enough for that. I am just learning Python, and would appreciate all > the help. please see my comments below and help me understand the code. Please don't email me directly, send questions to the list instead to give more people a chance to answer. > Code below: > > #WHAT IS A DICT? SAME AS LIST? This is a very basic question which is dealt with in every tutorial. Look here for a starting point: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers > #iterate over the Outfalls_ND table twice, the first time to calculate the > #sums per OUTFALL_ID and put them into a dict. With the second pass the > #Tot_Outf_Area column is updated > import arcgisscripting > def rows(cur): > while True: > row = cur.Next() > if row is None: > break #?? > yield row #?? break terminates a loop, yield gives back a result without terminating the function which is then called "generator". For now I recommend that you treat this generator as a black box. > gp = arcgisscripting.create() > gp.Workspace = "C:\\NPDES\\NPDES_PYTHON.mdb" > TABLE = "Outfalls_ND" > GROUP = "OUTFALL_ID" #does upper case mean anything?? (group below is lower > case?) Python is case-sensitive, so GROUP and group (and Group or grouP) are different names. I am following a convention here that uppercase names are used for constants, i. e. the value of GROUP never changes after the first assignment. > SUM = "AREA_ACRES" > TOTAL = "Tot_Outf_Area" > > aggregate = {} > cur = gp.UpdateCursor(TABLE) > for row in rows(cur): #is this diff from for rows in cur? > group = row.GetValue(GROUP) #loop thru rows and search for outfall_ID > amount = row.GetValue(SUM) #loop thru rows and search for area_acres > aggregate[group] = aggregate.get(group, 0.0) + amount #need help > w/explanation on aggregate fn > #aggregate[group] is what is it? is this a list of unique outfall_ID's? > #aggregate.get (group, 0.0) how do you get 0.0? > #I tried this code on a diff field and got this error: TypeError: > unsupported operand #type(s) for +: 'float' and 'NoneType' > > cur = gp.UpdateCursor(TABLE) > for row in rows(cur): > group = row.GetValue(GROUP) > row.SetValue(TOTAL, aggregate[group]) #?? > cur.UpdateRow(row) Sorry, I don't think answering any of the above questions worthwhile until you've worked through an introductory text. Once you /have/ a basic understanding you can often find out the answers by asking python itself. Just fire up the interactive interpreter and type >>> help(dict.get) If the explanation given there is not sufficient you can use the online documentation as a fallback: http://docs.python.org/library/stdtypes.html#mapping-types-dict Good look with your efforts! Peter From laicheng_kwan at innomedia.com.sg Tue Sep 7 04:39:48 2010 From: laicheng_kwan at innomedia.com.sg (Kwan Lai Cheng) Date: Tue, 7 Sep 2010 16:39:48 +0800 Subject: Bit fields in python? References: Message-ID: <13E27E02A9B14910A389A4495E729543@cs0403293> ----- Original Message ----- From: Stefan Behnel To: Sent: Tuesday, September 07, 2010 2:55 PM Subject: Re: Bit fields in python? > > If you can tell us what these structs are being used for in the original C > code, we might be able to point you to a suitable way to implement the > same > thing efficiently in Python. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > It's a test program for testing the DSP (Digital Signal Processor). Basically what it does is that it sends commands to the DSP via a driver and waits for a response from the DSP. The structures represent the data that I might receive from the DSP. For example if I send command A, DSP will send data in the format of structa to me, so I will cast the data I received to structa, and print the struct field values on screen. Each field in the structures represent some status or info about the DSP, different bits in an unsigned char or unsigned short field might represent different DSP status. I just found out that there's a ctypes module (http://docs.python.org/library/ctypes.html) in python that might solve my problem. I understand that it is already included in Python 2.5 & I'm using Python 2.6.2. However when I tried "from ctypes import *", I got "No module named _ctypes". What am I missing here? From jerry.fleming at saybot.com Tue Sep 7 05:39:18 2010 From: jerry.fleming at saybot.com (Jerry Fleming) Date: Tue, 07 Sep 2010 17:39:18 +0800 Subject: sqlalchemy: how to define association object with declarative style? Message-ID: Hi, I want to define the relationship for my users and their groups with declarative style (so that the relating model can inherit Timestamp mixin and Tablename mixin): class User(DeclarativeBase, Tablename, TimestampMixin): '''User avatar is named after its id. A user may be a student or teacher or both. ''' id = Column(Integer, Sequence('user_id_seq'), primary_key=True) username = Column(String(30), index=True, nullable=False, unique=True) password = Column(String(30), index=True, nullable=False) class Group(DeclarativeBase, Tablename, TimestampMixin): id = Column(Integer, Sequence('group_id_seq'), primary_key=True) name = Column(Unicode(20), unique=True, nullable=False) display = Column(Unicode(255)) class GroupUser(DeclarativeBase, Tablename, TimestampMixin): id = Column(Integer, Sequence('group_user_id_seq'), primary_key=True) user = Column(Integer, ForeignKey('user.id'), index=True), group = Column(Integer, ForeignKey('group.id'), index=True) I was wondering how to associate User and Group with GroupUser with GroupUser as the association object/proxy? The sqlalchemy docs only mention only mention association tables, or non-declarative manual mapping. Thanks. From thossie at gmail.com Tue Sep 7 05:43:26 2010 From: thossie at gmail.com (Dennis Verdonschot) Date: Tue, 7 Sep 2010 02:43:26 -0700 (PDT) Subject: How to determine if a Python script is being run right after startup on Windows References: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> <4c85d44a$0$28651$c3e8da3@news.astraweb.com> Message-ID: Hi Ryan, Maybe I'm missing something, but wouldn't creating a shortcut and putting that shortcut in your Start - Programs - Startup section of the Windows menu not work for this program? Or if really needed you can edit the start-up programs in the registry. If you add some logging ability to your program you can verify it has been run and you can still use commandline arguments by changing the shortcut. -- Dennis From bartc at freeuk.com Tue Sep 7 06:00:03 2010 From: bartc at freeuk.com (BartC) Date: Tue, 7 Sep 2010 11:00:03 +0100 Subject: Speed-up for loops In-Reply-To: <4c85adfe$0$11115$c3e8da3@news.astraweb.com> References: <4C7F7640.1010102@perfect-kreim.de><4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c85adfe$0$11115$c3e8da3 at news.astraweb.com... > On Mon, 06 Sep 2010 11:38:22 +0100, BartC wrote: >> >> Manually unrolling such a loop four times (ie. 4 copies of the body, and >> counting only to 25 million) increased the speed by between 16% and 47% >> (ie. runtime reducing by between 14% and 32%). > > Or you could *really* optimize it, as well as simplifying the code, by > writing: > > n = 100000000 > a = 10*n > > and doing a single multiplication rather than pointless repeated addition. It's not pointless; it's being used as a test of long it takes to do a=a+10 a hundred million times in a loop. (Similarly, if we wanted to investigate the speed of function calls, then a 'pointless' recursive implementation of fibonacci(36) that needed 76 million (or whatever) calls is far more useful than one that did it with just 1. But a lot of people just don't get this, for example some of the comments here: http://programmingzen.com/2007/11/28/holy-shmoly-ruby-19-smokes-python-away/ ) > Of course, if 10 (or 100) is not a constant but is just standing in for > something which varies each iteration: > > for i in xrange(100000000): > a = a + f(i) > > then unrolling the loop is even less useful. The overhead of the loop > itself is likely to be trivial compared to the cost of calling f() 100 > million times -- the added complexity to shave 3 seconds off a four > minute calculation simply isn't worth it. With Python 3 and def f(x): return x+1, unrolling this loop 4x improved speed by 15%; 4.00 minutes reduces to 3.30 minutes. In this code (adapted from a real piece of Python code): for i in xrange(1000000): a[i]=0 Unrolling 4x produced a 47% speedup. Now your program only takes 2:45 minutes. >(BTW why doesn't Python 3 just accept 'xrange' as a synonym for 'range'?) > > Why should it? But if you want it, you can do it: > > xrange = range > > There, that wasn't hard, was it? I think I just learned more about Python than from months of reading this group. So 'range' is just a class like any other. And that a class is something you can blithely copy from one variable to another. And whenever you see 'range' anywhere, you can't always be certain that someone hasn't done: range = 42 at some point. That explains a lot about the difficulties of implementing Python efficiently. (And the xrange=range trick works well thanks.) >) Integer arithmetic seems to go straight from 32-bits to long >> integers; why not use 64-bits before needing long integers? > > Why? That adds 50% more code, 50% more testing, 50% more places for bugs > to hide, 50% more effort required to maintain it, for something which *at > best* will be a trivial optimization which at best is of interest to a > small minority of Python coders. I would have suggested just using 64-bits anyway (on 32-bit hardware) as, currently, the slight extra overhead would be insignificant, provided it doesn't result in double the memory when there are many integers. As for being of minority interest, with the whole world rapidly becoming 64-bits, I would dispute that... >> repeat 100000000: # for example >> a = a + 10 > > Because now both the parser and all Python coders need to care about one > more reserved word, all so that one Python program in ten thousand can > save 0.1 ms occasionally. That's a minor detail. You can call it whatever you like. -- Bartc From ian at ianhobson.co.uk Tue Sep 7 06:18:10 2010 From: ian at ianhobson.co.uk (Ian Hobson) Date: Tue, 07 Sep 2010 11:18:10 +0100 Subject: Help needed - function apparently global cannot be called. Message-ID: <4C861162.9020100@ianhobson.co.uk> Hi all you experts, This has me beat. Has anyone any ideas about what might be going wrong? This is code from within a windows service (hence no print statements - no sys.stdout to print on!). I am trying to trace through to find where the code is not working. No stdout so I have to log to a file. I have the following code fragments. def log(message): f = open('d:\logfile.txt','a') f.write(message + "\n") f.close() from DelNotePrinter import DelNotePrinter note the order of the above - log is defined before the import. Later in the source I have log('disPrint is:'+disPrint) log('count is:'+count) log(repr(DelNotePrinter)) printer = DelNotePrinter(disPrint,int(count)) The DelNotePrinter.py file cannot us log even though it is declared as global. The code is... # coding=utf8 # DelNotePrinter = code to print delivery notes assorted imports removed for space reasons class DelNotePrinter(object): ''' Print Delivery Note on A5 in portrait ''' def __init__(self,printer,copies): ''' create printer and painter ''' global font,sm,log log('DelNotePrinter: starting') self.printer = QPrinter(QPrinter.HighResolution) etc The file the log writes contains.. disPrint is:HP Deskjet 6940 series count is:1 The > is followed by a newline and end of file! Where is the DelNotePrinter: starting message? If I replace the opening of __init__ with global font,sm,log f = open('d:\logfile.txt','a') f.write('DelNotePrinter: starting' + "\n") f.close() self.printer = QPrinter(QPrinter.HighResolution) then the message IS written to the log file. I have read http://docs.python.org/reference/simple_stmts.html#global very carefully and I still don't understand. Regards Ian p.s. There are no trackbacks, no events on the event log, and no error messages I have been able to find. When run as a script (not a service) DelNotePrinter does produce the expected printout. From krister.svanlund at gmail.com Tue Sep 7 06:19:02 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Tue, 7 Sep 2010 12:19:02 +0200 Subject: How to determine if a Python script is being run right after startup on Windows In-Reply-To: References: <616cc4a0-3f05-416d-ab64-f609de5f287c@u5g2000prn.googlegroups.com> <4c85d44a$0$28651$c3e8da3@news.astraweb.com> Message-ID: On Tue, Sep 7, 2010 at 11:43 AM, Dennis Verdonschot wrote: > Hi Ryan, > > Maybe I'm missing something, but wouldn't creating a shortcut and > putting that shortcut in your Start - Programs - Startup section of > the Windows menu not work for this program? Or if really needed you > can edit the start-up programs in the registry. > > If you add some logging ability to your program you can verify it has > been run and you can still use commandline arguments by changing the > shortcut. > > -- > Dennis > -- > http://mail.python.org/mailman/listinfo/python-list > I would recommend using a commandline switch (look at sys.argv in documentation) and just start the script with something like python script.py --change-wallpaper or maybe require a switch for getting to the GUI... From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 06:50:19 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 12:50:19 +0200 Subject: Help needed - function apparently global cannot be called. In-Reply-To: References: Message-ID: <4c8618e5$0$8784$426a74cc@news.free.fr> Ian Hobson a ?crit : > Hi all you experts, > > This has me beat. Has anyone any ideas about what might be going wrong? > > This is code from within a windows service (hence no print statements - > no sys.stdout to print on!). > > I am trying to trace through to find where the code is not working. No > stdout so I have to log to a file. Then you'd be better using the logging module from the stdlib. And FWIW, you should try to make you code testable in a non-service context... > I have the following code fragments. > > def log(message): > f = open('d:\logfile.txt','a') > f.write(message + "\n") > f.close() > > from DelNotePrinter import DelNotePrinter The convention is to use all_lower_names for modules - having modules and classes with the same (case-sensitive) name can be very misleading. > note the order of the above - log is defined before the import. And ? Do you think it will affect the imported module in any way ? Like, say, magically "inject" your log function in the DelNotePrinter module ?-) > Later in the source Where ? > I have > > log('disPrint is:'+disPrint) > log('count is:'+count) Do yourself a favor and learn string formating... > log(repr(DelNotePrinter)) > printer = DelNotePrinter(disPrint,int(count)) > The DelNotePrinter.py file cannot us log even though it is declared > as global. In Python, "global" means "module-level", and it's only necessary when you want to rebind a module-level name from within a function or method. The code is... > > # coding=utf8 > # DelNotePrinter = code to print delivery notes > assorted imports removed for space reasons Some of these imports surely explain why you don't just get a NameError when trying to call log() - wild guess : you have some "from xxx import *" statement that does import another callable named 'log'. > class DelNotePrinter(object): > ''' Print Delivery Note on A5 in portrait ''' > def __init__(self,printer,copies): > ''' create printer and painter ''' > global font,sm,log > log('DelNotePrinter: starting') > self.printer = QPrinter(QPrinter.HighResolution) If you want to access a name (function, class, whatever) defined in another module, you have to explicitely import it. > > The file the log writes contains.. > disPrint is:HP Deskjet 6940 series > count is:1 > > > The > is followed by a newline and end of file! Where is the > DelNotePrinter: starting message? We can't tell - but you can get at least some hint, cf below > If I replace the opening of __init__ with > global font,sm,log > f = open('d:\logfile.txt','a') > f.write('DelNotePrinter: starting' + "\n") > f.close() > self.printer = QPrinter(QPrinter.HighResolution) > > then the message IS written to the log file. Obviously, yes. Now please add this to your code: class DelNotePrinter(object): ''' Print Delivery Note on A5 in portrait ''' def __init__(self,printer,copies): ''' create printer and painter ''' global font,sm,log f = open('d:\logfile.txt','a') f.write('DelNotePrinter: starting' + "\n") # check what "log" is bound to in the currrent namespace f.write( "DelNotePrinter : log is '%s' from '%s'" % ( log, log.__module__ )) f.close() self.printer = QPrinter(QPrinter.HighResolution) > I have read http://docs.python.org/reference/simple_stmts.html#global > very carefully and I still don't understand. The statement definition makes no sense if you don't understand namespaces and bindings: http://docs.python.org/reference/executionmodel.html#naming-and-binding From marduk at letterboxes.org Tue Sep 7 07:14:00 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 07 Sep 2010 07:14:00 -0400 Subject: The Samurai Principle In-Reply-To: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: <1283858040.628347.2.camel@paska> On Mon, 2010-09-06 at 20:48 -0700, Phlip wrote: > Pythonistas: > > The "Samurai Principle" says to return victorious, or not at all. This > is why django.db wisely throws an exception, instead of simply > returning None, if it encounters a "record not found". How does that compare to, say, the "Kamikaze Principle"? ;) -a From sajuptpm at gmail.com Tue Sep 7 07:22:08 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Tue, 7 Sep 2010 04:22:08 -0700 (PDT) Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> <109hl7-ao8.ln1@satorlaser.homedns.org> Message-ID: <7bbe7204-f7dd-4054-97bd-7973ade72dc7@n19g2000prf.googlegroups.com> On Sep 7, 1:16?pm, Ulrich Eckhardt wrote: > sajuptpm wrote: > > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > > ((cpu_util,mem_util),(disk_util))] > > ie, l = [((30,50),(70)), ((50,20),(20))] > > > l.sort(key=lambda x:(-x[0][0], x[1][0])) > > # sorting cpu_util asc and disk_util desc > > One thing here: Without knowing what special meaning the indices have, this > code is impossible to understand. In my opinion, that code should rather be > > ? l.sort(key=lambda x: (-x.cpu_util, x.disk_util)) > > You could then save the comment, which btw may or may not describe the > actual code. > > > suppose i changed order that is l = [((mem_util,cpu_util), > > (disk_util)), ((mem_util,cpu_util),(disk_util))] > > So i have to change the sort code to l.sort(key=lambda x:(-x[0][1], > > x[1][0])) # sorting cpu_util asc and disk_util desc > > > I want to use same (common) sort code, that must work even if i > > changed tuple order. > > You don't have to use a lambda function. You can as well define the sorting > order in the same place of your code where you define the order inside the > elements, that way you would only have to adjust the sorting in one place. > > Otherwise, you will have to embed the order of the tuple inside the tuple or > the containing list. One approach would be to have a dictionary (which has > no order), or you use a separate type instead: > > ? class record(object): > ? ? ? pass > > ? r = record() > ? r.cpu_util = 12 > ? r.disk_util = 42 > ? l.append(r) > > However, this basically all boils down to either "don't use the sorting > (dict)" or "keep records sorted", so it doesn't really answer your > question. However, I'm afraid there is no answer to your question as it > stands. Maybe I could help you better if you explained why the order > changes etc, because normally I don't deal with data that has such a > volatile meaning, I rather normalize it on input and then use it in the > same way afterwards. > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 [((cpu_util,mem_util),(disk_util)),((cpu_util,mem_util),(disk_util))] i want to find the loaded machine based on cpu and mem and desk utilization by changing this order. I created a UI using that i can change the order of item in the tuple. But the problem is asc and desc sorting From raoulbia at gmail.com Tue Sep 7 07:39:37 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 04:39:37 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> Message-ID: On 7 sep, 02:18, Ben Finney wrote: > Ben Finney writes: > > We value respect for people here, and that's what you've been shown > > consistently. But respect for opinions, or for delicacy about > > learning, is not welcome here. > > Sloppy wording, I apologise. This should say ?? is not respect for a > person?. > > > In other words, we treat people as adults by default. I hope you'll > > continue to participate in that spirit. > > This is the main thrust of the message. > > -- > ?\ ? ? ? ??What if the Hokey Pokey IS what it's all about?? ?anonymous | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney Yes Master :) From contact at xavierho.com Tue Sep 7 07:46:20 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 7 Sep 2010 21:46:20 +1000 Subject: Minimum and Maximum of a list containing floating point numbers In-Reply-To: <4C858DDA.2090103@mrabarnett.plus.com> References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <4C858DDA.2090103@mrabarnett.plus.com> Message-ID: On 7 September 2010 10:56, MRAB wrote: > > > Incidentally, there's a builtin function called 'input' so using it as > a variable name is a discouraged! :-) Right-o! Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From raoulbia at gmail.com Tue Sep 7 07:59:01 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 04:59:01 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> Message-ID: <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> On 7 sep, 13:39, Baba wrote: > On 7 sep, 02:18, Ben Finney wrote: > > > > > > > Ben Finney writes: > > > We value respect for people here, and that's what you've been shown > > > consistently. But respect for opinions, or for delicacy about > > > learning, is not welcome here. > > > Sloppy wording, I apologise. This should say ?? is not respect for a > > person?. > > > > In other words, we treat people as adults by default. I hope you'll > > > continue to participate in that spirit. > > > This is the main thrust of the message. > > > -- > > ?\ ? ? ? ??What if the Hokey Pokey IS what it's all about?? ?anonymous | > > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | > > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > > Ben Finney > > Yes Master :) Sloppy wording, I apologise. This should say: If you find the question you're reading too easy then just don't answer. Noone is the owner of a democratic forum where freedom to ask the question one likes is paramount (as long of course as it is related to the group)...so let me repeat that, to say "Please do us a favour and at least try to figure things out on your own" is in my view inappropriate. To me it sounds "Do me a favur and get lost". Can you not understand that? I accept that it might not have been meant that way but see, misunderstandings happen easily so a more subtle approach is a wothwhile effort. My point: i always encourage people to get down from their ivory towers and to connect to the people...yes they will sometimes be lazy but they are genuine and very respectful (unlike what you think)... no offence now ok, it's not all that serious...open your mind, let lose all that righteousness and let's enjoy life :) Baba From raoulbia at gmail.com Tue Sep 7 08:05:56 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 05:05:56 -0700 (PDT) Subject: mutate dictionary or list Message-ID: Hi I am working on an exercise which requires me to write a funtion that will check if a given word can be found in a given dictionary (the hand). def is_valid_word(word, hand, word_list): """ Returns True if word is in the word_list and is entirely composed of letters in the hand. Otherwise, returns False. Does not mutate hand or word_list.""" I don't understand this part: Does not mutate hand or word_list I tried to google "python mutate list input" but to no avail It would be great if someone could give me a brief explanantion of the mutation concept. I know that a ditionary is unordered. How Can i however avoid 'acidental' mutation? Thanks Baba From roy at panix.com Tue Sep 7 08:09:12 2010 From: roy at panix.com (Roy Smith) Date: Tue, 07 Sep 2010 08:09:12 -0400 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> 1283665528.29444.python-list@pyyyyyyyyyy <4c83b425$0$28657$c3e8da3@news.astraweb.com> Message-ID: In article , "BartC" wrote: > (BTW why doesn't Python 3 just accept 'xrange' as a > synonym for 'range'?) If you've ever tried to maintain a legacy code base, you'll understand why "there's only one way to do it" is A Good Thing. Imagine that you're looking at some code which was written years ago, by people who are no longer around to answer questions. In one place, you see: for i in range(n): blah and in another, you see: for j in xrange(n): blah If you are truly a Python expert, you'll say to yourself, "range and xrange are synonyms", and move on to other things. If, however, you're not really an expert, you'll look at this and say, "Hmmm, in one place they used range(), and in another they used xrange(). Clearly, there's some reason for the difference, I need to figure out what it is, because that's probably key to my understanding why this code isn't working". So, you spend the next two hours pouring over reference manuals trying to understand the subtle difference, until your friend comes over and says, "You dolt, you just wasted half the afternoon. They're the same thing. Move on, this is not the bug you're looking for". If you think stuff like that can't happen, you've probably never jumped into the middle of a legacy code base written in a language you don't know very well. From fabio at aptana.com Tue Sep 7 08:13:04 2010 From: fabio at aptana.com (Fabio Zadrozny) Date: Tue, 7 Sep 2010 09:13:04 -0300 Subject: Pydev 1.6.2 Released Message-ID: Hi All, Pydev 1.6.2 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Pydev is now also distributed with Aptana Studio 3, so it can be gotten in a version that doesn't require installing it as a separate plugin. Get it at: http://aptana.com/products/studio3/download * Django templates editor (requires Aptana Studio 3) o Supports HTML files with HTML, CSS and Javascript o Supports CSS files o Outline page o Code-completion for Django templates based on templates (window > preferences > pydev > django templates editor > templates) o Code-completion for HTML, CSS and Javascript o Syntax highlighting based on the templates with the 'Django tags' context o Colors based on the Aptana themes * Python 2.7 grammar supported * Fixed indexing issue on contents getting getting stale in the cache * Fixed issue where the partitioning became wrong when entering a multiline string * Colors in the compare editor are now correct when using the Aptana themes * Extract method refactoring now works with "import" and "from ... import" inside a method * Source folders now appear before other folders * Fixed False positive on code analysis when using the property decorator What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/ Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From contact at xavierho.com Tue Sep 7 08:13:14 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 7 Sep 2010 22:13:14 +1000 Subject: mutate dictionary or list In-Reply-To: References: Message-ID: On 7 September 2010 22:05, Baba wrote: > > It would be great if someone could give me a brief explanantion of the > mutation concept. > In this case, to mutate is to change. If you must not mutate the list, you must not change it. In another words, reading from the list is fine. Writing to it is not. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From sajuptpm at gmail.com Tue Sep 7 09:24:06 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Tue, 7 Sep 2010 06:24:06 -0700 (PDT) Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) Message-ID: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> I have a list of tuples. l = [((30,50),(70)), ((50,20),(20))] for i in range(10): k = ((i+30,i+50),(i+70))#suppose creating new tuple in each iteration using some random value and in sert it into list. flag=True for i, v in enumerate(l): if v >= k: l.insert(i,k) flag = False break if flag: l.append(k) This code will give a list of tuples sorted in asc order. I need to change this code to sort this list by k[0][0] ascending and k[0][1] descending. What are the modifications needed in this code. I dont want to user sort() method of list. i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in another way .I want to know what the modification needed in the 'if' check to sort this list of tuples in k[0][0] ascending and k[0][1] descending. From phlip2005 at gmail.com Tue Sep 7 09:40:16 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 06:40:16 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> > How does that compare to, say, the "Kamikaze Principle"? ;) Return victorious AND not at all! (All return values are packed up and thrown...;) From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 09:42:14 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 15:42:14 +0200 Subject: accessing a text file In-Reply-To: <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> Message-ID: <4c86412e$0$5821$426a34cc@news.free.fr> Baba a ?crit : (snip) > If i had > received a friendly response from Benjamin (as opposed to "Please do > us a favor and at least try to figure things out on your own") According to usenet standards and given your initial question, this is a _very_ friendly answer. From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 09:55:47 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 15:55:47 +0200 Subject: mutate dictionary or list In-Reply-To: References: Message-ID: <4c86445c$0$12641$426a74cc@news.free.fr> Baba a ?crit : > Hi > > I am working on an exercise which requires me to write a funtion that > will check if a given word can be found in a given dictionary (the > hand). > > def is_valid_word(word, hand, word_list): > """ > Returns True if word is in the word_list and is entirely > composed of letters in the hand. Otherwise, returns False. > Does not mutate hand or word_list.""" > > I don't understand this part: Does not mutate hand or word_list Everything in Python is an object. A few objects are immutable (ints, strings, tuples...), ie you there's no way to modify the state of the object in place. Most objects are mutable, and this obviously includes lists and dicts (you can add / remove / replace list or dicts elements). Now the point is that when passing an object as argument to a function, you don't pass a copy of the object but the object itself, so if the object is mutable, you can mutate if from within the function. A simple (and really dumb) example being worth a thousand words: # mutate.py def update_dict(dic, key, value): print "in update_dic : dic id is %s" % id(dic) dic[key] = value def main(): dic = dict(a=1, b=2) lst = [1, 2, 3] print "in main : dic id is %s" % id(dic) print "dic : %s" % dic print "calling update_dict" update_dict(dic, "c", 3) print "after update_dict" print "in main : dic id is %s" % id(dic) print "dic : %s" % dic if __name__ == '__main__': main() > > I know that a ditionary is unordered. How Can i however avoid > 'acidental' mutation? This has nothing to do with dicts being ordered or not. And there's NO "accidental" mutation - you have to explicitely call a method or operator that mutate the dict. From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 09:56:42 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 15:56:42 +0200 Subject: The Samurai Principle In-Reply-To: <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> Message-ID: <4c864493$0$12641$426a74cc@news.free.fr> Phlip a ?crit : >> How does that compare to, say, the "Kamikaze Principle"? ;) > > Return victorious AND not at all! > > (All return values are packed up and thrown...;) ... and then it raises a SystemError !-) From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 09:58:18 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 15:58:18 +0200 Subject: Help needed - function apparently global cannot be called. In-Reply-To: References: Message-ID: <4c8644f3$0$12641$426a74cc@news.free.fr> Ian Hobson a ?crit : (snip) you may also want to read the recent "using modules" thread... From hobson42 at gmaiil.com Tue Sep 7 10:00:37 2010 From: hobson42 at gmaiil.com (Ian) Date: Tue, 07 Sep 2010 15:00:37 +0100 Subject: Help needed - function apparently global cannot be called. In-Reply-To: <4c8618e5$0$8784$426a74cc@news.free.fr> References: <4c8618e5$0$8784$426a74cc@news.free.fr> Message-ID: <4C864585.3050204@gmaiil.com> Hi Bruno, Thanks for your quick response. I still do not understand. On 07/09/2010 11:50, Bruno Desthuilliers wrote: > Ian Hobson a ?crit : >> Hi all you experts, >> >> This has me beat. Has anyone any ideas about what might be going wrong? >> >> This is code from within a windows service (hence no print statements >> - no sys.stdout to print on!). >> >> I am trying to trace through to find where the code is not working. >> No stdout so I have to log to a file. > > Then you'd be better using the logging module from the stdlib. And > FWIW, you should try to make you code testable in a non-service > context... Thanks for the tip. "Batteries included" means there are so many batteries you miss some. The Module I am trying to use works perfectly as a free standing routine. > >> I have the following code fragments. >> >> def log(message): >> f = open('d:\logfile.txt','a') >> f.write(message + "\n") >> f.close() >> >> from DelNotePrinter import DelNotePrinter > > > The convention is to use all_lower_names for modules - having modules > and classes with the same (case-sensitive) name can be very misleading. > The convention is a good one. > >> note the order of the above - log is defined before the import. > > And ? Do you think it will affect the imported module in any way ? > Like, say, magically "inject" your log function in the DelNotePrinter > module ?-) Just that log is defined before the global log is encountered to that if the compiler needed to set up a link at compile time it was able to do so. > > >> Later in the source > > Where ? > About 350 lines further down. >> I have >> >> log('disPrint is:'+disPrint) >> log('count is:'+count) > > Do yourself a favor and learn string formating... Agreed. :) - These are debug statements to discover what is going on. I have had so much trouble with problems NOT being reported, that I avoid anything that I am not 100% sure must work. > >> log(repr(DelNotePrinter)) >> printer = DelNotePrinter(disPrint,int(count)) > > >> The DelNotePrinter.py file cannot us log even though it is declared >> as global. > > In Python, "global" means "module-level", and it's only necessary when > you want to rebind a module-level name from within a function or method. Exactly! I want to bind the name log to the function I wrote. So I carefully placed log in global scope and told the compiler that when I referred to log I meant the global one I wrote. I expected that to bind log to the function I wrote. The compiler did not complain it was undefined (which would have caused a trackback on the Event log). But neither was the routine called. :( I still don't understand what is going wrong. > > The code is... >> >> # coding=utf8 >> # DelNotePrinter = code to print delivery notes >> assorted imports removed for space reasons > > Some of these imports surely explain why you don't just get a > NameError when trying to call log() - wild guess : you have some "from > xxx import *" statement that does import another callable named 'log'. > I don't think so. The lines are import sys import datetime from PyQt4.QtCore import * from PyQt4.QtGui import * from DataBaseClass import DataBase I know all PyQt classes begin with Q. Database I wrote, and it has no log in it. >> class DelNotePrinter(object): >> ''' Print Delivery Note on A5 in portrait ''' >> def __init__(self,printer,copies): >> ''' create printer and painter ''' >> global font,sm,log >> log('DelNotePrinter: starting') > > >> self.printer = QPrinter(QPrinter.HighResolution) > > If you want to access a name (function, class, whatever) defined in > another module, you have to explicitely import it. > >> >> The file the log writes contains.. >> disPrint is:HP Deskjet 6940 series >> count is:1 >> >> >> The > is followed by a newline and end of file! Where is the >> DelNotePrinter: starting message? > > We can't tell - but you can get at least some hint, cf below > >> If I replace the opening of __init__ with >> global font,sm,log >> f = open('d:\logfile.txt','a') >> f.write('DelNotePrinter: starting' + "\n") >> f.close() >> self.printer = QPrinter(QPrinter.HighResolution) >> >> then the message IS written to the log file. > > Obviously, yes. Now please add this to your code: > > class DelNotePrinter(object): > ''' Print Delivery Note on A5 in portrait ''' > def __init__(self,printer,copies): > ''' create printer and painter ''' > global font,sm,log > f = open('d:\logfile.txt','a') > f.write('DelNotePrinter: starting' + "\n") > > # check what "log" is bound to in the currrent namespace > f.write( > "DelNotePrinter : log is '%s' from '%s'" % ( > log, log.__module__ > )) > f.close() > self.printer = QPrinter(QPrinter.HighResolution) > I tried that (using copy/paste) and got no output! So I modified is slightly to global log f = open('d:\logfile.txt','a') f.write("test message\n") f.write( "DelNotePrinter : log is '%s' from '%s'" % ( log, log.__module__ )) f.close() self.printer = QPrinter(QPrinter.HighResolution) I get my "test message" and then nothing. When I close the service, the next log message comes from the closing code. There are no errors reported, no messages, no Event log entries and nothing further happens. Its as if the thread died. >> I have read http://docs.python.org/reference/simple_stmts.html#global >> very carefully and I still don't understand. > > The statement definition makes no sense if you don't understand > namespaces and bindings: > > http://docs.python.org/reference/executionmodel.html#naming-and-binding > Thanks for the pointer. What a truly execrable piece of writing - full of over-long sentences and multiple subordinate clauses. It routinely uses terms before definition, and sometimes without definition. It is astonishingly bad. The third sentence reads "Each occurrence of a name in the program text refers to the /binding/ of that name established in the innermost function block containing the use." What does that mean? It appears to mean that it is the assignment in the innermost function block that binds for all uses, not the first, not module blocks, not class blocks and not code blocks - but the innermost function block. That might be correct, but somehow I doubt it, for it would mean that earlier bindings are ignored or invalidated or not used or something - even if the inner block is not executed. I am not stupid and English is my mother tongue, and I have read that page many times. The implications of the passage are still opaque to me. How can I call a global function placed at the top of the source. Do I really have to move a 4 line function into its own file and import it again and again and again? Regards Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Sep 7 10:03:44 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 16:03:44 +0200 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: sajuptpm wrote: > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in > another way .I want to know what the modification needed in the 'if' > check to sort this list of tuples in k[0][0] ascending and k[0][1] > descending. It seems you are not getting any closer to your goal. Perhaps it would help if you could explain that goal clearly rather than describing the means you are employing to achieve it. > I have a list of tuples. > > l = [((30,50),(70)), ((50,20),(20))] By the way, (42) is not a tuple, it's an integer. To turn it into a 1-tuple you have to add a ',': >>> (42) 42 >>> (42,) (42,) >>> 42, (42,) Peter From deets at web.de Tue Sep 7 10:12:00 2010 From: deets at web.de (deets at web.de) Date: Tue, 07 Sep 2010 16:12:00 +0200 Subject: mutate dictionary or list References: Message-ID: <87zkvt4p8v.fsf@web.de> Baba writes: > Hi > > I am working on an exercise which requires me to write a funtion that > will check if a given word can be found in a given dictionary (the > hand). > > def is_valid_word(word, hand, word_list): > """ > Returns True if word is in the word_list and is entirely > composed of letters in the hand. Otherwise, returns False. > Does not mutate hand or word_list.""" > > I don't understand this part: Does not mutate hand or word_list > > I tried to google "python mutate list input" but to no avail > > It would be great if someone could give me a brief explanantion of the > mutation concept. Objects can be mutable or immutable. For example, in Python, integers, strings, floats and tuples are immutable. That means that you can't change their value. Mutable objects OTOH can be changed. For example, a list is mutable: l = ["foo"] l.append("bar") # mutating method print l #-> ['foo', 'bar'] That's all there is to it. So for the example at hand, don't use anything that mutates the passed arguments. E.g, if word_list really is a list, and for faster lookup of "word", you want to sort it, you are not allowed to do this: word_list.sort() # mutating!! Instead, you need to do new_word_list = sorted(word_list) # creates a *copy* of word_list, which is sorted. Actually, you can also try & use the module copy's "deepcopy"-function to ensure that you don't mutate the passed objects. Please not that this is *not* a mutating operation: l = [1, 2] h = l l = [3, 4] print h #-> [1, 2] The original list in l is still preserved un-modified, and referenced by the name h. Just binding a different object to an existing name doesn't change anything about the old object referenced by the name. Diez From sajuptpm at gmail.com Tue Sep 7 10:22:02 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Tue, 7 Sep 2010 07:22:02 -0700 (PDT) Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: On Sep 7, 7:03?pm, Peter Otten <__pete... at web.de> wrote: > sajuptpm wrote: > > i need to implement ?l.sort(key=lambda x:(x[0][0], -x[1][0])) in > > another way .I want to know what the modification needed in the 'if' > > check to sort this list of tuples in k[0][0] ascending and k[0][1] > > descending. > > It seems you are not getting any closer to your goal. Perhaps it would help > if you could explain that goal clearly rather than describing the means you > are employing to achieve it. > > > I have a list of tuples. > > > l = [((30,50),(70)), ((50,20),(20))] > > By the way, (42) is not a tuple, it's an integer. To turn it into a 1-tuple > you have to add a ',': > > >>> (42) > 42 > >>> (42,) > (42,) > >>> 42, > > (42,) > > Peter I have a list of tuples. l = [((30,50),(70,)), ((50,20),(20,))] for i in range(10): k = ((i+30,i+50),(i+70))#suppose creating new tuple in each iteration using some random value and in sert it into list. flag=True for i, v in enumerate(l): if v >= k: l.insert(i,k) flag = False break if flag: l.append(k) This code will give a list of tuples sorted in asc order. I need to change this code to sort this list by k[0][0] ascending and k[0][1] descending. What are the modifications needed in this code. I dont want to user sort() method of list. i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in another way .I want to know what the modification needed in the 'if' check to sort this list of tuples in k[0][0] ascending and k[0][1] descending. From debatem1 at gmail.com Tue Sep 7 10:23:04 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 7 Sep 2010 07:23:04 -0700 Subject: The Samurai Principle In-Reply-To: <4c864493$0$12641$426a74cc@news.free.fr> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> Message-ID: On Tue, Sep 7, 2010 at 6:56 AM, Bruno Desthuilliers wrote: > Phlip a ?crit : >>> >>> How does that compare to, say, the "Kamikaze Principle"? ;) >> >> Return victorious AND not at all! >> >> (All return values are packed up and thrown...;) > > ... and then it raises a SystemError !-) general protection fault Geremy Condra From bussiere at gmail.com Tue Sep 7 10:31:34 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Tue, 7 Sep 2010 16:31:34 +0200 Subject: knowing the caller of an import && exec question Message-ID: i've got toto.py : import titi def niwhom(): pass and titi.py : def nipang(): pass how can i know in titi.py that's it's toto.py that is calling titi.py and the path of toto ? And why : bidule.py : class bidetmusique: pass truc.py : X = __import__("bidule") why exec("X.bidetmusique()") return none and X.bidetmusique() return an object ? How could i do to make this string "X.bidetmusique()" return an object ? Regards and thanks Bussiere Eat the strawberry Google Fan boy From __peter__ at web.de Tue Sep 7 10:32:12 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 16:32:12 +0200 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: sajuptpm wrote: > On Sep 7, 7:03 pm, Peter Otten <__pete... at web.de> wrote: >> sajuptpm wrote: >> > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in >> > another way .I want to know what the modification needed in the 'if' >> > check to sort this list of tuples in k[0][0] ascending and k[0][1] >> > descending. >> >> It seems you are not getting any closer to your goal. Perhaps it would >> help if you could explain that goal clearly rather than describing the >> means you are employing to achieve it. >> >> > I have a list of tuples. >> >> > l = [((30,50),(70)), ((50,20),(20))] >> >> By the way, (42) is not a tuple, it's an integer. To turn it into a >> 1-tuple you have to add a ',': >> >> >>> (42) >> 42 >> >>> (42,) >> (42,) >> >>> 42, >> >> (42,) >> >> Peter > > > I have a list of tuples. > > l = [((30,50),(70,)), ((50,20),(20,))] > > for i in range(10): > k = ((i+30,i+50),(i+70))#suppose creating new tuple in each > iteration > using some random value and in sert it into list. > > flag=True > for i, v in enumerate(l): > if v >= k: > l.insert(i,k) > flag = False > break > if flag: > l.append(k) > > This code will give a list of tuples sorted in asc order. > I need to change this code to sort this list by k[0][0] ascending and > k[0][1] descending. > What are the modifications needed in this code. > I dont want to user sort() method of list. > > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in > another way .I want to know what the modification needed in the 'if' > check to sort this list of tuples in k[0][0] ascending and k[0][1] > descending. As a thought experiment assume that your audience had never heard of tuples or even Python. How would you then explain your goal? Peter From ben+python at benfinney.id.au Tue Sep 7 10:37:29 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Sep 2010 00:37:29 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> Message-ID: <87tym1bowm.fsf@benfinney.id.au> Baba writes: > to say "Please do us a favour and at least try to figure things out on > your own" is in my view inappropriate. That's what the person wanted you to see. How would you prefer that exact information to be imparted to you? How could it have been communicated so that it was not misunderstood? > To me it sounds "Do me a favur and get lost". Can you not understand > that? Honestly, I cannot read that meaning into the messages you've received in this forum. Please help us by showing how you think people could say what was said above without losing information. > no offence now ok, it's not all that serious...open your mind, let > lose all that righteousness and let's enjoy life :) All well and good, but let's try to see what went wrong in communication here and fix it. -- \ ?Faith, n. Belief without evidence in what is told by one who | `\ speaks without knowledge, of things without parallel.? ?Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney From aahz at pythoncraft.com Tue Sep 7 10:46:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Sep 2010 07:46:16 -0700 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: In article , BartC wrote: >"Steven D'Aprano" wrote in message >news:4c85adfe$0$11115$c3e8da3 at news.astraweb.com... >> >> xrange = range >> >> There, that wasn't hard, was it? > >I think I just learned more about Python than from months of reading this >group. > >So 'range' is just a class like any other. And that a class is something you >can blithely copy from one variable to another. And whenever you see 'range' >anywhere, you can't always be certain that someone hasn't done: > >range = 42 > >at some point. That explains a lot about the difficulties of implementing >Python efficiently. (And the xrange=range trick works well thanks.) Actually, range() is a function. But the same point applies, squared -- you really can never know what kind of object is hiding behind a name in the general case. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From ben+python at benfinney.id.au Tue Sep 7 10:46:43 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Sep 2010 00:46:43 +1000 Subject: mutate dictionary or list References: <87zkvt4p8v.fsf@web.de> Message-ID: <87pqwpboh8.fsf@benfinney.id.au> deets at web.de writes: > Objects can be mutable or immutable. For example, in Python, integers, > strings, floats and tuples are immutable. That means that you can't > change their value. Yes. Importantly, wherever you see code that you *think* is changing the value of an immutable object, you're thinking incorrectly. (There's no shame in that; other languages give us preconceptions that can be hard to shake off.) The only way to get a different value from an integer object is to ask Python for a different integer object; the original is unchanged. The same goes for tuples, strings, and all the other immutable types. > Mutable objects OTOH can be changed. [?] Some good articles to explain Python's object model: -- \ ?We can't depend for the long run on distinguishing one | `\ bitstream from another in order to figure out which rules | _o__) apply.? ?Eben Moglen, _Anarchism Triumphant_, 1999 | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 10:48:31 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 16:48:31 +0200 Subject: knowing the caller of an import && exec question In-Reply-To: References: Message-ID: <4c8650b8$0$9920$426a74cc@news.free.fr> bussiere bussiere a ?crit : > i've got toto.py : > > import titi > def niwhom(): > pass > > and titi.py : > > def nipang(): > pass > > how can i know in titi.py that's it's toto.py that is calling titi.py > and the path of toto ? You'd have to inspect the call stack. Not for the faint at heart... > And > > why : > > bidule.py : > class bidetmusique: > pass The naming convention is to capitalize class names, ie "Bidetmusique" or "BidetMusique" Heureusement qu'il n'y a pas grand monde ici pour comprendre le fran?ais, parce que comme nommage, ?a bat des records, l? !-) > > truc.py : > X = __import__("bidule") > > why exec("X.bidetmusique()") return none exec doesn't "return" anything - it executes code in a given context, eventually modifying the context. Now given your above code, a new bidetmusique instance is indeed created, but since it's not bound to anything, it's immediatly discarded. > and X.bidetmusique() return an object ? cf above > How could i do to make this string "X.bidetmusique()" return an object ? exec is 99 time out of 10 (nope, not a typo) the wrong solution. You already found how to dynamically import a module by name (I mean, name given as as string), all you need know is to find out how to dynamically retrieve a module attribute given it's name as string. And the answer is "getattr": # truc.py : X = __import__("bidule") cls = getattr(X, "bidetmusique") obj = cls() print obj HTH From contactprashantat at gmail.com Tue Sep 7 10:48:57 2010 From: contactprashantat at gmail.com (Prashant Kumar) Date: Tue, 7 Sep 2010 07:48:57 -0700 (PDT) Subject: Volunteer help with porting Message-ID: <5f12e647-14a7-43c4-ae5f-2dc91c7ddc5f@q40g2000prg.googlegroups.com> Hi everyone, My name is Prashant Kumar and I wish to contribute to the Python development process by helping convert certain existing python over to python3k. Is there anyway I could obtain a list of libraries which need to be ported over to python3k, sorted by importance(by importance i mean packages which serve as a dependency for larger number of packages being more important). I had originally mailed the python-dev mailing list and was pointed to this ML so that I could get details regarding 3rd party libraries which need to be ported. Thanks, Prashant Kumar From invalid at invalid.invalid Tue Sep 7 10:50:05 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 7 Sep 2010 14:50:05 +0000 (UTC) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> Message-ID: On 2010-09-07, Baba wrote: > Sloppy wording, I apologise. This should say: If you find the > question you're reading too easy then just don't answer. Noone is the > owner of a democratic forum where freedom to ask the question one > likes is paramount (as long of course as it is related to the > group)...so let me repeat that, to say "Please do us a favour and at > least try to figure things out on your own" is in my view > inappropriate. You need to read this: http://www.catb.org/esr/faqs/smart-questions.html > To me it sounds "Do me a favur and get lost". No, it means "Do yourself a favor, learn how to do things yourself." Remember: you're then one asking people to give you something for free. It's not up to them to conform to your expectations, rather you need to conform to theirs. Otherwise, they'll just ignore you. -- Grant Edwards grant.b.edwards Yow! FOOLED you! Absorb at EGO SHATTERING impulse gmail.com rays, polyester poltroon!! From pruebauno at latinmail.com Tue Sep 7 10:52:22 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 7 Sep 2010 07:52:22 -0700 (PDT) Subject: Minimum and Maximum of a list containing floating point numbers References: <17102528-8381-4875-9db3-ec6996864397@f6g2000yqa.googlegroups.com> <87fwxmcqpu.fsf@benfinney.id.au> <4c85a3f5$0$11115$c3e8da3@news.astraweb.com> Message-ID: <10aba5d5-e24a-4392-aa4a-fccb63afef7b@i5g2000yqe.googlegroups.com> On Sep 6, 10:31?pm, Steven D'Aprano wrote: > On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote: > > If you're going to use the list of float objects, you can convert them > > all with a list comprehension. > [...] > > ? ? >>> numbers_as_float = [float(x) for x in numbers_as_str] > > That's awfully verbose. A map is simpler: > > numbers_as_float = map(float, numbers_as_str) > > -- > Steven In Python 3.x it has one disadvantage: >>> numbers_as_float = map(float, numbers_as_str) >>> max(numbers_as_float) 10.24 >>> min(numbers_as_float) Traceback (most recent call last): File "", line 1, in min(numbers_as_float) ValueError: min() arg is an empty sequence >>> From no.email at please.post Tue Sep 7 11:33:55 2010 From: no.email at please.post (kj) Date: Tue, 7 Sep 2010 15:33:55 +0000 (UTC) Subject: audio time-stretching? Message-ID: Does anyone know of a Python module for *moderate* "time-stretching"[1] an MP3 (or AIFF) file? FWIW, the audio I want to time-stretch is human speech. TIA! ~K [1] By "moderate time stretching" I mean, for example, taking an audio that would normally play in 5 seconds, and stretch it so that it plays in 7.5 seconds, keeping the pitch unchanged. A lot of software out there does this badly; e.g. the time-stretched audio springs extraneous "beats" of intensity that are very obtrusive and annoying; I guess it's some weird wave self-interference effect. Also, I stress *moderate* time stretching to explicitly rule out the extreme (~50X) time-stretching that software like PaulStretch is designed to accomplish. From phlip2005 at gmail.com Tue Sep 7 12:02:49 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 09:02:49 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> Message-ID: <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Back to the topic, I tend to do this: for record in Model.objects.filter(pk=42): return record return sentinel Having lots of short methods helps, because return provides both control-flow and a result value. But it abuses 'for' to mean 'if'. I feel _reeeeally_ guilty about that! But I miss this, from (cough) RoR: record = Model.find(42) || sentinel Django should provide this: record = Model.objects.get(pk=42, _if_does_not_exist=sentinel) sentinel could be a lambda that concocts a new record (where such a record should not be created with get_or_create()). That would be efficient when you don't spend time constructing it just so the happy- path of .get() can throw it away. Or sentinel could be None, or a NullObject that efficiently behaves like a record but provides stubbed-out behaviors. My committees will be submitting these proposals to the Django committees shortly... C-: -- Phlip From debatem1 at gmail.com Tue Sep 7 12:48:52 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 7 Sep 2010 09:48:52 -0700 Subject: accessing a text file In-Reply-To: References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> Message-ID: On Tue, Sep 7, 2010 at 4:39 AM, Baba wrote: > On 7 sep, 02:18, Ben Finney wrote: >> Ben Finney writes: >> > We value respect for people here, and that's what you've been shown >> > consistently. But respect for opinions, or for delicacy about >> > learning, is not welcome here. >> >> Sloppy wording, I apologise. This should say ?? is not respect for a >> person?. >> >> > In other words, we treat people as adults by default. I hope you'll >> > continue to participate in that spirit. >> >> This is the main thrust of the message. >> >> -- >> ?\ ? ? ? ??What if the Hokey Pokey IS what it's all about?? ?anonymous | >> ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | >> _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| >> Ben Finney > > Yes Master :) This is in almost impressively poor taste. I know I'm done helping you now. Geremy Condra From briandenzer at gmail.com Tue Sep 7 13:01:01 2010 From: briandenzer at gmail.com (Brian D) Date: Tue, 7 Sep 2010 10:01:01 -0700 (PDT) Subject: What the \xc2\xa0 ?!! Message-ID: <662d8f01-f1f6-44a4-86e3-694b9b6a73ba@v41g2000yqv.googlegroups.com> In an HTML page that I'm scraping using urllib2, a \xc2\xa0 bytestring appears. The page's charset = utf-8, and the Chrome browser I'm using displays the characters as a space. The page requires authentication: https://www.nolaready.info/myalertlog.php When I try to concatenate strings containing the bytestring, Python chokes because it refuses to coerce the bytestring into ascii. wfile.write('|'.join(valueList)) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 163: ordinal not in range(128) In searching for help with this issue, I've learned that the bytestring *might* represent a non-breaking space. When I scrape the page using urllib2, however, the characters print as ?? in a Windows command prompt (though I wouldn't be surprised if this is some erroneous attempt by the antiquated command window to handle something it doesn't understand). If I use IDLE to attempt to decode the single byte referenced in the error message, and convert it into UTF-8, another error message is generated: >>> weird = unicode('\xc2', 'utf-8') Traceback (most recent call last): File "", line 1, in weird = unicode('\xc2', 'utf-8') UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 0: unexpected end of data If I attempt to decode the full bytestring, I don't obtain a human- readable string (expecting, perhaps, a non-breaking space): >>> weird = unicode('\xc2\xa0', 'utf-8') >>> par = ' - '.join(['This is', weird]) >>> par u'This is - \xa0' I suspect that the bytestring isn't UTF-8, but what is it? Latin1? >>> weirder = unicode('\xc2\xa0', 'latin1') >>> weirder u'\xc2\xa0' >>> 'This just gets ' + weirder u'This just gets \xc2\xa0' Or is it a Microsoft bytestring? >>> weirder = unicode('\xc2\xa0', 'mbcs') >>> 'This just gets ' + weirder u'This just gets \xc2\xa0' None of these codecs seem to work. Back to the original purpose, as I'm scraping the page, I'm storing the field/value pair in a dictionary with each iteration through table elements on the page. This is all fine, until a value is found that contains the offending bytestring. I have attempted to coerce all value strings into an encoding, but Python doesn't seem to like that when the string is already Unicode: valuesDict[fieldString] = unicode(value, 'UTF-8') TypeError: decoding Unicode is not supported The solution I've arrived at is to specify the encoding for value strings both when reading and writing value strings. for k, v in valuesDict.iteritems(): valuePair = ':'.join([k, v.encode('UTF-8')]) [snip] ... wfile.write('|'.join(valueList)) I'm not sure I have a question, but does this sound familiar to any Unicode experts out there? How should I handle these odd bytestring values? Am I doing it correctly, or what could I improve? Thanks! From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 7 13:12:02 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 19:12:02 +0200 Subject: The Samurai Principle In-Reply-To: <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <4c86725a$0$16728$426a74cc@news.free.fr> Phlip a ?crit : > Back to the topic, I tend to do this: > > for record in Model.objects.filter(pk=42): > return record > > return sentinel WTF alert here... > Having lots of short methods helps, because return provides both > control-flow and a result value. But it abuses 'for' to mean 'if'. I > feel _reeeeally_ guilty about that! > But I miss this, from (cough) RoR: > > record = Model.find(42) || sentinel > > Django should provide this: > > record = Model.objects.get(pk=42, _if_does_not_exist=sentinel) queryset.get can be used with multiple conditions - it's not necessarily restricted to pk lookups. However you name your "_if_does_not_exist" kwarg, it will be difficult to garantee that there will never be no nameclash with any possible valid model lookup argument... But if you feel like you found the correct name, you can of course monkeypatch queryset !-) From deets at web.de Tue Sep 7 13:15:47 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 07 Sep 2010 19:15:47 +0200 Subject: What the \xc2\xa0 ?!! References: <662d8f01-f1f6-44a4-86e3-694b9b6a73ba@v41g2000yqv.googlegroups.com> Message-ID: <87pqwp4gqk.fsf@web.de> Brian D writes: > In an HTML page that I'm scraping using urllib2, a \xc2\xa0 > bytestring appears. > > The page's charset = utf-8, and the Chrome browser I'm using displays > the characters as a space. > > The page requires authentication: > https://www.nolaready.info/myalertlog.php > > When I try to concatenate strings containing the bytestring, Python > chokes because it refuses to coerce the bytestring into ascii. > > wfile.write('|'.join(valueList)) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 163: ordinal not in range(128) > > In searching for help with this issue, I've learned that the > bytestring *might* represent a non-breaking space. It in fact does. > > When I scrape the page using urllib2, however, the characters print > as ?? in a Windows command prompt (though I wouldn't be surprised if > this is some erroneous attempt by the antiquated command window to > handle something it doesn't understand). Yes, it's trying to interpret that as two cp1252 (or whatever) bytes instead of one unbreakable space. > > If I use IDLE to attempt to decode the single byte referenced in the > error message, and convert it into UTF-8, another error message is > generated: > >>>> weird = unicode('\xc2', 'utf-8') > > Traceback (most recent call last): > File "", line 1, in > weird = unicode('\xc2', 'utf-8') > UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 0: > unexpected end of data Which is to be expected, as you ripped a UTF-8 escape sequence in half. > > If I attempt to decode the full bytestring, I don't obtain a human- > readable string (expecting, perhaps, a non-breaking space): You obtain a non-breakable space. What do you think it should look like in your terminal? It looks like ... nothing. Because it looks like a space. > >>>> weird = unicode('\xc2\xa0', 'utf-8') >>>> par = ' - '.join(['This is', weird]) >>>> par > u'This is - \xa0' > > I suspect that the bytestring isn't UTF-8, but what is it? Latin1? No, it is UTF-8 > >>>> weirder = unicode('\xc2\xa0', 'latin1') >>>> weirder > u'\xc2\xa0' >>>> 'This just gets ' + weirder > u'This just gets \xc2\xa0' > > Or is it a Microsoft bytestring? This is not weird, this is the python interpreter giving you the representation of a unicode-object when you do not print, so you can see what it looks like. And because you wrongly decoded it as latin1, it's garbage anyway. > >>>> weirder = unicode('\xc2\xa0', 'mbcs') >>>> 'This just gets ' + weirder > u'This just gets \xc2\xa0' > > None of these codecs seem to work. UTF-8 worked just fine. > > Back to the original purpose, as I'm scraping the page, I'm storing > the field/value pair in a dictionary with each iteration through table > elements on the page. This is all fine, until a value is found that > contains the offending bytestring. I have attempted to coerce all > value strings into an encoding, but Python doesn't seem to like that > when the string is already Unicode: > > valuesDict[fieldString] = unicode(value, 'UTF-8') > TypeError: decoding Unicode is not supported > > The solution I've arrived at is to specify the encoding for value > strings both when reading and writing value strings. > > for k, v in valuesDict.iteritems(): > valuePair = ':'.join([k, v.encode('UTF-8')]) > [snip] ... > wfile.write('|'.join(valueList)) > > I'm not sure I have a question, but does this sound familiar to any > Unicode experts out there? > > How should I handle these odd bytestring values? Am I doing it > correctly, or what could I improve? The overall solution is to decode the page or parts of it in whatever decoding it is delivered. You mentioned that the page is delivered in UTF-8, so you should use whatever gives you that information to decode the returned body. Diez From phlip2005 at gmail.com Tue Sep 7 13:20:35 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 10:20:35 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> Message-ID: <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> On Sep 7, 10:12?am, Bruno Desthuilliers wrote: > Phlip a ?crit : > > > Back to the topic, I tend to do this: > > > ? for record in Model.objects.filter(pk=42): > > ? ? ?return record > > > ? return sentinel > > WTF alert here... I don't see how anyone could WTF that. Are you pretending to be a newb who doesn't understanding it? F'em. > > Having lots of short methods helps, because return provides both > > control-flow and a result value. But it abuses 'for' to mean 'if'. I > > feel _reeeeally_ guilty about that! > > But I miss this, from (cough) RoR: > > > ? record = Model.find(42) || sentinel > > > Django should provide this: > > > ? record = Model.objects.get(pk=42, _if_does_not_exist=sentinel) > > queryset.get can be used with multiple conditions - it's not necessarily > ? restricted to pk lookups. However you name your "_if_does_not_exist" > kwarg, it will be difficult to garantee that there will never be no > nameclash with any possible valid model lookup argument... it can also be another method - .if_does_not_exist(sentinel). With a less sucky name. I would guess that Django provides some basic rules for avoiding name collisions. Nobody should call a field "pk__in", but if they do, they are screwed! But that's not important right now. > But if you feel like you found the correct name, you can of course > monkeypatch queryset !-) K now I gotta learn to add a new method to an existing class! From niklasro at gmail.com Tue Sep 7 13:27:23 2010 From: niklasro at gmail.com (Niklasro) Date: Tue, 7 Sep 2010 10:27:23 -0700 (PDT) Subject: datetime questions Message-ID: <454773b5-42e2-4223-9418-34faf12b5a90@t20g2000yqa.googlegroups.com> Hello Learning python datetime somewhat similar to SQL type timestamp my attempt creating a 24 h 2 months ago is str(datetime.now () - timedelta (days = 60)) +' cron '+ str(datetime.now () - timedelta (days = 59)) Do you agree? Can I improve this declaration? Regards Niklas Rosencrantz From ian.g.kelly at gmail.com Tue Sep 7 13:36:29 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Sep 2010 11:36:29 -0600 Subject: The Samurai Principle In-Reply-To: <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: > Back to the topic, I tend to do this: > > ?for record in Model.objects.filter(pk=42): > ? ? return record > > ?return sentinel How is that any better than just catching the exception? try: return Model.objects.get(pk=42) except Model.DoesNotExist: return sentinel The flow of control is much clearer this way. Cheers, Ian From aahz at pythoncraft.com Tue Sep 7 13:39:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Sep 2010 10:39:58 -0700 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: In article , Roy Smith wrote: > >Imagine that you're looking at some code which was written years ago, by >people who are no longer around to answer questions. In one place, you >see: > >for i in range(n): > blah > >and in another, you see: > >for j in xrange(n): > blah > >If you are truly a Python expert, you'll say to yourself, "range and >xrange are synonyms", and move on to other things. If, however, you're >not really an expert, you'll look at this and say, "Hmmm, in one place >they used range(), and in another they used xrange(). Clearly, there's >some reason for the difference, I need to figure out what it is, because >that's probably key to my understanding why this code isn't working". >So, you spend the next two hours pouring over reference manuals trying >to understand the subtle difference, until your friend comes over and >says, "You dolt, you just wasted half the afternoon. They're the same >thing. Move on, this is not the bug you're looking for". ...and if you're a Python guru, you might spend a little bit of time trying to figure out if the range() is causing the problem due to allocating a large chunk of memory.... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From raoulbia at gmail.com Tue Sep 7 13:45:52 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 10:45:52 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> Message-ID: <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> On 7 sep, 16:50, Grant Edwards wrote: > On 2010-09-07, Baba wrote: > > > Sloppy wording, I apologise. This should say: If you find the > > question you're reading too easy then just don't answer. Noone is the > > owner of a democratic forum where freedom to ask the question one > > likes is paramount (as long of course as it is related to the > > group)...so let me repeat that, to say "Please do us a favour and at > > least try to figure things out on your own" is in my view > > inappropriate. > > You need to read this: > > ?http://www.catb.org/esr/faqs/smart-questions.html > > > To me it sounds "Do me a favur and get lost". > > No, it means "Do yourself a favor, learn how to do things yourself." > > Remember: you're then one asking people to give you something for > free. It's not up to them to conform to your expectations, rather you > need to conform to theirs. ?Otherwise, they'll just ignore you. > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! FOOLED you! ?Absorb > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? EGO SHATTERING impulse > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ?rays, polyester poltroon!! "Please do us a favour" sounds condescending to me at least but maybe we Europeans are a bit touchy... However the following Wiki excerpt seems to go in my direction: "When someone makes a mistake -- whether it's a spelling error or a spelling flame, a stupid question or an unnecessarily long answer -- be kind about it. If it's a minor error, you may not need to say anything. Even if you feel strongly about it, think twice before reacting. Having good manners yourself doesn't give you license to correct everyone else. If you do decide to inform someone of a mistake, point it out politely, and preferably by private email rather than in public. Give people the benefit of the doubt; assume they just don't know any better. And never be arrogant or self-righteous about it." http://en.wikipedia.org/wiki/Netiquette Baba From phlip2005 at gmail.com Tue Sep 7 13:52:44 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 10:52:44 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On Sep 7, 10:36?am, Ian Kelly wrote: > On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: > > Back to the topic, I tend to do this: > > > ?for record in Model.objects.filter(pk=42): > > ? ? return record > > > ?return sentinel > > How is that any better than just catching the exception? > > try: > ? ? return Model.objects.get(pk=42) > except Model.DoesNotExist: > ? ? return sentinel > > The flow of control is much clearer this way. It reminds me of Visual Basic. And no it's not "much clearer". Exceptions are for catastrophic errors that the caller should care not to handle. A "record not found" is not a catastrophe. Read my original post. AAAND you need to test that the DoesNotExist occurs for the exact reason you expect. Your except is not complete. Making it complete is very hard, and will break as soon as the model changes. From johnroth1 at gmail.com Tue Sep 7 14:14:36 2010 From: johnroth1 at gmail.com (John Roth) Date: Tue, 7 Sep 2010 11:14:36 -0700 (PDT) Subject: What the \xc2\xa0 ?!! References: <662d8f01-f1f6-44a4-86e3-694b9b6a73ba@v41g2000yqv.googlegroups.com> Message-ID: <23f4a0f0-d38a-4e60-9ae7-a0ff27467e0f@y12g2000prb.googlegroups.com> On Sep 7, 11:01?am, Brian D wrote: > In an HTML page that I'm scraping using urllib2, a ?\xc2\xa0 > bytestring appears. > > The page's charset = utf-8, and the Chrome browser I'm using displays > the characters as a space. > > The page requires authentication:https://www.nolaready.info/myalertlog.php > > When I try to concatenate strings containing the bytestring, Python > chokes because it refuses to coerce the bytestring into ascii. > > wfile.write('|'.join(valueList)) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 163: ordinal not in range(128) > > In searching for help with this issue, I've learned that the > bytestring *might* represent a non-breaking space. > > When I scrape the page using urllib2, however, the characters print > as ??? ?in a Windows command prompt (though I wouldn't be surprised if > this is some erroneous attempt by the antiquated command window to > handle something it doesn't understand). > > If I use IDLE to attempt to decode the single byte referenced in the > error message, and convert it into UTF-8, another error message is > generated: > > >>> weird = unicode('\xc2', 'utf-8') > > Traceback (most recent call last): > ? File "", line 1, in > ? ? weird = unicode('\xc2', 'utf-8') > UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 0: > unexpected end of data > > If I attempt to decode the full bytestring, I don't obtain a human- > readable string (expecting, perhaps, a non-breaking space): > > >>> weird = unicode('\xc2\xa0', 'utf-8') > >>> par = ' - '.join(['This is', weird]) > >>> par > > u'This is - \xa0' > > I suspect that the bytestring isn't UTF-8, but what is it? Latin1? > > >>> weirder = unicode('\xc2\xa0', 'latin1') > >>> weirder > u'\xc2\xa0' > >>> 'This just gets ' + weirder > > u'This just gets \xc2\xa0' > > Or is it a Microsoft bytestring? > > >>> weirder = unicode('\xc2\xa0', 'mbcs') > >>> 'This just gets ' + weirder > > u'This just gets \xc2\xa0' > > None of these codecs seem to work. > > Back to the original purpose, as I'm scraping the page, I'm storing > the field/value pair in a dictionary with each iteration through table > elements on the page. This is all fine, until a value is found that > contains the offending bytestring. I have attempted to coerce all > value strings into an encoding, but Python doesn't seem to like that > when the string is already Unicode: > > valuesDict[fieldString] = unicode(value, 'UTF-8') > TypeError: decoding Unicode is not supported > > The solution I've arrived at is to specify the encoding for value > strings both when reading and writing value strings. > > for k, v in valuesDict.iteritems(): > ? ? valuePair = ':'.join([k, v.encode('UTF-8')]) > ? ? [snip] ... > ? ? wfile.write('|'.join(valueList)) > > I'm not sure I have a question, but does this sound familiar to any > Unicode experts out there? > > How should I handle these odd bytestring values? Am I doing it > correctly, or what could I improve? > > Thanks! Since it's UTF-8, one should go to one of the UTF-8 pages that describes how to decode it. As it turns out, its unicode hex value is A0, which is indeed a non-breaking space. This is probably as good as any page: http://en.wikipedia.org/wiki/UTF-8 John Roth From tjreedy at udel.edu Tue Sep 7 14:15:39 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 14:15:39 -0400 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) In-Reply-To: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: On 9/7/2010 9:24 AM, sajuptpm wrote: > I have a list of tuples. > > l = [((30,50),(70)), ((50,20),(20))] > > for i in range(10): > k = ((i+30,i+50),(i+70)) The (i+70) parens do nothing, as already explained to (20) Your set of test data are not very good as they do not test all the insertion possibilities. The value of the third number is not relevant to the problem and might as well be 0 for testing purposes. #suppose creating new tuple in each iteration > using some random value and in sert it into list. > > flag=True > for i, v in enumerate(l): You are reusing 'i' as index variable when it is already in use as index variable for the outer loop. This is a confusing and a bad idea in general, even if it happens to work. > if v>= k: > l.insert(i,k) > flag = False > break This block should be indented under the inner for loop > if flag: > l.append(k) flay can be avoided by using else clause of for statement > This code will give a list of tuples sorted in asc order. > I need to change this code to sort this list by k[0][0] ascending and > k[0][1] descending. > What are the modifications needed in this code. Change the v>=k test to be the one you want. Here is my code: l = [((30,51),0), ((30,49),0), ((32,20),0)] for i in range(5): k = ((i+29,i+51), 0) for i, v in enumerate(l): v00 = v[0][0] k00 = k[0][0] if v00 > k00 or v00==k00 and v[0][1] <= k[0][1]: l.insert(i,k) break else: l.append(k) print(l) # prints [((29, 51), 0), ((30, 52), 0), ((30, 51), 0), ((30, 49), 0), ((31, 53), 0), ((32, 54), 0), ((32, 20), 0), ((33, 55), 0)] > I dont want to user sort() method of list. Why not? Even for the example above, .sort is faster than doing the insert sort in Python code! Indent the above with def f1():. Then def f2(): l = [((30,51),0), ((30,49),0), ((32,20),0)] for i in range(5): l.append(((i+29,i+51), 0)) l.sort(key=lambda x:(x[0][0], -x[0][1])) import timeit print(timeit.timeit(f1,'from __main__ import f1,f2',number=100000)) print(timeit.timeit(f2,'from __main__ import f1,f2',number=100000)) #prints 2.51296240165 1.63514413145 > i need to implement l.sort(key=lambda x:(x[0][0], -x[1][0])) in That should be -x[0][1] It is a good idea to test code before posting. Any reason for the 'need' other than a wrong idea about relative speed? -- Terry Jan Reedy From ian.g.kelly at gmail.com Tue Sep 7 14:21:16 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Sep 2010 12:21:16 -0600 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 11:52 AM, Phlip wrote: > And no it's not "much clearer". It's clearer because it does exactly what it says it does, unlike your approach that masquerades as a loop. > Exceptions are for catastrophic errors No, they're for flagging "exceptional" states. /Errors/ are for catastrophic errors. The fact that errors are a subset of exceptions is just for convenience in handling. > AAAND you need to test that the DoesNotExist occurs for the exact > reason you expect. I'm not following you here. The only possible reason the exception can occur is if no matching row exists. If there were some other reason for raising an exception, then a different exception would be raised. > Your except is not complete. Making it complete is > very hard, and will break as soon as the model changes. Still not following you. What is it missing, and how will it break? From tjreedy at udel.edu Tue Sep 7 14:28:38 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 14:28:38 -0400 Subject: Bit fields in python? In-Reply-To: References: Message-ID: On 9/7/2010 12:06 AM, Kwan Lai Cheng wrote: > Hi, > I'm trying to rewrite a c program in python & encountered several > problems. I have some data structures in my c program like below: > typedef struct > { > unsigned short size; > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsigned short var_a3:2; > unsigned short var_a4:2; > unsigned int var_a5; > }structa; In Python, we cannot directly name bitfields within an int. However, we can *read, set, and flip bits with the bit operators and bit masks *define a dict that maps bitfield names to bit indexes *define named functions that use the above. *wrap or subclass int with a class that has attributes that map to a bitfield. I am pretty sure there is public code that does all of the above. Searching pypi.python.org for 'bitfield', I found BitDecoder 0.5.1 Decode bit-fields to human readable description This program (and Python module) will decode a value as per a bitfield definition. This is very useful for hardware registers that have meanings to parts of the bits in seperate. Google for more. -- Terry Jan Reedy From python.list at tim.thechases.com Tue Sep 7 14:36:08 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 07 Sep 2010 13:36:08 -0500 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <4C868618.2060507@tim.thechases.com> On 09/07/10 12:52, Phlip wrote: >> try: >> return Model.objects.get(pk=42) >> except Model.DoesNotExist: >> return sentinel >> >> The flow of control is much clearer this way. > > It reminds me of Visual Basic. > > And no it's not "much clearer". Exceptions are for catastrophic errors > that the caller should care not to handle. A "record not found" is not > a catastrophe. Exceptions are not limited to catastrophic errors, simply exceptional (not the common) cases. E.g. iterators raising StopException when exhausted. >>> i = iter(range(2)) >>> i.next() 0 >>> i.next() 1 >>> i.next() Traceback (most recent call last): File "", line 1, in StopIteration >>> i = iter(range(2)) >>> for v in i: ... print v ... 0 1 Running out of things to iterate over is pretty non-catastrophic in my book. :) Using exceptions as in the grandparent's post seem perfectly fine to me. The other option would be to LBYL: items = list(MyModel.objects.filter(...)) if len(items) == 1: do_something(items[0]) else: what_the(...) -tkc From phlip2005 at gmail.com Tue Sep 7 14:53:37 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 11:53:37 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On Sep 7, 11:36?am, Tim Chase wrote: > > And no it's not "much clearer". Exceptions are for catastrophic errors > > that the caller should care not to handle. A "record not found" is not > > a catastrophe. > > Exceptions are not limited to catastrophic errors, simply > exceptional (not the common) cases. ?E.g. iterators raising > StopException when exhausted. Exceptions are not "because we should only return one type of thing". They are for situations which the caller should care not to handle. Exceptions are for propagating. A "record not found" is an exemplary example of a situation the caller _should_ handle. > ? ?items = list(MyModel.objects.filter(...)) > ? ?if len(items) == 1: > ? ? ?do_something(items[0]) > ? ?else: > ? ? ?what_the(...) Both your version and mine read an entire cursor. But mine only rezzed the first object, whereas yours rezzed every object in the cursor, just to throw most of them away! From nagle at animats.com Tue Sep 7 15:02:07 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Sep 2010 12:02:07 -0700 Subject: Bug in Python 2.6 urlencode Message-ID: <4c868c2d$0$1581$742ec2ed@news.sonic.net> There's a bug in Python 2.6's "urllib.urlencode". If you pass in a Unicode character outside the ASCII range, instead of it being encoded properly, an exception is raised. File "C:\python26\lib\urllib.py", line 1267, in urlencode v = quote_plus(str(v)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 0: ordinal not in range(128) This will probably work in 3.x, because there, "str" converts to Unicode, and quote_plus can handle Unicode. This is one of those legacy bugs left from the pre-Unicode era. There's a workaround. Call urllib.urlencode with a second parameter of 1. This turns on the optional feature of accepting tuples in the argument to be encoded, and the code goes through a newer code path that works. Is it worth reporting 2.x bugs any more? Or are we in the version suckage period, where version N is abandonware and version N+1 isn't deployable yet. John Nagle From nagle at animats.com Tue Sep 7 15:13:41 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Sep 2010 12:13:41 -0700 Subject: Bit fields in python? In-Reply-To: References: Message-ID: <4c868ee2$0$1650$742ec2ed@news.sonic.net> On 9/6/2010 11:55 PM, Stefan Behnel wrote: > Kwan Lai Cheng, 07.09.2010 06:06: >> I'm trying to rewrite a c program in python& encountered several >> problems. I have some data structures in my c program like below: >> def __init__(self, size=0) >> >> Any equivalent for c data structures& bit fields in python? > > If you can tell us what these structs are being used for in the original > C code, we might be able to point you to a suitable way to implement the > same thing efficiently in Python. Python has the "struct" module for formatting binary data. http://docs.python.org/library/struct.html But it doesn't handle bit fields. Its lowest resolution is one byte. John Nagle From nad at acm.org Tue Sep 7 15:23:57 2010 From: nad at acm.org (Ned Deily) Date: Tue, 07 Sep 2010 12:23:57 -0700 Subject: Bug in Python 2.6 urlencode References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> Message-ID: In article <4c868c2d$0$1581$742ec2ed at news.sonic.net>, John Nagle wrote: > Is it worth reporting 2.x bugs any more? Or are we in the > version suckage period, where version N is abandonware and > version N+1 isn't deployable yet. Yes!! 2.7 is being actively maintained for bug fixes. (2.6 only for any security issues that might arise.) It's easy enough to see this if you take a glance at current activity on any of several Python development related mailing lists: http://www.python.org/community/lists/ -- Ned Deily, nad at acm.org From no.email at nospam.invalid Tue Sep 7 15:29:34 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Sep 2010 12:29:34 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7x39twpuxi.fsf@ruckus.brouhaha.com> <7xr5hguzzi.fsf@ruckus.brouhaha.com> <7xtymbzixt.fsf@ruckus.brouhaha.com> <7xr5heufhb.fsf@ruckus.brouhaha.com> <7xbp8el03t.fsf@ruckus.brouhaha.com> Message-ID: <7x4oe18i8x.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > But you?ll notice that Free Software comes with no such > restrictions. In fact, it is contrary to commonly-accepted Free > Software guidelines to impose any sort of restrictions on areas of use. Free software comes with an explicit disclaimer of liability (you get what you pay for). The Sun stuff ($$$$$) may have either an express or implied warranty that could mean they get hit up for damages if the software is wrong. IANAL YMMV etc. From python.list at tim.thechases.com Tue Sep 7 15:45:04 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 07 Sep 2010 14:45:04 -0500 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <4C869640.9030907@tim.thechases.com> On 09/07/10 13:53, Phlip wrote: > On Sep 7, 11:36 am, Tim Chase wrote: > >>> And no it's not "much clearer". Exceptions are for catastrophic errors >>> that the caller should care not to handle. A "record not found" is not >>> a catastrophe. >> >> Exceptions are not limited to catastrophic errors, simply >> exceptional (not the common) cases. E.g. iterators raising >> StopException when exhausted. > > Exceptions are not "because we should only return one type of thing". > They are for situations which the caller should care not to handle. > Exceptions are for propagating. A "record not found" is an exemplary > example of a situation the caller _should_ handle. Um...first you state "Exceptions are for catastrophic errors that the caller should not care to handle. A 'record not found' is not a catastrophe" and then you contradictingly go on to state "A 'record not found' is an exemplary example of a situation the caller _should_ handle". I'm not sure I follow your logic here. Exceptions allow both (1) the ability to handle the exceptional condition locally if you want to (including suppressing it) and (2) propagate the exception if you want to make the caller handle it. And if you really want, you can just subclass QuerySet to provide your own get_or_none() method to return your sentinel. >> items = list(MyModel.objects.filter(...)) >> if len(items) == 1: >> do_something(items[0]) >> else: >> what_the(...) > > Both your version and mine read an entire cursor. But mine only rezzed > the first object, whereas yours rezzed every object in the cursor, > just to throw most of them away! If a .get() returns more than one object (non-unique criteria are used), what _should_ it return? Agreed, if it pulls back a bajillion records, that's bad, so if you're concerned your conditions might do that despite the expectation they bring back 1-and-only-1 (.get() currently raises an exception if it brings back more than one result db/models/query.py around line 342 where MultipleObjectsReturned is raised), then I'd just slice them: items = list(MyModel.objects.filter(...)[:1]) if items: do_something(items[0]) else: what_the(...) -tkc From raoulbia at gmail.com Tue Sep 7 15:46:36 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 12:46:36 -0700 (PDT) Subject: compare dictionaries Message-ID: level: beginner word= 'even' dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} i want to know if word is entirely composed of letters in dict2 my approach: step 1 : convert word to dictionary(dict1) step2: for k in dict1.keys(): if k in dict2: if dict1[k] != dict2[k]: return False return True return False return True by adding a print statement i can see that this simply ends too early e.g. as soon as the first IF condition is met the loop exits i think this is easy but google and python doc didn't return any good hints so i'm trying here. Thanks Baba From rami.chowdhury at merton.oxon.org Tue Sep 7 15:54:17 2010 From: rami.chowdhury at merton.oxon.org (Rami Chowdhury) Date: Wed, 8 Sep 2010 01:54:17 +0600 Subject: Help needed - function apparently global cannot be called. In-Reply-To: <4C864585.3050204@gmaiil.com> References: <4c8618e5$0$8784$426a74cc@news.free.fr> <4C864585.3050204@gmaiil.com> Message-ID: Hi Ian, On Tue, Sep 7, 2010 at 20:00, Ian wrote: > On 07/09/2010 11:50, Bruno Desthuilliers wrote: > > note the order of the above - log is defined before the import. > > And ? Do you think it will affect the imported module in any way ? Like, > say, magically "inject" your log function in the DelNotePrinter module ?-) > > Just that log is defined before the global log is encountered to that if > the compiler needed to set up a link at compile time it was able to do so. > > I think I see where you're going wrong -- this bit me too when I was learning Python, having come from PHP. Unlike PHP, when you import a module in Python it does *not* inherit the importing module's namespace. So the "log" function you're accessing in DelNotePrinter.py is not the one you defined above the import statement. > In Python, "global" means "module-level", and it's only necessary when you > want to rebind a module-level name from within a function or method. > > Exactly! I want to bind the name log to the function I wrote. > As Bruno pointed out, the "global" statement is only necessary if you want to "rebind" a name -- i.e. if you want to modify how an object appears to the global scope. It's not necessary if you simply want to call a function. > > I have read http://docs.python.org/reference/simple_stmts.html#globalvery carefully and I still don't understand. > > > The statement definition makes no sense if you don't understand namespaces > and bindings: > > http://docs.python.org/reference/executionmodel.html#naming-and-binding > > Thanks for the pointer. What a truly execrable piece of writing - full of > over-long sentences and multiple subordinate clauses. It routinely uses > terms before definition, and sometimes without definition. It is > astonishingly bad. > Perhaps you could help rewrite it? I'm sure the maintainers would be very happy to get a documentation patch. > > The third sentence reads "Each occurrence of a name in the program text > refers to the *binding* of that name established in the innermost function > block containing the use." What does that mean? It appears to mean that it > is the assignment in the innermost function block that binds for all uses, > not the first, not module blocks, not class blocks and not code blocks - but > the innermost function block. That might be correct, but somehow I doubt it, > for it would mean that earlier bindings are ignored or invalidated or not > used or something - even if the inner block is not executed. > > I am not stupid and English is my mother tongue, and I have read that page > many times. The implications of the passage are still opaque to me. > > How can I call a global function placed at the top of the source. Do I > really have to move a 4 line function into its own file and import it again > and again and again? > The short answer is yes. If you have this and similar functions that you call from various modules, then it's ideal to put them in a utility module of their own. However, as imported modules are cached in Python, this isn't as expensive as you might think if you are more used to other languages. -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -------------- next part -------------- An HTML attachment was scrubbed... URL: From sschwarzer at sschwarzer.net Tue Sep 7 16:01:42 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Tue, 07 Sep 2010 22:01:42 +0200 Subject: Help needed - function apparently global cannot be called. In-Reply-To: References: Message-ID: <4C869A26.8060209@sschwarzer.net> Hi Ian, On 2010-09-07 12:18, Ian Hobson wrote: > f = open('d:\logfile.txt','a') Just a note: Using a backslash in a non-raw string will get you in trouble as soon as the backslash is followed by a character which makes a special character sequence, like "\n". For example, f = open('d:\nice_filename.txt', 'a') will give surprising results. :-) Either double the backslash, use a raw string, or, in the special case of file system paths, possibly use a forward slash. Stefan From no.email at nospam.invalid Tue Sep 7 16:06:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Sep 2010 13:06:01 -0700 Subject: compare dictionaries References: Message-ID: <7x4oe15nfa.fsf@ruckus.brouhaha.com> Baba writes: > word= 'even' > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > i want to know if word is entirely composed of letters in dict2 set(word) <= set(dict2.keys()) From bdesth.quelquechose at free.quelquepart.fr Tue Sep 7 16:06:37 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 22:06:37 +0200 Subject: The Samurai Principle In-Reply-To: <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> Message-ID: <4c86b6cc$0$10872$426a74cc@news.free.fr> Phlip a ?crit : > On Sep 7, 10:12 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Phlip a ?crit : >> >>> Back to the topic, I tend to do this: >>> for record in Model.objects.filter(pk=42): >>> return record >>> return sentinel >> WTF alert here... > > I don't see how anyone could WTF that. Are you pretending to be a newb > who doesn't understanding it? F'em. F'... newbies is definitly not the pythonic mindset. Python's mindset is about doing the most obvious thing, no trying to be smart. The obvious code here is: try: return Model.objects.get(pk=42) except Model.DoesNotExist: return sentinel so yes, your above snippet is bordering on WTF since it's not immediatly obvious - it takes at least one more second for me to parse, and I'm definitly not a Python nor Django newbie. That's something I'd immediatly rewrite if I had to work on this code. > I would guess that Django provides some basic rules for avoiding name > collisions. yes : common sense. > Nobody should call a field "pk__in" Nope, but "default" - which would be the obvious keyword here - is also a perfectly legitimate field name. >> But if you feel like you found the correct name, you can of course >> monkeypatch queryset !-) > > Know I gotta learn to add a new method to an existing class! It's as straightforward as possible once you know Python's object model: def somefunc(self, whatever): self.do_something_with(whatever) import somemodule somemodule.SomeClass.mymethod = somefunc From gherron at digipen.edu Tue Sep 7 16:08:27 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 07 Sep 2010 13:08:27 -0700 Subject: compare dictionaries In-Reply-To: References: Message-ID: <4C869BBB.8020706@digipen.edu> On 09/07/2010 12:46 PM, Baba wrote: > word= 'even' > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > Just go through each letter of word checking for its existence in dict2. Return False if one misses, and True if you get through the whole word: def ...(): for c in word: if c not in dict2: return False #if any character is not in dict return True # otherwise If you know of generator expressions, and remember that True and False are 1 and 0 respectively, then this works def ...(): return sum(c in dict2 for c in word) == len(word) Gary Herron -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From roberto.pagliari at gmail.com Tue Sep 7 16:12:25 2010 From: roberto.pagliari at gmail.com (Bob) Date: Tue, 7 Sep 2010 13:12:25 -0700 (PDT) Subject: can't send email Message-ID: Hello. I'm trying to send email using python 2.6.1 under snow leopard, but I can't get it to work. I'm trying one of the many examples I found on the web EXAMPLE 1 import smtplib fromaddr = 'fromuser at gmail.com' toaddrs = 'touser at gmail.com' msg = 'There was a terrible error that occured and I wanted you to know!' # Credentials (if needed) username = 'username' password = 'password' # The actual mail send server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username,password) server.sendmail(fromaddr, toaddrs, msg) server.quit() EXAMPLE 2 # Import smtplib for the actual sending function import smtplib # Import the email modules we'll need from email.mime.text import MIMEText # Open a plain text file for reading. For this example, assume that # the text file contains only ASCII characters. fp = open(textfile, 'rb') # Create a text/plain message msg = MIMEText(fp.read()) fp.close() # me == the sender's email address # you == the recipient's email address msg['Subject'] = 'The contents of %s' % textfile msg['From'] = me msg['To'] = you # Send the message via our own SMTP server, but don't include the # envelope header. s = smtplib.SMTP() s.sendmail(me, [you], msg.as_string()) s.quit() The error I get is this python email.py Traceback (most recent call last): File "email.py", line 2, in import smtplib File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/smtplib.py", line 46, in import email.utils File "/Users/Bob/Code/email.py", line 5, in from email.mime.text import MIMEText ImportError: No module named mime.text I'm using the native python version installed by apple, so I don't know why email and email.utils and mime are not found. I checked on the filesystem and they are present... Thanks From bdesth.quelquechose at free.quelquepart.fr Tue Sep 7 16:15:42 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 07 Sep 2010 22:15:42 +0200 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <4c86b8ed$0$9874$426a74cc@news.free.fr> Phlip a ?crit : > On Sep 7, 10:36 am, Ian Kelly wrote: >> On Tue, Sep 7, 2010 at 10:02 AM, Phlip wrote: >>> Back to the topic, I tend to do this: >>> for record in Model.objects.filter(pk=42): >>> return record >>> return sentinel >> How is that any better than just catching the exception? >> >> try: >> return Model.objects.get(pk=42) >> except Model.DoesNotExist: >> return sentinel >> >> The flow of control is much clearer this way. > > It reminds me of Visual Basic. Strange enough, your own code snippet reminds me of what I used to find when fixing VB programs some ten years ago. > And no it's not "much clearer". It is for any Python programmer - it's even TheOneObviousWay. > Exceptions are for catastrophic errors Chapter and verse, please ? Exceptions are for exceptional situations. When you call queryset.get, you do expect to have one single instance matching the lookup - specialy when doing a pk lookup. > AAAND you need to test that the DoesNotExist occurs for the exact > reason you expect. Bullshit. The only reason you'd get this exception is because there's no record matching your where clause. > Your except is not complete. Why so ? > Making it complete is > very hard, and will break as soon as the model changes. Why so ? From raoulbia at gmail.com Tue Sep 7 16:26:10 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 13:26:10 -0700 (PDT) Subject: compare dictionaries References: Message-ID: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> On 7 sep, 22:08, Gary Herron wrote: > On 09/07/2010 12:46 PM, Baba wrote: > > > word= 'even' > > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > Just go through each letter of word checking for its existence in > dict2. ?Return False if one misses, and True if you get through the > whole word: > > def ...(): > ? ?for c in word: > ? ? ?if c not in dict2: > ? ? ? ?return False #if any character is not in dict > ? ?return True ? ? ?# otherwise > > If you know of generator expressions, and remember that True and False > are 1 and 0 respectively, then this works > > def ...(): > ? ? ?return sum(c in dict2 ? for c in word) == len(word) > > Gary Herron > > -- > Gary Herron, PhD. > Department of Computer Science > DigiPen Institute of Technology > (425) 895-4418 ok but how do we address the fact that letter e needs to have the value 2 in the dictionary if it was to be True? in my example this condition is not met so the check would return False. Word is not entirely composed of letters in dict2, one of the letter is not in dict2 i.e. the 2nd e So finding a matching key seems to be the easy part, checking if the number of ocurrences of letter in 'word' == letter.value seems to be the tricky part From chris at rebertia.com Tue Sep 7 16:27:43 2010 From: chris at rebertia.com (Chris Rebert) Date: Tue, 7 Sep 2010 13:27:43 -0700 Subject: can't send email In-Reply-To: References: Message-ID: On Tue, Sep 7, 2010 at 1:12 PM, Bob wrote: > Hello. > I'm trying to send email using python 2.6.1 under snow leopard, but I > can't get it to work. I'm trying one of the many examples I found on > the web > The error I get is this > > python email.py > Traceback (most recent call last): > ?File "email.py", line 2, in > ? ?import smtplib > ?File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/smtplib.py", line 46, in > ? ?import email.utils > ?File "/Users/Bob/Code/email.py", line 5, in > ? ?from email.mime.text import MIMEText > ImportError: No module named mime.text > > > I'm using the native python version installed by apple, so I don't > know why email and email.utils and mime are not found. I checked on > the filesystem and they are present... Your /Users/Bob/Code/email.py file is shadowing the std lib "email" module. Rename your file to something else so that it no longer conflicts. Cheers, Chris -- http://blog.rebertia.com From roberto.pagliari at gmail.com Tue Sep 7 16:29:22 2010 From: roberto.pagliari at gmail.com (Bob) Date: Tue, 7 Sep 2010 13:29:22 -0700 (PDT) Subject: can't send email References: Message-ID: On Sep 7, 10:27?pm, Chris Rebert wrote: > On Tue, Sep 7, 2010 at 1:12 PM, Bob wrote: > > Hello. > > I'm trying to send email using python 2.6.1 under snow leopard, but I > > can't get it to work. I'm trying one of the many examples I found on > > the web > > > The error I get is this > > > python email.py > > Traceback (most recent call last): > > ?File "email.py", line 2, in > > ? ?import smtplib > > ?File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ > > python2.6/smtplib.py", line 46, in > > ? ?import email.utils > > ?File "/Users/Bob/Code/email.py", line 5, in > > ? ?from email.mime.text import MIMEText > > ImportError: No module named mime.text > > > I'm using the native python version installed by apple, so I don't > > know why email and email.utils and mime are not found. I checked on > > the filesystem and they are present... > > Your /Users/Bob/Code/email.py file is shadowing the std lib "email" > module. Rename your file to something else so that it no longer > conflicts. > > Cheers, > Chris > --http://blog.rebertia.com yes I just realized that... it works now!! thanks From nad at acm.org Tue Sep 7 16:30:14 2010 From: nad at acm.org (Ned Deily) Date: Tue, 07 Sep 2010 13:30:14 -0700 Subject: can't send email References: Message-ID: In article , Bob wrote: >[...] > The error I get is this > > python email.py > Traceback (most recent call last): > File "email.py", line 2, in > import smtplib > File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/smtplib.py", line 46, in > import email.utils > File "/Users/Bob/Code/email.py", line 5, in > from email.mime.text import MIMEText > ImportError: No module named mime.text Your module email.py is hiding the standard library's email package. Rename your file from email.py to something that doesn't conflict. -- Ned Deily, nad at acm.org From python at mrabarnett.plus.com Tue Sep 7 16:37:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Sep 2010 21:37:58 +0100 Subject: compare dictionaries In-Reply-To: <7x4oe15nfa.fsf@ruckus.brouhaha.com> References: <7x4oe15nfa.fsf@ruckus.brouhaha.com> Message-ID: <4C86A2A6.6040501@mrabarnett.plus.com> On 07/09/2010 21:06, Paul Rubin wrote: > Baba writes: >> word= 'even' >> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >> >> i want to know if word is entirely composed of letters in dict2 > > set(word)<= set(dict2.keys()) Do the numbers in dict2 represent the maximum number of times that the letter can be used? If yes, then build a similar dict for the word with the number of times that each letter occurs in the word and then check for every pair in the dict whether the key (ie, letter) occurs in dict2 and that the value (number of occurrences) isn't too many. From anand.shashwat at gmail.com Tue Sep 7 16:42:11 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 8 Sep 2010 02:12:11 +0530 Subject: compare dictionaries In-Reply-To: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> References: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> Message-ID: On Wed, Sep 8, 2010 at 1:56 AM, Baba wrote: > On 7 sep, 22:08, Gary Herron wrote: > > On 09/07/2010 12:46 PM, Baba wrote: > > > > > word= 'even' > > > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > > > Just go through each letter of word checking for its existence in > > dict2. Return False if one misses, and True if you get through the > > whole word: > > > > def ...(): > > for c in word: > > if c not in dict2: > > return False #if any character is not in dict > > return True # otherwise > > > > If you know of generator expressions, and remember that True and False > > are 1 and 0 respectively, then this works > > > > def ...(): > > return sum(c in dict2 for c in word) == len(word) > > > > Gary Herron > > > > -- > > Gary Herron, PhD. > > Department of Computer Science > > DigiPen Institute of Technology > > (425) 895-4418 > > ok but how do we address the fact that letter e needs to have the > value 2 in the dictionary if it was to be True? in my example this > condition is not met so the check would return False. Word is not > entirely composed of letters in dict2, one of the letter is not in > dict2 i.e. the 2nd e > Seems You did not understood Gary's solution. It is correct. Also, you asked for 'i want to know if word is entirely composed of letters in dict2' which you are getting. Did you tried running the code ? > So finding a matching key seems to be the easy part, checking if the > number of ocurrences of letter in 'word' == letter.value seems to be > the tricky part > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Sep 7 17:08:49 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Sep 2010 23:08:49 +0200 Subject: compare dictionaries References: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> Message-ID: Baba wrote: > On 7 sep, 22:08, Gary Herron wrote: >> On 09/07/2010 12:46 PM, Baba wrote: >> >> > word= 'even' >> > dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >> >> Just go through each letter of word checking for its existence in >> dict2. Return False if one misses, and True if you get through the >> whole word: >> >> def ...(): >> for c in word: >> if c not in dict2: >> return False #if any character is not in dict >> return True # otherwise >> >> If you know of generator expressions, and remember that True and False >> are 1 and 0 respectively, then this works >> >> def ...(): >> return sum(c in dict2 for c in word) == len(word) >> >> Gary Herron >> >> -- >> Gary Herron, PhD. >> Department of Computer Science >> DigiPen Institute of Technology >> (425) 895-4418 > > ok but how do we address the fact that letter e needs to have the > value 2 in the dictionary if it was to be True? in my example this > condition is not met so the check would return False. Word is not > entirely composed of letters in dict2, one of the letter is not in > dict2 i.e. the 2nd e > > So finding a matching key seems to be the easy part, checking if the > number of ocurrences of letter in 'word' == letter.value seems to be > the tricky part Just compare the two dictionaries dict1 == dict2 Or, if you want to allow dict2 to contain higher but not lower values all(v <= dict2.get(k, 0) for k, v in dict1.iteritems()) Peter From roberto.pagliari at gmail.com Tue Sep 7 17:26:11 2010 From: roberto.pagliari at gmail.com (Bob) Date: Tue, 7 Sep 2010 14:26:11 -0700 (PDT) Subject: formatted input Message-ID: Hi All, I have another question about formatted input. Suppose I am reading a text file, and that I want it to be something like this word11 = num11, word12 = num12, word13 = num13 etc... word21 = num21, word22 = num12, word23 = num23 etc... etc... where wordx1 belongs to a certain dictionary of words, say dic1, while wordx2 belongs to dic2, the numbers within some range and so on. I was wondering if there is something in the standard library I may use to check whether the file I am reading has a correct syntax according to my rules/dictionaries instead of implementing my own routine that would look like (pseudocode) for each line put words into a list check condition for each word Thanks From raoulbia at gmail.com Tue Sep 7 17:36:38 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 7 Sep 2010 14:36:38 -0700 (PDT) Subject: compare dictionaries References: <7x4oe15nfa.fsf@ruckus.brouhaha.com> Message-ID: <78fb4e82-0e9b-4f0c-b5da-9da6588d6a89@q2g2000yqq.googlegroups.com> On 7 sep, 22:37, MRAB wrote: > On 07/09/2010 21:06, Paul Rubin wrote: > > > Baba ?writes: > >> word= 'even' > >> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > > >> i want to know if word is entirely composed of letters in dict2 > > > set(word)<= set(dict2.keys()) > > Do the numbers in dict2 represent the maximum number of times that the > letter can be used? > > If yes, then build a similar dict for the word with the number of times > that each letter occurs in the word and then check for every pair in > the dict whether the key (ie, letter) occurs in dict2 and that the > value (number of occurrences) isn't too many. Hi MRAB Thanks for the hint. In my case i need to do the opposite: the number of times that each letter ocurs in the word needs to be smaller or equal to the number of times it apears in dict2. That way i am guaranteed that word is entirely made up of elements of dict2. Your hint pointed me in the right direction. for k in word.keys(): if k not in hand: return False elif k in hand: if word[k] > hand[k]: return False return True Baba From hobson42 at gmaiil.com Tue Sep 7 17:50:24 2010 From: hobson42 at gmaiil.com (Ian) Date: Tue, 07 Sep 2010 22:50:24 +0100 Subject: Help needed - function apparently global cannot be called. In-Reply-To: References: <4c8618e5$0$8784$426a74cc@news.free.fr> <4C864585.3050204@gmaiil.com> Message-ID: <4C86B3A0.6040709@gmaiil.com> Hi Rami, Stefan, Bruno. First a big thanks for your replies. On 07/09/2010 20:54, Rami Chowdhury wrote: > Hi Ian, > > I think I see where you're going wrong -- this bit me too when I was > learning Python, having come from PHP. Unlike PHP, when you import a > module in Python it does *not* inherit the importing module's > namespace. So the "log" function you're accessing in DelNotePrinter.py > is not the one you defined above the import statement. > Hmm. My php background shows that much. Huh? :) I guess so. > >> >> http://docs.python.org/reference/executionmodel.html#naming-and-binding >> >> > Thanks for the pointer. What a truly execrable piece of writing - > full of over-long sentences and multiple subordinate clauses. It > routinely uses terms before definition, and sometimes without > definition. It is astonishingly bad. > > > Perhaps you could help rewrite it? I'm sure the maintainers would be > very happy to get a documentation patch. I would be happy to re-write it but I do need to understand the subject better before that can happen. Clear and wrong will not help anyone. :) > > Do I really have to move a 4 line function into its own file and > import it again and again and again? > > > The short answer is yes. If you have this and similar functions that > you call from various modules, then it's ideal to put them in a > utility module of their own. However, as imported modules are cached > in Python, this isn't as expensive as you might think if you are more > used to other languages. > OK. Now I understand the need, the solution is easy. My first exploration of the wonders of writing windows services has had five things wrong with it: 1) Its windows - spit, crash, complicated, can't start a command line with elevated permissions, nash teeth, rip hair out. 2) Its services - so no stdout, or stderr, errors not reported, no "current directory" - burn and crash programming all over again. Deep joy! 3) pythonservice.exe - so module not called __main__ and initialisation not performed (unseen - see 2) - More fun. 4) multi-threading - I got really confused from this example http://docs.python.org/library/multiprocessing.html#exchanging-objects-between-processes becasue I got the wrong sort of Queue, so it stalled when it failed to call task_done() (there isn't such a method - but no error reported see 2). 5) Names pipes. The latest is that writing - yes writing - to the named pipe causes the reader to fail with (232, 'ConnectNamedPipe', 'The pipe is being closed.') if I write using php - yet I can write with python no trouble. There are down sides to "batteries included". When there are so many batteries, it can be hard to know if what you have is "good enough" or should you search for a more suitable one. Logging would have helped me a lot (assuming it would work in service environment with the permissions it would have had - a serious assumption). If it failed, it would have failed and hidden the problem. Oh to get on to proper GUI programming with python and PyQt! The next project. Wey Hey! Thanks again Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Tue Sep 7 17:56:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Sep 2010 14:56:07 -0700 Subject: compare dictionaries References: <7x4oe15nfa.fsf@ruckus.brouhaha.com> <78fb4e82-0e9b-4f0c-b5da-9da6588d6a89@q2g2000yqq.googlegroups.com> Message-ID: <7xy6bddxqg.fsf@ruckus.brouhaha.com> Baba writes: > for k in word.keys(): > if k not in hand: > return False > elif k in hand: > if word[k] > hand[k]: > return False > return True Untested: all(word[k] <= hand.get(k,0) for k in word) From deets at web.de Tue Sep 7 18:03:21 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 08 Sep 2010 00:03:21 +0200 Subject: formatted input References: Message-ID: Bob writes: > Hi All, > I have another question about formatted input. Suppose I am reading a > text file, and that I want it to be something like this > > word11 = num11, word12 = num12, word13 = num13 etc... > word21 = num21, word22 = num12, word23 = num23 etc... > etc... > > where wordx1 belongs to a certain dictionary of words, say dic1, while > wordx2 belongs to dic2, the numbers within some range and so on. I was > wondering if there is something in the standard library I may use to > check whether the file I am reading has a correct syntax according to > my rules/dictionaries instead of implementing my own routine that > would look like > (pseudocode) > for each line > put words into a list > check condition for each word No, there is no such thing. Either write something from scratch using string methods, or use pyparsing which is certainly up to the task (and much more) Diez From cournape at gmail.com Tue Sep 7 18:18:50 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 8 Sep 2010 07:18:50 +0900 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: > > One order of magnitude (say 10-20x slower) wouldn't be so bad. That's what > you might expect for a dynamically typed, interpreted language. 10/20x slower than C is only reached by extremely well optimized dynamic languages. It would be a tremendous achievement. If that's what you are after, look at LUA with its JIT, or scheme + stalin. For cases where vectorization is indeed not applicable (recursive algorithms), like in some signal processing, there are specialized tools which are very expressive while retaining good speed (faust is an interesting one for audio signal processing). > That would simply be delegating Python to a scripting language. That's a strange thing to say if you compare it to matlab. > It would be > nice if you could directly code low-level algorithms in it without relying > on accelerators It would be nice, but the fact is that python cannot do it - and is quite far from being able to do it. I don't think it is as important as you think it is, because things like numpy are extremely powerful in many cases. cheers, David From phlip2005 at gmail.com Tue Sep 7 18:20:27 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 15:20:27 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> <4c86b6cc$0$10872$426a74cc@news.free.fr> Message-ID: <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> On Sep 7, 1:06?pm, Bruno Desthuilliers wrote: > try: > ? ?return Model.objects.get(pk=42) > except Model.DoesNotExist: > ? ?return sentinel Visual Basic Classic had a Collection Class, which worked essentially like a real language's Hash, Map, or Dict. Except - it had no operation to test membership. It also could not enumerate by key and value (which would be 'for k,v in dict.items()'). To test for membership, you _had_ to catch an exception - using VB's tragically clumsy exception model. Hours of fun. That leads us to this topic: http://www.google.com/search?q=don't+use+exceptions+for+normal+control+flow From knny.myer at gmail.com Tue Sep 7 18:35:44 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Tue, 7 Sep 2010 18:35:44 -0400 Subject: formatted input In-Reply-To: References: Message-ID: <20100907223543.GA26961@5732Z> Bob (roberto.pagliari at gmail.com) wrote: > Hi All, > I have another question about formatted input. Suppose I am reading a > text file, and that I want it to be something like this > > word11 = num11, word12 = num12, word13 = num13 etc... > word21 = num21, word22 = num12, word23 = num23 etc... > etc... > > where wordx1 belongs to a certain dictionary of words, say dic1, while > wordx2 belongs to dic2, the numbers within some range and so on. I was > wondering if there is something in the standard library I may use to > check whether the file I am reading has a correct syntax according to > my rules/dictionaries instead of implementing my own routine that > would look like Python's `re` module > (pseudocode) > for each line > put words into a list > check condition for each word import re match_1 = re.compile("^words1") match_2 = re.compile("^words2") # Return a match object each re.match(match_1, "word11") re.match(match_2, "word21") I'm sure there are might be other ways to do the same thing. -- - Kenny Meyer To understand recursion, we must first understand recursion. -- From gherron at digipen.edu Tue Sep 7 18:49:35 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 07 Sep 2010 15:49:35 -0700 Subject: compare dictionaries In-Reply-To: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> References: <6f704e7a-2f0e-444f-a7bb-21d537a441df@j18g2000yqd.googlegroups.com> Message-ID: <4C86C17F.6060304@digipen.edu> On 09/07/2010 01:26 PM, Baba wrote: > On 7 sep, 22:08, Gary Herron wrote: > >> On 09/07/2010 12:46 PM, Baba wrote: >> >> >>> word= 'even' >>> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >>> >> Just go through each letter of word checking for its existence in >> dict2. Return False if one misses, and True if you get through the >> whole word: >> >> def ...(): >> for c in word: >> if c not in dict2: >> return False #if any character is not in dict >> return True # otherwise >> >> If you know of generator expressions, and remember that True and False >> are 1 and 0 respectively, then this works >> >> def ...(): >> return sum(c in dict2 for c in word) == len(word) >> >> Gary Herron >> >> -- >> Gary Herron, PhD. >> Department of Computer Science >> DigiPen Institute of Technology >> (425) 895-4418 >> > ok but how do we address the fact that letter e needs to have the > value 2 in the dictionary if it was to be True? in my example this > condition is not met so the check would return False. Word is not > entirely composed of letters in dict2, one of the letter is not in > dict2 i.e. the 2nd e > Huh??? I answered the problem as it was stated in the email -- it said nothing about *counting* the occurrences of letters. In order to not waste our (voluntary) time, perhaps you should carefully re-state the problem you'd liked solved. Then we'll see what we can come up with. > So finding a matching key seems to be the easy part, checking if the > number of ocurrences of letter in 'word' == letter.value seems to be > the tricky part > > -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From python at mrabarnett.plus.com Tue Sep 7 19:17:26 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Sep 2010 00:17:26 +0100 Subject: compare dictionaries In-Reply-To: <78fb4e82-0e9b-4f0c-b5da-9da6588d6a89@q2g2000yqq.googlegroups.com> References: <7x4oe15nfa.fsf@ruckus.brouhaha.com> <78fb4e82-0e9b-4f0c-b5da-9da6588d6a89@q2g2000yqq.googlegroups.com> Message-ID: <4C86C806.6010003@mrabarnett.plus.com> On 07/09/2010 22:36, Baba wrote: > On 7 sep, 22:37, MRAB wrote: >> On 07/09/2010 21:06, Paul Rubin wrote: >> >>> Baba writes: >>>> word= 'even' >>>> dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} >> >>>> i want to know if word is entirely composed of letters in dict2 >> >>> set(word)<= set(dict2.keys()) >> >> Do the numbers in dict2 represent the maximum number of times that the >> letter can be used? >> >> If yes, then build a similar dict for the word with the number of times >> that each letter occurs in the word and then check for every pair in >> the dict whether the key (ie, letter) occurs in dict2 and that the >> value (number of occurrences) isn't too many. > > Hi MRAB > > Thanks for the hint. In my case i need to do the opposite: the number > of times that each letter ocurs in the word needs to be smaller or > equal to the number of times it apears in dict2. That way i am > guaranteed that word is entirely made up of elements of dict2. > > Your hint pointed me in the right direction. > > for k in word.keys(): > if k not in hand: > return False > elif k in hand: > if word[k]> hand[k]: > return False > return True > If the first condition is True then the second will be False, so there's no need to check it: for k in word.keys(): if k not in hand: return False else: if word[k] > hand[k]: return False return True This can be shortened still further. From greg.ewing at canterbury.ac.nz Tue Sep 7 19:25:42 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Sep 2010 11:25:42 +1200 Subject: Queue cleanup In-Reply-To: <7xeid9gtuq.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> Message-ID: <8eo005FoboU1@mid.individual.net> Paul Rubin wrote: > Now extrapolate that error rate from 30 lines to a program the size of > Firefox (something like 5 MLOC), and you should see how fraught with > danger that style of programming is. But you don't write 5 MLOC of code using that programming style. You use it to write a small core something along the lines of, oh, I don't know, a Python interpreter, and then write the rest of the code on top of that platform. -- Greg From bussieremaillist at gmail.com Tue Sep 7 19:37:57 2010 From: bussieremaillist at gmail.com (bussiere maillist) Date: Wed, 8 Sep 2010 01:37:57 +0200 Subject: include a file in a python program In-Reply-To: References: Message-ID: Thanks all for your response i will try out this week, you have give me sufficient hint. Thanks again. Bussiere On Mon, Sep 6, 2010 at 9:50 AM, Niklasro(.appspot) wrote: > On Sep 5, 10:57?pm, bussiere bussiere wrote: >> i've got a python.txt that contain python and it must stay as it (python.txt) >> >> how can i include it in my program ? >> import python.txt doesn't work >> is there a way : >> a) to make an include("python.txt") >> b) tell him to treat .txt as .py file that i can make an import python ? >> i'am using python3 >> Regards >> Bussiere >> fan of torchwood >> Google Fan boy > > You can do it with tkinter to also enable GUI. > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin.kaplan at case.edu Tue Sep 7 19:38:13 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 7 Sep 2010 19:38:13 -0400 Subject: The Samurai Principle In-Reply-To: <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> <4c86b6cc$0$10872$426a74cc@news.free.fr> <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 6:20 PM, Phlip wrote: > On Sep 7, 1:06?pm, Bruno Desthuilliers > wrote: > >> try: >> ? ?return Model.objects.get(pk=42) >> except Model.DoesNotExist: >> ? ?return sentinel > > Visual Basic Classic had a Collection Class, which worked essentially > like a real language's Hash, Map, or Dict. > > Except - it had no operation to test membership. It also could not > enumerate by key and value (which would be 'for k,v in dict.items()'). > To test for membership, you _had_ to catch an exception - using VB's > tragically clumsy exception model. > > Hours of fun. That leads us to this topic: > > http://www.google.com/search?q=don't+use+exceptions+for+normal+control+flow > -- An experienced C programmer can program C in any language, but that doesn't mean it's a good idea to. When you're using a language, you should use the style that the language emphasizes. While you shouldn't use exceptions for control flow in C++, Java, or C#, there's nothing wrong with using them as such in Python. From bussiere at gmail.com Tue Sep 7 19:47:47 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Wed, 8 Sep 2010 01:47:47 +0200 Subject: include a file in a python program Message-ID: Thanks all for your response i will try out this week, you have give me sufficient hints. Thanks again. Bussiere From jtgalyon at gmail.com Tue Sep 7 19:53:30 2010 From: jtgalyon at gmail.com (Jason Galyon) Date: Tue, 07 Sep 2010 18:53:30 -0500 Subject: (Webinar) Connecting the Dots: US SEC, ABS Mandates, Financial Modeling and Python In-Reply-To: <4C86A9B1.10203@activestate.com> References: <4C86A9B1.10203@activestate.com> Message-ID: <1283903610.6863.2.camel@rivendell.clangalyon.com> Will this webcast/webinar perform on Linux? Jason On Tue, 2010-09-07 at 14:08 -0700, Kendra Penrose wrote: > Connecting the Dots: US SEC, ABS Mandates, Financial Modeling and Python > > Date: Wednesday September 22, 2010python-announce-list at python.org, > Time: 10:00am PST/1:00pm EST/ 17:00 UTC > Space is limited so register now at > https://www1.gotomeeting.com/register/151429928 > > Join us for a webinar co-hosted by Ann Rutledge, R&R Consulting, and > Diane Mueller, ActiveState, focused on the recent US SEC regulation, ABS > Mandates, Financial Modeling and Python. > > Recently, the US SEC published a proposal (33-9117) covering a series of > new initiatives to address the current lack of transparency of > asset-backed securities (ABS). This new series of SEC proposed > initiatives are a way of putting "teeth" into Reg AB that would give the > SEC (and the market) enough data to police and prevent events like the > recent subprime crisis. > > In this webinar, Ann Rutledge and Diane Mueller will discuss a new key > technical requirement in the SEC proposal; the provision of a Python > computer program and the market data required to properly monitor and > analyse these complex ABS transactions. The role of the proposed program > is to enable the capture of all the complicated terms of an ABS deal in > code that can be used to analyze the cash flows in each deal and how the > returns will get split up between different parties. Currently, > investors, fund managers, and investment managers receive a complex, > textual description of this information in the prospectus, which makes > it difficult to perform or visualize a rigorous quantitative or if-then > analysis of the asset-backed securities. > > By attending this webinar you will learn: > * some historical challenges regarding regulation of the asset-backed > securities (ABS) market > * technical benefits of Python and XML for capturing essential financial > information in ABS transactions > * about opportunities for collaboration between between regulators, > accounting standards bodies, and the open source software community > > If you are in the finance industry and are affected by the new SEC > regulations, you don't want to miss this webinar! > > Register at https://www1.gotomeeting.com/register/151429928 From ben+python at benfinney.id.au Tue Sep 7 20:07:19 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Sep 2010 10:07:19 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> Message-ID: <87aantayiw.fsf@benfinney.id.au> Baba writes: > However the following Wiki excerpt seems to go in my direction: No, it doesn't. It advises that people show kindness; as I've been arguing, that's exactly what you were shown. You haven't shown how the information being imparted could have been fully imparted in a way that's kinder, nor that it would be reasonable to do so. To put it another way: if you feel offended by an utterance, then insufficient kindness on the part of the speaker is not the only explanation. -- \ ?Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.? ?Anthony Taylor | Ben Finney From tjreedy at udel.edu Tue Sep 7 20:19:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 20:19:02 -0400 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de><4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: On 9/7/2010 6:00 AM, BartC wrote: >> Why should it? But if you want it, you can do it: >> >> xrange = range >> >> There, that wasn't hard, was it? > > I think I just learned more about Python than from months of reading this > group. > > So 'range' is just a class like any other. And that a class is something > you > can blithely copy from one variable to another. There is no copying of the class object. A new name is associated with the object. Any object can be given any number of names (aliases) that refer to the one and same object. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 7 20:43:04 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 20:43:04 -0400 Subject: Bug in Python 2.6 urlencode In-Reply-To: <4c868c2d$0$1581$742ec2ed@news.sonic.net> References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> Message-ID: On 9/7/2010 3:02 PM, John Nagle wrote: > There's a bug in Python 2.6's "urllib.urlencode". If you pass > in a Unicode character outside the ASCII range, instead of it > being encoded properly, an exception is raised. > > File "C:\python26\lib\urllib.py", line 1267, in urlencode > v = quote_plus(str(v)) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in > position 0: ordinal not in range(128) > > This will probably work in 3.x, because there, "str" converts > to Unicode, and quote_plus can handle Unicode. This is one of > those legacy bugs left from the pre-Unicode era. > > There's a workaround. Call urllib.urlencode with a second > parameter of 1. This turns on the optional feature of > accepting tuples in the argument to be encoded, and the > code goes through a newer code path that works. > > Is it worth reporting 2.x bugs any more? Or are we in the > version suckage period, where version N is abandonware and > version N+1 isn't deployable yet. You may report 2.7 bugs, but please verify that the behavior is a bug in 2.7. However, bugs that have been fixed by the switch to switch to unicode for text are unlikely to be fixed a second time in 2.7. You might suggest an enhancement to the doc for urlencode if that workaround is not clear. Or perhaps that workaround suggests that in this case, a fix would not be too difficult, and you can supply a patch. The basic deployment problem is that people who want to use unicode text also want to use libraries that have not been ported to use unicode text. That is the major issue for many porting projects. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 7 20:51:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Sep 2010 20:51:42 -0400 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: On 9/7/2010 2:53 PM, Phlip wrote: > They are for situations which the caller should care not to handle. Python is simply not designed that way. Exception raising and catching is a common flow-control method in Python. If you cannot stand that, Python is not for you. -- Terry Jan Reedy From ldo at geek-central.gen.new_zealand Tue Sep 7 21:23:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 08 Sep 2010 13:23:22 +1200 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: In message <74587da9-8861-4400-bbd7-1ea4f8182bb1 at l38g2000pro.googlegroups.com>, Phlip wrote: > Pythonistas: > > The "Samurai Principle" says to return victorious, or not at all. This > is why django.db wisely throws an exception, instead of simply > returning None, if it encounters a "record not found". Does catching the exception not defeat the ?Samurai Principle?? From greg.ewing at canterbury.ac.nz Tue Sep 7 21:40:48 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Sep 2010 13:40:48 +1200 Subject: what should __iter__ return? In-Reply-To: References: Message-ID: <8eo7tiF10cU1@mid.individual.net> Thomas Jollans wrote: > Hmm. Modifying an object while iterating over it isn't a great idea, ever: I wouldn't say never. Algorithms that calculate some kind of transitive closure can be expressed rather neatly by appending items to a list being iterated over. You can accommodate that kind of thing by writing the iterator like this: def __iter__(self): i = 0 while i < len(self): yield self[i] i += 1 -- Greg From bartc at freeuk.com Tue Sep 7 21:45:43 2010 From: bartc at freeuk.com (BartC) Date: Wed, 8 Sep 2010 02:45:43 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: "David Cournapeau" wrote in message news:mailman.546.1283897932.29448.python-list at python.org... > On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: > >> >> One order of magnitude (say 10-20x slower) wouldn't be so bad. That's >> what >> you might expect for a dynamically typed, interpreted language. > > 10/20x slower than C is only reached by extremely well optimized > dynamic languages. It would be a tremendous achievement. If that's Well, that is what I do (mess around with languages and stuff). Getting back to the OP's code again (trivial and pointless as it might seem), I got these results: C (gcc 3.4.5 -O3) 0.8 secs C (DMC-o) 2.3 secs C (lccwin32 -O) 2.9 secs My last interpreter 12.6 secs dynamically typed language (or 4.5 secs when told the type of 'a'; but that's cheating a little..) Python 3 177.0 secs That's why I was questioning the latter's performance in for-loops. But now that I know a bit more about Python (having dynamic everything) the figure is not so surprising. However, it's still slow! > what you are after, look at LUA with its JIT, or scheme + stalin. I've seen LuaJIT in action. It's timing for this test is 1.5 secs: forget being only 10x slower than C, it's faster than some C versions! (I'm sure it must be cheating somewhere...) -- bartc From python at mrabarnett.plus.com Tue Sep 7 22:07:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Sep 2010 03:07:09 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <4C86EFCD.1050009@mrabarnett.plus.com> On 08/09/2010 02:45, BartC wrote: > > > "David Cournapeau" wrote in message > news:mailman.546.1283897932.29448.python-list at python.org... >> On Sun, Sep 5, 2010 at 8:28 PM, BartC wrote: >> >>> >>> One order of magnitude (say 10-20x slower) wouldn't be so bad. That's >>> what >>> you might expect for a dynamically typed, interpreted language. >> >> 10/20x slower than C is only reached by extremely well optimized >> dynamic languages. It would be a tremendous achievement. If that's > > Well, that is what I do (mess around with languages and stuff). > > Getting back to the OP's code again (trivial and pointless as it might > seem), I got these results: > > C (gcc 3.4.5 -O3) 0.8 secs > C (DMC-o) 2.3 secs > C (lccwin32 -O) 2.9 secs > My last interpreter 12.6 secs dynamically typed language > (or 4.5 secs when told the type of 'a'; but that's > cheating a little..) > Python 3 177.0 secs > > That's why I was questioning the latter's performance in for-loops. But now > that I know a bit more about Python (having dynamic everything) the figure > is not so surprising. However, it's still slow! > >> what you are after, look at LUA with its JIT, or scheme + stalin. > > I've seen LuaJIT in action. It's timing for this test is 1.5 secs: > forget being only 10x slower than C, it's faster than some C versions! > (I'm sure it must be cheating somewhere...) > If you'd like to direct your skills to making CPython faster, without diminishing its flexibility, I'm sure it'll be welcomed. The source is all public, you know! :-) From nagle at animats.com Tue Sep 7 23:21:37 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Sep 2010 20:21:37 -0700 Subject: Bug in Python 2.6 urlencode In-Reply-To: References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> Message-ID: <4c87013f$0$1625$742ec2ed@news.sonic.net> On 9/7/2010 5:43 PM, Terry Reedy wrote: > On 9/7/2010 3:02 PM, John Nagle wrote: >> There's a bug in Python 2.6's "urllib.urlencode". If you pass >> in a Unicode character outside the ASCII range, instead of it >> being encoded properly, an exception is raised. >> >> File "C:\python26\lib\urllib.py", line 1267, in urlencode >> v = quote_plus(str(v)) >> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in >> position 0: ordinal not in range(128) >> >> This will probably work in 3.x, because there, "str" converts >> to Unicode, and quote_plus can handle Unicode. This is one of >> those legacy bugs left from the pre-Unicode era. >> >> There's a workaround. Call urllib.urlencode with a second >> parameter of 1. This turns on the optional feature of >> accepting tuples in the argument to be encoded, and the >> code goes through a newer code path that works. >> >> Is it worth reporting 2.x bugs any more? Or are we in the >> version suckage period, where version N is abandonware and >> version N+1 isn't deployable yet. > > You may report 2.7 bugs, but please verify that the behavior is a bug in > 2.7. However, bugs that have been fixed by the switch to switch to > unicode for text are unlikely to be fixed a second time in 2.7. You > might suggest an enhancement to the doc for urlencode if that workaround > is not clear. Or perhaps that workaround suggests that in this case, a > fix would not be too difficult, and you can supply a patch. > > The basic deployment problem is that people who want to use unicode text > also want to use libraries that have not been ported to use unicode > text. That is the major issue for many porting projects. In other words, we're in the version suckage period. John Nagle From greg.ewing at canterbury.ac.nz Tue Sep 7 23:31:11 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Sep 2010 15:31:11 +1200 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: <8eoeceFu9qU1@mid.individual.net> Lawrence D'Oliveiro wrote: > Does catching the exception not defeat the ?Samurai Principle?? Not if it lets you turn defeat into victory. Or redefine victory so that it includes defeat. Or something. -- Greg From phlip2005 at gmail.com Tue Sep 7 23:35:45 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 20:35:45 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> Message-ID: <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> On Sep 7, 6:23?pm, Lawrence D'Oliveiro wrote: > Does catching the exception not defeat the ?Samurai Principle?? Read my comic: http://c2.com/cgi/wiki?SamuraiPrinciple Exceptions are very dangerous by themselves, because if you don't trap them just right they can cause side-effects. They are worse than GOTO. From greg.ewing at canterbury.ac.nz Tue Sep 7 23:37:40 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 08 Sep 2010 15:37:40 +1200 Subject: Queue cleanup In-Reply-To: References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> Message-ID: <8eoeovF1atU1@mid.individual.net> Lawrence D'Oliveiro wrote: > But alone of all of these, garbage collection still remains just as costly > to implement as ever. That should tell you something about how poorly it > matches the characteristics of modern computing hardware. So maybe we need to redesign the hardware. Perhaps reference counts could be stored in their own special area of memory, updated in parallel with main memory accesses so that they don't slow anything down. Make it multiported so that all your cores can access it at once without locking. Maybe even build it out of counters instead of registers, so there's no data bus, only an address bus and inc/dec control lines. -- Greg From phlip2005 at gmail.com Tue Sep 7 23:38:14 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 20:38:14 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> Message-ID: <642cd655-ade1-40d9-8d02-66ca9354d3c3@q21g2000prm.googlegroups.com> On Sep 7, 5:51?pm, Terry Reedy wrote: > On 9/7/2010 2:53 PM, Phlip wrote: > > > They are for situations which the caller should care not to handle. > > Python is simply not designed that way. Exception raising and catching > is a common flow-control method in Python. If you cannot stand that, > Python is not for you. While I'm at it, I'm going to log into comp.lang.java.misc and explain to everyone why static typing is overkill, and implementation inheritance is good for you. Everyone gets defensive about the design flaws in their own language. But the django.db situation is not even a design flaw; just a misinterpretation of the Samurai Principle. int('yo') shall throw an exception, but a missing record could be the result you were looking for, so it's not exceptional. From phlip2005 at gmail.com Tue Sep 7 23:44:14 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 7 Sep 2010 20:44:14 -0700 (PDT) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> <4c86b6cc$0$10872$426a74cc@news.free.fr> <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> Message-ID: <663aa068-437f-4d79-9b05-c86c8ff16d54@m35g2000prn.googlegroups.com> On Sep 7, 4:38?pm, Benjamin Kaplan wrote: > When you're using a language, you should use the style that the > language emphasizes. You mean like this? uri = reverse('my_uri_name', kwargs=dict(pk=record.pk)) That 'kwargs' there is ... a lapse of judgement. It is exposing a technical detail (the "keyword arguments") instead of naming the variable after its intent. It should be 'params=', at least, to match the URI standards. I'm just sayin'... From ben+python at benfinney.id.au Wed Sep 8 00:08:04 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Sep 2010 14:08:04 +1000 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <4c86725a$0$16728$426a74cc@news.free.fr> <537ae758-9840-4ab4-9aa6-508f24a29b77@t5g2000prd.googlegroups.com> <4c86b6cc$0$10872$426a74cc@news.free.fr> <2724ec4e-eebf-4739-adac-90578e2a0054@h40g2000pro.googlegroups.com> <663aa068-437f-4d79-9b05-c86c8ff16d54@m35g2000prn.googlegroups.com> Message-ID: <8762ygc1y3.fsf@benfinney.id.au> Phlip writes: > On Sep 7, 4:38?pm, Benjamin Kaplan wrote: > > > When you're using a language, you should use the style that the > > language emphasizes. > > You mean like this? > > uri = reverse('my_uri_name', kwargs=dict(pk=record.pk)) Do you think that style is emphasised by Python? What gives you that impression? -- \ ?Program testing can be a very effective way to show the | `\ presence of bugs, but is hopelessly inadequate for showing | _o__) their absence.? ?Edsger W. Dijkstra | Ben Finney From stefan_ml at behnel.de Wed Sep 8 00:48:16 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 08 Sep 2010 06:48:16 +0200 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: BartC, 08.09.2010 03:45: > Getting back to the OP's code again (trivial and pointless as it might > seem), I got these results: > > C (gcc 3.4.5 -O3) 0.8 secs > C (DMC-o) 2.3 secs > C (lccwin32 -O) 2.9 secs >[...] > I've seen LuaJIT in action. It's timing for this test is 1.5 secs: > forget being only 10x slower than C, it's faster than some C versions! > (I'm sure it must be cheating somewhere...) Sure it does. C is statically compiled, while LuaJIT is a JIT compiler. It unjustly uses *runtime* information to compile the code. You can get a similar advantage with some C compilers by using profile based optimisation. BTW, I wonder why the code takes a whole 0.8 seconds to run in your gcc test. Maybe you should use a newer GCC version. It shouldn't take more than a couple of milliseconds (for program startup, OS calls, etc.), given that the output is a constant. Stefan From eliben at gmail.com Wed Sep 8 00:53:04 2010 From: eliben at gmail.com (Eli Bendersky) Date: Wed, 8 Sep 2010 07:53:04 +0300 Subject: Bit fields in python? In-Reply-To: References: Message-ID: > > > I'm trying to rewrite a c program in python & encountered several problems. > I have some data structures in my c program like below: > > typedef struct > { > unsigned short size; > > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsigned short var_a3:2; > unsigned short var_a4:2; > > unsigned int var_a5; > }structa; > > typedef struct > { > unsigned short size; > > unsigned char reserved:4; > unsigned char var_b1:1; > unsigned char var_b2:1; > unsigned char var_b3:1; > unsigned char var_b4:1; > > structa var_structa; > }structb; > > I tried to code the above in python but only got this far: > > class StructA(object): > def __init__(self, size=0) > self.size = size > > class StructB(object): > def __init__(self, size=0) > > Any equivalent for c data structures & bit fields in python? And how do I > define var_structa (in structb) in python? > > Bitfields are most commonly used for extreme space optimization - i.e. shoving several variables and flags with carefully limited ranges into a single work. In Python you rarely work this way (where such an optimization is warranted, Python isn't the best tool for the job). However, as in your use case, it is sometimes needed in Python in order to communicate with other devices over the network or some other link. In my work with Python and embedded devices I've found the construct library (http://construct.wikispaces.com/) very useful. It allows to you very easily define complex formats for frames/messages on the bit and byte level. The idea is to use construct to encode and decode messages being sent to an embedded device. It works great. If you have further questions about this approach, feel free to ask. Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Wed Sep 8 00:56:47 2010 From: nad at acm.org (Ned Deily) Date: Tue, 07 Sep 2010 21:56:47 -0700 Subject: Bug in Python 2.6 urlencode References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> <4c87013f$0$1625$742ec2ed@news.sonic.net> Message-ID: In article <4c87013f$0$1625$742ec2ed at news.sonic.net>, John Nagle wrote: > On 9/7/2010 5:43 PM, Terry Reedy wrote: > > On 9/7/2010 3:02 PM, John Nagle wrote: > >> There's a bug in Python 2.6's "urllib.urlencode". If you pass > >> in a Unicode character outside the ASCII range, instead of it > >> being encoded properly, an exception is raised. > >> > >> File "C:\python26\lib\urllib.py", line 1267, in urlencode > >> v = quote_plus(str(v)) > >> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in > >> position 0: ordinal not in range(128) > >> > >> This will probably work in 3.x, because there, "str" converts > >> to Unicode, and quote_plus can handle Unicode. This is one of > >> those legacy bugs left from the pre-Unicode era. > >> > >> There's a workaround. Call urllib.urlencode with a second > >> parameter of 1. This turns on the optional feature of > >> accepting tuples in the argument to be encoded, and the > >> code goes through a newer code path that works. > >> > >> Is it worth reporting 2.x bugs any more? Or are we in the > >> version suckage period, where version N is abandonware and > >> version N+1 isn't deployable yet. > > > > You may report 2.7 bugs, but please verify that the behavior is a bug in > > 2.7. However, bugs that have been fixed by the switch to switch to > > unicode for text are unlikely to be fixed a second time in 2.7. You > > might suggest an enhancement to the doc for urlencode if that workaround > > is not clear. Or perhaps that workaround suggests that in this case, a > > fix would not be too difficult, and you can supply a patch. > > > > The basic deployment problem is that people who want to use unicode text > > also want to use libraries that have not been ported to use unicode > > text. That is the major issue for many porting projects. > > In other words, we're in the version suckage period. It took me all of one minute to find where a similar issue was reported previously (http://bugs.python.org/issue1349732). One of the comments on the issue explains how to use the "doseq" form and an explicit encode to handle Unicode items. I don't see where that part of the suggestion made it into the documentation. I'm sure if you make a specific doc change suggestion, it will be incorporated into the 2.7 docs. If you think a code change is needed, suggest a specific patch. -- Ned Deily, nad at acm.org From pdlemper at earthlink.net Wed Sep 8 01:09:59 2010 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Wed, 08 Sep 2010 00:09:59 -0500 Subject: compare dictionaries References: Message-ID: On Tue, 7 Sep 2010 12:46:36 -0700 (PDT), Baba wrote: >level: beginner > >word= 'even' >dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2} > >i want to know if word is entirely composed of letters in dict2 > >my approach: >step 1 : convert word to dictionary(dict1) > >step2: >for k in dict1.keys(): > if k in dict2: > if dict1[k] != dict2[k]: > return False > return True > return False > return True > Assign letters to their corresponding primes with the following function - def alphaprime(c) : if c == 'a' return 2 elif c == 'b' return 3 elif c == 'c' return 5 ... elif c == 'y' return 97 elif c == 'z' return 101 else : return 0 Using above calculate a composite for the letters in the dictionary. Of course begin with 1 and multiply by the associated prime for each letter and repeat for each recurrence of that letter. Call this dictionarycomposite. Do the same for the word, parsing sequentially and multiplying by the prime for each letter. Call this wordcomposite. Now if dictionarycomposite % wordcomposite == 0 the word can be spelled with the letters in the dictionary. I used this in a word game : works fast. The Fundamental Theorum of Arithmetic may apply. Dave WB3DWE From nagle at animats.com Wed Sep 8 01:17:38 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Sep 2010 22:17:38 -0700 Subject: Bug in Python 2.6 urlencode In-Reply-To: References: <4c868c2d$0$1581$742ec2ed@news.sonic.net> <4c87013f$0$1625$742ec2ed@news.sonic.net> Message-ID: <4c871c6f$0$1584$742ec2ed@news.sonic.net> On 9/7/2010 9:56 PM, Ned Deily wrote: > In article<4c87013f$0$1625$742ec2ed at news.sonic.net>, > John Nagle wrote: >> On 9/7/2010 5:43 PM, Terry Reedy wrote: >>> On 9/7/2010 3:02 PM, John Nagle wrote: >>>> There's a bug in Python 2.6's "urllib.urlencode". If you pass >>>> in a Unicode character outside the ASCII range, instead of it >>>> being encoded properly, an exception is raised. .... >> >> In other words, we're in the version suckage period. > > It took me all of one minute to find where a similar issue was reported > previously (http://bugs.python.org/issue1349732). One of the comments > on the issue explains how to use the "doseq" form and an explicit encode > to handle Unicode items. I don't see where that part of the suggestion > made it into the documentation. I'm sure if you make a specific doc > change suggestion, it will be incorporated into the 2.7 docs. If you > think a code change is needed, suggest a specific patch. That's a very funny bug report. The report was created back in 2005: Title: urllib.urlencode provides two features in one param Type: feature request Stage: committed/rejected It wasn't listed as an actual bug. On 2005-12-29, "Mike Brown" writes "However, I was unable to reproduce your observation that doseq=0 results in urlencode not knowing how to handle unicode. The object is just passed to str()." This was back in the Python 2.4 days, when "str" restriction to ASCII wasn't enforced. Perhaps the original reporter and the developer were using different versions. Five years later (!) Terry J. Reedy writes '"put something somewhere" will not get action.' In July 2010, Senthil Kumaran writes "This was fixed as part of Issue8788. Closing this." Issue 8788 is a documentation fix only. John Nagle From kurianmthayil at gmail.com Wed Sep 8 02:02:10 2010 From: kurianmthayil at gmail.com (Kurian Thayil) Date: Wed, 8 Sep 2010 11:32:10 +0530 Subject: mail sending -- smtplib In-Reply-To: References: Message-ID: Got it fixed. It was a very silly mistake. mssg variable had each line with indent. Removed the indent and it worked. Regards, Kurian Thayil. On Tue, Sep 7, 2010 at 9:57 AM, Kurian Thayil wrote: > Hi All, > > I am a newbie in python. Just 2-3 days old wanting to learn this amazing > programming language. I was trying to send mails using smtplib module, so > did some google and found a code snippet. The mail gets sent, but doesn't > come in the right format when a for-loop is introduced (Not MIME standard?). > Without the for-loop the script works fine. Can anyone advice? > * > #!/usr/bin/env python > > import smtplib > > for i in range(1,5): > print "I is ",i > fromaddr='kurianmthayil at gmail.com' > toaddr='kurianmthayil at gmail.com' > print toaddr > mssg="""From: Kurian Thayil > To: Kurian Thayil > MIME-Version: 1.0 > Content-type: text/html > Subject: 12345 -- Reloaded :) > > Hey dude.. how are you???? > >



> Regards, >

> Kurian > """ > print "message is ",mssg > > smail=smtplib.SMTP('smtp.gmail.com',587) > > smail.ehlo() > smail.starttls() > smail.ehlo() > smail.login(fromaddr,'***********') > > smail.sendmail(fromaddr,toaddr,mssg) > print "Over" > * > > Regards, > > Kurian Thayil. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Sep 8 02:32:48 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Sep 2010 00:32:48 -0600 Subject: The Samurai Principle In-Reply-To: <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 9:35 PM, Phlip wrote: > Exceptions are very dangerous by themselves, because if you don't trap > them just right they can cause side-effects. And returning None on failure is dangerous, because if the programmer does not take care to handle that case, the program may attempt to regard it as actual data. This in turn results in hard-to-track bugs elsewhere in the program, a fate much worse than an unhandled exception. It's better to fail noisily than to fail silently. > They are worse than GOTO. This assertion is questionable at best. Exceptions are structured; goto is unstructured, giving you much more rope to hang yourself with. From sajuptpm at gmail.com Wed Sep 8 02:39:13 2010 From: sajuptpm at gmail.com (sajuptpm) Date: Tue, 7 Sep 2010 23:39:13 -0700 (PDT) Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> Message-ID: <7d2b1ed5-8cdd-4dcd-a8d0-065fda18e895@u5g2000prn.googlegroups.com> Detailed Description --------------------- l1 = [] l2 = [ ((3,8),(1,2)), ((1,3),(1,7)), ((7,0),(1,8)), ((4,2),(1,2)), ((2,9),(9,1)) ] I need to take each item from l2 and insert into l1 with first element(column)(3,1,7,4,2) sorted in ascending order and second element(column)(8,3,0,2,9) sorted in descending order. #SORTING for k in l2: flag=True for i, v in enumerate(l1): if v <= k: l1.insert(i,k) flag = False break if flag: l1.append(k) for a in l1: print a output ------- ((7, 0), (1, 8)) ((4, 2), (1, 2)) ((3, 8), (1, 2)) ((2, 9), (9, 1)) ((1, 3), (1, 7)) This will not give l1 with first element(column)(3,1,7,4,2) sorted in ascending order and second element(column)(8,3,0,2,9) sorted in descending order. -------------- I added a -ve signe to all first elements l2 = [ ((-3,8),(1,2)), ((-1,3),(1,7)), ((-7,0),(1,8)), ((-4,2),(1,2)), ((-2,9),(9,1)) ] #SORTING for k in l2: flag=True for i, v in enumerate(l1): if v <= k: l1.insert(i,k) flag = False break if flag: l1.append(k) for a in l1: print a output ------- ((-1, 3), (1, 7)) ((-2, 9), (9, 1)) ((-3, 8), (1, 2)) ((-4, 2), (1, 2)) ((-7, 0), (1, 8)) Now output is similar to first elements asc and second elements desc.But the problem is the -ve sign, i dont need that. Have any other method to do it?? From eckhardt at satorlaser.com Wed Sep 8 02:39:39 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 08 Sep 2010 08:39:39 +0200 Subject: list of tuples with dynamic change in position References: <74cea050-2e68-4982-979a-5beebbe80f20@l38g2000pro.googlegroups.com> <109hl7-ao8.ln1@satorlaser.homedns.org> <7bbe7204-f7dd-4054-97bd-7973ade72dc7@n19g2000prf.googlegroups.com> Message-ID: sajuptpm wrote: > i want to find the loaded machine based on cpu and mem and desk > utilization by changing this order. > > I created a UI using that i can change the order of item in the tuple. > But the problem is asc and desc sorting How about only changing the order in which the elements are displayed? In other words, the internal data is fixed, but both the sorting of the list and the order in which the parts of the records are displayed can be changed. Just my 2c Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From slaunger at gmail.com Wed Sep 8 02:55:48 2010 From: slaunger at gmail.com (Kim Hansen) Date: Wed, 8 Sep 2010 08:55:48 +0200 Subject: LZO decompressing with Python 2.5x on Windows for C dummies Message-ID: Hi list, I have some binary data files which contain embedded LZO compressed payloads mixed with normal C-struct like headers. I would like to have the ability to LZO decompress these payloads using a python 2.5.x script. I was hoping that there was an up-to-date plug-and-play LZO library available for Windows somewhere. However, I have not managed to find such a one. The closest I have gotten is on the official LZO home page: http://www.oberhumer.com/opensource/lzo/ There is a link to some old LZO 1.08 bindings for Python 2.2 there as a tar.gz (released back in 2002!) http://www.oberhumer.com/opensource/lzo/download/LZO-v1/python-lzo-1.08.tar.gz I managed to unpack that using the python tarfile module (very handy for the purpose) In essence, the tarball contains a setup.py lzomodule.c Makefile and some documentation It does not contain anything that appears to be binaries for Windows. The instructions indicate that I am supposed to build it myself using the Makefile. I do not have make nor a C-compiler installed, and I fear that if I were to compile it, it would be a very tedious process for me, and I would rather like to avoid it if at all possible. Concerning the Windows LZO binaries I have previously struggled with pytables and using LZO on Windows with HDF5 files, and in relation to that Francesc Alted was so kind to build Windows LZO ver. 1.08 binaries as discussed here http://www.pytables.org/moin/FAQ#A.5BWindows.5DCan.27tfindLZObinariesforWindows and available here as a zip file http://www.pytables.org/download/lzo-win Amongst others, this zip file has a Gwin32\bin\lzo1.dll file. By copying that to the ptables filder in my python25 installation I have managed to get LZO working with pytables. Getting back to the python bindings, the setup.py does contain a section, which indicates that it adresses a Windows platform also: ... if sys.platform == "win32": # Windows users have to configure the LZO_DIR path parameter to match # their LZO source installation. The path set here is just an example # and thus unlikely to match your installation. LZO_DIR = r"c:\src\lzo-1.08" include_dirs.append(os.path.join(CURL_DIR, "include")) extra_objects.append(os.path.join(CURL_DIR, "lzo.lib")) ... If I were clever enough I now guess I should be able to unpack the pytables lzo Windows binaries to some suitable place (any recommendations?) and modify the setup.py such that it correctly "binds the dll" (this is black magic to me). One thing, which concerns me, is that a file lzo.lib is mentioned in the current setup.py, but there is not a file with that name in the GnuWin32 zip zip file from Francesc in the lib folder of the zip I do find two lib files.: liblzo.lib liblzo-bcc.lib but are any of these related to the lzo.lib mentioned in the setup.py? It does not help that I have a very poor understanding of how Python binds to native libraries, nor how things should be "installed" manually. My next question, if somehow someone is able to guide me a little in the process, then how do I use the library once available. The README indicates that I should use the internal Python documentation- So I guess i should just open an IPython shell do an import lzo? and then tab on lzo. and see what is available? Sorry for the long post. Kind regards, Kim -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Sep 8 02:57:52 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Sep 2010 00:57:52 -0600 Subject: The Samurai Principle In-Reply-To: <642cd655-ade1-40d9-8d02-66ca9354d3c3@q21g2000prm.googlegroups.com> References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <642cd655-ade1-40d9-8d02-66ca9354d3c3@q21g2000prm.googlegroups.com> Message-ID: On Tue, Sep 7, 2010 at 9:38 PM, Phlip wrote: > Everyone gets defensive about the design flaws in their own language. > But the django.db situation is not even a design flaw; just a > misinterpretation of the Samurai Principle. int('yo') shall throw an > exception, but a missing record could be the result you were looking > for, so it's not exceptional. I consider it exceptional because it breaks the rule that Model.objects.get(...) returns an instance of Model. If it can also return None, then this needs to be checked for every time the method is called, because None does not implement the Model interface and will break if you try to use it like that. You're still doing exception handling; you're just doing it with an if instead of a try-except. I prefer to do exception handling in a block clearly marked as an exception handler. Out of curiosity, would you also regard the case where two matching records are found instead of one as not exceptional? After all, it could be the result you were looking for. What should QuerySet.get return in that case, if it doesn't raise an exception? From __peter__ at web.de Wed Sep 8 04:08:30 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 08 Sep 2010 10:08:30 +0200 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> <7d2b1ed5-8cdd-4dcd-a8d0-065fda18e895@u5g2000prn.googlegroups.com> Message-ID: sajuptpm wrote: > Now output is similar to first elements asc and second elements > desc.But the problem is the -ve sign, i dont need that. > > Have any other method to do it?? Sort twice: >>> for item in items: ... print item ... ('adams', 'anne') ('miller', 'arnold') ('miller', 'bill') ('adams', 'berta') ('adams', 'charlotte') ('miller', 'thomas') >>> items.sort(key=lambda x: x[1], reverse=True) >>> items.sort(key=lambda x: x[0]) >>> for item in items: ... print item ... ('adams', 'charlotte') ('adams', 'berta') ('adams', 'anne') ('miller', 'thomas') ('miller', 'bill') ('miller', 'arnold') See? First column ascending, second column descending within groups of rows with equal first column. Peter From tanja2late at googlemail.com Wed Sep 8 04:51:12 2010 From: tanja2late at googlemail.com (Tanje Toolate) Date: Wed, 8 Sep 2010 01:51:12 -0700 (PDT) Subject: console-editor written in python Message-ID: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> hi there, greetings. i am looking for a small, console-based (opensource) texteditor, written in python (or as shellscript!), but i'm not finding something usable. very find would be emacs-keybindings ... dank u well, tanja From raoulbia at gmail.com Wed Sep 8 06:04:24 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 8 Sep 2010 03:04:24 -0700 (PDT) Subject: mutate dictionary or list References: <87zkvt4p8v.fsf@web.de> <87pqwpboh8.fsf@benfinney.id.au> Message-ID: <6ff00c38-35a9-427e-937a-3f3cb99c2c6c@i5g2000yqe.googlegroups.com> On 7 sep, 16:46, Ben Finney wrote: > de... at web.de writes: > > Objects can be mutable or immutable. For example, in Python, integers, > > strings, floats and tuples are immutable. That means that you can't > > change their value. > > Yes. Importantly, wherever you see code that you *think* is changing the > value of an immutable object, you're thinking incorrectly. (There's no > shame in that; other languages give us preconceptions that can be hard > to shake off.) > > The only way to get a different value from an integer object is to ask > Python for a different integer object; the original is unchanged. The > same goes for tuples, strings, and all the other immutable types. > > > Mutable objects OTOH can be changed. > > [?] > > Some good articles to explain Python's object model: > > ? ? ? > ? ? ? > > -- > ?\ ? ? ? ? ? ? ?We can't depend for the long run on distinguishing one | > ? `\ ? ? ? ? bitstream from another in order to figure out which rules | > _o__) ? ? ? ? ? ? ? apply.? ?Eben Moglen, _Anarchism Triumphant_, 1999 | > Ben Finney Thanks all for feedback! Baba From raoulbia at gmail.com Wed Sep 8 06:30:00 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 8 Sep 2010 03:30:00 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> Message-ID: <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> On 8 sep, 02:07, Ben Finney wrote: > Baba writes: > > However the following Wiki excerpt seems to go in my direction: > > No, it doesn't. It advises that people show kindness; as I've been > arguing, that's exactly what you were shown. You haven't shown how the > information being imparted could have been fully imparted in a way > that's kinder, nor that it would be reasonable to do so. > > To put it another way: if you feel offended by an utterance, then > insufficient kindness on the part of the speaker is not the only > explanation. > > -- > ?\ ? ? ??Software patents provide one more means of controlling access | > ? `\ ? ? ?to information. They are the tool of choice for the internet | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? highwayman.? ?Anthony Taylor | > Ben Finney Hi Ben, Thanks for your feedback. My question is: Who owns this forum? If we all do then we are allowed to post questions that are simple and that could otherwise be answered by doing research. It is just unfriendly to tell someone to go and look it up by themselves. Who is licensed to judge what can and cannot be posted as a question? A teacher of mine used to say: "There are no stupid questions, there are only stupid answers." It is arrogant to tell someone in a Forum to "look it up yourself ,this question is too basic". Can you not understand that accessing a file can seem daunting at first? Believe me, documentation can be offputting too when you only start with programming. Per se the beauty of forums like these is that there are human beings willing to make such tasks as finding out how to access a text file less 'scary'. Whoever thinks he or she has a license to tell someone to look up the answer by themselves should think again. I reckon the only license we have is not to answer at all. I acknowledge that Benjamin pointed me to the right place to find an answer but somehow the "Please do us a favour" sounded bit arrogant, as if he owned the place (same goes for all those who sided against me here: do you own this forum?)...i'd be glad if there was a python for beginners forum but in the meantime i have to say i find it awesome to have this forum to get help. It makes a BIG difference. So sorry if i upset anyone, we all have our opinions and get carried away and can be stubborn, i DO respect everyone in this forum and i think it goes bothways. I've learned a few things in this post... So now, to use Benjamin words: Please do me a favour and let's move on :) Baba Baba From laicheng_kwan at innomedia.com.sg Wed Sep 8 06:43:20 2010 From: laicheng_kwan at innomedia.com.sg (Kwan Lai Cheng) Date: Wed, 8 Sep 2010 18:43:20 +0800 Subject: Bit fields in python? References: Message-ID: <2DB4DD760DFD46EBA608F9D121999F89@cs0403293> Thanks everyone for all the suggestions! New to python, so reading up on the struct module & Construct library now, hope to get my problem fixed soon. ----- Original Message ----- Bitfields are most commonly used for extreme space optimization - i.e. shoving several variables and flags with carefully limited ranges into a single work. In Python you rarely work this way (where such an optimization is warranted, Python isn't the best tool for the job). However, as in your use case, it is sometimes needed in Python in order to communicate with other devices over the network or some other link. In my work with Python and embedded devices I've found the construct library (http://construct.wikispaces.com/) very useful. It allows to you very easily define complex formats for frames/messages on the bit and byte level. The idea is to use construct to encode and decode messages being sent to an embedded device. It works great. If you have further questions about this approach, feel free to ask. Eli ------------------------------------------------------------------------------ -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Wed Sep 8 06:46:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 03:46:18 -0700 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <7xhbi0y0lh.fsf@ruckus.brouhaha.com> Baba writes: > It is just unfriendly > to tell someone to go and look it up by themselves. Someone seeing too many unthoughtful questions from you might tell you to look it up yourself, in the hopes of getting you to change your questioning style, so that your future questions will be more thoughtful and worth answering. But according to you that would be unfriendly. Another thing they could do is say nothing, but quietly configure their news-reading software to ignore your questions completely. Then none of your future questions would have any hope of being answered. Would that be less unfriendly, or more unfriendly? From debatem1 at gmail.com Wed Sep 8 06:55:21 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 8 Sep 2010 03:55:21 -0700 Subject: Bit fields in python? In-Reply-To: References: Message-ID: On Tue, Sep 7, 2010 at 9:53 PM, Eli Bendersky wrote: >> >> I'm trying to rewrite a c program in python & encountered several >> problems. I have some data structures in my c program like below: >> >> typedef struct >> { >> ??? unsigned short size; >> >> ??? unsigned short reserved:8; >> ??? unsigned short var_a1:2; >> ??? unsigned short var_a2:2; >> ??? unsigned short var_a3:2; >> ??? unsigned short var_a4:2; >> >> ??? unsigned int var_a5; >> }structa; >> >> ?typedef struct >> { >> ??? unsigned short size; >> >> ??? unsigned?char reserved:4; >> ??? unsigned?char var_b1:1; >> ??? unsigned?char var_b2:1; >> ??? unsigned?char var_b3:1; >> ??? unsigned?char var_b4:1; >> >> ????structa var_structa; >> }structb; >> >> I tried to code the above in python but only got this far: >> >> class StructA(object): >> ??? def __init__(self, size=0) >> ??? self.size = size >> >> class StructB(object): >> ??? def __init__(self, size=0) >> >> Any equivalent for c data structures & bit fields in python??And how do I >> define var_structa (in structb) in python? >> > > Bitfields are most commonly used for extreme space optimization - i.e. > shoving several variables and flags with carefully limited ranges into a > single work. In Python you rarely work this way (where such an optimization > is warranted, Python isn't the best tool for the job). However, as in your > use case, it is sometimes needed in Python in order to communicate with > other devices over the network or some other link. > > In my work with Python and embedded devices I've found the construct library > (http://construct.wikispaces.com/) very useful. It allows to you very easily > define complex formats for frames/messages on the bit and byte level. The > idea is to use construct to encode and decode messages being sent to an > embedded device. It works great. > > If you have further questions about this approach, feel free to ask. > > Eli That's really an excellent find. Thanks for bringing it up. Geremy Condra From eckhardt at satorlaser.com Wed Sep 8 06:55:56 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 08 Sep 2010 12:55:56 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de><4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: BartC wrote: > So 'range' is just a class like any other. And that a class is something > you can blithely copy from one variable to another. And whenever you see > 'range' anywhere, you can't always be certain that someone hasn't done: > > range = 42 > > at some point. True. I read an explanation here that IMHO pretty well explains what's going on: The "range" above is a label, attached with a piece of string to an object. The object in this case is the integer 42. The same object can have multiple labels attached to it, so "foo = bar" will just create a new label "foo" and attach it to the object that the label "bar" is already attached to. Note that I said object, which includes class instances like the int 42 above, but also the classes themselves, functions (or bound functions[1]) and modules (I hope I didn't miss any). > That explains a lot about the difficulties of implementing Python > efficiently. Yes, "range" is not a keyword or something intrinsic to the interpreter. It is just a name that is looked up whenever it is encountered, and that costs time. However, you also get some nice flexibility at that cost. Cheers! Uli [1] bound function = class function where the instance parameter is bound. Example: x = [] a = x.append a(42) # calls x.append(42) -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From raoulbia at gmail.com Wed Sep 8 07:28:32 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 8 Sep 2010 04:28:32 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> Message-ID: <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> On 8 sep, 12:46, Paul Rubin wrote: > Baba writes: > > It is just unfriendly > > to tell someone to go and look it up by themselves. > > Someone seeing too many unthoughtful questions from you might tell you > to look it up yourself, in the hopes of getting you to change your > questioning style, so that your future questions will be more thoughtful > and worth answering. ?But according to you that would be unfriendly. > > Another thing they could do is say nothing, but quietly configure their > news-reading software to ignore your questions completely. ?Then none of > your future questions would have any hope of being answered. ?Would that > be less unfriendly, or more unfriendly? Hi Paul I would support option 1 but phrased more thoughtfully than Benjamin did (that way no feelings will be hurt): "Dear xyz, Your question can easily be researched online. We suggest you give it a try and to look it up yourself. This will be beneficial both to you and to us. We do encourage to ask questions only when they have been researched first. We care about the quality of posts but we also understand that as a beginner one can tend to look for an easy or quick way to find answers. So in the meantime here's something to get you started: link" But where do you draw the line? Can we not just let people ask questions regardless? And let those answer who want to and those who don't just ignore the question? That seems so much easier to me. From cjwilliams43 at gmail.com Wed Sep 8 07:45:28 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Wed, 08 Sep 2010 07:45:28 -0400 Subject: console-editor written in python In-Reply-To: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: On 08-Sep-10 04:51 AM, Tanje Toolate wrote: > hi there, > > > greetings. > > i am looking for a small, console-based (opensource) texteditor, > written in python (or as shellscript!), but i'm not finding something > usable. > > very find would be emacs-keybindings ... > > > dank u well, > > > tanja What operating system do you use? Colin W. From tanja2late at googlemail.com Wed Sep 8 07:50:56 2010 From: tanja2late at googlemail.com (Tanje Toolate) Date: Wed, 8 Sep 2010 04:50:56 -0700 (PDT) Subject: console-editor written in python References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: > > What operating system do you use? > > Colin W. usually linux. sometimes bsd. tanja From tanja2late at googlemail.com Wed Sep 8 07:51:05 2010 From: tanja2late at googlemail.com (Tanje Toolate) Date: Wed, 8 Sep 2010 04:51:05 -0700 (PDT) Subject: console-editor written in python References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: <9eb44d17-8526-4655-b2f4-99ecca226141@b34g2000yqm.googlegroups.com> > > What operating system do you use? > > Colin W. usually linux. sometimes bsd. tanja From sustainable.future115 at gmail.com Wed Sep 8 08:25:20 2010 From: sustainable.future115 at gmail.com (......) Date: Wed, 8 Sep 2010 05:25:20 -0700 (PDT) Subject: Why Insulation is a Good Investment Message-ID: <49729c8c-8791-4a5e-80ae-cc3a4eab80c3@f25g2000yqc.googlegroups.com> Why Insulation is a Good Investment Investing in products to make homes more energy efficient pays significant dividends over a lifetime ? with none of the wild fluctuations of Wall Street. Insulation contributes to: - Greater comfort - Even temperature distribution - Improved acoustics - Better moisture control, which can reduce floor squeaks, drywall cracks, structure damage and condensation - Potential for increased resale value: Installing proper insulation levels can also make your home more attractive to potential buyers. In fact, most buyers list energy-efficiency as a prime consideration. The reason? Buyers know they can buy a more expensive home if heating and cooling bills can be kept down. - A more environmentally friendly home - Lower energy bills* Unless your home was constructed with special attention to energy efficiency, adding insulation will probably reduce your utility bills. - 60% of the existing homes in the United States are not insulated to the best level. - According toa study done by Harvard University's School of Public Health, 60% of the exising homes are likely to use more energy than newer homes, leading to very high heating and air-conditioning bills. - Even if you own a new home, adding insulation may save enough money in reduced utility bills to pay for itself within a few years and will continue to save you money for as long as you own the home.* Source: http://www.simplyinsulate.com/content/why/benefits.html From no.email at nospam.invalid Wed Sep 8 08:39:22 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 05:39:22 -0700 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> Message-ID: <7xmxrsif45.fsf@ruckus.brouhaha.com> Baba writes: > But where do you draw the line? Can we not just let people ask > questions regardless? And let those answer who want to and those who > don't just ignore the question? That seems so much easier to me. The first few times, it's easy to ignore the questions. After a few more times, it becomes easier to ignore the person asking the questions, and not even look at the questions. The answer to many of your questions also is not "research it online", but rather, "figure it out with your own creativity". That's what being a programmer is about--figuring out solutions that don't already exist elsewhere. From thracs at gmail.com Wed Sep 8 08:57:44 2010 From: thracs at gmail.com (Ann Thracs) Date: Wed, 8 Sep 2010 05:57:44 -0700 (PDT) Subject: One Jew RASPUTIN hires another gentile RASPUTIN - to look good in comparison - always, profligate white led by a misleader jew - roman polansky, bernard madoff, moshe katsav, Craigslist Killer Philip Markoff jew Message-ID: <45c75078-8d58-41db-a074-a49aadfa1d70@b34g2000yqm.googlegroups.com> One Jew RASPUTIN hires another gentile RASPUTIN - to look good in comparison - always, profligate white led by a misleader jew - roman polansky, bernard madoff, moshe katsav, Craigslist Killer Philip Markoff jew HP CEO Mark Hurd Resigns After Sexual-Harassment Probe JORDAN ROBERTSON and RACHEL METZ | 08/ 6/10 11:53 PM | AP Resignation On August 6, 2010, he resigned from all of his positions at HP, following discovery of inappropriate conduct in an investigation into a claim of sexual harassment made by former reality TV actress Jodie Fisher. THE ZIONIST JEW LARRY ELLISON WHOSE COMPANY STOLE SAUDI MONEY TO DEVELOP ARABIC SUPPORT OF ORACLE TO HELP ISRAEL MONITOR THE PALESTINIAN PRISON AND LABOR CAMP - ONE NEEDS TO DO INVESTIGATION TO FIND THE BONES - A LOT OF BONES IN HIS CLOSET . A thorough good investigation into oracle's past should prove this. There should be a wikileaks on corporate crimes as well. http://www.zpub.com/un/un-le.html "Hi there, can I buy you a car?" According to accusations from an ongoing trial, that's the approach the Oracle CEO used to convince company secretaries to, ahem, "date" the boss. The case involves a 33- year-old former employee [FALSELY AND WRONGLY] accused of forging an email message. The woman [Adelyn Lee], who was fired shortly after an affair with Ellison, obtained a $100,000 settlement from him. Larry Ellison's All-Time Top Pickup Line http://www.thesmokinggun.com/documents/crime/polanski-predator jew roman polanski raped 13 year old girl semantha geimer, orally, vaginally and anally without any mercy jew roman polanski raped 13 year old girl semantha geimer, orally, vaginally and anally without any mercy SAN FRANCISCO ? Hewlett-Packard Co. ousted its CEO on Friday for allegedly falsifying documents to conceal a relationship with a former contractor and help her get paid for work she didn't do. News of Mark Hurd's abrupt departure sent HP's stock tumbling. Shares of the world's biggest maker of personal computers and printers have doubled in value during his five-year stewardship, and HP became the world's No. 1 technology company by revenue in that time. The company said it learned about the relationship several weeks ago, when the woman, who did marketing work for HP, sent a letter accusing Hurd, 53, and the company of sexual harassment. An investigation found that Hurd falsified expense reports and other financial documents to conceal the relationship. The company said it found that its sexual harassment policy wasn't violated but that its standards of business conduct were. Hurd's "systematic pattern" of submitting falsified financial reports to hide the relationship From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 09:13:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 13:13:09 GMT Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> Message-ID: <4c878be5$0$11113$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 11:00:03 +0100, BartC wrote: >> for i in xrange(100000000): >> a = a + f(i) >> >> then unrolling the loop is even less useful. The overhead of the loop >> itself is likely to be trivial compared to the cost of calling f() 100 >> million times -- the added complexity to shave 3 seconds off a four >> minute calculation simply isn't worth it. > > With Python 3 and def f(x): return x+1, unrolling this loop 4x improved > speed by 15%; 4.00 minutes reduces to 3.30 minutes. I'm afraid that I can't replicate those figures. In my test, unrolling the loop causes a massive SLOWDOWN of 37%, not a speed up. Here is my test code: def f(x): return x+1 def test_loop(n): a = 0 for i in range(n): a += f(i) return a def test_unrolled(n): a = 0 for i in range(n//4): a += f(4*i) a += f(4*i+1) a += f(4*i+2) a += f(4*i+3) return a from timeit import Timer n = 10000000 assert test_loop(n) == test_unrolled(n) t1 = Timer('test_loop(n)', 'from __main__ import test_loop; n=%d' % n) t2 = Timer('test_unrolled(n)', 'from __main__ import test_unrolled; n=%d' % n) And here are the results using Python 3.1. Times are the best of 5 for 10 calls each to the loop_* functions, results given in seconds: >>> min(t1.repeat(number=10, repeat=5))/10 5.97409288883209 >>> min(t2.repeat(number=10, repeat=5))/10 8.25656900405883 I repeated it with a larger loop variable. Since the time per test was so large (over ten minutes per call on my machine!), I didn't see the need to run multiple trials: n *= 100 assert test_loop(n) == test_unrolled(n) t3 = Timer('test_loop(n)', 'from __main__ import test_loop; n=%d' % n) t4 = Timer('test_unrolled(n)', 'from __main__ import test_unrolled; n=%d' % n) And the results: >>> t3.timeit(number=1) 653.3572518825531 >>> t4.timeit(number=1) 864.6454808712006 That's slightly better (32% slower instead of 37% slower), but still a massive performance hit. Given these results, I'm prepared to say that loop unrolling in Python is almost certainly going to be a pessimation, not an optimization, no matter what you have inside the loop. -- Steven From alain at dpt-info.u-strasbg.fr Wed Sep 8 09:58:01 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 08 Sep 2010 15:58:01 +0200 Subject: Speed-up for loops References: <4C7F7640.1010102@perfect-kreim.de> <4c83b425$0$28657$c3e8da3@news.astraweb.com> <4c85adfe$0$11115$c3e8da3@news.astraweb.com> <4c878be5$0$11113$c3e8da3@news.astraweb.com> Message-ID: <87sk1k9w2e.fsf@dpt-info.u-strasbg.fr> Steven D'Aprano writes: >> With Python 3 and def f(x): return x+1, unrolling this loop 4x improved >> speed by 15%; 4.00 minutes reduces to 3.30 minutes. > I'm afraid that I can't replicate those figures. In my test, unrolling > the loop causes a massive SLOWDOWN of 37%, not a speed up. Here is my > test code: > > def f(x): > return x+1 > > def test_loop(n): > a = 0 > for i in range(n): > a += f(i) > return a > > def test_unrolled(n): > a = 0 > for i in range(n//4): > a += f(4*i) > a += f(4*i+1) > a += f(4*i+2) > a += f(4*i+3) > return a > > from timeit import Timer > n = 10000000 > assert test_loop(n) == test_unrolled(n) > t1 = Timer('test_loop(n)', > 'from __main__ import test_loop; n=%d' % n) > t2 = Timer('test_unrolled(n)', > 'from __main__ import test_unrolled; n=%d' % n) > > And here are the results using Python 3.1. Times are the best of 5 for 10 > calls each to the loop_* functions, results given in seconds: > >>>> min(t1.repeat(number=10, repeat=5))/10 > 5.97409288883209 >>>> min(t2.repeat(number=10, repeat=5))/10 > 8.25656900405883 Running this test with python 2.6 (on my laptop) led to: >>> min(t1.repeat(number=10, repeat=5))/10 2.10715539455 >>> min(t2.repeat(number=10, repeat=5))/10 2.43037149906 That's a 15% slowdown. Which is reasonable since you add four multiplies in the loop body. Changing your unrolled loop to: def test_unrolled(n): a = 0 for i in range(n//4): b = 4*i a += f(b) a += f(b+1) a += f(b+2) a += f(b+3) return a makes both versions run in approximately the same time (2.135 vs. 2.136). > That's slightly better (32% slower instead of 37% slower), but still a > massive performance hit. Given these results, I'm prepared to say that > loop unrolling in Python is almost certainly going to be a pessimation, > not an optimization, no matter what you have inside the loop. I don't really see why it should be the case. Do you have any idea? I don't think either that it should speed things up significantly. Loop unrolling in binary code is relevant mostly because it allows better instruction scheduling (i.e., scheduling has fewer constraints in longer instruction sequences). Python programs are way too far from binary code for scheduling opts to apply. -- Alain. From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 09:58:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 13:58:05 GMT Subject: Automatic delegation in Python 3 Message-ID: <4c87966d$0$11113$c3e8da3@news.astraweb.com> Delegation in old-style classes worked fine: # Python 2.6 >>> class Delegate: ... def __init__(self, x): ... self.__dict__['x'] = x ... def __getattr__(self, name): ... return getattr(self.x, name) ... def __setattr__(self, name, value): ... setattr(self.x, name, value) ... >>> obj = Delegate({}) >>> obj[1] = None >>> obj {1: None} But when I try the equivalent recipe with a new-style class, it behaves differently: >>> class Delegate2(object): ... def __init__(self, x): ... self.__dict__['x'] = x ... def __getattr__(self, name): ... return getattr(self.x, name) ... def __setattr__(self, name, value): ... setattr(self.x, name, value) ... >>> obj = Delegate2({}) >>> obj <__main__.Delegate2 object at 0x8f6130c> Okay, I get that one... because I'm inheriting from object, __getattr__ picks up object's __str__ method and uses that. But then there's this: >>> obj[1] = 0 Traceback (most recent call last): File "", line 1, in TypeError: 'Delegate2' object does not support item assignment But these work: >>> obj.__setitem__ >>> obj.__setitem__(1, None) >>> obj.x {1: None} What's going on here? I *think* this has something to do with special double-underscore methods being looked up on the class, not the instance, for new-style classes, but I'm not entirely sure. Unfortunately, I need to use delegation, not inheritance, and I need to use a new-style class, since I will be using Python 3. How can I do automatic delegation in Python 3? Is my only hope to give up on the elegance of automatic delegation, and code all the special methods as manual delegation? class Delegate2(object): def __setitem__(self, key, value): self.x[key] = value # and so on for everything else I care about... -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 10:21:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 14:21:11 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: <4c879bd7$0$11113$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 20:35:45 -0700, Phlip wrote: > Exceptions are very dangerous by themselves, because if you don't trap > them just right they can cause side-effects. Huh? If you don't trap them just right, the cause a stack trace, which is a side-effect I suppose. But it's an *intended* side-effect, since the alternative would be a core dump (or worse, an incorrect program that *doesn't* crash). This is a good thing! -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 10:26:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 14:26:34 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <1d5a8adb-e17d-46c2-841b-46453e780ce4@k17g2000prf.googlegroups.com> <4c864493$0$12641$426a74cc@news.free.fr> <21a709d0-cac9-4051-a002-868ac69014f9@x18g2000pro.googlegroups.com> <642cd655-ade1-40d9-8d02-66ca9354d3c3@q21g2000prm.googlegroups.com> Message-ID: <4c879d19$0$11113$c3e8da3@news.astraweb.com> On Tue, 07 Sep 2010 20:38:14 -0700, Phlip wrote: > On Sep 7, 5:51?pm, Terry Reedy wrote: >> On 9/7/2010 2:53 PM, Phlip wrote: >> >> > They are for situations which the caller should care not to handle. >> >> Python is simply not designed that way. Exception raising and catching >> is a common flow-control method in Python. If you cannot stand that, >> Python is not for you. > > While I'm at it, I'm going to log into comp.lang.java.misc and explain > to everyone why static typing is overkill, and implementation > inheritance is good for you. > > Everyone gets defensive about the design flaws in their own language. > But the django.db situation is not even a design flaw; just a > misinterpretation of the Samurai Principle. int('yo') shall throw an > exception, but a missing record could be the result you were looking > for, so it's not exceptional. I think you've misunderstood the meaning of "exception" if you think that. It doesn't mean "error". Nor does it mean "rare". (Although, given that exceptions in Python are expensive, one would hope they're not *too* common.) The unexceptional case of looking up a record is to find it. That, after all, is the purpose of the lookup function -- to find the given record. That's what it is designed to do, and anything else is considered exceptional. Whether the lookup function returns a special "not found" result, or raises an exception, or sets some magic global error code somewhere, it's still an exceptional case. -- Steven From aahz at pythoncraft.com Wed Sep 8 10:42:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Sep 2010 07:42:28 -0700 Subject: problem with simple multiprocessing script on OS X References: <5fcea7ea-13ad-41af-8a68-9d418f9cdf93@i31g2000yqm.googlegroups.com> <45015919-6de0-4ed3-b4fe-62824e16cd43@t11g2000vbc.googlegroups.com> Message-ID: In article , Darren Dale wrote: > >About a year ago, I contributed a patch to h5py which checks to see if >h5py is being imported into an active IPython session. If so, then a >custom tab completer is loaded to make it easier to navigate hdf5 >files. In the development version of IPython, a function that used to >return None if there was no instance of an IPython interactive shell >now creates and returns a new instance. This was the cause of the >error I was reporting. Hoist on your own petard, eh? ;-) Thanks for reporting the solution. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box." --Cliff Wells From invalid at invalid.invalid Wed Sep 8 10:44:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Sep 2010 14:44:12 +0000 (UTC) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> <4c879bd7$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-08, Steven D'Aprano wrote: > On Tue, 07 Sep 2010 20:35:45 -0700, Phlip wrote: > >> Exceptions are very dangerous by themselves, because if you don't trap >> them just right they can cause side-effects. > > Huh? > > If you don't trap them just right, they cause a stack trace, Not always. That is the effect of not trapping them at all. However, you can trap them incorrectly -- which can result in hard-to-track down problems. The main example of this is a "bare except" clause that not only catches and handles the "expected" exception but also catches (and mishandles/ignores) an unexpected one. > which is a side-effect I suppose. But it's an *intended* side-effect, > since the alternative would be a core dump (or worse, an incorrect > program that *doesn't* crash). This is a good thing! -- Grant Edwards grant.b.edwards Yow! -- I have seen the at FUN -- gmail.com From thomas at jollybox.de Wed Sep 8 10:49:31 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 8 Sep 2010 16:49:31 +0200 Subject: console-editor written in python In-Reply-To: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: <201009081649.32381.thomas@jollybox.de> On Wednesday 08 September 2010, it occurred to Tanje Toolate to exclaim: > hi there, > > > greetings. > > i am looking for a small, console-based (opensource) texteditor, > written in python (or as shellscript!), but i'm not finding something > usable. Why? (Also, I can't imagine anyone writing a shell script that deserves, or even aspires to deserve, the name "text editor"). > > very find would be emacs-keybindings ... Why not just use a real emacs ? From invalid at invalid.invalid Wed Sep 8 10:57:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Sep 2010 14:57:32 +0000 (UTC) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: On 2010-09-08, Baba wrote: > Thanks for your feedback. My question is: Who owns this forum? If we > all do then we are allowed to post questions that are simple and that > could otherwise be answered by doing research. Of course you're allowed to post such questions. And people are allowed to ignore you, to answer your question sarcastically, to attempt to teach you how to answer your own questions, or to respond in other ways. It's up to _you_ to make the effort to try to insure that you get a useful response. To that end here is how that is accomplished: http://catb.org/esr/faqs/smart-questions.html Maybe you don't _like_ the fact that you are expected to show just a tiny bit of inititiative and care in researching and posting your question, but that's pretty much the way it it works. I'm sure you'd prefer that everything was handed to you for free on a silver platter with a side order of beer and cookies. I'd prefer I was 20 years younger and 30 pounds lighter. Life's tough that way. > It is just unfriendly to tell someone to go and look it up by > themselves. 1) It isn't if give them a hint on where to look it up. 2) Posting questions like yours is considered unfriendly. > Who is licensed to judge what can and cannot be posted as a question? Nobody. Post whatever questions you want however you want in whatever language you want. If you don't care about actually _answering_ your question, feel free to continue in the same vein in which you started. If you _do_ care about getting a prompt, accurate answer, then: http://catb.org/esr/faqs/smart-questions.html > A teacher of mine used to say: "There are no stupid questions, there > are only stupid answers." Ask that teacher for help then. > It is arrogant to tell someone in a Forum to "look it up yourself, > this question is too basic". Perhaps it is. But remember you're the one asking strangers for a free service, so it's up to you to "play by the rules" in return for that free service. One of the rules is that you first try to answer the question yourself. > Can you not understand that accessing a file can seem daunting at > first? Maybe so, but reading a tutorial isn't. -- Grant Edwards grant.b.edwards Yow! I need to discuss at BUY-BACK PROVISIONS gmail.com with at least six studio SLEAZEBALLS!! From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 11:13:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 15:13:25 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> <4c879bd7$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c87a815$0$11113$c3e8da3@news.astraweb.com> On Wed, 08 Sep 2010 14:44:12 +0000, Grant Edwards wrote: > On 2010-09-08, Steven D'Aprano > wrote: >> On Tue, 07 Sep 2010 20:35:45 -0700, Phlip wrote: >> >>> Exceptions are very dangerous by themselves, because if you don't trap >>> them just right they can cause side-effects. >> >> Huh? >> >> If you don't trap them just right, they cause a stack trace, > > Not always. That is the effect of not trapping them at all. However, > you can trap them incorrectly -- which can result in hard-to-track down > problems. > > The main example of this is a "bare except" clause that not only catches > and handles the "expected" exception but also catches (and > mishandles/ignores) an unexpected one. Ah, fair enough. That would be a false positive error -- catching too much rather than too little. Still, that's no better, or worse, than misinterpreting special error codes that are returned by functions. The main error mode there is catching too little -- people neglect to check the error code, and therefore have buggy code: p = some_string.find('#') print some_string[:p] And who hasn't done this more than once? re.search(pattern, some_string).group() -- Steven From kixo82 at googlemail.com Wed Sep 8 11:25:33 2010 From: kixo82 at googlemail.com (mex) Date: Wed, 8 Sep 2010 08:25:33 -0700 (PDT) Subject: console-editor written in python References: <58aa31b8-8503-4f7e-9343-5f8c3b979d90@m1g2000yqo.googlegroups.com> Message-ID: On 8 Sep., 16:49, Thomas Jollans wrote: > On Wednesday 08 September 2010, it occurred to Tanje Toolate to exclaim: > > > hi there, > > > greetings. > > > i am looking for a small, console-based (opensource) texteditor, > > written in python (or as shellscript!), but i'm not finding something > > usable. > > Why? > (Also, I can't imagine anyone writing a shell script that deserves, or even > aspires to deserve, the name "text editor"). > > > > > very find would be emacs-keybindings ... > > Why not just use a real emacs ? why? because! ok, the part with the shellscript was a joke ... we usually use joe/jmacs but run into issues lately on customer- environments with precompiled versions of this editor. a python-based console- editor would be perfekt. tanja From bruno.42.desthuilliers at websiteburo.invalid Wed Sep 8 12:15:08 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 08 Sep 2010 18:15:08 +0200 Subject: accessing a text file In-Reply-To: <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> Message-ID: <4c87b67e$0$21620$426a74cc@news.free.fr> Baba a ?crit : > > "Dear xyz, > Your question can easily be researched online. We suggest you give it > a try and to look it up yourself. This will be beneficial both to you > and to us. We do encourage to ask questions only when they have been > researched first." On usenet - as well as on most technical forums / mailing lists / etc -, this usually condensed in a well-known four letters acronym : "RTFM" Hopefully c.l.py is an unusually friendly and polite place, so we tend to say it a bit more elegantly and most of the time we do indeed provide a link. This being said and given your attitude - you may not realize it, but by now you would have been flamed to hell and back on quite a few other newsgroups -, I'm very tempted to switch to option 2. From ron.eggler at gmail.com Wed Sep 8 12:59:18 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 8 Sep 2010 09:59:18 -0700 (PDT) Subject: listening socket Message-ID: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> Hi, I'm trying to create a listening socket connection on port 1514. I tried to follow the documentation at: http://docs.python.org/release/2.5.2/lib/socket-example.html and came up with following lines: import socket host = '' # Symbolic name meaning all available interfaces port = 1514 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while 1: data = conn.recv(1024) if not data: break conn.send(data) conn.close() but that is not working, i'm getting this: import: unable to open X server `' @ error/import.c/ImportImageCommand/ 362. ./sockettest.py: line 4: host: command not found ./sockettest.py: line 5: port: command not found ./sockettest.py: line 6: syntax error near unexpected token `(' ./sockettest.py: line 6: `s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)' now why would it try to open an x server??? :o From benjamin.kaplan at case.edu Wed Sep 8 13:06:44 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 8 Sep 2010 13:06:44 -0400 Subject: listening socket In-Reply-To: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> References: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> Message-ID: On Wed, Sep 8, 2010 at 12:59 PM, cerr wrote: > Hi, > > I'm trying to create a listening socket connection on port 1514. > I tried to follow the documentation at: > http://docs.python.org/release/2.5.2/lib/socket-example.html > and came up with following lines: > import socket > > host = '' ? ? ? ? ? ? ? ? # Symbolic name meaning all available > interfaces > port = 1514 ? ? ? ? ? ? ? # Arbitrary non-privileged port > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((host, port)) > s.listen(1) > conn, addr = s.accept() > print 'Connected by', addr > while 1: > ? ?data = conn.recv(1024) > ? ?if not data: break > ? ?conn.send(data) > conn.close() > but that is not working, i'm getting this: > import: unable to open X server `' @ error/import.c/ImportImageCommand/ > 362. > ./sockettest.py: line 4: host: command not found > ./sockettest.py: line 5: port: command not found > ./sockettest.py: line 6: syntax error near unexpected token `(' > ./sockettest.py: line 6: `s = socket.socket(socket.AF_INET, > socket.SOCK_STREAM)' > > now why would it try to open an x server??? :o > -- Because it's not executing it as a Python program. It's trying to execute it as a shell script. If you want to run a script as a Python program, either call the interpreter directly python sockettest.py or include a Shebang line as the first line of the file that tells the computer what interpreter to use #!/usr/bin/env python The file extension itself is meaningless to a Unix shell- it's just a part of the file name. From stef.mientki at gmail.com Wed Sep 8 13:09:12 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 08 Sep 2010 19:09:12 +0200 Subject: are there pros or contras, keeping a connection to a (sqlite) database ? Message-ID: <4C87C338.2070607@gmail.com> hello, I wrap my database in some class, and on creation of the instance, a connection to the database is created, and will stay connected until the program exists, something like this: self.conn = sqlite3.connect ( self.filename ) Now I wonder if there are pros or contras to keep the connection to the database continuously "open" ? thanks, Stef Mientki From ron.eggler at gmail.com Wed Sep 8 13:11:16 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 8 Sep 2010 10:11:16 -0700 (PDT) Subject: listening socket References: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> Message-ID: On Sep 8, 10:06?am, Benjamin Kaplan wrote: > On Wed, Sep 8, 2010 at 12:59 PM, cerr wrote: > > Hi, > > > I'm trying to create a listening socket connection on port 1514. > > I tried to follow the documentation at: > >http://docs.python.org/release/2.5.2/lib/socket-example.html > > and came up with following lines: > > import socket > > > host = '' ? ? ? ? ? ? ? ? # Symbolic name meaning all available > > interfaces > > port = 1514 ? ? ? ? ? ? ? # Arbitrary non-privileged port > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > s.bind((host, port)) > > s.listen(1) > > conn, addr = s.accept() > > print 'Connected by', addr > > while 1: > > ? ?data = conn.recv(1024) > > ? ?if not data: break > > ? ?conn.send(data) > > conn.close() > > but that is not working, i'm getting this: > > import: unable to open X server `' @ error/import.c/ImportImageCommand/ > > 362. > > ./sockettest.py: line 4: host: command not found > > ./sockettest.py: line 5: port: command not found > > ./sockettest.py: line 6: syntax error near unexpected token `(' > > ./sockettest.py: line 6: `s = socket.socket(socket.AF_INET, > > socket.SOCK_STREAM)' > > > now why would it try to open an x server??? :o > > -- > > Because it's not executing it as a Python program. It's trying to > execute it as a shell script. If you want to run a script as a Python > program, either call the interpreter directly > python sockettest.py > > or include a Shebang line as the first line of the file that tells the > computer what interpreter to use > #!/usr/bin/env python > > The file extension itself is meaningless to a Unix shell- it's just a > part of the file name. hoops right... heh, thanks... :$ clearly doing too many things at the same time... From ptmcg at austin.rr.com Wed Sep 8 13:17:37 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 8 Sep 2010 10:17:37 -0700 (PDT) Subject: mutate dictionary or list References: Message-ID: <80fde7c8-2169-473f-aeaf-1971cc3c4dbf@i5g2000yqe.googlegroups.com> On Sep 7, 7:05?am, Baba wrote: > Hi > > I am working on an exercise which requires me to write a funtion that > will check if a given word can be found in a given dictionary (the > hand). > > def is_valid_word(word, hand, word_list): > ? ? """ > ? ? Returns True if word is in the word_list and is entirely > ? ? composed of letters in the hand. Otherwise, returns False. > ? ? Does not mutate hand or word_list.""" > > I don't understand this part: Does not mutate hand or word_list > I would re-read your exercise description. hand is *not* a dictionary, but is most likely a list of individual letters. word_list too is probably *not* a dictionary, but a list of valid words (although this does bear a resemblance to what people in everyday life call a "dictionary"). Where did you get the idea that there was a dictionary in this problem? The "Does not mutate hand or word_list." is a constraint that you are not allowed to update the hand or word_list arguments. For instance, you must not call word_list.sort() in order to search for the given word using some sort of binary search. You must not determine if all the letters in word come from hand by modifying the hand list (like dropping letters from hand as they are found in word). There are ways to copy arguments if you use a destructive process on their contents, so that the original stays unmodified - but that sounds like part of the exercise for you to learn about. -- Paul From invalid at invalid.invalid Wed Sep 8 13:44:01 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Sep 2010 17:44:01 +0000 (UTC) Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> <4c879bd7$0$11113$c3e8da3@news.astraweb.com> <4c87a815$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-08, Steven D'Aprano wrote: > On Wed, 08 Sep 2010 14:44:12 +0000, Grant Edwards wrote: >> >>> If you don't trap them just right, they cause a stack trace, >> >> Not always. That is the effect of not trapping them at all. However, >> you can trap them incorrectly -- which can result in hard-to-track down >> problems. >> >> The main example of this is a "bare except" clause that not only catches >> and handles the "expected" exception but also catches (and >> mishandles/ignores) an unexpected one. > > Ah, fair enough. That would be a false positive error -- catching too > much rather than too little. > > Still, that's no better, or worse, than misinterpreting special error > codes that are returned by functions. No, I didn't mean to imply that was the case. I agree with your conclusion. I find it much easier to screw things up using the "exceptional return value" method than the "exception raise" method. -- Grant Edwards grant.b.edwards Yow! Psychoanalysis?? at I thought this was a nude gmail.com rap session!!! From invalid at invalid.invalid Wed Sep 8 13:47:38 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Sep 2010 17:47:38 +0000 (UTC) Subject: listening socket References: <716f5865-8dd3-4459-b85a-4156a1414052@f20g2000pro.googlegroups.com> Message-ID: On 2010-09-08, Benjamin Kaplan wrote: > On Wed, Sep 8, 2010 at 12:59 PM, cerr wrote: >> but that is not working, i'm getting this: >> import: unable to open X server `' @ error/import.c/ImportImageCommand/ [...] >> now why would it try to open an x server??? :o > > Because it's not executing it as a Python program. It's trying to > execute it as a shell script. What's even more fun is if you do have an X server, and the shell is able to run the import program, and it does open the X server, and so on... [Not that things like that ever happen to _me_] -- Grant Edwards grant.b.edwards Yow! I feel partially at hydrogenated! gmail.com From nagle at animats.com Wed Sep 8 14:39:50 2010 From: nagle at animats.com (John Nagle) Date: Wed, 08 Sep 2010 11:39:50 -0700 Subject: are there pros or contras, keeping a connection to a (sqlite) database ? In-Reply-To: References: Message-ID: <4c87d873$0$1590$742ec2ed@news.sonic.net> On 9/8/2010 10:09 AM, Stef Mientki wrote: > hello, > > I wrap my database in some class, and on creation of the instance, a connection to the database is > created, > and will stay connected until the program exists, something like this: > > self.conn = sqlite3.connect ( self.filename ) > > Now I wonder if there are pros or contras to keep the connection to the database continuously "open" ? > > thanks, > Stef Mientki Open is OK. Open is good, because the database system gets to cache some data. Open with an uncommitted transaction may leave the file locked, preventing access by other processes. So make sure you commit before you go idle. John Nagle From ron.eggler at gmail.com Wed Sep 8 14:43:50 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 8 Sep 2010 11:43:50 -0700 (PDT) Subject: executing script in fork Message-ID: <72682e09-3946-48ef-a726-d692932a0c5c@k1g2000prl.googlegroups.com> Hi There, I want to trigger another script and having it running forked to my mother process. I googled around and came up with following: commandlist=['./GPSsim.pl',proto,'files/gps.txt'] subprocess.Popen(commandlist) print "GPS simulator started" This however doesn't seem disconnect stdout but it still throws me back to the shell. How can I launch it with disconnected stdout and still continue running further code in my mother script? Thanks, Ron From bartc at freeuk.com Wed Sep 8 14:45:26 2010 From: bartc at freeuk.com (BartC) Date: Wed, 8 Sep 2010 19:45:26 +0100 Subject: Speed-up for loops In-Reply-To: <4c878be5$0$11113$c3e8da3@news.astraweb.com> References: <4C7F7640.1010102@perfect-kreim.de><4c83b425$0$28657$c3e8da3@news.astraweb.com><4c85adfe$0$11115$c3e8da3@news.astraweb.com> <4c878be5$0$11113$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c878be5$0$11113$c3e8da3 at news.astraweb.com... > On Tue, 07 Sep 2010 11:00:03 +0100, BartC wrote: > >>> for i in xrange(100000000): >>> a = a + f(i) >> With Python 3 and def f(x): return x+1, unrolling this loop 4x improved >> speed by 15%; 4.00 minutes reduces to 3.30 minutes. > > > I'm afraid that I can't replicate those figures. In my test, unrolling > the loop causes a massive SLOWDOWN of 37%, not a speed up. Here is my > test code: You're absolutely right. I completely forgot about modulating the i index for each duplicated line. > def test_unrolled(n): > a = 0 > for i in range(n//4): > a += f(4*i) > a += f(4*i+1) > a += f(4*i+2) > a += f(4*i+3) > return a Although tidying up your calculations (as already posted) gives code that is neither faster nor slower. I'd hoped that using the following would help, but did nothing in Python 3, and gave only 8-10% speedup in Python 2: for i in xrange(0,n,4): a=a+f(i) a=a+f(i+1) a=a+f(i+2) a=a+f(i+3) (On my other example of setting list elements to 0, this did improve speed by some 10% in Python 3, and 28% in '2'.) So using manual unrolling for an indexed loop is not going to be the right approach (it's also fiddly, and there is the problem of N not being a multiple of 4 or whatever). We're trying to avoid the iteration overhead, yet we're adding it in the code anyway, and as user-level code. But, I still think that internal support for such a thing might be worthwhile, when it can make certain assumptions about the loop range and index type. -- Bartc From tjreedy at udel.edu Wed Sep 8 14:55:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Sep 2010 14:55:30 -0400 Subject: another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) In-Reply-To: <7d2b1ed5-8cdd-4dcd-a8d0-065fda18e895@u5g2000prn.googlegroups.com> References: <4f366784-7ef6-45e8-a6fe-0d785320adb7@p24g2000pra.googlegroups.com> <7d2b1ed5-8cdd-4dcd-a8d0-065fda18e895@u5g2000prn.googlegroups.com> Message-ID: I believe I answered your question a day ago. If it has not reached you yet, try the gmane.org archives. -- Terry Jan Reedy From jonnojohnson at gmail.com Wed Sep 8 14:55:50 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 13:55:50 -0500 Subject: Slice a list of lists? Message-ID: I know that I can index into a list of lists like this: a=[[1,2,3],[4,5,6],[7,8,9]] a[0][2]=3 a[2][0]=7 but when I try to use fancy indexing to select the first item in each list I get: a[0][:]=[1,2,3] a[:][0]=[1,2,3] Why is this and is there a way to select [1,4,7]? From kdombrowski at gmail.com Wed Sep 8 14:58:22 2010 From: kdombrowski at gmail.com (Kenneth Dombrowski) Date: Wed, 8 Sep 2010 14:58:22 -0400 Subject: cPickle segfault with nested dicts in threaded env Message-ID: Hi all, Before creating an issue @ bugs.python.org I wanted to run the following by everyone We are having a difficult time with what looks like a cPickle issue when given a data structure containing >15 nested dictionaries, but only when threading is involved Environment is FreeBSD 8, Python 2.5.5 The following diff contains an addition for /usr/ports/lang/python25/work/Python-2.5.5/Lib/test/test_cpickle.py which reproduces the issue kenneth at kenneth0 Python-2.5.5 $ cat /tmp/test_cpickle.nested_dicts_in_threaded_env.diff 1a2 > import copy 2a4 > import threading 93a96,105 > def test_nested_dicts_in_threaded_env(self): > # segfaults on python2.5.5/FreeBSD 8.0-RELEASE-p2 > def threadloop(): > x = {} > for i in range(16): > x = {i:copy.copy(x)} > cPickle.dumps(x, 2) > t = threading.Thread(target=threadloop) > t.start() > Any thoughts will be appreciated, thanks for looking, Kenneth From usenot at geekmail.INVALID Wed Sep 8 15:08:11 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 8 Sep 2010 15:08:11 -0400 Subject: Slice a list of lists? References: Message-ID: <20100908150811.12e3ec3a@geekmail.INVALID> On Wed, 8 Sep 2010 13:55:50 -0500 Jonno wrote: > I know that I can index into a list of lists like this: > a=[[1,2,3],[4,5,6],[7,8,9]] > a[0][2]=3 > a[2][0]=7 > > but when I try to use fancy indexing to select the first item in each > list I get: Let me write out in words what you're doing, and it should become clear: > a[0][:]=[1,2,3] Here you're making a list of all elements of the first element of a. > a[:][0]=[1,2,3] > And here you're selecting the first element of all elements of a. Huh. Not quite as clear as I hoped. But ponder on this for a few moments. It'll dawn on you eventually. > Why is this and is there a way to select [1,4,7]? zip(*a)[0] (or rather list(zip(*a)[0]), if you definitely need a list and not a tuple) /W -- INVALID? DE! From benjamin.kaplan at case.edu Wed Sep 8 15:11:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 8 Sep 2010 15:11:51 -0400 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: > I know that I can index into a list of lists like this: > a=[[1,2,3],[4,5,6],[7,8,9]] > a[0][2]=3 > a[2][0]=7 > > but when I try to use fancy indexing to select the first item in each > list I get: > a[0][:]=[1,2,3] > a[:][0]=[1,2,3] > > Why is this and is there a way to select [1,4,7]? > -- It's not fancy indexing. It's called taking a slice of the existing list. Look at it this way a[0] means take the first element of a. The first element of a is [1,2,3] a[0][:] means take all the elements in that first element of a. All the elements of [1,2,3] are [1,2,3]. a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. a[:][0] means take the first element of all the elements of a. The first element of a[:] is [1,2,3]. There is no simple way to get [1,4,7] because it is just a list of lists and not an actual matrix. You have to extract the elements yourself. col = [] for row in a: col.append(row[0]) You can do this in one line using a list comprehension: [ row[0] for row in a ] > http://mail.python.org/mailman/listinfo/python-list > From usenot at geekmail.INVALID Wed Sep 8 15:12:30 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 8 Sep 2010 15:12:30 -0400 Subject: Slice a list of lists? References: <20100908150811.12e3ec3a@geekmail.INVALID> Message-ID: <20100908151230.37687067@geekmail.INVALID> Let me rephrase what I wrote a bit. On Wed, 8 Sep 2010 15:08:11 -0400 Andreas Waldenburger wrote: > > a[0][:]=[1,2,3] > Here you're making a list of all elements of the first element of a. > That is, you're making a copy of the first element of a. > > a[:][0]=[1,2,3] > > > And here you're selecting the first element of all elements of a. > That is, you're taking the first element of a copy of a. I hope this is a little less confusing. /W -- INVALID? DE! From usenot at geekmail.INVALID Wed Sep 8 15:17:08 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 8 Sep 2010 15:17:08 -0400 Subject: Slice a list of lists? References: Message-ID: <20100908151708.3dc68090@geekmail.INVALID> On Wed, 8 Sep 2010 15:11:51 -0400 Benjamin Kaplan wrote: > There is no simple way to get [1,4,7] because it is just a list of > lists and not an actual matrix. You have to extract the elements > yourself. > > col = [] > for row in a: > col.append(row[0]) > > > You can do this in one line using a list comprehension: > [ row[0] for row in a ] I would suggest this (esp. the list comprehension version) over my suggestion of zip(). WAAAYYYY more readable. Apparently I'm getting rusty. /W -- INVALID? DE! From python at mrabarnett.plus.com Wed Sep 8 15:30:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Sep 2010 20:30:34 +0100 Subject: [Python-ideas] with statement syntax forces ugly line breaks? In-Reply-To: References: <20100908175029.6617ae3b@dino> Message-ID: <4C87E45A.1080207@mrabarnett.plus.com> On 08/09/2010 19:07, Georg Brandl wrote: > Thus spake the Lord: Thou shalt indent with four spaces. No more, no > less. Four shall be the number of spaces thou shalt indent, and the > number of thy indenting shall be four. Eight shalt thou not indent, > nor either indent thou two, excepting that thou then proceed to four. > Tabs are right out. > FYI, that should be "thine indenting". "My/thy" before a consonant, "mine/thine" before a vowel. Compare with "a/an", which we still do. From tjreedy at udel.edu Wed Sep 8 15:45:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Sep 2010 15:45:46 -0400 Subject: Automatic delegation in Python 3 In-Reply-To: <4c87966d$0$11113$c3e8da3@news.astraweb.com> References: <4c87966d$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 9/8/2010 9:58 AM, Steven D'Aprano wrote: > Delegation in old-style classes worked fine: > > # Python 2.6 >>>> class Delegate: > ... def __init__(self, x): > ... self.__dict__['x'] = x > ... def __getattr__(self, name): > ... return getattr(self.x, name) > ... def __setattr__(self, name, value): > ... setattr(self.x, name, value) > ... >>>> obj = Delegate({}) >>>> obj[1] = None Since you are not setting a attribute, I was initially surprised that this worked. Then I remembered that this is executed for old-style classes as obj.__getattr__('__setitem__')(1,None) and that __setattr__ above is not involved. This is possible because old-style user classes were a world apart form builtin types. Once user-classes were integrated into the builting class/type hierarchy, they had to follow the same rules as the latter. One problem is that classes are also instances of their metaclass. This is somewhat explained in 3.3.8 'Special method lookup' (which I have read at least 3 times before understanding). As you discovered, this is not a complete win. The bottom line of 3.3.8: "Bypassing the __getattribute__() machinery in this fashion provides significant scope for speed optimisations within the interpreter, at the cost of some flexibility in the handling of special methods (the special method must be set on the class object itself in order to be consistently invoked by the interpreter)." You are seeing the cost. > Unfortunately, I need to use delegation, not inheritance, and I need to > use a new-style class, since I will be using Python 3. How can I do > automatic delegation in Python 3? Is my only hope to give up on the > elegance of automatic delegation, and code all the special methods as > manual delegation? Based on the above, it seems so. But I would search a bit more for delegation and proxy object and python 3 to see what others have done. -- Terry Jan Reedy From emile at fenx.com Wed Sep 8 15:51:41 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 08 Sep 2010 12:51:41 -0700 Subject: Slice a list of lists? In-Reply-To: <20100908151708.3dc68090@geekmail.INVALID> References: <20100908151708.3dc68090@geekmail.INVALID> Message-ID: On 9/8/2010 12:17 PM Andreas Waldenburger said... > On Wed, 8 Sep 2010 15:11:51 -0400 Benjamin Kaplan > wrote: > >> There is no simple way to get [1,4,7] because it is just a list of >> lists and not an actual matrix. You have to extract the elements >> yourself. >> >> col = [] >> for row in a: >> col.append(row[0]) >> >> >> You can do this in one line using a list comprehension: >> [ row[0] for row in a ] > > I would suggest this (esp. the list comprehension version) over my > suggestion of zip(). WAAAYYYY more readable. Apparently I'm getting > rusty. > zip is very handy for inverting rows and cols (x's and y's, whatever) >>> a = [(1,2),(3,4),(5,6),(7,8),(9,10)] >>> zip(*a) [(1, 3, 5, 7, 9), (2, 4, 6, 8, 10)] So, I like zip if you're dealing with a in a matrix-ish manner, and list comps for picking selected items out of a list. Emile From thomas at jollybox.de Wed Sep 8 15:55:56 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 8 Sep 2010 21:55:56 +0200 Subject: cPickle segfault with nested dicts in threaded env In-Reply-To: References: Message-ID: <201009082155.56851.thomas@jollybox.de> On Wednesday 08 September 2010, it occurred to Kenneth Dombrowski to exclaim: > Environment is FreeBSD 8, Python 2.5.5 Which architecture? Also, Python 2.5 is frightfully old. There's not really any problem with still using it, but nobody's maintaining it upstream, so don't bother reporting a bug with Python 2.5, as you'll just be told to test a newer version. Check if this still occurs in Python 2.7 and/or Python 3.1, and, if it does, then please do report the bug. Chances are this was actually fixed a couple of years ago. See: http://bugs.python.org/issue3640 (and http://bugs.python.org/issue3338) From pavlovevidence at gmail.com Wed Sep 8 16:03:13 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 8 Sep 2010 13:03:13 -0700 (PDT) Subject: cPickle segfault with nested dicts in threaded env References: Message-ID: <4ce8d0a7-6784-4936-ba82-2ef2f393e8cc@q21g2000prm.googlegroups.com> On Sep 8, 11:58?am, Kenneth Dombrowski wrote: > Hi all, > > Before creating an issue @ bugs.python.org I wanted to run the > following by everyone > > We are having a difficult time with what looks like a cPickle issue > when given a data structure containing >15 nested dictionaries, but > only when threading is involved > > Environment is FreeBSD 8, Python 2.5.5 Since Python 2.7 is released, Python 2.5 is no longer accepting bug fixes, only security fixes. So be aware. > The following diff contains an addition for > /usr/ports/lang/python25/work/Python-2.5.5/Lib/test/test_cpickle.py > which reproduces the issue > > kenneth at kenneth0 Python-2.5.5 $ cat > /tmp/test_cpickle.nested_dicts_in_threaded_env.diff > 1a2 > > > import copy > 2a4 > > import threading > 93a96,105 > > ? ? def test_nested_dicts_in_threaded_env(self): > > ? ? ? ? # segfaults on python2.5.5/FreeBSD 8.0-RELEASE-p2 > > ? ? ? ? def threadloop(): > > ? ? ? ? ? ? x = {} > > ? ? ? ? ? ? for i in range(16): > > ? ? ? ? ? ? ? ? x = {i:copy.copy(x)} > > ? ? ? ? ? ? cPickle.dumps(x, 2) > > ? ? ? ? t = threading.Thread(target=threadloop) > > ? ? ? ? t.start() > > Any thoughts will be appreciated, thanks for looking, Bug. Python should never segfault (unless you're doing bad things with ctypes). Even if threading isn't supported in this case, it should fail with an exception or have undefined behavior, not segfault. I would check to see if the same problem exists on 2.7, and file a bug report if so. If they fix it in 2.7 maybe you could apply the same fix to your own 2.5. Carl Banks From jonnojohnson at gmail.com Wed Sep 8 16:06:15 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 15:06:15 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan wrote: > On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >> I know that I can index into a list of lists like this: >> a=[[1,2,3],[4,5,6],[7,8,9]] >> a[0][2]=3 >> a[2][0]=7 >> >> but when I try to use fancy indexing to select the first item in each >> list I get: >> a[0][:]=[1,2,3] >> a[:][0]=[1,2,3] >> >> Why is this and is there a way to select [1,4,7]? >> -- > > It's not fancy indexing. It's called taking a slice of the existing > list. Look at it this way > a[0] means take the first element of a. The first element of a is [1,2,3] > a[0][:] means take all the elements in that first element of a. All > the elements of [1,2,3] are [1,2,3]. > > a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. > a[:][0] means take the first element of all the elements of a. The > first element of a[:] is [1,2,3]. > > There is no simple way to get [1,4,7] because it is just a list of > lists and not an actual matrix. You have to extract the elements > yourself. > > col = [] > for row in a: > ? ?col.append(row[0]) > > > You can do this in one line using a list comprehension: > [ row[0] for row in a ] > Thanks! (to Andreas too). Totally makes sense now. From tjreedy at udel.edu Wed Sep 8 16:17:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Sep 2010 16:17:02 -0400 Subject: what should __iter__ return? In-Reply-To: <8eo7tiF10cU1@mid.individual.net> References: <8eo7tiF10cU1@mid.individual.net> Message-ID: On 9/7/2010 9:40 PM, Gregory Ewing wrote: > Thomas Jollans wrote: > >> Hmm. Modifying an object while iterating over it isn't a great idea, >> ever: > > I wouldn't say never. How about "Modifying a collection while iterating over it without understanding the dangers is a bad idea." " Algorithms that calculate some kind of > transitive closure can be expressed rather neatly by appending > items to a list being iterated over. Which is one reason list modification while iterating is not prohibited. Deleting items while forward iterating and adding items while backward iterating may miss items unexpectedly. Adding items ahead of forward iteration and deleting items behind backward iterating are ok. The most common example of the latter is successively popping item off a stack. -- Terry Jan Reedy From jonnojohnson at gmail.com Wed Sep 8 16:18:56 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 15:18:56 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 3:06 PM, Jonno wrote: > On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan > wrote: >> On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >>> I know that I can index into a list of lists like this: >>> a=[[1,2,3],[4,5,6],[7,8,9]] >>> a[0][2]=3 >>> a[2][0]=7 >>> >>> but when I try to use fancy indexing to select the first item in each >>> list I get: >>> a[0][:]=[1,2,3] >>> a[:][0]=[1,2,3] >>> >>> Why is this and is there a way to select [1,4,7]? >>> -- >> >> It's not fancy indexing. It's called taking a slice of the existing >> list. Look at it this way >> a[0] means take the first element of a. The first element of a is [1,2,3] >> a[0][:] means take all the elements in that first element of a. All >> the elements of [1,2,3] are [1,2,3]. >> >> a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. >> a[:][0] means take the first element of all the elements of a. The >> first element of a[:] is [1,2,3]. >> >> There is no simple way to get [1,4,7] because it is just a list of >> lists and not an actual matrix. You have to extract the elements >> yourself. >> >> col = [] >> for row in a: >> ? ?col.append(row[0]) >> >> >> You can do this in one line using a list comprehension: >> [ row[0] for row in a ] >> > Thanks! (to Andreas too). Totally makes sense now. > Now if I want to select the first item in every 2nd item of list a (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of indices to use in a more complex for loop? From jonnojohnson at gmail.com Wed Sep 8 16:23:35 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 15:23:35 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: > On Wed, Sep 8, 2010 at 3:06 PM, Jonno wrote: >> On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan >> wrote: >>> On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >>>> I know that I can index into a list of lists like this: >>>> a=[[1,2,3],[4,5,6],[7,8,9]] >>>> a[0][2]=3 >>>> a[2][0]=7 >>>> >>>> but when I try to use fancy indexing to select the first item in each >>>> list I get: >>>> a[0][:]=[1,2,3] >>>> a[:][0]=[1,2,3] >>>> >>>> Why is this and is there a way to select [1,4,7]? >>>> -- >>> >>> It's not fancy indexing. It's called taking a slice of the existing >>> list. Look at it this way >>> a[0] means take the first element of a. The first element of a is [1,2,3] >>> a[0][:] means take all the elements in that first element of a. All >>> the elements of [1,2,3] are [1,2,3]. >>> >>> a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. >>> a[:][0] means take the first element of all the elements of a. The >>> first element of a[:] is [1,2,3]. >>> >>> There is no simple way to get [1,4,7] because it is just a list of >>> lists and not an actual matrix. You have to extract the elements >>> yourself. >>> >>> col = [] >>> for row in a: >>> ? ?col.append(row[0]) >>> >>> >>> You can do this in one line using a list comprehension: >>> [ row[0] for row in a ] >>> >> Thanks! (to Andreas too). Totally makes sense now. >> > > Now if I want to select the first item in every 2nd item of list a > (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of > indices to use in a more complex for loop? > Seems like the simplest way would be: [row[0] for row in a][::2] From tjreedy at udel.edu Wed Sep 8 16:27:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Sep 2010 16:27:02 -0400 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On 9/8/2010 2:55 PM, Jonno wrote: > I know that I can index into a list of lists like this: > a=[[1,2,3],[4,5,6],[7,8,9]] > a[0][2]=3 > a[2][0]=7 > > but when I try to use fancy indexing to select the first item in each > list I get: > a[0][:]=[1,2,3] > a[:][0]=[1,2,3] > > Why is this and is there a way to select [1,4,7]? You are trying to look at a list of lists as an array and have discovered where the asymmetry of the former makes the two non-equivalent. To slice multi-dimensional arrays any which way, you need an appropriate package, such as numpy. -- Terry Jan Reedy From benjamin.kaplan at case.edu Wed Sep 8 16:28:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 8 Sep 2010 16:28:51 -0400 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Wed, Sep 8, 2010 at 4:23 PM, Jonno wrote: > On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: >> On Wed, Sep 8, 2010 at 3:06 PM, Jonno wrote: >>> On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan >>> wrote: >>>> On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >>>>> I know that I can index into a list of lists like this: >>>>> a=[[1,2,3],[4,5,6],[7,8,9]] >>>>> a[0][2]=3 >>>>> a[2][0]=7 >>>>> >>>>> but when I try to use fancy indexing to select the first item in each >>>>> list I get: >>>>> a[0][:]=[1,2,3] >>>>> a[:][0]=[1,2,3] >>>>> >>>>> Why is this and is there a way to select [1,4,7]? >>>>> -- >>>> >>>> It's not fancy indexing. It's called taking a slice of the existing >>>> list. Look at it this way >>>> a[0] means take the first element of a. The first element of a is [1,2,3] >>>> a[0][:] means take all the elements in that first element of a. All >>>> the elements of [1,2,3] are [1,2,3]. >>>> >>>> a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. >>>> a[:][0] means take the first element of all the elements of a. The >>>> first element of a[:] is [1,2,3]. >>>> >>>> There is no simple way to get [1,4,7] because it is just a list of >>>> lists and not an actual matrix. You have to extract the elements >>>> yourself. >>>> >>>> col = [] >>>> for row in a: >>>> ? ?col.append(row[0]) >>>> >>>> >>>> You can do this in one line using a list comprehension: >>>> [ row[0] for row in a ] >>>> >>> Thanks! (to Andreas too). Totally makes sense now. >>> >> >> Now if I want to select the first item in every 2nd item of list a >> (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of >> indices to use in a more complex for loop? >> > Seems like the simplest way would be: > [row[0] for row in a][::2] Yes. You could either do that, or do [row[0] for row in a[::2]]. It doesn't make that much of a difference, unless memory is really tight (doing the ::2 first means your list is smaller to begin with) > -- > http://mail.python.org/mailman/listinfo/python-list > From usenot at geekmail.INVALID Wed Sep 8 16:44:52 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 8 Sep 2010 16:44:52 -0400 Subject: Slice a list of lists? References: Message-ID: <20100908164452.688dd8fd@geekmail.INVALID> On Wed, 8 Sep 2010 15:23:35 -0500 Jonno wrote: > On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: > [snip] > > Now if I want to select the first item in every 2nd item of list a > > (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of > > indices to use in a more complex for loop? > > > Seems like the simplest way would be: > [row[0] for row in a][::2] What you're doing here is selecting every second item of the list of first items of the items in a, not the first items of every second item in a (head spinning yet?). If I'm not completely mindbent right now, these are logically equivalent, but not computationally. Compare [row[0] for row in a][::2] # (your Python code) with [row[0] for row in a[::2]] # (as per your description) The first one is more work for your computer, because it'll pick out the first elements of *all* of the items in a, whereas the second only picks out the first elements of every second item in a (which is only half the amount of "picks" compared to the former). I just thought I'd mention it. Because it might make a difference in one of your programs some day. And because I'm a pedant ;). /W -- INVALID? DE! From thomas at jollybox.de Wed Sep 8 16:51:50 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 8 Sep 2010 22:51:50 +0200 Subject: Automatic delegation in Python 3 In-Reply-To: <4c87966d$0$11113$c3e8da3@news.astraweb.com> References: <4c87966d$0$11113$c3e8da3@news.astraweb.com> Message-ID: <201009082251.50668.thomas@jollybox.de> On Wednesday 08 September 2010, it occurred to Steven D'Aprano to exclaim: > What's going on here? I *think* this has something to do with special > double-underscore methods being looked up on the class, not the instance, > for new-style classes, but I'm not entirely sure. Yes, special methods are looked up on the type. So you have to make sure the type has the methods. > > Unfortunately, I need to use delegation, not inheritance, and I need to > use a new-style class, since I will be using Python 3. How can I do > automatic delegation in Python 3? Is my only hope to give up on the > elegance of automatic delegation, and code all the special methods as > manual delegation? Well, yes, you have to implement all the required special methods in the Delegate class. But there's no reason you have to do it manually. (I've never actually used this in the wild, but it looks like it works) >>> def makeDelegate(o): ... T = type(o) ... class Delegate: ... def __getattr__(self, name): ... return getattr(o, name) ... def __setattr__(self, name, value): ... setattr(self, name, value) ... def makewrapper(method): ... def wrapper(self, *args, **kwargs): ... return method(o, *args, **kwargs) ... return wrapper ... for methodname in dir(T): ... method = getattr(T, methodname) ... if methodname not in ('__getattr__', '__setattr__', ... '__init__', '__new__', '__class__'): ... try: ... setattr(Delegate, methodname, makewrapper(method)) ... except: pass ... return Delegate() ... >>> D = makeDelegate({'a': 1}) >>> D {'a': 1} >>> D['a'] 1 >>> D['a'] = 2 >>> D {'a': 2} >>> D.get('b') >>> D['b'] = True >>> D.get('b') True >>> From jonnojohnson at gmail.com Wed Sep 8 16:54:44 2010 From: jonnojohnson at gmail.com (Jonno) Date: Wed, 8 Sep 2010 15:54:44 -0500 Subject: Slice a list of lists? In-Reply-To: <20100908164452.688dd8fd@geekmail.INVALID> References: <20100908164452.688dd8fd@geekmail.INVALID> Message-ID: On Wed, Sep 8, 2010 at 3:44 PM, Andreas Waldenburger wrote: > On Wed, 8 Sep 2010 15:23:35 -0500 Jonno wrote: > >> On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: >> [snip] >> > Now if I want to select the first item in every 2nd item of list a >> > (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of >> > indices to use in a more complex for loop? >> > >> Seems like the simplest way would be: >> [row[0] for row in a][::2] > > What you're doing here is selecting every second item of the list of > first items of the items in a, not the first items of every second item > in a (head spinning yet?). > > If I'm not completely mindbent right now, these are logically > equivalent, but not computationally. > > Compare > ? ?[row[0] for row in a][::2] ?# (your Python code) > with > ? ?[row[0] for row in a[::2]] ?# (as per your description) > > The first one is more work for your computer, because it'll pick out > the first elements of *all* of the items in a, whereas the second only > picks out the first elements of every second item in a (which is only > half the amount of "picks" compared to the former). > > I just thought I'd mention it. Because it might make a difference in > one of your programs some day. And because I'm a pedant ;). Thanks again. It is nice to know how to do things properly even though in my case it probably won't make much difference. Terry, I would have used numpy arrays (I actually use them later in the code) except the lists in my list aren't all of the same length. From raoulbia at gmail.com Wed Sep 8 17:08:00 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 8 Sep 2010 14:08:00 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> <7xmxrsif45.fsf@ruckus.brouhaha.com> Message-ID: <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> On 8 sep, 14:39, Paul Rubin wrote: > Baba writes: > > But where do you draw the line? Can we not just let people ask > > questions regardless? And let those answer who want to and those who > > don't just ignore the question? That seems so much easier to me. > > The first few times, it's easy to ignore the questions. ?After a few > more times, it becomes easier to ignore the person asking the questions, > and not even look at the questions. > > The answer to many of your questions also is not "research it online", > but rather, "figure it out with your own creativity". ?That's what being > a programmer is about--figuring out solutions that don't already exist > elsewhere. Hi Paul If i look where i was 4 weeks ago and the progress i made in learning Python i am quite delighted. This forum has helped me and i appreciate it. I don't think i will ever tell a beginner to "do me a favour" and to look things up by himself nor will i use the RTFM line (refering to Bruno's post), i'd just be nice and helpful as everyone here is. Didn't realise ego's were that big but so is mine i suppose... kind regards Baba From russandheather at gmail.com Wed Sep 8 17:18:52 2010 From: russandheather at gmail.com (Russell Warren) Date: Wed, 8 Sep 2010 14:18:52 -0700 (PDT) Subject: Confused about nested scopes and when names get added to namespaces Message-ID: I'm having trouble understanding when variables are added to namespaces. I thought I understood it, but my nested function examples below have me very confused. In each test function below I have an x variable (so "x" is in the namespace of each test function). I also have a nested function in each (innerFunc) that has different flavors of trying to access or assign a variable named "x". --- def test1(): print "running test1..." x = 1 def innerFunc(): print "inner locals():", print "%s" % locals() # x not present (yet) x = 2 print x innerFunc() print "x left as %s\n" % x def test2(): print "running test2..." x = 1 def innerFunc(): print "inner locals():", print "%s" % locals() # x not present innerFunc() print "x left as %s\n" % x def test3(): print "running test3..." x = 1 def innerFunc(): print "inner locals():", print "%s" % locals() # how is x in locals in this case?? print x innerFunc() print "x left as %s\n" % x test1() test2() test3() --- With the nested scope rules, I thought that *at the time of* trying to access an object with a given name, if the name was not available in the namespace of the local function python would then check the namespace of the parent function. My tests above don't seem to match this. Specifically my "at the time of" assumption. What is happening in test3? How is it that "x" ends up in the local namespace before it is ever referenced? It seems that, prior to execution time, the python compiler is "magically" determining that I'm referencing a particular name before assignment and shoving it into the local namespace so it can be used. I did not think the compiler went into function bodies, aside from basic syntax checking. Further confusing me (or confirming the compiler behavior) is adding a 4th test with only one added line... def test4(): print "running test4..." x = 1 def innerFunc(): print "inner locals():", print "%s" % locals() # how is x in locals in this case?? print x x = 2 #ONLY ADDED LINE TO TEST3 innerFunc() print "x left as %s\n" % x In this case I get "UnboundLocalError: local variable 'x' referenced before assignment". I think this means that the compiler (prior to runtime) inspected the code, determined I will do an assignment, decided _not_ to bring the parent's x into the local namespace, and as a result caused the unbound name problem at runtime. It seems that the parent's "x" is brought directly into the local namespace (when appropriate), rather than the namespace lookup just moving up the hierarchy when not found. This is confusing to me and is making me question my understanding of namespace lookups. Are nested scopes a special case where the lookup is handled differently? What if I want to change the value of the parent's "x"? test4 implies that I can't. Have I got this right? Can someone please clarify what is going on? From russandheather at gmail.com Wed Sep 8 17:19:45 2010 From: russandheather at gmail.com (Russell Warren) Date: Wed, 8 Sep 2010 14:19:45 -0700 (PDT) Subject: Confused about nested scopes and when names get added to namespaces References: Message-ID: <3d88fe15-0044-4817-8a51-918b97b2cb39@11g2000yqq.googlegroups.com> My tests were run in python 2.6.5. From robert.kern at gmail.com Wed Sep 8 17:26:15 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 08 Sep 2010 16:26:15 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On 9/8/10 3:27 PM, Terry Reedy wrote: > On 9/8/2010 2:55 PM, Jonno wrote: >> I know that I can index into a list of lists like this: >> a=[[1,2,3],[4,5,6],[7,8,9]] >> a[0][2]=3 >> a[2][0]=7 >> >> but when I try to use fancy indexing to select the first item in each >> list I get: >> a[0][:]=[1,2,3] >> a[:][0]=[1,2,3] >> >> Why is this and is there a way to select [1,4,7]? > > You are trying to look at a list of lists as an array and have discovered where > the asymmetry of the former makes the two non-equivalent. To slice > multi-dimensional arrays any which way, you need an appropriate package, such as > numpy. A motivating example: [~] |1> import numpy [~] |2> a = numpy.array([[1,2,3],[4,5,6],[7,8,9]]) [~] |3> a array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) [~] |4> a[0,2] 3 [~] |5> a[2,0] 7 [~] |6> a[0,:] array([1, 2, 3]) [~] |7> a[:,0] array([1, 4, 7]) -- 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 Wed Sep 8 17:59:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 21:59:56 GMT Subject: what should __iter__ return? References: <8eo7tiF10cU1@mid.individual.net> Message-ID: <4c88075c$0$11113$c3e8da3@news.astraweb.com> On Wed, 08 Sep 2010 16:17:02 -0400, Terry Reedy wrote: > On 9/7/2010 9:40 PM, Gregory Ewing wrote: >> Thomas Jollans wrote: >> >>> Hmm. Modifying an object while iterating over it isn't a great idea, >>> ever: >> >> I wouldn't say never. > > How about "Modifying a collection while iterating over it without > understanding the dangers is a bad idea." "... unless you're being paid by the hour for debugging your code." *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Sep 8 18:02:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Sep 2010 22:02:07 GMT Subject: Automatic delegation in Python 3 References: <4c87966d$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c8807df$0$11113$c3e8da3@news.astraweb.com> On Wed, 08 Sep 2010 15:45:46 -0400, Terry Reedy wrote: [...] >> Unfortunately, I need to use delegation, not inheritance, and I need to >> use a new-style class, since I will be using Python 3. How can I do >> automatic delegation in Python 3? Is my only hope to give up on the >> elegance of automatic delegation, and code all the special methods as >> manual delegation? > > Based on the above, it seems so. But I would search a bit more for > delegation and proxy object and python 3 to see what others have done. That's what I was afraid of. Oh well. Thanks to those who answered. -- Steven From cmpython at gmail.com Wed Sep 8 18:29:56 2010 From: cmpython at gmail.com (CM) Date: Wed, 8 Sep 2010 15:29:56 -0700 (PDT) Subject: are there pros or contras, keeping a connection to a (sqlite) database ? References: Message-ID: On Sep 8, 1:09?pm, Stef Mientki wrote: > ?hello, > > I wrap my database in some class, and on creation of the instance, a connection to the database is > created, > and will stay connected until the program exists, something like this: > > ? ? self.conn = sqlite3.connect ( self.filename ) > > Now I wonder if there are pros or contras to keep the connection to the database continuously ?"open" ? > > thanks, > Stef Mientki I do the same thing--good to hear from John that keeping it open is OK. But another question that this provokes, at least for me is: what happens when you call .connect() on the same database multiple times from within different parts of the same app? Is that bad? And is it that there now multiple connections to the database, or one connection that has multiple names in different namespaces within the app? I'm not even sure what a "connection" really is; I assumed it was nothing more than a rule that says to write to the database with the file named in the parentheses. Further elaboration from the community would be helpful. Thanks, Che From barshirtcliff at gmail.com Wed Sep 8 18:32:24 2010 From: barshirtcliff at gmail.com (Bar Shirtcliff) Date: Wed, 8 Sep 2010 16:32:24 -0600 Subject: accessing a text file In-Reply-To: <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> <7xmxrsif45.fsf@ruckus.brouhaha.com> <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> Message-ID: <19592.3832.281882.702641@bar-macbook.local> | Hi Paul | | If i look where i was 4 weeks ago and the progress i made in learning | Python i am quite delighted. This forum has helped me and i appreciate | it. I don't think i will ever tell a beginner to "do me a favour" and | to look things up by himself nor will i use the RTFM line (refering to | Bruno's post), i'd just be nice and helpful as everyone here is. | Didn't realise ego's were that big but so is mine i suppose... | HEREow can you be learning so much python if you're constantly expressing your personal tastes and generally posturing on the Python forum? I know how words can capture one into a realm of pretended meaning and significance. The nice thing about programming, as opposed to the humanities, is that it's about actually doing things, or rather, actually building things that do things for you. Let's get to it! Best, Bar -- ---------------------------------------------------------------------- "All men are born mad. Some remain so." --Samuel Beckett From aahz at pythoncraft.com Wed Sep 8 18:45:29 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Sep 2010 15:45:29 -0700 Subject: Confused about nested scopes and when names get added to namespaces References: Message-ID: In article , Russell Warren wrote: > >def test4(): > print "running test4..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # how is x in locals in this case?? > print x > x = 2 #ONLY ADDED LINE TO TEST3 > innerFunc() > print "x left as %s\n" % x > >In this case I get "UnboundLocalError: local variable 'x' referenced >before assignment". I think this means that the compiler (prior to >runtime) inspected the code, determined I will do an assignment, >decided _not_ to bring the parent's x into the local namespace, and as >a result caused the unbound name problem at runtime. Bingo! >It seems that the parent's "x" is brought directly into the local >namespace (when appropriate), rather than the namespace lookup just >moving up the hierarchy when not found. This is confusing to me and >is making me question my understanding of namespace lookups. Are >nested scopes a special case where the lookup is handled differently? > >What if I want to change the value of the parent's "x"? test4 implies >that I can't. You need Python 3.x and the "nonlocal" keyword. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From emile at fenx.com Wed Sep 8 18:47:38 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 08 Sep 2010 15:47:38 -0700 Subject: Confused about nested scopes and when names get added to namespaces In-Reply-To: References: Message-ID: On 9/8/2010 2:18 PM Russell Warren said... > I'm having trouble understanding when variables are added to > namespaces. I thought I understood it, but my nested function > examples below have me very confused. Take a look at PEP 227 where nested scopes are introduced. http://www.python.org/dev/peps/pep-0227/ From the PEP: If a name is used within a code block, but it is not bound there and is not declared global, the use is treated as a reference to the nearest enclosing function region. > > In each test function below I have an x variable (so "x" is in the > namespace of each test function). I also have a nested function in > each (innerFunc) that has different flavors of trying to access or > assign a variable named "x". > > --- > def test1(): > print "running test1..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # x not present (yet) > x = 2 > print x > innerFunc() > print "x left as %s\n" % x > > def test2(): > print "running test2..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # x not present > innerFunc() > print "x left as %s\n" % x > > def test3(): > print "running test3..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # how is x in locals in this case?? > print x > innerFunc() > print "x left as %s\n" % x > > test1() > test2() > test3() > > --- > > With the nested scope rules, I thought that *at the time of* trying to > access an object with a given name, if the name was not available in > the namespace of the local function python would then check the > namespace of the parent function. My tests above don't seem to match > this. Specifically my "at the time of" assumption. > > What is happening in test3? How is it that "x" ends up in the local > namespace before it is ever referenced? It seems that, prior to > execution time, the python compiler is "magically" determining that > I'm referencing a particular name before assignment and shoving it > into the local namespace so it can be used. I did not think the > compiler went into function bodies, aside from basic syntax checking. > > Further confusing me (or confirming the compiler behavior) is adding a > 4th test with only one added line... > > def test4(): > print "running test4..." > x = 1 > def innerFunc(): > print "inner locals():", > print "%s" % locals() # how is x in locals in this case?? > print x > x = 2 #ONLY ADDED LINE TO TEST3 > innerFunc() > print "x left as %s\n" % x > > In this case I get "UnboundLocalError: local variable 'x' referenced > before assignment". I think this means that the compiler (prior to > runtime) inspected the code, determined I will do an assignment, x is local by virtue of being assigned to within the function. > decided _not_ to bring the parent's x into the local namespace, and as > a result caused the unbound name problem at runtime. > > It seems that the parent's "x" is brought directly into the local > namespace (when appropriate), rather than the namespace lookup just > moving up the hierarchy when not found. This is confusing to me and > is making me question my understanding of namespace lookups. Are > nested scopes a special case where the lookup is handled differently? > > What if I want to change the value of the parent's "x"? test4 implies > that I can't. You can't ever unless x is mutable. > > Have I got this right? Can someone please clarify what is going on? > I don't have time to go into further details at the moment. HTH, Emile From no.email at nospam.invalid Wed Sep 8 18:52:47 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 15:52:47 -0700 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> <4c879bd7$0$11113$c3e8da3@news.astraweb.com> <4c87a815$0$11113$c3e8da3@news.astraweb.com> Message-ID: <7xaanr3l1c.fsf@ruckus.brouhaha.com> Grant Edwards writes: > I find it much easier to screw things up using the > "exceptional return value" method than the "exception raise" method. That may be partly due to Python's not-so-good facilities for implementing the "exceptional return value" method. To be fair, plenty of other languages have similar shortcomings and it's mostly in more recent languages that the problem has really been recognized, and addressed with features like option types. From no.email at nospam.invalid Wed Sep 8 18:55:31 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 15:55:31 -0700 Subject: cPickle segfault with nested dicts in threaded env References: <4ce8d0a7-6784-4936-ba82-2ef2f393e8cc@q21g2000prm.googlegroups.com> Message-ID: <7x62yf3kws.fsf@ruckus.brouhaha.com> Carl Banks writes: > Since Python 2.7 is released, Python 2.5 is no longer accepting bug > fixes, only security fixes. So be aware. Segfaults should be treated as security holes unless there's convincing reasons that no exploit is possible. So the bug should be reported against 2.5 as well as later versions. From barshirtcliff at gmail.com Wed Sep 8 18:56:11 2010 From: barshirtcliff at gmail.com (Bar Shirtcliff) Date: Wed, 8 Sep 2010 16:56:11 -0600 Subject: accessing a text file In-Reply-To: <19592.3832.281882.702641@bar-macbook.local> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> <7xmxrsif45.fsf@ruckus.brouhaha.com> <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> <19592.3832.281882.702641@bar-macbook.local> Message-ID: <19592.5259.240514.451281@bar-macbook.local> | HEREow can you be learning so much python if you're constantly expressing typo there. I'm not sure how that happens, sometimes, but it's an untimely abbrev-expansion, in emacs VM. I meant to say, "How can you..." Cheers, Bar From jmayfield at cradlepoint.com Wed Sep 8 19:03:04 2010 From: jmayfield at cradlepoint.com (Justin Mayfield) Date: Wed, 8 Sep 2010 17:03:04 -0600 Subject: Bit fields in python? In-Reply-To: References: Message-ID: <4C881628.1010304@cradlepoint.com> Instead of rewriting your code you might consider wrapping it with the C-API. I prefer this approach (over ctypes) for anything "low level". http://docs.python.org/c-api/ On 09/06/2010 10:06 PM, Kwan Lai Cheng wrote: > Hi, > I'm trying to rewrite a c program in python & encountered several > problems. I have some data structures in my c program like below: > typedef struct > { > unsigned short size; > unsigned short reserved:8; > unsigned short var_a1:2; > unsigned short var_a2:2; > unsigned short var_a3:2; > unsigned short var_a4:2; > unsigned int var_a5; > }structa; > typedef struct > { > unsigned short size; > unsigned char reserved:4; > unsigned char var_b1:1; > unsigned char var_b2:1; > unsigned char var_b3:1; > unsigned char var_b4:1; > structa var_structa; > }structb; > I tried to code the above in python but only got this far: > class StructA(object): > def __init__(self, size=0) > self.size = size > class StructB(object): > def __init__(self, size=0) > Any equivalent for c data structures & bit fields in python? And how > do I define var_structa (in structb) in python? > Regards, > Kwan. > !SIG:4c85bc4844361237431282! -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Sep 8 19:13:37 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 09 Sep 2010 00:13:37 +0100 Subject: accessing a text file In-Reply-To: <19592.5259.240514.451281@bar-macbook.local> References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <7xhbi0y0lh.fsf@ruckus.brouhaha.com> <0b9d791e-94ff-4530-8ecf-b4a65cf1dd11@11g2000yqq.googlegroups.com> <7xmxrsif45.fsf@ruckus.brouhaha.com> <6dd83b1b-9d7b-4734-85d3-0abd9a8c9618@z28g2000yqh.googlegroups.com> <19592.3832.281882.702641@bar-macbook.local> <19592.5259.240514.451281@bar-macbook.local> Message-ID: <4C8818A1.30202@mrabarnett.plus.com> On 08/09/2010 23:56, Bar Shirtcliff wrote: > | HEREow can you be learning so much python if you're constantly expressing > > typo there. I'm not sure how that happens, sometimes, but it's an > untimely abbrev-expansion, in emacs VM. > > I meant to say, "How can you..." > An unkind soul would say that "it's a poor workman who blames his tools", but as it's emacs... ;-) From speeze.pearson at gmail.com Wed Sep 8 19:42:07 2010 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Wed, 8 Sep 2010 16:42:07 -0700 (PDT) Subject: Class changes in circular imports when __name__ == '__main__' References: <17a27900-18da-4179-93bd-dd0cb6cd2683@g21g2000prn.googlegroups.com> <39c85ff7-f1bb-47ad-95b3-bcb9ce9c0c5b@i4g2000prf.googlegroups.com> Message-ID: All right, thank you for helping! I'd had a little voice in the back of my mind nagging me that it might not be logical to include a bunch of classes and function definitions in my startup file, but I never got around to splitting it up. The module/script distinction makes sense, and it seems more elegant, too. Also, my program works now that I've rearranged things, which is a plus. Thanks! From ldo at geek-central.gen.new_zealand Wed Sep 8 20:38:04 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 09 Sep 2010 12:38:04 +1200 Subject: [Tutor] Arguments from the command line References: Message-ID: In message , Hugo Arts wrote: > sys.argv is a list of all arguments from the command line ... Interesting that Python didn?t bother to mimic the underlying POSIX convention of passing the command line as arguments to the mainline routine. I always felt it was more useful to have command arguments directly accessible as globals, rather than having to pass them from the mainline. From ldo at geek-central.gen.new_zealand Wed Sep 8 20:41:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 09 Sep 2010 12:41:20 +1200 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> Message-ID: In message <7xeid9gtuq.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lawrence D'Oliveiro writes: > >> That reinforces my point, about how easy it was to check the correctness >> of the code. In this case one simple fix, like this ... >> would render the code watertight. See how easy it is? > > Well, no, it's irrelevant how easy it is to fix the issue after it's > pointed out. In that case, I can similarly discount your attempts to fix up issues with garbage collectors after they?re pointed out, can I not? > Part of the problem is C itself. And yet, what are these complicated garbage collectors, that you intend relying on to work correctly with all their layers of tricks upon tricks, written in? C. From no.email at nospam.invalid Wed Sep 8 21:20:48 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 08 Sep 2010 18:20:48 -0700 Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> Message-ID: <7xfwxj67bj.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > In that case, I can similarly discount your attempts to fix up issues with > garbage collectors after they?re pointed out, can I not? Adapting GC algorithms to improve their performance or better use the capabilities of new hardware is much different than saying they didn't work in the first place. They've been around for 5 decades, they (like Python programs) work fine if you don't mind the performance cost, and for many applications that cost is acceptable even for quite simple and naive GC's. The continued work is to get that cost down even further. (And before criticizing GC performance, Have you ever profiled CPython to see how much time it's spending messing with reference counts? I didn't think so). >> Part of the problem is C itself. > And yet, what are these complicated garbage collectors, that you intend > relying on to work correctly with all their layers of tricks upon tricks, > written in? C. What tricks on tricks? Even the fanciest GC's are orders of magnitude less complicated than any serious database, optimizing compiler, OS kernel, file system, etc. Real-world software is complicated. Get used to that fact, and look for ways to manage the complexity and keep complex programs safe. Choosing to program with unsafe methods because you wish the complexity didn't exist is just deluded. It actually seems pretty crazy to me to write a garbage collector in C today even though it a GC needs unsafe pointer operations in a few places. C made some sense in the 1980's when computers were smaller and people didn't know better. A lot of the C code around today is legacy code from that era. These days it makes more sense to use a safe language with a few isolated "jailbreaks" (like an OS kernel that has a few lines of assembly code) than to write the whole thing in a language whose unsafety is everywhere. Here's a good paper by R. Fateman (criticizing C) that I just came across: http://www.franz.com/resources/educational_resources/white_papers/fault.prevention.pdf He suggests using Lisp instead, but one can't have everything ;-). FWIW, here are a couple pages about verifying GC's: http://flint.cs.yale.edu/flint/publications/hgc.html http://www.cs.technion.ac.il/~erez/Papers/verified-gc-popl09.pdf etc. I just don't understand that weird agenda you seem to have. But whatever. From ben+python at benfinney.id.au Wed Sep 8 21:31:04 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Sep 2010 11:31:04 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <87sk1jaejr.fsf@benfinney.id.au> Baba writes: > Thanks for your feedback. My question is: Who owns this forum? If we > all do then we are allowed to post questions that are simple and that > could otherwise be answered by doing research. That's a rather subservient perspective. Why are you seeking permission to ask questions? Why do you raise the issue of whether one is *allowed* to ask questions? If you take advice and requests as commandments, then I think that's pretty close to the root of the communication failures here. When someone asks you to change your behaviour, or describes the possible consequences that your behaviour entails, they're treating you as a responsible adult, not as a slave or infant. > It is just unfriendly to tell someone to go and look it up by > themselves. Yes, to *tell* them to do it would be unfriendly. You, however, received *requests* that you do so, with reasons why. Please help us all ? and you are included in ?us all? ? by learning the difference between a command and a request. -- \ ?It is difficult to get a man to understand something when his | `\ salary depends upon his not understanding it.? ?Upton Sinclair, | _o__) 1935 | Ben Finney From ben+python at benfinney.id.au Wed Sep 8 21:33:18 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Sep 2010 11:33:18 +1000 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <87occ7aeg1.fsf@benfinney.id.au> Grant Edwards writes: > I'm sure you'd prefer that everything was handed to you for free on a > silver platter with a side order of beer and cookies. I'd prefer I was > 20 years younger and 30 pounds lighter. Life's tough that way. Hell no. I'd prefer to have the total of my life experience and just have my *body* be twenty years younger :-) -- \ ?The greatest tragedy in mankind's entire history may be the | `\ hijacking of morality by religion.? ?Arthur C. Clarke, 1991 | _o__) | Ben Finney From invalid at invalid.invalid Wed Sep 8 22:03:15 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 9 Sep 2010 02:03:15 +0000 (UTC) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> <87occ7aeg1.fsf@benfinney.id.au> Message-ID: On 2010-09-09, Ben Finney wrote: > Grant Edwards writes: > >> I'm sure you'd prefer that everything was handed to you for free on a >> silver platter with a side order of beer and cookies. I'd prefer I was >> 20 years younger and 30 pounds lighter. Life's tough that way. > > Hell no. I'd prefer to have the total of my life experience and just > have my *body* be twenty years younger :-) I'd have to think about that for a while. A little bit of innocent optimism might be nice... -- Grant From robert.kern at gmail.com Wed Sep 8 23:23:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 08 Sep 2010 22:23:46 -0500 Subject: [Tutor] Arguments from the command line In-Reply-To: References: Message-ID: On 9/8/10 7:38 PM, Lawrence D'Oliveiro wrote: > In message, Hugo Arts > wrote: > >> sys.argv is a list of all arguments from the command line ... > > Interesting that Python didn?t bother to mimic the underlying POSIX > convention of passing the command line as arguments to the mainline routine. There *is* no mainline routine in Python. -- 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 aahz at pythoncraft.com Wed Sep 8 23:53:10 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Sep 2010 20:53:10 -0700 Subject: cPickle segfault with nested dicts in threaded env References: Message-ID: In article , Thomas Jollans wrote: > >Also, Python 2.5 is frightfully old. [...] "Frightfully"??? I'm sure plenty of people are still using Python 2.3 in production environments (certainly my last job did as of 1.5 years ago, and I would be mildly surprised if they upgraded by now). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From steve-REMOVE-THIS at cybersource.com.au Thu Sep 9 00:02:12 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 09 Sep 2010 04:02:12 GMT Subject: Queue cleanup References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> Message-ID: <4c885c44$0$28664$c3e8da3@news.astraweb.com> On Thu, 09 Sep 2010 12:41:20 +1200, Lawrence D'Oliveiro wrote: >> Part of the problem is C itself. > > And yet, what are these complicated garbage collectors, that you intend > relying on to work correctly with all their layers of tricks upon > tricks, written in? C. Not necessarily. Pascal, despite the contempt it is held in by university computer science departments, isn't quite dead, and some Pascal compilers use garbage collectors written in Pascal. FreePascal, I believe, is one of them. Likewise for other not-dead-yet low-level languages like Ada and Forth. As surprising as it seems to many, C is not the only low-level language around suitable for writing high-quality, efficient code. Just ask the Lisp community, which is thriving. For some definition of thriving. Admittedly C has far more attention to it than the others, so [insert weasel words here] the best C compilers tend to produce more efficient code than the best of the others, but Pascal, Ada and similar give you more security than C. I believe that when computer scientists of the future look back at the last few decades, they will judge that on balance C did more harm than good. Not that C is the only language that people can write buggy or insecure code, but C does tend to give the bugs so much help... :) -- Steven From steve-REMOVE-THIS at cybersource.com.au Thu Sep 9 00:58:02 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 09 Sep 2010 04:58:02 GMT Subject: [Tutor] Arguments from the command line References: Message-ID: <4c886959$0$28664$c3e8da3@news.astraweb.com> On Thu, 09 Sep 2010 12:38:04 +1200, Lawrence D'Oliveiro wrote: > In message , Hugo > Arts wrote: > >> sys.argv is a list of all arguments from the command line ... > > Interesting that Python didn?t bother to mimic the underlying POSIX > convention of passing the command line as arguments to the mainline > routine. What mainline routine? > I always felt it was more useful to have command arguments directly > accessible as globals, rather than having to pass them from the > mainline. http://c2.com/cgi/wiki?GlobalVariablesAreBad That's why we have namespaces. If you need the command line arguments, you just import sys and you have access to them. -- Steven From ldo at geek-central.gen.new_zealand Thu Sep 9 01:45:04 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 09 Sep 2010 17:45:04 +1200 Subject: [Tutor] Arguments from the command line References: Message-ID: In message , Dennis Lee Bieber wrote: > None of them have command line arguments "passed" in to some > starting point -- all had to use some runtime library function to ask > for the command line contents. It?s always a language-specific routine, since at the underlying POSIX level (exposed by C), the command line is passed as arguments to the mainline routine. From yue.nicholas at gmail.com Thu Sep 9 04:30:28 2010 From: yue.nicholas at gmail.com (Nicholas) Date: Thu, 9 Sep 2010 01:30:28 -0700 (PDT) Subject: [Q] Function Point Analysis (FPA) - Equivalent lines of code of Python Message-ID: <168f109f-834f-4e99-88cf-35e1ffdc6297@b4g2000pra.googlegroups.com> Hi, In FPA, there are tables which shows equivalent lines of code for each Function Point (FP) for a number of programming languages. e.g. http://www.qsm.com/?q=resources/function-point-languages-table/index.html However, I have yet to find the figures for Python. Is someone able to advise the closest language equivalent. Regards From news1234 at free.fr Thu Sep 9 04:41:50 2010 From: news1234 at free.fr (News123) Date: Thu, 09 Sep 2010 10:41:50 +0200 Subject: are there pros or contras, keeping a connection to a (sqlite) database ? In-Reply-To: References: Message-ID: <4c889dce$0$4622$426a34cc@news.free.fr> On 09/09/2010 12:29 AM, CM wrote: > On Sep 8, 1:09 pm, Stef Mientki wrote: >> hello, >> >> I wrap my database in some class, and on creation of the instance, a connection to the database is >> created, >> and will stay connected until the program exists, something like this: >> >> self.conn = sqlite3.connect ( self.filename ) >> >> Now I wonder if there are pros or contras to keep the connection to the database continuously "open" ? >> >> thanks, >> Stef Mientki > > I do the same thing--good to hear from John that keeping it open is > OK. > > But another question that this provokes, at least for me is: what > happens when you call .connect() on the same database multiple times > from within different parts of the same app? Is that bad? And is it > that there now multiple connections to the database, or one connection > that has multiple names in different namespaces within the app? CM, Do you talk about a multithreaded environment? or only about an environment with logically separate blocks (or with generators), and multiple objects each keeping their own connection. As far as I know sqlite can be compiled to be thread safe, but is not necessarily be default. No idea about the library used b python. I personally just started sqlite in one of my apps with multithrading and in order to be safe I went for the conservative approach connect, perform transactions, commit and close. However this is probably overkill and later in time I might also ty to keep connections open in order to increse performance. > I'm not even sure what a "connection" really is; I assumed it was > nothing more than a rule that says to write to the database with the > file named in the parentheses. > > Further elaboration from the community would be helpful. > > Thanks, > Che From no.email at nospam.invalid Thu Sep 9 04:45:04 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 09 Sep 2010 01:45:04 -0700 Subject: [Q] Function Point Analysis (FPA) - Equivalent lines of code of Python References: <168f109f-834f-4e99-88cf-35e1ffdc6297@b4g2000pra.googlegroups.com> Message-ID: <7x4odz5mr3.fsf@ruckus.brouhaha.com> Nicholas writes: > e.g. http://www.qsm.com/?q=resources/function-point-languages-table/index.html > However, I have yet to find the figures for Python. > Is someone able to advise the closest language equivalent. That table looks pretty bogus, but of the languages on the list, perl is probably about the closest to python in spirit and code density. From jaksonaquino at gmail.com Thu Sep 9 06:07:56 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Thu, 9 Sep 2010 07:07:56 -0300 Subject: SendKeys and Python 2.7 Message-ID: Hi, I would like to send code from Vim [1] to R [2] on Microsoft Windows. Vim needs python 2.7 but the pre-compiled SendKeys module [3] is only avaiable for python 2.6. How can I make SendKeys work with python 2.7? I don't know how to compile python code. Is there an alternative to SendKeys? I'm sending to R only "^v" to paste the content of the clipboard. Thanks, Jakson Aquino [1] http://www.vim.org/ [2] http://www.r-project.org/ [3] http://www.rutherfurd.net/python/sendkeys/#binaries From martin at address-in-sig.invalid Thu Sep 9 06:12:44 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 9 Sep 2010 10:12:44 +0000 (UTC) Subject: [Tutor] Arguments from the command line References: Message-ID: On Wed, 08 Sep 2010 21:58:49 -0700, Dennis Lee Bieber wrote: > On Thu, 09 Sep 2010 12:38:04 +1200, Lawrence D'Oliveiro > declaimed the following in > gmane.comp.python.general: > >> In message , Hugo >> Arts wrote: >> >> > sys.argv is a list of all arguments from the command line ... >> >> Interesting that Python didn?t bother to mimic the underlying POSIX >> convention of passing the command line as arguments to the mainline >> routine. >> > What "mainline routine"... The only programming language(s) I've > ever used that requires there be something called "main" in order to > start a program is the C/C++ family. > Java uses a method defined as "public static void main(String[] args)" > My college COBOL never used multifile assignments, so I'm not sure > if there was a difference between main and linked modules. > There isn't, but command line argument passing is implementation- dependent and is complicated by the ability to define callable sub- programs in the same source file as the main program. The most general method is to use ACCEPT statements. MicroFocus COBOL uses "ACCEPT ... FROM ARGUMENT-NUMBER", AIX COBOL uses a special system call and ICL 2900 COBOL and IBM COBOL/400, where the command line uses function call notation, map the command line arguments into a LINKAGE SECTION. In short: this area of COBOL is a mess. PL/I specifies the main procedure with an OPTIONS(MAIN) clause and declares the integer ARGC_ and pointer ARGV_ variables in it, which are used like their C equivalents. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From morfeokmg at gmail.com Thu Sep 9 07:25:51 2010 From: morfeokmg at gmail.com (Mauricio Martinez Garcia) Date: Thu, 9 Sep 2010 06:25:51 -0500 Subject: cath a timeout of httplib (Python 2.6.5) Message-ID: Hi!. I have a problem with httplib and timeout. (I use python 2.6.5 and httplib) I have the next code for the http connection (its a WebService Client). =================================================================== def ejecutaComandos(self,opcion, URL, commandString, conn, id): #pdb.set_trace() #fechatransacciones = conciliatorTime() #status = conn.status #date_transacc = fechatransacciones.getCompleteDate() try: try: enviaCommand = conn.request("POST", str(URL), commandString) respuestaCommand = conn.getresponse() except Exception as e: print 'Error de conexion: ',e #intentar=raw_input("Desea intentar nuevamente (S/N) : ") exit(1) respuestaWSDL = respuestaCommand.read() #print respuestaCommand nom_rand = str(random.choice('lmnopqrstuvwxyzABCDEFGHIJ'))+str(random.choice('abcdefghijk')) FileRand = nom_rand+'_tmp.xml' newFile = creaArchivos(FileRand,self.output) a = newFile.creaFile('w') #a = open('../output/responseXML.tmp', 'w') a.write(respuestaWSDL) a.close() #print XP_LOG+'respuesta de HLAPI recibida...'+str(date_transacc) #return respuestaWSDL return a.name #except httplib.HTTPException as he: except Exception as he: print "Error de ejecucion ...: %s " % (he) else: print "Error inesperado..." =================================================================== I need resend the command when a timeout error present, my idea its use a "while". =================================================================== while (intentar=='S'): try: enviaCommand = conn.request("POST", str(URL), commandString) respuestaCommand = conn.getresponse() raise Exception except Exception as e: print 'Error de conexion: ',e intentar=raw_input("Desea intentar nuevamente (S/N) : ") if (intentar=='N'): exit(1) =================================================================== But the information of "enviaCommand" it is lost, and it been only "None", then fail resend. As I can resend the information without the command loses itself. Greetings and tanks!. -- Mauricio Martinez Garcia morfeokmg at gmail.com "Si encuentras un tr?bol de cuatro hojas..., hallaras la felicidad. Pero ?Sabes?, seguramente no la encontrar?s, porque la felicidad se encuentra en silencio guardada en una jaula. EL trebol de Cuatro hojas nunca ser? de nadie... ?Que te parece si te adue?as de un tr?bol de tres hojas?..." "???????, ???????, ????????, ??????, ????, ????????, ????, ??????, ??????, ????, ???????, ???????, ????????????, ???????????, ?????????????, ?????????, ?????????, ???????, ??????, ?????????, ?????????, ????, ???????, ????"???", ?????? ??, ????? ?????? ?????? ???????? ??"???" ???????? ??????????" -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Thu Sep 9 07:28:40 2010 From: robin at reportlab.com (Robin Becker) Date: Thu, 09 Sep 2010 12:28:40 +0100 Subject: 32 bit bdist_wininst vs x64 platform Message-ID: <4C88C4E8.6080003@chamonix.reportlab.co.uk> A reportlab user is using 32 bit python on x64 win 2003. he has a problem installing our bdist_wininst exe because the installer cannot find python. Apparently the installer is looking at HKLM\Software to locate python, but on x64 32 bit program requests get redirected to HKLM\Software\Wow6432Node (Extended explanation in KB article 896459). Is this fixable by me making a local patch to my distutils to check for the real platform and modifying the RegOpenKeyEx call? Or is there some distutils magic that I'm missing? Does anyone know if the bdist_msi might be better? -- Robin Becker From Dominique.Holzwarth at ch.talaris.com Thu Sep 9 07:46:26 2010 From: Dominique.Holzwarth at ch.talaris.com (Holzwarth, Dominique (Berne Branch)) Date: Thu, 9 Sep 2010 12:46:26 +0100 Subject: importing module Message-ID: Hi all Lets assume I have the following structure of directories and python modules: Root-dir |_dir1 |_ script1.py |_dir2 |_ script2.py |_sudir2 |_ script3.py Is it possible to import script1 into script2 and script3? Or do have to put script1.py into the Lib\site-packages folder of my Python installation so that it'll be in the standard module search path? Thx & greets Dominique ***************************************************************************** This e-mail and any files attached are strictly confidential, may be legally privileged and are intended solely for the addressee. If you are not the intended recipient please notify the sender immediately by return email and then delete the e-mail and any attachments immediately. The views and or opinions expressed in this e-mail are not necessarily the views of Talaris Holdings Limited or any of its subsidiaries and the Talaris Group of companies, their directors, officers and employees make no representation about and accept no liability for its accuracy or completeness. You should ensure that you have adequate virus protection as the Talaris Group of companies do not accept liability for any viruses. Talaris Holdings Limited Registered No. 6569609 and Talaris Limited Registered No 6569621 are both registered in England with their registered office at: Talaris House, Crockford Lane, Chineham Business Park, Basingstoke, RG24 8QZ ***************************************************************************** From marduk at letterboxes.org Thu Sep 9 07:51:23 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 09 Sep 2010 07:51:23 -0400 Subject: SendKeys and Python 2.7 In-Reply-To: References: Message-ID: <1284033083.3449.8.camel@paska> On Thu, 2010-09-09 at 07:07 -0300, Jakson A. Aquino wrote: > Vim needs python 2.7 >From where do you base this assertion? I have been using vim 7.3 (with embedded python) with python 2.6 pretty much since it has been released. :version VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Aug 29 2010 07:21:44) [...] :python import sys; print sys.version 2.6.5 (release26-maint, Aug 28 2010, 21:57:54) [GCC 4.4.4] From heniser at yahoo.com Thu Sep 9 08:23:14 2010 From: heniser at yahoo.com (Ryan) Date: Thu, 9 Sep 2010 05:23:14 -0700 (PDT) Subject: Catching a SIGSEGV signal on an import Message-ID: Is there anyway to catch a SIGSEGV signal that results from an import? I'd like to get a list of all modules on the sys.path. The module pkgutil has a nice method, walk_packages, to do just that. But, there is a third party extension that throws a SIGSEGV when imported. I tried to create a signal handler with the signal module like: #!/bin/env python import pkgutil import signal import traceback def handler(signal, stackframe): raise ImportError # Handle seg faults that may occur during an import signal.signal(signal.SIGSEGV, handler) if __name__ == "__main__": goodMods = [] def onerror(pkgName): sys.stdout.write('Unable to import package %s\n' % pkgName) traceback.print_exc(file=sys.stdout) sys.stdout.write('\n') #sys.stdout.flush() for importer, mod, ispkg in pkgutil.walk_packages(path=None, onerror=onerror): goodMods.append(mod) for m in goodMods: sys.stdout.write(m + '\n') sys.stdout.flush() This sometimes works. But, since SIGSEGV is asynchronous it is not guaranteed to work all the time. In general, is there anyway to catch a SIGSEGV on import? If so, is there a way to use that with pkgutil.walk_packages to get all the modules on sys.path? Thanks, Ryan From __peter__ at web.de Thu Sep 9 08:51:21 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Sep 2010 14:51:21 +0200 Subject: importing module References: Message-ID: Holzwarth, Dominique (Berne Branch) wrote: > Hi all > > Lets assume I have the following structure of directories and python > modules: > > Root-dir > |_dir1 > |_ script1.py > |_dir2 > |_ script2.py > |_sudir2 > |_ script3.py > > Is it possible to import script1 into script2 and script3? Or do have to > put script1.py into the Lib\site-packages folder of my Python installation > so that it'll be in the standard module search path? You have three options - put script1.py into a directory in python's search path - modify the PYTHONPATH environment variable to include /path/to/dir1 - add a .pth file in a directory already in python's search path http://docs.python.org/library/site.html#module-site http://docs.python.org/install/#inst-search-path Peter From mwilson at the-wire.com Thu Sep 9 10:23:03 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 09 Sep 2010 10:23:03 -0400 Subject: [Tutor] Arguments from the command line References: Message-ID: Dennis Lee Bieber wrote: > On Thu, 09 Sep 2010 12:38:04 +1200, Lawrence D'Oliveiro > declaimed the following in > gmane.comp.python.general: > >> In message , Hugo >> Arts wrote: >> >> > sys.argv is a list of all arguments from the command line ... >> >> Interesting that Python didn?t bother to mimic the underlying POSIX >> convention of passing the command line as arguments to the mainline >> routine. >> > What "mainline routine"... The only programming language(s) I've > ever used that requires there be something called "main" in order to > start a program is the C/C++ family. [ ... ] > My college COBOL never used multifile assignments, so I'm not sure > if there was a difference between main and linked modules. Historical COBOL had a PROCEDURE DIVISION which marked the start of execution. But historical COBOL didn't pass parameters anyway. You read your optional arguments from a file, or accepted a few from an input device. I don't know PL/I generally, but with Multics PL/I any externally accessible procedure could be called from the command line: any_program$ea_proc a b c passing (for example) 'a', 'b', and 'c' as parameters. If the parameters were declared as variable-length character strings: ea_proc: proc (x, y, z); dcl (x, y, z) char (*); ... this would even work. Illustrating that the command-line-parameter-passing question is a deal with the operating system at least as much as it's a language issue. Posix aren't the only O/S. Mel. From giacomo.boffi at polimi.it Thu Sep 9 10:52:21 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Thu, 09 Sep 2010 16:52:21 +0200 Subject: [Tutor] Arguments from the command line References: Message-ID: <8662yfklzu.fsf@aiuole.stru.polimi.it> Dennis Lee Bieber writes: > FORTRAN just differentiates by having the main file start with > PROGRAM random_name > whereas subfiles are all either (or both) > SUBROUTINE another_name(args) > FUNCTION that_other_name(args) no BLOCKDATA? From kdombrowski at gmail.com Thu Sep 9 11:06:42 2010 From: kdombrowski at gmail.com (Kenneth Dombrowski) Date: Thu, 9 Sep 2010 11:06:42 -0400 Subject: cPickle segfault with nested dicts in threaded env In-Reply-To: <7x62yf3kws.fsf@ruckus.brouhaha.com> References: <4ce8d0a7-6784-4936-ba82-2ef2f393e8cc@q21g2000prm.googlegroups.com> <7x62yf3kws.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Sep 8, 2010 at 6:55 PM, Paul Rubin wrote: > Carl Banks writes: >> Since Python 2.7 is released, Python 2.5 is no longer accepting bug >> fixes, only security fixes. ?So be aware. > > Segfaults should be treated as security holes unless there's convincing > reasons that no exploit is possible. ?So the bug should be reported > against 2.5 as well as later versions. Hi Paul, Thanks for the input, it sounds reasonable to me. I reported it & the maintainers can decide what to do with it: http://bugs.python.org/issue9812 Thanks again everyone, Kenneth From ctops.legal at gmail.com Thu Sep 9 11:07:43 2010 From: ctops.legal at gmail.com (ctops.legal) Date: Thu, 9 Sep 2010 08:07:43 -0700 (PDT) Subject: Python script for repairing .mov file ? Message-ID: <2d1b137c-3722-420c-bbe3-55719482cc08@g10g2000vbc.googlegroups.com> Jave is much better; http://yfrog.com/naattempt1hj From fritz at loseries.info Thu Sep 9 11:20:03 2010 From: fritz at loseries.info (Fritz Loseries) Date: Thu, 09 Sep 2010 17:20:03 +0200 Subject: how to extract an implicit dict expression (with statement return) Message-ID: <4C88FB23.1060605@loseries.info> Hi, I do not know how to subject my problem in a better way. I have the following statement: return [ dict(x1 = elem.x1, x2 = elem.x2, x3 = elem.x3,) for elem in method(in_values) ] How can I transform it to an explicit description: result = ... return result Could not found a description for the here used form of for and what [...] means. Need this for debugging. Thanks for any help. Regards, Fritz From benjamin.kaplan at case.edu Thu Sep 9 11:28:05 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 9 Sep 2010 11:28:05 -0400 Subject: how to extract an implicit dict expression (with statement return) In-Reply-To: <4C88FB23.1060605@loseries.info> References: <4C88FB23.1060605@loseries.info> Message-ID: On Thu, Sep 9, 2010 at 11:20 AM, Fritz Loseries wrote: > Hi, > > I do not know how to subject my problem in a better way. > > I have the following statement: > > ? ?return [ dict(x1 = elem.x1, x2 = elem.x2, x3 = elem.x3,) > ? ? ? ? ? ? ? ?for elem in method(in_values) > ? ? ? ? ? ? ?] > > How can I transform it to an explicit description: > > ? ?result = ... > ? ?return result > > Could not found a description for the here used form of for and what > [...] means. > > Need this for debugging. > Thanks for any help. > > Regards, > > Fritz [ ] defines a list literal >>> [1,2,3] [1, 2, 3] >>> type(_) This particular syntax [ ____ for ___ in ___] is a list comprehension. It's creating an inline for-loop to generate a list. You can just lift the whole expression for the assignment. result = [ dict(x1 = elem.x1, x2 = elem.x2, x3 = elem.x3,) ? ? ? ? ? ? ? ?for elem in method(in_values) ? ? ? ? ? ? ?] return result > > -- > http://mail.python.org/mailman/listinfo/python-list > From breamoreboy at yahoo.co.uk Thu Sep 9 12:07:14 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Sep 2010 17:07:14 +0100 Subject: [Python-ideas] with statement syntax forces ugly line breaks? In-Reply-To: <4C87E45A.1080207@mrabarnett.plus.com> References: <20100908175029.6617ae3b@dino> <4C87E45A.1080207@mrabarnett.plus.com> Message-ID: On 08/09/2010 20:30, MRAB wrote: > On 08/09/2010 19:07, Georg Brandl wrote: >> Thus spake the Lord: Thou shalt indent with four spaces. No more, no >> less. Four shall be the number of spaces thou shalt indent, and the >> number of thy indenting shall be four. Eight shalt thou not indent, >> nor either indent thou two, excepting that thou then proceed to four. >> Tabs are right out. >> > FYI, that should be "thine indenting". > > "My/thy" before a consonant, "mine/thine" before a vowel. Compare with > "a/an", which we still do. Hopefully correct, but certainly better than you knowledge of Spanish :) Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Thu Sep 9 12:13:22 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Sep 2010 17:13:22 +0100 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On 08/09/2010 21:23, Jonno wrote: > On Wed, Sep 8, 2010 at 3:18 PM, Jonno wrote: >> On Wed, Sep 8, 2010 at 3:06 PM, Jonno wrote: >>> On Wed, Sep 8, 2010 at 2:11 PM, Benjamin Kaplan >>> wrote: >>>> On Wed, Sep 8, 2010 at 2:55 PM, Jonno wrote: >>>>> I know that I can index into a list of lists like this: >>>>> a=[[1,2,3],[4,5,6],[7,8,9]] >>>>> a[0][2]=3 >>>>> a[2][0]=7 >>>>> >>>>> but when I try to use fancy indexing to select the first item in each >>>>> list I get: >>>>> a[0][:]=[1,2,3] >>>>> a[:][0]=[1,2,3] >>>>> >>>>> Why is this and is there a way to select [1,4,7]? >>>>> -- >>>> >>>> It's not fancy indexing. It's called taking a slice of the existing >>>> list. Look at it this way >>>> a[0] means take the first element of a. The first element of a is [1,2,3] >>>> a[0][:] means take all the elements in that first element of a. All >>>> the elements of [1,2,3] are [1,2,3]. >>>> >>>> a[:] means take all the elements of a. So a[:] is [[1,2,3],[4,5,6],[7,8,9]]. >>>> a[:][0] means take the first element of all the elements of a. The >>>> first element of a[:] is [1,2,3]. >>>> >>>> There is no simple way to get [1,4,7] because it is just a list of >>>> lists and not an actual matrix. You have to extract the elements >>>> yourself. >>>> >>>> col = [] >>>> for row in a: >>>> col.append(row[0]) >>>> >>>> >>>> You can do this in one line using a list comprehension: >>>> [ row[0] for row in a ] >>>> >>> Thanks! (to Andreas too). Totally makes sense now. >>> >> >> Now if I want to select the first item in every 2nd item of list a >> (ie: [1,7]) can I use ::2 anywhere or do I need to create a list of >> indices to use in a more complex for loop? >> > Seems like the simplest way would be: > [row[0] for row in a][::2] The fastest way to find out is probably typing at the interactive prompt. Just jump in at the deep end and see what happens. Then wait until someone tells you to use the timeit module. Cheers. Mark Lawrence. From python at mrabarnett.plus.com Thu Sep 9 12:26:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 09 Sep 2010 17:26:27 +0100 Subject: [Python-ideas] with statement syntax forces ugly line breaks? In-Reply-To: References: <20100908175029.6617ae3b@dino> <4C87E45A.1080207@mrabarnett.plus.com> Message-ID: <4C890AB3.9030400@mrabarnett.plus.com> On 09/09/2010 17:07, Mark Lawrence wrote: > On 08/09/2010 20:30, MRAB wrote: >> On 08/09/2010 19:07, Georg Brandl wrote: >>> Thus spake the Lord: Thou shalt indent with four spaces. No more, no >>> less. Four shall be the number of spaces thou shalt indent, and the >>> number of thy indenting shall be four. Eight shalt thou not indent, >>> nor either indent thou two, excepting that thou then proceed to four. >>> Tabs are right out. >>> >> FYI, that should be "thine indenting". >> >> "My/thy" before a consonant, "mine/thine" before a vowel. Compare with >> "a/an", which we still do. > X-Antispam: NO; Spamcatcher 6.0.4. Score 1 > > Hopefully correct, but certainly better than you knowledge of Spanish :) > Or /your/ knowledge of English! (Muphry's Law) :-) From jonnojohnson at gmail.com Thu Sep 9 12:33:45 2010 From: jonnojohnson at gmail.com (Jonno) Date: Thu, 9 Sep 2010 11:33:45 -0500 Subject: Slice a list of lists? In-Reply-To: References: Message-ID: On Thu, Sep 9, 2010 at 10:58 AM, Robert Kern wrote: > Please keep responses on the mailing list. However, I will reply below > this one time. > > On Thu, Sep 9, 2010 at 10:35, Jonno wrote: >> On Wed, Sep 8, 2010 at 4:26 PM, Robert Kern wrote: >>> A motivating example: >>> >>> [~] >>> |1> import numpy >>> >>> [~] >>> |2> a = numpy.array([[1,2,3],[4,5,6],[7,8,9]]) >>> >>> [~] >>> |3> a >>> >>> array([[1, 2, 3], >>> ? ? ? [4, 5, 6], >>> ? ? ? [7, 8, 9]]) >>> >>> [~] >>> |4> a[0,2] >>> 3 >>> >>> [~] >>> |5> a[2,0] >>> 7 >>> >>> [~] >>> |6> a[0,:] >>> array([1, 2, 3]) >>> >>> [~] >>> |7> a[:,0] >>> array([1, 4, 7]) >>> >>> >>> -- >>> Robert Kern >> >> Thanks Robert. I'm actually much more familiar and comfortable with >> arrays so I know how to slice them. The problem is that the data comes >> from lines in a file which are not all of equal length. >> My understanding is that I need to manipulate the data as lists until >> I can get all the lists of equal length at which point I can make an >> array from it. > > If you have ragged arrays, then you do not want to slice down columns > to begin with. You might run into a row that does not have a value at > that column. If you need to slice down columns (whether the object > remains a list of lists or a numpy array), then you need to create a > rectangular array regardless. Do that first, then I recommend using > numpy arrays. Slicing down columns (probably) won't help you with > that. Understood. My data actually has 2 features which make it non-rectangular in most circumstances. One is the extra element at the start of every nth line (I now know how to remove that) and the second is that some lines contain more data than others. My data is essentially a m,m,n array but data from each row is shifted to the next line when the line is full (4 columns). A new row then starts a new line. I want to pick out the data and assign it to an array but I'm wondering whether I should first try to take the data on the extra lines, remove it and stick it on the end of the original line (the data from one "row" could extend onto multiple lines). Or whether I'm better trying to create the array using loops to index my way through the lines the way they already are laid out. Hope this makes sense. From ethan at stoneleaf.us Thu Sep 9 15:23:17 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Sep 2010 12:23:17 -0700 Subject: Difference between queues and pipes in multiprocessing In-Reply-To: References: <5E121D65-6150-4CC6-A35D-7834A81131AC@gmail.com> Message-ID: <4C893425.8090300@stoneleaf.us> James Mills wrote: > On Wed, Aug 4, 2010 at 7:20 PM, Navkirat Singh wrote: >> I was wondering what are the differences between queues and pipes implemented using multiprocessing python module. Am I correct if I say, in pipes, if another process writes to one receiving end concurrently, then an error will be raised and in queues the later processes data will just queued up? > > basically a Queue is a syncronization primitive used to > share and pass data to and from parent/child processes. > > A pipe is as the name suggests, a socket pair connected > end-to-end allowing for full-duplex communications. > Isn't a pipe's communications one-way, requiring two of them to achieve full-duplex? ~Ethan~ From stephen.boulet at gmail.com Thu Sep 9 15:43:43 2010 From: stephen.boulet at gmail.com (Stephen Boulet) Date: Thu, 9 Sep 2010 12:43:43 -0700 (PDT) Subject: Printing the name of a variable Message-ID: Does an arbitrary variable carry an attribute describing the text in its name? I'm looking for something along the lines of: x = 10 print x.name >>> 'x' Perhaps the x.__getattribute__ method? Thanks. From marduk at letterboxes.org Thu Sep 9 16:11:27 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 09 Sep 2010 16:11:27 -0400 Subject: Printing the name of a variable In-Reply-To: References: Message-ID: <1284063087.3181.17.camel@paska> On Thu, 2010-09-09 at 12:43 -0700, Stephen Boulet wrote: > Does an arbitrary variable carry an attribute describing the text in > its name? I'm looking for something along the lines of: > > x = 10 > print x.name > >>> 'x' > > Perhaps the x.__getattribute__ method? Thanks. Variables are not objects and so they have no attributes. You can't really de-reference the object being referenced as it can potentially contain multiple references, but an innacurate way of doing this would be, e.g. >>> x = [1, 2, 3] >>> y = x >>> g = globals() >>> varnames = [i for i in g if g[i] is x] ['x', 'y'] But this cries the question: why do you want to do this? And usually that question is asked when someone thinks that a: you shouldn't need to do this and b: whatever the desired effect there is probably a better way of accomplishing it. From markhirota at gmail.com Thu Sep 9 16:22:39 2010 From: markhirota at gmail.com (Mark Hirota) Date: Thu, 9 Sep 2010 13:22:39 -0700 Subject: Why does linecache avoid ? How can I get equivalent of inspect.getsource() for an interactive session? Message-ID: Here's my goal: To enable a function for interactive session use that, when invoked, will "put" source code for a specified object into a plaintext file. Based on some initial research, this seems similar to ipython's %save magic command (?) Example: def put(filename, object): f = open(filename, "w") f.write(inspect.getsource(object)) f.close() Of course, in an interactive session, if you define a function: >>> def addit(a,b): return a+b And then try to run inspect.getsource() on it, you'll get an exception: >>> inspect.getsource(addit) Traceback (most recent call last): File "", line 1, in File "C:\Python26\lib\inspect.py", line 689, in getsource lines, lnum = getsourcelines(object) File "C:\Python26\lib\inspect.py", line 678, in getsourcelines lines, lnum = findsource(object) File "C:\Python26\lib\inspect.py", line 526, in findsource raise IOError('could not get source code') IOError: could not get source code This appears to be due to the fact that the linecache standard library module doesn't include (?) Can anyone help shed some light on why this is -- and perhaps provide feedback on whether this goal is feasible? Thanks! From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu Sep 9 16:40:39 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Thu, 09 Sep 2010 22:40:39 +0200 Subject: SendKeys and Python 2.7 References: Message-ID: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Hi! Example for send ^V (with PyWin32): import time,win32api,win32con win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) time.sleep(0.05) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) @-salutations -- Michel Claveau From nobody at nowhere.com Thu Sep 9 17:03:59 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 09 Sep 2010 22:03:59 +0100 Subject: Difference between queues and pipes in multiprocessing References: <5E121D65-6150-4CC6-A35D-7834A81131AC@gmail.com> Message-ID: On Thu, 09 Sep 2010 12:23:17 -0700, Ethan Furman wrote: >> basically a Queue is a syncronization primitive used to >> share and pass data to and from parent/child processes. >> >> A pipe is as the name suggests, a socket pair connected >> end-to-end allowing for full-duplex communications. >> > > Isn't a pipe's communications one-way, requiring two of them to achieve > full-duplex? He's talking about multiprocessing.Pipe(), not a Unix pipe. On Unix, multiprocessing.Pipe() uses a socket pair if duplex==True and a pipe if duplex==False. On Windows it uses a named pipe (which can be either unidirectional or bidirectional). From nobody at nowhere.com Thu Sep 9 17:09:29 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 09 Sep 2010 22:09:29 +0100 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: On Wed, 08 Sep 2010 03:30:00 -0700, Baba wrote: > Who is licensed to judge what can and cannot be posted as a question? Exactly the same set of people who are licensed to judge what can and cannot be posted as an answer. If you don't like the responses you get here, you could try posting your questions on 4chan. If nothing else, that will give you a whole new perspective on what an "unfriendly" response really looks like. From nobody at nowhere.com Thu Sep 9 17:20:36 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 09 Sep 2010 22:20:36 +0100 Subject: Catching a SIGSEGV signal on an import References: Message-ID: On Thu, 09 Sep 2010 05:23:14 -0700, Ryan wrote: > But, since SIGSEGV is asynchronous SIGSEGV is almost always synchronous. > In general, is there anyway to catch a SIGSEGV on import? No. If SIGSEGV is raised, it often indicates that memory has been corrupted. At that point, you can't assume that the Python runtime is still functional. In general, even attempting to catch it is a bad idea. Particularly in a high-level language; getting it right in C is hard enough. From no.email at nospam.invalid Thu Sep 9 17:35:12 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 09 Sep 2010 14:35:12 -0700 Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <7x39ti4n3j.fsf@ruckus.brouhaha.com> Nobody writes: > If you don't like the responses you get here, you could try posting your > questions on 4chan. If nothing else, that will give you a whole new > perspective on what an "unfriendly" response really looks like. +1 QOTW From raoulbia at gmail.com Thu Sep 9 17:39:36 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 9 Sep 2010 14:39:36 -0700 (PDT) Subject: analysis of algoritms Message-ID: Hi In below code "the outer loop test in step 4 will execute ( n + 1 ) times (note that an extra step is required to terminate the for loop, hence n + 1 and not n executions), which will consume T4( n + 1 ) time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) 1 get a positive integer from input 2 if n > 10 3 print "This might take a while..." 4 for i = 1 to n 5 for j = 1 to i 6 print i * j 7 print "Done!" Why does step 4 execute n+1 times? what is the exta step mentioned above tnx Baba From tjreedy at udel.edu Thu Sep 9 17:40:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Sep 2010 17:40:14 -0400 Subject: Printing the name of a variable In-Reply-To: References: Message-ID: On 9/9/2010 3:43 PM, Stephen Boulet wrote: In Python, 'variable' is a synonym for name and identifier,' An object can have 0 to many names attached to it. An object can also be a member of 0 to many collections. Modules, classes, and functions have 'definition name' strings attached to them as their .__name__ attribute. This attribute is used to display the 'value' of these objects, as in >>> def f(): pass >>> f The __name__ attribute is also used in the idiom >>> if __name__ == '__main__': print("I am the main module") I am the main module to determine if a module is being run as the main module as imported into another module. -- Terry Jan Reedy From ron.eggler at gmail.com Thu Sep 9 17:45:06 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 9 Sep 2010 14:45:06 -0700 (PDT) Subject: how to kill a subprocess Message-ID: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> Hi There, I'm calling a python script from a php script which again calls a perl script with subprocess.popen(). This seems to work fine so far only that once the python script completed it is becoming a zombie because the perl script in the background is still running... so before i exit the python script, i would need to kill my perl subprocess. How can i do so? Thank you for hints & suggestions! Ron From almar.klein at gmail.com Thu Sep 9 17:54:29 2010 From: almar.klein at gmail.com (Almar Klein) Date: Thu, 9 Sep 2010 23:54:29 +0200 Subject: analysis of algoritms In-Reply-To: References: Message-ID: On 9 September 2010 23:39, Baba wrote: > Hi > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1 get a positive integer from input > 2 if n > 10 > 3 print "This might take a while..." > 4 for i = 1 to n > 5 for j = 1 to i > 6 print i * j > 7 print "Done!" > > Why does step 4 execute n+1 times? what is the exta step mentioned > above > Because it does two things: - increase i - check whether i is still smaller than n. If it is not, the loop is terminated Still, this is quite a simplification of what's really going on... Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From gasproni at asprotunity.com Thu Sep 9 18:03:28 2010 From: gasproni at asprotunity.com (aspro) Date: Thu, 9 Sep 2010 15:03:28 -0700 (PDT) Subject: [ANN] ACCU 2011 Conference Call for Proposals -- deadline approaching Message-ID: <7a15d251-b28e-4120-b534-e37b4d175737@c13g2000vbr.googlegroups.com> Hi all, This is a reminder that the deadline for the ACCU 2011 CfP is approaching fast--26th of September 2010. If you have not sent your proposals yet, below there are more details on how to do so. Call for Proposals - ACCU 2011 April 13-16, 2011. Barcelo Oxford Hotel, Oxford, UK Submission deadline: 26th of September 2010 Email proposals to: Giovanni Asproni, conference at accu.org http://www.accu.org/conference twitter: @accu2011 #accu2011 We invite you to propose a session for this leading software development conference. We have a long tradition of high quality sessions covering many aspects of software development, from programming languages (e.g., Java, C#, Python, Erlang, Haskell, Ruby, Groovy, C, C++, etc.), and technologies (libraries, frameworks, databases, etc.) to subjects about the wider development environment such as testing, architecture and design, development process, analysis, patterns, project management, and softer aspects such as team building, communication and leadership. Sessions may be either tutorial-based, presentations of case studies, or take the form of interactive workshops. We are always open to novel formats, so please contact us with your idea. The standard length of a session is 90 minutes, with some exceptions. In order to allow less experienced speakers to speak at the conference without the pressure of filling a full 90 minutes, we reserve a number of shorter 45 minute sessions. If you would like to run a session please let us know by emailing your proposals to conference at accu.org by the 26th of September 2010 at the latest. Please include the following to support your proposal: * Title (a working title if necessary) * Type (tutorial, workshop, case study, etc.) * Duration (45/90 min) * Speaker name(s) * Speaker biography (max 150 words) * Description (approx 250 words) Proposals about specific products and technologies will be taken under consideration only if they are open source and available for free (at least for non-commercial use). If you are interested in talking about a proprietary technology, there is the possibility of "sponsored sessions" which are presented outside the standard conference schedule. Please, email conference at accu.org for more information. If you are interested in knowing more about the conference you may like to consult the website for previous years' editions at http://www.accu.org/conference for background information. Speakers running one or more full 90 minute sessions receive a special conference package including free attendance, and assistance with their travel and accommodation costs. Speakers filling a 45 minute slot qualify for free conference attendance on the day of their session. The conference has always benefited from the strength of its programme. Please help us make 2011 another successful event. Giovanni Asproni Conference Chair From robert.kern at gmail.com Thu Sep 9 18:10:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 09 Sep 2010 17:10:22 -0500 Subject: analysis of algoritms In-Reply-To: References: Message-ID: On 9/9/10 4:39 PM, Baba wrote: > Hi > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1 get a positive integer from input > 2 if n> 10 > 3 print "This might take a while..." > 4 for i = 1 to n > 5 for j = 1 to i > 6 print i * j > 7 print "Done!" > > Why does step 4 execute n+1 times? what is the exta step mentioned > above You may wish to ask the question on the associated Discussion page for that article. Hopefully the author of that statement will notice it there. They are almost certainly not here. That said, an extra step is required because a real implementation of that algorithm in a language will create a variable `i` initialized to 1, increment it each round through the loop, and check it before running the loop. When the check indicates that it equals n + 1 (not n!) it will exit the loop. That particular pseudocode notation hides that detail. Of course, there are ways to implement that pseudocode that do not require the last check, but none of real importance. -- 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 gh at ghaering.de Thu Sep 9 18:16:58 2010 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 10 Sep 2010 00:16:58 +0200 Subject: are there pros or contras, keeping a connection to a (sqlite) database ? In-Reply-To: References: Message-ID: On Thu, Sep 9, 2010 at 12:29 AM, CM wrote: > [...] > I'm not even sure what a "connection" really is; I assumed it was > nothing more than a rule that says to write to the database with the > file named in the parentheses. [...] The following list is not exclusive, but these are the first things that I can think of. - SQLite connections have state like uncommitted transactions - SQLite connections have page caches and metadata caches (tables, structures and indices) Opening and closing SQLite connections is very cheap, but keeping connections open is usually a better approach. You have to have a "global" setting like the path to the database file anyway; so you can wrap a "global" connection object in a factory function just as well. In database applications that use the raw DB-APi i usually start with something like: def get_con(): # return database connection ... HTH -- Gerhard From cmpython at gmail.com Thu Sep 9 18:17:30 2010 From: cmpython at gmail.com (CM) Date: Thu, 9 Sep 2010 15:17:30 -0700 (PDT) Subject: are there pros or contras, keeping a connection to a (sqlite) database ? References: <4c889dce$0$4622$426a34cc@news.free.fr> Message-ID: <5870be5c-8c72-48c1-8af5-411c9fbb42e8@w4g2000vbh.googlegroups.com> On Sep 9, 4:41?am, News123 wrote: > On 09/09/2010 12:29 AM, CM wrote: > > > On Sep 8, 1:09 pm, Stef Mientki wrote: > >> ?hello, > > >> I wrap my database in some class, and on creation of the instance, a connection to the database is > >> created, > >> and will stay connected until the program exists, something like this: > > >> ? ? self.conn = sqlite3.connect ( self.filename ) > > >> Now I wonder if there are pros or contras to keep the connection to the database continuously ?"open" ? > > >> thanks, > >> Stef Mientki > > > I do the same thing--good to hear from John that keeping it open is > > OK. > > > But another question that this provokes, at least for me is: ?what > > happens when you call .connect() on the same database multiple times > > from within different parts of the same app? ?Is that bad? ?And is it > > that there now multiple connections to the database, or one connection > > that has multiple names in different namespaces within the app? > > CM, > > Do you talk about a multithreaded environment? > or only about an environment with logically separate blocks (or with > generators), > and multiple objects each keeping their own connection. More the latter. My calls to make a connection to the database are from within different classes that serve different aspects of the GUI. I have something like an anti-MVC pattern here, like ravioli code, where each GUI element gets what it needs from the database. They are all running in the main GUI thread. There is also, though, a wxPython timer (wxTimer) that will occasionally initiate a read or write to the database, though it will already have an open connection. Why? How would this matter? > As far as I know sqlite can be compiled to be thread safe, but is not > necessarily be default. > No idea about the library used b python. I haven't dealt with the issue of thread safety before, haven't thought about it really. > I personally just started sqlite in one of my apps with multithrading > and in order to be safe I went for the conservative approach > connect, perform transactions, commit and close. > However this is probably overkill and later in time I might also ty to > keep connections open in order to increse performance. So far the "many calls to .connect() approach" has not seemed problematic for my app. But I have nothing to compare it to. Che From thomas at jollybox.de Thu Sep 9 18:19:51 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 10 Sep 2010 00:19:51 +0200 Subject: Why does linecache avoid ? How can I get equivalent of inspect.getsource() for an interactive session? In-Reply-To: References: Message-ID: <201009100019.52461.thomas@jollybox.de> On Thursday 09 September 2010, it occurred to Mark Hirota to exclaim: > Here's my goal: > > To enable a function for interactive session use that, when invoked, > will "put" source code for a specified object into a plaintext file. > Based on some initial research, this seems similar to ipython's %save > magic command (?) > > Example: > > def put(filename, object): > f = open(filename, "w") > f.write(inspect.getsource(object)) > f.close() > > Of course, in an interactive session, if you define a function: > >>> def addit(a,b): return a+b > > And then try to run inspect.getsource() on it, you'll get an exception: > >>> inspect.getsource(addit) What inspect.getsource is is simply this: It finds out which module the object belongs to, checks the __file__ of that module, opens it (or the corresponsing .py file), and finds the right bit. This won't work for extension modules as they have no Python source, and it won't work for objects created on the interactive console or using exec, or eval, as they have no source file. > > Traceback (most recent call last): > File "", line 1, in > File "C:\Python26\lib\inspect.py", line 689, in getsource > lines, lnum = getsourcelines(object) > File "C:\Python26\lib\inspect.py", line 678, in getsourcelines > lines, lnum = findsource(object) > File "C:\Python26\lib\inspect.py", line 526, in findsource > raise IOError('could not get source code') > IOError: could not get source code > > This appears to be due to the fact that the linecache standard library > module doesn't include (?) > > Can anyone help shed some light on why this is -- and perhaps provide > feedback on whether this goal is feasible? > > Thanks! From nagle at animats.com Thu Sep 9 18:21:35 2010 From: nagle at animats.com (John Nagle) Date: Thu, 09 Sep 2010 15:21:35 -0700 Subject: Queue cleanup In-Reply-To: <7xfwxj67bj.fsf@ruckus.brouhaha.com> References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x4oeftuk4.fsf@ruckus.brouhaha.com> <7xr5hg3a7s.fsf@ruckus.brouhaha.com> <7xvd6sv0n4.fsf@ruckus.brouhaha.com> <7xeid9gtuq.fsf@ruckus.brouhaha.com> <7xfwxj67bj.fsf@ruckus.brouhaha.com> Message-ID: <4c895deb$0$1638$742ec2ed@news.sonic.net> On 9/8/2010 6:20 PM, Paul Rubin wrote: > What tricks on tricks? Even the fanciest GC's are orders of magnitude > less complicated than any serious database, optimizing compiler, OS > kernel, file system, etc. Real-world software is complicated. Get used > to that fact, and look for ways to manage the complexity and keep > complex programs safe. Choosing to program with unsafe methods because > you wish the complexity didn't exist is just deluded. Garbage collectors are difficult from a theoretical standpoint, and it's very difficult to make a correct concurrent garbage collector without using formal methods. But garbage collectors are not large pieces of code. John Nagle From alain at dpt-info.u-strasbg.fr Thu Sep 9 18:22:46 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 10 Sep 2010 00:22:46 +0200 Subject: analysis of algoritms References: Message-ID: <8762yea761.fsf@dpt-info.u-strasbg.fr> Baba writes: > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1 get a positive integer from input > 2 if n > 10 > 3 print "This might take a while..." > 4 for i = 1 to n > 5 for j = 1 to i > 6 print i * j > 7 print "Done!" > > Why does step 4 execute n+1 times? what is the exta step mentioned > above In "the outer loop test [...]", the important word is _test_. Line 4 has to test the value of i against n, which results in true n times and in false once (where it jumps to instruction 7). Note that this would be true even with python loops using range(n) or xrange(n), where the test is not an integer comparison. (Note also how this last remark tries to avoid complete off-topic-ness of this discussion in this group :-) -- Alain. From ethan at stoneleaf.us Thu Sep 9 18:24:20 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Sep 2010 15:24:20 -0700 Subject: Difference between queues and pipes in multiprocessing In-Reply-To: References: <5E121D65-6150-4CC6-A35D-7834A81131AC@gmail.com> Message-ID: <4C895E94.804@stoneleaf.us> Nobody wrote: > On Thu, 09 Sep 2010 12:23:17 -0700, Ethan Furman wrote: > >>> basically a Queue is a syncronization primitive used to >>> share and pass data to and from parent/child processes. >>> >>> A pipe is as the name suggests, a socket pair connected >>> end-to-end allowing for full-duplex communications. >>> >> Isn't a pipe's communications one-way, requiring two of them to achieve >> full-duplex? > > He's talking about multiprocessing.Pipe(), not a Unix pipe. > > On Unix, multiprocessing.Pipe() uses a socket pair if duplex==True and a > pipe if duplex==False. On Windows it uses a named pipe (which can be > either unidirectional or bidirectional). > Ah. I was confusing it with os.pipe(). Many thanks. ~Ethan~ From davea at ieee.org Thu Sep 9 18:26:52 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 09 Sep 2010 18:26:52 -0400 Subject: analysis of algoritms In-Reply-To: References: Message-ID: <4C895F2C.9020203@ieee.org> On 2:59 PM, Baba wrote: > Hi > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > times (note that an extra step is required to terminate the for loop, > hence n + 1 and not n executions), which will consume T4( n + 1 ) > time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) > > 1 get a positive integer from input > 2 if n> 10 > 3 print "This might take a while..." > 4 for i = 1 to n > 5 for j = 1 to i > 6 print i * j > 7 print "Done!" > > Why does step 4 execute n+1 times? what is the exta step mentioned > above > > tnx > Baba > Why are you posting a question about BASIC syntax in a Python forum? Python has no such statement, and its close approximations work much differently. If you really want an abstract answer, then you should be decomposing those BASIC statements into smaller atoms. The for statement is composed of at least three "atoms", one of which is probably executed n+1 times. A BASIC for statement for i=1 to n decomposes into approximately: 4a, i = 1 4b compare i to n 4c skip if greater 5, 6 do some stuff 4d increment i Note that the increment happens after steps 5 and 6, but it's part of line 4 Also note that the exact details depend thoroughly on the brand and version of BASIC, there being at least 60 versions out there. For example, I can think of at least three cases for what i will equal on line 7. Incidentally, in some versions of BASIC, 4b and 4c might come after 4d, and only be executed n times. DaveA From alain at dpt-info.u-strasbg.fr Thu Sep 9 18:29:27 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 10 Sep 2010 00:29:27 +0200 Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> Message-ID: <871v92a6uw.fsf@dpt-info.u-strasbg.fr> cerr writes: > I'm calling a python script from a php script which again calls a perl > script with subprocess.popen(). > This seems to work fine so far only that once the python script > completed it is becoming a zombie because the perl script in the > background is still running... so before i exit the python script, i > would need to kill my perl subprocess. > How can i do so? x.terminate() (and then x.wait()) where x is the value returned by subprocess.Popen(). -- Alain. P/S: I'm not sure why the python process survives, and I think your use of "zombie" is not correct (afaik a zombie is an exited process whose parent hasn't called wait() yet) From ron.eggler at gmail.com Thu Sep 9 18:52:21 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 9 Sep 2010 15:52:21 -0700 (PDT) Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> Message-ID: <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> On Sep 9, 3:29?pm, Alain Ketterlin wrote: > cerr writes: > > I'm calling a python script from a php script which again calls a perl > > script with subprocess.popen(). > > This seems to work fine so far only that once the python script > > completed it is becoming a zombie because the perl script in the > > background is still running... so before i exit the python script, i > > would need to kill my perl subprocess. > > How can i do so? > > x.terminate() (and then x.wait()) where x is the value returned by > subprocess.Popen(). Well, this is what I have: writelog("starting GPS simulator") commandlist=[GPSsim,proto,GPSfile] writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) process=subprocess.Popen(commandlist) writelog("GPS simulator started") ... ... os.kill(process.pid,9) os.wait() but this is not working for me... :( any clues? > P/S: I'm not sure why the python process survives, and I think your use > of "zombie" is not correct (afaik a zombie is an exited process whose > parent hasn't called wait() yet) This is what I have: localhost cgi-bin # ps ax | grep py 11853 ? Z 0:00 [python2.6] 12029 pts/1 S+ 0:00 grep --colour=auto py The 'Z' you see there stands for Zombie From python at mrabarnett.plus.com Thu Sep 9 19:18:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Sep 2010 00:18:24 +0100 Subject: how to kill a subprocess In-Reply-To: <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> Message-ID: <4C896B40.9040807@mrabarnett.plus.com> On 09/09/2010 23:52, cerr wrote: > On Sep 9, 3:29 pm, Alain Ketterlin > wrote: >> cerr writes: >>> I'm calling a python script from a php script which again calls a perl >>> script with subprocess.popen(). >>> This seems to work fine so far only that once the python script >>> completed it is becoming a zombie because the perl script in the >>> background is still running... so before i exit the python script, i >>> would need to kill my perl subprocess. >>> How can i do so? >> >> x.terminate() (and then x.wait()) where x is the value returned by >> subprocess.Popen(). > Well, this is what I have: > > writelog("starting GPS simulator") > commandlist=[GPSsim,proto,GPSfile] > writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) > process=subprocess.Popen(commandlist) > writelog("GPS simulator started") > ... > ... > os.kill(process.pid,9) > os.wait() > > but this is not working for me... :( any clues? > >> P/S: I'm not sure why the python process survives, and I think your use >> of "zombie" is not correct (afaik a zombie is an exited process whose >> parent hasn't called wait() yet) > > This is what I have: > > localhost cgi-bin # ps ax | grep py > 11853 ? Z 0:00 [python2.6] > 12029 pts/1 S+ 0:00 grep --colour=auto py > > The 'Z' you see there stands for Zombie > How about: process.kill() # New in Python 2.6 or: os.kill(process.pid, 9) then: process.wait() or: os.waitpid(process.pid, 0) From jaksonaquino at gmail.com Thu Sep 9 19:24:30 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Thu, 9 Sep 2010 20:24:30 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP wrote: > Hi! > > Example for send ^V ?(with PyWin32): > > ?import time,win32api,win32con > ?win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) > ?win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) > ?time.sleep(0.05) > ?win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) > ?win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) Thank you very much! Your code solved my problem. I added some lines to set the focus into R before the ^V and then back to Vim: import time,win32api,win32con,win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.AppActivate("R Console") win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) time.sleep(0.05) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) shell.AppActivate("Vim") Best regards, Jakson Aquino From wbrehaut at mcsnet.ca Thu Sep 9 19:27:37 2010 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Thu, 09 Sep 2010 17:27:37 -0600 Subject: analysis of algoritms References: Message-ID: On Thu, 09 Sep 2010 18:26:52 -0400, Dave Angel wrote: > On 2:59 PM, Baba wrote: >> Hi >> >> In below code "the outer loop test in step 4 will execute ( n + 1 ) >> times (note that an extra step is required to terminate the for loop, >> hence n + 1 and not n executions), which will consume T4( n + 1 ) >> time." (from http://en.wikipedia.org/wiki/Analysis_of_algorithms) >> >> 1 get a positive integer from input >> 2 if n> 10 >> 3 print "This might take a while..." >> 4 for i = 1 to n >> 5 for j = 1 to i >> 6 print i * j >> 7 print "Done!" >> >> Why does step 4 execute n+1 times? what is the exta step mentioned >> above >> >> tnx >> Baba >> >Why are you posting a question about BASIC syntax in a Python forum? >Python has no such statement, and its close approximations work much >differently. > >If you really want an abstract answer, then you should be decomposing >those BASIC statements into smaller atoms. The for statement is >composed of at least three "atoms", one of which is probably executed >n+1 times. > >A BASIC for statement for i=1 to n >decomposes into approximately: > >4a, i = 1 >4b compare i to n >4c skip if greater > 5, 6 do some stuff >4d increment i REM And the vuitally important: 4e GOTO 4b But, as Robert noted, this is undoubtedly "pseudocode" rather than BASIC. Pity it's not Python-oriented pseudocode... >Note that the increment happens after steps 5 and 6, but it's part of line 4 > >Also note that the exact details depend thoroughly on the brand and >version of BASIC, there being at least 60 versions out there. For >example, I can think of at least three cases for what i will equal on >line 7. > >Incidentally, in some versions of BASIC, 4b and 4c might come after 4d, >and only be executed n times. > >DaveA From magawake at gmail.com Thu Sep 9 20:05:22 2010 From: magawake at gmail.com (Mag Gam) Date: Thu, 9 Sep 2010 20:05:22 -0400 Subject: reading multiple files Message-ID: I have 3 files which are constantly being updated therefore I use tail -f /var/log/file1, tail -f /var/log/file2, and tail -f /var/log/file3 For 1 file I am able to manage by tail -f /var/log/file1 | python prog.py prog.py looks like this: f=sys.stdin for line in f: print line But how can I get data from /var/log/file2 and /var/log/file3 ? I prefer a native python way instead of doing tail -f TIA From alain at dpt-info.u-strasbg.fr Thu Sep 9 20:31:25 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 10 Sep 2010 02:31:25 +0200 Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> Message-ID: <87wrqu8mn6.fsf@dpt-info.u-strasbg.fr> cerr writes: >> x.terminate() (and then x.wait()) where x is the value returned by >> subprocess.Popen(). > Well, this is what I have: > > writelog("starting GPS simulator") > commandlist=[GPSsim,proto,GPSfile] > writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) > process=subprocess.Popen(commandlist) > writelog("GPS simulator started") > ... > ... > os.kill(process.pid,9) > os.wait() > > but this is not working for me... :( any clues? Should be ok. A minor point: os.kill(...) and os.wait() have equivalent (portable) convenience methods on Popen. Also, it may be better to send SIGTERM (15) instead of SIGKILL, to ensure the victim can die gracefully (e.g., remove temp files). >> P/S: I'm not sure why the python process survives, and I think your use >> of "zombie" is not correct (afaik a zombie is an exited process whose >> parent hasn't called wait() yet) > > This is what I have: > > localhost cgi-bin # ps ax | grep py > 11853 ? Z 0:00 [python2.6] > 12029 pts/1 S+ 0:00 grep --colour=auto py > > The 'Z' you see there stands for Zombie This is from "man ps": Processes marked are dead processes (so-called "zombies") that remain because their parent has not destroyed them properly. These processes will be destroyed by init(8) if the parent process exits. So the problem is with what launches this python process (11853). If this process is the python interpreter running the program above, check how you launch it. If this process is something else, check its parent process. -- Alain. From cpblpublic at gmail.com Thu Sep 9 20:36:34 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Thu, 9 Sep 2010 17:36:34 -0700 (PDT) Subject: weighted mean; weighted standard error of the mean (sem) Message-ID: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> I am looking for some reaally basic statistical tools. I have some sample data, some sample weights for those measurements, and I want to calculate a mean and a standard error of the mean. Here are obvious places to look: numpy scipy.stats statsmodels It seems to me that numpy's "mean" and "average" functions have their names backwards. That is, often a mean is defined more generally than average, and includes the possibility of weighting, but in this case it is "average" that has a weights argument. Can these functions be merged/renamed/deprecated in the future? It's clear to me that "mean" should allow for weights. None of these modules, above, offer standard error of the mean which incorporates weights. numpy's "sem" doesn't, and that's the closest thing. numpy's "var" doesn't allow weights. There aren't any weighted variances in the above modules. Again, are there favoured codes for these functions? Can they be incorporated appropriately in the future? Most immediately, I'd love to get code for weighted sem. I'll write it otherwise, but if I do I'd love to know whom to bug to get it incorporated into numpy.sem ... Thanks! None of them have this basic function. Has anyone written one? From bartc at freeuk.com Thu Sep 9 21:06:51 2010 From: bartc at freeuk.com (BartC) Date: Fri, 10 Sep 2010 02:06:51 +0100 Subject: Speed-up for loops In-Reply-To: References: <4C7F7640.1010102@perfect-kreim.de> Message-ID: <%xfio.95946$c_6.89631@newsfe30.ams2> "Stefan Behnel" wrote in message news:mailman.563.1283921317.29448.python-list at python.org... > BartC, 08.09.2010 03:45: >> Getting back to the OP's code again (trivial and pointless as it might >> seem), I got these results: >> >> C (gcc 3.4.5 -O3) 0.8 secs >> C (DMC-o) 2.3 secs >> C (lccwin32 -O) 2.9 secs > BTW, I wonder why the code takes a whole 0.8 seconds to run in your gcc > test. Maybe you should use a newer GCC version. It shouldn't take more > than a couple of milliseconds (for program startup, OS calls, etc.), given > that the output is a constant. It turns out the 0.8 second version cheats. It counts to a billion, but does not do the work asked (a=a+10). The fastest time that will do what it is requested, is about 1.2 seconds, when register-based, and about 3 seconds when memory-based. This reduces the slowdown on Python 3 from 220x to 150x, and down to 60x when register-versions are not counted (as use of registers can't be guaranteed). (Python 2 was about 20% faster.) -- Bartc From alain at dpt-info.u-strasbg.fr Thu Sep 9 21:19:39 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 10 Sep 2010 03:19:39 +0200 Subject: reading multiple files References: Message-ID: <87sk1i8kes.fsf@dpt-info.u-strasbg.fr> Mag Gam writes: > I have 3 files which are constantly being updated therefore I use tail > -f /var/log/file1, tail -f /var/log/file2, and tail -f /var/log/file3 > > For 1 file I am able to manage by > tail -f /var/log/file1 | python prog.py > > prog.py looks like this: > f=sys.stdin > for line in f: > print line > > But how can I get data from /var/log/file2 and /var/log/file3 ? Use shell tricks, e.g., with bash: yourpythonprog <(tail -f .../file1) <(tail -f .../file2) <(...) and let your prog open its three parameters like regular files (they are fifos actually). If your shell doesn't support <(...), create the fifos and redirect tail output before launching your prog. If you want "purer" python, launch the three "tail -f" with subprocess, and use the select module to get input (you didn't explain the logic you will follow to track three files---you may not need select if you expect one line from each file before waiting for the next line of any). > I prefer a native python way instead of doing tail -f Emulating tail will require a lot of stat/seeks, and finding lines will require an additional level of complexity. Also, tail -f has a cost [*]. The only way to avoid it is to use inotify, which seems to have a python interface, available at http://pyinotify.sourceforge.net/ (I've never used it). Again, emulating tail -f with inotify is significant work. -- Alain. [*] Paul Rubin is one of the authors, I think he reads this group. From tim.leslie at gmail.com Thu Sep 9 21:27:07 2010 From: tim.leslie at gmail.com (Tim Leslie) Date: Fri, 10 Sep 2010 11:27:07 +1000 Subject: weighted mean; weighted standard error of the mean (sem) In-Reply-To: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> References: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> Message-ID: On 10 September 2010 10:36, C Barrington-Leigh wrote: > > Most immediately, I'd love to get code for weighted sem. I'll write it > otherwise, but if I do I'd love to know whom to bug to get it > incorporated into numpy.sem ... The best place to ask about numpy related stuff is the numpy mailing list at: http://mail.scipy.org/mailman/listinfo/numpy-discussion This is also the best place to present a patch if you have code to contribute. In my experience the numpy devs are always happy to have new contributors, but be sure to discuss the problem first, as the folk over there might be able to provide a solution which doesn't require a new patch. Cheers, Tim > > Thanks! > > None of them have this basic function. Has anyone written one? > -- > http://mail.python.org/mailman/listinfo/python-list > From python at rcn.com Thu Sep 9 21:37:49 2010 From: python at rcn.com (Raymond Hettinger) Date: Thu, 9 Sep 2010 18:37:49 -0700 (PDT) Subject: How Python works: What do you know about support for negative indices? Message-ID: Hello Folks. It doesn't seem to be common knowledge when and how a[x] gets translated to a[x+len(x)]. So, here's a short info post on how Python supports negative indices for sequences. I've put the answer below, but if you want to quickly test your own knowledge, ask yourself which of these support negative indices: 'abcde'[-2] # builtin string class, bracket syntax 'abcde'.__getitem__(-2) # builtin class, magic method collections.deque('abcde')[-2] # extension class, bracket syntax collections.deque('abcde').__getitem__[-2] # extension class, magic method class S(str): pass class T(str): def __getitem__(self, i): print(i) return 'd' class U(str): def __getitem__(self, i): print(i) return 'd' def __len__(self): return 5 class V(str): 'str subclass overriding key methods' def __getitem__(self, i): print(i) return 'd' def __len__(self): return 5 def __iter__(self): return iter('abcde') def __contains__(self, val): return val in 'abcde' class W: 'object subclass registered as Sequence' def __init__(self, data): self.data = data def __getitem__(self, i): print(i) return 'd' def __len__(self): return 5 def __iter__(self): return iter('abcde') def __contains__(self, val): return val in 'abcde' collections.Sequence.register(V) class X(collections.Sequence): 'Subclass the Sequence abstract base class' def __init__(self, data): self.data = data def __getitem__(self, i): print(i) return 'd' def __len__(self): return 5 def __iter__(self): return iter('abcde') def __contains__(self, val): return val in 'abcde' Essentially, the example raise these questions: * Are negative indices tied to the grammar (i.e. binary subscription)? * Does it matter if you call a magic method instead of using brackets? * Are they tied to particular concrete classes (str, list, tuple, deque, dict)? * If so, how does subclassing affect index handling? * What parts of user defined classes affect handling of indices? * Are they part of the abstract layer (PyObject_GetItem)? * Are they tied to the Sequence ABC? * How are mapping lookups differentiated (d[-2] where d is a Mapping)? ------------- Answers below -------------- | | | | | | | | | | | | | | | | The first five examples support negative indices. The builtin sequence types: str, deque, list and tuple, all have negative index support built in to their concrete implementations (such as str.__getitem__) and that behavior persists for subclassers as long as they don't override __getitem__. The parse of "a['x']" matches the "subscription" rule in Grammar/ Grammar. That compiles the BINARY_SUBSCR opcode which pops off the evaluated expressions for "a" and "x" and calls the abstract layer, PyObject_GetItem() which routes most calls to the concrete implementation (i.e. myobj.__getitem__). The exception to concrete dispatch is a fast path for builtin classes or their subclasses that 1) are recognized as sequences (i.e. not a dictionary and have not overridden __getitem__) 2) where "x" is an index (i.e. not a float) If so, it is passed to an intermediate abstract layer, PySequence_SetItem() which will apply negative index handling iff the sequence defines a __len__ method. In other words, the handling of negative indices is always up to the concrete class. It is not part of the grammar, or the definition of subscriptions, or the dispatch sequence. The docs guarantee that Python's builtin sequences implement support for negative indices ( http://docs.python.org/dev/reference/expressions.html#subscriptions ) and they all do so through their individual __getitem__ implementations. Builtin Python sequences also have a fast path that make negative index handling automatic, but this is just an invisible optimization and can be bypassed by calling myobj.__getitem__ directly. Note on slicing: slices are handled the same way (at least in 3.x), so it is the responsibility of concrete classes to add support if they choose to do so. Some, like lists tuples and string do support slicing and some objects like deque do not. Interestingly, the grammar has rules for slicing, but that is implemented as making a slice instance as the argument to the lookup. The actual lookup work is dispatched to the concrete class and there is no fast path along the way. Hope you all found this to be informative, Raymond From cpblpublic at gmail.com Thu Sep 9 21:43:47 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Thu, 9 Sep 2010 18:43:47 -0700 (PDT) Subject: weighted mean; weighted standard error of the mean (sem) References: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> Message-ID: <88998386-68b7-41bc-9d89-0a33ca1195e1@w15g2000pro.googlegroups.com> > The best place to ask about numpy related stuff is the numpy mailing list at: > > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > This is also the best place to present a patch if you have code to > contribute. In my experience the numpy devs are always happy to have > new contributors, but be sure to discuss the problem first, as the > folk over there might be able to provide a solution which doesn't > require a new patch. Thanks, Tim, Ooops -- the sem() I mentioned is sciypy.stats.sem, not in numpy... Does your advice hold? Thanks, c From tim.leslie at gmail.com Thu Sep 9 22:03:06 2010 From: tim.leslie at gmail.com (Tim Leslie) Date: Fri, 10 Sep 2010 12:03:06 +1000 Subject: weighted mean; weighted standard error of the mean (sem) In-Reply-To: <88998386-68b7-41bc-9d89-0a33ca1195e1@w15g2000pro.googlegroups.com> References: <0af4ce27-7df7-47ee-afd4-ad26c0a60941@y12g2000prb.googlegroups.com> <88998386-68b7-41bc-9d89-0a33ca1195e1@w15g2000pro.googlegroups.com> Message-ID: On 10 September 2010 11:43, C Barrington-Leigh wrote: > >> The best place to ask about numpy related stuff is the numpy mailing list at: >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> This is also the best place to present a patch if you have code to >> contribute. In my experience the numpy devs are always happy to have >> new contributors, but be sure to discuss the problem first, as the >> folk over there might be able to provide a solution which doesn't >> require a new patch. > > > Thanks, Tim, > > Ooops -- the sem() I mentioned is ?sciypy.stats.sem, not in numpy... > Does your advice hold? > Thanks, For discussion out that function you probably want the scipy-user mailing list. For completeness, here's the full list of related mailing lists: http://www.scipy.org/Mailing_Lists Cheers, Tim > c > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Thu Sep 9 22:05:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 10 Sep 2010 12:05:49 +1000 Subject: Printing the name of a variable References: Message-ID: <878w3a9wua.fsf@benfinney.id.au> Albert Hopkins writes: > On Thu, 2010-09-09 at 12:43 -0700, Stephen Boulet wrote: > > Does an arbitrary variable carry an attribute describing the text in > > its name? > > Variables are not objects and so they have no attributes. Another way of thinking about is that there are no variables, only bindings between references and objects. The bindings are not directly accessible and have no attributes. Any object may have zero, one, or many references to it at any given time. Those references might be names, or something else (such as an index in a container). Python does nothing to make the references accessible to the object. If you want to keep track of such associations, you need to employ some mechanism to do so explicitly. > You can't really de-reference the object being referenced as it can > potentially contain multiple references Including the case where an object has no explicit references beyond the current expression. > But this cries the question: why do you want to do this? And usually > that question is asked when someone thinks that a: you shouldn't need > to do this and b: whatever the desired effect there is probably a > better way of accomplishing it. To anticipate a common case: if you feel you need to maintain a mapping between names and objects, Python's built-in mapping type is ?dict?; use that. -- \ ?If you do not trust the source do not use this program.? | `\ ?Microsoft Vista security dialogue | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Sep 9 22:21:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 10 Sep 2010 12:21:40 +1000 Subject: How Python works: What do you know about support for negative indices? References: Message-ID: <874ody9w3v.fsf@benfinney.id.au> Raymond Hettinger writes: > It doesn't seem to be common knowledge when and how a[x] gets > translated to a[x+len(x)]. So, here's a short info post on how Python > supports negative indices for sequences. Thanks for this. Could you post your messages using a channel that doesn't arbitrarily split your paragraphs into long-short-long-short lines? It makes paragraphs burdensome to read, and I skipped most of the message because of that. I encourage anyone whose messages are munged like that to seek correction from their mail service provider, and switch to a different one until it's fixed. -- \ ?Oh, I realize it's a penny here and a penny there, but look at | `\ me: I've worked myself up from nothing to a state of extreme | _o__) poverty.? ?Groucho Marx | Ben Finney From magawake at gmail.com Thu Sep 9 22:35:06 2010 From: magawake at gmail.com (Mag Gam) Date: Thu, 9 Sep 2010 22:35:06 -0400 Subject: reading multiple files In-Reply-To: <87sk1i8kes.fsf@dpt-info.u-strasbg.fr> References: <87sk1i8kes.fsf@dpt-info.u-strasbg.fr> Message-ID: Thanks for your response. I was going by this thread, http://mail.python.org/pipermail/tutor/2009-January/066101.html makes you wonder even if its possible. I will try your first solution by doing mkfifo on the files. On Thu, Sep 9, 2010 at 9:19 PM, Alain Ketterlin wrote: > Mag Gam writes: > >> I have 3 files which are constantly being updated therefore I use tail >> -f /var/log/file1, tail -f /var/log/file2, and tail -f /var/log/file3 >> >> For 1 file I am able to manage by >> tail -f /var/log/file1 | python prog.py >> >> prog.py looks like this: >> f=sys.stdin >> for line in f: >> ? print line >> >> But how can I get data from /var/log/file2 and /var/log/file3 ? > > Use shell tricks, e.g., with bash: > > yourpythonprog <(tail -f .../file1) <(tail -f .../file2) <(...) > > and let your prog open its three parameters like regular files (they are > fifos actually). If your shell doesn't support <(...), create the fifos > and redirect tail output before launching your prog. > > If you want "purer" python, launch the three "tail -f" with subprocess, > and use the select module to get input (you didn't explain the logic you > will follow to track three files---you may not need select if you expect > one line from each file before waiting for the next line of any). > >> I prefer a native python way instead of doing tail -f > > Emulating tail will require a lot of stat/seeks, and finding lines will > require an additional level of complexity. > > Also, tail -f has a cost [*]. The only way to avoid it is to use > inotify, which seems to have a python interface, available at > http://pyinotify.sourceforge.net/ (I've never used it). Again, emulating > tail -f with inotify is significant work. > > -- Alain. > > [*] Paul Rubin is one of the authors, I think he reads this group. > -- > http://mail.python.org/mailman/listinfo/python-list > From mwilson at the-wire.com Thu Sep 9 23:10:54 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 09 Sep 2010 23:10:54 -0400 Subject: Printing the name of a variable References: Message-ID: Stephen Boulet wrote: > Does an arbitrary variable carry an attribute describing the text in > its name? I'm looking for something along the lines of: > > x = 10 > print x.name >>>> 'x' > > Perhaps the x.__getattribute__ method? Thanks. Hmm. "Recent scholarship suggests that the Iliad and the Odyssey may not have been written by Homer, but by someone else with the same name." Mel. From metolone+gmane at gmail.com Fri Sep 10 01:37:14 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 9 Sep 2010 22:37:14 -0700 Subject: How Python works: What do you know about support for negativeindices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: "Ben Finney" wrote in message news:874ody9w3v.fsf at benfinney.id.au... > Raymond Hettinger writes: > >> It doesn't seem to be common knowledge when and how a[x] gets >> translated to a[x+len(x)]. So, here's a short info post on how Python >> supports negative indices for sequences. > > Thanks for this. Could you post your messages using a channel that > doesn't arbitrarily split your paragraphs into long-short-long-short > lines? It makes paragraphs burdensome to read, and I skipped most of the > message because of that. > > I encourage anyone whose messages are munged like that to seek > correction from their mail service provider, and switch to a different > one until it's fixed. > > -- > \ ?Oh, I realize it's a penny here and a penny there, but look at | > `\ me: I've worked myself up from nothing to a state of extreme | > _o__) poverty.? ?Groucho Marx | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list It came across fine for me (on much maligned Outlook Express, no less). -Mark From nhodgson at bigpond.net.au Fri Sep 10 02:27:02 2010 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 10 Sep 2010 16:27:02 +1000 Subject: How Python works: What do you know about support for negativeindices? In-Reply-To: References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: <4dkio.6129$FH2.3731@viwinnwfe02.internal.bigpond.com> Mark Tolonen: > It came across fine for me (on much maligned Outlook Express, no less). Yes, looks fine to me both in Thunderbird (news, not mailing list) and at Google Groups. There is a single text part with all lines except an URL easily within 80 columns. Perhaps there is a problem in Ben's reader or in the mailing list gateway. Neil From skippy.hammond at gmail.com Fri Sep 10 03:09:27 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 10 Sep 2010 17:09:27 +1000 Subject: 32 bit bdist_wininst vs x64 platform In-Reply-To: <4C88C4E8.6080003@chamonix.reportlab.co.uk> References: <4C88C4E8.6080003@chamonix.reportlab.co.uk> Message-ID: <4C89D9A7.9070403@gmail.com> Hi Robin, On 9/09/2010 9:28 PM, Robin Becker wrote: > A reportlab user is using 32 bit python on x64 win 2003. he has a > problem installing our bdist_wininst exe because the installer cannot > find python. That should work fine - lots of pywin32 users do exactly that. > Apparently the installer is looking at HKLM\Software to locate python, > but on x64 32 bit program requests get redirected to > HKLM\Software\Wow6432Node (Extended explanation in KB article 896459). > > Is this fixable by me making a local patch to my distutils to check for > the real platform and modifying the RegOpenKeyEx call? Or is there some > distutils magic that I'm missing? As you mention, 32bit apps querying the registry get redirected in some cases - but so long as the 32bit bdist_wininst stub is used, that too will get redirected, so it should all work out fine. Is it possible they are attempting to install an x64 version of reportlab on a 32bit python? Mark From paul.nospam at rudin.co.uk Fri Sep 10 03:13:33 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 10 Sep 2010 08:13:33 +0100 Subject: Printing the name of a variable References: Message-ID: <87eid2xe8y.fsf@rudin.co.uk> Stephen Boulet writes: > Does an arbitrary variable carry an attribute describing the text in > its name? I'm looking for something along the lines of: > > x = 10 > print x.name >>>> 'x' > > Perhaps the x.__getattribute__ method? Thanks. The first thing is... what is your use case for this? I'd guess that you probably don't want to do this even if you think you do :) The thing referred to by x is the number 10. When you write x.name (or property) then you're dealing with the number 10, not with some representation of the variable x. There may be many variables (or none) that refer to that number at any given time during the execution of your code... and the object itself "knows" nothing about any of these. A good way to think about variable lookup is as a dictionary . It's something like "variables['x'].name". Once the "varables['x'] bit has been evaluated the link with 'x' is gone... we just have the result of the lookup. If you want to know how it actually works, then read up on python namespaces and scopes, e.g. here: . From eckhardt at satorlaser.com Fri Sep 10 03:36:08 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 10 Sep 2010 09:36:08 +0200 Subject: How Python works: What do you know about support for negative indices? References: Message-ID: <8o3pl7-8ch.ln1@satorlaser.homedns.org> Raymond Hettinger wrote: > collections.deque('abcde').__getitem__[-2] # extension class, magic > method Small nit: You don't mean [square] brackets here, right? Otherwise, good posting, thank you! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From bussiere at gmail.com Fri Sep 10 03:40:42 2010 From: bussiere at gmail.com (bussiere bussiere) Date: Fri, 10 Sep 2010 09:40:42 +0200 Subject: inspect the call stack Message-ID: i v'e got this : i've got toto.py : import titi def niwhom(): pass and titi.py : def nipang(): pass how can i know in titi.py that's it's toto.py that is calling titi.py and the path of toto ? how can i inspect the call stack or an other way ? Regards Bussiere Google Fan boy From robin at reportlab.com Fri Sep 10 04:52:57 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 10 Sep 2010 09:52:57 +0100 Subject: 32 bit bdist_wininst vs x64 platform In-Reply-To: <4C89D9A7.9070403@gmail.com> References: <4C88C4E8.6080003@chamonix.reportlab.co.uk> <4C89D9A7.9070403@gmail.com> Message-ID: <4C89F1E9.1060308@chamonix.reportlab.co.uk> .......... > > As you mention, 32bit apps querying the registry get redirected in some cases - > but so long as the 32bit bdist_wininst stub is used, that too will get > redirected, so it should all work out fine. Is it possible they are attempting > to install an x64 version of reportlab on a 32bit python? .......... I'm a bit puzzled about this as well, they mentioned something about the python being embedded so perhaps that's the problem. I am trying to ascertain the exact context. -- Robin Becker From ldo at geek-central.gen.new_zealand Fri Sep 10 05:26:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 10 Sep 2010 21:26:26 +1200 Subject: SendKeys and Python 2.7 References: Message-ID: In message , Jakson A. Aquino wrote: > I would like to send code from Vim [1] to R [2] on Microsoft Windows. Why such a roundabout way? Why not just run R in a subprocess and feed it a script to run? > [1] http://www.vim.org/ > [2] http://www.r-project.org/ From ldo at geek-central.gen.new_zealand Fri Sep 10 05:27:56 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 10 Sep 2010 21:27:56 +1200 Subject: [Tutor] Arguments from the command line References: <8662yfklzu.fsf@aiuole.stru.polimi.it> Message-ID: In message <8662yfklzu.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: > Dennis Lee Bieber writes: > >> FORTRAN just differentiates by having the main file start with >> PROGRAM random_name >> whereas subfiles are all either (or both) >> SUBROUTINE another_name(args) >> FUNCTION that_other_name(args) > > no BLOCKDATA? I think you mean COMMON. From ldo at geek-central.gen.new_zealand Fri Sep 10 05:28:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 10 Sep 2010 21:28:47 +1200 Subject: [Tutor] Arguments from the command line References: Message-ID: In message , Mel wrote: > But historical COBOL didn't pass parameters anyway. You read > your optional arguments from a file, or accepted a few from an input > device. I think it could also read from switches. As in front-panel on/off switches. From giacomo.boffi at polimi.it Fri Sep 10 05:44:32 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Fri, 10 Sep 2010 11:44:32 +0200 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: <864odyszjz.fsf@aiuole.stru.polimi.it> Ben Finney writes: > Raymond Hettinger writes: > >> It doesn't seem to be common knowledge when and how a[x] gets >> translated to a[x+len(x)]. So, here's a short info post on how Python >> supports negative indices for sequences. > > Thanks for this. Could you post your messages using a channel that > doesn't arbitrarily split your paragraphs into long-short-long-short > lines? hi Ben, i see that you uses gnus... well, it's gnus that does the unwanted formatting try C-u g, as dettailed below, ciao g runs `gnus-summary-show-article' `gnus-summary-show-article' is an interactive compiled Lisp function -- loaded from "gnus-sum" (gnus-summary-show-article &optional ARG) Documentation: Force redisplaying of the current article. If ARG (the prefix) is a number, show the article with the charset defined in `gnus-summary-show-article-charset-alist', or the charset input. If ARG (the prefix) is non-nil and not a number, show the raw article without any article massaging functions being run. Normally, the key strokes are `C-u g'. -- la lenza penzola -- PMF, in IHC From tartley at tartley.com Fri Sep 10 06:13:31 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 10 Sep 2010 03:13:31 -0700 (PDT) Subject: Printing the name of a variable References: Message-ID: <76613ad4-5d89-4f68-a075-79db0c15fa5d@y3g2000vbm.googlegroups.com> On Sep 9, 9:11?pm, Albert Hopkins wrote: > On Thu, 2010-09-09 at 12:43 -0700, Stephen Boulet wrote: > > Does an arbitrary variable carry an attribute describing the text in > > its name? I'm looking for something along the lines of: > > > x = 10 > > print x.name > > >>> 'x' > > > Perhaps the x.__getattribute__ method? Thanks. > > Variables are not objects and so they have no attributes. > > You can't really de-reference the object being referenced as it can > potentially contain multiple references, but an innacurate way of doing > this would be, e.g. > > >>> x = [1, 2, 3] > >>> y = x > >>> g = globals() > >>> varnames = [i for i in g if g[i] is x] > > ['x', 'y'] > > But this cries the question: why do you want to do this? ?And usually > that question is asked when someone thinks that a: you shouldn't need to > do this and b: whatever the desired effect there is probably a better > way of accomplishing it. I have in the past wondered about creating a kind of graphical debugger, that rendered representations of all the objects in globals and/or locals, to give you a visual representation of your variables and their states. Would this be a valid use case to try and look up the variable names which reference various in-memory objects? From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 06:14:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Sep 2010 10:14:40 GMT Subject: How Python works: What do you know about support for negative indices? References: Message-ID: <4c8a0510$0$11111$c3e8da3@news.astraweb.com> On Thu, 09 Sep 2010 18:37:49 -0700, Raymond Hettinger wrote: > Hello Folks. > > It doesn't seem to be common knowledge when and how a[x] gets translated > to a[x+len(x)]. So, here's a short info post on how Python supports > negative indices for sequences. [...] > Hope you all found this to be informative, Thanks Raymond! -- Steven From giacomo.boffi at polimi.it Fri Sep 10 06:25:17 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Fri, 10 Sep 2010 12:25:17 +0200 Subject: [Tutor] Arguments from the command line References: <8662yfklzu.fsf@aiuole.stru.polimi.it> Message-ID: <86wrqtsxo2.fsf@aiuole.stru.polimi.it> Lawrence D'Oliveiro writes: > In message <8662yfklzu.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: > >> Dennis Lee Bieber writes: >> >>> FORTRAN just differentiates by having the main file start with >>> PROGRAM random_name >>> whereas subfiles are all either (or both) >>> SUBROUTINE another_name(args) >>> FUNCTION that_other_name(args) >> >> no BLOCKDATA? > > I think you mean COMMON. i meant BLOCKDATA From simon at brunningonline.net Fri Sep 10 06:26:24 2010 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 10 Sep 2010 11:26:24 +0100 Subject: Printing the name of a variable In-Reply-To: References: Message-ID: On 9 September 2010 20:43, Stephen Boulet wrote: > Does an arbitrary variable carry an attribute describing the text in > its name? I'm looking for something along the lines of: > > x = 10 > print x.name >>>> 'x' -- Cheers, Simon B. From fetchinson at googlemail.com Fri Sep 10 06:46:18 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 10 Sep 2010 12:46:18 +0200 Subject: How Python works: What do you know about support for negative indices? In-Reply-To: <874ody9w3v.fsf@benfinney.id.au> References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: > Raymond Hettinger writes: > >> It doesn't seem to be common knowledge when and how a[x] gets >> translated to a[x+len(x)]. So, here's a short info post on how Python >> supports negative indices for sequences. > > Thanks for this. Could you post your messages using a channel that > doesn't arbitrarily split your paragraphs into long-short-long-short > lines? It came across fine for me as well (gmail with basic html interface). > It makes paragraphs burdensome to read, and I skipped most of the > message because of that. You might want to switch to a client where you do not have this problem. > I encourage anyone whose messages are munged like that to seek > correction from their mail service provider, and switch to a different > one until it's fixed. I encourage anyone who has problems with reading various emails, newsgroup postings, forums and what not, to start using modern tools that work with the vast majority of other tools. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From robin at reportlab.com Fri Sep 10 07:57:21 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 10 Sep 2010 12:57:21 +0100 Subject: 32 bit bdist_wininst vs x64 platform In-Reply-To: <4C89F1E9.1060308@chamonix.reportlab.co.uk> References: <4C88C4E8.6080003@chamonix.reportlab.co.uk> <4C89D9A7.9070403@gmail.com> <4C89F1E9.1060308@chamonix.reportlab.co.uk> Message-ID: <4C8A1D21.4040303@chamonix.reportlab.co.uk> On 10/09/2010 09:52, Robin Becker wrote: > .......... >> >> As you mention, 32bit apps querying the registry get redirected in some cases - >> but so long as the 32bit bdist_wininst stub is used, that too will get >> redirected, so it should all work out fine. Is it possible they are attempting >> to install an x64 version of reportlab on a 32bit python? > .......... > > I'm a bit puzzled about this as well, they mentioned something about the python > being embedded so perhaps that's the problem. I am trying to ascertain the exact > context. > > I found out that although the end users had installed the amd64 python they were using reportlab-2.4.win32-py2.6.exe which is 32 bit. That complained until they fixed everything up by brute force registry copying. Fortunately, I don't think the pyds are importable and reportlab is robust enough to fall back to a working state even without those. -- Robin Becker From bruno.42.desthuilliers at websiteburo.invalid Fri Sep 10 10:50:58 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 10 Sep 2010 16:50:58 +0200 Subject: include a file in a python program In-Reply-To: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> References: <4c8423d3$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c8a45b9$0$12932$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Mon, 06 Sep 2010 00:57:30 +0200, bussiere bussiere wrote: > >> i've got a python.txt that contain python and it must stay as it >> (python.txt) > > Why? Is it against the law to change it? *wink* > >> how can i include it in my program ? >> import python.txt doesn't work > > > You could write a custom importer to handle it, but I can't help you with > that. Try Google. > >> is there a way : >> a) to make an include("python.txt") >> b) tell him to treat .txt as .py file that i can make an import python ? > > fp = open("python.txt") > text = fp.read() > fp.close() > exec(text) or just: execfile("python.txt") > But keep in mind that the contents of python.txt will be executed as if > you had typed it yourself. If you don't trust the source with your life > (or at least with the contents of your computer), don't execute it. +10 From bruno.42.desthuilliers at websiteburo.invalid Fri Sep 10 10:56:17 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 10 Sep 2010 16:56:17 +0200 Subject: inspect the call stack In-Reply-To: References: Message-ID: <4c8a46f8$0$4568$426a34cc@news.free.fr> bussiere bussiere a ?crit : > i v'e got this : > i've got toto.py : > > import titi > def niwhom(): > pass > > and titi.py : > > def nipang(): > pass > > how can i know in titi.py that's it's toto.py that is calling titi.py > and the path of toto ? > > how can i inspect the call stack or an other way ? http://www.google.fr/search?q=python+inspect+the+call+stack First answer should point you to the relevant part of the FineManual(tm): http://docs.python.org/library/inspect.html And while we're at it, what about not opening a new thread for a question already partially answered ? From michael.a.powe at gmail.com Fri Sep 10 12:09:15 2010 From: michael.a.powe at gmail.com (naugiedoggie) Date: Fri, 10 Sep 2010 09:09:15 -0700 (PDT) Subject: Trap Authentication Errors in HTTP Request Message-ID: Hello, I have a script that authenticates to a web service provider to retrieve data. This script provides an authentication header built in a very basic way like this: # Creates an authentication object with the credentials for a given URL def createPasswordManager(headers) : passwordManager = urllib2.HTTPPasswordMgrWithDefaultRealm() passwordManager.add_password(None,overview_url,headers[0],headers[1]) return passwordManager # Creates an authentication handler for the authentication object created above def createAuthenticationHandler(passwordManager) : authenticationHandler = urllib2.HTTPBasicAuthHandler(passwordManager) return authenticationHandler # Creates an opener that sets the credentials in the Request def createOpener(authHandler) : return urllib2.build_opener(authHandler) This script makes multiple calls for data. I would like to trap an exception for authentication failure so that it doesn't go through its entire list of calls when there's a problem with the login. The assumption is that if there is a login failure, the script is using incorrect authentication information. I have the call for data retrieval wrapped in try/except, to catch HTTPError, but apparently no '401' is explicitly thrown when authentication fails. And I don't see an explicit Exception that is thrown in urllib2 for handling these failures. How can I achieve my goal of trapping these exceptions and exiting cleanly? Thanks. mp From jakecjacobson at gmail.com Fri Sep 10 12:20:46 2010 From: jakecjacobson at gmail.com (jakecjacobson) Date: Fri, 10 Sep 2010 09:20:46 -0700 (PDT) Subject: How to Convert IO Stream to XML Document Message-ID: I am trying to build a Python script that reads a Sitemap file and push the URLs to a Google Search Appliance. I am able to fetch the XML document and parse it with regular expressions but I want to move to using native XML tools to do this. The problem I am getting is if I use urllib.urlopen(url) I can convert the IO Stream to a XML document but if I use urllib2.urlopen and then read the response, I get the content but when I use minidom.parse() I get a "IOError: [Errno 2] No such file or directory:" error THIS WORKS but will have issues if the IO Stream is a compressed file def GetPageGuts(net, url): pageguts = urllib.urlopen(url) xmldoc = minidom.parse(pageguts) return xmldoc # THIS DOESN'T WORK, but I don't understand why def GetPageGuts(net, url): request=getRequest_obj(net, url) response = urllib2.urlopen(request) response.headers.items() pageguts = response.read() # Test to see if the response is a gzip/compressed data stream if isCompressedFile(response, url): compressedstream = StringIO.StringIO(pageguts) gzipper = gzip.GzipFile(fileobj = compressedstream) pageguts = gzipper.read() xmldoc = minidom.parse(pageguts) response.close() return xmldoc # I am getting the following error Starting SiteMap Manager ... Traceback (most recent call last): File "./tester.py", line 267, in ? main() File "./tester.py", line 49, in main fetchSiteMap(ResourceDict, line) File "./tester.py", line 65, in fetchSiteMap pageguts = GetPageGuts(ResourceDict['NET'], url) File "./tester.py", line 89, in GetPageGuts xmldoc = minidom.parse(pageguts) File "/usr/lib/python2.4/xml/dom/minidom.py", line 1915, in parse return expatbuilder.parse(file) File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 922, in parse fp = open(file, 'rb') IOError: [Errno 2] No such file or directory: '\n\n\nhttp://www.myorg.org/janes/ sitemaps/binder_sitemap.xml\n2010-09-09\n\n\nhttp://www.myorg.org/janes/sitemaps/ dir_sitemap.xml\n2010-05-05\n \n\nhttp://www.myorg.org/janes/sitemaps/ mags_sitemap.xml\n2010-09-09\n \n\nhttp://www.myorg.org/janes/sitemaps/ news_sitemap.xml\n2010-09-09\n \n\nhttp://www.myorg.org/janes/sitemaps/ sent_sitemap.xml\n2010-09-09\n \n\nhttp://www.myorg.org/janes/sitemaps/ srep_sitemap.xml\n2001-05-04\n \n\nhttp://www.myorg.org/janes/sitemaps/yb_sitemap.xml\n2010-09-09\n\n\n' # A couple of supporting things def getRequest_obj(net, url): request = urllib2.Request(url) request.add_header('User-Agent', 'ICES Sitemap Bot dni-ices- searchadmin at ugov.gov') request.add_header('Accept-encoding', 'gzip') return request def isCompressedFile(r, u): answer=False if r.headers.has_key('Content-encoding'): answer=True else: # Check to see if the URL ends in .gz if u.endswith(".gz"): answer=True return answer From fuglyducky at gmail.com Fri Sep 10 12:27:28 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Fri, 10 Sep 2010 09:27:28 -0700 (PDT) Subject: Ugh! Python 3.1.x and MySQL Message-ID: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> Most of the python books coming out now are Py3K. I just started programming and have a need to access a MySQL database. I would like to use Python to do this. Unfortunately, I cannot find anyone that has created anything that allows my to do this. I've tried installing an ODBC driver and using sqlalchemy, oursql, and a few other things with no luck. So...just wondering if anyone is aware of any libraries/modules that I can use to connect to a MySQL DB using Python 3.1.x? Ideally, I'd like to be able to this from both x86 and x64 systems (if that makes any difference). Thanks for any input you may have!!! From nitinpawar432 at gmail.com Fri Sep 10 12:28:36 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Fri, 10 Sep 2010 21:58:36 +0530 Subject: How to Convert IO Stream to XML Document In-Reply-To: References: Message-ID: try using parse from string ... and try minidom.parse(StringIO.StingIO(string)).documentElement On Fri, Sep 10, 2010 at 9:50 PM, jakecjacobson wrote: > I am trying to build a Python script that reads a Sitemap file and > push the URLs to a Google Search Appliance. I am able to fetch the > XML document and parse it with regular expressions but I want to move > to using native XML tools to do this. The problem I am getting is if > I use urllib.urlopen(url) I can convert the IO Stream to a XML > document but if I use urllib2.urlopen and then read the response, I > get the content but when I use minidom.parse() I get a "IOError: > [Errno 2] No such file or directory:" error > > THIS WORKS but will have issues if the IO Stream is a compressed file > def GetPageGuts(net, url): > pageguts = urllib.urlopen(url) > xmldoc = minidom.parse(pageguts) > return xmldoc > > # THIS DOESN'T WORK, but I don't understand why > def GetPageGuts(net, url): > request=getRequest_obj(net, url) > response = urllib2.urlopen(request) > response.headers.items() > pageguts = response.read() > # Test to see if the response is a gzip/compressed data stream > if isCompressedFile(response, url): > compressedstream = StringIO.StringIO(pageguts) > gzipper = gzip.GzipFile(fileobj = compressedstream) > pageguts = gzipper.read() > xmldoc = minidom.parse(pageguts) > response.close() > return xmldoc > > # I am getting the following error > Starting SiteMap Manager ... > Traceback (most recent call last): > File "./tester.py", line 267, in ? > main() > File "./tester.py", line 49, in main > fetchSiteMap(ResourceDict, line) > File "./tester.py", line 65, in fetchSiteMap > pageguts = GetPageGuts(ResourceDict['NET'], url) > File "./tester.py", line 89, in GetPageGuts > xmldoc = minidom.parse(pageguts) > File "/usr/lib/python2.4/xml/dom/minidom.py", line 1915, in parse > return expatbuilder.parse(file) > File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 922, in > parse > fp = open(file, 'rb') > IOError: [Errno 2] No such file or directory: ' encoding="UTF-8"?>\n\n\nhttp://www.myorg.org/janes/ > sitemaps/binder_sitemap.xml\n2010-09-09\n sitemap>\n\nhttp://www.myorg.org/janes/sitemaps/ > dir_sitemap.xml\n2010-05-05\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > mags_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > news_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > sent_sitemap.xml\n2010-09-09\n > \n\nhttp://www.myorg.org/janes/sitemaps/ > srep_sitemap.xml\n2001-05-04\n > \n\nhttp://www.myorg.org/janes/sitemaps/yb_sitemap.xml loc>\n2010-09-09\n\n\n' > > # A couple of supporting things > def getRequest_obj(net, url): > request = urllib2.Request(url) > request.add_header('User-Agent', 'ICES Sitemap Bot dni-ices- > searchadmin at ugov.gov') > request.add_header('Accept-encoding', 'gzip') > return request > > def isCompressedFile(r, u): > answer=False > if r.headers.has_key('Content-encoding'): > answer=True > else: > # Check to see if the URL ends in .gz > if u.endswith(".gz"): > answer=True > return answer > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From jaksonaquino at gmail.com Fri Sep 10 12:49:00 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Fri, 10 Sep 2010 13:49:00 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: Message-ID: On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro wrote: > In message , Jakson A. > Aquino wrote: > >> I would like to send code from Vim [1] to R [2] on Microsoft Windows. > > Why such a roundabout way? Why not just run R in a subprocess and feed it a > script to run? Emacs with ESS runs R in a subprocess (at least I think it does). Vim can't do that. The plugin doesn't simply send code to R. It has many other features that make it easier to edit R scripts. Best, Jakson From python at mrabarnett.plus.com Fri Sep 10 12:52:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Sep 2010 17:52:54 +0100 Subject: [Python-ideas] Why not f(*my_list, *my_other_list) ? In-Reply-To: References: Message-ID: <4C8A6266.5090501@mrabarnett.plus.com> On 10/09/2010 17:37, cool-RR wrote: > I noticed that it's impossible to call a Python function with two > starred argument lists, like this: `f(*my_list, *my_other_list)`. I > mean, if someone wants to feed two lists of arguments into a function, > why not? > > I understand why you can't have two stars in a function definition; But > why can't you have two (or more) stars in a function call? > Would there be any advantage over `f(*(my_list + my_other_list))`? From ian.g.kelly at gmail.com Fri Sep 10 13:03:54 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 10 Sep 2010 11:03:54 -0600 Subject: [Python-ideas] Why not f(*my_list, *my_other_list) ? In-Reply-To: <4C8A6266.5090501@mrabarnett.plus.com> References: <4C8A6266.5090501@mrabarnett.plus.com> Message-ID: On Fri, Sep 10, 2010 at 10:52 AM, MRAB wrote: > On 10/09/2010 17:37, cool-RR wrote: >> >> I noticed that it's impossible to call a Python function with two >> starred argument lists, like this: `f(*my_list, *my_other_list)`. I >> mean, if someone wants to feed two lists of arguments into a function, >> why not? >> >> I understand why you can't have two stars in a function definition; But >> why can't you have two (or more) stars in a function call? >> > Would there be any advantage over `f(*(my_list + my_other_list))`? That fails if my_list and my_other_list are different types, whereas the *args syntax happily accepts any iterable object. From stefan_ml at behnel.de Fri Sep 10 13:13:42 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 10 Sep 2010 19:13:42 +0200 Subject: [Python-ideas] Why not f(*my_list, *my_other_list) ? In-Reply-To: References: <4C8A6266.5090501@mrabarnett.plus.com> Message-ID: Ian Kelly, 10.09.2010 19:03: > On Fri, Sep 10, 2010 at 10:52 AM, MRAB wrote: >> On 10/09/2010 17:37, cool-RR wrote: >>> >>> I noticed that it's impossible to call a Python function with two >>> starred argument lists, like this: `f(*my_list, *my_other_list)`. I >>> mean, if someone wants to feed two lists of arguments into a function, >>> why not? >>> >>> I understand why you can't have two stars in a function definition; But >>> why can't you have two (or more) stars in a function call? >>> >> Would there be any advantage over `f(*(my_list + my_other_list))`? > > That fails if my_list and my_other_list are different types, whereas > the *args syntax happily accepts any iterable object. But I think it's still a rare enough use case to require f(*(tuple(my_list) + tuple(my_other_list))) when you need it, although the concatenation would likely get split up and moved into an explicit variable anyway. Stefan From johnroth1 at gmail.com Fri Sep 10 13:13:53 2010 From: johnroth1 at gmail.com (John Roth) Date: Fri, 10 Sep 2010 10:13:53 -0700 (PDT) Subject: Function Point Analysis (FPA) - Equivalent lines of code of Python References: <168f109f-834f-4e99-88cf-35e1ffdc6297@b4g2000pra.googlegroups.com> Message-ID: <6445cba6-48b4-4f38-9073-34f26592385e@u4g2000prn.googlegroups.com> On Sep 9, 2:30?am, Nicholas wrote: > Hi, > > ? In FPA, there are tables which shows equivalent lines of code for > each Function Point (FP) for a number of programming languages. > > ? e.g.http://www.qsm.com/?q=resources/function-point-languages-table/index.... > > ? However, I have yet to find the figures for Python. > > ? Is someone able to advise the closest language equivalent. > > Regards Function points do not translate to lines of code except when they're standardized across a specific organization's portfolio of software. I agree with Paul, any global table trying to do that is going to be pretty bogus. John Roth From no.email at nospam.invalid Fri Sep 10 13:28:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 10 Sep 2010 10:28:14 -0700 Subject: [Python-ideas] Why not f(*my_list, *my_other_list) ? References: <4C8A6266.5090501@mrabarnett.plus.com> Message-ID: <7x7hit7bkh.fsf@ruckus.brouhaha.com> Ian Kelly writes: >> Would there be any advantage over `f(*(my_list + my_other_list))`? > > That fails if my_list and my_other_list are different types, whereas > the *args syntax happily accepts any iterable object. f(*itertools.chain(my_list, my_other_list)) From ron.eggler at gmail.com Fri Sep 10 13:51:25 2010 From: ron.eggler at gmail.com (cerr) Date: Fri, 10 Sep 2010 10:51:25 -0700 (PDT) Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> Message-ID: <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> On Sep 9, 4:18?pm, MRAB wrote: > On 09/09/2010 23:52, cerr wrote: > > > > > On Sep 9, 3:29 pm, Alain Ketterlin > > wrote: > >> cerr ?writes: > >>> I'm calling a python script from a php script which again calls a perl > >>> script with subprocess.popen(). > >>> This seems to work fine so far only that once the python script > >>> completed it is becoming a zombie because the perl script in the > >>> background is still running... so before i exit the python script, i > >>> would need to kill my perl subprocess. > >>> How can i do so? > > >> x.terminate() (and then x.wait()) where x is the value returned by > >> subprocess.Popen(). > > Well, this is what I have: > > > ? ?writelog("starting GPS simulator") > > ? ?commandlist=[GPSsim,proto,GPSfile] > > ? ?writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2]) > > ? ?process=subprocess.Popen(commandlist) > > ? ?writelog("GPS simulator started") > > ? ?... > > ? ?... > > ? ?os.kill(process.pid,9) > > ? ?os.wait() > > > but this is not working for me... :( any clues? > > >> P/S: I'm not sure why the python process survives, and I think your use > >> of "zombie" is not correct (afaik a zombie is an exited process whose > >> parent hasn't called wait() yet) > > > This is what I have: > > > localhost cgi-bin # ps ax | grep py > > 11853 ? ? ? ? ?Z ? ? ?0:00 [python2.6] > > 12029 pts/1 ? ?S+ ? ? 0:00 grep --colour=auto py > > > The 'Z' you see there stands for Zombie > > How about: > > ? ? ?process.kill() # New in Python 2.6 > > or: > > ? ? ?os.kill(process.pid, 9) > > then: > > ? ? ?process.wait() > > or: > > ? ? ?os.waitpid(process.pid, 0) HI MRAB, Thanks for your suggestion, changed my code now to: process=subprocess.Popen(commandlist) ... ... process.kill() os.waitpid(process.pid, 0) but it's not killing the process running. it still runs in the background and i don't see any errors, we're running python 2.6.4 any more clues? Thanks, Ron From rami.chowdhury at merton.oxon.org Fri Sep 10 14:10:45 2010 From: rami.chowdhury at merton.oxon.org (Rami Chowdhury) Date: Sat, 11 Sep 2010 00:10:45 +0600 Subject: Ugh! Python 3.1.x and MySQL In-Reply-To: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> References: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> Message-ID: On Fri, Sep 10, 2010 at 22:27, fuglyducky wrote: > Most of the python books coming out now are Py3K. I just started > programming and have a need to access a MySQL database. I would like > to use Python to do this. Unfortunately, I cannot find anyone that has > created anything that allows my to do this. > > I've tried installing an ODBC driver and using sqlalchemy, oursql, and > a few other things with no luck. > > So...just wondering if anyone is aware of any libraries/modules that I > can use to connect to a MySQL DB using Python 3.1.x? > Have you tried OurSQL (http://packages.python.org/oursql/)? > > Ideally, I'd like to be able to this from both x86 and x64 systems (if > that makes any difference). > > Thanks for any input you may have!!! > -- > http://mail.python.org/mailman/listinfo/python-list > -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Fri Sep 10 14:23:34 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 10 Sep 2010 14:23:34 -0400 Subject: bool constructor is inconsistent? Message-ID: IN [3]: bool('False') Out[3]: True In [4]: int('32') Out[4]: 32 From sschwarzer at sschwarzer.net Fri Sep 10 14:35:10 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Fri, 10 Sep 2010 20:35:10 +0200 Subject: bool constructor is inconsistent? In-Reply-To: References: Message-ID: <4C8A7A5E.1010404@sschwarzer.net> Hi Neal, On 2010-09-10 20:23, Neal Becker wrote: > IN [3]: bool('False') > Out[3]: True If you consider strings, only an empty string has a false value. So the string 'False' which is non-empty, results in a true boolean value. For example, you can use if my_string: ... to execute some code if the string is not empty. Stefan From stefan_ml at behnel.de Fri Sep 10 14:36:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 10 Sep 2010 20:36:07 +0200 Subject: bool constructor is inconsistent? In-Reply-To: References: Message-ID: Neal Becker, 10.09.2010 20:23: > IN [3]: bool('False') > Out[3]: True Not inconsistent at all: >>> bool('false') True >>> bool('true') True >>> bool('') False >>> bool(32) True >>> bool(0) False It simply follows Python's boolean coercion rules. If you consider it inconsisten w.r.t. int('32'), then what about >>> list('[]') ['[', ']'] Stefan From emile at fenx.com Fri Sep 10 14:36:14 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 10 Sep 2010 11:36:14 -0700 Subject: bool constructor is inconsistent? In-Reply-To: References: Message-ID: On 9/10/2010 11:23 AM Neal Becker said... > IN [3]: bool('False') > Out[3]: True > > In [4]: int('32') > Out[4]: 32 > >>> eval('False') False >>> eval('32') 32 >>> Otherwise, 'False' is just a string? Emile From lists at cheimes.de Fri Sep 10 14:45:32 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 10 Sep 2010 20:45:32 +0200 Subject: how to kill a subprocess In-Reply-To: <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> Message-ID: Am 10.09.2010 19:51, schrieb cerr: > Thanks for your suggestion, changed my code now to: > > process=subprocess.Popen(commandlist) > ... > ... > process.kill() > os.waitpid(process.pid, 0) > but it's not killing the process running. it still runs in the > background and i don't see any errors, we're running python 2.6.4 > any more clues? It's not an issue with your Python process but with its parent process. The parent process has to call the OS's waitpid() function with the PID of the Python process in order to reap it. Please show us how you are starting and controlling the Python process in your PHP code. Christian From ron.eggler at gmail.com Fri Sep 10 14:56:15 2010 From: ron.eggler at gmail.com (cerr) Date: Fri, 10 Sep 2010 11:56:15 -0700 (PDT) Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> Message-ID: <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> On Sep 10, 11:45?am, Christian Heimes wrote: > Am 10.09.2010 19:51, schrieb cerr: > > > Thanks for your suggestion, changed my code now to: > > > ? process=subprocess.Popen(commandlist) > > ? ... > > ? ... > > ? process.kill() > > ? os.waitpid(process.pid, 0) > > but it's not killing the process running. it still runs in the > > background and i don't see any errors, we're running python 2.6.4 > > any more clues? > > It's not an issue with your Python process but with its parent process. > The parent process has to call the OS's waitpid() function with the PID > of the Python process in order to reap it. Please show us how you are > starting and controlling the Python process in your PHP code. But I wanna kill the child process I start from my python code. It's like PHP -> Python -> Perl and when the connection PHP -> Python seems to work well! From sonukr666 at gmail.com Fri Sep 10 15:10:55 2010 From: sonukr666 at gmail.com (sahilsk) Date: Fri, 10 Sep 2010 12:10:55 -0700 (PDT) Subject: 3D cube navigation Message-ID: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> hi, i need to make a 3d cube as a navigation menu.. each face having separate button .. or effect. any idea, how can i make one such 3D figures with functionality of mouse events? From lists at cheimes.de Fri Sep 10 15:18:27 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 10 Sep 2010 21:18:27 +0200 Subject: how to kill a subprocess In-Reply-To: <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> Message-ID: Am 10.09.2010 20:56, schrieb cerr: > But I wanna kill the child process I start from my python code. > It's like > PHP -> Python -> Perl > > and when the connection PHP -> Python seems to work well! You have said that the Python process becomes a zombie process. This clearly tells me that the issue is in your PHP script. See http://en.wikipedia.org/wiki/Fork-exec Christian From drobinow at gmail.com Fri Sep 10 15:56:38 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 10 Sep 2010 15:56:38 -0400 Subject: bool constructor is inconsistent? In-Reply-To: <4C8A7A5E.1010404@sschwarzer.net> References: <4C8A7A5E.1010404@sschwarzer.net> Message-ID: On Fri, Sep 10, 2010 at 2:35 PM, Stefan Schwarzer wrote: > Hi Neal, > > On 2010-09-10 20:23, Neal Becker wrote: >> IN [3]: bool('False') >> Out[3]: True > > If you consider strings, only an empty string has a false > value. So the string 'False' which is non-empty, results in > a true boolean value. > ... I've always felt that if a humorous post needs a smiley, that it's not funny. However, there is the risk of being misunderstood. From pruebauno at latinmail.com Fri Sep 10 15:57:50 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 10 Sep 2010 12:57:50 -0700 (PDT) Subject: Ugh! Python 3.1.x and MySQL References: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> Message-ID: <6cbd92b3-261d-4d6f-b5de-c3af9f44f16f@l17g2000vbf.googlegroups.com> On Sep 10, 12:27?pm, fuglyducky wrote: > Most of the python books coming out now are Py3K. I just started > programming and have a need to access a MySQL database. I would like > to use Python to do this. Unfortunately, I cannot find anyone that has > created anything that allows my to do this. > > I've tried installing an ODBC driver and using sqlalchemy, oursql, and > a few other things with no luck. > > So...just wondering if anyone is aware of any libraries/modules that I > can use to connect to a MySQL DB using Python 3.1.x? > > Ideally, I'd like to be able to this from both x86 and x64 systems (if > that makes any difference). > > Thanks for any input you may have!!! Google found this: http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/3831691 From ron.eggler at gmail.com Fri Sep 10 16:14:16 2010 From: ron.eggler at gmail.com (cerr) Date: Fri, 10 Sep 2010 13:14:16 -0700 (PDT) Subject: how to kill a subprocess References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> Message-ID: <3f38a424-7130-486c-9dbf-bb19a70fce69@k17g2000prf.googlegroups.com> On Sep 10, 12:18?pm, Christian Heimes wrote: > Am 10.09.2010 20:56, schrieb cerr: > > > But I wanna kill the child process I start from my python code. > > It's like > > PHP -> Python -> Perl > > > and when the connection PHP -> Python seems to work well! > > You have said that the Python process becomes a zombie process. This > clearly tells me that the issue is in your PHP script. Seehttp://en.wikipedia.org/wiki/Fork-exec No, the Perl becomes the zombie. From lists at cheimes.de Fri Sep 10 16:36:36 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 10 Sep 2010 22:36:36 +0200 Subject: how to kill a subprocess In-Reply-To: <3f38a424-7130-486c-9dbf-bb19a70fce69@k17g2000prf.googlegroups.com> References: <8864d515-aaad-4409-8abe-335bc871222c@m17g2000prl.googlegroups.com> <871v92a6uw.fsf@dpt-info.u-strasbg.fr> <45a5f079-c7e5-4cda-8434-15060f322d4e@h37g2000pro.googlegroups.com> <62d2df55-7c9b-4ce2-b86b-581d2f1738e6@y32g2000prc.googlegroups.com> <8268e2bf-2c94-413d-9bed-c2a92fe0fe79@y12g2000prb.googlegroups.com> <3f38a424-7130-486c-9dbf-bb19a70fce69@k17g2000prf.googlegroups.com> Message-ID: Am 10.09.2010 22:14, schrieb cerr: > No, the Perl becomes the zombie. How are you killing the Python process? Are you sending SIGINT, SIGTERM or SIGKILL? SIGKILL can prevent Python from running its cleanup code. Christian From tjreedy at udel.edu Fri Sep 10 17:13:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 10 Sep 2010 17:13:55 -0400 Subject: How Python works: What do you know about support for negative indices? In-Reply-To: References: Message-ID: On 9/9/2010 9:37 PM, Raymond Hettinger wrote: > The docs guarantee that Python's builtin sequences implement support > for negative indices ( http://docs.python.org/dev/reference/expressions.html#subscriptions The relevant paragraphs are " For built-in objects, there are two types of objects that support subscription: If the primary is a mapping, the expression list must evaluate to an object whose value is one of the keys of the mapping, and the subscription selects the value in the mapping that corresponds to that key. (The expression list is a tuple except if it has exactly one item.) If the primary is a sequence, the expression (list) must evaluate to an integer. If this value is negative, the length of the sequence is added to it (so that, e.g., x[-1] selects the last item of x.) The resulting value must be a nonnegative integer less than the number of items in the sequence, and the subscription selects the item whose index is that value (counting from zero). " Reading the third paragraph out of context, one can miss the restriction to built-in objects. I had assumed that the conversion using len(), when available, happened prior to the __getitem__ call. I believe I need to add the restriction in my discussion of negative indexing in my book. I would like the above rewritten something like the following: " Two types of built-in objects support subscription as primaries: mappings and sequences. For built-in mappings, the.... For built-in sequences, the ... " The second paragraph was written before defaultdict and does not apply to them. I presume that it is an extension rather than built-in class for the purpose of the Reference. > Hope you all found this to be informative, Definitely. I save a copy for future reference. -- Terry Jan Reedy From aahz at pythoncraft.com Fri Sep 10 18:14:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 10 Sep 2010 15:14:31 -0700 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: In article , Daniel Fetchinson wrote: >Attribution missing: >> >> I encourage anyone whose messages are munged like that to seek >> correction from their mail service provider, and switch to a different >> one until it's fixed. > >I encourage anyone who has problems with reading various emails, >newsgroup postings, forums and what not, to start using modern tools >that work with the vast majority of other tools. Why? Raymond's post worked fine for me with trn3.6.... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ldo at geek-central.gen.new_zealand Fri Sep 10 18:17:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:17:21 +1200 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: In message , Ian Kelly wrote: > And returning None on failure is dangerous, because if the programmer > does not take care to handle that case, the program may attempt to > regard it as actual data. But None *is* actual data. From ldo at geek-central.gen.new_zealand Fri Sep 10 18:18:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:18:47 +1200 Subject: [Tutor] Arguments from the command line References: <8662yfklzu.fsf@aiuole.stru.polimi.it> <86wrqtsxo2.fsf@aiuole.stru.polimi.it> Message-ID: In message <86wrqtsxo2.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: > Lawrence D'Oliveiro writes: > >> In message <8662yfklzu.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: >> >>> no BLOCKDATA? >> >> I think you mean COMMON. > > i meant BLOCKDATA BLOCKDATA is an initializer. The actual storage is allocated by COMMON. From ldo at geek-central.gen.new_zealand Fri Sep 10 18:19:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:19:49 +1200 Subject: SendKeys and Python 2.7 References: Message-ID: In message , Jakson A. Aquino wrote: > On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro > wrote: > >> In message , Jakson >> A. Aquino wrote: >> >>> I would like to send code from Vim [1] to R [2] on Microsoft Windows. >> >> Why such a roundabout way? Why not just run R in a subprocess and feed it >> a script to run? > > Emacs with ESS runs R in a subprocess (at least I think it does). Vim > can't do that. Why not? > The plugin doesn't simply send code to R. It has many other features > that make it easier to edit R scripts. But those are editing functions, nothing to do with R. From ldo at geek-central.gen.new_zealand Fri Sep 10 18:23:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:23:47 +1200 Subject: [Python-ideas] with statement syntax forces ugly line breaks? References: <20100908175029.6617ae3b@dino> Message-ID: In message , MRAB wrote: > On 08/09/2010 19:07, Georg Brandl wrote: > >> Thus spake the Lord: Thou shalt indent with four spaces. No more, no >> less. Four shall be the number of spaces thou shalt indent, and the >> number of thy indenting shall be four. Eight shalt thou not indent, >> nor either indent thou two, excepting that thou then proceed to four. >> Tabs are right out. >> > FYI, that should be "thine indenting". > > "My/thy" before a consonant, "mine/thine" before a vowel. Compare with > "a/an", which we still do. The funny thing is, that?s technically ?Modern English?... From ldo at geek-central.gen.new_zealand Fri Sep 10 18:32:48 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 10:32:48 +1200 Subject: [Q] Function Point Analysis (FPA) - Equivalent lines of code of Python References: <168f109f-834f-4e99-88cf-35e1ffdc6297@b4g2000pra.googlegroups.com> <7x4odz5mr3.fsf@ruckus.brouhaha.com> Message-ID: In message <7x4odz5mr3.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Nicholas writes: >> >> http://www.qsm.com/?q=resources/function-point-languages- table/index.html > > That table looks pretty bogus ... Dead giveaways are the disparity between the Ada, C++ and PL/I figures, and the fact that FORTRAN scores lower than C. Plus the inclusion of HTML and Dotnet on a par with the others. And what are ?Web Scripts", if not JavaScript? From jaksonaquino at gmail.com Fri Sep 10 18:34:11 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Fri, 10 Sep 2010 19:34:11 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: Message-ID: On Fri, Sep 10, 2010 at 7:19 PM, Lawrence D'Oliveiro wrote: > In message , Jakson A. > Aquino wrote: >> On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro >> wrote: >>> In message , Jakson >>> A. Aquino wrote: >>>> I would like to send code from Vim [1] to R [2] on Microsoft Windows. >>> >>> Why such a roundabout way? Why not just run R in a subprocess and feed it >>> a script to run? >> >> Emacs with ESS runs R in a subprocess (at least I think it does). Vim >> can't do that. > > Why not? I don't know how to embed R into Vim, but I would be grateful if you could explain how to do it since this could be an opportunity to improve my plugin. From robert.kern at gmail.com Fri Sep 10 18:38:45 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 10 Sep 2010 17:38:45 -0500 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote: > In message, Ian Kelly > wrote: > >> And returning None on failure is dangerous, because if the programmer >> does not take care to handle that case, the program may attempt to >> regard it as actual data. > > But None *is* actual data. And that is exactly the reason why the Samurai Principle says to not return None when the function fails to do what it intended to do. -- 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 krister.svanlund at gmail.com Fri Sep 10 19:09:00 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Sat, 11 Sep 2010 01:09:00 +0200 Subject: 3D cube navigation In-Reply-To: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> Message-ID: On Fri, Sep 10, 2010 at 9:10 PM, sahilsk wrote: > hi, i need to make a 3d cube as a navigation menu.. each face having > separate ?button .. or effect. > any idea, ?how can i make one such 3D figures with functionality of > mouse events? In what environment, what toolkit, for what purpose? From nagle at animats.com Fri Sep 10 19:10:31 2010 From: nagle at animats.com (John Nagle) Date: Fri, 10 Sep 2010 16:10:31 -0700 Subject: Ugh! Python 3.1.x and MySQL In-Reply-To: <6cbd92b3-261d-4d6f-b5de-c3af9f44f16f@l17g2000vbf.googlegroups.com> References: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> <6cbd92b3-261d-4d6f-b5de-c3af9f44f16f@l17g2000vbf.googlegroups.com> Message-ID: <4c8abae2$0$1647$742ec2ed@news.sonic.net> On 9/10/2010 12:57 PM, nn wrote: > On Sep 10, 12:27 pm, fuglyducky wrote: >> Most of the python books coming out now are Py3K. I just started >> programming and have a need to access a MySQL database. I would like >> to use Python to do this. Unfortunately, I cannot find anyone that has >> created anything that allows my to do this. >> >> I've tried installing an ODBC driver and using sqlalchemy, oursql, and >> a few other things with no luck. >> >> So...just wondering if anyone is aware of any libraries/modules that I >> can use to connect to a MySQL DB using Python 3.1.x? >> >> Ideally, I'd like to be able to this from both x86 and x64 systems (if >> that makes any difference). >> >> Thanks for any input you may have!!! > > Google found this: > > http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/3831691 That's progress, but it's a fork of MySQLdb. Can it be checked into the MySQLdb project on SourceForge? John Nagle From phlip2005 at gmail.com Fri Sep 10 19:12:19 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 10 Sep 2010 16:12:19 -0700 (PDT) Subject: 3D cube navigation References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> Message-ID: On Sep 10, 12:10?pm, sahilsk wrote: > hi, i need to make a 3d cube as a navigation menu.. each face having > separate ?button .. or effect. > any idea, ?how can i make one such 3D figures with functionality of > mouse events? omg If you have to ask, you probably are not ready for the answer! Is this a personal project, or are you satisfying a customer? If the latter, is it a desktop project, or a web project? If a web project, can you use a PNG of a rendered cube? Render it with PovRay (which is honestly a ton of fun to author in), then use tags to define clicks on various faces. >From here, the question arises WHY your client wants this. Must the cube rotate? Is it designed to be user hostile? Must the user rotate the cube to find the correct menu item? If you want to spend a couple weeks coding a nice learning project, you could do a rotating cube in HTML5 using the control. Someone probably has an example out there, but efficient trigonometric matrix transformations in JavaScript are not for the faint of heart. If this is for the desktop, get a Python library that wraps something that wraps OpenGL or DirectX. Or just google for "python 3d cube". Have fun! -- Phlip From martin at address-in-sig.invalid Fri Sep 10 19:42:29 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 10 Sep 2010 23:42:29 +0000 (UTC) Subject: Ugh! Python 3.1.x and MySQL References: <7250e9ba-cfb2-408a-98a0-65835bbc4bb7@i4g2000prf.googlegroups.com> Message-ID: On Fri, 10 Sep 2010 09:27:28 -0700, fuglyducky wrote: > Most of the python books coming out now are Py3K. I just started > programming and have a need to access a MySQL database. I would like to > use Python to do this. Unfortunately, I cannot find anyone that has > created anything that allows my to do this. > > I've tried installing an ODBC driver and using sqlalchemy, oursql, and a > few other things with no luck. > > So...just wondering if anyone is aware of any libraries/modules that I > can use to connect to a MySQL DB using Python 3.1.x? > > Ideally, I'd like to be able to this from both x86 and x64 systems (if > that makes any difference). > You don't say what OS you're using, but if you're on a *NIX, take a look at pyodbc: http://code.google.com/p/pyodbc/ This Python module is a wrapper for unixODBC and consequently works with standard MySQL ODBC drivers. iODBC: http://www.iodbc.org/ is similar If you want something that's Windows compatible I can't help: I don't use either Windows or MySQL. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 20:16:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 00:16:08 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: <4c8aca47$0$11111$c3e8da3@news.astraweb.com> On Sat, 11 Sep 2010 10:17:21 +1200, Lawrence D'Oliveiro wrote: > In message , Ian > Kelly wrote: > >> And returning None on failure is dangerous, because if the programmer >> does not take care to handle that case, the program may attempt to >> regard it as actual data. > > But None *is* actual data. Of course it is. Which makes it hard to distinguish None used as data from None used as a signal for an exceptional case. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 20:20:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 00:20:57 GMT Subject: 3D cube navigation References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> Message-ID: <4c8acb69$0$11111$c3e8da3@news.astraweb.com> On Sat, 11 Sep 2010 01:09:00 +0200, Krister Svanlund wrote: > On Fri, Sep 10, 2010 at 9:10 PM, sahilsk wrote: >> hi, i need to make a 3d cube as a navigation menu.. each face having >> separate ?button .. or effect. >> any idea, ?how can i make one such 3D figures with functionality of >> mouse events? > > In what environment, what toolkit, for what purpose? What do you mean, "what environment"? Surely there's only one? The Original Poster obviously wants a 3D navigation cube for ksh under FreeBSD. *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 20:25:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 00:25:07 GMT Subject: bool constructor is inconsistent? References: Message-ID: <4c8acc63$0$11111$c3e8da3@news.astraweb.com> On Fri, 10 Sep 2010 14:23:34 -0400, Neal Becker wrote: > IN [3]: bool('False') > Out[3]: True > > In [4]: int('32') > Out[4]: 32 Where is the inconsistency? bool('False') returns the same result as for any other non-empty string: >>> bool("not true") True >>> bool("no") True >>> bool("incorrect") True >>> bool("wrong") True >>> bool("Faux") True >>> bool("Falsch") True >>> bool("Falso") True >>> bool("?") True >>> bool("?????") True Treating the string "False" as identical to the named global False would be inconsistent. -- Steven From jaksonaquino at gmail.com Fri Sep 10 20:45:04 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Fri, 10 Sep 2010 21:45:04 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: On Thu, Sep 9, 2010 at 8:24 PM, Jakson A. Aquino wrote: > On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP > wrote: >> Hi! >> >> Example for send ^V ?(with PyWin32): >> >> ?import time,win32api,win32con >> ?win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) >> ?win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) >> ?time.sleep(0.05) >> ?win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) >> ?win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) > > Thank you very much! Your code solved my problem. I added some lines > to set the focus into R before the ^V and then back to Vim: Unfortunately, I was wrong. Your code do send the ^v as expected, but I have problem with the selection of the Windows which will receive the ^v. The code above was OK in a Windows XP running inside VirtualBox, but when tested in a real machine, it proved to be highly inconsistent. Sometimes the ^v gets pasted into R, but more frequently it is pasted into Vim itself or nowhere. Below is the complete code that I'm using. It's a vim script. The python code is delimited by "python << EOL" and "EOL": function! SendToRPy(aString) python << EOL import time import win32api import win32con import win32com.client import win32clipboard import vim aString = vim.eval("a:aString") win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(aString) win32clipboard.CloseClipboard() shell = win32com.client.Dispatch("WScript.Shell") ok = shell.AppActivate("R Console") if ok: win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) time.sleep(0.05) win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) shell.AppActivate("Vim") else: vim.command("call RWarningMsg('Is R running?')") time.sleep(1) EOL endfunction When R isn't running, the script correctly shows the warning message "Is R running?". Does anyone know what should I do to correctly use the AppActivate function or is there a better approach to this problem? Thanks! Jakson Aquino From python.list at tim.thechases.com Fri Sep 10 21:01:25 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 10 Sep 2010 20:01:25 -0500 Subject: 3D cube navigation In-Reply-To: <4c8acb69$0$11111$c3e8da3@news.astraweb.com> References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> <4c8acb69$0$11111$c3e8da3@news.astraweb.com> Message-ID: <4C8AD4E5.8050801@tim.thechases.com> On 09/10/10 19:20, Steven D'Aprano wrote: > On Sat, 11 Sep 2010 01:09:00 +0200, Krister Svanlund wrote: >> On Fri, Sep 10, 2010 at 9:10 PM, sahilsk wrote: >>> hi, i need to make a 3d cube as a navigation menu.. each face having >>> separate button .. or effect. >> >> In what environment, what toolkit, for what purpose? > > What do you mean, "what environment"? Surely there's only one? The > Original Poster obviously wants a 3D navigation cube for ksh under > FreeBSD. Drat...all my work on a 3d navigation-cube working under ProDos on the Apple ][e for naught...what am I gonna do with all these 360k 5.25" floppies now?! -tkc From ben+python at benfinney.id.au Fri Sep 10 21:17:16 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 11 Sep 2010 11:17:16 +1000 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: <87vd6d84f7.fsf@benfinney.id.au> Ben Finney writes: > Raymond Hettinger writes: > > > It doesn't seem to be common knowledge when and how a[x] gets > > translated to a[x+len(x)]. So, here's a short info post on how > > Python supports negative indices for sequences. > > Thanks for this. Could you post your messages using a channel that > doesn't arbitrarily split your paragraphs into long-short-long-short > lines? It makes paragraphs burdensome to read, and I skipped most of > the message because of that. For those who think the problem may be with the recipient's software, I see the same annoying line-wrapping problems in the archived message . There's been enough sidetracking of Raymond's thread, though, so that factual contribution will hopefully be my last in this thread on this issue. -- \ ?Choose mnemonic identifiers. If you can't remember what | `\ mnemonic means, you've got a problem.? ?Larry Wall | _o__) | Ben Finney From python at mrabarnett.plus.com Fri Sep 10 21:38:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Sep 2010 02:38:05 +0100 Subject: SendKeys and Python 2.7 In-Reply-To: References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: <4C8ADD7D.4010801@mrabarnett.plus.com> On 11/09/2010 01:45, Jakson A. Aquino wrote: > On Thu, Sep 9, 2010 at 8:24 PM, Jakson A. Aquino wrote: >> On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP >> wrote: >>> Hi! >>> >>> Example for send ^V (with PyWin32): >>> >>> import time,win32api,win32con >>> win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) >>> win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) >>> time.sleep(0.05) >>> win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) >>> win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) >> >> Thank you very much! Your code solved my problem. I added some lines >> to set the focus into R before the ^V and then back to Vim: > > Unfortunately, I was wrong. Your code do send the ^v as expected, but > I have problem with the selection of the Windows which will receive > the ^v. The code above was OK in a Windows XP running inside > VirtualBox, but when tested in a real machine, it proved to be highly > inconsistent. Sometimes the ^v gets pasted into R, but more frequently > it is pasted into Vim itself or nowhere. Below is the complete code > that I'm using. It's a vim script. The python code is delimited by > "python<< EOL" and "EOL": > > function! SendToRPy(aString) > python<< EOL > import time > import win32api > import win32con > import win32com.client > import win32clipboard > import vim > > aString = vim.eval("a:aString") > win32clipboard.OpenClipboard() > win32clipboard.EmptyClipboard() > win32clipboard.SetClipboardText(aString) > win32clipboard.CloseClipboard() > shell = win32com.client.Dispatch("WScript.Shell") > ok = shell.AppActivate("R Console") > if ok: > win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0) > win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0) > time.sleep(0.05) > win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | > win32con.KEYEVENTF_KEYUP, 0) > win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0) > shell.AppActivate("Vim") > else: > vim.command("call RWarningMsg('Is R running?')") > time.sleep(1) > EOL > endfunction > > When R isn't running, the script correctly shows the warning message > "Is R running?". Does anyone know what should I do to correctly use > the AppActivate function or is there a better approach to this > problem? > I'd add some more small sleeps to give Windows/R time to act, IYSWIM. I learned that from experience. :-) From steve at REMOVE-THIS-cybersource.com.au Fri Sep 10 22:00:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 02:00:14 GMT Subject: Refactoring similar subclasses Message-ID: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> I have some code that currently takes four different classes, A, B, C and D, and subclasses each of them in the same way: class MyA(A): def method(self, x): result = super(MyA, self).method(x) if result == "spam": return "spam spam spam" return result # many more methods overloaded class MyB(B): def method(self, x): result = super(MyB, self).method(x) if result == "spam": return "spam spam spam" return result # many more methods overloaded and so on, for MyC and MyD. There's a lot of duplicated code in there. What techniques do you suggest for reducing the code duplication? I thought about some variation of: names = "MyA MyB MyC MyD".split() bases = [A, B, C, D] d = dict-of-overloaded-methods for name, base in zip(names, bases): globals()[name] = type(name, [base], d) but I'm not sure that this is a good approach, or how to inject the right arguments to super in the dict. Any suggestions or guidelines? -- Steven From cosmo_general at yahoo.com Fri Sep 10 23:28:52 2010 From: cosmo_general at yahoo.com (Muddy Coder) Date: Fri, 10 Sep 2010 20:28:52 -0700 (PDT) Subject: Hide DOS console for .pyc file Message-ID: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Hi Folks, For a quick testing purpose, I deliver .pyc files to my customer. I don't want the black DOS console appearing behind my GUI, but I have no idea how to do it. Somebody can help? Thanks! Cosmo From kelvin.you at gmail.com Sat Sep 11 00:38:03 2010 From: kelvin.you at gmail.com (=?UTF-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B5aSp5rav5LiN6KeB5a62?=) Date: Fri, 10 Sep 2010 21:38:03 -0700 (PDT) Subject: default value for __init__ doesn't work Message-ID: Please look at below code snippet: class test(): def __init__(self, a, dic={}): self.a = a self.dic = dic print('__init__ params:',a, dic) def get(self): self.dic[1] = 2 self.dic[4] = 5 def foo(): print('in foo function') bar = test(1) bar.get() if __name__ == '__main__': foo() foo() ----------------------- Result: in foo function __init__ params: 1 {} in foo function __init__ params: 1 {1: 2, 4: 5} But my expect result is : in foo function __init__ params: 1 {} in foo function __init__ params: 1 {} it seems that the default value for dic doesn't work on the second call for the class test. It's wired. Who can give a explaination for this scenario? From stefan_ml at behnel.de Sat Sep 11 01:09:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Sep 2010 07:09:56 +0200 Subject: How to Convert IO Stream to XML Document In-Reply-To: References: Message-ID: jakecjacobson, 10.09.2010 18:20: > response = urllib2.urlopen(request) > pageguts = response.read() > xmldoc = minidom.parse(pageguts) Check the minidom docs, there's a parseString() function that does what it says. Also, don't forget to take a look at xml.etree.ElementTree. Depending on what you want to do with the XML result, it'll likely be easier to use and faster than minidom. The function there is called fromstring(), just in case ;) Stefan From benjamin.kaplan at case.edu Sat Sep 11 01:14:54 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 11 Sep 2010 01:14:54 -0400 Subject: default value for __init__ doesn't work In-Reply-To: References: Message-ID: On Sat, Sep 11, 2010 at 12:38 AM, ??????????????? wrote: > Please look at below code snippet: > class test(): > ? ?def __init__(self, a, dic={}): > ? ? ? ?self.a = a > ? ? ? ?self.dic = dic > ? ? ? ?print('__init__ params:',a, dic) > This is a pretty popular mistake to make. Default arguments aren't evaluated when you call the method. They're created when the method is created (meaning when you first run the file and the class itself is defined), and that's it. Because you do self.dic = dic, this means that every instance of the object will receive the same dict object. Change it for one object, and the change will show up in all of them. The solution to this is to use a sentinel value, like None def __init__(self, a, dic=None) : if dic is None : self.dic = {} else : self.dic = dic If None is a valid value for the parameter, make a sentinel object and use that sentinel = object() def __init__(self, a, dic=sentinel) : if dic is sentinel : #you want to use is here, not == ... From kelvin.you at gmail.com Sat Sep 11 01:55:33 2010 From: kelvin.you at gmail.com (=?UTF-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B5aSp5rav5LiN6KeB5a62?=) Date: Fri, 10 Sep 2010 22:55:33 -0700 (PDT) Subject: default value for __init__ doesn't work References: Message-ID: On Sep 11, 1:14?pm, Benjamin Kaplan wrote: > On Sat, Sep 11, 2010 at 12:38 AM, ??????????????? wrote: > > Please look at below code snippet: > > class test(): > > ? ?def __init__(self, a, dic={}): > > ? ? ? ?self.a = a > > ? ? ? ?self.dic = dic > > ? ? ? ?print('__init__ params:',a, dic) > > This is a pretty popular mistake to make. Default arguments aren't > evaluated when you call the method. They're created when the method is > created (meaning when you first run the file and the class itself is > defined), and that's it. Because you do self.dic = dic, this means > that every instance of the object will receive the same dict object. > Change it for one object, and the change will show up in all of them. > The solution to this is to use a sentinel value, like None > > def __init__(self, a, dic=None) : > ? ? if dic is None : > ? ? ? ? self.dic = {} > ? ? else : > ? ? ? ? self.dic = dic > > If None is a valid value for the parameter, make a sentinel object and use that > > sentinel = object() > def __init__(self, a, dic=sentinel) : > ? ? if dic is sentinel : #you want to use is here, not == > ? ? ? ... Got it. Thanks for point out my mistake. You are very nice. From kelvin.you at gmail.com Sat Sep 11 02:05:04 2010 From: kelvin.you at gmail.com (=?UTF-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B5aSp5rav5LiN6KeB5a62?=) Date: Fri, 10 Sep 2010 23:05:04 -0700 (PDT) Subject: default value for __init__ doesn't work References: Message-ID: <1b0dfe29-cdd2-48b1-9dae-3b29e7da4c3a@g21g2000prn.googlegroups.com> On Sep 11, 1:55?pm, ??????????????? wrote: > On Sep 11, 1:14?pm, Benjamin Kaplan wrote: > > > > > On Sat, Sep 11, 2010 at 12:38 AM, ??????????????? wrote: > > > Please look at below code snippet: > > > class test(): > > > ? ?def __init__(self, a, dic={}): > > > ? ? ? ?self.a = a > > > ? ? ? ?self.dic = dic > > > ? ? ? ?print('__init__ params:',a, dic) > > > This is a pretty popular mistake to make. Default arguments aren't > > evaluated when you call the method. They're created when the method is > > created (meaning when you first run the file and the class itself is > > defined), and that's it. Because you do self.dic = dic, this means > > that every instance of the object will receive the same dict object. > > Change it for one object, and the change will show up in all of them. > > The solution to this is to use a sentinel value, like None > > > def __init__(self, a, dic=None) : > > ? ? if dic is None : > > ? ? ? ? self.dic = {} > > ? ? else : > > ? ? ? ? self.dic = dic > > > If None is a valid value for the parameter, make a sentinel object and use that > > > sentinel = object() > > def __init__(self, a, dic=sentinel) : > > ? ? if dic is sentinel : #you want to use is here, not == > > ? ? ? ... > > Got it. Thanks for point out my mistake. You are very nice. I remember the same issue was occurred in my C++ program. There I have a function with a parameter referenced a default object . May be C++ also constructs the the default arguments before the function is called. Thank you again to help me so much! From jearl at notengoamigos.org Sat Sep 11 02:53:34 2010 From: jearl at notengoamigos.org (Jason Earl) Date: Sat, 11 Sep 2010 00:53:34 -0600 Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: <87mxrodb4h.fsf@notengoamigos.org> On Fri, Sep 10 2010, Muddy Coder wrote: > Hi Folks, > > For a quick testing purpose, I deliver .pyc files to my customer. I > don't want the black DOS console appearing behind my GUI, but I have > no idea how to do it. Somebody can help? Thanks! > > > Cosmo I don't really use Windows any more, so I might be off the mark, but I think that you need to look into using pythonw.exe instead of python.exe. Solving your problem might be as easy as changing the name of your file from foo.py to foo.pyw. Jason From __peter__ at web.de Sat Sep 11 02:53:38 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 11 Sep 2010 08:53:38 +0200 Subject: Refactoring similar subclasses References: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I have some code that currently takes four different classes, A, B, C and > D, and subclasses each of them in the same way: > > class MyA(A): > def method(self, x): > result = super(MyA, self).method(x) > if result == "spam": > return "spam spam spam" > return result > # many more methods overloaded > > > class MyB(B): > def method(self, x): > result = super(MyB, self).method(x) > if result == "spam": > return "spam spam spam" > return result > # many more methods overloaded > > > and so on, for MyC and MyD. There's a lot of duplicated code in there. > What techniques do you suggest for reducing the code duplication? I > thought about some variation of: > > names = "MyA MyB MyC MyD".split() > bases = [A, B, C, D] > d = dict-of-overloaded-methods > for name, base in zip(names, bases): > globals()[name] = type(name, [base], d) > > > but I'm not sure that this is a good approach, or how to inject the right > arguments to super in the dict. > > Any suggestions or guidelines? You could use a mixin: class Mixin(object): def method(self, x): result = super(Mixin, self).method(x) if result == "spam": return "spam spam spam" return result # ... for name, base in zip(names, bases): globals()[name] = type(name, (Mixin, base), {}) Peter From ldo at geek-central.gen.new_zealand Sat Sep 11 03:22:58 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 19:22:58 +1200 Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: In message <3a2d194c-9b34-4b84-8680-28bdfb53b975 at y3g2000vbm.googlegroups.com>, Muddy Coder wrote: > For a quick testing purpose, I deliver .pyc files to my customer. I > don't want the black DOS console appearing behind my GUI, but I have > no idea how to do it. Somebody can help? Thanks! Don?t run it on Windows. From ldo at geek-central.gen.new_zealand Sat Sep 11 03:24:04 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 19:24:04 +1200 Subject: SendKeys and Python 2.7 References: Message-ID: In message , Jakson A. Aquino wrote: > On Fri, Sep 10, 2010 at 7:19 PM, Lawrence D'Oliveiro > wrote: > >> In message , Jakson >> A. Aquino wrote: >> >>> On Fri, Sep 10, 2010 at 6:26 AM, Lawrence D'Oliveiro >>> wrote: >> >>>> In message , >>>> Jakson A. Aquino wrote: >>>> >>>>> I would like to send code from Vim [1] to R [2] on Microsoft Windows. >>>> >>>> Why such a roundabout way? Why not just run R in a subprocess and feed >>>> it a script to run? >>> >>> Emacs with ESS runs R in a subprocess (at least I think it does). Vim >>> can't do that. >> >> Why not? > > I don't know how to embed R into Vim ... I wasn?t saying ?embed?, I was saying ?run R in a subprocess?. From ldo at geek-central.gen.new_zealand Sat Sep 11 03:25:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 19:25:05 +1200 Subject: SendKeys and Python 2.7 References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: In message , Jakson A. Aquino wrote: > Your code do send the ^v as expected, but I have problem with the > selection of the Windows which will receive the ^v. The code above was OK > in a Windows XP running inside VirtualBox, but when tested in a real > machine, it proved to be highly inconsistent. Sometimes the ^v gets pasted > into R, but more frequently it is pasted into Vim itself or nowhere. No big surprise your roundabout GUI-fiddling approach is flaky. From steve at REMOVE-THIS-cybersource.com.au Sat Sep 11 03:58:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 07:58:08 GMT Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: <4c8b3690$0$11111$c3e8da3@news.astraweb.com> On Fri, 10 Sep 2010 20:28:52 -0700, Muddy Coder wrote: > Hi Folks, > > For a quick testing purpose, I deliver .pyc files to my customer. I > don't want the black DOS console appearing behind my GUI, but I have no > idea how to do it. Somebody can help? Thanks! Google is your friend. Googling for "Python dos window" brings up this as the third hit: http://www.velocityreviews.com/forums/t344026-how-to-run-python-in- windows-w-o-popping-a-dos-box.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Sep 11 04:03:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 11 Sep 2010 08:03:56 GMT Subject: Refactoring similar subclasses References: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> Message-ID: <4c8b37ec$0$11111$c3e8da3@news.astraweb.com> On Sat, 11 Sep 2010 08:53:38 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> I have some code that currently takes four different classes, A, B, C >> and D, and subclasses each of them in the same way: [...] >> Any suggestions or guidelines? > > You could use a mixin: Nice! I'll give it a try. I knew that sooner or later I'd find a reason for mixins :) -- Steven From davea at ieee.org Sat Sep 11 05:37:06 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 11 Sep 2010 05:37:06 -0400 Subject: Hide DOS console for .pyc file In-Reply-To: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: <4C8B4DC2.3000007@ieee.org> On 2:59 PM, Muddy Coder wrote: > Hi Folks, > > For a quick testing purpose, I deliver .pyc files to my customer. I > don't want the black DOS console appearing behind my GUI, but I have > no idea how to do it. Somebody can help? Thanks! > > > Cosmo > In Windows, the executable file statically determines whether a console is created. There are two executables shipped with Python, python.exe and pythonw.exe. You want to use the latter. The real question is how to cause Windows to run that rather than python.exe. Answer depends on how your use is launching his program. If he's starting from a shortcut, change the name of the executable on the shortcut. If he's starting by double-clicking on the script name, change the extension of the script from .py to .pyw You mention that you're shipping only .pyc files. If that's the case, add one more, a .pyw that imports your main script. Of course, that may mean changing that script a little so it works as a module. DaveA From __peter__ at web.de Sat Sep 11 05:44:32 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 11 Sep 2010 11:44:32 +0200 Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > In message > <3a2d194c-9b34-4b84-8680-28bdfb53b975 at y3g2000vbm.googlegroups.com>, Muddy > Coder wrote: > >> For a quick testing purpose, I deliver .pyc files to my customer. I >> don't want the black DOS console appearing behind my GUI, but I have >> no idea how to do it. Somebody can help? Thanks! > > Don?t run it on Windows. If you switch the OS for every minor problem you'll run out of operating systems pretty soon... From jaksonaquino at gmail.com Sat Sep 11 05:46:00 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Sat, 11 Sep 2010 06:46:00 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: On Sat, Sep 11, 2010 at 4:25 AM, Lawrence D'Oliveiro wrote: > In message , Jakson A. > Aquino wrote: > >> Your code do send the ^v as expected, but I have problem with the >> selection of the Windows which will receive the ^v. The code above was OK >> in a Windows XP running inside VirtualBox, but when tested in a real >> machine, it proved to be highly inconsistent. Sometimes the ^v gets pasted >> into R, but more frequently it is pasted into Vim itself or nowhere. > > No big surprise your roundabout GUI-fiddling approach is flaky. Thanks for your comment, but could you please suggest a feasible and non flaky approach? From jaksonaquino at gmail.com Sat Sep 11 05:55:07 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Sat, 11 Sep 2010 06:55:07 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: <4C8ADD7D.4010801@mrabarnett.plus.com> References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> <4C8ADD7D.4010801@mrabarnett.plus.com> Message-ID: On Fri, Sep 10, 2010 at 10:38 PM, MRAB wrote: > I'd add some more small sleeps to give Windows/R time to act, IYSWIM. I > learned that from experience. :-) I've tried adding sleeps, small and large, but they didn't make much of a difference. Anyway, different machines could require different amounts of sleep and, thus, this workaround may not be generalizable enough since the plugin would be used by many people on different systems. Thanks, Jakson From ldo at geek-central.gen.new_zealand Sat Sep 11 06:31:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 22:31:34 +1200 Subject: SendKeys and Python 2.7 References: <4c89464f$0$10213$ba4acef3@reader.news.orange.fr> Message-ID: In message , Jakson A. Aquino wrote: > On Sat, Sep 11, 2010 at 4:25 AM, Lawrence D'Oliveiro > wrote: > >> In message , Jakson >> A. Aquino wrote: >> >>> Your code do send the ^v as expected, but I have problem with the >>> selection of the Windows which will receive the ^v. The code above was >>> OK in a Windows XP running inside VirtualBox, but when tested in a real >>> machine, it proved to be highly inconsistent. Sometimes the ^v gets >>> pasted into R, but more frequently it is pasted into Vim itself or >>> nowhere. >> >> No big surprise your roundabout GUI-fiddling approach is flaky. > > Thanks for your comment, but could you please suggest a feasible and > non flaky approach? I already did. From ldo at geek-central.gen.new_zealand Sat Sep 11 06:32:27 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 11 Sep 2010 22:32:27 +1200 Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: In message , Peter Otten wrote: > Lawrence D'Oliveiro wrote: > >> In message >> <3a2d194c-9b34-4b84-8680-28bdfb53b975 at y3g2000vbm.googlegroups.com>, Muddy >> Coder wrote: >> >>> For a quick testing purpose, I deliver .pyc files to my customer. I >>> don't want the black DOS console appearing behind my GUI, but I have >>> no idea how to do it. Somebody can help? Thanks! >> >> Don?t run it on Windows. > > If you switch the OS for every minor problem you'll run out of operating > systems pretty soon... Not if you choose a suitably flexible and portable one to begin with. From rafalgulinski at gmail.com Sat Sep 11 06:59:20 2010 From: rafalgulinski at gmail.com (rav) Date: Sat, 11 Sep 2010 03:59:20 -0700 (PDT) Subject: 3D cube navigation References: <13a41f82-5f5d-473e-8750-5bc875b66e2c@p24g2000pra.googlegroups.com> Message-ID: <24439775-fae6-415b-8fd3-54a524168a62@y3g2000vbm.googlegroups.com> On Sep 10, 9:10?pm, sahilsk wrote: > hi, i need to make a 3d cube as a navigation menu.. each face having > separate ?button .. or effect. > any idea, ?how can i make one such 3D figures with functionality of > mouse events? One of options is AS3 and Papervision3D - free Flex SDK and many tutorials are available in the web. From sschwarzer at sschwarzer.net Sat Sep 11 09:16:19 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 11 Sep 2010 15:16:19 +0200 Subject: Design: Module interface vs. library interface Message-ID: <4C8B8123.80704@sschwarzer.net> Hello, I maintain ftputil [1], an FTP client library. Users of the library may use it like this: | import ftputil | | with ftputil.FTPHost(server, userid, password) as ftp_host: | # for example, make a remote file and read its content | with ftp_host.open("remote_name", "rb") as remote_fobj: | data = remote_fobj.read() Even though "ftp files" are defined in module `ftp_file` [2] via class `FTPFile`, users of the ftputil library should never use `FTPFile` directly; it's up to `FTPHost.open` to generate these file objects. Now, from the "point of view" of the _module_ `ftp_file`, I'd use | # ftp_file.py | | # used outside this module | __all__ = ['FTPFile'] | | class FTPFile(object): | ... | # ftputil.py | | import ftp_file | | class FTPHost(object): | ... | def open(name, mode): | ... | return ftp_file.FTPFile(...) On the other hand, from the point of view of the _library_ ftputil, `FTPFile` isn't part of the official API, so I may as well write | # ftp_file.py | | # be explicit, no user-public interface | __all__ = [] | | class FTPFile(object): | ... Which approach would you prefer and why? Or some other approach? Would you use a different approach if the library-internal class was named `_FTPFile` instead of `FTPFile`? [1] http://ftputil.sschwarzer.net [2] http://ftputil.sschwarzer.net/trac/browser/ftp_file.py Stefan From bearophileHUGS at lycos.com Sat Sep 11 10:33:29 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Sat, 11 Sep 2010 07:33:29 -0700 (PDT) Subject: Static typing, Python, D, DbC Message-ID: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> I write some Python code almost every day, but lately I am using a lot the D language too. After using D for about three years I now know some of it, but when I need to write short (< about 1000 lines) *correct* programs, Python is still the more productive for me. Static typing, and the usage of transitive const of D are a strange thing. It seems obvious that they lead to safer code, but on the other hand experimentally I have seen that my short Python programs are less buggy than equivalent D ones. Static typing looks safer, but D offers many low level features, and generally it contains many more traps or ways to shoot your own foot, that they more than compensate for the "lack of safety" coming from Python dynamic typing, even when you don't use those low level features. Maybe for large (> about 100_000 lines) programs D may come out to be less bug-prone than Python (thanks to the better data hiding and static typing), but I am not sure of this at all... Static typing also has a significant costs. When you write D2 code often something doesn't work because of some transitive const or immutable (or just because of the large number of bugs that need to be fixed still in the D compiler). So here you pay some cost as debugging time (or time to avoid those problems). And there is a mental cost too, because you need to keep part of your attention on those const- related things instead of your algorithms, etc. ---------------- Lately while I program with Python one of the D features that I most miss is a built-in Design By Contract (see PEP 316), because it avoids (or helps me to quickly find and fix) many bugs. In my opinion DbC is also very good used with doctests. You may implement a poor's man DbC in Python like this: class Foo: def _invariant(self): assert ... assert ... return True def bar(self, ...): assert self._invariant() ... res = ... assert self._invariant() return res But this missed several useful features of DbC. >From the D standard library, I have also appreciated a lazy string split (something like a str.xplit()). In some situations it reduces memory waste and increases code performance. ---------------- I have installed this, on a Windows Vista OS: http://www.python.org/ftp/python/2.7/python-2.7.msi But I have had two problems, the 'random' module was empty, and it didn't import the new division from the future, so I've had to remove it and reinstall 2.6.6. Is this just a problem of mine? Bye, bearophile From aahz at pythoncraft.com Sat Sep 11 10:42:11 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Sep 2010 07:42:11 -0700 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> <87vd6d84f7.fsf@benfinney.id.au> Message-ID: In article <87vd6d84f7.fsf at benfinney.id.au>, Ben Finney wrote: >Ben Finney writes: >> Raymond Hettinger writes: >>> >>> It doesn't seem to be common knowledge when and how a[x] gets >>> translated to a[x+len(x)]. So, here's a short info post on how >>> Python supports negative indices for sequences. >> >> Thanks for this. Could you post your messages using a channel that >> doesn't arbitrarily split your paragraphs into long-short-long-short >> lines? It makes paragraphs burdensome to read, and I skipped most of >> the message because of that. > >For those who think the problem may be with the recipient's software, I >see the same annoying line-wrapping problems in the archived message >. Still looks like *your* problem to me; except for exactly one paragraph, I don't see comb-style formatting in Lynx at that URL. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From zak.mc.kraken at libero.it Sat Sep 11 11:34:35 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sat, 11 Sep 2010 17:34:35 +0200 Subject: bug in python documentation? Message-ID: from http://docs.python.org/library/unittest.html -->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8-- Here is a short script to test three functions from the random module: import random import unittest class TestSequenceFunctions(unittest.TestCase): def setUp(self): self.seq = range(10) def test_shuffle(self): # make sure the shuffled sequence does not lose any elements random.shuffle(self.seq) self.seq.sort() self.assertEqual(self.seq, range(10)) # should raise an exception for an immutable sequence self.assertRaises(TypeError, random.shuffle, (1,2,3)) def test_choice(self): element = random.choice(self.seq) self.assertTrue(element in self.seq) def test_sample(self): with self.assertRaises(ValueError): random.sample(self.seq, 20) for element in random.sample(self.seq, 5): self.assertTrue(element in self.seq) if __name__ == '__main__': unittest.main() --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- but test_sample() it's a strange method: what's that "with self.assertRaises(ValueErrorr)"? infact, running the script I have $ python test_unittest.py .E. ====================================================================== ERROR: test_sample (__main__.TestSequenceFunctions) ---------------------------------------------------------------------- Traceback (most recent call last): File "./test_data_manip.py", line 23, in test_sample with self.assertRaises(ValueError): TypeError: failUnlessRaises() takes at least 3 arguments (2 given) ---------------------------------------------------------------------- Ran 3 tests in 0.001s FAILED (errors=1) $ -- By ZeD From benjamin.kaplan at case.edu Sat Sep 11 11:44:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 11 Sep 2010 11:44:46 -0400 Subject: bug in python documentation? In-Reply-To: References: Message-ID: On Sat, Sep 11, 2010 at 11:34 AM, Vito 'ZeD' De Tullio wrote: > from http://docs.python.org/library/unittest.html > > -->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8---->8-- > > Here is a short script to test three functions from the random module: > > import random > import unittest > > class TestSequenceFunctions(unittest.TestCase): > > ? ?def setUp(self): > ? ? ? ?self.seq = range(10) > > ? ?def test_shuffle(self): > ? ? ? ?# make sure the shuffled sequence does not lose any elements > ? ? ? ?random.shuffle(self.seq) > ? ? ? ?self.seq.sort() > ? ? ? ?self.assertEqual(self.seq, range(10)) > > ? ? ? ?# should raise an exception for an immutable sequence > ? ? ? ?self.assertRaises(TypeError, random.shuffle, (1,2,3)) > > ? ?def test_choice(self): > ? ? ? ?element = random.choice(self.seq) > ? ? ? ?self.assertTrue(element in self.seq) > > ? ?def test_sample(self): > ? ? ? ?with self.assertRaises(ValueError): > ? ? ? ? ? ?random.sample(self.seq, 20) > ? ? ? ?for element in random.sample(self.seq, 5): > ? ? ? ? ? ?self.assertTrue(element in self.seq) > > if __name__ == '__main__': > ? ?unittest.main() > > --8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- > > > but test_sample() it's a strange method: what's that "with > self.assertRaises(ValueErrorr)"? > > infact, running the script I have > > $ python test_unittest.py > .E. > ====================================================================== > ERROR: test_sample (__main__.TestSequenceFunctions) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "./test_data_manip.py", line 23, in test_sample > ? ?with self.assertRaises(ValueError): > TypeError: failUnlessRaises() takes at least 3 arguments (2 given) > > ---------------------------------------------------------------------- > Ran 3 tests in 0.001s > > FAILED (errors=1) > $ > > > -- > By ZeD You're looking at the 2.7 documentation. Are you using 2.7? From thomas at jollybox.de Sat Sep 11 11:47:32 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 11 Sep 2010 17:47:32 +0200 Subject: bug in python documentation? In-Reply-To: References: Message-ID: <201009111747.32867.thomas@jollybox.de> On Saturday 11 September 2010, it occurred to Vito 'ZeD' De Tullio to exclaim: > from http://docs.python.org/library/unittest.html > > $ python test_unittest.py > .E. > ====================================================================== > ERROR: test_sample (__main__.TestSequenceFunctions) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "./test_data_manip.py", line 23, in test_sample > with self.assertRaises(ValueError): > TypeError: failUnlessRaises() takes at least 3 arguments (2 given) > > ---------------------------------------------------------------------- > Ran 3 tests in 0.001s > > FAILED (errors=1) > $ Which Python version are you using? To quote the docs you linked: http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises """ Changed in version 2.7: Added the ability to use assertRaises() as a context manager. """ Are you using Python 2.7 (or 3.x)? -------------- next part -------------- An HTML attachment was scrubbed... URL: From zak.mc.kraken at libero.it Sat Sep 11 12:21:49 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sat, 11 Sep 2010 18:21:49 +0200 Subject: bug in python documentation? References: Message-ID: Benjamin Kaplan wrote: > You're looking at the 2.7 documentation. Are you using 2.7? whoops, no: 2.6.5 :\ (but the "new in python X.Y.Z" disclaimer does not apply to the example snippets?) -- By ZeD From thomas at jollybox.de Sat Sep 11 12:28:07 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 11 Sep 2010 18:28:07 +0200 Subject: [Python-ideas] with statement syntax forces ugly line breaks? In-Reply-To: References: <20100908175029.6617ae3b@dino> Message-ID: <201009111828.08299.thomas@jollybox.de> On Saturday 11 September 2010, it occurred to Lawrence D'Oliveiro to exclaim: > In message , MRAB > > wrote: > > On 08/09/2010 19:07, Georg Brandl wrote: > >> Thus spake the Lord: Thou shalt indent with four spaces. No more, no > >> less. Four shall be the number of spaces thou shalt indent, and the > >> number of thy indenting shall be four. Eight shalt thou not indent, > >> nor either indent thou two, excepting that thou then proceed to four. > >> Tabs are right out. > > > > FYI, that should be "thine indenting". > > > > "My/thy" before a consonant, "mine/thine" before a vowel. Compare with > > "a/an", which we still do. > > The funny thing is, that?s technically ?Modern English?... ... and it's regularly used in a number of best-selling books. From lie.1296 at gmail.com Sat Sep 11 12:36:28 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 12 Sep 2010 02:36:28 +1000 Subject: Static typing, Python, D, DbC In-Reply-To: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> Message-ID: <4c8bb00f@dnews.tpgi.com.au> On 09/12/10 00:33, Bearophile wrote: > ---------------- > > Lately while I program with Python one of the D features that I most > miss is a built-in Design By Contract (see PEP 316), because it avoids > (or helps me to quickly find and fix) many bugs. In my opinion DbC is > also very good used with doctests. > You may implement a poor's man DbC in Python like this: I would do it like this: from DbC import DbC class Foo(__metaclass__=DbC): def __invariant(self): ... automatically asserted for all methods ... def __precond(self): ... automatically asserted for all methods ... def __postcond(self): ... automatically asserted for all methods ... @precond(attr=value) # asserts self.attr==value @postcond(func) # a function for more complex assertions def bar(self, ...): ... clean, uncluttered code ... and set DbC.uninstall() to uninstall all precond/postcond/invariants at runtime without any additional overhead. These are all definitely possible with metaclasses and decorators. > From the D standard library, I have also appreciated a lazy string > split (something like a str.xplit()). In some situations it reduces > memory waste and increases code performance. Care to open an issue at the tracker? Considering that many Python 3 builtins is now lazy, there might be a chance this is an oversight, or there might be a reason why string.split is not lazy. From fields.emmett at gmail.com Sat Sep 11 12:59:26 2010 From: fields.emmett at gmail.com (fields) Date: Sat, 11 Sep 2010 09:59:26 -0700 (PDT) Subject: triangle python user's group? References: <3c95f09c-1fa7-4c63-9f13-3f2776c2ab41@j18g2000yqd.googlegroups.com> Message-ID: <40e801f1-de0b-40a3-8a82-b2fb43165a00@v23g2000vbi.googlegroups.com> Tim: trizpug.org - fields On Aug 31, 12:38?pm, "Tim Arnold" wrote: > "Albert Hopkins" wrote in message > > news:mailman.219.1283200967.29448.python-list at python.org... > > > On Mon, 2010-08-30 at 12:38 -0700, Tim Arnold wrote: > >> Hi, > >> Is there a python users group in the Research Triangle Park area > >> (North Carolina, USA)? > > > Google "triangle python user's group" > > > thanks for the pointer.... > --Tim From tjreedy at udel.edu Sat Sep 11 13:19:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 11 Sep 2010 13:19:13 -0400 Subject: Hide DOS console for .pyc file In-Reply-To: References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: On 9/11/2010 6:32 AM, Lawrence D'Oliveiro wrote: > In message, Peter Otten wrote: > >> Lawrence D'Oliveiro wrote: >> >>> In message >>> <3a2d194c-9b34-4b84-8680-28bdfb53b975 at y3g2000vbm.googlegroups.com>, Muddy >>> Coder wrote: >>> >>>> For a quick testing purpose, I deliver .pyc files to my customer. I >>>> don't want the black DOS console appearing behind my GUI, but I have >>>> no idea how to do it. Somebody can help? Thanks! Have them run with pythonw.exe instead of python.exe. That is how IDLE does it. -- Terry Jan Reedy From wolfgang.lipp at gmail.com Sat Sep 11 14:15:32 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sat, 11 Sep 2010 11:15:32 -0700 (PDT) Subject: fast kdtree tree implementation for python 3? Message-ID: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> does anyone have a suggestion for a ready-to-go, fast kdtree implementation for python 3.1 and up, for nearest-neighbor searches? i used to use the one from numpy/scipy, but find it a pain to install for python 3. also, i'm trying to wrap the code from http://code.google.com/p/kdtree/ using cython, but i'm still getting errors. i wish stuff like kdtree, levenshtein edit distance and similar things were available in the standard library. From stef.mientki at gmail.com Sat Sep 11 14:42:47 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 11 Sep 2010 20:42:47 +0200 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? Message-ID: <4C8BCDA7.6080202@gmail.com> thanks, Stef Mientki From robert.kern at gmail.com Sat Sep 11 15:11:12 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 11 Sep 2010 14:11:12 -0500 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? In-Reply-To: <4C8BCDA7.6080202@gmail.com> References: <4C8BCDA7.6080202@gmail.com> Message-ID: SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So it's not clear what you mean when you say the database is "windows-1252". Can you be more specific? -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From stefan_ml at behnel.de Sat Sep 11 15:26:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Sep 2010 21:26:22 +0200 Subject: fast kdtree tree implementation for python 3? In-Reply-To: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: _wolf, 11.09.2010 20:15: > does anyone have a suggestion for a ready-to-go, fast kdtree > implementation for python 3.1 and up, for nearest-neighbor searches? i > used to use the one from numpy/scipy, but find it a pain to install > for python 3. The latest release is supposed to work with Py3. > also, i'm trying to wrap the code from http://code.google.com/p/kdtree/ > using cython, but i'm still getting errors. If you subscribe to the cython-users mailing list, you can ask for help there. > i wish stuff like kdtree, levenshtein edit distance and similar things > were available in the standard library. Since you're looking for an implementation, I guess you won't be the one volunteering to maintain such code in the stdlib, would you? Stefan From nawijn at gmail.com Sat Sep 11 15:56:40 2010 From: nawijn at gmail.com (Marco Nawijn) Date: Sat, 11 Sep 2010 12:56:40 -0700 (PDT) Subject: fast kdtree tree implementation for python 3? References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: On 11 sep, 20:15, _wolf wrote: > does anyone have a suggestion for a ready-to-go, fast kdtree > implementation for python 3.1 and up, for nearest-neighbor searches? i > used to use the one from numpy/scipy, but find it a pain to install > for python 3. also, i'm trying to wrap the code fromhttp://code.google.com/p/kdtree/ > using cython, but i'm still getting errors. > > i wish stuff like kdtree, levenshtein edit distance and similar things > were available in the standard library. Do you know about the kdtree implementation in biopython? I don't know if it is already available for Python 3, but for me it worked fine in Python 2.X. Marco From michael.a.powe at gmail.com Sat Sep 11 16:00:22 2010 From: michael.a.powe at gmail.com (naugiedoggie) Date: Sat, 11 Sep 2010 13:00:22 -0700 (PDT) Subject: SOLVED: Re: Trap Authentication Errors in HTTP Request References: Message-ID: On Sep 10, 12:09?pm, naugiedoggie wrote: > Hello, > > I have a script that authenticates to a web service provider to > retrieve data. ?This script provides an authentication header built in > a very basic way like this: The answer is that there is something whacked in the Windoze implementation for urllib2. It turns out that the script works fine when run in a linux console. '401' error is trapped as expected by an exception handler. In Winblows, the builtin handler for authentication is supposed to take a dump after 5 retries, but this seems to not happen. The retries continue until a recursion exception is fired. At this point the script dumps back to the console. An exception handler for Exception will catch this. Thanks. mp From michael.a.powe at gmail.com Sat Sep 11 16:29:19 2010 From: michael.a.powe at gmail.com (naugiedoggie) Date: Sat, 11 Sep 2010 13:29:19 -0700 (PDT) Subject: Bug: urllib2 basic authentication does not trap auth failure in windows? Message-ID: <3b2de754-4e12-44b5-ac91-152d1173cc80@n7g2000vbo.googlegroups.com> Hello, Is this a known issue? I have a script that authenticates to a web service. urllib2 process for authenticating for basic auth is supposed to dump out after 5 retries. Here's a note from the urllib2.py code: def http_error_auth_reqed(self, auth_header, host, req, headers): authreq = headers.get(auth_header, None) if self.retried > 5: # Don't fail endlessly - if we failed once, we'll probably # fail a second time. Hm. Unless the Password Manager is # prompting for the information. Crap. This isn't great # but it's better than the current 'repeat until recursion # depth exceeded' approach raise HTTPError(req.get_full_url(), 401, "digest auth failed", headers, None) This note is from the digest handler but the basic handler is exactly the same in the important respects. What happens in a windows console is that, in fact, the code dumps with the message 'maximum recursion depth reached.' Whereas, in the linux console, the same script exits appropriately with the trapped 401 error that authentication failed. Thanks. mp From news1234 at free.fr Sat Sep 11 16:39:39 2010 From: news1234 at free.fr (News123) Date: Sat, 11 Sep 2010 22:39:39 +0200 Subject: play sound on Ubuntu 10.4. (pulse audio?) Message-ID: <4c8be910$0$21261$426a74cc@news.free.fr> Hi, >From a python script I'd like to play sound on Ubuntu 10.4 I made two attempts: the first one is drectly writing to '/dev/audio', which works, but only if no other application plays audio (like for example amarok) The second attempt was playing audio via ALSA. The application doesn't fail, but I can hear nothing Now I don't know how to continue More details below 1.) write directly to /dev/audio ==================================== def Beep_dev_au(frequency, duration, amplitude=10): sample = 8000 half_period = int(sample/frequency/2) beep = chr(amplitude)*half_period+chr(0)*half_period beep *= int(duration*frequency/1000) audio = file('/dev/audio', 'wb') audio.write(beep) audio.close() the function works well and beeps if no other application is playing audio. When running it while for example amarok is playing audio, it will fail with: IOError: [Errno 16] Device or resource busy: '/dev/audio' 2. Accessing audio via ALSA ============================= import alsaaudio # def Beep_alsa(frequency, duration=1000, amplitude=1): sample = 44100 pcm = alsaaudio.PCM(type=alsaaudio.PCM_PLAYBACK) pcm.setchannels(1) pcm.setrate(sample) pcm.setformat(alsaaudio.PCM_FORMAT_S16_LE) half_period = int(sample/frequency/2) beep = (chr(0)+chr(amplitude))*half_period+(chr(0)*2)*half_period print "L",len(beep) beep *= int(duration*sample/half_period/2000) pcm.setperiodsize(160) for idx in xrange(0,len(beep),320): frm = beep[idx:idx+320] if len(frm) == 320: pcm.write(frm) this function doesn't raise an exception, but hear nothing. I'm a little lost. As far as I understand Ubuntu uses the pulse audio system by default. (That's probably why ALSA is not working) What would be the correct way to play audio on such a system or even better. What would be the way to detect how to play audio on a linux system without knowing ufront whether the system uses pulse, ALSA or whatever? Thanks for your suggestions. N From michael.a.powe at gmail.com Sat Sep 11 17:03:50 2010 From: michael.a.powe at gmail.com (naugiedoggie) Date: Sat, 11 Sep 2010 14:03:50 -0700 (PDT) Subject: How to Convert IO Stream to XML Document References: Message-ID: <16975673-6aad-426c-84da-f782f3457d41@k30g2000vbn.googlegroups.com> On Sep 10, 12:20?pm, jakecjacobson wrote: > I am trying to build a Python script that reads a Sitemap file and > push the URLs to a Google Search Appliance. ?I am able to fetch the > XML document and parse it with regular expressions but I want to move > to using native XML tools to do this. ?The problem I am getting is if > I use urllib.urlopen(url) I can convert the IO Stream to a XML > document but if I use urllib2.urlopen and then read the response, I > get the content but when I use minidom.parse() I get a "IOError: > [Errno 2] No such file or directory:" error Hello, This may not be helpful, but I note that you are doing two different things with your requests, and judging from the documentation, the objects returned by urllib and urllib2 openers do not appear to be the same. I don't know why you are calling urllib.urlopen(url) and urllib2.urlopen(request), but I can tell you that I have used urllib2 opener to retrieve a web services document in XML and then parse it with minidom.parse(). > > THIS WORKS but will have issues if the IO Stream is a compressed file > def GetPageGuts(net, url): > ? ? ? ? pageguts = urllib.urlopen(url) > ? ? ? ? xmldoc = minidom.parse(pageguts) > ? ? ? ? return xmldoc > > # THIS DOESN'T WORK, but I don't understand why > def GetPageGuts(net, url): > ? ? ? ? request=getRequest_obj(net, url) > ? ? ? ? response = urllib2.urlopen(request) > ? ? ? ? response.headers.items() > ? ? ? ? pageguts = response.read() Did you note the documentation says: "One caveat: the read() method, if the size argument is omitted or negative, may not read until the end of the data stream; there is no good way to determine that the entire stream from a socket has been read in the general case." No EOF marker might be the cause of the parsing problem. Thanks. mp From aahz at pythoncraft.com Sat Sep 11 17:03:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Sep 2010 14:03:58 -0700 Subject: palindrome iteration References: <49c856c4-e6f4-4e4e-b1b4-694a50e56080@f6g2000yqa.googlegroups.com> <4c778ab6$0$4778$426a74cc@news.free.fr> Message-ID: In article , Dave Angel wrote: > >def is_palindrom(s): > s = s.lower() > return s == s[::-1] To deal with "real" palindromes such as, "Madam, I'm Adam," you should probably strip all spaces and punctuation: # untested pat = re.compile(r'[a-z]') def is_palindrome(s): letters = pat.findall(s.lower()) return letters == reversed(letters) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From wolfgang.lipp at gmail.com Sat Sep 11 17:33:21 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sat, 11 Sep 2010 14:33:21 -0700 (PDT) Subject: fast kdtree tree implementation for python 3? References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: > Since you're looking for an implementation, I guess you won't be the one > volunteering to maintain such code in the stdlib, would you? this is indeed a problem. i am probably not the right one for this kind of task. however, i do sometimes feel like the standard library carries too much cruft from yesteryear. things like decent image and sound manipulation, fuzzy string comparison, fast asynchronous HTTP serving and requesting are definitely things i believe a 2010 programming language with batteries included should strive to provide. one avenue to realize this goal could be to prioritize the packages in pypi. pypi is basically a very good idea and has made things like finding and installing packages much easier. however, it is also organized like a dump pile. there are centuries old packages there few people ever use. i suggest to add aging (many old packages are good ones, but also often display a crude form of inner organization; conversely, a library not updated for a long time is unlikely to be a good answer to your problem; aging works in both directions), popularity, and community prioritization (where people vote for essential and relevant solutions) to the standard library as well as to pypi; in other words, to unify the two. batteries included is a very good idea, but there are definitely some old and leaky batteries in there. sadly, since the standard library modules are always included in each installation, there are no figures on how much needed they are after all. one would guess that were such figures available, the aifc library would come near the end of a ranked listing. if the community manages, by download figures and voting, to class packages, a much clearer picture could emerge about the importance of packages. one could put python packages into: * Class A all those packages without which python would not run (such as sys and site); into * Class B ('basics'), officially maintained packages; into * Class C ('community'), packages that are deemed important or desirable and which are open for community contributions (to make it likely they get updated soon enough whenever needed); into * Class D ('debut') all packages submitted to pypi and favorably tested, reviewed and found relevant by a certain number of people; into * Class E ('entry') all packages submitted or found elsewhere on the web, but not approved by the community; into * Class F ('failure') all packages that were proposed but never produced code, and all packages known to be not a good ideas to use (see discussion going on at http://pypi.python.org/pypi/python-cjson). Class F can help people to avoid going down the wrong path when choosing software. well this goes far beyond the kdtree question. maybe i'll make it a proposal for a PEP. From usernet at ilthio.net Sat Sep 11 17:42:42 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 11 Sep 2010 21:42:42 +0000 (UTC) Subject: play sound on Ubuntu 10.4. (pulse audio?) References: <4c8be910$0$21261$426a74cc@news.free.fr> Message-ID: On 2010-09-11, News123 wrote: > What would be the way to detect how to play audio on a linux system > without knowing ufront whether the system uses pulse, ALSA or whatever? I would suggest libao: http://www.xiph.org/ao/ and it's python bindings: http://nixbit.com/cat/multimedia/audio/libao/ From stef.mientki at gmail.com Sat Sep 11 17:45:15 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 11 Sep 2010 23:45:15 +0200 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? In-Reply-To: References: <4C8BCDA7.6080202@gmail.com> Message-ID: <4C8BF86B.6060902@gmail.com> On 11-09-2010 21:11, Robert Kern wrote: > SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So it's not clear what > you mean when you say the database is "windows-1252". Can you be more specific? I doubt that, but I'm not sure ... For some databases written by other programs and written with Python, with cursor = self.conn.cursor () self.conn.text_factory = str Can only be read back with with text_factory = str then the resulting string columns contains normal strings with windows 1252 coding, like character 0xC3 Reading these databases with text_factory = unicode, results in exceptions, when such a string with 0xC3 is encountered. As I want to switch completely to unicode, to prevent these kind of problems in the future. cheers, Stef From nhodgson at bigpond.net.au Sat Sep 11 17:58:29 2010 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sun, 12 Sep 2010 07:58:29 +1000 Subject: How Python works: What do you know about support for negative indices? In-Reply-To: <87vd6d84f7.fsf@benfinney.id.au> References: <874ody9w3v.fsf@benfinney.id.au> <87vd6d84f7.fsf@benfinney.id.au> Message-ID: <9YSio.6159$Yv.899@viwinnwfe01.internal.bigpond.com> Ben Finney: > For those who think the problem may be with the recipient's software, I > see the same annoying line-wrapping problems in the archived message > . That looks well-formatted to me and just the same as I see in a news reader. There appear to be deliberate wraps at sentence end or automatic wraps to fit <80 columns. Which lines are wrong and why are they wrong? Neil From robert.kern at gmail.com Sat Sep 11 18:07:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 11 Sep 2010 17:07:52 -0500 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? In-Reply-To: <4C8BF86B.6060902@gmail.com> References: <4C8BCDA7.6080202@gmail.com> <4C8BF86B.6060902@gmail.com> Message-ID: On 9/11/10 4:45 PM, Stef Mientki wrote: > On 11-09-2010 21:11, Robert Kern wrote: >> SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So it's not clear what >> you mean when you say the database is "windows-1252". Can you be more specific? > I doubt that, but I'm not sure ... From the documentation, it looks like SQLite does not attempt to validate the input as UTF-8 encoded, so it is possible that someone pushed in raw bytes. See "Support for UTF-8 and UTF-16" in the following page: http://www.sqlite.org/version3.html > For some databases written by other programs and > written with Python, with > cursor = self.conn.cursor () > self.conn.text_factory = str > > Can only be read back with with text_factory = str > then the resulting string columns contains normal strings with windows 1252 coding, like character 0xC3 You can probably use self.conn.text_factory = lambda x: x.decode('windows-1252') to read the data, though I've never tried to use that API myself. You will need to write a program yourself that opens one connection to your existing database for reading and another connection to another database (using the defaults) for writing. Then iterate over your tables and copy data from one database to the other. You may also be able to simply dump the database to a text file using "sqlite3 bad-database.db .dump > bad-sql.sql", read the text file into Python as a string, decode it from windows-1252 to unicode and then encode it as utf-8 and write it back out. Then use "sqlite3 good-database.db .read good-sql.sql" to create the new database. I've never tried such a thing, so it may not work. -- 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 cs at zip.com.au Sat Sep 11 18:26:40 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 12 Sep 2010 08:26:40 +1000 Subject: How Python works: What do you know about support for negative indices? In-Reply-To: References: Message-ID: <20100911222640.GA28076@cskk.homeip.net> On 10Sep2010 12:46, Daniel Fetchinson wrote: | > Raymond Hettinger writes: | >> It doesn't seem to be common knowledge when and how a[x] gets | >> translated to a[x+len(x)]. So, here's a short info post on how Python | >> supports negative indices for sequences. | > | > Thanks for this. Could you post your messages using a channel that | > doesn't arbitrarily split your paragraphs into long-short-long-short | > lines? | | It came across fine for me as well (gmail with basic html interface). | | > It makes paragraphs burdensome to read, and I skipped most of the | > message because of that. | | You might want to switch to a client where you do not have this problem. It was fine for me too, using mutt (fixed width text interface, 80 column terminal). -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A monkey has the right to copy what he sees other monkeys doing. Shouldn't humans have equivalent rights? - Alien Being From wolfgang.lipp at gmail.com Sat Sep 11 18:38:16 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sat, 11 Sep 2010 15:38:16 -0700 (PDT) Subject: fast kdtree tree implementation for python 3? References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: <746c2c3c-ba01-418c-b43c-c22c0c279d6f@c32g2000vbq.googlegroups.com> > Do you know about the kdtree implementation in biopython? I don't know > if it is already available for Python 3, but for me it worked fine in > Python 2.X. i heard they use a brute-force approach and it's slow. that's just rumors alright. also, judging from the classes list on http://www.biopython.org/DIST/docs/api/module-tree.html, you will see you can probably tune in to the latest radio moscow news using it. way too much for my needs, i just want to find the nearest neighbor on a 2D-plane. but thanks for the suggestion. From nagle at animats.com Sat Sep 11 18:53:38 2010 From: nagle at animats.com (John Nagle) Date: Sat, 11 Sep 2010 15:53:38 -0700 Subject: Static typing, Python, D, DbC In-Reply-To: <4c8bb00f@dnews.tpgi.com.au> References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> Message-ID: <4c8c086c$0$1597$742ec2ed@news.sonic.net> On 9/11/2010 9:36 AM, Lie Ryan wrote: > On 09/12/10 00:33, Bearophile wrote: > >> ---------------- >> >> Lately while I program with Python one of the D features that I most >> miss is a built-in Design By Contract (see PEP 316), because it avoids >> (or helps me to quickly find and fix) many bugs. In my opinion DbC is >> also very good used with doctests. > >> You may implement a poor's man DbC in Python like this: > > I would do it like this: Design by contract really isn't a good fit to Python. I've done proof of correctness work, and there are suitable languages for it. It needs a language where global static analysis is possible, so you can reliably tell what can changes what. John Nagle From patrick.charron.pc at gmail.com Sat Sep 11 19:58:19 2010 From: patrick.charron.pc at gmail.com (Patrick Charron) Date: Sat, 11 Sep 2010 23:58:19 +0000 (UTC) Subject: audio time-stretching? References: Message-ID: On Tue, 07 Sep 2010 15:33:55 +0000, kj wrote: > Does anyone know of a Python module for *moderate* "time-stretching"[1] > an MP3 (or AIFF) file? > > FWIW, the audio I want to time-stretch is human speech. If you are running your script on Linux you may use gstreamer(pyGST). With gstreamer you can use filter to modify audio and video file or stream. P.S. Maybe gstreamer can work on windows to From ldo at geek-central.gen.new_zealand Sat Sep 11 20:08:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 12 Sep 2010 12:08:26 +1200 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: In message , Robert Kern wrote: > On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote: > >> In message, Ian >> Kelly wrote: >> >>> And returning None on failure is dangerous, because if the programmer >>> does not take care to handle that case, the program may attempt to >>> regard it as actual data. >> >> But None *is* actual data. > > And that is exactly the reason why the Samurai Principle says to not > return None when the function fails to do what it intended to do. How can the function ?fail? when it returns what it is specified to return? From ldo at geek-central.gen.new_zealand Sat Sep 11 20:08:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 12 Sep 2010 12:08:26 +1200 Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: In message , Robert Kern wrote: > On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote: > >> In message, Ian >> Kelly wrote: >> >>> And returning None on failure is dangerous, because if the programmer >>> does not take care to handle that case, the program may attempt to >>> regard it as actual data. >> >> But None *is* actual data. > > And that is exactly the reason why the Samurai Principle says to not > return None when the function fails to do what it intended to do. How can the function ?fail? when it returns what it is specified to return? From ben+python at benfinney.id.au Sat Sep 11 20:57:36 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 12 Sep 2010 10:57:36 +1000 Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> <87vd6d84f7.fsf@benfinney.id.au> <9YSio.6159$Yv.899@viwinnwfe01.internal.bigpond.com> Message-ID: <87r5gz93sv.fsf@benfinney.id.au> Neil Hodgson writes: > There appear to be deliberate wraps at sentence end or automatic wraps > to fit <80 columns. The automatic wraps in the code presented in the message are wrong. The automatic wraps in the bullet point list are, if not wrong, at least presumably unintended. I hope that clears up what I meant in this case. The effort devoted to explaining this issue far outweighs the burden it caused initially. I'll try to be more explicit when presenting it in future, to forestall this. -- \ ?Of all classes the rich are the most noticed and the least | `\ studied.? ?John Kenneth Galbraith, _The Age of Uncertainty_, | _o__) 1977 | Ben Finney From greg.ewing at canterbury.ac.nz Sat Sep 11 21:11:17 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 12 Sep 2010 13:11:17 +1200 Subject: Queue cleanup In-Reply-To: References: <08bd9595-10b1-4b4c-9577-baa65032933a@y3g2000vbm.googlegroups.com> <4c78572c$0$28655$c3e8da3@news.astraweb.com> <7x39tz42fd.fsf@ruckus.brouhaha.com> <8eoeovF1atU1@mid.individual.net> Message-ID: <8f2nm9FrnnU1@mid.individual.net> Dennis Lee Bieber wrote: > declaimed the following > >>So maybe we need to redesign the hardware. > > Remember the iAPX-432? > http://en.wikipedia.org/wiki/Intel_iAPX_432#Garbage_collection Not quite what I had in mind. That sounds like a conventional GC algorithm that happens to be implemented in microcode. I'm thinking about ways of designing the memory itself to help with GC. Instead of putting all the smarts in the CPU, move some of them into the RAM. -- Greg From cournape at gmail.com Sat Sep 11 21:50:27 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 12 Sep 2010 10:50:27 +0900 Subject: fast kdtree tree implementation for python 3? In-Reply-To: References: <1ec504e0-800f-4f5c-b412-4c3fae6f27f9@k9g2000vbo.googlegroups.com> Message-ID: On Sun, Sep 12, 2010 at 4:26 AM, Stefan Behnel wrote: > _wolf, 11.09.2010 20:15: >> >> does anyone have a suggestion for a ready-to-go, fast kdtree >> implementation for python 3.1 and up, for nearest-neighbor searches? i >> used to use the one from numpy/scipy, but find it a pain to install >> for python 3. > > The latest release is supposed to work with Py3. The latest (1.5) of numpy does, but there is no support of scipy for python 3 yet, unless you use unreleased code. I think it is fair to say it is still rough around the edges, cheers, David From narkewoody at gmail.com Sat Sep 11 23:10:33 2010 From: narkewoody at gmail.com (narke) Date: Sun, 12 Sep 2010 03:10:33 GMT Subject: Distribute Non Library Message-ID: My simple tool writing in python get bigger and bigger and I think I'd better split my code into several files. But, unlike what in some other languages, there is no way to compile these several files into a single executable. Before I splitting my simple tool program, I just put it in /usr/local/bin and run, very simple. Now I have to consider distribute a lot of files in a whole. I know distutils can help, but I feel it is a little uncomfortable, since I am not sharing a library, I am not sharing any thing. I just want to refactory my code. Is there a better solution to my case? Can I simply create a directory in /usr/local/bin and put my script and other used files into the directory? Does distutils help in this case? Thanks in advance. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From robert.kern at gmail.com Sun Sep 12 01:20:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 12 Sep 2010 00:20:46 -0500 Subject: The Samurai Principle In-Reply-To: References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: On 9/11/10 7:08 PM, Lawrence D'Oliveiro wrote: > In message, Robert > Kern wrote: > >> On 9/10/10 5:17 PM, Lawrence D'Oliveiro wrote: >> >>> In message, Ian >>> Kelly wrote: >>> >>>> And returning None on failure is dangerous, because if the programmer >>>> does not take care to handle that case, the program may attempt to >>>> regard it as actual data. >>> >>> But None *is* actual data. >> >> And that is exactly the reason why the Samurai Principle says to not >> return None when the function fails to do what it intended to do. > > How can the function ?fail? when it returns what it is specified to return? The Samurai Principle is about what specifications and guarantees a programmer should make about his functions. It gives advice for programmers on how to specify their functions in the face of failure conditions the function itself sees. For example, a function that is supposed to fetch a record from a database given a key, a failure condition would be that the key does not exist in the database. Or the connection times out, or anything else that prevents the function from retrieving a correct record for the key. The Principle says that a programmer should specify his function such that it raises an exception to signify this failure rather than to return None. Of course, a programmer may make his functions' contracts as loose as he pleases, and thus returning None may be "correct" in the sense that it satisfies those contracts. The Principle simply advises that making such contracts is not a good idea. -- 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 mahaboobnisha at gmail.com Sun Sep 12 02:50:06 2010 From: mahaboobnisha at gmail.com (roshini begum) Date: Sat, 11 Sep 2010 23:50:06 -0700 (PDT) Subject: click ads of this site for your good, hot and brite future Message-ID: <11bb80b7-ce6d-4b77-a2c8-d7b85a3c4ebc@b4g2000pra.googlegroups.com> www.127760.blogspot.com From steve at REMOVE-THIS-cybersource.com.au Sun Sep 12 03:55:01 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Sep 2010 07:55:01 GMT Subject: The Samurai Principle References: <74587da9-8861-4400-bbd7-1ea4f8182bb1@l38g2000pro.googlegroups.com> <5f386e5e-2cb6-4acf-a46a-e7acb1d5c3f7@u4g2000prn.googlegroups.com> Message-ID: <4c8c8755$0$11113$c3e8da3@news.astraweb.com> On Sun, 12 Sep 2010 12:08:26 +1200, Lawrence D'Oliveiro wrote: >> And that is exactly the reason why the Samurai Principle says to not >> return None when the function fails to do what it intended to do. > > How can the function ?fail? when it returns what it is specified to > return? Are you trolling? On the unlikely event that you're not, if you have a function called "len", the *intent* of the function is to return the length of its argument. That's why it's called "len" rather than "raise_exception" or "return_none", say. The use of the term "fail" is entirely unexceptional here. It is normal English to say such things as "the function re.match() returns None if the regular expression fails to match" or "if we fail to acquire a lock, raise an Exception". -- Steven From stef.mientki at gmail.com Sun Sep 12 05:14:34 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 12 Sep 2010 11:14:34 +0200 Subject: is there a way to get the encoding of python file Message-ID: <4C8C99FA.2070405@gmail.com> hello, Is it possible to get the encoding of a python file from the first source line, (if there's any), after importing it ( with '__import__' ) # -*- coding: windows-1252 -*- thanks, Stef From stef.mientki at gmail.com Sun Sep 12 05:16:14 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 12 Sep 2010 11:16:14 +0200 Subject: is there a library/program that converts sqlite database from windows-1252 to utf-8 ? In-Reply-To: References: <4C8BCDA7.6080202@gmail.com> <4C8BF86B.6060902@gmail.com> Message-ID: <4C8C9A5E.7090001@gmail.com> On 12-09-2010 00:07, Robert Kern wrote: > On 9/11/10 4:45 PM, Stef Mientki wrote: >> On 11-09-2010 21:11, Robert Kern wrote: >>> SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So it's not clear what >>> you mean when you say the database is "windows-1252". Can you be more specific? >> I doubt that, but I'm not sure ... > > From the documentation, it looks like SQLite does not attempt to validate the input as UTF-8 > encoded, so it is possible that someone pushed in raw bytes. See "Support for UTF-8 and UTF-16" in > the following page: > > http://www.sqlite.org/version3.html > >> For some databases written by other programs and >> written with Python, with >> cursor = self.conn.cursor () >> self.conn.text_factory = str >> >> Can only be read back with with text_factory = str >> then the resulting string columns contains normal strings with windows 1252 coding, like >> character 0xC3 > > You can probably use > > self.conn.text_factory = lambda x: x.decode('windows-1252') > > to read the data, though I've never tried to use that API myself. > > You will need to write a program yourself that opens one connection to your existing database for > reading and another connection to another database (using the defaults) for writing. Then iterate > over your tables and copy data from one database to the other. > > You may also be able to simply dump the database to a text file using "sqlite3 bad-database.db > .dump > bad-sql.sql", read the text file into Python as a string, decode it from windows-1252 to > unicode and then encode it as utf-8 and write it back out. Then use "sqlite3 good-database.db > .read good-sql.sql" to create the new database. I've never tried such a thing, so it may not work. > Yes, I think I've to do somethhing like that, to conserve the structure and field types, it's even more complex. cheers, Stef From yoavglazner at gmail.com Sun Sep 12 05:22:10 2010 From: yoavglazner at gmail.com (Glazner) Date: Sun, 12 Sep 2010 02:22:10 -0700 (PDT) Subject: Distribute Non Library References: Message-ID: On Sep 12, 5:10?am, narke wrote: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. ?But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. ?Now I have to consider distribute > a lot of files in a whole. ?I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. ?Is there a better > solution to my case? ?Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? ?Does > distutils help in this case? > > Thanks in advance. try : python mayApp.zip myApp.zip <--> all your files + a __main__.py file as a starting point... From darragh.ssa at gmail.com Sun Sep 12 07:01:00 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 12 Sep 2010 04:01:00 -0700 (PDT) Subject: Minimal-D Message-ID: <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19@n7g2000vbo.googlegroups.com> Hey I'm creating a program called minimal-d which brings together many "things" you would otherwise use seperate to develop. These things are a file-manager,text-editor,ftp-client and sql-client. The program is currently in alpha, but it would be nice if some people tried it out and pointed out some minors,goodies or things that should/ could be appended. It is written in python 2.6 but 2.4 should be good enough, you also need wxPython 2.8. It is wriiten for linux so if you're on windows use it on your own responsability. you can download a .deb or a .tar.gz from launchpad: http://launchpad.net/d-cm my email: darragh.ssa at gmail.com further information: http://kruptology.blogspot.com/2010/09/minimal-d-02.html From thomas at jollybox.de Sun Sep 12 07:50:09 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 12 Sep 2010 13:50:09 +0200 Subject: Distribute Non Library In-Reply-To: References: Message-ID: <201009121350.10287.thomas@jollybox.de> On Sunday 12 September 2010, it occurred to narke to exclaim: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. Now I have to consider distribute > a lot of files in a whole. I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. Is there a better > solution to my case? Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? Does > distutils help in this case? Make it a package (or module), install it with distutils, and create a simple stub script that you put in /usr/local/bin to load it. From lie.1296 at gmail.com Sun Sep 12 08:00:24 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 12 Sep 2010 22:00:24 +1000 Subject: Static typing, Python, D, DbC In-Reply-To: <4c8c086c$0$1597$742ec2ed@news.sonic.net> References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> Message-ID: <4c8cc0da$1@dnews.tpgi.com.au> On 09/12/10 08:53, John Nagle wrote: > On 9/11/2010 9:36 AM, Lie Ryan wrote: >> On 09/12/10 00:33, Bearophile wrote: >> >>> ---------------- >>> >>> Lately while I program with Python one of the D features that I most >>> miss is a built-in Design By Contract (see PEP 316), because it avoids >>> (or helps me to quickly find and fix) many bugs. In my opinion DbC is >>> also very good used with doctests. >> >>> You may implement a poor's man DbC in Python like this: >> >> I would do it like this: > > Design by contract really isn't a good fit to Python. I've > done proof of correctness work, and there are suitable languages > for it. It needs a language where global static analysis is > possible, so you can reliably tell what can changes what. As long as you're not using some funny magic (e.g. monkey patching); then IMO python copes reasonably well. Though, I agree, Python probably isn't really suitable for formal proofing (the best way to assert program's correctness in python is by unittesting, which isn't a formal proof, just one that works most of the time). From bearophileHUGS at lycos.com Sun Sep 12 08:15:03 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 12 Sep 2010 05:15:03 -0700 (PDT) Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> Message-ID: <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> John Nagle: > Design by contract really isn't a good fit to Python. I have used some times the class invariant done manually, as I have shown, and it has avoided me some bugs, so I have experimentally seen you are wrong. > I've done proof of correctness work, and there are suitable languages > for it. It needs a language where global static analysis is > possible, so you can reliably tell what can changes what. I see DbC for Python as a way to avoid or fix some of the bugs of the program, and not to perform proof of correctness of the code. Even if you can't be certain, you are able reduce the probabilities of some bugs to happen. Bye, bearophile From news1234 at free.fr Sun Sep 12 08:53:31 2010 From: news1234 at free.fr (News123) Date: Sun, 12 Sep 2010 14:53:31 +0200 Subject: play sound on Ubuntu 10.4. (pulse audio?) In-Reply-To: References: <4c8be910$0$21261$426a74cc@news.free.fr> Message-ID: <4c8ccd4b$0$12648$426a74cc@news.free.fr> Hi Tim, On 09/11/2010 11:42 PM, Tim Harig wrote: > On 2010-09-11, News123 wrote: >> What would be the way to detect how to play audio on a linux system >> without knowing ufront whether the system uses pulse, ALSA or whatever? > > I would suggest libao: > http://www.xiph.org/ao/ > and it's python bindings: > http://nixbit.com/cat/multimedia/audio/libao/ Thanks a lot. Yes, libao is a nice solution. After having fixed some audio setup issues on my PC I have now the ALSA and the libao solution working. import ao pcm = ao.AudioDevice("pulse", bits=16, rate=sample, channels=1, byte_format=1) pcmdata = create_pcmdata() pcm.play(pcmdata) From sccolbert at gmail.com Sun Sep 12 09:02:56 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 12 Sep 2010 09:02:56 -0400 Subject: palindrome iteration In-Reply-To: References: <49c856c4-e6f4-4e4e-b1b4-694a50e56080@f6g2000yqa.googlegroups.com> <4c778ab6$0$4778$426a74cc@news.free.fr> Message-ID: ;) In [29]: s = 'bannab' In [30]: a = np.frombuffer(s.lower(), dtype='uint8') In [31]: np.all(a == a[::-1]) Out[31]: True In [32]: s = 'bannac' In [33]: a = np.frombuffer(s.lower(), dtype='uint8') In [34]: np.all(a == a[::-1]) Out[34]: False -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at web.de Sun Sep 12 09:04:42 2010 From: deets at web.de (Diez B. Roggisch) Date: Sun, 12 Sep 2010 15:04:42 +0200 Subject: Distribute Non Library References: Message-ID: narke writes: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. Now I have to consider distribute > a lot of files in a whole. I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. Is there a better > solution to my case? Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? Does > distutils help in this case? Consider using setuptools + console entry points. With these, you will automatically generate a shell-script to execute for your otherwise eggified and easy installable package. Diez From reddyrajendraprasad123 at gmail.com Sun Sep 12 09:32:21 2010 From: reddyrajendraprasad123 at gmail.com (Joody) Date: Sun, 12 Sep 2010 06:32:21 -0700 (PDT) Subject: jobs for all-interview tips-career info Message-ID: http://www.interviewtips-jobs.blogspot.com From cmpython at gmail.com Sun Sep 12 11:17:23 2010 From: cmpython at gmail.com (CM) Date: Sun, 12 Sep 2010 08:17:23 -0700 (PDT) Subject: Distribute Non Library References: Message-ID: On Sep 11, 11:10?pm, narke wrote: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. ?But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Sure there is. py2exe, py2app, cx_freeze, etc. From raoulbia at gmail.com Sun Sep 12 11:40:16 2010 From: raoulbia at gmail.com (Baba) Date: Sun, 12 Sep 2010 08:40:16 -0700 (PDT) Subject: analysis of algoritms References: <8762yea761.fsf@dpt-info.u-strasbg.fr> Message-ID: <8650f842-5d76-484e-a282-ab242a8ae4da@k13g2000vbq.googlegroups.com> On Sep 9, 11:22?pm, Alain Ketterlin wrote: > Baba writes: > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > > times (note that an extra step is required to terminate the for loop, > > hence n + 1 and not n executions), which will consume T4( n + 1 ) > > time." (fromhttp://en.wikipedia.org/wiki/Analysis_of_algorithms) > > > 1 ? ?get a positive integer from input > > 2 ? ?if n > 10 > > 3 ? ? ? ?print "This might take a while..." > > 4 ? ?for i = 1 to n > > 5 ? ? ? ?for j = 1 to i > > 6 ? ? ? ? ? ?print i * j > > 7 ? ?print "Done!" > > > Why does step 4 execute n+1 times? what is the exta step mentioned > > above > > In "the outer loop test [...]", the important word is _test_. Line 4 has > to test the value of i against n, which results in true n times and in > false once (where it jumps to instruction 7). > > Note that this would be true even with python loops using range(n) or > xrange(n), where the test is not an integer comparison. > > (Note also how this last remark tries to avoid complete off-topic-ness > of this discussion in this group :-) > > -- Alain. Hi Alain Thanks for the explanation! Baba From sbassi at clubdelarazon.org Sun Sep 12 11:57:24 2010 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Sun, 12 Sep 2010 12:57:24 -0300 Subject: Issue 1 of "PET: English Translation" a Python magazine is out! In-Reply-To: <201009100000.09830.ralsina@netmanagers.com.ar> References: <201009100000.09830.ralsina@netmanagers.com.ar> Message-ID: ---------- Forwarded message ---------- From: Roberto Alsina Date: Fri, Sep 10, 2010 at 12:00 AM Subject: [pyar] Issue 1 of "PET: English Translation" a Python magazine is out! To: python-announce-list at python.org, Python Argentina This magazine is a community effort. It's done by Python guys in Argentina. We are quite proud of it, and we hope you like it too. You can read Issue 1 in our webpage: http://revista.python.org.ar/1/html-en/ It's available in several different formats, including PDF, ePub, Mobipocket, HTML and FB2, and is released under a CC-by-nc-sa license. It has been translated to english by us, and we are not native speakers. Hopefully Shakespeare will not raise from his grave to slap us for grievous offense against his language! But, to save us from the Wrath of Wil, feel free to point out any mistakes and unhappy turns of phrase in the comments. Now that we have the english version out, we have *much bigger* plans for our second issue. We'll keep you posted. _______________________________________________ pyar mailing list pyar at python.org.ar http://listas.python.org.ar/listinfo/pyar PyAr - Python Argentina - Sitio web: http://www.python.org.ar/ -- Sebasti?n Bassi. Lic. en Biotecnologia. Curso de Python en un d?a: http://bit.ly/cursopython Python Book: www.py4bio.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From narkewoody at gmail.com Sun Sep 12 12:29:49 2010 From: narkewoody at gmail.com (narke) Date: Sun, 12 Sep 2010 16:29:49 GMT Subject: Distribute Non Library References: Message-ID: On 2010-09-12, Glazner wrote: > On Sep 12, 5:10?am, narke wrote: >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. ?But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. Before I splitting my simple tool program, I just put it in >> /usr/local/bin and run, very simple. ?Now I have to consider distribute >> a lot of files in a whole. ?I know distutils can help, but I feel it is >> a little uncomfortable, since I am not sharing a library, I am not >> sharing any thing. I just want to refactory my code. ?Is there a better >> solution to my case? ?Can I simply create a directory in /usr/local/bin >> and put my script and other used files into the directory? ?Does >> distutils help in this case? >> >> Thanks in advance. > > try : > python mayApp.zip > > myApp.zip <--> all your files + a __main__.py file as a starting > point... looks also not decent :( i want my tool appear as an executabe, not an zip. but thank you anyway. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From deets at web.de Sun Sep 12 12:48:09 2010 From: deets at web.de (Diez B. Roggisch) Date: Sun, 12 Sep 2010 18:48:09 +0200 Subject: Distribute Non Library References: Message-ID: narke writes: > On 2010-09-12, Glazner wrote: >> On Sep 12, 5:10?am, narke wrote: >>> My simple tool writing in python get bigger and bigger and I think I'd >>> better split my code into several files. ?But, unlike what in some other >>> languages, there is no way to compile these several files into a single >>> executable. Before I splitting my simple tool program, I just put it in >>> /usr/local/bin and run, very simple. ?Now I have to consider distribute >>> a lot of files in a whole. ?I know distutils can help, but I feel it is >>> a little uncomfortable, since I am not sharing a library, I am not >>> sharing any thing. I just want to refactory my code. ?Is there a better >>> solution to my case? ?Can I simply create a directory in /usr/local/bin >>> and put my script and other used files into the directory? ?Does >>> distutils help in this case? >>> >>> Thanks in advance. >> >> try : >> python mayApp.zip >> >> myApp.zip <--> all your files + a __main__.py file as a starting >> point... > > looks also not decent :( i want my tool appear as an executabe, not an > zip. but thank you anyway. Again: http://www.5dollarwhitebox.org/drupal/node/75 Diez From robert.kern at gmail.com Sun Sep 12 13:28:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 12 Sep 2010 12:28:32 -0500 Subject: is there a way to get the encoding of python file In-Reply-To: <4C8C99FA.2070405@gmail.com> References: <4C8C99FA.2070405@gmail.com> Message-ID: On 9/12/10 4:14 AM, Stef Mientki wrote: > hello, > > Is it possible to get the encoding of a python file from the first source line, > (if there's any), > after importing it ( with '__import__' ) > > # -*- coding: windows-1252 -*- The regular expression used to match the encoding declaration is given here: http://docs.python.org/reference/lexical_analysis.html#encoding-declarations -- 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 peterwfh2000 at gmail.com Sun Sep 12 16:17:37 2010 From: peterwfh2000 at gmail.com (PETER WONG F H (+971 50 8320722)) Date: Sun, 12 Sep 2010 13:17:37 -0700 (PDT) Subject: Required RENT Marina and JLT, 050-8320722 Message-ID: <5c65c22d-9cc1-47fa-8a66-ce682b85d4ed@t11g2000vbc.googlegroups.com> Required RENT Marina and JLT, 050-8320722 Dear I have a client who is looking to Rent apartment :- 1. Dubai Marina and JLT :- Studio ,1Bed and 2 Bed only (any building) Please send me your direct availabilities, or call me, viewing tomorrow, thank you! Peter Wong F.H ??? (????RERA BRN: 8866) Dubai Mob ?? : +971 50 83 20 722 Malaysia Mob : +6012-2956466 Fax ?? : +971 4 32 30 895 E-mail ?? : peterwfh2000 at gmail.com Company ?? : Pinky Real Estate Broker????? (????RERA ORN: 1866) Website : http://groups.google.com/group/dubai-property-club/boxsubscribe?p=FixAddr&email&_referer Note: If you want to be removed from our contacts, just reply to this e-mail with REMOVE. The content of this email is only a guide. The information, prices and availability of the properties may change without prior notice From no.email at nospam.invalid Sun Sep 12 16:28:05 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 12 Sep 2010 13:28:05 -0700 Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> Message-ID: <7x1v8y906i.fsf@ruckus.brouhaha.com> Bearophile writes: > I see DbC for Python as a way to avoid or fix some of the bugs of the > program, and not to perform proof of correctness of the code. Even if > you can't be certain, you are able reduce the probabilities of some > bugs to happen. I think DbC as envisioned by the Eiffel guy who coined (and trademarked) the term is that it's a static verification technique, marketing-speak annotating subroutines with pre- and post- conditions that can be checked with Hoare logic. Runtime checks wouldn't qualify as that. From cpblpublic at gmail.com Sun Sep 12 17:06:07 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Sun, 12 Sep 2010 14:06:07 -0700 (PDT) Subject: "pointlabel"-like function for Python: distribute text labels on a 2-d scatter plot to avoid overlapping labels Message-ID: Hello. There is a function for R (http://bm2.genes.nig.ac.jp/RGM2/ R_current/library/maptools/man/pointLabel.html) to help with placing/ locating text labels in an optimized way so as to minimise some measure of text overlap (or likely text overlap). Has anyone written or ported such a thing for Python? Thanks, c From e_d_k at yahoo.com Sun Sep 12 17:47:09 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Sun, 12 Sep 2010 14:47:09 -0700 (PDT) Subject: Static typing, Python, D, DbC In-Reply-To: <7x1v8y906i.fsf@ruckus.brouhaha.com> Message-ID: <567559.41044.qm@web120509.mail.ne1.yahoo.com> --- On Sun, 9/12/10, Paul Rubin wrote: > From: Paul Rubin > Subject: Re: Static typing, Python, D, DbC > To: python-list at python.org > Date: Sunday, September 12, 2010, 4:28 PM > Bearophile > writes: > > I see DbC for Python as a way to avoid or fix some of > the bugs of the > > program, and not to perform proof of correctness of > the code. Even if > > you can't be certain, you are able reduce the > probabilities of some > > bugs to happen. > > I think DbC as envisioned by the Eiffel guy who coined (and > trademarked) > the term is that it's a static verification technique, > marketing-speak > annotating subroutines with pre- and post- conditions that > can be > checked with Hoare logic.? Runtime checks wouldn't > qualify as that. Eiffel throws an exception when a contract is violated. That is run time behavior, not static verification. -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From cpblpublic at gmail.com Sun Sep 12 17:58:41 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Sun, 12 Sep 2010 14:58:41 -0700 (PDT) Subject: "pointlabel"-like function for Python: distribute text labels on a 2-d scatter plot to avoid overlapping labels References: Message-ID: <9c164614-952b-4fbe-b787-96a90b105f68@v6g2000prd.googlegroups.com> > measure of text overlap (or likely text overlap). ?Has anyone written > or ported such a thing for Python? Hm (talking to myself)... the link I gave above has some references, and one of those includes some python code. Seems not packaged up yet for plots, but may be close: http://meta.wikimedia.org/wiki/Map_generator#Placing_labels Anything better? c From paul.hermeneutic at gmail.com Sun Sep 12 18:08:56 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Sun, 12 Sep 2010 16:08:56 -0600 Subject: Current install methodolgy eggs? Message-ID: <8f51bqFrflU1@mid.individual.net> What is the currently favored installation process for Python applications? The last time I looked, it was eggs. Is that still true? Is there any integration of eggs and handling into the base Python distribution? Is PEP 376 intended for applications written in Python, or just the Python distribution? Any good links to source of information. I would like to instill the habit of using a decent install process for even the smallest of utilities. From aahz at pythoncraft.com Sun Sep 12 18:33:22 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Sep 2010 15:33:22 -0700 Subject: How Python works: What do you know about support for negative indices? References: <87vd6d84f7.fsf@benfinney.id.au> <9YSio.6159$Yv.899@viwinnwfe01.internal.bigpond.com> <87r5gz93sv.fsf@benfinney.id.au> Message-ID: In article <87r5gz93sv.fsf at benfinney.id.au>, Ben Finney wrote: >Neil Hodgson writes: >> >> There appear to be deliberate wraps at sentence end or automatic wraps >> to fit <80 columns. > >The automatic wraps in the code presented in the message are wrong. The >automatic wraps in the bullet point list are, if not wrong, at least >presumably unintended. That is considerably different from your original claim that the post contained formatting that was "long-short-long-short", aka comb formatting. >I hope that clears up what I meant in this case. The effort devoted to >explaining this issue far outweighs the burden it caused initially. I'll >try to be more explicit when presenting it in future, to forestall this. s/explicit/accurate/ Had you noted that some lines of code were wrapped short, I would have agreed with you, but I also would have noted that it's not a big deal. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ben+python at benfinney.id.au Sun Sep 12 18:40:02 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 13 Sep 2010 08:40:02 +1000 Subject: Current install methodolgy eggs? References: <8f51bqFrflU1@mid.individual.net> Message-ID: <8762ya8u2l.fsf@benfinney.id.au> Paul Watson writes: > What is the currently favored installation process for Python > applications? ?python ./setup.py install?, using the standard library's Distutils library. Other third-party libraries build on top of that and are generally backward-compatible. > The last time I looked, it was eggs. Is that still true? I don't think eggs were ever the favoured distribution method. They are one *option* provided by Setuptools, but even then a so-called ?sdist? (source distribution) is the favoured distribution format, installed using the above command. > Any good links to source of information. I would like to instill the > habit of using a decent install process for even the smallest of > utilities. This is a dream shared by many, but Distutils has much improvement to be done yet. Recently ? the past couple of years ? a lot of progress has been made on this front, and Python 3.x is getting many of the benefits; look up the ?Distutils2? efforts for more. -- \ ?That's all very good in practice, but how does it work in | `\ *theory*?? ?anonymous | _o__) | Ben Finney From nagle at animats.com Sun Sep 12 18:57:28 2010 From: nagle at animats.com (John Nagle) Date: Sun, 12 Sep 2010 15:57:28 -0700 Subject: Current install methodolgy eggs? In-Reply-To: <8762ya8u2l.fsf@benfinney.id.au> References: <8f51bqFrflU1@mid.individual.net> <8762ya8u2l.fsf@benfinney.id.au> Message-ID: <4c8d5ae1$0$1588$742ec2ed@news.sonic.net> On 9/12/2010 3:40 PM, Ben Finney wrote: > Paul Watson writes: > >> What is the currently favored installation process for Python >> applications? > > ?python ./setup.py install?, using the standard library's Distutils > library. > > Other third-party libraries build on top of that and are generally > backward-compatible. > >> The last time I looked, it was eggs. Is that still true? > > I don't think eggs were ever the favoured distribution method. They are > one *option* provided by Setuptools, but even then a so-called ?sdist? > (source distribution) is the favoured distribution format, installed > using the above command. > >> Any good links to source of information. I would like to instill the >> habit of using a decent install process for even the smallest of >> utilities. > > This is a dream shared by many, but Distutils has much improvement to be > done yet. Recently ? the past couple of years ? a lot of progress has > been made on this front, and Python 3.x is getting many of the benefits; > look up the ?Distutils2? efforts for more. There's some discussion of a common installer on the Python development group, but that's probably the wrong approach. A more effective approach would be something that takes a standard "setup.py" file and wraps it in a Windows installer file, an RPM file, or whatever the platform uses as standard. The "eggs" system never worked very well. It made too many assumptions about where various things were, and when it guessed wrong, you were stuck. John Nagle From contact at xavierho.com Sun Sep 12 19:03:46 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 13 Sep 2010 09:03:46 +1000 Subject: Current install methodolgy eggs? In-Reply-To: <8762ya8u2l.fsf@benfinney.id.au> References: <8f51bqFrflU1@mid.individual.net> <8762ya8u2l.fsf@benfinney.id.au> Message-ID: On 13 September 2010 08:40, Ben Finney > wrote: > Paul Watson writes: > > > What is the currently favored installation process for Python > > applications? > > ?python ./setup.py install?, using the standard library's Distutils > library. > I thought it was python setup.py install or ./setup.py install if you had the permissions set correctly. What distro are you using? Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From bearophileHUGS at lycos.com Sun Sep 12 19:32:29 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 12 Sep 2010 16:32:29 -0700 (PDT) Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> <7x1v8y906i.fsf@ruckus.brouhaha.com> Message-ID: <0151fd8a-87cd-4017-9a63-c9d8be0696ba@a19g2000vbi.googlegroups.com> Paul Rubin: > I think DbC as envisioned by the Eiffel guy who coined (and trademarked) > the term is that it's a static verification technique, marketing-speak > annotating subroutines with pre- and post- conditions that can be > checked with Hoare logic. Runtime checks wouldn't qualify as that. The implementations of DbC in D and C# run their tests at run-time (but in theory an external tool may find a way to perform part of those tests at compile-time). A full implementation of DbC contains several other things beside preconditions and postconditions, see http://www.python.org/dev/peps/pep-0316/ (it misses few things like loop invariants and loop variants). For me DbC is useful almost as unit-testing (I use them at the same time), this is why in the original post I have said it's one of the things I miss most in Python. Bye, bearophile From paul.hermeneutic at gmail.com Sun Sep 12 20:05:13 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Sun, 12 Sep 2010 18:05:13 -0600 Subject: Current install methodolgy eggs? In-Reply-To: <8762ya8u2l.fsf@benfinney.id.au> References: <8f51bqFrflU1@mid.individual.net> <8762ya8u2l.fsf@benfinney.id.au> Message-ID: <8f585sFu3rU1@mid.individual.net> On 2010-09-12 16:40, Ben Finney wrote: > This is a dream shared by many, but Distutils has much improvement to be > done yet. Recently ? the past couple of years ? a lot of progress has > been made on this front, and Python 3.x is getting many of the benefits; > look up the ?Distutils2? efforts for more. Many thanks for your comments, Ben. Looks like I should learn distutils well. I see the distutils2 work going on. I hope it is designed to work with Python 2.x. That would help it get some traction in existing packages. Most platforms have an installation methodology. Oracle Solaris (yea, hard for me to get use to as well) has pkgadd. Microsoft has the .msi installer. Do you think it would be possible to create a toolset that would produce installation kits in each of these forms? That would make the install conform with the standard platform installer. Is this worthwhile thinking about? From narkewoody at gmail.com Sun Sep 12 21:22:17 2010 From: narkewoody at gmail.com (narke) Date: Mon, 13 Sep 2010 01:22:17 GMT Subject: Distribute Non Library References: Message-ID: On 2010-09-12, Diez B. Roggisch wrote: > narke writes: > >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. Before I splitting my simple tool program, I just put it in >> /usr/local/bin and run, very simple. Now I have to consider distribute >> a lot of files in a whole. I know distutils can help, but I feel it is >> a little uncomfortable, since I am not sharing a library, I am not >> sharing any thing. I just want to refactory my code. Is there a better >> solution to my case? Can I simply create a directory in /usr/local/bin >> and put my script and other used files into the directory? Does >> distutils help in this case? > > Consider using setuptools + console entry points. With these, you will > automatically generate a shell-script to execute for your otherwise > eggified and easy installable package. > > Diez That's really attracting. I will try, thanks! -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke test post From narkewoody at gmail.com Sun Sep 12 21:23:04 2010 From: narkewoody at gmail.com (narke) Date: Mon, 13 Sep 2010 01:23:04 GMT Subject: Distribute Non Library References: Message-ID: On 2010-09-12, CM wrote: > On Sep 11, 11:10?pm, narke wrote: >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. ?But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. > > Sure there is. py2exe, py2app, cx_freeze, etc. Also good solution! Thanks for the help. And, cx_freeze looks even workable on my Linux. Great. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke test post From ldo at geek-central.gen.new_zealand Sun Sep 12 21:23:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 13 Sep 2010 13:23:53 +1200 Subject: Minimal-D References: <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19@n7g2000vbo.googlegroups.com> Message-ID: In message <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19 at n7g2000vbo.googlegroups.com>, Kruptein wrote: > Hey I'm creating a program called minimal-d which brings together many > "things" you would otherwise use seperate to develop. These things > are a file-manager,text-editor,ftp-client and sql-client. We have that already. It?s called a ?Linux distro?. From Dave Sun Sep 12 22:24:22 2010 From: Dave (Dave) Date: Sun, 12 Sep 2010 21:24:22 -0500 Subject: Anyone using python on Mint Linux ? Message-ID: Just read that Mint is a fine version of Debian Linux. Any comments about python on this ? Thanks, Dave WB3DWE From no.email at nospam.invalid Sun Sep 12 22:50:23 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 12 Sep 2010 19:50:23 -0700 Subject: Static typing, Python, D, DbC References: Message-ID: <7x39tenyq8.fsf@ruckus.brouhaha.com> Ed Keith writes: >> I think DbC as envisioned by the Eiffel guy... >> the term is that it's a static verification technique, > > Eiffel throws an exception when a contract is violated. That is run > time behavior, not static verification. The runtime checks are for when static analysis hasn't been supplied (that is usually a partly manual process). DBC is always intended to be statically verified as I understand it. Doing it at runtime is just a hackish fallback. From xahlee at gmail.com Sun Sep 12 23:14:09 2010 From: xahlee at gmail.com (Xah Lee) Date: Sun, 12 Sep 2010 20:14:09 -0700 (PDT) Subject: reddit = porn fodder Message-ID: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> reddit = porn fodder Didn't realize, but Reddit is now a porn fodder. http://www.reddit.com/r/LegalTeens/ http://www.reddit.com/r/highheels http://www.reddit.com/r/gonewild/ Its traffic also seems to incleased 10 times since 2008. See: Computer Language Websites Popularity. >From my experience, if you just add one page that is remotely related to sex, that page's traffic will eclipse your other hundred pages. (See: Moving Porn out of XahLee.org.) So, i wonder what percentage of reddit traffic is porn related. (it also means more $$$.) Note that there's lots of semi-porn related sites that became huge sucess. These sites typically start by a teen as teen drivel fodder, where almost 100% content is naked chicks or lurid pictures. Then, when they become big, either the luridness gets reduced or moved out, and or the site become more respectable as some digital age trend setter. For example: 4chan, Fark.com. In fact, facebook started that way. See: Facebook's Ethics. note that reddit was originally somewhat a site for programers, written in common lisp. For links, see: http://xahlee.blogspot.com/2010/09/reddit-porn-fodder.html Xah ? xahlee.org ? From aahz at pythoncraft.com Mon Sep 13 00:00:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Sep 2010 21:00:28 -0700 Subject: Anyone using python on Mint Linux ? References: Message-ID: In article , wrote: > >Just read that Mint is a fine version of Debian Linux. >Any comments about python on this ? Why would there be? Either it works or it's broken, and given that it's Debian, I'd certainly bet that Python works. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From debatem1 at gmail.com Mon Sep 13 00:41:13 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 12 Sep 2010 21:41:13 -0700 Subject: Anyone using python on Mint Linux ? In-Reply-To: References: Message-ID: On Sun, Sep 12, 2010 at 7:24 PM, wrote: > Just read that Mint is a fine version of Debian Linux. > Any comments about python on this ? > Thanks, ?Dave WB3DWE I used to do some of my development on Mint. Was happy with it then, and I suspect that the same would be true now. Geremy Condra From alf.p.steinbach+usenet at gmail.com Mon Sep 13 00:46:48 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 13 Sep 2010 06:46:48 +0200 Subject: Static typing, Python, D, DbC In-Reply-To: <7x39tenyq8.fsf@ruckus.brouhaha.com> References: <7x39tenyq8.fsf@ruckus.brouhaha.com> Message-ID: * Paul Rubin, on 13.09.2010 04:50: > Ed Keith writes: >>> I think DbC as envisioned by the Eiffel guy... >>> the term is that it's a static verification technique, >> >> Eiffel throws an exception when a contract is violated. That is run >> time behavior, not static verification. > > The runtime checks are for when static analysis hasn't been supplied > (that is usually a partly manual process). DBC is always intended to be > statically verified as I understand it. Doing it at runtime is just a > hackish fallback. DBC can't in generally be statically checked. E.g. a precondition of a routine might be that its argument is a sorted array. So regarding the nature of the checks it's not hopelessly incompatible with Python. Cheers, - Alf -- blog at From nagle at animats.com Mon Sep 13 00:47:26 2010 From: nagle at animats.com (John Nagle) Date: Sun, 12 Sep 2010 21:47:26 -0700 Subject: Static typing, Python, D, DbC In-Reply-To: <7x39tenyq8.fsf@ruckus.brouhaha.com> References: <7x39tenyq8.fsf@ruckus.brouhaha.com> Message-ID: <4c8dacea$0$1640$742ec2ed@news.sonic.net> On 9/12/2010 7:50 PM, Paul Rubin wrote: > Ed Keith writes: >>> I think DbC as envisioned by the Eiffel guy... >>> the term is that it's a static verification technique, >> >> Eiffel throws an exception when a contract is violated. That is run >> time behavior, not static verification. > > The runtime checks are for when static analysis hasn't been supplied > (that is usually a partly manual process). DBC is always intended to be > statically verified as I understand it. Doing it at runtime is just a > hackish fallback. Right. Static verification is finally a production technology. All signed Windows 7 drivers must pass Microsoft's static checker, which checks that they don't have bad pointers and call all the driver APIs correctly. That's real "design by contract". It's not that relevant to Python, where you can't crash the underlying system. But it really matters in languages where you can. John Nagle From cloudcontrollers at gmail.com Mon Sep 13 00:53:04 2010 From: cloudcontrollers at gmail.com (cloudcontrol) Date: Sun, 12 Sep 2010 21:53:04 -0700 (PDT) Subject: Python script for MySQL Passwords Unreliable on first boot (rc.local) Message-ID: The script below works great when logged in as root and run from the command line, but when run at first boot using /etc/rc.local in Ubuntu 10.04, it fails about 25% of the time- the system root, mysql root and some mysql user passwords are set correctly, but one will fail with console log reporting standard mysql login error: "ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: YES)" Is there something about running python scripts from init jobs that I should account for, such as an environment variable? #!/usr/bin/env python # Udates system & MySQL root passwords on first boot files = ['/home/ubuntu/passwords','/opt/data1/alfresco/extensions/ extension/alfresco-global.properties','/opt/data/etc/mysql/ debian.cnf','/home/ubuntu/duncil'] userpasswords = {'root':'ROOTPASSWORD'} mysqlpasswords = {'root':'MYSQLPASSWORD','alfresco':'alfrescoPASSWORD','debian-sys- maint':'debian-sys-maintPASSWORD'} otherpasswords = ['OTHERPASSWORD'] log = '/var/log/firstrun' import random, string import crypt import re from subprocess import PIPE, Popen def getsalt(chars = string.letters + string.digits): # generate a random 2-character 'salt' return random.choice(chars) + random.choice(chars) def getpwd(chars = string.letters + string.digits, len = 12): retval = ""; for i in range(0, len): # generate 12 character alphanumeric password retval += random.choice(chars) return retval def replace_pass(filename): handle = open(filename, 'r') hbuf = handle.read() handle.close() for placeholder, password in pdict.iteritems(): hbuf = re.sub(placeholder, password, hbuf) try: # Output file handle = open(filename, 'w') handle.write(hbuf) handle.close() except: pass #logh.write('failed to update ' + filename + "\n") #logh.write('maybe you don\'t have permision to write to it? \n') logh = open(log, "a") logh.write("Starting...\n") # Generate passwords pdict = {} for user, placeholder in userpasswords.iteritems(): syspass = getpwd() Popen(['usermod', '--password', crypt.crypt(syspass, getsalt()), user]) logh.write(placeholder + ": User " + user + " --> " + syspass + "\n") pdict[placeholder] = syspass # What's the MySQL Root password placeholder? mplace = mysqlpasswords['root'] for user, placeholder in mysqlpasswords.iteritems(): mpass = getpwd() if (("root" in mysqlpasswords) and (mysqlpasswords['root'] in pdict)): mrootpass = pdict[mysqlpasswords['root']] else: mrootpass = "" Popen(['mysql', '-uroot', "--password=" + mrootpass, "-e", "UPDATE user SET Password = PASSWORD('" + mpass + "') WHERE User = '" + user + "';FLUSH PRIVILEGES;","mysql"]) logh.write(placeholder + ": MySQL " + user + " --> " + mpass + "\n") pdict[placeholder] = mpass for placeholder in otherpasswords: opass = getpwd() logh.write(placeholder + ": " + opass + "\n") pdict[placeholder] = opass # Update passwords for file in files: logh.write("Replacing placeholders in " + file + "\n") replace_pass(file) logh.write("Finished\n") logh.close From darragh.ssa at gmail.com Mon Sep 13 01:42:17 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 12 Sep 2010 22:42:17 -0700 (PDT) Subject: Minimal-D References: <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19@n7g2000vbo.googlegroups.com> Message-ID: <798a0db8-0ef0-4f35-9427-b713fec45914@g10g2000vbc.googlegroups.com> On Sep 13, 3:23?am, Lawrence D'Oliveiro wrote: > In message > <383a7e4b-819f-4bdf-9b0c-e22baa9b6... at n7g2000vbo.googlegroups.com>, Kruptein > wrote: > > > Hey I'm creating a program called minimal-d which brings together many > > "things" you would otherwise use seperate to develop. ?These things > > are a file-manager,text-editor,ftp-client and sql-client. > > We have that already. It?s called a ?Linux distro?. Well I didn't know that although I use it perhaps daily? From esj at harvee.org Mon Sep 13 02:01:00 2010 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 13 Sep 2010 02:01:00 -0400 Subject: Static typing, Python, D, DbC In-Reply-To: <7x1v8y906i.fsf@ruckus.brouhaha.com> References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> <7x1v8y906i.fsf@ruckus.brouhaha.com> Message-ID: <4C8DBE1C.6040705@harvee.org> On 9/12/2010 4:28 PM, Paul Rubin wrote: > Bearophile writes: >> I see DbC for Python as a way to avoid or fix some of the bugs of the >> program, and not to perform proof of correctness of the code. Even if >> you can't be certain, you are able reduce the probabilities of some >> bugs to happen. > I think DbC as envisioned by the Eiffel guy who coined (and trademarked) > the term is that it's a static verification technique, marketing-speak > annotating subroutines with pre- and post- conditions that can be > checked with Hoare logic. Runtime checks wouldn't qualify as that. Programming by contract as popularized by Bertrand Meyer (that Eiffel guy) was designed for run-time checks because that's when errors show. Programming by contract is based on Dijkstra's weakest precondition work. http://www.scss.tcd.ie/Edsko.de.Vries/talks/weakest_precondition.pdf During the last five years before my hands went bad, I spent significant amount of time working with formal methods and simpler concepts such as design by contract. Design by contract made the last five years of my programming career the most rewarding it had ever been. It was nice to finally write code that was significantly, and measurably better than those coded using Brown 25 (another fine product from Uranus)[1]. one of the common mistakes have seen about programming by contract or design by contract is that people assume it's a proof of correctness. It's not, it's an experiential proof that the code is executing correctly to the extent that you've characterized the pre-and post-conditions. Formal proofs are considered a dead-end as far as I can tell but it's been a good number of years since I've really investigated that particular domain. If my opinion is worth anything to anyone, I would highly recommend adopting some form of programming by contract in everything you write. use the properties that Dijkstra taught us with the weakest precondition to test only what you need to test. If you are careless, assertions can build up to a significant percentage of the code base and Slow execution. the argument for dealing with this, last time I looked, was that you turn off assertions when your code is "running". This logic is flawed because bugs exist and will assert themselves at the worst possible time which usually means after you turned off the assertions. Personally, I see assertions as another form of defensive programming. If you can define preconditions as excluding bad data, then your mainline body becomes faster/smaller. Anyway, this debate was going on circa 1990 and possibly even earlier when Dykstra wrote his first papers. Consider me a double plus vote for strong programming by contract capability in Python. If I can ever get programming by voice working in a reasonable way, I might even be able to use it. :-) PS, to explain Brown 25 in case you weren't watching "those damn kids" comedy movies in the 1970s with a bunch of very stoned friends. Thank God for campus buses keeping us out of cars. [1] http://www.youtube.com/watch?v=008BPUdQ1XA From chris.mahan at gmail.com Mon Sep 13 02:18:13 2010 From: chris.mahan at gmail.com (Christopher Mahan) Date: Sun, 12 Sep 2010 23:18:13 -0700 Subject: Meeting in October Message-ID: Meeting in October? Chris Mahan (818) 671-1709 http://christophermahan.com/ chris.mahan at gmail.com http://twitter.com/chris_mahan From mientki at nonet.com Mon Sep 13 04:02:00 2010 From: mientki at nonet.com (Marc Mientki) Date: Mon, 13 Sep 2010 10:02:00 +0200 Subject: reddit = porn fodder In-Reply-To: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> References: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> Message-ID: Am 13.09.2010 05:14, schrieb Xah Lee: > note that reddit was originally somewhat a site for programers, > written in common lisp. It is still for Lisp programmers: http://www.reddit.com/r/lisp/ regards Marc From ldo at geek-central.gen.new_zealand Mon Sep 13 04:24:50 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 13 Sep 2010 20:24:50 +1200 Subject: Minimal-D References: <383a7e4b-819f-4bdf-9b0c-e22baa9b6d19@n7g2000vbo.googlegroups.com> <798a0db8-0ef0-4f35-9427-b713fec45914@g10g2000vbc.googlegroups.com> Message-ID: In message <798a0db8-0ef0-4f35-9427- b713fec45914 at g10g2000vbc.googlegroups.com>, Kruptein wrote: > On Sep 13, 3:23 am, Lawrence D'Oliveiro > wrote: > >> In message >> <383a7e4b-819f-4bdf-9b0c-e22baa9b6... at n7g2000vbo.googlegroups.com>, >> Kruptein wrote: >> >> > Hey I'm creating a program called minimal-d which brings together many >> > "things" you would otherwise use seperate to develop. These things >> > are a file-manager,text-editor,ftp-client and sql-client. >> >> We have that already. It?s called a ?Linux distro?. > > Well I didn't know that although I use it perhaps daily? You didn?t know that all those features are just a checkbox in the package manager away? From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 13 05:39:09 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 13 Sep 2010 11:39:09 +0200 Subject: Refactoring similar subclasses In-Reply-To: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> References: <4c8ae2ad$0$11111$c3e8da3@news.astraweb.com> Message-ID: <4c8df13d$0$23080$426a34cc@news.free.fr> Steven D'Aprano a ?crit : > I have some code that currently takes four different classes, A, B, C and > D, and subclasses each of them in the same way: > > class MyA(A): > def method(self, x): > result = super(MyA, self).method(x) > if result == "spam": > return "spam spam spam" > return result > # many more methods overloaded > > > class MyB(B): > def method(self, x): > result = super(MyB, self).method(x) > if result == "spam": > return "spam spam spam" > return result > # many more methods overloaded > If that's really what your code is doing - I mean, calling the super() implementation, checking the result and eventually returning something else instead - then a simple decorator might be enough... Could even be "applied" by the metaclass. From bearophileHUGS at lycos.com Mon Sep 13 06:03:16 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Mon, 13 Sep 2010 03:03:16 -0700 (PDT) Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> <7x1v8y906i.fsf@ruckus.brouhaha.com> Message-ID: <53f4134f-70c5-4b3c-bae6-46e94f9d7d0f@j19g2000vbh.googlegroups.com> John Nagle: > All signed Windows 7 drivers must pass Microsoft's static checker, > which checks that they don't have bad pointers and call all the > driver APIs correctly. I didn't know this, thank you. I'll read more about this topic. ---------------- Eric S. Johansson: > If you are careless, assertions can build up to a > significant percentage of the code base and Slow execution. the argument for > dealing with this, last time I looked, was that you turn off assertions when > your code is "running". This logic is flawed because bugs exist and will assert > themselves at the worst possible time which usually means after you turned off > the assertions. These are real problems. In some situations the code is "fast enough" even with those runtime tests, so in those situations it's better to keep them active even in release builds or when you use the program (this is often true for small script-like programs). But in some situations you want a faster final program. Running the run-time contracts only when you test the code and removing them when you run the program for real sounds silly or dangerous. But life is made of trade-offs, and running those contracts during testing is better than _never_ running them. In practice if your tests are done well enough (they are similar to the real usage of the program), the contracts are able to catch most of the bugs anyway before the release build. The run-time contracts may slow down the code, but there are few ways to reduce this problem. You have to write your contracts taking care of not changing the computational complexity of the routine/method they guard (so you usually don't want to perform a O(n) test for a routine with O(n ln n) worst-case complexity). You run your tests often, so if some tests are too much slow you see it soon and you may fix the problem (the same is true for slow unit tests). In D there are several ways to "layer" the work you perform at runtime, there is not just the release build and test build. You have the version and debug statements, you may use them inside DbC contracts too. So in normal test builds I use faster contracts, but if I spot a bug I lower the debug level and I recompile the D code, activating heavier tests, to better spot where the bug is. One good thing of DbC is that when the "density" of presence of contracts in your programs gets higher of some threshold, most of the bugs present in the code show themselves up as failed assertions/contracts. To me it seems related to percolation theory :-) (http://en.wikipedia.org/ wiki/Percolation_threshold ). In D you may also use enforce(), that's essentially a camouflaged throw/raise statement, if you use it outside DbC contracts, they are tests that run even in release builds when your contracts are disabled. Bye, bearophile From tartley at tartley.com Mon Sep 13 06:13:57 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Mon, 13 Sep 2010 03:13:57 -0700 (PDT) Subject: Hide DOS console for .pyc file References: <3a2d194c-9b34-4b84-8680-28bdfb53b975@y3g2000vbm.googlegroups.com> Message-ID: <6b02e793-521c-4514-b8a1-ec9df1ecc43c@q26g2000vbn.googlegroups.com> On Sep 11, 11:32?am, Lawrence D'Oliveiro wrote: > In message , Peter Otten wrote: > > > Lawrence D'Oliveiro wrote: > > >> In message > >> <3a2d194c-9b34-4b84-8680-28bdfb53b... at y3g2000vbm.googlegroups.com>, Muddy > >> Coder wrote: > > >>> For a quick testing purpose, I deliver .pyc files to my customer. I > >>> don't want the black DOS console appearing behind my GUI, but I have > >>> no idea how to do it. Somebody can help? Thanks! > > >> Don?t run it on Windows. > > > If you switch the OS for every minor problem you'll run out of operating > > systems pretty soon... > > Not if you choose a suitably flexible and portable one to begin with. It isn't the OP choosing, it's his client. Now, I dislike aspects of Windows as much as anybody, but even I can see that dictating which OS your client is allowed to use if they want to run your program is sometimes not a viable option. From kinglabs.in at gmail.com Mon Sep 13 08:45:36 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Mon, 13 Sep 2010 05:45:36 -0700 (PDT) Subject: WMI in Python Message-ID: Hi All, I am new to programming and python, Being a system administrator I have chose Inventory (Software & Hardware ) as my first project. I would like to know experts advice on the best way to build the same using python. I would like to this tool to evolve into full fledge application. I would like to collect the complete information of system hardware & and also software installed from registry and add/remove program and feed this data into database. Regards, KINGLABS From ed at leafe.com Mon Sep 13 09:14:15 2010 From: ed at leafe.com (Ed Leafe) Date: Mon, 13 Sep 2010 09:14:15 -0400 Subject: ANN: Dabo 0.9.3 released Message-ID: It's been a while, but we've finally released version 0.9.3 of the Dabo framework! Since Dabo has a Web Update feature that lets developers receive regular updates between releases, the changes won't be too big for most current users of the framework, but compared to the 0.9.2 release, lots has been fixed and improved! Full release notes are at: http://svn.dabodev.com/dabo/tags/dabo-0.9.3/ChangeLog ...but here are the major changes since 0.9.2: - integration of the native Python logging module for all Dabo logging - support for DES3 cryptography in Dabo encryption - changed all pathing to be relative to the app's HomeDirectory - full parameterization of SQL calls - addition of the dRichTextBox control - improvement of unicode support with the dabo.lib.ustr() method You can grab the latest version, as always, from http://dabodev.com/download -- Ed Leafe From rodrick.brown at gmail.com Mon Sep 13 09:42:32 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Mon, 13 Sep 2010 09:42:32 -0400 Subject: WMI in Python In-Reply-To: References: Message-ID: <702BE5F2-EE8B-41BE-9BD4-847693CC20FC@gmail.com> The easiest way to do this is to use the native OS tools readily available to do the collection and log to a central location or if possible shared location accessible by all systems, once you have all the data you want to feed into your RDBMS you could easily parse these logs using python and the native db access module. I hope this give you a pointer. Sent from my iPhone 4. On Sep 13, 2010, at 8:45 AM, KING LABS wrote: > Hi All, > > I am new to programming and python, Being a system administrator I > have chose Inventory (Software & Hardware ) as my first project. > > I would like to know experts advice on the best way to build the same > using python. I would like to this tool to evolve into full fledge > application. > > I would like to collect the complete information of system hardware & > and also software installed from registry and add/remove program and > feed this data into database. > > Regards, > KINGLABS > -- > http://mail.python.org/mailman/listinfo/python-list From kinglabs.in at gmail.com Mon Sep 13 09:51:49 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Mon, 13 Sep 2010 06:51:49 -0700 (PDT) Subject: WMI in Python References: Message-ID: <90bf3587-941a-460b-ab48-9b02d6c830f4@x20g2000pro.googlegroups.com> On Sep 13, 6:42?pm, Rodrick Brown wrote: > The easiest way to do this is to use the native OS tools readily available to do the collection and log to a central location or if possible shared location accessible by all systems, once you have all the data you want to feed into your RDBMS you could easily parse these logs using python and the native db access module. > > I hope this give you a pointer. > > Sent from my iPhone 4. > > On Sep 13, 2010, at 8:45 AM, KING LABS wrote: > > > > > Hi All, > > > I am new to programming and python, Being a system administrator I > > have chose Inventory (Software & Hardware ) as my first project. > > > I would like to know experts advice on the best way to build the same > > using python. I would like to this tool to evolve into full fledge > > application. > > > I would like to collect the complete information of system hardware & > > and also software ?installed from registry and add/remove program and > > feed this data into database. > > > Regards, > > KINGLABS > > -- > >http://mail.python.org/mailman/listinfo/python-list I am trying to learn Python programming. Since I need a custom inventory management tool for my work place. I am considering it as a project in the process of learning Python. I am not looking for easiest way of doing things. I am considering using Python . Also I would need to build a setup of the tool for easy installation. Hope I am clear this time Regards, KINGLABS From ed at leafe.com Mon Sep 13 10:29:44 2010 From: ed at leafe.com (Ed Leafe) Date: Mon, 13 Sep 2010 10:29:44 -0400 Subject: WMI in Python In-Reply-To: <90bf3587-941a-460b-ab48-9b02d6c830f4@x20g2000pro.googlegroups.com> References: <90bf3587-941a-460b-ab48-9b02d6c830f4@x20g2000pro.googlegroups.com> Message-ID: <6F97D7E6-3109-446B-8C5B-9EC71B8F02D1@leafe.com> On Sep 13, 2010, at 9:51 AM, KING LABS wrote: > I am trying to learn Python programming. Since I need a custom > inventory management tool for my work place. I am considering it as a > project in the process of learning Python. > > I am not looking for easiest way of doing things. > I am considering using Python . Also I would need to build a setup of > the tool for easy installation. > > Hope I am clear this time If you're looking for a rich client (i.e., desktop) application, and not a web app, you should check out Dabo: http://dabodev.com. We have hundreds of developers around the world using Dabo to build many different kinds of business applications. -- Ed Leafe From no.email at nospam.invalid Mon Sep 13 11:05:43 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 13 Sep 2010 08:05:43 -0700 Subject: Static typing, Python, D, DbC References: <809c5d31-564d-4242-a200-290f293c4745@c16g2000vbp.googlegroups.com> <4c8bb00f@dnews.tpgi.com.au> <4c8c086c$0$1597$742ec2ed@news.sonic.net> <4bc2b776-0461-45b7-81e7-1f0979773bef@c16g2000vbp.googlegroups.com> <7x1v8y906i.fsf@ruckus.brouhaha.com> <53f4134f-70c5-4b3c-bae6-46e94f9d7d0f@j19g2000vbh.googlegroups.com> Message-ID: <7x4odt65vc.fsf@ruckus.brouhaha.com> Bearophile writes: > But in some situations you want a faster final program. Running the > run-time contracts only when you test the code and removing them when > you run the program for real sounds silly or dangerous. But life is > made of trade-offs, and running those contracts during testing is > better than _never_ running them. For some programs, having the contracts fail during running "for real" is intolerable, so if you're not ready to remove the runtime tests, then program is not ready to run for real. The Wikipedia article about DBC http://en.wikipedia.org/wiki/Design_by_contract makes it sound like what I thought, the preferred enforcement method is static, but runtime testing can be used as a fallback. I'm pretty sure Eiffel itself comes with static DBC tools. From aahz at pythoncraft.com Mon Sep 13 11:12:15 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Sep 2010 08:12:15 -0700 Subject: Looking for Python and Python/Django workplaces in Chicago References: <894aa094-70c8-4c0e-b2c6-f2b783f68929@l20g2000yqe.googlegroups.com> Message-ID: In article <894aa094-70c8-4c0e-b2c6-f2b783f68929 at l20g2000yqe.googlegroups.com>, Erik Reppen wrote: > >I'm a really strong front end web dev with an interest in becoming >more of a generalist web and app dev through Python. Anybody aware of >studios/agencies that actually prefer Python in Chicago I could keep >an eye on. Nobody else has responded, so I'll just refer you to the usual job boards, including http://www.python.org/community/jobs/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From aahz at pythoncraft.com Mon Sep 13 11:14:04 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Sep 2010 08:14:04 -0700 Subject: WMI in Python References: Message-ID: In article , KING LABS wrote: > >I would like to collect the complete information of system hardware & >and also software installed from registry and add/remove program and >feed this data into database. You should subscribe to the win32 mailing list: http://mail.python.org/mailman/listinfo/python-win32 Before you ask questions there, do a bit of searching first -- there are lots of examples. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From giacomo.boffi at polimi.it Mon Sep 13 11:18:06 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Mon, 13 Sep 2010 17:18:06 +0200 Subject: [Tutor] Arguments from the command line References: <8662yfklzu.fsf@aiuole.stru.polimi.it> <86wrqtsxo2.fsf@aiuole.stru.polimi.it> Message-ID: <86d3shlljl.fsf@aiuole.stru.polimi.it> Dennis Lee Bieber writes: > On Fri, 10 Sep 2010 12:25:17 +0200, Giacomo Boffi > declaimed the following in > gmane.comp.python.general: > >> Lawrence D'Oliveiro writes: >> >> > In message <8662yfklzu.fsf at aiuole.stru.polimi.it>, Giacomo Boffi wrote: >> > >> >> Dennis Lee Bieber writes: >> >> >> >>> FORTRAN just differentiates by having the main file start with >> >>> PROGRAM random_name >> >>> whereas subfiles are all either (or both) >> >>> SUBROUTINE another_name(args) >> >>> FUNCTION that_other_name(args) >> >> >> >> no BLOCKDATA? >> > >> > I think you mean COMMON. >> >> i meant BLOCKDATA > > It exists but I've only seen it used once... And I don't recall it > being "executable" in the same way as program/function/subroutine. i simply meant that the BLOCKDATA statement can begin a subfile as well as SUBROUTINE or FUNCTION -- Sar? un'ingenua ma continuo a pensarla come prima, anche se probabilmente i fatti mi smentiscono. -- Francy, in IHC From malaclypse2 at gmail.com Mon Sep 13 11:31:12 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 13 Sep 2010 11:31:12 -0400 Subject: WMI in Python In-Reply-To: References: Message-ID: On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > Hi All, > > I am new to programming and python, Being a system administrator I > have chose Inventory (Software & Hardware ) as my first project. You'll probably want to look at the python WMI module: http://timgolden.me.uk/python/wmi/index.html as well as the pywin32 module: http://sourceforge.net/projects/pywin32/ IIRC, there's been quite a bit of discussion about inventorying installed software on the pywin32 mailing list: http://mail.python.org/mailman/listinfo/python-win32 -- Jerry From thomas at jollybox.de Mon Sep 13 11:32:22 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Mon, 13 Sep 2010 17:32:22 +0200 Subject: Python script for MySQL Passwords Unreliable on first boot (rc.local) In-Reply-To: References: Message-ID: <201009131732.23506.thomas@jollybox.de> On Monday 13 September 2010, it occurred to cloudcontrol to exclaim: > The script below works great when logged in as root and run from the > command line, but when run at first boot using /etc/rc.local in Ubuntu > 10.04, it fails about 25% of the time- the system root, mysql root and > some mysql user passwords are set correctly, but one will fail with > console log reporting standard mysql login error: "ERROR 1045 (28000): > Access denied for user 'root' @ 'localhost' (using password: YES)" It looks like MySQL itself isn't properly set up (yet) in those cases. But why/how? Ubuntu uses upstart to boot up. I don't know much about how this works, but I understand it's dependency-based, and I expect it's parallel as well, where possible. This means that different init scripts could run in a different order sometimes, or even at the same time. However, rc.local should really always be run last. It does not, by and of itself, specify any dependencies, but it could require anything. It would be ludicrous for Ubuntu to run rc.local before or at the same time as other scripts, such as the MySQL one. The only plausible explanation for this strange behaviour I can think of right now would be that either a) Upstart/Ubuntu is just plain stupid, or b) The MySQL init script spawns MySQL in the background and doesn't wait for it to start up correctly. This seams highly unlikely and atypical of MySQL init scripts, but maybe that's what's happening. So this might be a bug in Ubuntu. The way to fix this might simply be to detect the login error and retry, say, 5 times with 1-second intervals. > > Is there something about running python scripts from init jobs that I > should account for, such as an environment variable? > > #!/usr/bin/env python > > # Udates system & MySQL root passwords on first boot > files = ['/home/ubuntu/passwords','/opt/data1/alfresco/extensions/ > extension/alfresco-global.properties','/opt/data/etc/mysql/ > debian.cnf','/home/ubuntu/duncil'] > userpasswords = {'root':'ROOTPASSWORD'} > mysqlpasswords = > {'root':'MYSQLPASSWORD','alfresco':'alfrescoPASSWORD','debian-sys- > maint':'debian-sys-maintPASSWORD'} > otherpasswords = ['OTHERPASSWORD'] > log = '/var/log/firstrun' > > import random, string > import crypt > import re > from subprocess import PIPE, Popen > > def getsalt(chars = string.letters + string.digits): > # generate a random 2-character 'salt' > return random.choice(chars) + random.choice(chars) > > def getpwd(chars = string.letters + string.digits, len = 12): > retval = ""; > for i in range(0, len): > # generate 12 character alphanumeric password > retval += random.choice(chars) > > return retval > > def replace_pass(filename): > handle = open(filename, 'r') > hbuf = handle.read() > handle.close() > for placeholder, password in pdict.iteritems(): > hbuf = re.sub(placeholder, password, hbuf) > > try: > # Output file > handle = open(filename, 'w') > handle.write(hbuf) > handle.close() > except: > pass > #logh.write('failed to update ' + filename + "\n") > #logh.write('maybe you don\'t have permision to write to it? > \n') > > logh = open(log, "a") > logh.write("Starting...\n") > # Generate passwords > pdict = {} > for user, placeholder in userpasswords.iteritems(): > syspass = getpwd() > Popen(['usermod', '--password', crypt.crypt(syspass, getsalt()), > user]) > logh.write(placeholder + ": User " + user + " --> " + syspass + > "\n") > pdict[placeholder] = syspass > > # What's the MySQL Root password placeholder? > mplace = mysqlpasswords['root'] > for user, placeholder in mysqlpasswords.iteritems(): > mpass = getpwd() > if (("root" in mysqlpasswords) and (mysqlpasswords['root'] in > pdict)): > mrootpass = pdict[mysqlpasswords['root']] > else: > mrootpass = "" > > Popen(['mysql', '-uroot', "--password=" + mrootpass, "-e", "UPDATE > user SET Password = PASSWORD('" + mpass + "') WHERE User = '" + user + > "';FLUSH PRIVILEGES;","mysql"]) > logh.write(placeholder + ": MySQL " + user + " --> " + mpass + > "\n") > pdict[placeholder] = mpass > > for placeholder in otherpasswords: > opass = getpwd() > logh.write(placeholder + ": " + opass + "\n") > pdict[placeholder] = opass > > # Update passwords > for file in files: > logh.write("Replacing placeholders in " + file + "\n") > replace_pass(file) > > logh.write("Finished\n") > logh.close From cousinstanley at gmail.com Mon Sep 13 11:52:57 2010 From: cousinstanley at gmail.com (Cousin Stanley) Date: Mon, 13 Sep 2010 15:52:57 +0000 (UTC) Subject: palindrome iteration References: <49c856c4-e6f4-4e4e-b1b4-694a50e56080@f6g2000yqa.googlegroups.com> <4c778ab6$0$4778$426a74cc@news.free.fr> Message-ID: > To deal with "real" palindromes such as, "Madam, I'm Adam," > you should probably strip all spaces and punctuation: > > # untested > pat = re.compile(r'[a-z]') > def is_palindrome(s): > letters = pat.findall(s.lower()) > return letters == reversed(letters) Using python 2.5 the above solution always returned False for me until the reversed( letters ) iterator was explicitly coerced into a list .... return letters == list( reversed( letters ) ) -- Stanley C. Kitching Human Being Phoenix, Arizona From chris.morisset at gmail.com Mon Sep 13 11:58:37 2010 From: chris.morisset at gmail.com (Chris) Date: Mon, 13 Sep 2010 08:58:37 -0700 (PDT) Subject: From IDL to Python Message-ID: <9029e94e-383c-42d9-b670-16f8e351ed04@b4g2000pra.googlegroups.com> Hi, I'm an IDL user since years and try now to learn Python since a few days. I'm blogging the various steps of this transition to: http://idl2python.blogspot.com/ I hope that other IDL switchers can help me by commenting on the blog and helping (me and others) to learn quickly the basics of Python. Cheers, Christophe From narkewoody at gmail.com Mon Sep 13 12:20:51 2010 From: narkewoody at gmail.com (narke) Date: Mon, 13 Sep 2010 16:20:51 GMT Subject: smtplib with Google Message-ID: Hi, Can anyone please show me a workable example that can let me use google's smtp server to send out a message? Thanks. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From namekuseijin at gmail.com Mon Sep 13 12:58:04 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 13 Sep 2010 13:58:04 -0300 Subject: reddit = porn fodder In-Reply-To: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> References: <56b8ad22-9233-4741-9f91-ecf7848c7db5@x24g2000pro.googlegroups.com> Message-ID: Xah Lee escreveu: > reddit = porn fodder > > Didn't realize, but Reddit is now a porn fodder. > > http://www.reddit.com/r/LegalTeens/ > http://www.reddit.com/r/highheels > http://www.reddit.com/r/gonewild/ > > Its traffic also seems to incleased 10 times since 2008. See: Computer > Language Websites Popularity. > > From my experience, if you just add one page that is remotely related > to sex, that page's traffic will eclipse your other hundred pages [snip] > note that reddit was originally somewhat a site for programers, > written in common lisp. guess the lesson here is that Python is more sexy than Lisp. :p -- a game sig: http://tinyurl.com/d3rxz9 --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From egrefen at gmail.com Mon Sep 13 13:05:38 2010 From: egrefen at gmail.com (Edward Grefenstette) Date: Mon, 13 Sep 2010 10:05:38 -0700 (PDT) Subject: Frustrating segfaults with Shelf Message-ID: Dear Pythonistas, Below is a simple script that reads relations from a generator (they're just tuples of strings) and attempts to write them to a database. It's simple as hell, and if I simply ignore the database and have it print to stdout by replacing the line "depsDB[str(index)] = rels" with "print rels" it works just fine. However every time I try to run it just inexplicably segfaults. Help, anyone? Best, Edward ======================================== from WNvectorBuilder import relBuilder import sys import cPickle as pickle import shelve def main(argv): ## read filenames from command line arguments depsFile = open(argv[1]) lemmaFile = open(argv[2]) depsDB = shelve.open(argv[3],"c") ## load lemma dictionary from lemma file lemmaDict = pickle.load(lemmaFile) ## index of database entries index = 0 ## read relations from relation generator, write each relation to database under new index for rels in relBuilder(depsFile,lemmaDict): index += 1 depsDB[str(index)] = rels del rels if __name__ == '__main__': main(sys.argv) ======================================== From chris at simplistix.co.uk Mon Sep 13 13:06:02 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 13 Sep 2010 18:06:02 +0100 Subject: business date and calendar libraries? Message-ID: <4C8E59FA.3060508@simplistix.co.uk> Hi All, I'm wondering what libraries people would use to answer the following questions relating to business days: - on a naive level; "what's give me the last business day" (ie: skipping weekends) - on a less-naive level; same question but taking into account public holidays - on a horrific level; same question, but taking into account business days of a particular market (NYSE, LSE, etc) cheers, Chris From thudfoo at opensuse.us Mon Sep 13 13:19:52 2010 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 13 Sep 2010 10:19:52 -0700 Subject: smtplib with Google In-Reply-To: References: Message-ID: On Mon, Sep 13, 2010 at 9:20 AM, narke wrote: > > Hi, > > Can anyone please show me a workable example that can let me use > google's smtp server to send out a message? ?Thanks. > Go here: http://code.activestate.com/recipes/langs/python/ and search for this gmail From aioe.org at technicalbloke.com Mon Sep 13 14:04:53 2010 From: aioe.org at technicalbloke.com (r0g) Date: Mon, 13 Sep 2010 19:04:53 +0100 Subject: Expected bahaviour of os.chroot and os.getcwd Message-ID: Hi CLP! Not been here for ages, I hope everyone is doing well :) I just want to check if this is the intended behaviour (2.2 to 2.7)... > import os > print os.getcwd() > os.chroot("/home/r0g/whatever/") > print os.getcwd() > os.chdir("/") > print os.getcwd() >>> /home/r0g/AAA_BACKED_UP/Code/py >>> /home/r0g/AAA_BACKED_UP/Code/py >>> / i.e. So do I always have to change directory after changing into a chroot? The reason I ask is because an app I was running inside the chrooted environment (specifically: apt-get) was trying to access files outside the chroot and erroring when it couldn't. I figured it must be doing a getcwd() and getting the cwd of the script that initialized the chroot. I just wanted to confirm that's how it's supposed to work so I'd appreciate it if anyone either knows or can point me to the docs that explain in more detail than http://docs.python.org/library/os.html Also, out of curiosity... If it does work (and should work) the way I think it does how come os.chroot doesn't set the cwd to "/" for you? It's not a costly operation and it could prevent errors of ignorance such as my own. Are there any good reasons why a person (who isn't a hacker / cracker / kludger) would want chrooted processes to be able to see the calling script's cwd anyway? Maybe I'm having a failure of imagination today but the only things I can think that info could be useful for are jailbreaking, nefarious reconnaissance and real ugly hacks. Maybe someone here can enlighten me :) Yours curiously, Roger Heathcote From emile at fenx.com Mon Sep 13 14:09:40 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 13 Sep 2010 11:09:40 -0700 Subject: Frustrating segfaults with Shelf In-Reply-To: References: Message-ID: On 9/13/2010 10:05 AM Edward Grefenstette said... > Dear Pythonistas, > > Below is a simple script that reads relations from a generator > (they're just tuples of strings) and attempts to write them to a > database. It's simple as hell, Ecept of course that no one else can test it due to the dependencies. > and if I simply ignore the database and > have it print to stdout by replacing the line "depsDB[str(index)] = > rels" with "print rels" it works just fine. However every time I try > to run it just inexplicably segfaults. Help, anyone? There are reported problems with the backend database in pre 2.3 python versions. There are also known problems with shelves being accessed by differing versions. So, I'd start by updating as needed, creating a new repository, then testing that. Once it works, migrate the data over if needed. If it doesn't work, it'll be tough to help out if narrowing things down to a specific reproducible test case is difficult. Describe the debugging techniques you're trying with the results you're getting, and we can help contribute with other things to try. HTH, Emile From python at rcn.com Mon Sep 13 14:28:46 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 13 Sep 2010 11:28:46 -0700 (PDT) Subject: How Python works: What do you know about support for negative indices? References: <874ody9w3v.fsf@benfinney.id.au> Message-ID: [Ben Finney] > I encourage anyone whose messages are munged like that to seek > correction from their mail service provider, and switch to a different > one until it's fixed. The post was typed on a mobile device into the text window on Google Groups. It's too bad that inane concerns with newline placement overwhelmed the substance of the post. Raymond From ian.g.kelly at gmail.com Mon Sep 13 14:38:55 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 13 Sep 2010 12:38:55 -0600 Subject: Expected bahaviour of os.chroot and os.getcwd In-Reply-To: References: Message-ID: On Mon, Sep 13, 2010 at 12:04 PM, r0g wrote: > i.e. So do I always have to change directory after changing into a chroot? > Yes, as documented in the man page for the chroot system call: This call changes an ingredient in the pathname resolution process and does > nothing else. > > This call does not change the current working directory, so that after the > call '.' can be outside the tree rooted at '/'. In particular, the superuser > can escape from a 'chroot jail' by doing 'mkdir foo; chroot foo; cd ..'. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon Sep 13 14:48:46 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 13 Sep 2010 20:48:46 +0200 Subject: PIL : "The _imaging C module is not installed" Message-ID: <4c8e720f$0$10204$ba4acef3@reader.news.orange.fr> Hello! (*** sorry for my bad english***) I have the message (title), but only with PIL 1.1.7 (Windows XP, Vista or 7 (32 bits or 64 bits)). I tried: _imaging.pyd exist in C:\Python26\Lib\site-packages\PIL OK python -v >>> import Image OK sys.path contain C:\Python26\Lib\site-packages\PIL OK python >>> import _imaging OK I tested on more than 6 computers, with new installations, or update installations. Same problem. Same problem, also, with Python 2.6 or Python 2.7 If I install again PIL 1.1.6, all scripts run OK. Then, I install again PIL 1.1.7, the problem returns. It is the only thing than I wait before update to Python 2.7 One idea? Thanks in advance. -- Michel Claveau From krdean at gmail.com Mon Sep 13 14:53:26 2010 From: krdean at gmail.com (kBob) Date: Mon, 13 Sep 2010 11:53:26 -0700 (PDT) Subject: From IDL to Python References: <9029e94e-383c-42d9-b670-16f8e351ed04@b4g2000pra.googlegroups.com> Message-ID: <692bd562-314f-41dc-82b4-538f56c2da1b@z30g2000prg.googlegroups.com> On Sep 13, 9:58?am, Chris wrote: > Hi, > > I'm an IDL user since years and try now to learn Python since a few > days. > I'm blogging the various steps of this transition to:http://idl2python.blogspot.com/ > I hope that other IDL switchers can help me by commenting on the blog > and helping (me and others) to learn quickly the basics of Python. > Cheers, > Christophe I have been using IDL and ENVI for years and started working with Python this summer. Mostly, as I find myself working with ArcGIS users and Python is popular among this group. I couldn't convinced them that IDL/ENVI was easier. Did my first "widget" with Python/Tkinter, which does require more work. Still can't get my Python version of the Widget/Hourglass to work correctly. However, you see, you may have to rebuild those IDL routines your so use to using in IDL. However, some areas are alot easier with Python like XML and Net URL stuff (working on OGC WMS and WFS project). There is plenty of examples to help you out. Maybe I should start my own blog spot, just to share my experiences. Kelly Dean Milliken, CO From stef.mientki at gmail.com Mon Sep 13 15:00:19 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 13 Sep 2010 21:00:19 +0200 Subject: is there a way to get the encoding of python file In-Reply-To: References: <4C8C99FA.2070405@gmail.com> Message-ID: <4C8E74C3.50602@gmail.com> On 12-09-2010 19:28, Robert Kern wrote: > On 9/12/10 4:14 AM, Stef Mientki wrote: >> hello, >> >> Is it possible to get the encoding of a python file from the first source line, >> (if there's any), >> after importing it ( with '__import__' ) >> >> # -*- coding: windows-1252 -*- > > The regular expression used to match the encoding declaration is given here: > > http://docs.python.org/reference/lexical_analysis.html#encoding-declarations > yes, but then I've to read the first line of the file myself. In the meanwhile I found another (better ?) solution, (I'm using Python 2.6) Place these 2 lines at the top of the file # -*- coding: windows-1252 -*- from __future__ import unicode_literals or these # -*- coding: utf-8 -*- from __future__ import unicode_literals then you always get the correct unicode string back. thanks, Stef From enleverLesX_XXmcX at XmclavXeauX.com.invalid Mon Sep 13 15:02:03 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Mon, 13 Sep 2010 21:02:03 +0200 Subject: SendKeys and Python 2.7 References: Message-ID: <4c8e752d$0$5432$ba4acef3@reader.news.orange.fr> Re! Sorry for time, but I am very busy... With Python + Pywin32, you can force the activation of a window (before send some keys...) See: win32gui.SetForegroundWindow(w_handle) or win32gui.SetActiveWindow(w_handle) For to find a windows (and his handle), see: win32gui.EnumWindows() win32gui.GetWindowTex() or win32gui.FindWindowEx() @-salutations -- Michel Claveau From drobinow at gmail.com Mon Sep 13 15:02:09 2010 From: drobinow at gmail.com (David Robinow) Date: Mon, 13 Sep 2010 15:02:09 -0400 Subject: business date and calendar libraries? In-Reply-To: <4C8E59FA.3060508@simplistix.co.uk> References: <4C8E59FA.3060508@simplistix.co.uk> Message-ID: On Mon, Sep 13, 2010 at 1:06 PM, Chris Withers wrote: > I'm wondering what libraries people would use to answer the following > questions relating to business days: > > - on a naive level; "what's give me the last business day" (ie: skipping > weekends) import datetime def is_weekend(year, month, day): return datetime.date(year, month, day).weekday() in (5,6) That should get you started. > - on a less-naive level; same question but taking into account public > holidays This depends on which government is oppressing you. > > - on a horrific level; same question, but taking into account business days > of a particular market (NYSE, LSE, etc) This is just an instance of the public holiday case. You need to define the holidays. If you read lisp you might want to look at the emacs calendar module for some hints on how they describe holidays, such as, for a US-biased example, Martin Luther King day is the third Monday in January, Memorial Day is the last Monday in May, Good Friday is not a public holiday but some markets are closed. From python at rcn.com Mon Sep 13 16:07:19 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 13 Sep 2010 13:07:19 -0700 (PDT) Subject: How Python works: What do you know about support for negative indices? References: Message-ID: <975f6488-09f4-4d80-8889-6e973fbf114e@h40g2000pro.googlegroups.com> On Sep 10, 2:13?pm, Terry Reedy wrote: > Reading the third paragraph out of context, one can miss the restriction > to built-in objects. I had assumed that the conversion using len(), when > available, happened prior to the __getitem__ call. Yes, that's a common misconception. It is probably based on the current wording of the docs and on the PySequence_GetItem() optimized fast-path for builtin and extension sequences. >From the users point-of-view, the important thing is that it (effectively) occurs in the __getitem__() code, that builtin sequences and extensions support it, and that else where it is optional. Another way of saying it is: if you are ever writing a __getitem__() method in Python (even for a subclass of a builtin sequence), then it is up to you to decide whether to add support for negative indices and slicing. Raymond From robert.kern at gmail.com Mon Sep 13 16:31:19 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 13 Sep 2010 15:31:19 -0500 Subject: is there a way to get the encoding of python file In-Reply-To: <4C8E74C3.50602@gmail.com> References: <4C8C99FA.2070405@gmail.com> <4C8E74C3.50602@gmail.com> Message-ID: On 9/13/10 2:00 PM, Stef Mientki wrote: > On 12-09-2010 19:28, Robert Kern wrote: >> On 9/12/10 4:14 AM, Stef Mientki wrote: >>> hello, >>> >>> Is it possible to get the encoding of a python file from the first source line, >>> (if there's any), >>> after importing it ( with '__import__' ) >>> >>> # -*- coding: windows-1252 -*- >> >> The regular expression used to match the encoding declaration is given here: >> >> http://docs.python.org/reference/lexical_analysis.html#encoding-declarations >> > yes, but then I've to read the first line of the file myself. > > In the meanwhile I found another (better ?) solution, (I'm using Python 2.6) > > > Place these 2 lines at the top of the file > # -*- coding: windows-1252 -*- > from __future__ import unicode_literals > > or these > # -*- coding: utf-8 -*- > from __future__ import unicode_literals > > then you always get the correct unicode string back. Ah. I see. You don't actually need to know the encoding; you just want to use literals with raw, unescaped characters embedded in them. This may interfere with the cases when you need a real str object. In Python 2.x, if you want a unicode literal, just use one like so: u'?'. As long as the encoding declaration is correct, this will work just fine. -- 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 thomas at jollybox.de Mon Sep 13 16:56:26 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Mon, 13 Sep 2010 22:56:26 +0200 Subject: is there a way to get the encoding of python file In-Reply-To: References: <4C8C99FA.2070405@gmail.com> <4C8E74C3.50602@gmail.com> Message-ID: <201009132256.26345.thomas@jollybox.de> On Monday 13 September 2010, it occurred to Robert Kern to exclaim: > On 9/13/10 2:00 PM, Stef Mientki wrote: > > On 12-09-2010 19:28, Robert Kern wrote: > >> On 9/12/10 4:14 AM, Stef Mientki wrote: > >>> hello, > >>> > >>> Is it possible to get the encoding of a python file from the first > >>> source line, (if there's any), > >>> after importing it ( with '__import__' ) > >>> > >>> # -*- coding: windows-1252 -*- > >> > >> The regular expression used to match the encoding declaration is given > >> here: > >> > >> http://docs.python.org/reference/lexical_analysis.html#encoding-declarat > >> ions > > > > yes, but then I've to read the first line of the file myself. > > > > In the meanwhile I found another (better ?) solution, (I'm using Python > > 2.6) > > > > > > Place these 2 lines at the top of the file > > # -*- coding: windows-1252 -*- > > from __future__ import unicode_literals > > > > or these > > # -*- coding: utf-8 -*- > > from __future__ import unicode_literals > > > > then you always get the correct unicode string back. > > Ah. I see. You don't actually need to know the encoding; you just want to > use literals with raw, unescaped characters embedded in them. > > This may interfere with the cases when you need a real str object. If you assume that unicode_literals from __future__ works, you can also assume that the b'bytestring' syntax works. > In > Python 2.x, if you want a unicode literal, just use one like so: u'?'. As > long as the encoding declaration is correct, this will work just fine. From modulus10 at yahoo.com Mon Sep 13 18:59:30 2010 From: modulus10 at yahoo.com (C3) Date: Mon, 13 Sep 2010 15:59:30 -0700 (PDT) Subject: Newbie question about Python + CouchDB Message-ID: <317194.60083.qm@web50801.mail.re2.yahoo.com> Total newbie here - have a quick question I have a script that takes data in a flat text file, breaks it up and builds a CouchDB with all my data - however during the loop in which the data is loaded into couchdb - I sometimes get crashes becuase of a duplicate Document ID (which in my case is the serial number of a product) i was wondering if it is possible to; 1. capture the HTTP status code for each post 2. write logic around that code (such as "skip post if error code was a 409") thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From AmFreak at web.de Mon Sep 13 19:07:48 2010 From: AmFreak at web.de (AmFreak at web.de) Date: Tue, 14 Sep 2010 01:07:48 +0200 Subject: Converting an ugly path to a shell path Message-ID: Hi, im using a QFileDialog to let the user select a path that is used later in a command send to the shell like this: retcode = Popen(command + " " + path, shell=True, stdout = PIPE, stderr = PIPE) The problem that occurs now is when the user selects an "ugly" path like this /home/user/!" ?$/. The shell don't understand the special chars so i have to escape them with "\" . Is there a function that does this ? If there isn't i would use a RegEx but I can't even seem to find a list containing all special chars :/ Greetings AmFreak From prologic at shortcircuit.net.au Mon Sep 13 19:33:15 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 14 Sep 2010 09:33:15 +1000 Subject: Newbie question about Python + CouchDB In-Reply-To: <317194.60083.qm@web50801.mail.re2.yahoo.com> References: <317194.60083.qm@web50801.mail.re2.yahoo.com> Message-ID: On Tue, Sep 14, 2010 at 8:59 AM, C3 wrote: > i was wondering if it is possible to; > > 1. capture the HTTP status code for each post > 2. write logic around that code (such as "skip post if error code was a > 409") An appropriate exception should by thrown when it "crashes". Use an appropriate try/except block to "catch" the exception(s). cheers James -- -- James Mills -- -- "Problems are solved by method" -------------- next part -------------- An HTML attachment was scrubbed... URL: From prakash.stack at gmail.com Mon Sep 13 19:36:33 2010 From: prakash.stack at gmail.com (prakash jp) Date: Tue, 14 Sep 2010 05:06:33 +0530 Subject: WMI in Python In-Reply-To: References: Message-ID: Very true most systems admins requirement range from : knoowing the Service tag for a given IP to knowing the system harware details such as RAM sizes etc. This is where Remote Inventory Management comes in handy. There is vault of already existing vb scripts/perl scripts and batch files. To me it looks fine if one can create a common interface and link the preexistant scripts. Else, wmi command line can be directly implemented in python through os.system("COMMAND WMI") so that redistributable python exe be created through py2exe Regards Prakash -------------- next part -------------- An HTML attachment was scrubbed... URL: From malaclypse2 at gmail.com Mon Sep 13 19:37:08 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 13 Sep 2010 19:37:08 -0400 Subject: Converting an ugly path to a shell path In-Reply-To: References: Message-ID: On Mon, Sep 13, 2010 at 7:07 PM, wrote: > The problem that occurs now is when the user selects an "ugly" path like > this /home/user/!" ?$/. > The shell don't understand the special chars so i have to escape them with > "\" . > Is there a function that does this ? http://stackoverflow.com/questions/35817/whats-the-best-way-to-escape-ossystem-calls-in-python seems to cover most of the possibilities. Particularly, do you really need shell=True? If not, you can just call Popen([command, path], stdout=PIPE, stderr=PIPE) and not worry about it. -- Jerry From jaksonaquino at gmail.com Mon Sep 13 19:57:37 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Mon, 13 Sep 2010 20:57:37 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: <4c8e752d$0$5432$ba4acef3@reader.news.orange.fr> References: <4c8e752d$0$5432$ba4acef3@reader.news.orange.fr> Message-ID: On Mon, Sep 13, 2010 at 4:02 PM, Michel Claveau - MVP wrote: > Re! > > Sorry for time, but I am very busy... > > > With Python + Pywin32, you can force the activation of a window (before > send some keys...) > See: > ?win32gui.SetForegroundWindow(w_handle) > > or > ?win32gui.SetActiveWindow(w_handle) > > > > For to find a windows (and his handle), see: > ?win32gui.EnumWindows() > ?win32gui.GetWindowTex() > or > ?win32gui.FindWindowEx() Thanks! I have found a simple workaround: sending Alt+Tab to R Console. Tomorrow I will test your solution. I can't do it right now because I don't have a real machine running Windows here. Best regards, Jakson From narkewoody at gmail.com Mon Sep 13 20:28:28 2010 From: narkewoody at gmail.com (narke) Date: Tue, 14 Sep 2010 00:28:28 GMT Subject: smtplib with Google References: Message-ID: On 2010-09-13, member thudfoo wrote: > On Mon, Sep 13, 2010 at 9:20 AM, narke wrote: >> >> Hi, >> >> Can anyone please show me a workable example that can let me use >> google's smtp server to send out a message? ?Thanks. >> > > Go here: > > http://code.activestate.com/recipes/langs/python/ > > and search for this > > gmail Thanks! -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke From ldo at geek-central.gen.new_zealand Mon Sep 13 20:30:57 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 14 Sep 2010 12:30:57 +1200 Subject: Expected bahaviour of os.chroot and os.getcwd References: Message-ID: In message , r0g wrote: > i.e. So do I always have to change directory after changing into a chroot? When all else fails, read the man page . From egrefen at gmail.com Mon Sep 13 20:33:35 2010 From: egrefen at gmail.com (Edward Grefenstette) Date: Mon, 13 Sep 2010 17:33:35 -0700 (PDT) Subject: Frustrating segfaults with Shelf References: Message-ID: Dear Emile, Thank you for your response. Upgrading python and starting with a blank database somehow did the trick! Best, Edward On Sep 13, 7:09?pm, Emile van Sebille wrote: > On 9/13/2010 10:05 AM Edward Grefenstette said... > > > Dear Pythonistas, > > > Below is a simple script that reads relations from a generator > > (they're just tuples of strings) and attempts to write them to a > > database. It's simple as hell, > > Ecept of course that no one else can test it due to the dependencies. > > > and if I simply ignore the database and > > have it print to stdout by replacing the line "depsDB[str(index)] = > > rels" with "print rels" it works just fine. However every time I try > > to run it just inexplicably segfaults. Help, anyone? > > There are reported problems with the backend database in pre 2.3 python > versions. ?There are also known problems with shelves being accessed by > differing versions. > > So, I'd start by updating as needed, creating a new repository, then > testing that. ?Once it works, migrate the data over if needed. > > If it doesn't work, it'll be tough to help out if narrowing things down > to a specific reproducible test case is difficult. ?Describe the > debugging techniques you're trying with the results you're getting, and > we can help contribute with other things to try. > > HTH, > > Emile From kinglabs.in at gmail.com Tue Sep 14 01:39:57 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Mon, 13 Sep 2010 22:39:57 -0700 (PDT) Subject: WMI in Python References: Message-ID: On Sep 13, 8:31?pm, Jerry Hill wrote: > On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > > Hi All, > > > I am new to programming and python, Being a system administrator I > > have chose Inventory (Software & Hardware ) as my first project. > > You'll probably want to look at the python WMI module:http://timgolden.me.uk/python/wmi/index.html > > as well as the pywin32 module:http://sourceforge.net/projects/pywin32/ > > IIRC, there's been quite a bit of discussion about inventorying > installed software on the pywin32 mailing list:http://mail.python.org/mailman/listinfo/python-win32 > > -- > Jerry Thank you all, I will go through the links provided and suggestions. Shall get back to you on this soon. From kinglabs.in at gmail.com Tue Sep 14 01:46:32 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Mon, 13 Sep 2010 22:46:32 -0700 (PDT) Subject: WMI in Python References: Message-ID: On Sep 14, 10:39?am, KING LABS wrote: > On Sep 13, 8:31?pm, Jerry Hill wrote: > > > On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > > > Hi All, > > > > I am new to programming and python, Being a system administrator I > > > have chose Inventory (Software & Hardware ) as my first project. > > > You'll probably want to look at the python WMI module:http://timgolden.me.uk/python/wmi/index.html > > > as well as the pywin32 module:http://sourceforge.net/projects/pywin32/ > > > IIRC, there's been quite a bit of discussion about inventorying > > installed software on the pywin32 mailing list:http://mail.python.org/mailman/listinfo/python-win32 > > > -- > > Jerry > > Thank you all, I will go through the links provided and suggestions. > Shall get back to you on this soon. The following information is exactly what I am trying to collect for the inventory. I can find vb scripts with googling. I want to do the same with Python & Win32. Use Server/Client architecture . Client(agent) updates the information to server. ---------------------------------------------------------------------------------------- BIOS: System serial number, manufacturer, and model Bios manufacturer, version, and date Processors: Type, count (how many of them), manufacturer, speed, and cache Memory: Physical memory type, manufacturer, capacity, and slot number Total physical memory Total swap/paging memory Video: Video adapter: Chipset/model, manufacturer, memory size, speed, and screen resolution Display monitor: Manufacturer, description, refresh rate, type, serial number, and caption Storage/removable devices: Manufacturer, model, size, type, speed( all when applicable) Drive letter, filesystem type, partition/volume size, free space Network adapters/telephony: Manufacturer, model, type, speed, and description MAC and IP address, mask and IP gateway, DHCP server used Miscellaneous hardware: Input devices: Keyboard, mouse, and pointing device Sound devices: Manufacturer name, type, and description System slots: Name, type, and designation System ports: Type, name, caption, and description Software Information: ( from registry & add/remove program ) Operating system: Name, version, comments, and registration info Installed software: Name, publisher, version (from Add / Remove software or Programs and Features menu) Custom-specified registry queries (applicable to Windows OS) ------------------------------------------------------------------------------------------------------------------ From vontio at gmail.com Tue Sep 14 02:41:09 2010 From: vontio at gmail.com (Von) Date: Tue, 14 Sep 2010 14:41:09 +0800 Subject: python datetime Message-ID: Hi, How to determine a date is just the 7th day after today ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep the 7th day is 5 Oct,is there simple way to do this work? I wish I explained clear Bests, -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.ricordeau at gmail.com Tue Sep 14 03:50:40 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Tue, 14 Sep 2010 09:50:40 +0200 Subject: python datetime In-Reply-To: References: Message-ID: <20100914095040.6e26e15c@moriz.interne> # Determine diff days between two dates import datetime now = datetime.date(2010, 9, 28) next = datetime.date(2010, 10, 5) delta = next - now #delta is datetime.timedelta type. #(You can extract days diff) # Determine date in 7 days import datetime now = datetime.date(2010, 9, 28) delta = datetime.timedelta(days=7) next = now + delta Le Tue, 14 Sep 2010 14:41:09 +0800, Von a ?crit : > Hi, > How to determine a date is just the 7th day after today > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep the > 7th day is 5 Oct,is there simple way to do this work? > I wish I explained clear > > Bests, From __peter__ at web.de Tue Sep 14 03:51:37 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Sep 2010 09:51:37 +0200 Subject: python datetime References: Message-ID: Von wrote: > How to determine a date is just the 7th day after today > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep > the 7th day is 5 Oct,is there simple way to do this work? > I wish I explained clear The datetime module takes care of this >>> import datetime as dt >>> dt.date(2010, 9, 28) + dt.timedelta(days=7) datetime.date(2010, 10, 5) See http://docs.python.org/library/datetime.html Why didn't you find that yourself? It's the first match if you google for python datetime. Peter From vontio at gmail.com Tue Sep 14 04:43:25 2010 From: vontio at gmail.com (Von) Date: Tue, 14 Sep 2010 16:43:25 +0800 Subject: python datetime In-Reply-To: <20100914095040.6e26e15c@moriz.interne> References: <20100914095040.6e26e15c@moriz.interne> Message-ID: Thank you,the timedelta class is awesome. On Tue, Sep 14, 2010 at 3:50 PM, Michael Ricordeau < michael.ricordeau at gmail.com> wrote: > > # Determine diff days between two dates > import datetime > now = datetime.date(2010, 9, 28) > next = datetime.date(2010, 10, 5) > delta = next - now > > #delta is datetime.timedelta type. > #(You can extract days diff) > > # Determine date in 7 days > import datetime > now = datetime.date(2010, 9, 28) > delta = datetime.timedelta(days=7) > next = now + delta > > > > > > > > > > > Le Tue, 14 Sep 2010 14:41:09 +0800, > Von a ?crit : > > > Hi, > > How to determine a date is just the 7th day after today > > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep > the > > 7th day is 5 Oct,is there simple way to do this work? > > I wish I explained clear > > > > Bests, > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Tue Sep 14 05:23:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 14 Sep 2010 21:23:03 +1200 Subject: Converting an ugly path to a shell path References: Message-ID: In message , AmFreak at web.de wrote: > The shell don't understand the special chars so i have to escape them with > "\" . > Is there a function that does this ? You could get the shell (at least if it?s Bash) itself to do this. Try the following script: import sys import os import subprocess os.environ["ARG1"] = sys.argv[1] sys.stdout.write \ ( subprocess.Popen ( args = "printf $'%q\\n' \"$ARG1\"", stdout = subprocess.PIPE, shell = True ).communicate()[0] ) Sample output: ldo at theon:hack> ./escape_try '\ & # *' \\\\ \&\ #\ \* From nobody at nowhere.com Tue Sep 14 06:19:57 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 14 Sep 2010 11:19:57 +0100 Subject: Expected bahaviour of os.chroot and os.getcwd References: Message-ID: On Mon, 13 Sep 2010 19:04:53 +0100, r0g wrote: > i.e. So do I always have to change directory after changing into a chroot? You don't *have* to change the directory, but not doing so probably defeats the point of performing a chroot(). > The reason I ask is because an app I was running inside the chrooted > environment (specifically: apt-get) was trying to access files outside > the chroot and erroring when it couldn't. I figured it must be doing a > getcwd() and getting the cwd of the script that initialized the chroot. > I just wanted to confirm that's how it's supposed to work so I'd > appreciate it if anyone either knows or can point me to the docs that > explain in more detail than http://docs.python.org/library/os.html See the relevant manpages. os.chroot, os.chdir and os.getcwd are relatively thin interfaces to the underlying OS functions. > Also, out of curiosity... If it does work (and should work) the way I > think it does how come os.chroot doesn't set the cwd to "/" for you? Because os.chroot just calls the OS' chroot(), which doesn't perform an implicit chdir(). I don't know whether there is any deep reason for the behaviour (beyond the Unix philosophy of "do what I say, not what you think I mean"), but it's been that way forever and isn't likely to change. > It's not a costly operation and it could prevent errors of ignorance > such as my own. Are there any good reasons why a person (who isn't a > hacker / cracker / kludger) would want chrooted processes to be able to > see the calling script's cwd anyway? Maybe I'm having a failure of > imagination today but the only things I can think that info could be > useful for are jailbreaking, nefarious reconnaissance and real ugly > hacks. Maybe someone here can enlighten me :) chroot() wasn't designed as a security mechanism. It simply allows you to control a parameter of the filename resolution algorithm (i.e. the root directory). If you want to use it as a security mechanism, you have to perform additional work, i.e. ensuring that there are no other ways of escaping the chroot (cwd, descriptors, etc). Oh, and you need to lose the ability to perform a further chroot (root privilege or CAP_SYS_CHROOT), otherwise you can just do e.g.: os.chdir("/") os.mkdir("foo") os.chroot("foo") os.chdir("..") Making Python's os.chroot() call os.chdir() wouldn't help from a security standpoint, as the code can still achieve the "raw" behaviour with e.g. ctypes or os.system("chroot ..."). From nobody at nowhere.com Tue Sep 14 06:32:29 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 14 Sep 2010 11:32:29 +0100 Subject: Converting an ugly path to a shell path References: Message-ID: On Tue, 14 Sep 2010 01:07:48 +0200, AmFreak wrote: > im using a QFileDialog to let the user select a path that is used later in > a command send to the shell like this: > > retcode = Popen(command + " " + path, shell=True, stdout = PIPE, stderr = > PIPE) > > The problem that occurs now is when the user selects an "ugly" path like > this /home/user/!" ?$/. > The shell don't understand the special chars so i have to escape them with > "\" . Is there some fundamental reason why you're using a shell? Most of the time, you're better off executing the command directly, i.e.: process = Popen([command, path], shell=False, ...) If you must "unparse" the path for the benefit of the shell, the first question is: *which* shell? For a typical Bourne shell, quoting a string using: qstring = r"'" + string.replace(r"'", r"'\''") + r"'" should be reliable. This won't work for Windows, though; look at the source code for the subprocess module for the (rather bizarre) quoting rules used by Windows. From vontio at gmail.com Tue Sep 14 06:34:10 2010 From: vontio at gmail.com (Von) Date: Tue, 14 Sep 2010 18:34:10 +0800 Subject: python tkinter Listbox Message-ID: Hi all, I am building a simple tool using tkinter,and need multiselection checklist.I find that Listbox with option selectmode=tkinter.MULTIPLE could do this for me. But when I have two Listboxs,I do some selection with one,then do selection with another one,the previous listbox get cleared.I wonder how to keep the previous listbox selected. Wish I explained clear. Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From carlos.grohmann at gmail.com Tue Sep 14 07:02:26 2010 From: carlos.grohmann at gmail.com (Carlos Grohmann) Date: Tue, 14 Sep 2010 04:02:26 -0700 (PDT) Subject: help removing pyQt dll from dist created with py2exe Message-ID: Hello all, i've been trying to build an .exe with py2exe. After many tentatives, it worked, but the total space used by the app goes to 30Mb. It is a simple app, that uses wxpython, matplotlib and numpy. I checked the library.zip file and notived that there is a pyQt-related file there: Pyqt - QtGui.pyo - 8 Mb I'm not using Qt at all, so I assume it would be safe to not have this file, but I don't see how to do it. my setup.py file follows. many thanks Carlos #---------------------------------------------------------------------- from distutils.core import setup import py2exe from glob import glob # Remove the build folder, a bit slower but ensures that build contains the latest import shutil shutil.rmtree("build", ignore_errors=True) # my setup.py is based on one generated with gui2exe, so data_files is done a bit differently data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', 'scrolledpanel', 'customtreectrl', 'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', 'wx.lib.wordwrap', 'types', 'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', 'matplotlib.figure', 'matplotlib.backends.backend_wxagg', 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', 'matplotlib.patches', 'matplotlib.lines', 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', 'matplotlib.collections', 'matplotlib.font_manager', 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' ] excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', 'sqlite3', 'bsddb', 'curses', 'email','_fltkagg', '_gtk', '_gtkcairo', '_agg2', '_cairo', '_cocoaagg', 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' ] packages = ['encodings','pytz','scipy'] dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', 'libglib-2.0-0.dll', 'libcairo-2.dll', 'libpango-1.0-0.dll', 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', 'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', 'QtCore4.dll' ] icon_resources = [] bitmap_resources = [] other_resources = [] # add the mpl mpl-data folder and rc file import matplotlib as mpl data_files += mpl.get_py2exe_datafiles() setup( windows=['OpenStereo.py'], # compressed and optimize reduce the size options = {"py2exe": {"compressed": 2, "optimize": 2, "includes": includes, "excludes": excludes, "packages": packages, "dll_excludes": dll_excludes, # using 2 to reduce number of files in dist folder # using 1 is not recommended as it often does not work "bundle_files": 2, "dist_dir": 'dist', "xref": False, "skip_archive": False, "ascii": False, "custom_boot_script": '', } }, # using zipfile to reduce number of files in dist zipfile = r'lib\library.zip', data_files=data_files ) From almar.klein at gmail.com Tue Sep 14 08:21:07 2010 From: almar.klein at gmail.com (Almar Klein) Date: Tue, 14 Sep 2010 14:21:07 +0200 Subject: help removing pyQt dll from dist created with py2exe In-Reply-To: References: Message-ID: Hi, Have you tried adding "PyQt4", "PyQt4.QtGui" and "PyQt4.QtCore" to your list of excludes? (Maybe only "PyQt4.QtGui" is sufficient.) Almar On 14 September 2010 13:02, Carlos Grohmann wrote: > Hello all, > > i've been trying to build an .exe with py2exe. After many tentatives, > it worked, but the total space used by the app goes to 30Mb. It is a > simple app, that uses wxpython, matplotlib and numpy. I checked the > library.zip file and notived that there is a pyQt-related file there: > > Pyqt - QtGui.pyo - 8 Mb > > I'm not using Qt at all, so I assume it would be safe to not have this > file, but I don't see how to do it. > > my setup.py file follows. > > many thanks > > Carlos > > > #---------------------------------------------------------------------- > from distutils.core import setup > import py2exe > from glob import glob > > # Remove the build folder, a bit slower but ensures that build > contains the latest > import shutil > shutil.rmtree("build", ignore_errors=True) > > # my setup.py is based on one generated with gui2exe, so data_files is > done a bit differently > data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] > > includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', > 'scrolledpanel', 'customtreectrl', > 'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', > 'wx.lib.wordwrap', 'types', > 'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', > 'matplotlib.figure', > 'matplotlib.backends.backend_wxagg', > 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', > 'matplotlib.patches', 'matplotlib.lines', > 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', > 'matplotlib.collections', 'matplotlib.font_manager', > 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' > ] > > excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', > 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', > 'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', > 'sqlite3', > 'bsddb', 'curses', 'email','_fltkagg', '_gtk', > '_gtkcairo', > '_agg2', '_cairo', '_cocoaagg', > 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' > ] > > packages = ['encodings','pytz','scipy'] > > dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', > 'tcl84.dll', 'tk84.dll', > 'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', > 'libglib-2.0-0.dll', > 'libcairo-2.dll', 'libpango-1.0-0.dll', > 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', > 'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', > 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', > 'QtCore4.dll' > ] > > icon_resources = [] > bitmap_resources = [] > other_resources = [] > > # add the mpl mpl-data folder and rc file > import matplotlib as mpl > data_files += mpl.get_py2exe_datafiles() > > setup( > windows=['OpenStereo.py'], > # compressed and optimize reduce the size > options = {"py2exe": {"compressed": 2, > "optimize": 2, > "includes": includes, > "excludes": excludes, > "packages": packages, > "dll_excludes": dll_excludes, > # using 2 to reduce number of files in dist > folder > # using 1 is not recommended as it often > does not work > "bundle_files": 2, > "dist_dir": 'dist', > "xref": False, > "skip_archive": False, > "ascii": False, > "custom_boot_script": '', > } > }, > > # using zipfile to reduce number of files in dist > zipfile = r'lib\library.zip', > > data_files=data_files > ) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Tue Sep 14 09:11:31 2010 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 14 Sep 2010 14:11:31 +0100 Subject: Expected bahaviour of os.chroot and os.getcwd References: Message-ID: On 14/09/10 11:19, Nobody wrote: > On Mon, 13 Sep 2010 19:04:53 +0100, r0g wrote: > >> i.e. So do I always have to change directory after changing into a chroot? > > You don't *have* to change the directory, but not doing so probably > defeats the point of performing a chroot(). Thanks for the info 'Nobody', that was really clear and helpful :) It's kinda obvious once it's pointed out I suppose, the docs for the os module are primarily the os's own docs, should have thought to check the manpages eh, duh! Thanks very much for getting back to me, Roger. From lsolesen at gmail.com Tue Sep 14 10:14:51 2010 From: lsolesen at gmail.com (lsolesen) Date: Tue, 14 Sep 2010 07:14:51 -0700 (PDT) Subject: Install python-mcrypt on Ubuntu Message-ID: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> I am trying to install python-mcrypt (http://labix.org/python-mcrypt) on Ubuntu, but I cannot get it to work. I have the following python installed: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 I get the following message when trying to install. lsolesen at lsolesen-lenovo:~/Desktop/python-mcrypt-1.1$ python setup.py install running install running build running build_ext building 'mcrypt' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o mcrypt.c:24:20: error: Python.h: No such file or directory mcrypt.c:25:26: error: structmember.h: No such file or directory mcrypt.c:39: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:43: error: ?NULL? undeclared here (not in a function) mcrypt.c:54: error: expected specifier-qualifier-list before ?PyObject_HEAD? mcrypt.c:69: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?MCRYPT_members? mcrypt.c:75: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?PyTypeObject? mcrypt.c: In function ?catch_mcrypt_error?: mcrypt.c:89: warning: implicit declaration of function ?strdup? mcrypt.c:89: warning: incompatible implicit declaration of built-in function ?strdup? mcrypt.c:90: warning: implicit declaration of function ?strlen? mcrypt.c:90: warning: incompatible implicit declaration of built-in function ?strlen? mcrypt.c:92: warning: implicit declaration of function ?PyErr_SetString? mcrypt.c:92: error: ?MCRYPTError? undeclared (first use in this function) mcrypt.c:92: error: (Each undeclared identifier is reported only once mcrypt.c:92: error: for each function it appears in.) mcrypt.c:93: warning: implicit declaration of function ?free? mcrypt.c:93: warning: incompatible implicit declaration of built-in function ?free? mcrypt.c: At top level: mcrypt.c:103: error: expected declaration specifiers or ?...? before ?PyObject? mcrypt.c: In function ?get_iv_from_obj?: mcrypt.c:105: error: ?ivobj? undeclared (first use in this function) mcrypt.c:105: error: ?Py_None? undeclared (first use in this function) mcrypt.c:107: warning: implicit declaration of function ?PyString_Check? mcrypt.c:108: warning: implicit declaration of function ?PyString_Size? mcrypt.c:109: warning: implicit declaration of function ?PyString_AsString? mcrypt.c:110: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:111: warning: implicit declaration of function ?PyErr_Format? mcrypt.c:111: error: ?PyExc_ValueError? undeclared (first use in this function) mcrypt.c:113: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:117: error: ?PyExc_TypeError? undeclared (first use in this function) mcrypt.c: In function ?check_algorithm?: mcrypt.c:133: warning: implicit declaration of function ?strcmp? mcrypt.c: In function ?check_key?: mcrypt.c:167: error: ?PyExc_ValueError? undeclared (first use in this function) mcrypt.c:171: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:180: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?init_mcrypt?: mcrypt.c:208: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:225: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:230: error: ?MCRYPTError? undeclared (first use in this function) mcrypt.c:258: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:258: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:259: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:261: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:263: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:266: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:267: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:268: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:269: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:271: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:272: warning: implicit declaration of function ?PyMem_Free? mcrypt.c:272: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:273: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:274: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:275: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:276: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:279: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:282: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:283: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:284: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:285: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:286: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:287: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:290: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:297: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:297: warning: implicit declaration of function ?PyMem_Malloc? mcrypt.c:298: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:299: warning: implicit declaration of function ?PyErr_NoMemory? mcrypt.c:302: warning: implicit declaration of function ?memcpy? mcrypt.c:302: warning: incompatible implicit declaration of built-in function ?memcpy? mcrypt.c:302: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:303: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:303: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:304: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:309: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:309: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:311: warning: implicit declaration of function ?memset? mcrypt.c:311: warning: incompatible implicit declaration of built-in function ?memset? mcrypt.c:311: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:311: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:313: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:316: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:317: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:318: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:319: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:322: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:323: error: ?MCRYPTObject? has no member named ?init? mcrypt.c: In function ?MCRYPT_dealloc?: mcrypt.c:332: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:333: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:335: warning: implicit declaration of function ?PyErr_Clear? mcrypt.c:337: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:338: warning: incompatible implicit declaration of built-in function ?free? mcrypt.c:338: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:339: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:341: error: ?MCRYPTObject? has no member named ?ob_type? mcrypt.c:341: error: ?PyObject? undeclared (first use in this function) mcrypt.c:341: error: expected expression before ?)? token mcrypt.c: At top level: mcrypt.c:345: error: expected declaration specifiers or ?...? before ?PyObject? mcrypt.c:345: error: expected declaration specifiers or ?...? before ?PyObject? mcrypt.c: In function ?MCRYPT__init__?: mcrypt.c:351: error: ?PyObject? undeclared (first use in this function) mcrypt.c:351: error: ?aobj? undeclared (first use in this function) mcrypt.c:352: error: ?mobj? undeclared (first use in this function) mcrypt.c:357: warning: implicit declaration of function ?PyArg_ParseTupleAndKeywords? mcrypt.c:357: error: ?args? undeclared (first use in this function) mcrypt.c:357: error: ?kwargs? undeclared (first use in this function) mcrypt.c:363: error: ?Py_None? undeclared (first use in this function) mcrypt.c:368: error: ?PyExc_TypeError? undeclared (first use in this function) mcrypt.c:389: error: ?MCRYPTError? undeclared (first use in this function) mcrypt.c:411: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:413: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:418: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:418: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:419: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:420: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:423: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:423: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:424: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:425: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:428: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:428: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:429: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:430: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:434: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:434: warning: incompatible implicit declaration of built-in function ?strdup? mcrypt.c:435: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c: At top level: mcrypt.c:458: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:491: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:511: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:535: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:597: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:668: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:806: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:940: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:954: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:972: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1002: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1023: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1039: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1056: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1070: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1079: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?MCRYPT_methods? mcrypt.c:1164: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?PyTypeObject? mcrypt.c:1212: error: expected ?)? before ?*? token mcrypt.c:1236: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1266: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1300: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1348: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1397: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1430: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1463: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1496: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1531: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1567: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?*? token mcrypt.c:1605: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?mcrypt_methods? mcrypt.c:1705: warning: return type defaults to ?int? mcrypt.c: In function ?DL_EXPORT?: mcrypt.c:1705: error: expected declaration specifiers before ?initmcrypt? mcrypt.c:1768: error: expected ?{? at end of input error: command 'gcc' failed with exit status 1 From lsolesen at gmail.com Tue Sep 14 10:26:44 2010 From: lsolesen at gmail.com (lsolesen) Date: Tue, 14 Sep 2010 07:26:44 -0700 (PDT) Subject: Install python-mcrypt on Ubuntu References: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> Message-ID: Tried on another machine, but with this error: lsolesen at lsolesen-toshiba:~/Desktop/python-mcrypt-1.1$ python setup.py install running install running build running build_ext building 'mcrypt' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o mcrypt.c:23:20: error: mcrypt.h: No such file or directory mcrypt.c:55: error: expected specifier-qualifier-list before ?MCRYPT? mcrypt.c:70: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:71: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c: In function ?catch_mcrypt_error?: mcrypt.c:86: warning: implicit declaration of function ?mcrypt_strerror? mcrypt.c:86: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?get_iv_from_obj?: mcrypt.c:110: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:110: warning: comparison between pointer and integer mcrypt.c:113: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:113: warning: format ?%d? expects type ?int?, but argument 3 has type ?struct PyMemberDef *? mcrypt.c: In function ?check_algorithm?: mcrypt.c:130: warning: implicit declaration of function ?mcrypt_list_algorithms? mcrypt.c:130: warning: assignment makes pointer from integer without a cast mcrypt.c:134: warning: implicit declaration of function ?mcrypt_free_p? mcrypt.c: In function ?check_mode?: mcrypt.c:147: warning: implicit declaration of function ?mcrypt_list_modes? mcrypt.c:147: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?check_key?: mcrypt.c:171: warning: implicit declaration of function ?mcrypt_enc_get_key_size? mcrypt.c:171: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:180: warning: implicit declaration of function ?mcrypt_enc_get_supported_key_sizes? mcrypt.c:180: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:180: warning: assignment makes pointer from integer without a cast mcrypt.c:188: warning: implicit declaration of function ?mcrypt_free? mcrypt.c: In function ?init_mcrypt?: mcrypt.c:208: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:208: warning: initialization makes integer from pointer without a cast mcrypt.c:225: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:225: warning: statement with no effect mcrypt.c:258: warning: implicit declaration of function ?mcrypt_enc_set_state? mcrypt.c:258: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:258: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:259: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:261: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:261: warning: statement with no effect mcrypt.c:263: warning: implicit declaration of function ?mcrypt_generic_deinit? mcrypt.c:263: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:266: warning: implicit declaration of function ?mcrypt_generic_init? mcrypt.c:266: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:267: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:268: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:269: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:271: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:271: warning: statement with no effect mcrypt.c:272: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:273: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:274: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:274: warning: statement with no effect mcrypt.c:275: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:275: warning: statement with no effect mcrypt.c:276: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:276: warning: statement with no effect mcrypt.c:279: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:279: warning: statement with no effect mcrypt.c:282: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:282: warning: statement with no effect mcrypt.c:283: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:284: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:285: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:285: warning: statement with no effect mcrypt.c:286: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:286: warning: statement with no effect mcrypt.c:287: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:287: warning: statement with no effect mcrypt.c:290: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:297: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:297: warning: statement with no effect mcrypt.c:298: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:302: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:303: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:303: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:303: warning: passing argument 1 of ?PyMem_Malloc? makes integer from pointer without a cast /usr/include/python2.6/pymem.h:52: note: expected ?size_t? but argument is of type ?struct PyMemberDef *? mcrypt.c:303: warning: statement with no effect mcrypt.c:304: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:309: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:309: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:309: warning: passing argument 3 of ?memcpy? makes integer from pointer without a cast /usr/include/bits/string3.h:49: note: expected ?size_t? but argument is of type ?struct PyMemberDef *? mcrypt.c:311: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:311: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:311: warning: passing argument 3 of ?memset? makes integer from pointer without a cast /usr/include/bits/string3.h:78: note: expected ?size_t? but argument is of type ?struct PyMemberDef *? mcrypt.c:313: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:316: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:317: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:318: error: ?MCRYPTObject? has no member named ?init_iv? mcrypt.c:318: warning: statement with no effect mcrypt.c:319: error: ?MCRYPTObject? has no member named ?init_key? mcrypt.c:319: warning: statement with no effect mcrypt.c:322: error: ?MCRYPTObject? has no member named ?init_key_size? mcrypt.c:322: warning: statement with no effect mcrypt.c:323: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:323: warning: statement with no effect mcrypt.c: In function ?MCRYPT_dealloc?: mcrypt.c:332: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:333: error: ?MCRYPTObject? has no member named ?init? mcrypt.c:337: warning: implicit declaration of function ?mcrypt_module_close? mcrypt.c:337: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:338: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:339: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c: In function ?MCRYPT__init__?: mcrypt.c:397: warning: implicit declaration of function ?mcrypt_module_is_block_algorithm? mcrypt.c:400: warning: implicit declaration of function ?mcrypt_module_is_block_algorithm_mode? mcrypt.c:411: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:411: warning: implicit declaration of function ?mcrypt_module_open? mcrypt.c:411: warning: statement with no effect mcrypt.c:413: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:413: error: ?MCRYPT_FAILED? undeclared (first use in this function) mcrypt.c:413: error: (Each undeclared identifier is reported only once mcrypt.c:413: error: for each function it appears in.) mcrypt.c:418: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:418: warning: implicit declaration of function ?mcrypt_enc_is_block_mode? mcrypt.c:418: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:418: warning: statement with no effect mcrypt.c:419: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:419: warning: passing argument 1 of ?catch_mcrypt_error? makes integer from pointer without a cast mcrypt.c:80: note: expected ?int? but argument is of type ?struct PyMemberDef *? mcrypt.c:420: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:423: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:423: warning: implicit declaration of function ?mcrypt_enc_get_block_size? mcrypt.c:423: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:423: warning: statement with no effect mcrypt.c:424: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:424: warning: passing argument 1 of ?catch_mcrypt_error? makes integer from pointer without a cast mcrypt.c:80: note: expected ?int? but argument is of type ?struct PyMemberDef *? mcrypt.c:425: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:428: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:428: warning: implicit declaration of function ?mcrypt_enc_get_iv_size? mcrypt.c:428: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:428: warning: statement with no effect mcrypt.c:429: error: ?MCRYPTObject? has no member named ?iv_size? mcrypt.c:429: warning: passing argument 1 of ?catch_mcrypt_error? makes integer from pointer without a cast mcrypt.c:80: note: expected ?int? but argument is of type ?struct PyMemberDef *? mcrypt.c:430: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:434: error: ?MCRYPTObject? has no member named ?algorithm? mcrypt.c:434: warning: statement with no effect mcrypt.c:435: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:435: warning: statement with no effect mcrypt.c: In function ?MCRYPT_encrypt?: mcrypt.c:551: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:552: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:552: warning: assignment makes integer from pointer without a cast mcrypt.c:575: warning: implicit declaration of function ?mcrypt_generic? mcrypt.c:575: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_decrypt?: mcrypt.c:614: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:615: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:615: warning: assignment makes integer from pointer without a cast mcrypt.c:632: warning: implicit declaration of function ?mdecrypt_generic? mcrypt.c:632: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_encrypt_file?: mcrypt.c:700: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:700: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:700: warning: assignment makes integer from pointer without a cast mcrypt.c:738: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:738: error: invalid operands to binary / (have ?int? and ?struct PyMemberDef *?) mcrypt.c:738: warning: assignment makes integer from pointer without a cast mcrypt.c:739: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:739: error: invalid operands to binary % (have ?int? and ?struct PyMemberDef *?) mcrypt.c:739: warning: assignment makes integer from pointer without a cast mcrypt.c:745: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:745: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:745: warning: assignment makes integer from pointer without a cast mcrypt.c:751: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:751: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:751: warning: assignment makes integer from pointer without a cast mcrypt.c:757: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_decrypt_file?: mcrypt.c:841: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:841: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:841: warning: assignment makes integer from pointer without a cast mcrypt.c:887: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:887: error: invalid operands to binary / (have ?int? and ?struct PyMemberDef *?) mcrypt.c:887: warning: assignment makes integer from pointer without a cast mcrypt.c:888: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:888: error: invalid operands to binary * (have ?int? and ?struct PyMemberDef *?) mcrypt.c:888: warning: assignment makes integer from pointer without a cast mcrypt.c:893: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:902: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:902: warning: assignment makes integer from pointer without a cast mcrypt.c:905: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:905: warning: comparison between pointer and integer mcrypt.c:907: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:907: warning: assignment makes integer from pointer without a cast mcrypt.c:913: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:913: error: invalid operands to binary - (have ?int? and ?struct PyMemberDef *?) mcrypt.c:919: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:919: warning: comparison between pointer and integer mcrypt.c: In function ?MCRYPT_get_block_size?: mcrypt.c:943: error: ?MCRYPTObject? has no member named ?block_size? mcrypt.c:943: warning: passing argument 1 of ?PyInt_FromLong? makes integer from pointer without a cast /usr/include/python2.6/intobject.h:38: note: expected ?long int? but argument is of type ?struct PyMemberDef *? mcrypt.c: In function ?MCRYPT_get_key_size?: mcrypt.c:957: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_get_key_sizes?: mcrypt.c:979: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c:979: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?MCRYPT_has_iv?: mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 1 of ?strlen? from incompatible pointer type /usr/include/string.h:397: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 2 of ?__builtin_strcmp? from incompatible pointer type mcrypt.c:1008: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 2 of ?__builtin_strcmp? from incompatible pointer type mcrypt.c:1008: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 1 of ?strlen? from incompatible pointer type /usr/include/string.h:397: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 2 of ?__builtin_strcmp? from incompatible pointer type mcrypt.c:1008: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: error: ?MCRYPTObject? has no member named ?mode? mcrypt.c:1008: warning: passing argument 2 of ?__builtin_strcmp? from incompatible pointer type mcrypt.c:1008: note: expected ?const char *? but argument is of type ?struct PyMemberDef *? mcrypt.c:1010: warning: implicit declaration of function ?mcrypt_enc_mode_has_iv? mcrypt.c:1010: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_get_iv_size?: mcrypt.c:1026: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_is_block_algorithm?: mcrypt.c:1042: warning: implicit declaration of function ?mcrypt_enc_is_block_algorithm? mcrypt.c:1042: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?MCRYPT_is_block_mode?: mcrypt.c:1059: error: ?MCRYPTObject? has no member named ?block_mode? mcrypt.c:1059: warning: passing argument 1 of ?PyInt_FromLong? makes integer from pointer without a cast /usr/include/python2.6/intobject.h:38: note: expected ?long int? but argument is of type ?struct PyMemberDef *? mcrypt.c: In function ?MCRYPT_is_block_algorithm_mode?: mcrypt.c:1073: warning: implicit declaration of function ?mcrypt_enc_is_block_algorithm_mode? mcrypt.c:1073: error: ?MCRYPTObject? has no member named ?thread? mcrypt.c: In function ?_mcrypt_list_algorithms?: mcrypt.c:1316: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?_mcrypt_list_modes?: mcrypt.c:1364: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ?_mcrypt_is_block_mode?: mcrypt.c:1445: warning: implicit declaration of function ?mcrypt_module_is_block_mode? mcrypt.c: In function ?_mcrypt_get_block_size?: mcrypt.c:1512: warning: implicit declaration of function ?mcrypt_module_get_algo_block_size? mcrypt.c: In function ?_mcrypt_get_key_size?: mcrypt.c:1547: warning: implicit declaration of function ?mcrypt_module_get_algo_key_size? mcrypt.c: In function ?_mcrypt_get_key_sizes?: mcrypt.c:1585: warning: implicit declaration of function ?mcrypt_module_get_algo_supported_key_sizes? mcrypt.c:1586: warning: assignment makes pointer from integer without a cast error: command 'gcc' failed with exit status 1 From lists at cheimes.de Tue Sep 14 10:28:16 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 14 Sep 2010 16:28:16 +0200 Subject: Install python-mcrypt on Ubuntu In-Reply-To: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> References: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> Message-ID: Am 14.09.2010 16:14, schrieb lsolesen: > I am trying to install python-mcrypt (http://labix.org/python-mcrypt) > on Ubuntu, but I cannot get it to work. I have the following python > installed: sudo apt-get install python-dev Christian From lallous at lgwm.org Tue Sep 14 10:30:50 2010 From: lallous at lgwm.org (lallous) Date: Tue, 14 Sep 2010 07:30:50 -0700 (PDT) Subject: help with calling a static method in a private class Message-ID: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> How can I keep the class private and have the following work: [code] class __internal_class(object): @staticmethod def meth1(s): print "meth1:", s @staticmethod def meth2(s): print "meth2:", __internal_class.meth1(s) x = __internal_class() x.meth2('sdf') [/code] Thanks From deets at web.de Tue Sep 14 10:38:50 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 14 Sep 2010 16:38:50 +0200 Subject: help with calling a static method in a private class References: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> Message-ID: <87r5gwgzk5.fsf@web.de> lallous writes: > How can I keep the class private and have the following work: > > [code] > class __internal_class(object): > @staticmethod > def meth1(s): > print "meth1:", s > > @staticmethod > def meth2(s): > print "meth2:", > __internal_class.meth1(s) > > x = __internal_class() > > x.meth2('sdf') > [/code] By not using a double underscore. It is effectless on classes anyway (they are not hidden because of that). And additionally, but simply not using staticmethods at all. It's a rather obscure feature of python - usually, classmethods are what is considered a static method in other languages. And with that, even your double underscores work: class __internal_class(object): @classmethod def meth1(cls, s): print "meth1:", s @classmethod def meth2(cls, s): print "meth2:", cls.meth1(s) x = __internal_class() x.meth2('sdf') Diez From lists at cheimes.de Tue Sep 14 10:41:29 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 14 Sep 2010 16:41:29 +0200 Subject: Install python-mcrypt on Ubuntu In-Reply-To: References: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> Message-ID: Am 14.09.2010 16:26, schrieb lsolesen: > Tried on another machine, but with this error: > > lsolesen at lsolesen-toshiba:~/Desktop/python-mcrypt-1.1$ python setup.py > install > running install > running build > running build_ext > building 'mcrypt' extension > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - > Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c > mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o > mcrypt.c:23:20: error: mcrypt.h: No such file or directory You are missing the development headers for mcrypt, too. sudo apt-get install libmcrypt-dev Christian From benjamin.kaplan at case.edu Tue Sep 14 10:48:27 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Sep 2010 10:48:27 -0400 Subject: Install python-mcrypt on Ubuntu In-Reply-To: References: <3e2074b5-d0a3-419e-818f-3ac530394bbc@k30g2000vbn.googlegroups.com> Message-ID: On Tue, Sep 14, 2010 at 10:26 AM, lsolesen wrote: > > mcrypt.c:23:20: error: mcrypt.h: No such file or directory Well, there's your problem. You don't have the mcrypt headers installed. sudo apt-get install libmcrypt-dev From bruno.42.desthuilliers at websiteburo.invalid Tue Sep 14 11:34:11 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 14 Sep 2010 17:34:11 +0200 Subject: help with calling a static method in a private class In-Reply-To: <87r5gwgzk5.fsf@web.de> References: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> <87r5gwgzk5.fsf@web.de> Message-ID: <4c8f95eb$0$21752$426a74cc@news.free.fr> Diez B. Roggisch a ?crit : > lallous writes: > >> How can I keep the class private and have the following work: >> >> [code] >> class __internal_class(object): >> @staticmethod >> def meth1(s): >> print "meth1:", s >> >> @staticmethod >> def meth2(s): >> print "meth2:", >> __internal_class.meth1(s) >> >> x = __internal_class() >> >> x.meth2('sdf') >> [/code] > > By not using a double underscore. It is effectless on classes anyway > (they are not hidden because of that). FWIW, if what you want is to mark the class as being implementation (ie: not part of your module's API), just prefix it with a single underscore. > > And additionally, but simply not using staticmethods at all. +1 From nanothermite911fbibustards at gmail.com Tue Sep 14 11:37:34 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Tue, 14 Sep 2010 08:37:34 -0700 (PDT) Subject: The Brutal Truth About 911 MOSQUE - The JEWS and YANNKS themselves MAILED ANTHRAX and used NANO THERMITE to DEMOLISH the buildings Message-ID: Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA About me: The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From carlos.grohmann at gmail.com Tue Sep 14 11:45:21 2010 From: carlos.grohmann at gmail.com (Carlos Grohmann) Date: Tue, 14 Sep 2010 12:45:21 -0300 Subject: help removing pyQt dll from dist created with py2exe In-Reply-To: References: Message-ID: many thanks Almar. No more pyqt stuff in my dist. cheers carlos On Tue, Sep 14, 2010 at 09:21, Almar Klein wrote: > Hi, > > Have you tried adding "PyQt4", "PyQt4.QtGui" and "PyQt4.QtCore" to your list > of excludes? > (Maybe only "PyQt4.QtGui" is sufficient.) > > ? Almar > > > On 14 September 2010 13:02, Carlos Grohmann > wrote: >> >> Hello all, >> >> i've been trying to build an .exe with py2exe. After many tentatives, >> it worked, but the total space used by the app goes to 30Mb. It is a >> simple app, that uses wxpython, matplotlib and numpy. I checked the >> library.zip file and notived that there is a pyQt-related file there: >> >> Pyqt - QtGui.pyo - 8 Mb >> >> I'm not using Qt at all, so I assume it would be safe to not have this >> file, but I don't see how to do it. >> >> my setup.py file follows. >> >> many thanks >> >> Carlos >> >> >> #---------------------------------------------------------------------- >> from distutils.core import setup >> import py2exe >> from glob import glob >> >> # Remove the build folder, a bit slower but ensures that build >> contains the latest >> import shutil >> shutil.rmtree("build", ignore_errors=True) >> >> # my setup.py is based on one generated with gui2exe, so data_files is >> done a bit differently >> data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] >> >> includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', >> 'scrolledpanel', 'customtreectrl', >> ? ? ? ? ? ?'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', >> 'wx.lib.wordwrap', 'types', >> ? ? ? ? ? ?'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', >> 'matplotlib.figure', >> ? ? ? ? ? ?'matplotlib.backends.backend_wxagg', >> 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', >> ? ? ? ? ? ?'matplotlib.patches', 'matplotlib.lines', >> 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', >> ? ? ? ? ? ?'matplotlib.collections', 'matplotlib.font_manager', >> 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' >> ? ? ? ? ? ?] >> >> excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', >> ? ? ? ? ? ?'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', >> ? ? ? ? ? ?'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', >> 'sqlite3', >> ? ? ? ? ? ?'bsddb', 'curses', 'email','_fltkagg', '_gtk', >> '_gtkcairo', >> ? ? ? ? ? ?'_agg2', '_cairo', '_cocoaagg', >> 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' >> ? ? ? ? ? ?] >> >> packages = ['encodings','pytz','scipy'] >> >> dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', >> 'tcl84.dll', 'tk84.dll', >> ? ? ? ? ? ? ? ?'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', >> 'libglib-2.0-0.dll', >> ? ? ? ? ? ? ? ?'libcairo-2.dll', 'libpango-1.0-0.dll', >> 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', >> ? ? ? ? ? ? ? ?'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', >> 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', >> ? ? ? ? ? ? ? ?'QtCore4.dll' >> ? ? ? ? ? ? ? ?] >> >> icon_resources = [] >> bitmap_resources = [] >> other_resources = [] >> >> # add the mpl mpl-data folder and rc file >> import matplotlib as mpl >> data_files += mpl.get_py2exe_datafiles() >> >> setup( >> ? ?windows=['OpenStereo.py'], >> ? ? ? ? ? ? ? ? ? ? ? ? ?# compressed and optimize reduce the size >> ? ?options = {"py2exe": {"compressed": 2, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"optimize": 2, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"includes": includes, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"excludes": excludes, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"packages": packages, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"dll_excludes": dll_excludes, >> ? ? ? ? ? ? ? ? ? ? ? ? ?# using 2 to reduce number of files in dist >> folder >> ? ? ? ? ? ? ? ? ? ? ? ? ?# using 1 is not recommended as it often >> does not work >> ? ? ? ? ? ? ? ? ? ? ? ? ?"bundle_files": 2, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"dist_dir": 'dist', >> ? ? ? ? ? ? ? ? ? ? ? ? ?"xref": False, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"skip_archive": False, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"ascii": False, >> ? ? ? ? ? ? ? ? ? ? ? ? ?"custom_boot_script": '', >> ? ? ? ? ? ? ? ? ? ? ? ? } >> ? ? ? ? ? ? ?}, >> >> ? ?# using zipfile to reduce number of files in dist >> ? ?zipfile = r'lib\library.zip', >> >> ? ?data_files=data_files >> ) >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- Prof. Carlos Henrique Grohmann - Geologist D.Sc. Institute of Geosciences - Univ. of S?o Paulo, Brazil http://www.igc.usp.br/pessoais/guano http://lattes.cnpq.br/5846052449613692 Linux User #89721 ________________ Can?t stop the signal. From post at andre-bell.de Tue Sep 14 12:59:48 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Tue, 14 Sep 2010 18:59:48 +0200 Subject: String formatting with the format string syntax Message-ID: <4C8FAA04.8000201@andre-bell.de> Hello, I'm used to write in Python something like >>> s = 'some text that says: %(hello)s' and then have a dictionary like >>> english = { 'hello': 'hello' } and get the formatted output like this: >>> s % english Occasionally I want to extract the field names from the template string. I was used to write a class like class Extractor(object): def __init__(self): self.keys = [] def __getitem__(self, key): self.keys.append(key) return '' and use it like this: >>> e = Extractor() >>> res = s % e >>> e.keys ['hello'] Now Python has the format method for string formatting with the more advanced handling. So I could as well write >>> s = 'some text that says: {hello!s}' >>> s.format(hello='hello') My question is, if I do have a string template which uses the newer format string syntax, how do I best extract the field information? I found the str._formatter_parser() method which I could use like this: keys = [] for (a, key, c, d) in s._formatter_parser(): if key: keys.append(key) Is there a more elegant solution? What are a, c, d? Where can I find additional information on this method? Should one use a method that actually starts with an _? Couldn't this one change any time soon? Thanks for any help Andre From miki.tebeka at gmail.com Tue Sep 14 14:20:18 2010 From: miki.tebeka at gmail.com (Miki) Date: Tue, 14 Sep 2010 11:20:18 -0700 (PDT) Subject: String formatting with the format string syntax References: Message-ID: You can use ** syntax: >>> english = {'hello':'hello'} >>> s.format(**english) On Sep 14, 9:59?am, Andre Alexander Bell wrote: > Hello, > > I'm used to write in Python something like > > ?>>> s = 'some text that says: %(hello)s' > > and then have a dictionary like > > ?>>> english = { 'hello': 'hello' } > > and get the formatted output like this: > > ?>>> s % english > > Occasionally I want to extract the field names from the template string. > I was used to write a class like > > class Extractor(object): > ? ? ?def __init__(self): > ? ? ? ? ?self.keys = [] > ? ? ?def __getitem__(self, key): > ? ? ? ? ?self.keys.append(key) > ? ? ? ? ?return '' > > and use it like this: > > ?>>> e = Extractor() > ?>>> res = s % e > ?>>> e.keys > ['hello'] > > Now Python has the format method for string formatting with the more > advanced handling. So I could as well write > > ?>>> s = 'some text that says: {hello!s}' > ?>>> s.format(hello='hello') > > My question is, if I do have a string template which uses the newer > format string syntax, how do I best extract the field information? > > I found the str._formatter_parser() method which I could use like this: > > keys = [] > for (a, key, c, d) in s._formatter_parser(): > ? ? ?if key: > ? ? ? ? ?keys.append(key) > > Is there a more elegant solution? > What are a, c, d? > Where can I find additional information on this method? > Should one use a method that actually starts with an _? > Couldn't this one change any time soon? > > Thanks for any help > > Andre From neil.benn at ziath.com Tue Sep 14 14:36:18 2010 From: neil.benn at ziath.com (Neil Benn) Date: Tue, 14 Sep 2010 11:36:18 -0700 Subject: Cross Compiling Python for ARM Message-ID: Hello, I've been working on an embedded ARM system which boots up quick (a beagleboard running a skinnied down version of Angstrom). For this I need to compile a lot of libraries from scratch. One of the things I need is Python; I've cross compiled Python and it works OK when I try to run it on an image on the same system which is more complete (the same hardware running Lucid Ubuntu). However when I try to run on the skinnied down image I get the following feedback: # ./python -sh: ./python: not found I'm guessing that Python is depending on some libraries which I don't have but as my situation is unusual I'm not sure what I am missing. So, I'm asking for help which is what libraries does python depend on on Linux? Thanks in advance. Cheers, Neil -- -- Neil Benn Msc Director Ziath Ltd Phone :+44 (0)7508 107942 Website - http://www.ziath.com IMPORTANT NOTICE: This message, including any attached documents, is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify Ziath Ltd immediately by email at info at ziath.com. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollybox.de Tue Sep 14 15:19:16 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Tue, 14 Sep 2010 21:19:16 +0200 Subject: Cross Compiling Python for ARM In-Reply-To: References: Message-ID: <201009142119.17639.thomas@jollybox.de> On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: > # > ./python > > -sh: ./python: not found I'm guessing either there is no file ./python, or /bin/sh is fundamentally broken. From thomas at jollybox.de Tue Sep 14 15:20:25 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Tue, 14 Sep 2010 21:20:25 +0200 Subject: String formatting with the format string syntax In-Reply-To: References: Message-ID: <201009142120.25442.thomas@jollybox.de> On Tuesday 14 September 2010, it occurred to Miki to exclaim: > You can use ** syntax: > >>> english = {'hello':'hello'} > >>> s.format(**english) No, you can't. This only works with dicts, not with arbitrary mappings, or dict subclasses that try to do some kind of funny stuff. > > On Sep 14, 9:59 am, Andre Alexander Bell wrote: > > Hello, > > > > I'm used to write in Python something like > > > > >>> s = 'some text that says: %(hello)s' > > > > and then have a dictionary like > > > > >>> english = { 'hello': 'hello' } > > > > and get the formatted output like this: > > > > >>> s % english > > > > Occasionally I want to extract the field names from the template string. > > I was used to write a class like > > > > class Extractor(object): > > def __init__(self): > > self.keys = [] > > def __getitem__(self, key): > > self.keys.append(key) > > return '' > > > > and use it like this: > > > > >>> e = Extractor() > > >>> res = s % e > > >>> e.keys > > ['hello'] > > > > Now Python has the format method for string formatting with the more > > advanced handling. So I could as well write > > > > >>> s = 'some text that says: {hello!s}' > > >>> s.format(hello='hello') > > > > My question is, if I do have a string template which uses the newer > > format string syntax, how do I best extract the field information? > > > > I found the str._formatter_parser() method which I could use like this: > > > > keys = [] > > for (a, key, c, d) in s._formatter_parser(): > > if key: > > keys.append(key) > > > > Is there a more elegant solution? > > What are a, c, d? > > Where can I find additional information on this method? > > Should one use a method that actually starts with an _? > > Couldn't this one change any time soon? > > > > Thanks for any help > > > > Andre From blye at telkomsa.net Tue Sep 14 15:20:28 2010 From: blye at telkomsa.net (bli) Date: Tue, 14 Sep 2010 12:20:28 -0700 (PDT) Subject: WMI in Python References: Message-ID: <26ea4ebe-d455-47d6-b637-4e8ecb895f2d@k9g2000vbo.googlegroups.com> On Sep 14, 7:46?am, KING LABS wrote: > On Sep 14, 10:39?am, KING LABS wrote: > > > > > > > > > > > On Sep 13, 8:31?pm, Jerry Hill wrote: > > > > On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > > > > Hi All, > > > > > I am new to programming and python, Being a system administrator I > > > > have chose Inventory (Software & Hardware ) as my first project. > > > > You'll probably want to look at the python WMI module:http://timgolden.me.uk/python/wmi/index.html > > > > as well as the pywin32 module:http://sourceforge.net/projects/pywin32/ > > > > IIRC, there's been quite a bit of discussion about inventorying > > > installed software on the pywin32 mailing list:http://mail.python.org/mailman/listinfo/python-win32 > > > > -- > > > Jerry > > > Thank you all, I will go through the links provided and suggestions. > > Shall get back to you on this soon. > > The following information is exactly what I am trying to collect for > the inventory. I can find vb scripts with googling. I want to do the > same with Python & Win32. Use Server/Client architecture . > Client(agent) updates the information to server. > > ---------------------------------------------------------------------------------------- > > BIOS: > > System serial number, manufacturer, and model > Bios manufacturer, version, and date > > Processors: > > Type, count (how many of them), manufacturer, speed, and cache > > Memory: > > Physical memory type, manufacturer, capacity, and slot number > Total physical memory > Total swap/paging memory > > Video: > > Video adapter: Chipset/model, manufacturer, memory size, speed, and > screen resolution > > Display monitor: Manufacturer, description, refresh rate, type, serial > number, and caption > > Storage/removable devices: > > Manufacturer, model, size, type, speed( all when applicable) > > Drive letter, filesystem type, partition/volume size, free space > > Network adapters/telephony: > > Manufacturer, model, type, speed, and description > MAC and IP address, mask and IP gateway, DHCP server used > > Miscellaneous hardware: > > Input devices: Keyboard, mouse, and pointing device > Sound devices: Manufacturer name, type, and description > System slots: Name, type, and designation > System ports: Type, name, caption, and description > > Software Information: ( from registry & add/remove program ) > > Operating system: Name, version, comments, and registration info > Installed software: Name, publisher, version (from Add / Remove > software or Programs and Features menu) > Custom-specified registry queries (applicable to Windows OS) > > ------------------------------------------------------------------------------------------------------------------ when I found Python :-) I downloaded from a Ms site many (+- 120) py programs for hardware and os stuff and collated them into one script. Astonishing amount of data in the innards of a computer, do not print some of these!@#! I meant to wrap it in a neat menu (any time now), but it is easy to use as is. A few of the options : 102 --- -List Terminal Services Terminals- 103 --- -List Terminal Services Permissions- 104 --- -List Terminal Services Session Settings- 105 --- - List Terminal Services Session Directory Settings- 106 --- - List Terminal Services Network Adapter- 107 --- -List Terminal Services Environment Settings- 108 --- -List Terminal Services Logon Settings- 109 --- -List Terminal Services General Settings- 110 --- -List Terminal Services Client Settings- 111 --- -List Terminal Services Terminal Settings- 112 --- -List Terminal Service Service Properties- 113 --- -List Info about Binary Files used on Computer- 114 --- -List Info about CODECS on this computer- 115 --- -List Installed Software- 116 --- -List Installed Software Features- Happy to send to you, will post it somewhere soon. From benjamin.kaplan at case.edu Tue Sep 14 15:57:32 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Sep 2010 15:57:32 -0400 Subject: String formatting with the format string syntax In-Reply-To: <201009142120.25442.thomas@jollybox.de> References: <201009142120.25442.thomas@jollybox.de> Message-ID: On Tue, Sep 14, 2010 at 3:20 PM, Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Miki to exclaim: >> You can use ** syntax: >> >>> english = {'hello':'hello'} >> >>> s.format(**english) > > No, you can't. This only works with dicts, not with arbitrary mappings, or > dict subclasses that try to do some kind of funny stuff. > That was changed in 2.6 http://docs.python.org/release/2.6.6/whatsnew/2.6.html#other-language-changes From david at boddie.org.uk Tue Sep 14 15:59:58 2010 From: david at boddie.org.uk (David Boddie) Date: Tue, 14 Sep 2010 21:59:58 +0200 Subject: Cross Compiling Python for ARM References: Message-ID: On Tuesday 14 September 2010 21:19, Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: >> # >> ./python >> >> -sh: ./python: not found > > > I'm guessing either there is no file ./python, or /bin/sh is fundamentally > broken. Yes, it may be instructive to use the file command to see what ./python actually is: file ./python David From nytrokiss at gmail.com Tue Sep 14 17:25:00 2010 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 14 Sep 2010 14:25:00 -0700 Subject: Default python compile options Message-ID: Hi, I am trying to compile Python 2.7 on Ubuntu and I am wondering what are the default compile options (i.e ./configure ..) for ubuntu. I just want the standard ones that are included with the python2.6 version on ubuntu. Can someone please shed some light? Thanks, James -- http://www.goldwatches.com -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From sridharr at activestate.com Tue Sep 14 17:25:24 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Tue, 14 Sep 2010 14:25:24 -0700 Subject: python27.exe vs python2.7.exe ... Message-ID: Hi, As you may already know, ActivePython provides versioned Python executables that makes it possible to invoke a particular X.Y version from the command line directly if you have multiple Python versions on PATH. Eg: C:\Python27\python26.exe C:\Python27\python27.exe C:\Python31\python31.exe In the upcoming releases, we are considering to change this format to match the unix executables (with a 'dot' in it). Eg: C:\Python27\python2.6.exe C:\Python27\python2.7.exe C:\Python31\python3.1.exe The idea is to be able to invoke "python2.7 myscript.py" on both Unix and Windows. Thoughts? Because there is bin/python3 on unix (to separate it from the default 2.x interpreter) - it is perhaps a good idea to have "C:\Python31\python3.exe" as well. -srid From xrgtn at yandex.ru Tue Sep 14 17:42:52 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Wed, 15 Sep 2010 00:42:52 +0300 Subject: scp with paramiko In-Reply-To: <8bfa00e7-2ae5-42a3-bb45-fcdb491d70e4@x18g2000pro.googlegroups.com> References: <8bfa00e7-2ae5-42a3-bb45-fcdb491d70e4@x18g2000pro.googlegroups.com> Message-ID: <20100914214252.GA6755@xrgtn-q40> Hello, On Wed, Sep 01, 2010 at 09:56:18AM -0700, cerr wrote: > I want to download a file from a client using > paramiko. I found plenty of ressources using > google on how to send a file but none that > would describe how to download files from a > client. Download files from remote to local? Get sftp object as usual, then e.g.: for f in sftp.listdir(rdir): lf = os.path.join(opts.tmpdir, f) sftp.get(rdir + "/" + f, lf) sftp.get() uses path + "/" + basename instead of os.path.join() because the latter uses local pathname conventions which may or may not be appropriate for remote system. -- With best regards, xrgtn From prologic at shortcircuit.net.au Tue Sep 14 17:50:29 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 15 Sep 2010 07:50:29 +1000 Subject: Default python compile options In-Reply-To: References: Message-ID: On Wed, Sep 15, 2010 at 7:25 AM, James Matthews wrote: > I am trying to compile Python 2.7 on Ubuntu and I am wondering what are the > default compile options (i.e ./configure ..) for ubuntu. I just want the > standard ones that are included with the python2.6 version on ubuntu. Can > someone please shed some light? You can easily find this out for yourself. Ubuntu is a Debian-based system. Use dpkg-source to get the source package of python-2.6 and have a look at how it builds. cheers James PS: There's nothing wrong with a plain old ./configure (no options). -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Tue Sep 14 17:52:29 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 15 Sep 2010 07:52:29 +1000 Subject: python27.exe vs python2.7.exe ... In-Reply-To: References: Message-ID: On Wed, Sep 15, 2010 at 7:25 AM, Sridhar Ratnakumar wrote: > Thoughts? I've never been a Windows developer (probably never will be), but I have one thought: Why has ActivePython not been doing this all along ? cheers James -- -- James Mills -- -- "Problems are solved by method" From trentm at activestate.com Tue Sep 14 18:31:47 2010 From: trentm at activestate.com (Trent Mick) Date: Tue, 14 Sep 2010 15:31:47 -0700 Subject: python27.exe vs python2.7.exe ... In-Reply-To: References: Message-ID: <4C8FF7D3.1010805@activestate.com> On 10-09-14 2:52 PM, James Mills wrote: > On Wed, Sep 15, 2010 at 7:25 AM, Sridhar Ratnakumar > wrote: >> Thoughts? > > I've never been a Windows developer (probably never will be), but I > have one thought: > > Why has ActivePython not been doing this all along ? Hind sight is 20/20 is all I can say. :) When I added support for "pythonXY.exe" instead of "pythonX.Y.exe" I was trying to add an out-of-the-box equivalent for what I saw some core developers doing with their own batch scripts: py20.bat, py21.bat, etc. I didn't think to provide equivalence to the Unix shortcuts. Also, this was a looong time ago (back when python 1.5, 1.6 and 2.0 were still relevant) so it could be there there *weren't* many of the typical (now) Linux "pythonX.Y" installed executables. Trent -- Trent Mick ActiveState From prologic at shortcircuit.net.au Tue Sep 14 18:36:12 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 15 Sep 2010 08:36:12 +1000 Subject: python27.exe vs python2.7.exe ... In-Reply-To: <4C8FF7D3.1010805@activestate.com> References: <4C8FF7D3.1010805@activestate.com> Message-ID: On Wed, Sep 15, 2010 at 8:31 AM, Trent Mick wrote: > Hind sight is 20/20 is all I can say. :) Perhaps having 1/60 sight is better ? :) > When I added support for "pythonXY.exe" instead of "pythonX.Y.exe" I was > trying to add an out-of-the-box equivalent for what I saw some core > developers doing with their own batch scripts: py20.bat, py21.bat, etc. ?I > didn't think to provide equivalence to the Unix shortcuts. Also, this was a > looong time ago (back when python 1.5, 1.6 and 2.0 were still relevant) so > it could be there there *weren't* many of the typical (now) Linux > "pythonX.Y" installed executables. Good point :) My comment was just a comment, nothing negative intended! cheers james -- -- James Mills -- -- "Problems are solved by method" From post at andre-bell.de Tue Sep 14 19:14:02 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Wed, 15 Sep 2010 01:14:02 +0200 Subject: String formatting with the format string syntax In-Reply-To: References: Message-ID: <4C9001BA.8010705@andre-bell.de> On 09/14/2010 08:20 PM, Miki wrote: > You can use ** syntax: >>>> english = {'hello':'hello'} >>>> s.format(**english) Thanks for your answer. Actually your answer tells me that my example was misleading. Consider the template s = 'A template with {variable1} and {variable2} placeholders.' I'm seeking a way to extract the named placesholders, i.e. the names 'variable1' and 'variable2' from the template. I'm not trying to put in values for them. I hope this is clearer. Thanks again Andre From astan.chee at al.com.au Tue Sep 14 19:32:24 2010 From: astan.chee at al.com.au (Astan Chee) Date: Wed, 15 Sep 2010 09:32:24 +1000 Subject: webcam in gtalk/xmpp Message-ID: <4C900608.1030409@al.com.au> Hi, I was wondering if there is an implementation in any of the xmpp python API (e.g. xmpppy, etc) that implements broadcasting webcam (as well as audio-chat). The documentation on xmpppy doesn't show me how this can be done. Is this even possible? Thanks Astan From greg.ewing at canterbury.ac.nz Tue Sep 14 19:54:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 15 Sep 2010 11:54:00 +1200 Subject: Numpy: Multiplying arrays of matrices Message-ID: <8fag9dF4mtU1@mid.individual.net> Suppose I have two N+2 dimensional arrays, representing N-d arrays of 2-d matrices. I want to perform matrix multiplication between corresponding matrices in these arrays. I had thought that dot() might do this, but it appears not, because e.g. applying it to two 3-d arrays gives a 4-d array, not another 3-d array. I'd also like to be able to find the inverse of each matrix in one of these arrays, but again, inv() doesn't do what I want -- it only works on 2-d arrays. Any thoughts on how to achieve these things using numpy functions? -- Greg From nytrokiss at gmail.com Tue Sep 14 20:20:48 2010 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 14 Sep 2010 17:20:48 -0700 Subject: Default python compile options In-Reply-To: References: Message-ID: Thanks James, I did try the plain old configure but I was missing compression zlib and I wanted to make sure that I wasn't going to be be running in circles having to run ./configure a bunch of times so I decided to ask) James On Tue, Sep 14, 2010 at 2:50 PM, James Mills wrote: > On Wed, Sep 15, 2010 at 7:25 AM, James Matthews > wrote: > > I am trying to compile Python 2.7 on Ubuntu and I am wondering what are > the > > default compile options (i.e ./configure ..) for ubuntu. I just want the > > standard ones that are included with the python2.6 version on ubuntu. Can > > someone please shed some light? > > You can easily find this out for yourself. > > Ubuntu is a Debian-based system. > > Use dpkg-source to get the source package of python-2.6 and have a > look at how it builds. > > cheers > James > > PS: There's nothing wrong with a plain old ./configure (no options). > > -- > -- James Mills > -- > -- "Problems are solved by method" > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Tue Sep 14 20:25:05 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 15 Sep 2010 10:25:05 +1000 Subject: Default python compile options In-Reply-To: References: Message-ID: On Wed, Sep 15, 2010 at 10:20 AM, James Matthews wrote: > Thanks James, > I did try the plain old configure but I was missing compression zlib and I > wanted to make sure that I wasn't going to be be running in circles having > to run ./configure a bunch of times so I decided to ask) You might need to installed some other packages from Ubuntu/Debian eg: zlib-dev Building python requires certain "development libraries" that Ubuntu/Debian systems do not install by default (they are separate packages). cheers James -- -- James Mills -- -- "Problems are solved by method" From bearophileHUGS at lycos.com Tue Sep 14 20:26:25 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Tue, 14 Sep 2010 17:26:25 -0700 (PDT) Subject: palindrome iteration References: <49c856c4-e6f4-4e4e-b1b4-694a50e56080@f6g2000yqa.googlegroups.com> Message-ID: <8affa77e-6d86-4d80-8e7a-55a28d2c3dd6@k11g2000vbf.googlegroups.com> Baba: > def i_palindrome(pal): > while len(pal)>1: > if pal[0] == pal[-1]: > pal=pal[1:-1] > return True > > print i_palindrome('annab') In normal programming a significant percentage of the time is spent debugging. Experience shows that even short functions may be buggy. If you don't want to waste too much time debugging your code you need to adopt a bit more rigorous approach to write programs. Learning to play piano requires a lot of self-discipline, programming too needs some. Ask yourself what are the exact purposes of your function/class/ program. And then define what are the correct outputs for all input corner cases you are able to find. This is TDD, Thought-driven development. For this program, what's the right output for mixed case strings, for empty strings, for input strings that contain many words with mixed white space and punctuation between them, for unicode strings that contain weird characters? Generally even simple functions may become very complex if you want to manage even complex input cases. You are free to ignore some of those inputs, to keep your code simple enough, but it's usually better for your function to not just ignore some inputs, but give some kind of error for the inputs you don't want to consider. Let's say you accept simple Unicode strings, you don't want to ignore white space, an empty string is palindrome, text cases need to be ignored. I don't like Test-Driven development a lot because your most powerful tool is your brain&mind and not your unit-tests, but I like tests a lot. So you need tests for this small function too. Here doctests are enough. Your first test is better to fail, to be sure your doctest is working: def is_palindrome(text): """ >>> is_palindrome("xy") False """ return True if __name__ == "__main__": import doctest doctest.testmod() print "Doctests done." Code formatting and function and argument names are important to keep code readable to yourself, improve its future maintenance, and reduce the total bug count. You may write this Python function in a high level style like this: def is_palidrome(text): ltext = text.lower() return ltext == ltext[::-1] But that doesn't teach you much programming, so for learning purposes you may try to create one function in lower-level style (that also doesn't stress the garbage collector, despite probably being overall slower in Python). So we use iterative loops and single char tests. But if you use a language as Scheme then a recursive solution too is a normal option. Now you need to invent the algorithm that solves your problem. Inventing algorithms that solve your problems is an art that requires training, experience and even ideas from this little book: http://en.wikipedia.org/wiki/How_to_Solve_It There are few ways to solve that problem, one possible way it to look at the first and last char of the string (ignoring their case), if they are different the given word is not palindrome, otherwise you look at the second and penultimate char, and you perform similar comparisons for all the char pairs. If your string length is odd there is no need to test the last char, but if you want to test it with itself because it keeps the code simpler it's not a problem. To avoid bugs like ones in your code you may think about the loop invariant and loop variant. This blog post shows an example to follow: http://reprog.wordpress.com/2010/04/25/writing-correct-code-part-1-invariants-binary-search-part-4a/ I use two indexes, i and j, that move forward and backwards in sync starting from the first and last char of the 'text' string. The program stops when they are on the same char or they cross. I have used an elaborate loop invariant, for this simple program it's overkill, but shows how you may do it. i ==> <== j +--+--+--+--+--+--+--+--+--+ text | | | | | | | | | | +--+--+--+--+--+--+--+--+--+ 0 1 2 3 4 5 6 7 8 def _is_palindrome_loop_invariant(i, j, length): assert i >= 0 assert i < length assert j >= 0 assert j < length assert i <= j assert i == length - 1 - j return True def is_palindrome(text): """ >>> is_palindrome("") True >>> is_palindrome("1") True >>> is_palindrome(u"x") True >>> is_palindrome("aa") True >>> is_palindrome("ab") False >>> is_palindrome("abc") False >>> [is_palindrome(s) for s in ["abA", "ABA", "ABA"]] [True, True, True] >>> is_palindrome("aibohphobia") True >>> is_palindrome("aibohphobia" * 1000) True >>> is_palindrome(list("aibohphobia")) True >>> is_palindrome([1, 2, 3]) Traceback (most recent call last): ... AttributeError: 'int' object has no attribute 'lower' """ n = len(text) i = 0 j = n - 1 while i < j: assert _is_palindrome_loop_invariant(i, j, n) if text[i].lower() != text[j].lower(): return False else: i += 1 j -= 1 return True if __name__ == "__main__": import doctest doctest.testmod() print "Doctests done." is_palindrome([1, 2, 3]) fails not because the input is a list, but because integers lack the lower() method. It's useful to add few failing doctests too, to show what are the limits of the duck typing of the function. As you see I have tried some corner cases, empty string, single char, two chars, three chars, and more. I have also added a 'stress test' with a larger input. In Python this code is not efficient because of the interpreter overhead and because I call a lower() method on each char (string of length 1), so this is not good Python code. But it's easy to translate to a lower level language, and I think Psyco does a good enough work on it. In C language (plus stdbool) the tolower() is more efficient, but strlen() wastes some time. Often it's better to keep around the length too of your strings, for example using a "fat pointer", as in D. // C code //#define NDEBUG #include "assert.h" #include "stdio.h" #include "string.h" #include "stdbool.h" #include "ctype.h" #include "stdlib.h" bool is_palindrome_loop_invariant(int i, int j, int length) { assert(i >= 0); assert(i < length); assert(j >= 0); assert(j < length); assert(i <= j); assert(i == length - 1 - j); return true; } bool is_palindrome(const char *text) { const int n = strlen(text); int i = 0; int j = n - 1; while (i < j) { assert(is_palindrome_loop_invariant(i, j, n)); if (tolower(text[i]) != tolower(text[j])) { return false; } else { i++; j--; } } return true; } void is_palindrome_test() { assert(is_palindrome("")); assert(is_palindrome("1")); assert(is_palindrome("aa")); assert(!is_palindrome("ab")); assert(!is_palindrome("abc")); assert(is_palindrome("aba")); assert(is_palindrome("abA")); assert(is_palindrome("AbA")); assert(is_palindrome("ABA")); assert(is_palindrome("aibohphobia")); assert(!is_palindrome("aaaaabaaaa")); const int n = 1000; const char *s = "aibohphobia"; const int len_s = strlen(s); char *text = malloc(n * len_s + 1); if (text == NULL) exit(EXIT_FAILURE); int i; char *p = text; for (i = 0; i < n; i++) { memcpy(p, s, len_s); p += len_s; } text[n * len_s] = '\0'; // puts(text); assert(is_palindrome(text)); } int main() { is_palindrome_test(); return EXIT_SUCCESS; } C experts (or good C lints) are probably able to find some loss of precision or loss of sign errors in the following lines: const int n = strlen(text); const int len_s = strlen(s); char *text = malloc(n * len_s + 1); memcpy(p, s, len_s); Writing perfect C code isn't an easy art. (I have used signed values because writing correct C code with unsigned values is a pain, despite avoids loss of precision or sign). Compiling the C code with GCC 4.5.1, and disabled assertions (NDEBUG defined): -O3 -Wall -fomit-frame-pointer -S The loop of is_palindrome() gets compiled to (x86, 32 bit): L10: addl $1, %esi subl $1, %ebx cmpl %ebx, %esi jge L9 L4: movsbl (%edi,%esi), %eax movl %eax, (%esp) call _tolower movl %eax, %ebp movsbl (%edi,%ebx), %eax movl %eax, (%esp) call _tolower cmpl %eax, %ebp je L10 Those two calls to _tolower inside the loop don't help performance, but if you know your strings contain only upper case and lower case chars, and you are able to assume few other things on your machine, it's easy to replace them with non-portable inlined code. The addl and subl are the i++ and j--, GCC has moved them at top as commonly done optimization. The first cmpl is the (i < j) test, and the jge is a jump that ends the loop when it's the right time to do so. The movsbl go read one char, and put them in eax. The movl are necessary to set arguments for the call to the tolower function. The last cmpl compares the results of the tolower, and je (jump equal) jumps to the start of the loop if they are equal. Bye, bearophile From paul.hermeneutic at gmail.com Tue Sep 14 22:50:04 2010 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Tue, 14 Sep 2010 20:50:04 -0600 Subject: distutils, cygwin, 'not a regular file' Message-ID: <8faqj0FnoeU1@mid.individual.net> So, what is not a regular file about this? Is there any way to find out which files are being considered irregular? $ uname -a CYGWIN_NT-6.0-WOW64 pwatson 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin $ cat setup.py from distutils.core import setup setup( name='xlsexport', version='0.3', py_modules=['xlsexport'] ) 20:47 pwatson [ pwatson:/cygdrive/c/Users/pwatson/bin/xlsexport] 12 $ python setup.py sdist running sdist warning: sdist: missing required meta-data: url warning: sdist: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied reading manifest file 'MANIFEST' creating xlsexport-0.3 making hard links in xlsexport-0.3... ' not a regular file -- skipping ' not a regular file -- skipping ' not a regular file -- skipping tar -cf dist/xlsexport-0.3.tar xlsexport-0.3 gzip -f9 dist/xlsexport-0.3.tar removing 'xlsexport-0.3' (and everything under it) From justlooks at gmail.com Tue Sep 14 23:03:40 2010 From: justlooks at gmail.com (ch huang) Date: Wed, 15 Sep 2010 11:03:40 +0800 Subject: can not import hashlib Message-ID: i have a big problem,here is and any can help me? Python 2.6.5 (r265:79063, Apr 1 2010, 05:22:20) [GCC 4.4.3 20100316 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/hashlib.py", line 136, in md5 = __get_builtin_constructor('md5') File "/usr/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor import _md5 ImportError: No module named _md5 -------------- next part -------------- An HTML attachment was scrubbed... URL: From eliben at gmail.com Wed Sep 15 01:31:31 2010 From: eliben at gmail.com (Eli Bendersky) Date: Wed, 15 Sep 2010 07:31:31 +0200 Subject: Bit fields in python? In-Reply-To: <993B42015FA04D5D973F1870E384AAB5@cs0403293> References: <993B42015FA04D5D973F1870E384AAB5@cs0403293> Message-ID: > Hi, > > I'm trying to use the construct library, but encountered a problem. May I > know how do I implement the following using the construct library? > > typedef struct > { > unsigned short size; > . > . > }CodecInfo; > > typedef struct > { > unsigned short size; > CodecInfo mastercodec; > CodecInfo slavecodec; > }StatusInfo; > > StatusInfo t; > printf("%hu %hu\n", t.mastercodec.size,t.slavecodec.size); > > Not sure how to include 2 copies of the CodecInfo Struct into StatusInfo > Struct & be able to access CodecInfo's fields like the example above: > > CodecInfo = Struct("CodecInfo", > . > . > . > ) > > StatusInfo = Struct("StatusInfo", > CodecInfo, > CodecInfo > ) > > Status = StatusInfo.parse(buf) > > You can just nest Struct objects. Here's one implementation of what you're looking for: from construct import * def make_codec_info(name): return Struct(name, ULInt16('size')) StatusInfo = Struct('StatusInfo', ULInt16('size'), make_codec_info('mastercodec'), make_codec_info('slavecodec'), ) c = StatusInfo.parse('\x12\x13\x01\x02\x03\x04') print c P.S. It is covered in the first part of construct's tutorial ( http://construct.wikispaces.com/tut-basics). The tutorial is a pretty good starting point for using construct. Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From zhxia at njnet.edu.cn Wed Sep 15 01:36:40 2010 From: zhxia at njnet.edu.cn (Xia, Zhen) Date: Wed, 15 Sep 2010 13:36:40 +0800 Subject: can not import hashlib In-Reply-To: References: Message-ID: <20100915133640.759c0be0.zhxia@njnet.edu.cn> Your python is compiled without md5. Maybe your system misses some libraries and you have to re-compile the python. On Wed, 15 Sep 2010 11:03:40 +0800 ch huang wrote: > i have a big problem,here is > and any can help me? > > Python 2.6.5 (r265:79063, Apr 1 2010, 05:22:20) > [GCC 4.4.3 20100316 (prerelease)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import hashlib > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/hashlib.py", line 136, in > md5 = __get_builtin_constructor('md5') > File "/usr/lib/python2.6/hashlib.py", line 63, in > __get_builtin_constructor > import _md5 > ImportError: No module named _md5 > From vontio at gmail.com Wed Sep 15 02:13:42 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 14:13:42 +0800 Subject: python call a procedure at the specified time Message-ID: Hi, I have a python script running behind the scene,and I need it to call a method on sunday 9 o'clock. I get an idea,that I get the current time,and calculate the seconds to sunday 9 o'clock, then sleep these seconds and call my method,I think there could be an elegant way to resolve this. Regards, -------------- next part -------------- An HTML attachment was scrubbed... URL: From nitinpawar432 at gmail.com Wed Sep 15 02:15:15 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Wed, 15 Sep 2010 11:45:15 +0530 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: are you looking for something like cron? On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: > Hi, > I have a python script running behind the scene,and I need it to call a > method on sunday 9 o'clock. > I get an idea,that I get the current time,and calculate the seconds to > sunday 9 o'clock, > then sleep these seconds and call my method,I think there could be an > elegant way to resolve this. > > Regards, > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From vontio at gmail.com Wed Sep 15 02:24:39 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 14:24:39 +0800 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: Hi Nitin,I need a python solution for that. On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: > are you looking for something like cron? > > On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: > >> Hi, >> I have a python script running behind the scene,and I need it to call a >> method on sunday 9 o'clock. >> I get an idea,that I get the current time,and calculate the seconds to >> sunday 9 o'clock, >> then sleep these seconds and call my method,I think there could be an >> elegant way to resolve this. >> >> Regards, >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Nitin Pawar > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nitinpawar432 at gmail.com Wed Sep 15 02:35:29 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Wed, 15 Sep 2010 12:05:29 +0530 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: I think to do so either you will need to schedule a cron or write a daemon process which will run continuously. Assuming that its running only once a day or say timely manner daemon will be a costly affair for system resources To schedule crons for python, this might be useful (using yaml) http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml Thanks, Nitin On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: > Hi Nitin,I need a python solution for that. > > > On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: > >> are you looking for something like cron? >> >> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >> >>> Hi, >>> I have a python script running behind the scene,and I need it to call a >>> method on sunday 9 o'clock. >>> I get an idea,that I get the current time,and calculate the seconds to >>> sunday 9 o'clock, >>> then sleep these seconds and call my method,I think there could be an >>> elegant way to resolve this. >>> >>> Regards, >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> >> -- >> Nitin Pawar >> >> > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Sep 15 02:38:40 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Sep 2010 08:38:40 +0200 Subject: String formatting with the format string syntax References: Message-ID: Andre Alexander Bell wrote: > On 09/14/2010 08:20 PM, Miki wrote: >> You can use ** syntax: >>>>> english = {'hello':'hello'} >>>>> s.format(**english) > > Thanks for your answer. Actually your answer tells me that my example > was misleading. Consider the template > > s = 'A template with {variable1} and {variable2} placeholders.' > > I'm seeking a way to extract the named placesholders, i.e. the names > 'variable1' and 'variable2' from the template. I'm not trying to put in > values for them. > > I hope this is clearer. >>> s = 'A template with {variable1} and {variable2} placeholders.' >>> [name for _, name, _, _ in s._formatter_parser() if name is not None] ['variable1', 'variable2'] Peter From kristian.nissen at gmail.com Wed Sep 15 03:22:16 2010 From: kristian.nissen at gmail.com (kristiannissen) Date: Wed, 15 Sep 2010 00:22:16 -0700 (PDT) Subject: google app engine _method? put(self): Message-ID: <006e5cdb-5654-4073-b728-2be9d0cf7be3@u13g2000vbo.googlegroups.com> How can I get the request passed on to my views when using this middleware? class RestHTTPMiddleware(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): request = Request(environ) body = StringIO.StringIO(request.body) method = webapp.Request(environ).get('_method', None) if method: environ['REQUEST_METHOD'] = method.upper() environ['wsgi.input'] = body return self.app(environ, start_response) when i test : class Spot(webapp.RequestHandler): def put(self): logging.info("hello from put %s", self.request.get("author")) the following is logged: "spot put" but with no value. This is how it's implemented: def main(): app = webapp.WSGIApplication([ (r'/spot/new/$', Spot), ], debug=True) # run_wsgi_app(application) wsgiref.handlers.CGIHandler().run(RestHTTPMiddleware(app)) and this is the form:
From vontio at gmail.com Wed Sep 15 03:25:32 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 15:25:32 +0800 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: Thanks Nitin,I wonder how cron works,does it create a timer thread for each task? On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: > I think to do so either you will need to schedule a cron or write a daemon > process which will run continuously. > Assuming that its running only once a day or say timely manner daemon will > be a costly affair for system resources > > To schedule crons for python, this might be useful (using yaml) > > http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml > > Thanks, > Nitin > > > On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: > >> Hi Nitin,I need a python solution for that. >> >> >> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >> >>> are you looking for something like cron? >>> >>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>> >>>> Hi, >>>> I have a python script running behind the scene,and I need it to call a >>>> method on sunday 9 o'clock. >>>> I get an idea,that I get the current time,and calculate the seconds to >>>> sunday 9 o'clock, >>>> then sleep these seconds and call my method,I think there could be an >>>> elegant way to resolve this. >>>> >>>> Regards, >>>> >>>> -- >>>> http://mail.python.org/mailman/listinfo/python-list >>>> >>>> >>> >>> >>> -- >>> Nitin Pawar >>> >>> >> > > > -- > Nitin Pawar > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vontio at gmail.com Wed Sep 15 03:35:26 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 15:35:26 +0800 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: I have read the cron man page just now,It says that cron wakes up every minute to check task. I will try install/uninstall with cron. Cheers, On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: > Thanks Nitin,I wonder how cron works,does it create a timer thread for each > task? > > > On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: > >> I think to do so either you will need to schedule a cron or write a daemon >> process which will run continuously. >> Assuming that its running only once a day or say timely manner daemon will >> be a costly affair for system resources >> >> To schedule crons for python, this might be useful (using yaml) >> >> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >> >> Thanks, >> Nitin >> >> >> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >> >>> Hi Nitin,I need a python solution for that. >>> >>> >>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >>> >>>> are you looking for something like cron? >>>> >>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>> >>>>> Hi, >>>>> I have a python script running behind the scene,and I need it to call a >>>>> method on sunday 9 o'clock. >>>>> I get an idea,that I get the current time,and calculate the seconds to >>>>> sunday 9 o'clock, >>>>> then sleep these seconds and call my method,I think there could be an >>>>> elegant way to resolve this. >>>>> >>>>> Regards, >>>>> >>>>> -- >>>>> http://mail.python.org/mailman/listinfo/python-list >>>>> >>>>> >>>> >>>> >>>> -- >>>> Nitin Pawar >>>> >>>> >>> >> >> >> -- >> Nitin Pawar >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nitinpawar432 at gmail.com Wed Sep 15 03:44:08 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Wed, 15 Sep 2010 13:14:08 +0530 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: cron is daemon running which maps the tasks with the frequency if you want to run a task at a specific time, you can schedule it for the same if you need any help, ping on gtalk, can help you out Thanks, Nitin On Wed, Sep 15, 2010 at 1:05 PM, Von wrote: > I have read the cron man page just now,It says that cron wakes up every > minute to check task. > I will try install/uninstall with cron. > > Cheers, > > > On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: > >> Thanks Nitin,I wonder how cron works,does it create a timer thread for >> each task? >> >> >> On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: >> >>> I think to do so either you will need to schedule a cron or write a >>> daemon process which will run continuously. >>> Assuming that its running only once a day or say timely manner daemon >>> will be a costly affair for system resources >>> >>> To schedule crons for python, this might be useful (using yaml) >>> >>> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >>> >>> Thanks, >>> Nitin >>> >>> >>> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >>> >>>> Hi Nitin,I need a python solution for that. >>>> >>>> >>>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >>>> >>>>> are you looking for something like cron? >>>>> >>>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>>> >>>>>> Hi, >>>>>> I have a python script running behind the scene,and I need it to call >>>>>> a method on sunday 9 o'clock. >>>>>> I get an idea,that I get the current time,and calculate the seconds to >>>>>> sunday 9 o'clock, >>>>>> then sleep these seconds and call my method,I think there could be an >>>>>> elegant way to resolve this. >>>>>> >>>>>> Regards, >>>>>> >>>>>> -- >>>>>> http://mail.python.org/mailman/listinfo/python-list >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Nitin Pawar >>>>> >>>>> >>>> >>> >>> >>> -- >>> Nitin Pawar >>> >>> >> > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Sep 15 04:00:45 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Sep 2010 10:00:45 +0200 Subject: String formatting with the format string syntax References: Message-ID: Peter Otten wrote: > Andre Alexander Bell wrote: > >> On 09/14/2010 08:20 PM, Miki wrote: >>> You can use ** syntax: >>>>>> english = {'hello':'hello'} >>>>>> s.format(**english) >> >> Thanks for your answer. Actually your answer tells me that my example >> was misleading. Consider the template >> >> s = 'A template with {variable1} and {variable2} placeholders.' >> >> I'm seeking a way to extract the named placesholders, i.e. the names >> 'variable1' and 'variable2' from the template. I'm not trying to put in >> values for them. >> >> I hope this is clearer. > >>>> s = 'A template with {variable1} and {variable2} placeholders.' >>>> [name for _, name, _, _ in s._formatter_parser() if name is not None] > ['variable1', 'variable2'] Caveat: the format spec may contain names, too. Here's an attempt to take that into account: def extract_names(t, recurse=1): for _, name, fmt, _ in t._formatter_parser(): if name is not None: yield name if recurse and fmt is not None: for name in extract_names(fmt, recurse-1): yield name t = "before {one:{two}{three}} after" print(t) for name in extract_names(t): print(name) >>> list(extract_names("{one:{two}{three}}")) ['one', 'two', 'three'] Don't expect correct results for illegal formats: >>> list(extract_names("{one:{two:{three}}}")) ['one', 'two'] >>> "{one:{two:{three}}}".format(one=1, two=2, three=3) Traceback (most recent call last): File "", line 1, in ValueError: Max string recursion exceeded Duplicate names may occur: >>> list(extract_names("{one} {one} {one}")) ['one', 'one', 'one'] Positional arguments are treated like names: >>> list(extract_names("{0} {1} {0}")) ['0', '1', '0'] >>> list(extract_names("{} {} {}")) ['', '', ''] Peter From post at andre-bell.de Wed Sep 15 04:13:54 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Wed, 15 Sep 2010 10:13:54 +0200 Subject: String formatting with the format string syntax In-Reply-To: References: Message-ID: <4C908042.8020708@andre-bell.de> On 09/15/2010 10:00 AM, Peter Otten wrote: > def extract_names(t, recurse=1): > for _, name, fmt, _ in t._formatter_parser(): > if name is not None: > yield name > if recurse and fmt is not None: > for name in extract_names(fmt, recurse-1): > yield name Thanks Peter, I very much like this generator solution. It will work for all situations I can currently think of. However, one thing remains. It is based on the _format_parser method. And as I wrote in my original post this one - since it starts with _ - suggests to me to better not be used. So if using this method is completely ok, why does it start with _, why is it almost undocumented? Or did I miss something, some docs somewhere? Best regards Andre From __peter__ at web.de Wed Sep 15 04:48:35 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Sep 2010 10:48:35 +0200 Subject: String formatting with the format string syntax References: Message-ID: Andre Alexander Bell wrote: > On 09/15/2010 10:00 AM, Peter Otten wrote: >> def extract_names(t, recurse=1): >> for _, name, fmt, _ in t._formatter_parser(): >> if name is not None: >> yield name >> if recurse and fmt is not None: >> for name in extract_names(fmt, recurse-1): >> yield name > > Thanks Peter, I very much like this generator solution. It will work for > all situations I can currently think of. > > However, one thing remains. It is based on the _format_parser method. > And as I wrote in my original post this one - since it starts with _ - > suggests to me to better not be used. So if using this method is > completely ok, why does it start with _, why is it almost undocumented? > Or did I miss something, some docs somewhere? Sorry, I really should have read your original post carefully/completely. It would have spared me from finding _formatter_parser() independently... I personally would not be too concerned about the leading underscore, but you can use string.Formatter().parse(template) instead. Peter From mummerx at gmail.com Wed Sep 15 04:51:30 2010 From: mummerx at gmail.com (Douglas) Date: Wed, 15 Sep 2010 01:51:30 -0700 (PDT) Subject: Accessing windoze file attributes Message-ID: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Environment: X86, 1Gb RAM, Win XP, latest SP, Excel 2003. Hi, can anyone direct a relative newbie to the best source of info? I am writing my own backup app in Python 2.5.2 (all my company will allow me to use) using IDLE. I intend to run this app daily via the Task Scheduler to back up a mission-critical spreadsheet that only I use. It works well enough, but now I want to make it sensitive to the "A" attribute (only backup the file if it is set), and update it afterwards (unset it). This will help me avoid wasted disk due to needless backups. I have searched the inter-web and not found any info on how to do access/alter Windows file attributes. Please can someone direct me to a web page with suitable info (preferably with code snyppyts)? Many thanks, in advance. -- Douglas From dmitrey.kroshko at scipy.org Wed Sep 15 05:11:39 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Wed, 15 Sep 2010 02:11:39 -0700 (PDT) Subject: ANN: OpenOpt 0.31, FuncDesigner 0.21, DerApproximator 0.21 Message-ID: Hi all, I'm glad to inform you about new releases of our completely free (BSD license) cross-platform software, written using Python language and NumPy: OpenOpt 0.31 (numerical optimization), FuncDesigner 0.21 (automatic differentiation, modelling, interpolation, integration), DerApproximator 0.21 (finite-differences derivatives approximation). For release details see http://forum.openopt.org/viewtopic.php?id=299 or visit our homepage http://openopt.org Regards, Dmitrey From email at spam.la Wed Sep 15 05:40:58 2010 From: email at spam.la (http://thisisvegas.com/get/a/179639) Date: Wed, 15 Sep 2010 02:40:58 -0700 Subject: This is Vegas - Get $2400 Free Message-ID: This is Vegas - Get $2400 Free http://thisisvegas.com/get/a/179639 Click here to download over 400 Free Games http://thisisvegas.com/get/wd/206052 From vontio at gmail.com Wed Sep 15 06:22:23 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 18:22:23 +0800 Subject: python cxfreeze package pyqt app lost icon and tray icon Message-ID: Hi, Here is my command: cxfreeze --target-dir=AutoOrder gui.py --base-name=D:\Python31\Lib\site-packages\cx_Freeze\bases\Win32GUI.exe --include-path=. -z icon.jpg Both app icon and tray icon used icon.jpg Regards, -------------- next part -------------- An HTML attachment was scrubbed... URL: From post at andre-bell.de Wed Sep 15 06:35:23 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Wed, 15 Sep 2010 12:35:23 +0200 Subject: String formatting with the format string syntax In-Reply-To: References: Message-ID: <4C90A16B.8040804@andre-bell.de> On 09/15/2010 10:48 AM, Peter Otten wrote: > I personally would not be too concerned about the leading underscore, but > you can use > > string.Formatter().parse(template) > > instead. Thanks for this pointer. I like it this way. So if I now combine your generator with your suggestion, I end up with something like this: def extract_names(t, recurse=1): import string for _, name, fmt, _ in string.Formatter().parse(t): if name is not None: yield name if recurse and fmt is not None: for name in extract_names(fmt, recurse-1): yield name Pretty cool. Thanks a lot. Andre From k.sahithi2862 at gmail.com Wed Sep 15 06:37:51 2010 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 15 Sep 2010 03:37:51 -0700 (PDT) Subject: XXX HOT PHOTOS&VIDEOS Message-ID: <390e4289-ab6f-4851-ac72-aa46482099dc@b4g2000pra.googlegroups.com> FOR HOT SEXY PHOTOS&VIDEOS [EXPOSING PHOTO] http://hotheroinesphotos.blogspot.com/2010/09/exposing-photo.html FOR HOT VIDEOS WITH SEXY PHOTO http://hotheroinesphotos.blogspot.com/2010/09/kangana-in-sexy-feel.html HOT MALLU AUNTY http://hotheroinesphotos.blogspot.com/2010/09/mallu-aunty.html LASYA HOT SEXY PHOTO http://hotheroinesphotos.blogspot.com/2010/09/sexy-lasya.html CHARMI HOT BOOBS SHOW http://hotheroinesphotos.blogspot.com/2010/09/charmi-boobs-show.html HOT MALLU AUNTY http://hotheroinesphotos.blogspot.com/2010/09/mallu-special.html SNEHA IN A BIKINI http://hotheroinesphotos.blogspot.com/2010/09/sneha-in-bikini.html From lallous at lgwm.org Wed Sep 15 06:38:39 2010 From: lallous at lgwm.org (lallous) Date: Wed, 15 Sep 2010 03:38:39 -0700 (PDT) Subject: help with calling a static method in a private class References: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> <87r5gwgzk5.fsf@web.de> Message-ID: <293456d9-ecbe-4300-b938-725b11e299c2@q9g2000vbd.googlegroups.com> On Sep 14, 4:38?pm, de... at web.de (Diez B. Roggisch) wrote: > lallous writes: > > How can I keep the class private and have the following work: > > > [code] > > class __internal_class(object): > > ? ? @staticmethod > > ? ? def meth1(s): > > ? ? ? ? print "meth1:", s > > > ? ? @staticmethod > > ? ? def meth2(s): > > ? ? ? ? print "meth2:", > > ? ? ? ? __internal_class.meth1(s) > > > x = __internal_class() > > > x.meth2('sdf') > > [/code] > > By not using a double underscore. It is effectless on classes anyway > (they are not hidden because of that). > > And additionally, but simply not using staticmethods at all. It's a > rather obscure feature ofpython- usually, classmethods are what is > considered a static method in other languages. And with that, even your > double underscores work: > > class __internal_class(object): > ? ? @classmethod > ? ? def meth1(cls, s): > ? ? ? ? print "meth1:", s > > ? ? @classmethod > ? ? def meth2(cls, s): > ? ? ? ? print "meth2:", > ? ? ? ? cls.meth1(s) > > x = __internal_class() > > x.meth2('sdf') > > Diez Thanks, that does the trick. From vontio at gmail.com Wed Sep 15 06:53:57 2010 From: vontio at gmail.com (Von) Date: Wed, 15 Sep 2010 18:53:57 +0800 Subject: python call a procedure at the specified time In-Reply-To: References: Message-ID: I used timer way,and I found that threading.Timer didn't work with PyQt,so I used QTimer instead,and it did work. On Wed, Sep 15, 2010 at 3:44 PM, Nitin Pawar wrote: > cron is daemon running which maps the tasks with the frequency > > if you want to run a task at a specific time, you can schedule it for the > same > > if you need any help, ping on gtalk, can help you out > > Thanks, > Nitin > > On Wed, Sep 15, 2010 at 1:05 PM, Von wrote: > >> I have read the cron man page just now,It says that cron wakes up every >> minute to check task. >> I will try install/uninstall with cron. >> >> Cheers, >> >> >> On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: >> >>> Thanks Nitin,I wonder how cron works,does it create a timer thread for >>> each task? >>> >>> >>> On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: >>> >>>> I think to do so either you will need to schedule a cron or write a >>>> daemon process which will run continuously. >>>> Assuming that its running only once a day or say timely manner daemon >>>> will be a costly affair for system resources >>>> >>>> To schedule crons for python, this might be useful (using yaml) >>>> >>>> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >>>> >>>> Thanks, >>>> Nitin >>>> >>>> >>>> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >>>> >>>>> Hi Nitin,I need a python solution for that. >>>>> >>>>> >>>>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >>>>> >>>>>> are you looking for something like cron? >>>>>> >>>>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>>>> >>>>>>> Hi, >>>>>>> I have a python script running behind the scene,and I need it to call >>>>>>> a method on sunday 9 o'clock. >>>>>>> I get an idea,that I get the current time,and calculate the seconds >>>>>>> to sunday 9 o'clock, >>>>>>> then sleep these seconds and call my method,I think there could be >>>>>>> an elegant way to resolve this. >>>>>>> >>>>>>> Regards, >>>>>>> >>>>>>> -- >>>>>>> http://mail.python.org/mailman/listinfo/python-list >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Nitin Pawar >>>>>> >>>>>> >>>>> >>>> >>>> >>>> -- >>>> Nitin Pawar >>>> >>>> >>> >> > > > -- > Nitin Pawar > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at web.de Wed Sep 15 07:28:32 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 15 Sep 2010 13:28:32 +0200 Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: <87mxrjgs9r.fsf@web.de> Douglas writes: > Hi, can anyone direct a relative newbie to the best source of info? > I am writing my own backup app in Python 2.5.2 (all my company will > allow me to use) using IDLE. > I intend to run this app daily via the Task Scheduler to back up a > mission-critical spreadsheet that only I use. > It works well enough, but now I want to make it sensitive to the "A" > attribute (only backup the file if it is set), and update it > afterwards (unset it). This will help me avoid wasted disk due to > needless backups. > I have searched the inter-web and not found any info on how to do > access/alter Windows file attributes. > Please can someone direct me to a web page with suitable info > (preferably with code snyppyts)? No windows nowhere here, but os.stat should be your friend. Diez From drobinow at gmail.com Wed Sep 15 07:45:08 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 15 Sep 2010 07:45:08 -0400 Subject: Accessing windoze file attributes In-Reply-To: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: On Wed, Sep 15, 2010 at 4:51 AM, Douglas wrote: > Environment: X86, 1Gb RAM, Win XP, latest SP, Excel 2003. > > Hi, can anyone direct a relative newbie to the best source of info? > I am writing my own backup app in Python 2.5.2 (all my company will > allow me to use) using IDLE. > I intend to run this app daily via the Task Scheduler to back up a > mission-critical spreadsheet that only I use. > It works well enough, but now I want to make it sensitive to the "A" > attribute (only backup the file if it is set), and update it > afterwards (unset it). This will help me avoid wasted disk due to > needless backups. > I have searched the inter-web and not found any info on how to do > access/alter Windows file attributes. > Please can someone direct me to a web page with suitable info > (preferably with code snyppyts)? http://code.activestate.com/recipes/303343-changing-file-attributes-on-windows/ From ldo at geek-central.gen.new_zealand Wed Sep 15 08:32:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 16 Sep 2010 00:32:45 +1200 Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: In message <8dc0fa8e-f0e6-4603-9283-186551597e8d at a19g2000vbi.googlegroups.com>, Douglas wrote: > It works well enough, but now I want to make it sensitive to the "A" > attribute (only backup the file if it is set), and update it > afterwards (unset it). This will help me avoid wasted disk due to > needless backups. Why reinvent rsync? From lanyjie at yahoo.com Wed Sep 15 08:34:06 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 15 Sep 2010 05:34:06 -0700 (PDT) Subject: 3>0 is True Message-ID: <602031.32211.qm@web54205.mail.re2.yahoo.com> Hi, I am not sure how to interprete this, in the interactive mode: >>> 3>0 is True False >>> (3>0) is True True >>> 3> (0 is True) True Why did I get the first 'False'? I'm a little confused. Thanks in advance for anybody who shed some light on this. YL From ldo at geek-central.gen.new_zealand Wed Sep 15 08:34:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 16 Sep 2010 00:34:22 +1200 Subject: distutils, cygwin, 'not a regular file' References: <8faqj0FnoeU1@mid.individual.net> Message-ID: In message <8faqj0FnoeU1 at mid.individual.net>, Paul Watson wrote: > ' not a regular file -- skipping > ' not a regular file -- skipping > ' not a regular file -- skipping Just a guess, is the file it?s complaining about named ?'?? From __peter__ at web.de Wed Sep 15 08:46:07 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Sep 2010 14:46:07 +0200 Subject: 3>0 is True References: Message-ID: Yingjie Lan wrote: > I am not sure how to interprete this, in the interactive mode: > >>>> 3>0 is True > False >>>> (3>0) is True > True >>>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. http://docs.python.org/reference/expressions.html#notin """ Unlike C, all comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation. Also unlike C, expressions like a < b < c have the interpretation that is conventional in mathematics: comparison ::= or_expr ( comp_operator or_expr )* comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | "!=" | "is" ["not"] | ["not"] "in" Comparisons yield boolean values: True or False. Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false). """ Peter From jpiitula at ling.helsinki.fi Wed Sep 15 08:47:04 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 15 Sep 2010 15:47:04 +0300 Subject: 3>0 is True References: Message-ID: Yingjie Lan writes: > I am not sure how to interprete this, in the interactive mode: > > >>> 3>0 is True > False > >>> (3>0) is True > True > >>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. It is interpreted as equivalent to this: >>> 3 > 0 and 0 is True False >From the language reference at python.org (section 5.9 Comparisons): expressions like a < b < c have the interpretation that is conventional in mathematics ... Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false). From michael.ricordeau at gmail.com Wed Sep 15 08:47:11 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Wed, 15 Sep 2010 14:47:11 +0200 Subject: 3>0 is True In-Reply-To: <602031.32211.qm@web54205.mail.re2.yahoo.com> References: <602031.32211.qm@web54205.mail.re2.yahoo.com> Message-ID: <20100915144711.601e57da@moriz.interne> Because "is" operator take precedence on ">" operator . Le Wed, 15 Sep 2010 05:34:06 -0700 (PDT), Yingjie Lan a ?crit : > Hi, > > I am not sure how to interprete this, in the interactive mode: > > >>> 3>0 is True > False > >>> (3>0) is True > True > >>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. > > Thanks in advance for anybody who shed some light on this. > > YL > > > From mwilson at the-wire.com Wed Sep 15 08:57:13 2010 From: mwilson at the-wire.com (Mel) Date: Wed, 15 Sep 2010 08:57:13 -0400 Subject: 3>0 is True References: Message-ID: Yingjie Lan wrote: > I am not sure how to interprete this, in the interactive mode: > >>>> 3>0 is True > False >>>> (3>0) is True > True >>>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. > > Thanks in advance for anybody who shed some light on this. This looks like comparison chaining. `is` is a comparison operator, like `>`, and chains of comparisons are handled differently. `a < b < c` is equivalent to `(a < b) and (b < c)` Therefore the first expression is testing (3 > 0) and (0 is True) Mel. From michael.ricordeau at gmail.com Wed Sep 15 09:03:31 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Wed, 15 Sep 2010 15:03:31 +0200 Subject: 3>0 is True In-Reply-To: <20100915144711.601e57da@moriz.interne> References: <602031.32211.qm@web54205.mail.re2.yahoo.com> <20100915144711.601e57da@moriz.interne> Message-ID: <20100915150331.17a5b528@moriz.interne> Not really true for ">" and "is" : http://docs.python.org/reference/expressions.html#evaluation-order Operator ">" and operator "is" are in the same precedence but in group Comparisons : "Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right ? see section Comparisons" The important words here are : "all have the SAME PRECEDENCE and chain from left to right" See also : http://docs.python.org/reference/expressions.html#comparisons So for : >>> 3 > 0 is True #first evaluation is : >>> 3 > 0 ---> True #second evaluation is : >>> 0 is True ---> False (and second evaluation is not result of first one !) Le Wed, 15 Sep 2010 14:47:11 +0200, Michael Ricordeau a ?crit : > Because "is" operator take precedence on ">" operator . > > Le Wed, 15 Sep 2010 05:34:06 -0700 (PDT), > Yingjie Lan a ?crit : > > > Hi, > > > > I am not sure how to interprete this, in the interactive mode: > > > > >>> 3>0 is True > > False > > >>> (3>0) is True > > True > > >>> 3> (0 is True) > > True > > > > Why did I get the first 'False'? I'm a little confused. > > > > Thanks in advance for anybody who shed some light on this. > > > > YL > > > > > > From js at corefiling.co.uk Wed Sep 15 09:04:24 2010 From: js at corefiling.co.uk (Jon Siddle) Date: Wed, 15 Sep 2010 14:04:24 +0100 Subject: 3>0 is True In-Reply-To: <602031.32211.qm@web54205.mail.re2.yahoo.com> References: <602031.32211.qm@web54205.mail.re2.yahoo.com> Message-ID: <4C90C458.2080103@corefiling.co.uk> As others have said, it's not a matter of precendence. Using the compiler module you can see how python actually parses this: 3 > (0 is True) Compare(Const(3), [('>', Compare(Const(0), [('is', Name('True'))]))]) No great surprise there. 3 > 0 is True Compare(Const(3), [('>', Const(0)), ('is', Name('True'))]) As you can see, it's not the same. Two comparisons are being done "at once", not one comparison on the result of another. Hope this helps On 15/09/10 13:34, Yingjie Lan wrote: > Hi, > > I am not sure how to interprete this, in the interactive mode: > >>>> 3>0 is True > False >>>> (3>0) is True > True >>>> 3> (0 is True) > True > > Why did I get the first 'False'? I'm a little confused. > > Thanks in advance for anybody who shed some light on this. > > YL > > > -- Jon Siddle, CoreFiling Limited Software Tools Developer http://www.corefiling.com Phone: +44-1865-203192 From lanyjie at yahoo.com Wed Sep 15 09:33:57 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 15 Sep 2010 06:33:57 -0700 (PDT) Subject: 3>0 is True In-Reply-To: <4C90C458.2080103@corefiling.co.uk> Message-ID: <369612.86166.qm@web54203.mail.re2.yahoo.com> > From: Jon Siddle > Subject: Re: 3>0 is True > To: python-list at python.org > Date: Wednesday, September 15, 2010, 5:04 PM > ? As others have said, it's not > a matter of precendence. Using the > compiler module > you can see how python actually parses this: > > 3 > (0 is True) > Compare(Const(3), [('>', Compare(Const(0), [('is', > Name('True'))]))]) > > No great surprise there. > > 3 > 0 is True > Compare(Const(3), [('>', Const(0)), ('is', > Name('True'))]) > > As you can see, it's not the same. Two comparisons are > being done "at > once", not > one comparison on the result of another. > > Hope this helps Thank you all for nailing down this itching issue for me! All I can say is: Wow! You all have a teribly nice day! Yingjie From chris at simplistix.co.uk Wed Sep 15 09:49:09 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 15 Sep 2010 14:49:09 +0100 Subject: os.path.normcase rationale? Message-ID: <4C90CED5.8050005@simplistix.co.uk> Hi All, I'm curious as to why, with a file called "Foo.txt" os.path.normcase('FoO.txt') will return "foo.txt" rather than "Foo.txt"? Yes, I know the behaviour is documented, but I'm wondering if anyone can remember the rationale for that behaviour? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From pruebauno at latinmail.com Wed Sep 15 09:54:31 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 15 Sep 2010 06:54:31 -0700 (PDT) Subject: business date and calendar libraries? References: <4C8E59FA.3060508@simplistix.co.uk> Message-ID: <26d4ebce-33a6-4715-81ad-fb2a0422a8f8@g18g2000vbn.googlegroups.com> On Sep 13, 3:02?pm, David Robinow wrote: > On Mon, Sep 13, 2010 at 1:06 PM, Chris Withers wrote: > > I'm wondering what libraries people would use to answer the following > > questions relating to business days: > > > - on a less-naive level; same question but taking into account public > > holidays > > ?This depends on which government is oppressing you. > > > - on a horrific level; same question, but taking into account business days > > of a particular market (NYSE, LSE, etc) > > ?This is just an instance of the public holiday case. You need to > define the holidays. > ?If you read lisp you might want to look at the emacs calendar module > for some hints on how they describe holidays, such as, for a US-biased > example, ?Martin Luther King day is the third Monday in January, > Memorial Day is the last Monday in May, Good Friday is not a public > holiday but some markets are closed. A good way to do this IMHO is to keep a list of "holidays" for each year in your program and check if a day is in the list to do your calculations. The list could be automatically generated by an algorithm that figures out all the weird holiday dates or -as is done in many companies- some honcho adds them according to his preference to a database. From cjwilliams43 at gmail.com Wed Sep 15 12:36:16 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Wed, 15 Sep 2010 12:36:16 -0400 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: <8fag9dF4mtU1@mid.individual.net> References: <8fag9dF4mtU1@mid.individual.net> Message-ID: On 14-Sep-10 19:54 PM, Gregory Ewing wrote: > Suppose I have two N+2 dimensional arrays, representing > N-d arrays of 2-d matrices. I want to perform matrix > multiplication between corresponding matrices in these > arrays. > > I had thought that dot() might do this, but it appears > not, because e.g. applying it to two 3-d arrays gives > a 4-d array, not another 3-d array. > > I'd also like to be able to find the inverse of each > matrix in one of these arrays, but again, inv() doesn't > do what I want -- it only works on 2-d arrays. > > Any thoughts on how to achieve these things using numpy > functions? > There is a Matrix sub-class which permit you to do that sort of thimg. Colin W. From andrewt.herd at gmail.com Wed Sep 15 12:53:50 2010 From: andrewt.herd at gmail.com (Andrew) Date: Wed, 15 Sep 2010 09:53:50 -0700 (PDT) Subject: Deleting widgets from PyQt4 QFormWidget Message-ID: I'm trying to remove the widgets from the QFormLayout widget from PyQt4. According to the documentation I should be able to use the command .takeAt(int) which will delete the widget from the layout and then return to me the QLayoutWidget. It currently is giving me back the widget, but is not removing it from the layout. At the moment, I'm simply trying to clear out all the widgets on the layout with this: def clearForm(self): print ("Clearing") print self.dataForm.rowCount() for i in range(self.dataForm.rowCount()-1, -1, -1): print " .", tmp = self.dataForm.takeAt(i) print tmp.widget() tmp = "" print self.dataForm.rowCount() It goes through each widget on the layout, and prints out the classes .__repr__ on the tmp.widget() line since tmp is a QLayoutWidget. So it's doing the returning part, but they still exist instead of being deleted like the documentation explains. Am I missing a step or is this just broken? I haven't been able to find anything else on this issue yet. If it's broke, is there any potential workaround? I'm using python 2.6.4 and PyQt4 4.7.6 Thanks, Andrew From andrewt.herd at gmail.com Wed Sep 15 13:10:11 2010 From: andrewt.herd at gmail.com (Andrew) Date: Wed, 15 Sep 2010 10:10:11 -0700 (PDT) Subject: Deleting widgets from PyQt4 QFormWidget References: Message-ID: <25e05bac-f0b8-40d9-a632-1b471a210c10@h37g2000pro.googlegroups.com> On Sep 15, 9:53?am, Andrew wrote: > I'm trying to remove the widgets from the QFormLayout widget from > PyQt4. According to the documentation I should be able to use the > command .takeAt(int) which will delete the widget from the layout and > then return to me the QLayoutWidget. > It currently is giving me back the widget, but is not removing it from > the layout. > At the moment, I'm simply trying to clear out all the widgets on the > layout with this: > > def clearForm(self): > ? ? ? ? ? ? ? ? print ("Clearing") > ? ? ? ? ? ? ? ? print self.dataForm.rowCount() > ? ? ? ? ? ? ? ? for i in range(self.dataForm.rowCount()-1, -1, -1): > ? ? ? ? ? ? ? ? ? ? ? ? print " .", > ? ? ? ? ? ? ? ? ? ? ? ? tmp = self.dataForm.takeAt(i) > ? ? ? ? ? ? ? ? ? ? ? ? print tmp.widget() > ? ? ? ? ? ? ? ? ? ? ? ? tmp = "" > ? ? ? ? ? ? ? ? print self.dataForm.rowCount() > > It goes through each widget on the layout, and prints out the > classes .__repr__ on the tmp.widget() line since tmp is a > QLayoutWidget. So it's doing the returning part, but they still exist > instead of being deleted like the documentation explains. > > Am I missing a step or is this just broken? I haven't been able to > find anything else on this issue yet. If it's broke, is there any > potential workaround? > > I'm using python 2.6.4 and PyQt4 4.7.6 > > Thanks, > Andrew QLayoutWidget, I meant a QWidgetItem. From anand.shashwat at gmail.com Wed Sep 15 13:25:11 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 15 Sep 2010 13:25:11 -0400 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: <8fag9dF4mtU1@mid.individual.net> References: <8fag9dF4mtU1@mid.individual.net> Message-ID: On Tue, Sep 14, 2010 at 7:54 PM, Gregory Ewing wrote: > Suppose I have two N+2 dimensional arrays, representing > N-d arrays of 2-d matrices. I want to perform matrix > multiplication between corresponding matrices in these > arrays. > > I had thought that dot() might do this, but it appears > not, because e.g. applying it to two 3-d arrays gives > a 4-d array, not another 3-d array. > > I'd also like to be able to find the inverse of each > matrix in one of these arrays, but again, inv() doesn't > do what I want -- it only works on 2-d arrays. > > Any thoughts on how to achieve these things using numpy > functions? > Unrelated to numpy, but you can apply the basics of dynamic programming to optimize the stuff. > -- > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From edg at greenberg.org Wed Sep 15 13:38:16 2010 From: edg at greenberg.org (Ed Greenberg) Date: Wed, 15 Sep 2010 12:38:16 -0500 Subject: Debugger - fails to "continue" with breakpoint set Message-ID: <4C910488.8020203@greenberg.org> I'm pretty new to Python, but I am really enjoying it as an alternative to Perl and PHP. When I run the debugger [import pdb; pdb.set_trace()] and then do next and step, and evaluate variables, etc, when I hit 'c' for continue, we go to the end, just fine. As soon as I set a breakpoint down the line, [b ] the behavior of 'c' changes. Instead of continuing until the breakpoint, or until the end, if the breakpoint is hidden by a conditional, the debugger starts to treat 'c' as a step (or a next, I'm not sure which.) This behavior is repeatable and consistent. I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu 8.04 (Hardy), both using the installed packages. I must be missing something. Assistance will be welcome. Thanks, Ed Greenberg From mummerx at gmail.com Wed Sep 15 13:38:47 2010 From: mummerx at gmail.com (Douglas) Date: Wed, 15 Sep 2010 10:38:47 -0700 (PDT) Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: @Diez and @David Thanks guys. Both excellent leads. Colour me happy. I can now make progress and meet some deadlines. :) @Lawrence > Why reinvent rsync? In what way is rsync relevant to the stated problem? Did you actually READ the question? Note: I use Linux at home (yes, even rsync) and very much prefer it to Windows. However, at work I have no choice but to use the resources the company provides - which is Windows; have you got that straight now? If you have something more helpful and mature to say, relevant to the actual question, then I will gladly hear it, and even apologise. Otherwise, don't bother. I already enough from respondents who were far more adult, knowledgeable and helpful ... and all the more impressive in comparison. Sincerely, -- Douglas From ron.eggler at gmail.com Wed Sep 15 14:32:43 2010 From: ron.eggler at gmail.com (cerr) Date: Wed, 15 Sep 2010 11:32:43 -0700 (PDT) Subject: socket.error: [Errno 98] Address already in use Message-ID: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Hi There, I get a socket error "[Errno 98] Address already in use" when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, addr = s.accept() while conn and loop: ... ... ... conn.close() Shouldn't that clean it all up properly? Thanks for hints & suggestions! Ron From thomas at jollybox.de Wed Sep 15 14:49:04 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 15 Sep 2010 20:49:04 +0200 Subject: socket.error: [Errno 98] Address already in use In-Reply-To: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: <201009152049.04891.thomas@jollybox.de> On Wednesday 15 September 2010, it occurred to cerr to exclaim: > Hi There, > > I get a socket error "[Errno 98] Address already in use" when i try to > open a socket that got closed before with close(). How come close() > doesn't close the socket properly? > My socket code : > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((host, port)) > s.listen(1) > ... > ... > ... > while loop: > conn, addr = s.accept() > while conn and loop: > ... > ... > ... > conn.close() > > Shouldn't that clean it all up properly? `s` is still listening? From hansmu at xs4all.nl Wed Sep 15 14:54:13 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 15 Sep 2010 20:54:13 +0200 Subject: Cross Compiling Python for ARM In-Reply-To: References: Message-ID: <4c911670$0$41115$e4fe514c@news.xs4all.nl> Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: >> # >> ./python >> >> -sh: ./python: not found > > > I'm guessing either there is no file ./python, or /bin/sh is fundamentally > broken. .... or ./python is a symlink to a file that does not exist, or ./python is a script and the shebang line points to an interpreter that does not exist. The most popular way to get the latter problem is to write the script on a Windows box and then upload it to Unix box using FTP in binary mode (or some other transport that doesn't adjust the line endings). Try the command "file ./python". If it reports something like: ./python: a /usr/bin/python\015 script text executable , then the \015 tells you that you need to use dos2unix. It may be the case that /bin/sh is fundamentally broken if it reports "./python: file not found" if the problem is really the shebang line. Unfortunately, some shells are fundamentally broken this way. Hope this helps, -- HansM From thomas at jollybox.de Wed Sep 15 14:54:58 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 15 Sep 2010 20:54:58 +0200 Subject: distutils, cygwin, 'not a regular file' In-Reply-To: <8faqj0FnoeU1@mid.individual.net> References: <8faqj0FnoeU1@mid.individual.net> Message-ID: <201009152054.58285.thomas@jollybox.de> On Wednesday 15 September 2010, it occurred to Paul Watson to exclaim: > So, what is not a regular file about this? Is there any way to find out > which files are being considered irregular? Regular files are the kind of files used to store bytes. Other kinds of files you might find in a file system include: directories symbolic links pipes (FIFOs) sockets (UNIX/LOCAL domain) character devices block devices Also, for help on interpreting the message at hand, see Lawrence d'Oliveiro's response. > > $ uname -a > CYGWIN_NT-6.0-WOW64 pwatson 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin > > $ cat setup.py > > from distutils.core import setup > > setup( > name='xlsexport', > version='0.3', > > py_modules=['xlsexport'] > ) > 20:47 pwatson [ pwatson:/cygdrive/c/Users/pwatson/bin/xlsexport] 12 > $ python setup.py sdist > running sdist > warning: sdist: missing required meta-data: url > warning: sdist: missing meta-data: either (author and author_email) or > (maintainer and maintainer_email) must be supplied > reading manifest file 'MANIFEST' > creating xlsexport-0.3 > making hard links in xlsexport-0.3... > ' not a regular file -- skipping > ' not a regular file -- skipping > ' not a regular file -- skipping > tar -cf dist/xlsexport-0.3.tar xlsexport-0.3 > gzip -f9 dist/xlsexport-0.3.tar > removing 'xlsexport-0.3' (and everything under it) From invalid at invalid.invalid Wed Sep 15 14:58:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 15 Sep 2010 18:58:32 +0000 (UTC) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On 2010-09-15, cerr wrote: > I get a socket error "[Errno 98] Address already in use" when i try to > open a socket that got closed before with close(). How come close() > doesn't close the socket properly? > My socket code : > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((host, port)) > s.listen(1) > ... > ... > ... > while loop: > conn, addr = s.accept() > while conn and loop: > ... > ... > ... > conn.close() At what line does the error occur? To what does the phrase "open a socket" refer? Have you tried the usual solution of setting the SO_REUSEADDR option on the socket before calling bind? http://www.google.com/search?q=socket+%27address+already+in+use%27 -- Grant Edwards grant.b.edwards Yow! I own seven-eighths of at all the artists in downtown gmail.com Burbank! From thomas at jollybox.de Wed Sep 15 15:04:28 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 15 Sep 2010 21:04:28 +0200 Subject: Debugger - fails to "continue" with breakpoint set In-Reply-To: <4C910488.8020203@greenberg.org> References: <4C910488.8020203@greenberg.org> Message-ID: <201009152104.28899.thomas@jollybox.de> On Wednesday 15 September 2010, it occurred to Ed Greenberg to exclaim: > I'm pretty new to Python, but I am really enjoying it as an alternative > to Perl and PHP. > > When I run the debugger [import pdb; pdb.set_trace()] and then do next > and step, and evaluate variables, etc, when I hit 'c' for continue, we > go to the end, just fine. > > As soon as I set a breakpoint down the line, [b ] the > behavior of 'c' changes. Instead of continuing until the breakpoint, or > until the end, if the breakpoint is hidden by a conditional, the > debugger starts to treat 'c' as a step (or a next, I'm not sure which.) > > This behavior is repeatable and consistent. > > I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu > 8.04 (Hardy), both using the installed packages. > > I must be missing something. Assistance will be welcome. I can't reproduce this. Please post a small script and debugger session transcript that illustrate the problem clearly. Maybe, on the way, you'll discover something you'd been missing. Maybe someone here will be able to help you then (maybe someone is now, but not me...). Maybe it's a bug (which it would be, if it behaves as you describe, but as I said, it appears to work for me). From nicoddemus at gmail.com Wed Sep 15 16:10:59 2010 From: nicoddemus at gmail.com (Bruno Oliveira) Date: Wed, 15 Sep 2010 17:10:59 -0300 Subject: Multiprocessing Queue strange behavior Message-ID: Hi list, I recently found a bug in my company's code because of a strange behavior using multiprocessing.Queue. The following code snippet: from multiprocessing import Queue queue = Queue() queue.put('x') print queue.get_nowait() Fails with: ... File "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", line 153, in getNoWait return self.get(False) File "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", line 129, in get raise Empty Queue.Empty Strangely, changing this to: queue = Queue() queue.put('x') time.sleep(0.1) # <<< print queue.get_nowait() Works as expected. Using the original snippet changing the import to threading's Queue also works. It seems like there's a bug in multiprocessing's Queue implementation. Opinions? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Sep 15 16:47:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Sep 2010 21:47:46 +0100 Subject: Multiprocessing Queue strange behavior In-Reply-To: References: Message-ID: <4C9130F2.80000@mrabarnett.plus.com> On 15/09/2010 21:10, Bruno Oliveira wrote: > Hi list, > > I recently found a bug in my company's code because of a strange > behavior using multiprocessing.Queue. The following code snippet: > > from multiprocessing import Queue > > queue = Queue() > queue.put('x') > print queue.get_nowait() > Fails with: > > ... > File > "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", > line 153, in getNoWait > return self.get(False) > File > "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", > line 129, in get > raise Empty > Queue.Empty > > Strangely, changing this to: > > queue = Queue() > queue.put('x') > time.sleep(0.1) # <<< > print queue.get_nowait() > Works as expected. Using the original snippet changing the import to > threading's Queue also works. > > It seems like there's a bug in multiprocessing's Queue implementation. > Opinions? > I don't think it's a bug as such. The purpose of the multiprocessing queue is to transfer data between different processes, which don't have a shared address space (unlike threads, which do). The transfer involves passing the data between the processes via a pipe. This is done in a background thread and takes some time to complete, so the data won't appear immediately. It looks like it doesn't matter that the putter and the getter happen to be in the same process, possibly because no-one expected that someone would use a multiprocessing queue within the same process like that, so it doesn't check for a shortcut. From mariakirsan at hotmail.com Wed Sep 15 16:51:19 2010 From: mariakirsan at hotmail.com (Maria) Date: Wed, 15 Sep 2010 13:51:19 -0700 (PDT) Subject: Please I need help! Message-ID: <5581bb73-66b3-4d8c-a0b4-b04f8d6956c7@a11g2000vbn.googlegroups.com> I urgently need money help!https://siteheart.com/js/chat/chat.html? ent=9228&hash=97b8aa4b4eec4801f941b0aa97cd2587&ipcsid=842e10a5515ee7299638a546b6b2997f Maria From ben+python at benfinney.id.au Wed Sep 15 17:12:16 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 16 Sep 2010 07:12:16 +1000 Subject: os.path.normcase rationale? References: Message-ID: <87lj727lu7.fsf@benfinney.id.au> Chris Withers writes: > I'm curious as to why, with a file called "Foo.txt" > os.path.normcase('FoO.txt') will return "foo.txt" rather than > "Foo.txt"? What kind of answer are you looking for? A direct answer would be: it does that because on case-insensitive filesystems, it doesn't matter what the case is, so there's no need for anything more complex than all lowercase. > Yes, I know the behaviour is documented The docstring is fairly poor, IMO. You might want to submit a bug report to improve it. > but I'm wondering if anyone can remember the rationale for that > behaviour? I can't speak to that. Does the above answer seem sufficient? -- \ ?I think there is a world market for maybe five computers.? | `\ ?Thomas Watson, chairman of IBM, 1943 | _o__) | Ben Finney From robert.kern at gmail.com Wed Sep 15 17:46:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 15 Sep 2010 16:46:22 -0500 Subject: business date and calendar libraries? In-Reply-To: <4C8E59FA.3060508@simplistix.co.uk> References: <4C8E59FA.3060508@simplistix.co.uk> Message-ID: On 9/13/10 12:06 PM, Chris Withers wrote: > Hi All, > > I'm wondering what libraries people would use to answer the following questions > relating to business days: > > - on a naive level; "what's give me the last business day" (ie: skipping weekends) > > - on a less-naive level; same question but taking into account public holidays > > - on a horrific level; same question, but taking into account business days of a > particular market (NYSE, LSE, etc) Quantlib has a fairly good (by which I mean, horrific) collection of these implemented in C++: http://quantlib.svn.sourceforge.net/viewvc/quantlib/trunk/QuantLib/ql/time/calendars/ If you only need a few of these, it can be more straightforward to look at them and recode them rather than trying to build Quantlib and its wrappers. Most of them have some algorithmic component (e.g. weekends, "easy" recurring holidays) and some exceptional cases (e.g. the days NYSE was closed after 2001-09-11). -- 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 Sep 15 17:47:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 15 Sep 2010 16:47:02 -0500 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: References: <8fag9dF4mtU1@mid.individual.net> Message-ID: On 9/15/10 11:36 AM, Colin J. Williams wrote: > On 14-Sep-10 19:54 PM, Gregory Ewing wrote: >> Suppose I have two N+2 dimensional arrays, representing >> N-d arrays of 2-d matrices. I want to perform matrix >> multiplication between corresponding matrices in these >> arrays. >> >> I had thought that dot() might do this, but it appears >> not, because e.g. applying it to two 3-d arrays gives >> a 4-d array, not another 3-d array. >> >> I'd also like to be able to find the inverse of each >> matrix in one of these arrays, but again, inv() doesn't >> do what I want -- it only works on 2-d arrays. >> >> Any thoughts on how to achieve these things using numpy >> functions? > > There is a Matrix sub-class which permit you to do that sort of thimg. No, it doesn'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 edg at greenberg.org Wed Sep 15 18:17:52 2010 From: edg at greenberg.org (Ed Greenberg) Date: Wed, 15 Sep 2010 17:17:52 -0500 Subject: Debugger - fails to "continue" with breakpoint set In-Reply-To: <201009152104.28899.thomas@jollybox.de> References: <4C910488.8020203@greenberg.org> <201009152104.28899.thomas@jollybox.de> Message-ID: <4C914610.5060904@greenberg.org> On 09/15/2010 02:04 PM, Thomas Jollans wrote: > On Wednesday 15 September 2010, it occurred to Ed Greenberg to exclaim: > >> I'm pretty new to Python, but I am really enjoying it as an alternative >> to Perl and PHP. >> >> When I run the debugger [import pdb; pdb.set_trace()] and then do next >> and step, and evaluate variables, etc, when I hit 'c' for continue, we >> go to the end, just fine. >> >> As soon as I set a breakpoint down the line, [b] the >> behavior of 'c' changes. Instead of continuing until the breakpoint, or >> until the end, if the breakpoint is hidden by a conditional, the >> debugger starts to treat 'c' as a step (or a next, I'm not sure which.) >> >> This behavior is repeatable and consistent. >> >> I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu >> 8.04 (Hardy), both using the installed packages. >> >> I must be missing something. Assistance will be welcome. >> > I can't reproduce this. Please post a small script and debugger session > transcript that illustrate the problem clearly. > > Maybe, on the way, you'll discover something you'd been missing. Maybe someone > here will be able to help you then (maybe someone is now, but not me...). > Maybe it's a bug (which it would be, if it behaves as you describe, but as I > said, it appears to work for me). > Here is my debugger session as requested. Note that I set a breakpoint at line 7, but c still stops at lines 4, 5 and 6. I hope somebody can explain this. ------------------------------------------------- root at cloud4:~# python --version Python 2.6.4 root at cloud4:~# python test.py > /root/test.py(3)() -> a=1 (Pdb) l 1 #!/usr/bin/python 2 import pdb;pdb.set_trace() 3 -> a=1 4 b=2 5 c=3 6 d=4 7 print a,b,c,d 8 [EOF] (Pdb) b 7 Breakpoint 1 at /root/test.py:7 (Pdb) c > /root/test.py(4)() -> b=2 (Pdb) c > /root/test.py(5)() -> c=3 (Pdb) c > /root/test.py(6)() -> d=4 (Pdb) c > /root/test.py(7)() -> print a,b,c,d (Pdb) c 1 2 3 4 --Return-- > /root/test.py(7)()->None -> print a,b,c,d (Pdb) c root at cloud4:~# From greg.ewing at canterbury.ac.nz Wed Sep 15 19:14:55 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 16 Sep 2010 11:14:55 +1200 Subject: os.path.normcase rationale? In-Reply-To: <87lj727lu7.fsf@benfinney.id.au> References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <8fd2c1FvvhU1@mid.individual.net> Ben Finney wrote: > it doesn't matter what the case is, so there's no need for > anything more complex than all lowercase. Also doing what was suggested would require looking at what's in the file system, which would be a lot of bother to go to for no good reason, and would fail for paths that don't correspond to an existing file. -- Greg From ethan at stoneleaf.us Wed Sep 15 19:23:20 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Sep 2010 16:23:20 -0700 Subject: it doesn't work ;) [class recursive function] Message-ID: <4C915568.3080007@stoneleaf.us> I need some fresh eyes, or better brains, or both! The expected debugging output is a list of names in alphabetical order from each node (there are about 90 of them); what I am getting is this: --> dbf.tables.Index.from_file('', r'aad13658_last_name_for_state.idx') starting next_item call for root ----- 512 30 ----- more nodes CARNAHAN 1536 ENGLUND 1024 HOLSTEIN 2048 MATTHEWS 2560 ROSENFELD 3072 TERWILLIGER 3584 YAZZOLINO 4096 and then it stops. I should get about nine of these sections, and I'm only getting one. class Index(object): @classmethod def from_file(cls, table, index_file): def get_idx_records(data, length, howmany): print "get_idx_records: keylen - %d; howmany - %d" %\ (length, howmany) ptr = 0 current = 0 while current < howmany: key = data[ptr:ptr+length].replace('\x00','') rec = io.unpackLongInt(data[ptr+length:ptr+length+4],\ bigendian=True) yield key, rec ptr += length + 4 current += 1 def next_item(idx_file, node_loc, keylen): print idx_file, node_loc, keylen, '\n','-----' idx_file.seek(node_loc) data_chunk = idx_file.read(512) attributes = io.unpackShortInt(data_chunk[:2]) howmany = io.unpackShortInt(data_chunk[2:4]) if attributes in (2, 3): print "actual records" for key, rec in get_idx_records(data_chunk[12:512],\ keylen, howmany): yield key, rec else: print "more nodes" for ignore, next_node in \ get_idx_records(data_chunk[12:512],\ keylen, howmany): print ignore, next_node next_item(idx_file, next_node, keylen) idx = object.__new__(cls) #- idx.key = lambda rec: DoNotIndex data = open(index_file, 'rb') header = data.read(512) rootnode = io.unpackLongInt(header[:4]) keylen = io.unpackShortInt(header[12:14]) idx.__doc__ = header[16:236].replace('\x00','') for_expr = header[236:456].replace('\x00','') if for_expr: idx.__doc__ += ' for ' + for_expr.replace('=','==') print "starting next_item call for root" for rec in next_item(data, rootnode, keylen): print rec Any ideas appreciated! ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: aad13658_last_name_for_state.idx Type: application/octet-stream Size: 4608 bytes Desc: not available URL: From gavcomedy at gmail.com Wed Sep 15 19:58:00 2010 From: gavcomedy at gmail.com (gavino) Date: Wed, 15 Sep 2010 16:58:00 -0700 (PDT) Subject: compiling python 3.1.2 with local readline fails to get readline - help! Message-ID: I compiled readline 6.1 myself. # ./configure --prefix=/home/apps/python --disable-shared --with- pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6 --enable-readline --with-readline=/home/apps/readline/lib/ # make -j14 .... .... modules not installed: ........ readline ......... Python starts but no readline. What is the proper configure flag to use a locally compiled readline? I tried with and without --with-readline and with readline/ and readline/lib as shown above. thx for help From python at mrabarnett.plus.com Wed Sep 15 20:01:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Sep 2010 01:01:40 +0100 Subject: it doesn't work ;) [class recursive function] In-Reply-To: <4C915568.3080007@stoneleaf.us> References: <4C915568.3080007@stoneleaf.us> Message-ID: <4C915E64.50308@mrabarnett.plus.com> On 16/09/2010 00:23, Ethan Furman wrote: > I need some fresh eyes, or better brains, or both! > > The expected debugging output is a list of names in alphabetical order > from each node (there are about 90 of them); what I am getting is this: > > --> dbf.tables.Index.from_file('', r'aad13658_last_name_for_state.idx') > > starting next_item call for root > ----- > > 512 30 > ----- > more nodes > CARNAHAN 1536 > ENGLUND 1024 > HOLSTEIN 2048 > MATTHEWS 2560 > ROSENFELD 3072 > TERWILLIGER 3584 > YAZZOLINO 4096 > > and then it stops. I should get about nine of these sections, and I'm > only getting one. > > > [snip code] > > > > Any ideas appreciated! > 'next_item' is a generator, but it's just calling itself and discarding the result. I think it should be yielding the results to its caller. That fix gives me 7 sections in total. From prologic at shortcircuit.net.au Wed Sep 15 20:12:08 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 10:12:08 +1000 Subject: compiling python 3.1.2 with local readline fails to get readline - help! In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 9:58 AM, gavino wrote: > I compiled readline 6.1 myself. > > # ?./configure --prefix=/home/apps/python --disable-shared --with- > pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6 > --enable-readline --with-readline=/home/apps/readline/lib/ > # ?make -j14 > .... > .... > modules not installed: > ........ ? ?readline ? ......... > > Python starts but no readline. > > What is the proper configure flag to use a locally compiled readline? > I tried with and without --with-readline and with readline/ and > readline/lib as shown above. > thx for help AFAIK, there are no "readline" specific options in python 2.x's ./configure options: # pwd /usr/ports/opt/python/Python-2.6.5 # ./configure --help | grep readline -i # I could be wrong... Are you sure you've configured and compile readline correctly and that you've set the appropriate environment variables and paths for C/C++ compilers (eg: GCC) to pick it up ? cheers James -- -- James Mills -- -- "Problems are solved by method" From jason.swails at gmail.com Wed Sep 15 20:13:04 2010 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 15 Sep 2010 20:13:04 -0400 Subject: classes and dictionaries Message-ID: Hello everyone, I'm encountering an issue in one of my Python classes that makes extensive use of dictionaries. I was under the impression that each time an object was instantiated, all of its variables were created in a new section of memory, so that if you change the value of the variable in one instance, it left that variable's value in another instance alone. In the object that I wrote, I have 3 different dictionaries: parm_data, pointers, and formats, all defined in the same place. When I load 2 instances of this object, parm_data and formats each take on different values between the two objects (as they should), but for some reason pointers does not. I've seen this problem with python2.6.4 and 2.6.1 (and I believe earlier versions as well, but I'm not sure). I've attached a tarball with the relevant code and a sample script that shows what I mean. If anyone can tell me why the dictionary from 2 different objects are exactly the same for pointers, but are different for, e.g. parm_data and formats, that would be greatly appreciated. Thanks! Jason -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: prmtop_test.tgz Type: application/x-gzip Size: 10749 bytes Desc: not available URL: From hansyin at gmail.com Wed Sep 15 20:14:14 2010 From: hansyin at gmail.com (Hans) Date: Wed, 15 Sep 2010 17:14:14 -0700 (PDT) Subject: program organization question for web development with python Message-ID: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> Hi, I'm new to this area. Please allow me to ask some (maybe stupid) questions. I'm planning to write a web application which used for searching my mysql database. 1. files organization I have this in my main.py: print """%s""" % (record[0],table_name,cursor_name,record1) it kind of works but not comfortable to me. Do I have to use two files(main.py and display_tb.py)? does that means each hyper-link needs a single file? Can I put those files together and then they can share variables,classes, modules, etc? 2. database cursor as parameter? I created database cursor in my main.py and then I have to use it in another file(display_tb.py), Can I? I put cursor as a parameter and try to send it through hyper-link. but it somehow does not work. error log listed below: /usr/lib/cgi-bin/display_tb.py in () 20 sql_str = "SELECT * FROM %s " % search_str_list 21 print "

%s

" % sql_str 22 cursor_ptr.execute(sql_str) 23 result = cursor_ptr.fetchall() 24 cursor_ptr = '', cursor_ptr.execute undefined, sql_str = 'SELECT * FROM env_test where id=20 ' : 'str' object has no attribute 'execute' args = ("'str' object has no attribute 'execute'",) message = "'str' object has no attribute 'execute'" From share.it.usa at gmail.com Wed Sep 15 20:19:05 2010 From: share.it.usa at gmail.com (Health Coach) Date: Wed, 15 Sep 2010 17:19:05 -0700 (PDT) Subject: work opportunity Message-ID: <3b890b18-657d-45ad-bc9d-a09f4118c4b4@l32g2000prn.googlegroups.com> FREE to Join ! You get up to 35% cashback for every qualified purchase you make on the site. On any personal referrals, you'll also make 1/2% on their qualifying purchases! ********************************************* www.ma360eMall.com Everything you need and want Get paid to shop with Cashback up to 35% Many more hot deals.... ma360emall at gmail.com ********************************************** http://w.mawebcenters.com/ma360emall/ http://motivescosmetics.marketamerica.com/MA360EMALL/ http://isotonix.marketamerica.com/MA360EMALL/USA From prologic at shortcircuit.net.au Wed Sep 15 20:30:46 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 10:30:46 +1000 Subject: classes and dictionaries In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 10:13 AM, Jason Swails wrote: > Hello everyone, > > I'm encountering an issue in one of my Python classes that makes extensive > use of dictionaries.? I was under the impression that each time an object > was instantiated, all of its variables were created in a new section of > memory, so that if you change the value of the variable in one instance, it > left that variable's value in another instance alone.? In the object that I > wrote, I have 3 different dictionaries: parm_data, pointers, and formats, > all defined in the same place.? When I load 2 instances of this object, > parm_data and formats each take on different values between the two objects > (as they should), but for some reason pointers does not.? I've seen this > problem with python2.6.4 and 2.6.1 (and I believe earlier versions as well, > but I'm not sure).? I've attached a tarball with the relevant code and a > sample script that shows what I mean. > > If anyone can tell me why the dictionary from 2 different objects are > exactly the same for pointers, but are different for, e.g. parm_data and > formats, that would be greatly appreciated. In short (without creating a huge thread of unnecessary chatter), if you reference an object in 2 different dictionaries, the values (dictionary values) will be identical. The following example might help you understand this. >>> class Foo(object): ... def __init__(self, data=None): ... self.data = {"params": data} ... >>> a = b = object() >>> id(a), id(b) (3075279112L, 3075279112L) >>> foo = Foo(a) >>> bar = Foo(b) >>> foo.data, bar.data ({'params': }, {'params': }) >>> id(foo.data["params"]), id(bar.data["params"]) (3075279112L, 3075279112L) >>> cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Sep 15 20:33:05 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 10:33:05 +1000 Subject: program organization question for web development with python In-Reply-To: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> Message-ID: On Thu, Sep 16, 2010 at 10:14 AM, Hans wrote: > I'm new to this area. Please allow me to ask some (maybe stupid) > questions. Without reading the rest of your post too much. Designs are up to you, I can't comment. I can only share in a fairly common view, and that is, we'd encourage you to use a web framework as opposed to plain old CGI. cheers james -- -- James Mills -- -- "Problems are solved by method" From python at mrabarnett.plus.com Wed Sep 15 20:36:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Sep 2010 01:36:41 +0100 Subject: classes and dictionaries In-Reply-To: References: Message-ID: <4C916699.2040202@mrabarnett.plus.com> On 16/09/2010 01:13, Jason Swails wrote: > Hello everyone, > > I'm encountering an issue in one of my Python classes that makes > extensive use of dictionaries. I was under the impression that each > time an object was instantiated, all of its variables were created in a > new section of memory, so that if you change the value of the variable > in one instance, it left that variable's value in another instance > alone. In the object that I wrote, I have 3 different dictionaries: > parm_data, pointers, and formats, all defined in the same place. When I > load 2 instances of this object, parm_data and formats each take on > different values between the two objects (as they should), but for some > reason pointers does not. I've seen this problem with python2.6.4 and > 2.6.1 (and I believe earlier versions as well, but I'm not sure). I've > attached a tarball with the relevant code and a sample script that shows > what I mean. > > If anyone can tell me why the dictionary from 2 different objects are > exactly the same for pointers, but are different for, e.g. parm_data and > formats, that would be greatly appreciated. > When you bind to a name in the class namespace: class Example: foo = "class attribute" the name is an attribute of the class. If you want a name to be an attribute of an instance then you should refer to the instance explicitly: class Example: def __init__(self): self.bar = "instance attribute" From jipalaciosortega at gmail.com Wed Sep 15 20:51:04 2010 From: jipalaciosortega at gmail.com (jipalaciosortega at gmail.com) Date: Thu, 16 Sep 2010 02:51:04 +0200 Subject: socket.error: [Errno 98] Address already in use In-Reply-To: References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: <4C9169F8.4020906@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 El 15/09/2010 20:58, Grant Edwards escribi?: > On 2010-09-15, cerr wrote: > >> I get a socket error "[Errno 98] Address already in use" when i >> try to open a socket that got closed before with close(). How >> come close() doesn't close the socket properly? My socket code : >> >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >> s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, >> addr = s.accept() while conn and loop: ... ... ... conn.close() > > At what line does the error occur? > > To what does the phrase "open a socket" refer? > > Have you tried the usual solution of setting the SO_REUSEADDR > option on the socket before calling bind? > > http://www.google.com/search?q=socket+%27address+already+in+use%27 > Maybe, you have any other proccess in your system using your listen port, for example apache... - -- _ _ _ _ _ _ _ _ _ _ _ Jose Ignacio Palacios Ortega /_ _/ / / / _ / / _ / Telf: +34 637 058 813 / / / / / /_ / / / / / / Correo-e: jipalaciosortega at gmail.com _ / / / / / _ _ _/ / / / / Msn: jipalaciosortega at gmail.com / /_ / / / / / / / /_/ / ID firma PGP: 0x0EB87E48 \ _ _ / /_/ /_/ /_ _ _/ Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ 4cgAniOoR70hu7UylkpgAr3JI5hxNXYP =MoYK -----END PGP SIGNATURE----- From gavcomedy at gmail.com Wed Sep 15 21:10:39 2010 From: gavcomedy at gmail.com (gavino) Date: Wed, 15 Sep 2010 18:10:39 -0700 (PDT) Subject: compiling python 3.1.2 with local readline fails to get readline - help! References: Message-ID: On Sep 15, 5:12?pm, James Mills wrote: > On Thu, Sep 16, 2010 at 9:58 AM, gavino wrote: > > I compiled readline 6.1 myself. > > > # ?./configure --prefix=/home/apps/python --disable-shared --with- > > pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6 > > --enable-readline --with-readline=/home/apps/readline/lib/ > > # ?make -j14 > > .... > > .... > > modules not installed: > > ........ ? ?readline ? ......... > > > Python starts but no readline. > > > What is the proper configure flag to use a locally compiled readline? > > I tried with and without --with-readline and with readline/ and > > readline/lib as shown above. > > thx for help > > AFAIK, there are no "readline" specific options in python 2.x's > ./configure options: > > # pwd > /usr/ports/opt/python/Python-2.6.5 > # ./configure --help | grep readline -i > # > > I could be wrong... Are you sure you've configured and compile > readline correctly and that you've set the appropriate environment > variables and paths for C/C++ compilers (eg: GCC) to pick it up ? > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" I am comiling 3.1.2. I am not root but a user. I compiled readline and it did not complain. gdb and zlib and some other modules also were not found. From prologic at shortcircuit.net.au Wed Sep 15 21:39:30 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 11:39:30 +1000 Subject: [Python-Dev] problem with python 3.1 In-Reply-To: References: Message-ID: (Posting to python general discussion). On Thu, Sep 16, 2010 at 10:17 AM, Jo?o Vitor wrote: > I made a program that, according to my teacher, is correct but is not > running properly. > The program is really simple: > import math > x = input ("Coloque o valor do primeiro cateto:") > y = input ("Coloque o valor do segundo cateto:") > z = x**2 > w = y**2 > soma = z + w > h = math.sqrt (soma) > print = "O valor da hipotenusa ?:", h > But after I put the value of x and y this error appears: > Traceback (most recent call last): > ??File "C:/lista03.py", line 4, in > ?? ?z = x**2 > TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' > My teacher said the program ran normally in his computer, but in my it > doesn't! > why? You're teacher has clearly overlooked that you must convert the values of x and y to int's using either: x = int(input(...)) or x = int(x) You cannot perform (most) mathematical operators where the operands are of different types (in Python) eg: str and int cheers James PS: Please post questions like this to either the tutor or general python mailing list(s). -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Wed Sep 15 21:41:35 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 11:41:35 +1000 Subject: compiling python 3.1.2 with local readline fails to get readline - help! In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 11:10 AM, gavino wrote: > I am comiling 3.1.2. > I am not root but a user. > I compiled readline and it did not complain. > gdb and zlib ?and some other modules also were not found. Like I said earlier in my previous post, is the readline line that you compiled and installed to your home directory actually working and can you actually compile any C programs that use this custom readline ? cheers James -- -- James Mills -- -- "Problems are solved by method" From wuwei23 at gmail.com Wed Sep 15 22:01:07 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 15 Sep 2010 19:01:07 -0700 (PDT) Subject: WMI in Python References: Message-ID: KING LABS wrote: > The following information is exactly what I am trying to collect for > the inventory. I can find vb scripts with googling. I want to do the > same with Python & Win32. Use Server/Client architecture . > Client(agent) updates the information to server. I highly agree with the recommendations for Tim Golden's WMI library. I once used it during an MS VBScript course for sys admins to produce python equivalents of the VBS code; it was far, _far_ easier to componentise & reuse python code than VBS. However, for a quick & ready solution, have you looked at Microsoft's Scriptomatic?[2] It's a handy little tool that lets you specify the WMI query you want and produces code for you, with Python being one of the targets. It _should_ be able to handle most of everything you're after, with the exception of Software Information (from memory that's not something WMI covers?). Once Scriptomatic has generated the bulk of the WMI code, that's the payload of your client-side script. There are many many many ways of doing simple client/server set ups in python, just google and pick one that works at a suitable abstraction level for you. Here's a straightforward sockets-based approach[3] (that I've never used but looks okay). 1: http://timgolden.me.uk/python/wmi/index.html 2: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&displaylang=en 3: http://wdvl.internet.com/Authoring/python/client/watts06152009.html From ldo at geek-central.gen.new_zealand Wed Sep 15 22:19:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 16 Sep 2010 14:19:53 +1200 Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: In message , Douglas wrote: >> Why reinvent rsync? > In what way is rsync relevant to the stated problem? Did you actually > READ the question? Yes. > Note: I use Linux at home (yes, even rsync) and very much prefer it to > Windows. However, at work I have no choice but to use the resources > the company provides - which is Windows; have you got that straight > now? Doesn?t change the fact that you?re reinventing rsync. From ldo at geek-central.gen.new_zealand Wed Sep 15 22:23:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 16 Sep 2010 14:23:44 +1200 Subject: WMI in Python References: Message-ID: In message , alex23 wrote: > However, for a quick & ready solution, have you looked at Microsoft's > Scriptomatic?[2] It's a handy little tool that lets you specify the > WMI query you want and produces code for you, with Python being one of > the targets. Why not just call Scriptomatic directly from within the Python script, then? Machine-generated code has no place in a source file to be maintained by a human. From rodrick.brown at gmail.com Wed Sep 15 22:31:14 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 15 Sep 2010 22:31:14 -0400 Subject: How do you preserve time values with date.datefromtimestamp() Message-ID: I'm doing something like >>> today = datetime.date.fromtimestamp(1284584357.241863) >>> today.ctime() 'Wed Sep 15 00:00:00 2010' Why isn't the time field being populated what I expect is to see something like Wed Sep 15 2010 16:59:17:241863 -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -------------- next part -------------- An HTML attachment was scrubbed... URL: From research at johnohagan.com Wed Sep 15 23:18:56 2010 From: research at johnohagan.com (John O'Hagan) Date: Thu, 16 Sep 2010 03:18:56 +0000 Subject: Argparse: add_argument with action=append appends to default Message-ID: <201009160318.57152.research@johnohagan.com> I find this surprising: >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--test', action='append', default=['default']) [...] >>> parser.parse_args(['--test', 'arg']) Namespace(test=['default', 'arg']) As an argument is provided, I didn't expect to see the default in there as well. From the argparse docs: "the default value is used when the option string was not present at the command line". While it doesn't say "_only_ when...", that's what I would have expected. Is there a reason for this behaviour? Is there a way to do what I want, to get a list of appended options _or_ a default list (apart from setting defaults outside the parser, a good way to lose track of things)? Thanks, John From cs at zip.com.au Wed Sep 15 23:33:50 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 16 Sep 2010 13:33:50 +1000 Subject: How do you preserve time values with date.datefromtimestamp() In-Reply-To: References: Message-ID: <20100916033350.GA10543@cskk.homeip.net> On 15Sep2010 22:31, Rodrick Brown wrote: | I'm doing something like | | >>> today = datetime.date.fromtimestamp(1284584357.241863) | >>> today.ctime() | 'Wed Sep 15 00:00:00 2010' | | Why isn't the time field being populated what I expect is to see something | like Wed Sep 15 2010 16:59:17:241863 Because you asked for a "date". A "date" only has day resolution. It's like going: i = int(1.234) which quite legitimately results in "1" (the interger, not a string). You want a datetime, thus: >>> today = datetime.datetime.fromtimestamp(1284584357.241863) >>> today datetime.datetime(2010, 9, 16, 6, 59, 17, 241863) >>> today.ctime() 'Thu Sep 16 06:59:17 2010' Note that .ctime() is a specific historic time reporting format of very limited utility - you're a lot better off not considering it as a storage value or as a value to print, unless you actually need to work in the domains where it is used. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Tiggers don't like honey. - A.A.Milne, The House at Pooh Corner From sumerc at gmail.com Thu Sep 16 00:05:49 2010 From: sumerc at gmail.com (k3xji) Date: Wed, 15 Sep 2010 21:05:49 -0700 (PDT) Subject: select() call and filedescriptor out of range in select error Message-ID: Hi all, We have a select-based server written in Python. Occasionally, maybe twice a month there occurs a weird problem, select() returns with filedescriptor out of range in select() error. This is of course a normal error and handled gracefully. Our policy is to take down few users for select() to handle the next cycle. However, once this error occurs, this also fails too: self.__Sockets.remove(socket) self.__Socket's is the very basic list of sockets we use in our IO loop. The call fails with: remove(x): x not in list First of all, in our entire application there is no line of code like remove(x), meaning there is no x variable. Second, the Exception shows the line number containing above code. So self.__Sockets.remove(socket) this fails with remove(x): x not in list.... I cannot understand the problem. It happens in sporadic manner and it feels that the ValueError of select() call somehow corrupts the List structure itself in Python? Not sure if something like that is possible. Thanks in advance, From pavlovevidence at gmail.com Thu Sep 16 00:13:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 15 Sep 2010 21:13:33 -0700 (PDT) Subject: Numpy: Multiplying arrays of matrices References: <8fag9dF4mtU1@mid.individual.net> Message-ID: <701b305b-a684-4b79-b147-420d27f78b41@q40g2000prg.googlegroups.com> On Sep 14, 4:54?pm, Gregory Ewing wrote: > Suppose I have two N+2 dimensional arrays, representing > N-d arrays of 2-d matrices. I want to perform matrix > multiplication between corresponding matrices in these > arrays. > > I had thought that dot() might do this, but it appears > not, because e.g. applying it to two 3-d arrays gives > a 4-d array, not another 3-d array. > > I'd also like to be able to find the inverse of each > matrix in one of these arrays, but again, inv() doesn't > do what I want -- it only works on 2-d arrays. > > Any thoughts on how to achieve these things using numpy > functions? I find for situations like this the best thing I can do is hand code the bounded operation and use the slicing to handle the arbitrarily large stuff with slicing. So, r[:,:,1,1] = a[:,:,1,1]*b[:,:,1,1] + a[:,:,2,1]*b[:,:,1,2] r[:,:,1,2] = a[:,:,1,2]*b[:,:,1,1] + a[:,:,2,2]*b[:,:,1,2] etc. Carl Banks From steve-REMOVE-THIS at cybersource.com.au Thu Sep 16 00:29:39 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Sep 2010 04:29:39 GMT Subject: help with calling a static method in a private class References: <53803bab-909c-46e5-a104-c48b38896fba@c32g2000vbq.googlegroups.com> <87r5gwgzk5.fsf@web.de> Message-ID: <4c919d33$0$11127$c3e8da3@news.astraweb.com> On Tue, 14 Sep 2010 16:38:50 +0200, Diez B. Roggisch wrote: > And additionally, but simply not using staticmethods at all. It's a > rather obscure feature of python - usually, classmethods are what is > considered a static method in other languages. Are you sure about that? I know Java isn't necessarily "other languages", but my understanding is that static methods in Java are the same as static methods in Python -- they're essentially ordinary functions glued to a class, and they don't receive either the instance or the class as an argument. http://leepoint.net/notes-java/flow/methods/50static-methods.html (Aside: I don't know about others, but I find that article *incredibly* hard to read. E.g. Static methods typically take all they data from parameters and compute something from those parameters, with no reference to variables. What, parameters aren't variables? What about local variables? I know what they *mean*, but it causes a double-take every time I read it. And when they distinguish between *classes* and *objects*, that's another double-take, because of course in Python classes are objects.) C# seems to be the same: http://dotnetperls.com/static-method as is C++ (I believe), except I'm too lazy to find a good reference. -- Steven From nad at acm.org Thu Sep 16 00:49:14 2010 From: nad at acm.org (Ned Deily) Date: Wed, 15 Sep 2010 21:49:14 -0700 Subject: select() call and filedescriptor out of range in select error References: Message-ID: In article , k3xji wrote: > We have a select-based server written in Python. Occasionally, maybe > twice a month there occurs a weird problem, select() returns with > filedescriptor out of range in select() error. This is of course a > normal error and handled gracefully. Our policy is to take down few > users for select() to handle the next cycle. However, once this error > occurs, this also fails too: > > self.__Sockets.remove(socket) > > self.__Socket's is the very basic list of sockets we use in our IO > loop. The call fails with: > remove(x): x not in list > > First of all, in our entire application there is no line of code like > remove(x), meaning there is no x variable. Second, the Exception shows > the line number containing above code. So > self.__Sockets.remove(socket) this fails with remove(x): x not in > list.... > > I cannot understand the problem. It happens in sporadic manner and it > feels that the ValueError of select() call somehow corrupts the List > structure itself in Python? Not sure if something like that is > possible. That error message is a generic exception message. It just means the object to be removed is not in the list. For example: >>> l = [a, b] >>> a, b = 1, 2 >>> l = [a, b] >>> l.remove(a) >>> l.remove(a) Traceback (most recent call last): File "", line 1, in ValueError: list.remove(x): x not in list If the problem is that the socket object in question no longer exists, you can protect your code there by enclosing the remove operation in a try block, like: try: self.__Sockets.remove(socket) except ValueError: pass -- Ned Deily, nad at acm.org From steve-REMOVE-THIS at cybersource.com.au Thu Sep 16 01:00:50 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Sep 2010 05:00:50 GMT Subject: select() call and filedescriptor out of range in select error References: Message-ID: <4c91a482$0$11127$c3e8da3@news.astraweb.com> On Wed, 15 Sep 2010 21:05:49 -0700, k3xji wrote: > Hi all, > > We have a select-based server written in Python. Occasionally, maybe > twice a month there occurs a weird problem, select() returns with > filedescriptor out of range in select() error. This is of course a > normal error and handled gracefully. Our policy is to take down few > users for select() to handle the next cycle. However, once this error > occurs, this also fails too: > > self.__Sockets.remove(socket) > > self.__Socket's is the very basic list of sockets we use in our IO loop. > The call fails with: > remove(x): x not in list Please show the *exact* error message, including the traceback, by copying and pasting it. Do not retype it by hand, or summarize it, or put it into your own words. > First of all, in our entire application there is no line of code like > remove(x), meaning there is no x variable. Look at this example: >>> sockets = [] >>> sockets.remove("Hello world") Traceback (most recent call last): File "", line 1, in ValueError: list.remove(x): x not in list "x" is just a placeholder. It doesn't refer to an actual variable x. > Second, the Exception shows > the line number containing above code. So self.__Sockets.remove(socket) > this fails with remove(x): x not in list.... Exactly. > I cannot understand the problem. It happens in sporadic manner and it > feels that the ValueError of select() call somehow corrupts the List > structure itself in Python? Not sure if something like that is possible. Anything is possible, but it's not likely. What's far more likely is that you have a bug in your code, and that somehow, under rare circumstances, it tries to remove something from a list that was never inserted into the list. Or it tries to remove it twice. My guess is something like this: try: socket = get_socket() self._sockets.append(socket) except SomeError: pass # later on self._sockets.remove(socket) -- Steven From prologic at shortcircuit.net.au Thu Sep 16 01:51:38 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 16 Sep 2010 15:51:38 +1000 Subject: select() call and filedescriptor out of range in select error In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 2:49 PM, Ned Deily wrote: > If the problem is that the socket object in question no longer exists, > you can protect your code there by enclosing the remove operation in a > try block, like: The question that remains to be seen however is: Why does your list contain dirty data ? Your code has likely removed the socket object from the list before, why is it attempting to remove it again ? I would consider you re-look at your code's logic rather than patch up the code with a "band-aid-solution". cheers James -- -- James Mills -- -- "Problems are solved by method" From post at andre-bell.de Thu Sep 16 02:24:03 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Thu, 16 Sep 2010 08:24:03 +0200 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: <8fag9dF4mtU1@mid.individual.net> References: <8fag9dF4mtU1@mid.individual.net> Message-ID: <4C91B803.4080005@andre-bell.de> Hi, I assume you have arrays like these: >>> import numpy as np >>> m1 = np.random.rand(size=(4,3,3)) >>> m2 = np.random.rand(size=(4,3,3)) So that m1[0] is a 3x3 Matrix and m1[1] is another one, i.e. you have four matrices. On 09/15/2010 01:54 AM, Gregory Ewing wrote: > I had thought that dot() might do this, but it appears > not, because e.g. applying it to two 3-d arrays gives > a 4-d array, not another 3-d array. You now want to compute the matrixproducts like this >>> np.dot(m1[0], m2[0]) and most likely you want to do this for all of the pairs >>> m1m2 = np.array(map(lambda (a,b): np.dot(a,b), zip(m1,m2))) or you could write the loop >>> m1m2 = np.empty_like(m1) >>> for i in range(m1m2.shape[0]): ... m1m2[i] = np.dot(m1, m2) which might scale better > I'd also like to be able to find the inverse of each > matrix in one of these arrays, but again, inv() doesn't > do what I want -- it only works on 2-d arrays. Same as before >>> m1inv = np.array(map(np.linalg.inv, m1)) or writing the loop >>> m1inv = np.empty_like(m1) >>> for i in range(m1inv.shape[0]): ... m1inv[i] = np.linalg.inv(m1[i]) Once again, I'm not sure whether or not it is acceptable to have the overhead of treating the array as a list. Andre From nagle at animats.com Thu Sep 16 02:25:38 2010 From: nagle at animats.com (John Nagle) Date: Wed, 15 Sep 2010 23:25:38 -0700 Subject: python27.exe vs python2.7.exe ... In-Reply-To: References: Message-ID: <4c91b86f$0$1660$742ec2ed@news.sonic.net> On 9/14/2010 2:25 PM, Sridhar Ratnakumar wrote: > Hi, > > As you may already know, ActivePython provides versioned Python executables that makes it possible to invoke a particular X.Y version from the command line directly if you have multiple Python versions on PATH. Eg: > > C:\Python27\python26.exe > C:\Python27\python27.exe > C:\Python31\python31.exe > > In the upcoming releases, we are considering to change this format to match the unix executables (with a 'dot' in it). Eg: > > C:\Python27\python2.6.exe > C:\Python27\python2.7.exe > C:\Python31\python3.1.exe > > The idea is to be able to invoke "python2.7 myscript.py" on both Unix and Windows. > > Thoughts? > > Because there is bin/python3 on unix (to separate it from the default 2.x interpreter) - it is perhaps a good idea to have "C:\Python31\python3.exe" as well. > > -srid > Take a look at Debian's Python policy. http://www.debian.org/doc/packaging-manuals/python-policy/ch-python.html at "Interpreter Name". They've addressed this. Consistency would be appreciated. Thank you. John Nagle From post at andre-bell.de Thu Sep 16 02:48:23 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Thu, 16 Sep 2010 08:48:23 +0200 Subject: Numpy: Multiplying arrays of matrices In-Reply-To: <4C91B803.4080005@andre-bell.de> References: <8fag9dF4mtU1@mid.individual.net> <4C91B803.4080005@andre-bell.de> Message-ID: <4C91BDB7.7030602@andre-bell.de> On 09/16/2010 08:24 AM, Andre Alexander Bell wrote: > or you could write the loop > > >>> m1m2 = np.empty_like(m1) > >>> for i in range(m1m2.shape[0]): > ... m1m2[i] = np.dot(m1, m2) This should have been ... m1m2[i] = np.dot(m1[i], m2[i]) Sorry for the typo. Andre From sumerc at gmail.com Thu Sep 16 02:51:34 2010 From: sumerc at gmail.com (k3xji) Date: Wed, 15 Sep 2010 23:51:34 -0700 (PDT) Subject: select() call and filedescriptor out of range in select error References: <4c91a482$0$11127$c3e8da3@news.astraweb.com> Message-ID: <0119c83d-c43e-44c0-a874-a758248e9ca6@y3g2000vbm.googlegroups.com> > Please show the *exact* error message, including the traceback, by > copying and pasting it. Do not retype it by hand, or summarize it, or put > it into your own words. Unfortunately this is not possible. The logging system I designed only gives the following information, as we have millions of logs per-day of custom exceptions I didnot include the full traceback.Here is only what I have: 1448) 15/09/10 20:02:08 - [*] ERROR: Physical max client limit reached. Please contact maintenance.filedescriptor out of range in select()[scSocketServer.py:215:][Port:515] The code generating the error is: try: self.__ReadersInCycle, self.__WritersInCycle, e = \ select( self.__Sockets, self.__WritersInCycle, [], base.scOptions.scOPT_SELECT_TIMEOUT) except ValueError, e: LogError('Physical max client limit reached.' \ ' Please contact maintenance.'+ str(e)) self.scSvr_OnClientPhysicalLimitReached() #define a policy here continue > > First of all, in our entire application there is no line of code like > > remove(x), meaning there is no x variable. > > Look at this example: > > >>> sockets = [] > >>> sockets.remove("Hello world") > > Traceback (most recent call last): > ? File "", line 1, in > ValueError: list.remove(x): x not in list > Ok. Thanks. > Anything is possible, but it's not likely. What's far more likely is that > you have a bug in your code, and that somehow, under rare circumstances, > it tries to remove something from a list that was never inserted into the > list. Or it tries to remove it twice. > > My guess is something like this: > > try: > ? ? socket = get_socket() > ? ? self._sockets.append(socket) > except SomeError: > ? ? pass > # later on > self._sockets.remove(socket) > Hmm.. Might be, but inside the self.__Sockets list there is the ListenSocket() which is the real listening socket. Naturally, I am using it in the read list of select() on every server cycle. The weird thing is that the ListenSocket itself is throwing the "not in list" exception, too! And one thing I am sure is that I have not written any kind of code that removes the Listen socket from the List, that is just impossible. Additionaly, there are very few places that I traverse the __Sockets list for optimization. The only places I delete something from the __Sockets list: 1) a user disconnects (normal disconnect, authentication or ping timeout) 3) server is being stopped or restarted Other than that there is not access to that variable from outside objects, as can be seen it is also private. And please keep in mind that this bug is there for about a year, so many code reviews have passed successfully without noticing the type of error you are suggesting. And more information on system: I am running Python 2.4 on CentOS. By the way, through digging the logs and system, it turns out select(..) is hitting the per-process FD limit. Although the system wide ulimit is unlimited, I think Python "selectmodule.c" enforces the rule to 1024. I am getting the error after hitting that limit and somehow as I just explained the __ListenSocket is being removed from the read list which causes it to be lost and Server instance is just lost forever. Putting a try..except to that code and re-init server port is a solution but I guess a bad one, because I will have not found the root cause. Thanks in advance, From steve-REMOVE-THIS at cybersource.com.au Thu Sep 16 03:14:47 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 16 Sep 2010 07:14:47 GMT Subject: select() call and filedescriptor out of range in select error References: Message-ID: <4c91c3e7$0$11127$c3e8da3@news.astraweb.com> On Thu, 16 Sep 2010 15:51:38 +1000, James Mills wrote: > On Thu, Sep 16, 2010 at 2:49 PM, Ned Deily wrote: >> If the problem is that the socket object in question no longer exists, >> you can protect your code there by enclosing the remove operation in a >> try block, like: > > > The question that remains to be seen however is: > > Why does your list contain dirty data ? Your code has likely removed the > socket object from the list before, why is it attempting to remove it > again ? > > I would consider you re-look at your code's logic rather than patch up > the code with a "band-aid-solution". Well said. -- Steven From __peter__ at web.de Thu Sep 16 03:26:32 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Sep 2010 09:26:32 +0200 Subject: Argparse: add_argument with action=append appends to default References: Message-ID: John O'Hagan wrote: > I find this surprising: > >>>> import argparse >>>> parser = argparse.ArgumentParser() >>>> parser.add_argument('--test', action='append', default=['default']) > [...] >>>> parser.parse_args(['--test', 'arg']) > Namespace(test=['default', 'arg']) > > As an argument is provided, I didn't expect to see the default in there as > well. From the argparse docs: "the default value is used when the option > string was not present at the command line". While it doesn't say "_only_ > when...", that's what I would have expected. > > Is there a reason for this behaviour? Is there a way to do what I want, to > get a list of appended options _or_ a default list (apart from setting > defaults outside the parser, a good way to lose track of things)? You could either tweak the default value or the action: $ cat append.py import argparse class DefaultList(list): def __copy__(self): return [] if __name__ == "__main__": p = argparse.ArgumentParser() p.add_argument("-t", "--test", action="append", default=DefaultList(["default"])) print p.parse_args() $ python append.py -t one -t two Namespace(test=['one', 'two']) $ python append.py -t one Namespace(test=['one']) $ python append.py Namespace(test=['default']) $ cat append1.py import argparse class DefaultAppend(argparse._AppendAction): def __call__(self, parser, namespace, values, option_string=None): items = argparse._copy.copy(argparse._ensure_value(namespace, self.dest, [])) try: self._not_first except AttributeError: self._not_first = True del items[:] items.append(values) setattr(namespace, self.dest, items) if __name__ == "__main__": p = argparse.ArgumentParser() p.add_argument("-t", "--test", action=DefaultAppend, default=["default"]) print p.parse_args() $ python append1.py -t one -t two Namespace(test=['one', 'two']) $ python append1.py -t one Namespace(test=['one']) $ python append1.py Namespace(test=['default']) Peter From wuwei23 at gmail.com Thu Sep 16 03:39:41 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 16 Sep 2010 00:39:41 -0700 (PDT) Subject: WMI in Python References: Message-ID: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> Lawrence D'Oliveiro wrote: > Why not just call Scriptomatic directly from within the Python script, then? Because Scriptomatic _generates scripts to access WMI_, that's what it _does_. Are you _seriously_ advocating writing Python code to fire up a Windows application, programmatically manipulating a GUI to generate more Python code for your original script to import or exec? For your question to make any real sense, you'd want to ask "Why not access WMI directly...", which you might notice was the first recommendation I made. > Machine-generated code has no place in a source file to be maintained by a > human. As you've made your disdain for Windows _perfectly_ clear through your incessant sniping on this list, I think I'm pretty safe in saying you have no idea of the quality of Scriptomatic's output. I don't understand what possibly makes you believe you're qualified to make such a statement. From jeeva235 at hotmail.com Thu Sep 16 03:39:58 2010 From: jeeva235 at hotmail.com (superman) Date: Thu, 16 Sep 2010 00:39:58 -0700 (PDT) Subject: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INVESTMENT Message-ID: MAKE UPTO $5000 P/M $2000 IN FIRST 30 DAYS! NO INVESTMENT Generate $50 to $100 whenever you have a couple of hours free time to spare. You could make $50 or more in the next 2 hours. Starting right Now!Today! http://snipurl.com/11i6lw GET PAID TO: Take online surveys and make from $5 to $75, or more Participate in focus groups and make up to $150 an hour Take phone surveys and you can earn as much as $120 an hour Try new products (and keep the free products too) Preview new movie trailers for $4 to $25 an hour http://snipurl.com/11i6lw Earn from your free website Awesome earnings get paid for your honest work Join as a free member and get paid to your bank account To join the Network follow the link http://snipurl.com/11i6lw From k.sahithi2862 at gmail.com Thu Sep 16 04:44:34 2010 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 16 Sep 2010 01:44:34 -0700 (PDT) Subject: HOT PHOTOS&VIDEOS Message-ID: FOR HOT SEXY PHOTOS&VIDEOS [EXPOSING PHOTO] http://hotheroinesphotos.blogspot.com/2010/09/exposing-photo.html FOR HOT VIDEOS WITH SEXY PHOTO http://hotheroinesphotos.blogspot.com/2010/09/kangana-in-sexy-feel.html HOT MALLU AUNTY http://hotheroinesphotos.blogspot.com/2010/09/mallu-aunty.html LASYA HOT SEXY PHOTO http://hotheroinesphotos.blogspot.com/2010/09/sexy-lasya.html CHARMI HOT BOOBS SHOW http://hotheroinesphotos.blogspot.com/2010/09/charmi-boobs-show.html HOT MALLU AUNTY http://hotheroinesphotos.blogspot.com/2010/09/mallu-special.html SNEHA IN A BIKINI http://hotheroinesphotos.blogspot.com/2010/09/sneha-in-bikini.html From davea at ieee.org Thu Sep 16 05:46:36 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 16 Sep 2010 05:46:36 -0400 Subject: Accessing windoze file attributes In-Reply-To: References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: <4C91E77C.1050808@ieee.org> On 2:59 PM, Douglas wrote: > @Diez and @David > Thanks guys. Both excellent leads. Colour me happy. I can now make > progress and meet some deadlines. :) > > @Lawrence >> Why reinvent rsync? > In what way is rsync relevant to the stated problem? Did you actually > READ the question? > Note: I use Linux at home (yes, even rsync) and very much prefer it to > Windows. However, at work I have no choice but to use the resources > the company provides - which is Windows; have you got that straight > now? > If you have something more helpful and mature to say, relevant to the > actual question, then I will gladly hear it, and even apologise. > Otherwise, don't bother. I already enough from respondents who were > far more adult, knowledgeable and helpful ... and all the more > impressive in comparison. > > Sincerely, > -- Douglas > Let's see. You're a first-time poster on this forum, and you choose to attack Lawrence, who was giving you a succinct reference to a possible solution to your problem. So how does mentioning a program that could directly solve your problem constitute immature and unhelpful response? Have you checked out any of the several rsync implementations on Windows? Some require cygwin, but there are a couple that would seem not to. Maybe try http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp or http://www.itefix.no/i2/node/10650 There are several reasons why any particular one of these may not be appropriate for your needs, but being stuck on Windows isn't really one of them. DaveA From hobson42 at gmaiil.com Thu Sep 16 06:06:15 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 16 Sep 2010 11:06:15 +0100 Subject: business date and calendar libraries? In-Reply-To: <4C8E59FA.3060508@simplistix.co.uk> References: <4C8E59FA.3060508@simplistix.co.uk> Message-ID: <4C91EC17.9010000@gmaiil.com> On 13/09/2010 18:06, Chris Withers wrote: > Hi All, > > I'm wondering what libraries people would use to answer the following > questions relating to business days: > > - on a naive level; "what's give me the last business day" (ie: > skipping weekends) > > - on a less-naive level; same question but taking into account public > holidays > > - on a horrific level; same question, but taking into account business > days of a particular market (NYSE, LSE, etc) Hi Chris, Having written one of these for UK holidays, it was easy once I obtained a routine to calculate the date of Easter :) We decided that editing a list of holidays each year was "too hard" and so they would always be calculated so.. I had a "isWorkday()" routine that returned false for everything below, and true otherwise: Every Sat and Sun Jan 1st, and the first Monday in Jan The day after Easter day The first Monday in May (Month = May and day <= 7 and dow = Monday) The last Monday in May (day >= 25 .... The last Monday in August (day >= 25 .... Every day from 23rd Dec to the end of the year. (unique to company). I believe that officially, Christmas holiday is the first week-day on or after 25th Dec. Boxing Day/St Stephens holiday is the week-day after the Christmas holiday date above. Hope this helps. Ian From raoulbia at gmail.com Thu Sep 16 06:36:10 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 16 Sep 2010 03:36:10 -0700 (PDT) Subject: accessing a text file References: <49b5a289-ad84-4e58-b6e9-b5551edd5b40@z28g2000yqh.googlegroups.com> <2b1ec847-df4b-48a2-b61f-4e11edadc2d1@u6g2000yqh.googlegroups.com> <5ba28765-3fac-4de5-aa3c-6ca5da368ec7@t20g2000yqa.googlegroups.com> <87wrqyculn.fsf@benfinney.id.au> <87sk1mcsof.fsf@benfinney.id.au> <3c861605-7e0c-449d-bb1b-cb523cdb8618@h7g2000yqn.googlegroups.com> <059cffaa-f482-4e91-847b-22c2fc6186fc@26g2000yqv.googlegroups.com> <87aantayiw.fsf@benfinney.id.au> <0ff73340-9b7c-46da-91db-361a75fa2302@g17g2000yqe.googlegroups.com> Message-ID: <32c15d1d-5785-488e-b957-18f486476363@l17g2000vbf.googlegroups.com> On Sep 9, 10:09?pm, Nobody wrote: > On Wed, 08 Sep 2010 03:30:00 -0700, Baba wrote: > > Who is licensed to judge what can and cannot be posted as a question? > > Exactly the same set of people who are licensed to judge what can and > cannot be posted as an answer. > > If you don't like the responses you get here, you could try posting your > questions on 4chan. If nothing else, that will give you a whole new > perspective on what an "unfriendly" response really looks like. I would to apologise to anyone who might have been upset or offended by my reaction. I am new to forums (as i am new to programming) so i hope i might be forgiven for not appreciating the true value of the support one can receive on this forum. I wish to reiterate that i underatand that experts provide help free of charge and in their spare time so there's no point for me to like or dislike the style of an answer. Baba From mummerx at gmail.com Thu Sep 16 07:50:23 2010 From: mummerx at gmail.com (Douglas) Date: Thu, 16 Sep 2010 04:50:23 -0700 (PDT) Subject: Accessing windoze file attributes References: <8dc0fa8e-f0e6-4603-9283-186551597e8d@a19g2000vbi.googlegroups.com> Message-ID: @Dave Grateful thanks for your web site suggestions, and I will look them up. @Lawrence Pleasee accept my apologies. I mistook your brevity for a superior snotty attitude. From dusan.smitran at gmail.com Thu Sep 16 08:04:56 2010 From: dusan.smitran at gmail.com (dusans) Date: Thu, 16 Sep 2010 05:04:56 -0700 (PDT) Subject: Python autocomplete module Message-ID: Is there a python module to make autocomplete suggestion easy. I would build an api reference as a string: CATALOG1.SCHEME1.TABLE1.column1 CATALOG1.SCHEME1.TABLE1.column2 CATALOG1.SCHEME1.TABLE1.column3 . . CATALOG10.SCHEME10.TABLE100.column1 CATALOG10.SCHEME10.TABLE100.column2 CATALOG10.SCHEME10.TABLE100.column3 And when the user types and want suggestions he would get a nice list. Example: I trype "CATALOG10.SCHEME10." then i request autocomplete and it would return the tables in the specified scheme. Tnx From anand.shashwat at gmail.com Thu Sep 16 08:18:43 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 16 Sep 2010 17:48:43 +0530 Subject: Python autocomplete module In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 5:34 PM, dusans wrote: > Is there a python module to make autocomplete suggestion easy. > Try 'rlcompleter' module. Though I haven't tried it myself, just used it in .pythonrc for auto-completion in intepretor mode. http://docs.python.org/library/rlcompleter.html -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicoddemus at gmail.com Thu Sep 16 08:32:31 2010 From: nicoddemus at gmail.com (Bruno Oliveira) Date: Thu, 16 Sep 2010 09:32:31 -0300 Subject: Multiprocessing Queue strange behavior In-Reply-To: <4C9130F2.80000@mrabarnett.plus.com> References: <4C9130F2.80000@mrabarnett.plus.com> Message-ID: Hi, thanks for the answer. I thought about that, but the problem is that I found the problem in code that *was* using the Queue between processes. This code for example fails around 60% of the time in one of our linux machines (raising an Empty exception): from processing import Queue, Process import time def Consume(queue): print queue.get_nowait() if __name__ == '__main__': queue = Queue() queue.put('x') p = Process(target=Consume, args=(queue,)) p.start() p.join() Again, putting a sleep call before starting the consumer process makes the code work all time. That is the main reason I believe there is a problem in the Queue code somewhere. Cheers, On Wed, Sep 15, 2010 at 5:47 PM, MRAB wrote: > On 15/09/2010 21:10, Bruno Oliveira wrote: > >> Hi list, >> >> I recently found a bug in my company's code because of a strange >> behavior using multiprocessing.Queue. The following code snippet: >> >> from multiprocessing import Queue >> >> queue = Queue() >> queue.put('x') >> print queue.get_nowait() >> Fails with: >> >> ... >> File >> >> "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", >> line 153, in getNoWait >> return self.get(False) >> File >> >> "E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py", >> line 129, in get >> raise Empty >> Queue.Empty >> >> Strangely, changing this to: >> >> queue = Queue() >> queue.put('x') >> time.sleep(0.1) # <<< >> print queue.get_nowait() >> Works as expected. Using the original snippet changing the import to >> threading's Queue also works. >> >> It seems like there's a bug in multiprocessing's Queue implementation. >> Opinions? >> >> I don't think it's a bug as such. > > The purpose of the multiprocessing queue is to transfer data between > different processes, which don't have a shared address space (unlike > threads, which do). > > The transfer involves passing the data between the processes via a > pipe. This is done in a background thread and takes some time to > complete, so the data won't appear immediately. It looks like it > doesn't matter that the putter and the getter happen to be in the same > process, possibly because no-one expected that someone would use a > multiprocessing queue within the same process like that, so it doesn't > check for a shortcut. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kinglabs.in at gmail.com Thu Sep 16 08:41:54 2010 From: kinglabs.in at gmail.com (KING LABS) Date: Thu, 16 Sep 2010 05:41:54 -0700 (PDT) Subject: WMI in Python References: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> Message-ID: On Sep 16, 12:39?pm, alex23 wrote: > Lawrence D'Oliveiro wrote: > > Why not just call Scriptomatic directly from within the Python script, then? > > Because Scriptomatic _generates scripts to access WMI_, that's what it > _does_. Are you _seriously_ advocating writing Python code to fire up > a Windows application, programmatically manipulating a GUI to generate > more Python code for your original script to import or exec? > > For your question to make any real sense, you'd want to ask "Why not > access WMI directly...", which you might notice was the first > recommendation I made. > > > Machine-generated code has no place in a source file to be maintained by a > > human. > > As you've made your disdain for Windows _perfectly_ clear through your > incessant sniping on this list, I think I'm pretty safe in saying you > have no idea of the quality of Scriptomatic's output. I don't > understand what possibly makes you believe you're qualified to make > such a statement. Thank you all .... looks I got lot of reading to be done now based on all your suggestions. From coolaj86 at gmail.com Thu Sep 16 09:17:58 2010 From: coolaj86 at gmail.com (AJ ONeal) Date: Thu, 16 Sep 2010 07:17:58 -0600 Subject: Stream Audio to Web Clients Message-ID: I'm looking for an example (perhaps with red5) for this scenario: 1. I install some server tools on my ubuntu box 2. I place an mp3 and an m4a in a special location 3. I click a play button on a web page and both songs play in random order AJ ONeal -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreadpiratejeff at gmail.com Thu Sep 16 11:25:06 2010 From: dreadpiratejeff at gmail.com (J) Date: Thu, 16 Sep 2010 11:25:06 -0400 Subject: Very stupid question about a % symbol Message-ID: OK, this is a very stupid question about a very simple topic, but Google is failing me this morning... I'm trying to print a string that looks like this: Reported memory amounts are within 10% tolerance and the print line looks (for now) like this: print "Reported memory amounts are within %s%s tolerance" % (self.mem_tolerance,'%') Is there a better way to print a '%' in the string when also using formating? That works, but I've been looking for a way that looks... less kludgey. I've tried things like this: print "blahblahblah %s \%" % variable but the first %s forces every other % to be interpreted as additional format markers. So while what I'm doing works, I was hoping someone could either confirm that that's the right way, or show me a better way. Cheers Jeff From googler.1.webmaster at spamgourmet.com Thu Sep 16 11:34:51 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 16 Sep 2010 08:34:51 -0700 (PDT) Subject: compile Py2.6 on SL Message-ID: Hi, I have some trouble with Python on Snow Leopard (10.6.3). I compile Python as a framework(for 32/64bit) without any problems. But implementing the lib in my C app, I get the following error on linking: Undefined symbols: "_Py_InitModule4_64", referenced from: RegisterModule_BPY(char const*, PyMethodDef*, char const*, _object*, int)in i_moduleobject.o ld: symbol(s) not found I read a lot of stuff about this problem, but nothing helped me. My app is in 64-bit and I compiled Python for 32/64bit. When I compile exactly the same package with the same configure flags under Leopard (10.5.8) it works fine. Any ideas? Thanks a lot! Bye, moerchendiser2k3 From contact at xavierho.com Thu Sep 16 12:04:42 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 17 Sep 2010 02:04:42 +1000 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: On 17 September 2010 01:25, J wrote: > Is there a better way to print a '%' in the string when also using > formating? > I believe %% will escape the % and prints it straight out. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Thu Sep 16 12:09:14 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 16 Sep 2010 16:09:14 +0000 (UTC) Subject: Very stupid question about a % symbol References: Message-ID: On 2010-09-16, J wrote: > Reported memory amounts are within 10% tolerance >>> "Reported memory amounts are within %d%% tolerance" % 10 'Reported memory amounts are within 10% tolerance' -- Grant Edwards grant.b.edwards Yow! It's the RINSE CYCLE!! at They've ALL IGNORED the gmail.com RINSE CYCLE!! From python.list at tim.thechases.com Thu Sep 16 12:14:19 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 16 Sep 2010 11:14:19 -0500 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: <4C92425B.8040301@tim.thechases.com> On 09/16/10 10:25, J wrote: > OK, this is a very stupid question about a very simple topic, but > print "Reported memory amounts are within %s%s tolerance" % > (self.mem_tolerance,'%') > > Is there a better way to print a '%' in the string when also using formating? > > I've tried things like this: > > print "blahblahblah %s \%" % variable So close print "blah %s %%" % variable -tkc From dreadpiratejeff at gmail.com Thu Sep 16 12:23:08 2010 From: dreadpiratejeff at gmail.com (J) Date: Thu, 16 Sep 2010 12:23:08 -0400 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 12:09, Grant Edwards wrote: > On 2010-09-16, J wrote: > >> Reported memory amounts are within 10% tolerance > >>>> "Reported memory amounts are within %d%% tolerance" % 10 > 'Reported memory amounts are within 10% tolerance' Thanks for the replies... I KNEW there was a simple way to escape the % but I had no idea what it was (I just had conviction). I was thrown when the \ didn't escape it... never knew about %%. But now I do! Thanks for the replies! From jason.swails at gmail.com Thu Sep 16 12:24:00 2010 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 16 Sep 2010 12:24:00 -0400 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: Ha, I had this same problem, but I was trying to do dynamic formatting: ("%%%s" % format) % number where "format" is a python-ized fortran format string (i.e. "9.4E"). Looks kinda weird and less elegant than the {0:{1}}-type .format() syntax, but at least it preserves backwards compatibility to pythons older than 2.6. Before I found out how to cancel the %, the statement looked like ("%"+"%s" % format) % number. Not much of a change, but still a nice thing to know since I play with %s a lot. Thanks! (even though I'm not the original asker) Jason On Thu, Sep 16, 2010 at 12:09 PM, Grant Edwards wrote: > On 2010-09-16, J wrote: > > > Reported memory amounts are within 10% tolerance > > >>> "Reported memory amounts are within %d%% tolerance" % 10 > 'Reported memory amounts are within 10% tolerance' > > -- > Grant Edwards grant.b.edwards Yow! It's the RINSE > CYCLE!! > at They've ALL IGNORED the > gmail.com RINSE CYCLE!! > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ron.eggler at gmail.com Thu Sep 16 12:33:06 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 16 Sep 2010 09:33:06 -0700 (PDT) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: <4138d49d-5681-40d8-8d52-761143ce645b@p22g2000pre.googlegroups.com> On Sep 15, 5:51?pm, "jipalaciosort... at gmail.com" wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > El 15/09/2010 20:58, Grant Edwards escribi?: > > > > > On 2010-09-15, cerr wrote: > > >> I get a socket error "[Errno 98] Address already in use" when i > >> try to open a socket that got closed before with close(). How > >> come close() doesn't close the socket properly? My socket code : > > >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > >> s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, > >> addr = s.accept() while conn and loop: ... ... ... conn.close() > > > At what line does the error occur? > > > To what does the phrase "open a socket" refer? > > > Have you tried the usual solution of setting the SO_REUSEADDR > > option on the socket before calling bind? > > >http://www.google.com/search?q=socket+%27address+already+in+use%27 > > Maybe, you have any other proccess in your system using your listen > port, for example apache... Nope negative, I have one process on my system only that occupies port 1514. > > - -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?_ _ _ ? _ ? _ _ _ _ ? _ _ _ > Jose Ignacio Palacios Ortega ? ? ? ? ? ? ?/_ ? _/ / / / ?_ ? / / _ ? / > Telf: +34 637 058 813 ? ? ? ? ? ? ? ? ? ? ? / / ?/ / / /_ / / / / / / > Correo-e: jipalaciosort... at gmail.com ?_ ? ?/ / ?/ / / _ _ _/ / / / / > Msn: jipalaciosort... at gmail.com ? ? ?/ /_ / / ?/ / / / ? ? ?/ /_/ / > ID firma PGP: 0x0EB87E48 ? ? ? ? ? ? \ _ _ / ?/_/ /_/ ? ? ?/_ _ _/ > Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48 > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (MingW32) > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ > > iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ > 4cgAniOoR70hu7UylkpgAr3JI5hxNXYP > =MoYK > -----END PGP SIGNATURE----- From tom.browder at gmail.com Thu Sep 16 12:33:25 2010 From: tom.browder at gmail.com (Tom Browder) Date: Thu, 16 Sep 2010 11:33:25 -0500 Subject: Python 2.7 Won't Build Message-ID: I am trying to rebujild the 2.7 maintenance branch and get this error on Ubuntu 10.04.1 LTS: XXX lineno: 743, opcode: 0 Traceback (most recent call last): File "/usr/local/src/python-2.7-maint-svn/Lib/site.py", line 62, in import os File "/usr/local/src/python-2.7-maint-svn/Lib/os.py", line 743, in def urandom(n): SystemError: unknown opcode I installed it successfully once so I may be getting conflicts, but I can't figure it out. There were some similar bugs reported in previous versions but I didn't see a clear solution. I have unset my PYTHONPATH and LD_LIBRARY_PATH, but python2.7 is my default python. I guess my next step will be to manually remove python 2.7 unless I hear some solutions soon. Thanks, -Tom Thomas M. Browder, Jr. Niceville, Florida USA From ron.eggler at gmail.com Thu Sep 16 12:43:45 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 16 Sep 2010 09:43:45 -0700 (PDT) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Sep 15, 11:58?am, Grant Edwards wrote: > On 2010-09-15, cerr wrote: > > > > > > > I get a socket error "[Errno 98] Address already in use" when i try to > > open a socket that got closed before with close(). How come close() > > doesn't close the socket properly? > > My socket code : > > > ? s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > ? s.bind((host, port)) > > ? s.listen(1) > > ... > > ... > > ... > > ? while loop: > > ? ? conn, addr = s.accept() > > ? ? while conn and loop: > > ... > > ... > > ... > > ? ? ?conn.close() > > At what line does the error occur? The whole message I get looks like: Traceback (most recent call last): File "./checkGPIO.py", line 148, in main() File "./checkGPIO.py", line 75, in main s.bind((host, port)) File "", line 1, in bind socket.error: [Errno 98] Address already in use Where line 75 contains following: s.bind((host, port)) > > To what does the phrase "open a socket" refer? create a listening socket...? > Have you tried the usual solution of setting the SO_REUSEADDR option > on the socket before calling bind? yep, that did it for me, thanks a lot! :) > http://www.google.com/search?q=socket+%27address+already+in+use%27 Google's your friend if you can read ;) > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! I own seven-eighths of > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? all the artists in downtown > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ?Burbank! From mark.pelletier at asrcms.com Thu Sep 16 12:55:51 2010 From: mark.pelletier at asrcms.com (mark.pelletier at asrcms.com) Date: Thu, 16 Sep 2010 09:55:51 -0700 (PDT) Subject: Too many threads Message-ID: <716be5f9-79b9-43c7-9c04-0454d015086d@j30g2000vbr.googlegroups.com> For some reason, the tasks I put into my thread pool occasionally get run more than once. Here's the code: # ------------------------------------------------------------------------------------------------------------------- from threading import Thread from queue import Queue import subprocess class ThreadPool(object): def __init__(self, thread_count): ''' Argument thread_count is the maximum number of theads. ''' self.thread_count = thread_count self.queue = Queue() # create and start the threads for i in range(self.thread_count): t = Thread(target=self._worker) t.daemon = True t.start() def _worker(self): ''' A "private" method that pulls tasks off the queue and does something with them. ''' while True: item = self.queue.get() print(item) self.queue.task_done() def run(self, tasklist): ''' Put tasks in the queue. ''' for item in tasklist: self.queue.put(item) # block until all threads are done. self.queue.join() # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - tasklist = [ 'task1', 'task2', 'task3', 'task4', 'task5', 'task6', 'task7', 'task8', 'task9', 'task10', 'task11', 'task12', 'task13', 'task14', 'task15', 'task16'] if __name__ == '__main__': t = ThreadPool(3) t.run(tasklist) #--------------------------------------------------------------------------------------------------- And here's some typical output: task1 task2 task2 task3 task4 task5 task5 task6 task7 task8 task8 task9 task8 task9 task10 task11 task11 task12 task13 task13 task14 task15 task15 task16 I only want a task to get fired off once. What am I doing wrong? Thanks! From hansyin at gmail.com Thu Sep 16 13:19:32 2010 From: hansyin at gmail.com (Hans) Date: Thu, 16 Sep 2010 10:19:32 -0700 (PDT) Subject: program organization question for web development with python References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> Message-ID: <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> On Sep 15, 5:33?pm, James Mills wrote: > On Thu, Sep 16, 2010 at 10:14 AM, Hans wrote: > > I'm new to this area. Please allow me to ask some (maybe stupid) > > questions. > > Without reading the rest of your post too much. Designs are up to you, > I can't comment. > > I can only share in a fairly common view, and that is, we'd encourage > you to use a web framework > as opposed to plain old CGI. > > cheers > james > > -- > -- James Mills > -- > -- "Problems are solved by method" Hi James, Thanks for response. Maybe I did not make my question clear. I never tried python web programing before, so I want to start from CGI. I read something about web framework like django, but seems it's a little bit complicated. my task is actually very simple: get search string from input, and then search database, print search result. I thought CGI should be good enough to do this. I don't have any idea about how to organize those cgi codes, so what I'm asking is: 1. do I have to have each single file for each hyper-link? Can I put them together? how? 2. how can I pass a db_cursor to another file? can I use db_cursor as a parameter? Thanks again! Hans From lehmannmapson at cnm.de Thu Sep 16 13:40:02 2010 From: lehmannmapson at cnm.de (Marten Lehmann) Date: Thu, 16 Sep 2010 19:40:02 +0200 Subject: Problem building python 2.7 with --enable-shared Message-ID: <8ff33iFi97U1@mid.individual.net> Hello, I've build python 2.7 successfully by just calling configure, make and make install. But to use python within PostgreSQL, I need to built python with --enable-shared. I tried to do so (configure --enable-shared), but I see these lines several times in the log (but compiling continues): /usr/bin/ld: /test/python/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /test/python/lib/libpython2.7.a: could not read symbols: Bad value collect2: ld returned 1 exit status Later, the compiling process ends completely: PYTHONPATH=/var/tmp/vrmd-python2-root/test/python/lib/python2.7 LD_LIBRARY_PATH=/usr/src/redhat/BUILD/Python-2.7: \ ./python -Wi -tt /var/tmp/vrmd-python2-root/test/python/lib/python2.7/compileall.py \ -d /test/python/lib/python2.7 -f \ -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ /var/tmp/vrmd-python2-root/test/python/lib/python2.7 Traceback (most recent call last): File "/var/tmp/vrmd-python2-root/test/python/lib/python2.7/compileall.py", line 17, in import struct File "/var/tmp/vrmd-python2-root/test/python/lib/python2.7/struct.py", line 1, in from _struct import * ImportError: No module named _struct make: *** [libinstall] Error 1 Any ideas, what I have done wrong? Kind regards Marten From python at mrabarnett.plus.com Thu Sep 16 14:01:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Sep 2010 19:01:58 +0100 Subject: program organization question for web development with python In-Reply-To: <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> Message-ID: <4C925B96.60000@mrabarnett.plus.com> On 16/09/2010 18:19, Hans wrote: > On Sep 15, 5:33 pm, James Mills wrote: >> On Thu, Sep 16, 2010 at 10:14 AM, Hans wrote: >>> I'm new to this area. Please allow me to ask some (maybe stupid) >>> questions. >> >> Without reading the rest of your post too much. Designs are up to you, >> I can't comment. >> >> I can only share in a fairly common view, and that is, we'd encourage >> you to use a web framework >> as opposed to plain old CGI. >> >> cheers >> james >> >> -- >> -- James Mills >> -- >> -- "Problems are solved by method" > > Hi James, > > Thanks for response. > Maybe I did not make my question clear. I never tried python web > programing before, so I want to start from CGI. > > I read something about web framework like django, but seems it's a > little bit complicated. my task is actually very simple: get search > string from input, and then search database, print search result. I > thought CGI should be good enough to do this. > > I don't have any idea about how to organize those cgi codes, so what > I'm asking is: > > 1. do I have to have each single file for each hyper-link? Can I put > them together? how? > 2. how can I pass a db_cursor to another file? can I use db_cursor as > a parameter? > I recently wrote a web-based program using CherryPy, which was very straightforward. That might suit your needs. From iurisilvio at gmail.com Thu Sep 16 14:09:02 2010 From: iurisilvio at gmail.com (Iuri) Date: Thu, 16 Sep 2010 15:09:02 -0300 Subject: program organization question for web development with python In-Reply-To: <4C925B96.60000@mrabarnett.plus.com> References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> <4C925B96.60000@mrabarnett.plus.com> Message-ID: Another pretty web framework is Bottle (http://bottle.paws.de). It is very easy to setup and use. I use it to tasks like this one you want. []s iuri On Thu, Sep 16, 2010 at 3:01 PM, MRAB wrote: > On 16/09/2010 18:19, Hans wrote: > >> On Sep 15, 5:33 pm, James Mills wrote: >> >>> On Thu, Sep 16, 2010 at 10:14 AM, Hans wrote: >>> >>>> I'm new to this area. Please allow me to ask some (maybe stupid) >>>> questions. >>>> >>> >>> Without reading the rest of your post too much. Designs are up to you, >>> I can't comment. >>> >>> I can only share in a fairly common view, and that is, we'd encourage >>> you to use a web framework >>> as opposed to plain old CGI. >>> >>> cheers >>> james >>> >>> -- >>> -- James Mills >>> -- >>> -- "Problems are solved by method" >>> >> >> Hi James, >> >> Thanks for response. >> Maybe I did not make my question clear. I never tried python web >> programing before, so I want to start from CGI. >> >> I read something about web framework like django, but seems it's a >> little bit complicated. my task is actually very simple: get search >> string from input, and then search database, print search result. I >> thought CGI should be good enough to do this. >> >> I don't have any idea about how to organize those cgi codes, so what >> I'm asking is: >> >> 1. do I have to have each single file for each hyper-link? Can I put >> them together? how? >> 2. how can I pass a db_cursor to another file? can I use db_cursor as >> a parameter? >> >> I recently wrote a web-based program using CherryPy, which was very > straightforward. That might suit your needs. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lehmannmapson at cnm.de Thu Sep 16 14:11:23 2010 From: lehmannmapson at cnm.de (Marten Lehmann) Date: Thu, 16 Sep 2010 20:11:23 +0200 Subject: Problem building python 2.7 with --enable-shared In-Reply-To: <8ff33iFi97U1@mid.individual.net> References: <8ff33iFi97U1@mid.individual.net> Message-ID: <8ff4ubFt5tU1@mid.individual.net> The strange thing is: This only happens when I'm compiling through rpmbuild. Issuing the same commands (configure --enable-shared, make, make install) directly on the shell works fine... From thomas at jollybox.de Thu Sep 16 14:12:38 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 16 Sep 2010 20:12:38 +0200 Subject: Problem building python 2.7 with --enable-shared In-Reply-To: <8ff33iFi97U1@mid.individual.net> References: <8ff33iFi97U1@mid.individual.net> Message-ID: <201009162012.39459.thomas@jollybox.de> On Thursday 16 September 2010, it occurred to Marten Lehmann to exclaim: > Hello, > > I've build python 2.7 successfully by just calling configure, make and > make install. But to use python within PostgreSQL, I need to built > python with --enable-shared. > > I tried to do so (configure --enable-shared), but I see these lines > several times in the log (but compiling continues): Did you start with a clean source tree? If you just reconfigured and called make again in the source tree where you already had built Python, make will just re-use the old object files, which would be built without -fPIC and whatever other options are required for the shared library linking to work. > > /usr/bin/ld: /test/python/lib/libpython2.7.a(abstract.o): relocation > R_X86_64_32 against `a local symbol' can not be used when making a > shared object; recompile with -fPIC > /test/python/lib/libpython2.7.a: could not read symbols: Bad value > collect2: ld returned 1 exit status If you get this when building from a fresh source tree, I can't explain why this might happen, but, again, starting afresh, this time adding -fPIC to the CFLAGS, may work. But I expect that the configure script, or makefile, or libtool, or whatever, should do this, hence my guess that maybe you're using leftover object files. (hint: make clean) > > Later, the compiling process ends completely: > > PYTHONPATH=/var/tmp/vrmd-python2-root/test/python/lib/python2.7 > LD_LIBRARY_PATH=/usr/src/redhat/BUILD/Python-2.7: \ > ./python -Wi -tt > /var/tmp/vrmd-python2-root/test/python/lib/python2.7/compileall.py \ > -d /test/python/lib/python2.7 -f \ > -x > 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ > /var/tmp/vrmd-python2-root/test/python/lib/python2.7 > Traceback (most recent call last): > File > "/var/tmp/vrmd-python2-root/test/python/lib/python2.7/compileall.py", > line 17, in > import struct > File > "/var/tmp/vrmd-python2-root/test/python/lib/python2.7/struct.py", line > 1, in > from _struct import * > ImportError: No module named _struct > make: *** [libinstall] Error 1 > > Any ideas, what I have done wrong? > > Kind regards > Marten From lehmannmapson at cnm.de Thu Sep 16 15:02:53 2010 From: lehmannmapson at cnm.de (Marten Lehmann) Date: Thu, 16 Sep 2010 21:02:53 +0200 Subject: Problem building python 2.7 with --enable-shared In-Reply-To: References: <8ff33iFi97U1@mid.individual.net> Message-ID: <8ff7utFh63U1@mid.individual.net> I digged into this one step further: I compared the output of configure and make. For configure, there is no change. But for make, I found out something, that I didn't expected: When configure is called with a prefix to a location, where a valid python installation already exists, it uses these locations for gcc, although it shouldn't (we are about to compile a clean, brandnew python version, so why should it include parts of an existing python installation?). Additionally to the default include paths gcc [...] -I. -IInclude -I./Include -I/usr/local/include -I/usr/src/redhat/BUILD/Python-2.7/Include -I/usr/src/redhat/BUILD/Python-2.7 [...] the path of the existing Python installation is added: -I/test/python2/include And additionally the default library paths and libs gcc [...] -L/usr/local/lib -L. -lpython2.7 [...] the path of the existing Python libs is added: gcc [...9 -L/vrmd/python2/lib So linking to python2.7 during make doesn't link to the freshly build library, but to the existing in the system. And at least in my case, where I'm switching from a python installation without --enabled-shared to a new version including --enable-shared, this causes serious problems: /usr/bin/ld: /vrmd/python2/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC -/vrmd/python2/lib/libpython2.7.a: could not read symbols: Bad value -collect2: ld returned 1 exit status Is there any option I missed in configure or any variable that I might set to correct this? Or should a file a bug to the python developers? Deinstalling python before compiling or renaming the python directory is not a good solution. Kind regards Marten From rdh at new.rr.com Thu Sep 16 15:35:46 2010 From: rdh at new.rr.com (DataSmash) Date: Thu, 16 Sep 2010 12:35:46 -0700 (PDT) Subject: Too much code - slicing Message-ID: I need to create a simple utility to remove characters from either the right or left side of directories. This works, but there has to be a better way. I tried to use a variable inside the brackets but I can't get that to work. Can anyone think of a way to do this with less code? Thanks! import os dirs = filter(os.path.isdir, os.listdir('')) for dir in dirs: # Left side if num == '1' and side == "l": code = dir[1:] if num == '2' and side == "l": code = dir[2:] if num == '3' and side == "l": code = dir[3:] if num == '4' and side == "l": code = dir[4:] if num == '5' and side == "l": code = dir[5:] if num == '6' and side == "l": code = dir[6:] if num == '7' and side == "l": code = dir[7:] if num == '8' and side == "l": code = dir[8:] if num == '9' and side == "l": code = dir[9:] if num == '10' and side == "l": code = dir[10:] # Right side if num == '1' and side == "r": code = dir[:-1] if num == '2' and side == "r": code = dir[:-2] if num == '3' and side == "r": code = dir[:-3] if num == '4' and side == "r": code = dir[:-4] if num == '5' and side == "r": code = dir[:-5] if num == '6' and side == "r": code = dir[:-6] if num == '7' and side == "r": code = dir[:-7] if num == '8' and side == "r": code = dir[:-8] if num == '9' and side == "r": code = dir[:-9] if num == '10' and side == "r": code = dir[:-10] print " Renaming "+dir+" to "+code os.rename(dir, code) From benjamin.kaplan at case.edu Thu Sep 16 15:47:49 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 16 Sep 2010 15:47:49 -0400 Subject: Too much code - slicing In-Reply-To: References: Message-ID: On Thu, Sep 16, 2010 at 3:35 PM, DataSmash wrote: > I need to create a simple utility to remove characters from either the > right or left side of directories. > This works, but there has to be a better way. ?I tried to use a > variable inside the brackets but I can't get > that to work. ?Can anyone think of a way to do this with less code? > Thanks! > > import os > > dirs = filter(os.path.isdir, os.listdir('')) > for dir in dirs: > > ? ?# Left side The int() type will convert a string to an int for you. So all you need to do is check the side and slice accordingly. if side=='l': code = dir[int(num):] else : code = dir[:-1*int(num)] From andrei.avk at gmail.com Thu Sep 16 16:20:33 2010 From: andrei.avk at gmail.com (AK) Date: Thu, 16 Sep 2010 16:20:33 -0400 Subject: Too much code - slicing In-Reply-To: References: Message-ID: <4C927C11.8050805@gmail.com> On 09/16/2010 03:47 PM, Benjamin Kaplan wrote: > On Thu, Sep 16, 2010 at 3:35 PM, DataSmash wrote: >> I need to create a simple utility to remove characters from either the >> right or left side of directories. >> This works, but there has to be a better way. I tried to use a >> variable inside the brackets but I can't get >> that to work. Can anyone think of a way to do this with less code? >> Thanks! >> >> import os >> >> dirs = filter(os.path.isdir, os.listdir('')) >> for dir in dirs: >> >> # Left side > > > The int() type will convert a string to an int for you. So all you > need to do is check the side and slice accordingly. > > if side=='l': > code = dir[int(num):] > else : > code = dir[:-1*int(num)] I also like this construct that works, I think, since 2.6: code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] -ak From rdh at new.rr.com Thu Sep 16 16:40:14 2010 From: rdh at new.rr.com (DataSmash) Date: Thu, 16 Sep 2010 13:40:14 -0700 (PDT) Subject: Too much code - slicing References: Message-ID: <74f71197-f6a7-42ab-93e6-7af1de8e646f@j2g2000vbo.googlegroups.com> On Sep 16, 2:47?pm, Benjamin Kaplan wrote: > On Thu, Sep 16, 2010 at 3:35 PM, DataSmash wrote: > > I need to create a simple utility to remove characters from either the > > right or left side of directories. > > This works, but there has to be a better way. ?I tried to use a > > variable inside the brackets but I can't get > > that to work. ?Can anyone think of a way to do this with less code? > > Thanks! > > > import os > > > dirs = filter(os.path.isdir, os.listdir('')) > > for dir in dirs: > > > ? ?# Left side > > > > The int() type will convert a string to an int for you. So all you > need to do is check the side and slice accordingly. > > if side=='l': > ? ? code = dir[int(num):] > else : > ? ? code = dir[:-1*int(num)] Much appreciated! I thought I tried every combination, guess I didn't try this as it works great. Thanks again. From b.f.lundin at gmail.com Thu Sep 16 17:40:25 2010 From: b.f.lundin at gmail.com (=?ISO-8859-1?Q?bj=F6rn_lundin?=) Date: Thu, 16 Sep 2010 14:40:25 -0700 (PDT) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: <9e71eee4-ccfa-439f-905b-47351ef06197@e20g2000vbn.googlegroups.com> > Where line 75 contains following: > s.bind((host, port)) As Tomas pointed out, you close conn, but you do not close the server socket 's' /Bj?rn From nagle at animats.com Thu Sep 16 17:46:45 2010 From: nagle at animats.com (John Nagle) Date: Thu, 16 Sep 2010 14:46:45 -0700 Subject: The trouble with "dynamic attributes". In-Reply-To: References: Message-ID: <4c929052$0$1601$742ec2ed@news.sonic.net> There's a tendency to use "dynamic attributes" in Python when trying to encapsulate objects from other systems. It almost works. But it's usually a headache in the end, and should be discouraged. Here's why. Some parsers, like BeautifulSoup, try to encapsulate HTML tag fields as Python attributes. This gives trouble for several reasons. First, the syntax for Python attributes and Python tags is different. Some strings won't convert to attributes. You can crash BeautifulSoup (which is supposed to be robust against bad HTML) by using a non-ASCII character in a tag in an HTML document it is parsing. Then there's the reserved word problem. "class" is a valid field name in HTML, and a reserved word in Python. So there has to be a workaround for reserved words. There's also the problem that user-created attributes go into the same namespace as other object attributes. This creates a vulnerability comparable to MySQL injection. If an attacker controls the input being parsed, they may be able to induce a store into something they shouldn't be able to access. This problem shows up again in "suds", the module for writing SOAP RPC clients. This module tries to use attributes for XML structures, and it almost works. It tends to founder when the XML data model has strings that aren't valid attributes. ("-" appears frequently in XML fields, but is not valid in an attribute name.) Using a dictionary, or inheriting an object from "dict", doesn't create these problems. The data items live in their own dictionary, and can't clash with anything else. Of course, you have to write tag['a'] instead of tag.a but then, at least you know what to do when you need tag['class'] "suds", incidentally, tries to do both. They accept both item.fieldname and item['fieldname'] But they are faking a dictionary, and it doesn't quite work right. 'fieldname' in item works correctly, but the form to get None when the field is missing, item.get('fieldname',None) isn't implemented. Much of the code that uses objects as dictionaries either predates the days when you couldn't inherit from "dict", or was written by Javascript programmers. (In Javascript, an object and a dictionary are the same thing. In Python, they're not.) In new code, it's better to inherit from "dict". It eliminates the special cases. John Nagle From prologic at shortcircuit.net.au Thu Sep 16 18:06:03 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 08:06:03 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c929052$0$1601$742ec2ed@news.sonic.net> References: <4c929052$0$1601$742ec2ed@news.sonic.net> Message-ID: On Fri, Sep 17, 2010 at 7:46 AM, John Nagle wrote: > There's a tendency to use "dynamic attributes" in Python when > trying to encapsulate objects from other systems. ?It almost > works. ?But it's usually a headache in the end, and should be > discouraged. ?Here's why. What do you mean by "dynamic attributes " ? Can you show a simple code example ? cheers James -- -- James Mills -- -- "Problems are solved by method" From vlastimil.brom at gmail.com Thu Sep 16 18:11:25 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 17 Sep 2010 00:11:25 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) Message-ID: Hi all, I'd like to ask for suggestions regarding suitable datastracture for storing textual metadata along with a plain text string. The input format I have is simply text with custom tags like ; I'd prefer to have this human readable format the original data source. For the application, the tags are extracted and stored in a custom datastructure along with the plain text.The queries should either return the tagset for a given text position (index) or reversely the text indices for a given tag-value combination.. (I posted some more detailed remarks earlier, as I was beginning with this topic http://mail.python.org/pipermail/python-list/2007-December/1130275.html http://mail.python.org/pipermail/python-list/2008-May/1141958.html Meanwhile I managed to get working code using python native datastructures (nested defaultdicts and sets); however after some time I am now planning to adapt this code for a web-based program and am considering alternative datastructures, for simplicity I started with sqlite (which should actually suffice for the data volume and traffic in question). I put together some code, which works as expected, but I suspect somehow, that there must be better ways of doing it. Two things I am not quite clear about are using the placeholders for the data identifiers and "chaining" the SELECT parameters. I Couldn't find a way to use "?" placeholder for table or column names, hence I ended up using string interpolation for them and placeholders for the data values, like. curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, index_col), (text_index,)) is there a better way or is it not supposed to supply these identifiers programatically? For getting the matching text indices given the tags, tag_values combination I ended up with a clumsy query: combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % (index_col, text_name, tag) for tag in tags] sql_query = " INTERSECT ".join(combined_query_list) curs.execute(sql_query, tag_values) which produces e.g.: SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" WHERE "VN"==? or alternatively: select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) sql_query = select_begin + where_subquery with the resulting query string like: SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') (BTW, are these queries equivalent, as the outputs suggest, or are there some distinctions to be aware of?) Anyway, I can't really believe, this would be the expected way ... (I only marginally looked into sqlalchemy, which might simplify this a bit, is this true? - Currently I only use the standard lib, depending on the available server setup (python 2.6)). Thanks in advance for any suggestions or pointers on both the sql usage as well as the general datatype question. regards, Vlastimil Brom From david at boddie.org.uk Thu Sep 16 18:23:26 2010 From: david at boddie.org.uk (David Boddie) Date: Fri, 17 Sep 2010 00:23:26 +0200 Subject: Deleting widgets from PyQt4 QFormWidget References: Message-ID: On Wednesday 15 September 2010 18:53, Andrew wrote: > I'm trying to remove the widgets from the QFormLayout widget from > PyQt4. According to the documentation I should be able to use the > command .takeAt(int) which will delete the widget from the layout and > then return to me the QLayoutWidget. It will remove the widget from the layout but it won't delete it because it doesn't own it. The widget will still remain within its parent widget. You have to either reparent it to another widget, or delete it manually. [...] > Am I missing a step or is this just broken? I haven't been able to > find anything else on this issue yet. If it's broke, is there any > potential workaround? Try calling deleteLater() on each widget when you take it from the layout. Does that work? David From python at mrabarnett.plus.com Thu Sep 16 19:17:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 00:17:24 +0100 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: Message-ID: <4C92A584.8060303@mrabarnett.plus.com> On 16/09/2010 23:11, Vlastimil Brom wrote: > Hi all, > I'd like to ask for suggestions regarding suitable datastracture for > storing textual metadata along with a plain text string. > The input format I have is simply text with custom tags like tag_value>; I'd prefer to have this human readable format the original > data source. > For the application, the tags are extracted and stored in a custom > datastructure along with the plain text.The queries should either > return the tagset for a given text position (index) or reversely the > text indices for a given tag-value combination.. > (I posted some more detailed remarks earlier, as I was beginning with this topic > http://mail.python.org/pipermail/python-list/2007-December/1130275.html > http://mail.python.org/pipermail/python-list/2008-May/1141958.html > > Meanwhile I managed to get working code using python native > datastructures (nested defaultdicts and sets); however after some time > I am now planning to adapt this code for a web-based program and am > considering alternative datastructures, for simplicity I started with > sqlite (which should actually suffice for the data volume and traffic > in question). > > I put together some code, which works as expected, but I suspect > somehow, that there must be better ways of doing it. > > Two things I am not quite clear about are using the placeholders for > the data identifiers and "chaining" the SELECT parameters. > > I Couldn't find a way to use "?" placeholder for table or column > names, hence I ended up using string interpolation for them and > placeholders for the data values, like. > curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, > index_col), (text_index,)) > is there a better way or is it not supposed to supply these > identifiers programatically? > You would normally expect the structure of the database to be fixed and only the contents to vary. > For getting the matching text indices given the tags, tag_values > combination I ended up with a clumsy query: > > combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % > (index_col, text_name, tag) for tag in tags] > sql_query = " INTERSECT ".join(combined_query_list) > curs.execute(sql_query, tag_values) > > which produces e.g.: > SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" > WHERE "VN"==? > > or alternatively: > > select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) > where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) > sql_query = select_begin + where_subquery > > with the resulting query string like: > SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') > > (BTW, are these queries equivalent, as the outputs suggest, or are > there some distinctions to be aware of?) > > Anyway, I can't really believe, this would be the expected way ... > If you're selecting rows of a table then using 'AND' would seem the obvious way. > (I only marginally looked into sqlalchemy, which might simplify this a > bit, is this true? - Currently I only use the standard lib, depending > on the available server setup (python 2.6)). > > Thanks in advance for any suggestions or pointers on both the sql > usage as well as the general datatype question. > > regards, > Vlastimil Brom From python at mrabarnett.plus.com Thu Sep 16 19:27:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 00:27:08 +0100 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c929052$0$1601$742ec2ed@news.sonic.net> References: <4c929052$0$1601$742ec2ed@news.sonic.net> Message-ID: <4C92A7CC.8000505@mrabarnett.plus.com> On 16/09/2010 22:46, John Nagle wrote: > There's a tendency to use "dynamic attributes" in Python when > trying to encapsulate objects from other systems. It almost > works. But it's usually a headache in the end, and should be > discouraged. Here's why. > > Some parsers, like BeautifulSoup, try to encapsulate HTML tag > fields as Python attributes. This gives trouble for several reasons. > First, the syntax for Python attributes and Python tags is different. > Some strings won't convert to attributes. You can crash BeautifulSoup > (which is supposed to be robust against bad HTML) by using a non-ASCII > character in a tag in an HTML document it is parsing. > > Then there's the reserved word problem. "class" is a valid field > name in HTML, and a reserved word in Python. So there has to be a > workaround for reserved words. > > There's also the problem that user-created attributes go into the > same namespace as other object attributes. This creates a vulnerability > comparable to MySQL injection. If an attacker controls the input > being parsed, they may be able to induce a store into something > they shouldn't be able to access. > > This problem shows up again in "suds", the module for writing > SOAP RPC clients. This module tries to use attributes for > XML structures, and it almost works. It tends to founder when > the XML data model has strings that aren't valid attributes. > ("-" appears frequently in XML fields, but is not valid in an > attribute name.) > > Using a dictionary, or inheriting an object from "dict", doesn't > create these problems. The data items live in their own dictionary, > and can't clash with anything else. Of course, you have to write > > tag['a'] > > instead of > > tag.a > > but then, at least you know what to do when you need > > tag['class'] > > "suds", incidentally, tries to do both. They accept both > > item.fieldname > > and > > item['fieldname'] > > But they are faking a dictionary, and it doesn't quite work right. > > 'fieldname' in item > > works correctly, but the form to get None when the field is missing, > > item.get('fieldname',None) > > isn't implemented. > > Much of the code that uses objects as dictionaries either predates > the days when you couldn't inherit from "dict", or was written by > Javascript programmers. (In Javascript, an object and a dictionary > are the same thing. In Python, they're not.) In new code, it's > better to inherit from "dict". It eliminates the special cases. > For the work on updating the re module there was a discussion about whether named capture groups should be available as attributes of the match object or via subscripting (or both?). Subscripting seemed preferable to me because: 1. Adding attributes looks too much like 'magic'. 2. What should happen if a group name conflicts with a normal attribute? 3. What should happen if a group name conflicts with a reserved word? For those reasons the new regex module uses subscripting. It's more Pythonic, IMHO. From prologic at shortcircuit.net.au Thu Sep 16 19:36:15 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 09:36:15 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <4C92A7CC.8000505@mrabarnett.plus.com> References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4C92A7CC.8000505@mrabarnett.plus.com> Message-ID: On Fri, Sep 17, 2010 at 9:27 AM, MRAB wrote: > For the work on updating the re module there was a discussion about > whether named capture groups should be available as attributes of the > match object or via subscripting (or both?). Subscripting seemed > preferable to me because: > > 1. Adding attributes looks too much like 'magic'. > > 2. What should happen if a group name conflicts with a normal attribute? > > 3. What should happen if a group name conflicts with a reserved word? > > For those reasons the new regex module uses subscripting. It's more > Pythonic, IMHO. I agree with 2) and 3) and in general this is probably a "good approach". cheers James -- -- James Mills -- -- "Problems are solved by method" From jeanluc434 at gmail.com Thu Sep 16 19:36:55 2010 From: jeanluc434 at gmail.com (Jean Luc Truchtersheim) Date: Thu, 16 Sep 2010 16:36:55 -0700 (PDT) Subject: File read from stdin and printed to temp file are not identicial? Message-ID: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Hello, I am trying to read from stdin and dump what's read to a temporary file. My code works for small files but as soon as I have a file that has, e.g., more than 300 lines, there is always one and only one line that is truncated compared to the input. Here is my code: #--------------------------------------------------------------------------------- #! /usr/bin/env python import sys from tempfile import * if __name__ == "__main__": data = [] f_in = NamedTemporaryFile(suffix=".txt", delete=False) for line in sys.stdin: f_in.write(line) data.append(line) f_in.close f = open(f_in.name, 'rb') i=0 for line in f: if data[i] != line: print >>sys.stderr, "line %d:\nfile(%d):\"%s\"\narray(%d):\"%s\"" % (i+1, len(line), line, len(data[i]), data[i]) i += 1 sys.exit() #------------------------------------------------------------------------------------------------- I feel that I must be doing something very stupid, but I don't really know what. Any idea? Can anybody reproduce this behavior. Thanks a bunch for any help. Jean Luc. From vlastimil.brom at gmail.com Thu Sep 16 19:56:49 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 17 Sep 2010 01:56:49 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: <4C92A584.8060303@mrabarnett.plus.com> References: <4C92A584.8060303@mrabarnett.plus.com> Message-ID: 2010/9/17 MRAB : > On 16/09/2010 23:11, Vlastimil Brom wrote: >> >>... >> I put together some code, which works as expected, but I suspect >> somehow, that there must be better ways of doing it. >> >> Two things I am not quite clear about are using the placeholders for >> the data identifiers and "chaining" the SELECT parameters. >> >> I Couldn't find a way to use "?" placeholder for table or column >> names, hence I ended up using string interpolation for them and >> placeholders for the data values, like. >> curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, >> index_col), (text_index,)) >> is there a better way or is it not supposed to supply these >> identifiers programatically? >> > You would normally expect the structure of the database to be fixed and > only the contents to vary. > >> For getting the matching text indices given the tags, tag_values >> combination I ended up with a clumsy query: >> >> combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % >> (index_col, text_name, tag) for tag in tags] >> sql_query = " INTERSECT ".join(combined_query_list) >> curs.execute(sql_query, tag_values) >> >> which produces e.g.: >> SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" >> WHERE "VN"==? >> >> or alternatively: >> >> select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) >> where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) >> sql_query = select_begin + where_subquery >> >> with the resulting query string like: >> SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') >> >> (BTW, are these queries equivalent, as the outputs suggest, or are >> there some distinctions to be aware of?) >> >> Anyway, I can't really believe, this would be the expected way ... >> > If you're selecting rows of a table then using 'AND' would seem the > obvious way. > > Thanks for the answer, Well, that may be a part of the problem, the database structure is going to be fixed once I'll have the text sources complete, but I was trying to keep it more general, also allowing the identifiers to be passed programmatically (based on the tagged text in question). yes, I am just selecting rows - based on the combination of the column values (which, I guess, might be an usual database approach(?). However, I was unsure, whether it is usual to construct the query string this way - partly using string interpolation or sequence joining. Or should there normally be no need for construct like the above and I am doing something wrong in a more general sense? Thanks again, Vlastimil Brom From jason.swails at gmail.com Thu Sep 16 19:57:09 2010 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 16 Sep 2010 19:57:09 -0400 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Message-ID: On Thu, Sep 16, 2010 at 7:36 PM, Jean Luc Truchtersheim < jeanluc434 at gmail.com> wrote: > Hello, > > I am trying to read from stdin and dump what's read to a temporary > file. My code works for small files but as soon as I have a file that > has, e.g., more than 300 lines, there is always one and only one line > that is truncated compared to the input. > > Here is my code: > > #--------------------------------------------------------------------------------- > #! /usr/bin/env python > > import sys > from tempfile import * > > if __name__ == "__main__": > data = [] > f_in = NamedTemporaryFile(suffix=".txt", delete=False) > for line in sys.stdin: > f_in.write(line) > data.append(line) > f_in.close > Does this need to be f_in.close() ? > f = open(f_in.name, 'rb') > i=0 > for line in f: > if data[i] != line: > print >>sys.stderr, "line > %d:\nfile(%d):\"%s\"\narray(%d):\"%s\"" % > (i+1, len(line), line, len(data[i]), data[i]) > i += 1 > sys.exit() > > #------------------------------------------------------------------------------------------------- > > I feel that I must be doing something very stupid, but I don't really > know what. > > Any idea? > > Can anybody reproduce this behavior. > > Thanks a bunch for any help. > > Jean Luc. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Sep 16 20:06:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 01:06:08 +0100 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Message-ID: <4C92B0F0.3010600@mrabarnett.plus.com> On 17/09/2010 00:36, Jean Luc Truchtersheim wrote: > Hello, > > I am trying to read from stdin and dump what's read to a temporary > file. My code works for small files but as soon as I have a file that > has, e.g., more than 300 lines, there is always one and only one line > that is truncated compared to the input. > > Here is my code: > #--------------------------------------------------------------------------------- > #! /usr/bin/env python > > import sys > from tempfile import * > > if __name__ == "__main__": > data = [] > f_in = NamedTemporaryFile(suffix=".txt", delete=False) > for line in sys.stdin: > f_in.write(line) > data.append(line) > f_in.close > f = open(f_in.name, 'rb') > i=0 > for line in f: > if data[i] != line: > print>>sys.stderr, "line %d:\nfile(%d):\"%s\"\narray(%d):\"%s\"" % > (i+1, len(line), line, len(data[i]), data[i]) > i += 1 > sys.exit() > #------------------------------------------------------------------------------------------------- > > I feel that I must be doing something very stupid, but I don't really > know what. > > Any idea? > > Can anybody reproduce this behavior. > > Thanks a bunch for any help. > > Jean Luc. You're not closing f_in. That line should be: f_in.close() From prologic at shortcircuit.net.au Thu Sep 16 20:08:03 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 10:08:03 +1000 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Message-ID: On Fri, Sep 17, 2010 at 9:36 AM, Jean Luc Truchtersheim wrote: > Can anybody reproduce this behavior. Jean it would help if you could provide samples of your input and output files. I'm pretty sure I might have a clue as to what your problem might be, but I can't be sure until I see the input and resulting output files. cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Thu Sep 16 20:10:34 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 10:10:34 +1000 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <4C92B0F0.3010600@mrabarnett.plus.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> <4C92B0F0.3010600@mrabarnett.plus.com> Message-ID: On Fri, Sep 17, 2010 at 10:06 AM, MRAB wrote: > You're not closing f_in. That line should be: Although this _could_ be the problem (buffers not being flushed and the file being properly closed, etc) it could be something else... --James -- -- James Mills -- -- "Problems are solved by method" From python at mrabarnett.plus.com Thu Sep 16 20:18:04 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 01:18:04 +0100 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: <4C92A584.8060303@mrabarnett.plus.com> Message-ID: <4C92B3BC.6090901@mrabarnett.plus.com> On 17/09/2010 00:56, Vlastimil Brom wrote: > 2010/9/17 MRAB: >> On 16/09/2010 23:11, Vlastimil Brom wrote: >>> >>> ... >>> I put together some code, which works as expected, but I suspect >>> somehow, that there must be better ways of doing it. >>> >>> Two things I am not quite clear about are using the placeholders for >>> the data identifiers and "chaining" the SELECT parameters. >>> >>> I Couldn't find a way to use "?" placeholder for table or column >>> names, hence I ended up using string interpolation for them and >>> placeholders for the data values, like. >>> curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, >>> index_col), (text_index,)) >>> is there a better way or is it not supposed to supply these >>> identifiers programatically? >>> >> You would normally expect the structure of the database to be fixed and >> only the contents to vary. >> >>> For getting the matching text indices given the tags, tag_values >>> combination I ended up with a clumsy query: >>> >>> combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % >>> (index_col, text_name, tag) for tag in tags] >>> sql_query = " INTERSECT ".join(combined_query_list) >>> curs.execute(sql_query, tag_values) >>> >>> which produces e.g.: >>> SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" >>> WHERE "VN"==? >>> >>> or alternatively: >>> >>> select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) >>> where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) >>> sql_query = select_begin + where_subquery >>> >>> with the resulting query string like: >>> SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') >>> >>> (BTW, are these queries equivalent, as the outputs suggest, or are >>> there some distinctions to be aware of?) >>> >>> Anyway, I can't really believe, this would be the expected way ... >>> >> If you're selecting rows of a table then using 'AND' would seem the >> obvious way. >> >> > Thanks for the answer, > Well, that may be a part of the problem, the database structure is > going to be fixed once I'll have the text sources complete, but I was > trying to keep it more general, also allowing the identifiers to be > passed programmatically (based on the tagged text in question). > > yes, I am just selecting rows - based on the combination of the column > values (which, I guess, might be an usual database approach(?). > However, I was unsure, whether it is usual to construct the query > string this way - partly using string interpolation or sequence > joining. > Or should there normally be no need for construct like the above and I > am doing something wrong in a more general sense? > In general you'd have a fixed database structure and fixed queries. You'd design it so that you wouldn't have different columns for different tagged texts, forcing you to change the database structure when texts were added or removed, but no-one will come around to your house to stop you creating queries dynamically. :-) From jeanluc434 at gmail.com Thu Sep 16 20:25:54 2010 From: jeanluc434 at gmail.com (Jean Luc Truchtersheim) Date: Thu, 16 Sep 2010 17:25:54 -0700 (PDT) Subject: File read from stdin and printed to temp file are not identicial? References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> Message-ID: <03679b87-ab47-4316-a755-176d2fce07de@v23g2000vbi.googlegroups.com> Dear Fellow python users, Many thanks for your help. Those missing brackets were the cause of my problem. Now my program works as expected. Many, many heartfelt thanks. From prologic at shortcircuit.net.au Thu Sep 16 20:35:40 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 10:35:40 +1000 Subject: File read from stdin and printed to temp file are not identicial? In-Reply-To: <03679b87-ab47-4316-a755-176d2fce07de@v23g2000vbi.googlegroups.com> References: <24b5cb21-56e6-4d13-ae92-7aee57dbf44e@t11g2000vbc.googlegroups.com> <03679b87-ab47-4316-a755-176d2fce07de@v23g2000vbi.googlegroups.com> Message-ID: On Fri, Sep 17, 2010 at 10:25 AM, Jean Luc Truchtersheim wrote: > Dear Fellow python users, > > Many thanks for your help. > > Those missing brackets were the cause of my problem. > > Now my program works as expected. > > Many, many heartfelt thanks. Glad to hear it! Do you understand why ? cheers James -- -- James Mills -- -- "Problems are solved by method" From googler.1.webmaster at spamgourmet.com Thu Sep 16 21:33:27 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 16 Sep 2010 18:33:27 -0700 (PDT) Subject: The trouble with "dynamic attributes". References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4C92A7CC.8000505@mrabarnett.plus.com> Message-ID: <2e749113-5c9f-475e-85e5-f6c787559572@a30g2000vbt.googlegroups.com> I am really sorry, but what are you talking about ? Hmmm, ...I have problems to compile Python on SL, I did not ask anything about "dynamic attribute". I don't get it... From ldo at geek-central.gen.new_zealand Thu Sep 16 21:47:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 17 Sep 2010 13:47:22 +1200 Subject: WMI in Python References: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> Message-ID: In message <257b2d99-03d4-491b-8f8b-dccd2bc102a7 at p22g2000pre.googlegroups.com>, alex23 wrote: > Lawrence D'Oliveiro wrote: > >> Why not just call Scriptomatic directly from within the Python script, >> then? > > Because Scriptomatic _generates scripts to access WMI_, that's what it > _does_. Precisely why I suggested running it on the fly. Because machine-generated code has no place in a source file to be maintained by a human. > Are you _seriously_ advocating writing Python code to fire up > a Windows application, programmatically manipulating a GUI to generate > more Python code for your original script to import or exec? If that?s the only way you can use Scriptomatic, then the stupidity lies with the one who suggested using such a brain-dead tool in the first place. > As you've made your disdain for Windows _perfectly_ clear through your > incessant sniping on this list, I think I'm pretty safe in saying you > have no idea of the quality of Scriptomatic's output. The quality of the output is not at issue here. The point is that it is machine-generated from an input command, therefore it makes sense from a maintenance viewpoint to keep the input command, not the machine-generated output, in the source file, and simply generate the latter from the former as part of the build process. Unfortunately, as you have made abundantly clear above, Scriptomatic is a GUI-only tool, totally unsuited to this sort of use. From prologic at shortcircuit.net.au Thu Sep 16 22:12:28 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 17 Sep 2010 12:12:28 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <2e749113-5c9f-475e-85e5-f6c787559572@a30g2000vbt.googlegroups.com> References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4C92A7CC.8000505@mrabarnett.plus.com> <2e749113-5c9f-475e-85e5-f6c787559572@a30g2000vbt.googlegroups.com> Message-ID: On Fri, Sep 17, 2010 at 11:33 AM, moerchendiser2k3 wrote: > I am really sorry, but what are you talking about ? Hmmm, ...I have > problems to compile Python on SL, I did not ask anything about > "dynamic attribute". I don't get it... You are subscribed to the python mailing list. Check your subscription status with the link below. cheers James -- -- James Mills -- -- "Problems are solved by method" From nobody at nowhere.com Thu Sep 16 22:17:50 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 17 Sep 2010 03:17:50 +0100 Subject: os.path.normcase rationale? References: Message-ID: On Wed, 15 Sep 2010 14:49:09 +0100, Chris Withers wrote: > I'm curious as to why, with a file called "Foo.txt" > os.path.normcase('FoO.txt') will return "foo.txt" rather than "Foo.txt"? normcase() doesn't look at the filesystem; it's just string manipulation. From nobody at nowhere.com Thu Sep 16 22:35:41 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 17 Sep 2010 03:35:41 +0100 Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: On Thu, 16 Sep 2010 07:12:16 +1000, Ben Finney wrote: >> Yes, I know the behaviour is documented > > The docstring is fairly poor, IMO. You might want to submit a bug report > to improve it. The description in the library documentation is misleading: os.path.normcase(path) Normalize the case of a pathname. On Unix and Mac OS X, this returns the path unchanged; on case-insensitive filesystems, it converts the path to lowercase. On Windows, it also converts forward slashes to backward slashes. It implies that the behaviour depends upon the actual filesystem, which isn't the case. It only depends upon the platform, i.e. it assumes that all filenames are case-sensitive on Unix systems and case-insensitive on Windows. But Unix systems can access FAT/SMBFS/etc filesystems which are case-insensitive. From tjreedy at udel.edu Thu Sep 16 22:41:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Sep 2010 22:41:42 -0400 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c929052$0$1601$742ec2ed@news.sonic.net> References: <4c929052$0$1601$742ec2ed@news.sonic.net> Message-ID: On 9/16/2010 5:46 PM, John Nagle wrote: By mistakenly posted this as a response to "compile Py2.6 on SL", you 1) confused the OP and 2) limited it audience -- I agree with your points, but would have missed this if I had had threads collapsed, as I usually do, since I have no interest in 2.6 compilation. -- Terry Jan Reedy From tjreedy at udel.edu Thu Sep 16 22:48:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Sep 2010 22:48:21 -0400 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: On 9/16/2010 12:23 PM, J wrote: > Thanks for the replies... I KNEW there was a simple way to escape the > % but I had no idea what it was (I just had conviction). > > I was thrown when the \ didn't escape it... never knew about %%. But > now I do! Thanks for the replies! Doubling an escape char, whatever it is, is a common convention: >>> print("Print a {{}} format string line this: {{{}}}".format(2)) Print a {} format string line this: {2} -- Terry Jan Reedy From cs at zip.com.au Fri Sep 17 00:38:26 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 17 Sep 2010 14:38:26 +1000 Subject: Too many threads In-Reply-To: <716be5f9-79b9-43c7-9c04-0454d015086d@j30g2000vbr.googlegroups.com> References: <716be5f9-79b9-43c7-9c04-0454d015086d@j30g2000vbr.googlegroups.com> Message-ID: <20100917043826.GA21464@cskk.homeip.net> On 16Sep2010 09:55, mark.pelletier at asrcms.com wrote: | For some reason, the tasks I put into my thread pool occasionally get | run more than once. | | Here's the code: You need to post your _exact_ code. I had to change: from queue import Queue into from Queue import Queue So: _do_ you have a "queue" (lowercase) module? Is it buggy? Let's pretend not. Using the standard Queue module I can't reproduce your problem and your code looks correct to my eye. However, it is possible that the output stream used by print() is not thread safe. In which case your multiple outputs may stem from output buffer mishandling and not from your thread pool. Make another Queue to receice items, change _worker() to .put(item) onto it and collect form the queue and print in the program's main code. That way only one thread (the main one) will be trying to print(), removing the possibility of mismanagement of the output if print() is not thread safe. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Rules of Optimization: Rule 1: Don't do it. Rule 2 (for experts only): Don't do it yet. - M.A. Jackson From nad at acm.org Fri Sep 17 01:14:46 2010 From: nad at acm.org (Ned Deily) Date: Thu, 16 Sep 2010 22:14:46 -0700 Subject: Too many threads References: <716be5f9-79b9-43c7-9c04-0454d015086d@j30g2000vbr.googlegroups.com> <20100917043826.GA21464@cskk.homeip.net> Message-ID: In article <20100917043826.GA21464 at cskk.homeip.net>, Cameron Simpson wrote: > On 16Sep2010 09:55, mark.pelletier at asrcms.com > wrote: > | For some reason, the tasks I put into my thread pool occasionally get > | run more than once. > | > | Here's the code: > > You need to post your _exact_ code. I had to change: > from queue import Queue > into > from Queue import Queue > So: _do_ you have a "queue" (lowercase) module? Is it buggy? The OP is probably using Python 3. -- Ned Deily, nad at acm.org From cs at zip.com.au Fri Sep 17 01:22:59 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 17 Sep 2010 15:22:59 +1000 Subject: Too many threads In-Reply-To: References: Message-ID: <20100917052259.GA28454@cskk.homeip.net> On 16Sep2010 22:14, Ned Deily wrote: | In article <20100917043826.GA21464 at cskk.homeip.net>, | Cameron Simpson wrote: | | > On 16Sep2010 09:55, mark.pelletier at asrcms.com | > wrote: | > | For some reason, the tasks I put into my thread pool occasionally get | > | run more than once. | > | | > | Here's the code: | > | > You need to post your _exact_ code. I had to change: | > from queue import Queue | > into | > from Queue import Queue | > So: _do_ you have a "queue" (lowercase) module? Is it buggy? | | The OP is probably using Python 3. Ah, that explains the print(). Anyone know if print() is thread safe in python 3? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If I repent anything, it is very likely to be my good behavior. What demon possessed me that I behaved so well? - Henry David Thoreau From nad at acm.org Fri Sep 17 01:38:41 2010 From: nad at acm.org (Ned Deily) Date: Thu, 16 Sep 2010 22:38:41 -0700 Subject: Too many threads References: <20100917052259.GA28454@cskk.homeip.net> Message-ID: In article <20100917052259.GA28454 at cskk.homeip.net>, Cameron Simpson wrote: > On 16Sep2010 22:14, Ned Deily wrote: > | In article <20100917043826.GA21464 at cskk.homeip.net>, > | Cameron Simpson wrote: > | > | > On 16Sep2010 09:55, mark.pelletier at asrcms.com > | > wrote: > | > | For some reason, the tasks I put into my thread pool occasionally get > | > | run more than once. > | > | > | > | Here's the code: > | > > | > You need to post your _exact_ code. I had to change: > | > from queue import Queue > | > into > | > from Queue import Queue > | > So: _do_ you have a "queue" (lowercase) module? Is it buggy? > | > | The OP is probably using Python 3. > > Ah, that explains the print(). Anyone know if print() is thread safe in > python 3? I vaguely recalled a similar problem and, on the second try, found it: http://bugs.python.org/issue6750 Looks like that fix should have been in Python 3.1.2. -- Ned Deily, nad at acm.org From justin.mailinglists at gmail.com Fri Sep 17 02:59:43 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Thu, 16 Sep 2010 23:59:43 -0700 (PDT) Subject: SimpleHTTPServer, external CSS, and Google Chrome Message-ID: <057af264-995d-4e60-9887-d053b93bd988@m17g2000prl.googlegroups.com> I am running "python -m SimpleHTTPServer 80" on Windows XP Pro SP 3 (Python 2.5.4) browsing http://localhost/ using IE8 and FireFox 3.6, I get blue text on red background on Google Chrome 6.0 however, I get blue text on white background placing index.htm and styles.css (see below) under IIS, I get blue text on red background for all browsers, including Google Chrome 6.0. I get exactly the same results when browsing from another machine. what's wrong? what do I need to change in SimpleHTTPServer? index.htm -------------- your title

foo bar

-------------- styles.css -------------- body { background-color: red; } -------------- From vlastimil.brom at gmail.com Fri Sep 17 04:44:43 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 17 Sep 2010 10:44:43 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: <4C92B3BC.6090901@mrabarnett.plus.com> References: <4C92A584.8060303@mrabarnett.plus.com> <4C92B3BC.6090901@mrabarnett.plus.com> Message-ID: 2010/9/17 MRAB : > On 17/09/2010 00:56, Vlastimil Brom wrote: >> >> 2010/9/17 MRAB: >>> >>> On 16/09/2010 23:11, Vlastimil Brom wrote: >>>> >>>> ... >>>> I put together some code, which works as expected, but I suspect >>>> somehow, that there must be better ways of doing it. >>>> >>>> Two things I am not quite clear about are using the placeholders for >>>> the data identifiers and "chaining" the SELECT parameters. >>>> >>>> I Couldn't find a way to use "?" placeholder for table or column >>>> names, hence I ended up using string interpolation for them and >>>> placeholders for the data values, like. >>>> curs.execute('SELECT * FROM "%s" WHERE "%s"==?' % (text_name, >>>> index_col), (text_index,)) >>>> is there a better way or is it not supposed to supply these >>>> identifiers programatically? >>>> >>> You would normally expect the structure of the database to be fixed and >>> only the contents to vary. >>> >>>> For getting the matching text indices given the tags, tag_values >>>> combination I ended up with a clumsy query: >>>> >>>> combined_query_list = ['SELECT "%s" FROM "%s" WHERE "%s"==?' % >>>> (index_col, text_name, tag) for tag in tags] >>>> sql_query = " INTERSECT ".join(combined_query_list) >>>> curs.execute(sql_query, tag_values) >>>> >>>> which produces e.g.: >>>> SELECT "ind" FROM "n" WHERE "KC"==? INTERSECT SELECT "ind" FROM "n" >>>> WHERE "VN"==? >>>> >>>> or alternatively: >>>> >>>> select_begin = 'SELECT "%s" FROM "%s" WHERE ' % (index_col, text_name) >>>> where_subquery = " AND ".join('"%s"==?' % (tag,) for tag in tags) >>>> sql_query = select_begin + where_subquery >>>> >>>> with the resulting query string like: >>>> SELECT "ind" FROM "n" WHERE "KC"==? AND "VN"==? ('12', '1') >>>> >>>> (BTW, are these queries equivalent, as the outputs suggest, or are >>>> there some distinctions to be aware of?) >>>> >>>> Anyway, I can't really believe, this would be the expected way ... >>>> >>> If you're selecting rows of a table then using 'AND' would seem the >>> obvious way. >>> >>> >> Thanks for the answer, >> Well, that may be a part of the problem, the database structure is >> going to be fixed once I'll have the text sources complete, but I was >> trying to keep it more general, also allowing the identifiers to be >> passed programmatically (based on the tagged text in question). >> >> yes, I am just selecting rows - based on the combination of the column >> values (which, I guess, might be an usual database approach(?). >> However, I was unsure, whether it is usual to construct the query >> string this way - partly using string interpolation or sequence >> joining. >> Or should there normally be no need for construct like the above and I >> am doing something wrong in a more general sense? >> > In general you'd have a fixed database structure and fixed queries. > You'd design it so that you wouldn't have different columns for > different tagged texts, forcing you to change the database structure > when texts were added or removed, but no-one will come around to your > house to stop you creating queries dynamically. :-) > -- > http://mail.python.org/mailman/listinfo/python-list > Ok, thanks for confirming my suspicion :-), Now I have to decide whether I shall use my custom data structure, where I am on my own, or whether using an sql database in such a non-standard way has some advantages... The main problem indeed seems to be the fact, that I consider the tagged texts to be the primary storage format, whereas the database is only means for accessing it more conveniently. Thanks again, vbr From vgnulinux at gmail.com Fri Sep 17 05:31:39 2010 From: vgnulinux at gmail.com (VGNU Linux) Date: Fri, 17 Sep 2010 15:01:39 +0530 Subject: Embedded Systems development using Python In-Reply-To: References: Message-ID: Hi All, Appreciate your response. Now I am going to use Telit Module GE865-QUAD with support for GPS and GPRS capabilities. It also has built-in python interpreter for developing application for the module. But still I have no idea which microprocessor/microcontroller to use. Can anyone help me out here ? Is there any microprocessor/microcontroller which I could use with Python and Telit module? Any help here will be appreciated. Regards, VGNU On Mon, Sep 6, 2010 at 8:54 PM, Grant Edwards wrote: > On 2010-09-06, Stefan Behnel wrote: > > VGNU Linux, 06.09.2010 13:02: > >> Can Python be used for embedded systems development ? > > > > It can and has been. > > > > What kind of embedded system with what set of capabilities are you > thinking > > about? TV sets? Mobile phones? Smart dust? > > [The OP never showed up on my sever for some reason] > > If you google for "deeply embedded python", you'll find some raterh > old links: > > http://tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy > > http://groups.google.com/group/python-on-a-chip/web/list-of-small-python-implementations > > http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html > > A few years ago I used Python on a prototype for a bicycle computer > with GPS, four buttons, and a small LCD screen. It was more or less > comparable to a PDA with Linux running on an 200MHz XScale with > something like 16MB of flash and 32MB of SDRAM. > > IIRC, that project used OpenEmbedded, and all I had to do was build > the Python package that's already there in OE. I don't remember if I > was using PySDL or PyQt for the UI -- I remember experimenting with > both on desktop hosts at the time. > > I don't think that product ever saw daylight. There was just now way > they could have competed with Garmin. > > -- > Grant > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Fri Sep 17 05:36:43 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 17 Sep 2010 11:36:43 +0200 Subject: program organization question for web development with python In-Reply-To: <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> Message-ID: <4c933693$0$4439$426a34cc@news.free.fr> Hans a ?crit : (snip) > Maybe I did not make my question clear. I never tried python web > programing before, so I want to start from CGI. You can indeed learn quite a few things doing raw CGI - the most important one being why frameworks are a good idea !-) > I read something about web framework like django, but seems it's a > little bit complicated. Not that much IMHO, but being an early django user I'm probably a bit biased. Now Python is known as "the language with more web frameworks than keywords", so you could probably check some lighter framework like web.py (http://webpy.org/) or flask (http://flask.pocoo.org/). > my task is actually very simple: get search > string from input, and then search database, print search result. I > thought CGI should be good enough to do this. CGI is "good enough" to do any web stuff - just like assembler is "good enough" to write any application !-) > I don't have any idea about how to organize those cgi codes, so what > I'm asking is: > > 1. do I have to have each single file for each hyper-link? Can I put > them together? how? > > 2. how can I pass a db_cursor to another file? can I use db_cursor as > a parameter? Obviously not. FWIW, both questions show a lack of understanding of the HTTP protocol, and you can't hope to do anything good in web programming if you don't understand at least the basics of the HTTP protocol, specially the request/response cycle. Now for a couple more practical answers: There are basically two ways to organize your url => code mapping: 1/ have only one cgi script and use querystring params to tell which action should be executed. 2/ have one cgi script per action. The choice is up to you. For a simple app like yours, the first solution is probably the most obvious : always display the seach form, if the user submitted the form also display the result list. That's how google works (wrt/ user interface I mean). Now if you still need / want to have distinct scripts and want to factor out some common code, you just put the common code in a module that you import from each script. From steve at REMOVE-THIS-cybersource.com.au Fri Sep 17 06:55:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Sep 2010 10:55:44 GMT Subject: Very stupid question about a % symbol References: Message-ID: <4c934930$0$28657$c3e8da3@news.astraweb.com> On Thu, 16 Sep 2010 11:25:06 -0400, J wrote: > OK, this is a very stupid question about a very simple topic, but Google > is failing me this morning... [...] Others have already answered your question, but for future reference, many people won't bother to read posts with a meaningless subject line like "Very stupid question about ...". Very stupid questions invite very stupid answers. I guess you can be grateful that this Python group is more friendly than the average tech group, otherwise you might have got no answers at all, or a sarcastic one. Besides, your actual question isn't stupid at all. It is a sensible, although basic, question. A better subject line would have been: "How to insert percent sign in % format strings?" or some variation thereof. This will also be of benefit to others, who some day may be Googling for the answer to the same question. Regards, -- Steven From enleverLesX_XXmcX at XmclavXeauX.com.invalid Fri Sep 17 07:21:17 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 17 Sep 2010 13:21:17 +0200 Subject: compile Py2.6 on SL References: Message-ID: <4c934f3c$0$5417$ba4acef3@reader.news.orange.fr> Hello! SL (SilverLight) is a library/techno who give functions. You cannot compile Python on SL (SilverLight). @-salutations -- Michel Claveau From contact at xavierho.com Fri Sep 17 07:23:13 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 17 Sep 2010 21:23:13 +1000 Subject: Very stupid question about a % symbol In-Reply-To: References: Message-ID: On 17 September 2010 12:48, Terry Reedy wrote: > Doubling an escape char, whatever it is, is a common convention: > >>> print("Print a {{}} format string line this: {{{}}}".format(2)) > Print a {} format string line this: {2} > Wow. That's convoluted. Took me a minute to process. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Fri Sep 17 08:14:39 2010 From: jason.swails at gmail.com (Jason Swails) Date: Fri, 17 Sep 2010 08:14:39 -0400 Subject: compile Py2.6 on SL In-Reply-To: <4c934f3c$0$5417$ba4acef3@reader.news.orange.fr> References: <4c934f3c$0$5417$ba4acef3@reader.news.orange.fr> Message-ID: On Fri, Sep 17, 2010 at 7:21 AM, Michel Claveau - MVP wrote: > Hello! > > SL (SilverLight) is a library/techno who give functions. > You cannot compile Python on SL (SilverLight). > I think the original thread meant Snow Leopard (the latest Mac OS X) > > @-salutations > -- > Michel Claveau > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Sep 17 08:51:31 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 17 Sep 2010 08:51:31 -0400 Subject: MySQL Query Problem Message-ID: Hi; I have this code: cursor.execute('insert into Passengers values (Null, %s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, curr_sex, curr_weight, price, curr_rt, curr_confirmation)) Now, when I print it out, add quotes where necessary and enter it in at a mysql prompt, all goes well. But when I do it this way, it enters null values for curr_customer and curr_weight! Same darn thing printed out works at the prompt. What gives? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.pelletier at asrcms.com Fri Sep 17 09:25:47 2010 From: mark.pelletier at asrcms.com (mark.pelletier at asrcms.com) Date: Fri, 17 Sep 2010 06:25:47 -0700 (PDT) Subject: Too many threads References: <20100917052259.GA28454@cskk.homeip.net> Message-ID: <3ce61e43-75fd-4091-9dae-161d119fa9f5@e20g2000vbn.googlegroups.com> On Sep 17, 1:38?am, Ned Deily wrote: > In article <20100917052259.GA28... at cskk.homeip.net>, > ?Cameron Simpson wrote: > > > > > > > On 16Sep2010 22:14, Ned Deily wrote: > > | In article <20100917043826.GA21... at cskk.homeip.net>, > > | ?Cameron Simpson wrote: > > | > > | > On 16Sep2010 09:55, mark.pellet... at asrcms.com > > | > wrote: > > | > | For some reason, the tasks I put into my thread pool occasionally get > > | > | run more than once. > > | > | > > | > | Here's the code: > > | > > > | > You need to post your _exact_ code. I had to change: > > | > ? from queue import Queue > > | > into > > | > ? from Queue import Queue > > | > So: _do_ you have a "queue" (lowercase) module? Is it buggy? > > | > > | The OP is probably using Python 3. > > > Ah, that explains the print(). Anyone know if print() is thread safe in > > python 3? > > I vaguely recalled a similar problem and, on the second try, found it: > > http://bugs.python.org/issue6750 > > Looks like that fix should have been in Python 3.1.2. > > -- > ?Ned Deily, > ?n... at acm.org- Hide quoted text - > > - Show quoted text - I was a little surprised at my problems, as I cribbed the code from http://docs.python.org/py3k/library/queue.html?highlight=queue#queue.Queue.put But in the end, yeah it does look like a thread-safe problem with print. I tried replacing the print statement by using another queue, and it worked just fine. Glad to know that it's fixed in 3.1.2; of course, I am running 3.1.1. Doesn't matter, the print statement was just for demonstration purposes. I'm actually going to put a subprocess.getoutput() there. Wonder if that's thread safe? Thanks, Cameron and Ned From victorsubervi at gmail.com Fri Sep 17 09:26:48 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 17 Sep 2010 09:26:48 -0400 Subject: MySQL Query Problem In-Reply-To: References: Message-ID: Here's some more data: print 'insert into Passengers values (Null, %s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")' % (curr_flight, curr_customer, name, curr_sex, curr_weight, price, curr_rt, curr_confirmation) cursor.execute('insert into Passengers values (Null, %s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, curr_sex, curr_weight, price, curr_rt, curr_confirmation)) database.commit() cursor.execute('select last_insert_id() from Passengers') last_insert_id = cursor.fetchone()[0] print 'update Passengers set name=%s, weight=%s where id=%s' % (name, curr_weight, last_insert_id) cursor.execute('update Passengers set name=%s, weight=%s where id=%s', (name, curr_weight, last_insert_id)) database.commit() This prints out: insert into Passengers values (Null, 1, 1, Dr. Mengela, Male, 155, 100, 100, 654, "no", "n/a") update Passengers set name=Dr. Mengela, weight=155 where id=15 Here's what's in the database: mysql> select * from Passengers; +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ | id | flights_id | customer_id | name | sex | weight | price | round_trip | confirmation | late_fee | late_fee_paid | +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ | 1 | 1 | 1 | '' | NULL | NULL | 0.00 | 0 | 12345 | NULL | NULL | | 15 | 1 | 1 | '' | Male | NULL | 0.00 | 100 | 654 | no | n/a | +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ 2 rows in set (0.00 sec) mysql> describe Passengers; +---------------+-------------------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------------------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | flights_id | int(11) | NO | MUL | NULL | | | customer_id | int(11) | NO | MUL | NULL | | | name | varchar(40) | YES | | NULL | | | sex | enum('Male','Female') | YES | | NULL | | | weight | int(11) | YES | | NULL | | | price | float(6,2) | NO | | NULL | | | round_trip | tinyint(1) | NO | | 1 | | | confirmation | varchar(20) | YES | | NULL | | | late_fee | enum('no','yes') | YES | | no | | | late_fee_paid | enum('n/a','paid','not paid') | YES | | n/a | | +---------------+-------------------------------+------+-----+---------+----------------+ 11 rows in set (0.00 sec) and when I run the update: mysql> select * from Passengers; +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ | id | flights_id | customer_id | name | sex | weight | price | round_trip | confirmation | late_fee | late_fee_paid | +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ | 1 | 1 | 1 | '' | NULL | NULL | 0.00 | 0 | 12345 | NULL | NULL | | 15 | 1 | 1 | Dr. Mengela | Male | 155 | 0.00 | 100 | 654 | no | n/a | +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ 2 rows in set (0.00 sec) Please explain why it does that! TIA, beno On Fri, Sep 17, 2010 at 8:51 AM, Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('insert into Passengers values (Null, %s, %s, %s, > %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, > curr_sex, curr_weight, price, curr_rt, curr_confirmation)) > > Now, when I print it out, add quotes where necessary and enter it in at a > mysql prompt, all goes well. But when I do it this way, it enters null > values for curr_customer and curr_weight! Same darn thing printed out works > at the prompt. What gives? > TIA, > beno > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Fri Sep 17 10:32:36 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 17 Sep 2010 07:32:36 -0700 (PDT) Subject: WMI in Python References: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> Message-ID: <210f30c4-22da-405f-ad4b-cc46841ca686@p22g2000pre.googlegroups.com> Lawrence D'Oliveiro wrote: > Because machine-generated > code has no place in a source file to be maintained by a human. Endlessly repeating your bigotry doesn't make it any more true. From lo.maximo73 at gmail.com Fri Sep 17 10:56:19 2010 From: lo.maximo73 at gmail.com (ElMariachi) Date: Fri, 17 Sep 2010 07:56:19 -0700 (PDT) Subject: Compiling SWIG Extensions With VC2008 and VC2010 Both Installed Message-ID: <29739343.post@talk.nabble.com> I am attempting to compile a SWIG extension library for QuantLib (www.quantlib.org) on Windows 7 running Python 2.6. 2.6 needs VC2008 to compile extensions yet distutils cannot find this version, is there a way I can specify that this version be used? Currently, when I attempt a build, I get a lot of the following errors: python setup.py build running build running build_py running build_ext building 'QuantLib._QuantLib' extension C:\Python26\Scripts\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include -IC:\Python26\PC -c QuantLib/quantlib_wrap.cpp -o build QuantLib/quantlib_wrap.cpp:3423:26: ql/version.hpp: No such file or directory QuantLib/quantlib_wrap.cpp:3424: error: `QL_HEX_VERSION' was not declared in this scope QuantLib/quantlib_wrap.cpp:3425: error: `QL_VERSION' was not declared in this scope QuantLib/quantlib_wrap.cpp:3484:27: ql/quantlib.hpp: No such file or directory QuantLib/quantlib_wrap.cpp:3487:6: #error using an old version of QuantLib, please update QuantLib/quantlib_wrap.cpp:3874:48: boost/algorithm/string/case_conv.hpp: No such file or directory QuantLib/quantlib_wrap.cpp:3878: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3878: error: expected nested-name-specifier before "Error" QuantLib/quantlib_wrap.cpp:3878: error: `Error' has not been declared QuantLib/quantlib_wrap.cpp:3879: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3879: error: expected nested-name-specifier before "Handle" QuantLib/quantlib_wrap.cpp:3879: error: `Handle' has not been declared QuantLib/quantlib_wrap.cpp:3880: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3880: error: expected nested-name-specifier before "RelinkableHandle" QuantLib/quantlib_wrap.cpp:3880: error: `RelinkableHandle' has not been declared QuantLib/quantlib_wrap.cpp:3883: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3883: error: expected nested-name-specifier before "Integer" QuantLib/quantlib_wrap.cpp:3883: error: `Integer' has not been declared QuantLib/quantlib_wrap.cpp:3884: error: `QuantLib' has not been declared QuantLib/quantlib_wrap.cpp:3884: error: expected nested-name-specifier before "BigInteger" QuantLib/quantlib_wrap.cpp:3884: error: `BigInteger' has not been declared -- View this message in context: http://old.nabble.com/Compiling-SWIG-Extensions-With-VC2008-and-VC2010-Both-Installed-tp29739343p29739343.html Sent from the Python - python-list mailing list archive at Nabble.com. From victorsubervi at gmail.com Fri Sep 17 10:59:32 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 17 Sep 2010 10:59:32 -0400 Subject: MySQL Query Problem In-Reply-To: References: Message-ID: I rebooted MySQL and it now works fine ;) On Fri, Sep 17, 2010 at 9:26 AM, Victor Subervi wrote: > Here's some more data: > > print 'insert into Passengers values (Null, %s, %s, %s, %s, %s, %s, > %s, %s, "no", "n/a")' % (curr_flight, curr_customer, name, curr_sex, > curr_weight, price, curr_rt, curr_confirmation) > > cursor.execute('insert into Passengers values (Null, %s, %s, %s, > %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, > curr_sex, curr_weight, price, curr_rt, curr_confirmation)) > database.commit() > cursor.execute('select last_insert_id() from Passengers') > last_insert_id = cursor.fetchone()[0] > print 'update Passengers set name=%s, weight=%s where id=%s' % > (name, curr_weight, last_insert_id) > cursor.execute('update Passengers set name=%s, weight=%s where > id=%s', (name, curr_weight, last_insert_id)) > database.commit() > > This prints out: > > insert into Passengers values (Null, 1, 1, Dr. Mengela, Male, 155, 100, > 100, 654, "no", "n/a") > update Passengers set name=Dr. Mengela, weight=155 where id=15 > > Here's what's in the database: > > mysql> select * from Passengers; > > +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ > | id | flights_id | customer_id | name | sex | weight | price | round_trip > | confirmation | late_fee | late_fee_paid | > > +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ > | 1 | 1 | 1 | '' | NULL | NULL | 0.00 | 0 > | 12345 | NULL | NULL | > | 15 | 1 | 1 | '' | Male | NULL | 0.00 | 100 > | 654 | no | n/a | > > +----+------------+-------------+------+------+--------+-------+------------+--------------+----------+---------------+ > 2 rows in set (0.00 sec) > > mysql> describe Passengers; > > +---------------+-------------------------------+------+-----+---------+----------------+ > | Field | Type | Null | Key | Default | > Extra | > > +---------------+-------------------------------+------+-----+---------+----------------+ > | id | int(11) | NO | PRI | NULL | > auto_increment | > | flights_id | int(11) | NO | MUL | NULL > | | > | customer_id | int(11) | NO | MUL | NULL > | | > | name | varchar(40) | YES | | NULL > | | > | sex | enum('Male','Female') | YES | | NULL > | | > | weight | int(11) | YES | | NULL > | | > | price | float(6,2) | NO | | NULL > | | > | round_trip | tinyint(1) | NO | | 1 > | | > | confirmation | varchar(20) | YES | | NULL > | | > | late_fee | enum('no','yes') | YES | | no > | | > | late_fee_paid | enum('n/a','paid','not paid') | YES | | n/a > | | > > +---------------+-------------------------------+------+-----+---------+----------------+ > 11 rows in set (0.00 sec) > > and when I run the update: > > mysql> select * from Passengers; > > +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ > | id | flights_id | customer_id | name | sex | weight | price | > round_trip | confirmation | late_fee | late_fee_paid | > > +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ > | 1 | 1 | 1 | '' | NULL | NULL | 0.00 > | 0 | 12345 | NULL | NULL | > | 15 | 1 | 1 | Dr. Mengela | Male | 155 | 0.00 > | 100 | 654 | no | n/a | > > +----+------------+-------------+-------------+------+--------+-------+------------+--------------+----------+---------------+ > 2 rows in set (0.00 sec) > > Please explain why it does that! > TIA, > beno > > > On Fri, Sep 17, 2010 at 8:51 AM, Victor Subervi wrote: > >> Hi; >> I have this code: >> >> cursor.execute('insert into Passengers values (Null, %s, %s, %s, >> %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, >> curr_sex, curr_weight, price, curr_rt, curr_confirmation)) >> >> Now, when I print it out, add quotes where necessary and enter it in at a >> mysql prompt, all goes well. But when I do it this way, it enters null >> values for curr_customer and curr_weight! Same darn thing printed out works >> at the prompt. What gives? >> TIA, >> beno >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Fri Sep 17 11:11:43 2010 From: aahz at pythoncraft.com (Aahz) Date: 17 Sep 2010 08:11:43 -0700 Subject: compile Py2.6 on SL References: <4c934f3c$0$5417$ba4acef3@reader.news.orange.fr> Message-ID: In article <4c934f3c$0$5417$ba4acef3 at reader.news.orange.fr>, Michel Claveau - MVP wrote: > >SL (SilverLight) is a library/techno who give functions. >You cannot compile Python on SL (SilverLight). SL (Snow Leopard) is a popular platform for Python development. I suppose this is another argument against TLAs. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From python at mrabarnett.plus.com Fri Sep 17 12:03:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 17:03:14 +0100 Subject: MySQL Query Problem In-Reply-To: References: Message-ID: <4C939142.5020407@mrabarnett.plus.com> On 17/09/2010 15:59, Victor Subervi wrote: > I rebooted MySQL and it now works fine ;) > I recommend that you always list the column names explicitly to be on the safe side: cursor.execute('insert into Passengers (flights_id, customer_id, name, sex , weight, price, round_trip, confirmation, late_fee, late_fee_paid) values (%s, %s, %s, %s, %s, %s, %s, %s, "no", "n/a")', (curr_flight, curr_customer, name, curr_sex, curr_weight, price, curr_rt, curr_confirmation)) [snip code] From jabba.laci at gmail.com Fri Sep 17 12:05:18 2010 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 17 Sep 2010 12:05:18 -0400 Subject: self-closing window with wxPython Message-ID: Hi, I'd like to create a simple alarm application that shows an alarm window. The application should shut down automatically after 5 seconds. The problem is the following: * If I keep the mouse outside of the window, the application keeps running. Somehow self.Destroy() is not taken into account. * If the mouse is over the window and I keep moving it, the window closes. I'm using Ubuntu Linux with wxPython 2.8. Below you can find what I have so far. Thanks, Laszlo ========== class MyThread(threading.Thread): def __init__(self, parent): self.parent = parent threading.Thread.__init__(self) def run(self): print time.time() # appears on stdout time.sleep(5) print time.time() # appears on stdout self.parent.Destroy() # ??? doesn't work if the mouse is outside of the application window class Alarm(wx.Frame): def __init__(self, title, *args): wx.Frame.__init__(self, None, -1, title, pos=(0, 0), size=(800, 600), *args) self.sleepThread = MyThread(self) self.sleepThread.start() self.Bind(wx.EVT_CLOSE, self.on_close) def on_close(self, event): self.Destroy() ========== To call it: class Main(wx.PySimpleApp): def OnInit(self): self.frame = alarm.Alarm("Alarm 0.1") self.SetTopWindow(self.frame) self.SetExitOnFrameDelete(True) self.frame.Show() return True a = Main() a.MainLoop() ===== From vinay_sajip at yahoo.co.uk Fri Sep 17 12:34:23 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 17 Sep 2010 09:34:23 -0700 (PDT) Subject: Configuring logging for Web applications Message-ID: <71ec0bf9-b480-4272-aa57-743ca5d53244@g10g2000vbc.googlegroups.com> For those of you writing web applications and having multiple web applications in the same Python process, if you are interesting in using Python logging to write to web-application-specific logs, you may be interested in this link: http://plumberjack.blogspot.com/2010/09/configuring-logging-for-web.html If you have any feedback on that post, please comment on that post itself rather than here ;-) Thanks and regards, Vinay Sajip From lie.1296 at gmail.com Fri Sep 17 12:58:29 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 18 Sep 2010 02:58:29 +1000 Subject: Debugger - fails to "continue" with breakpoint set In-Reply-To: References: Message-ID: <4c939dfa$1@dnews.tpgi.com.au> On 09/16/10 03:38, Ed Greenberg wrote: > I'm pretty new to Python, but I am really enjoying it as an alternative > to Perl and PHP. > > When I run the debugger [import pdb; pdb.set_trace()] and then do next > and step, and evaluate variables, etc, when I hit 'c' for continue, we > go to the end, just fine. > > As soon as I set a breakpoint down the line, [b ] the > behavior of 'c' changes. Instead of continuing until the breakpoint, or > until the end, if the breakpoint is hidden by a conditional, the > debugger starts to treat 'c' as a step (or a next, I'm not sure which.) > > This behavior is repeatable and consistent. > can you write a test script and post its corresponding gdb session that demonstrates what you meant? From lie.1296 at gmail.com Fri Sep 17 13:08:54 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 18 Sep 2010 03:08:54 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c929052$0$1601$742ec2ed@news.sonic.net> References: <4c929052$0$1601$742ec2ed@news.sonic.net> Message-ID: <4c93a06c$1@dnews.tpgi.com.au> On 09/17/10 07:46, John Nagle wrote: > There's a tendency to use "dynamic attributes" in Python when > trying to encapsulate objects from other systems. It almost > works. But it's usually a headache in the end, and should be > discouraged. Here's why. I personally love them, they makes XML files looks more like python objects. foo bar being able to say: if a.b == 'foo': print a.c is very convenient. Yes, it doesn't work if the attribute contains special characters that python doesn't recognize; but you shouldn't use these syntax if that's the case. And even dict-syntax is not perfect for accessing XML file, e.g.: foo bar should a['b'] be 'foo' or 'bar'? So, personally I think both attribute-syntax and dict-syntax should continue; it should be up to the programmer to determine whether the limitations imposed by these syntaxes are suitable for their need (e.g. if the programmer knows he would only use alphabet tag name, then attr-style syntax is fine; and if he knows that there is no duplicate, then dict-style syntax is fine as well; and if he can't rely on both, then and only then, he'd be forced to do it the long way) From python at mrabarnett.plus.com Fri Sep 17 13:28:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 18:28:13 +0100 Subject: it doesn't work ;) [class recursive function] In-Reply-To: <4C939D6F.4040606@stoneleaf.us> References: <4C915568.3080007@stoneleaf.us> <4C915E64.50308@mrabarnett.plus.com> <4C939D6F.4040606@stoneleaf.us> Message-ID: <4C93A52D.5060008@mrabarnett.plus.com> On 17/09/2010 17:55, Ethan Furman wrote: > MRAB wrote: >> On 16/09/2010 00:23, Ethan Furman wrote: >> >>> I need some fresh eyes, or better brains, or both! >>> >> 'next_item' is a generator, but it's just calling itself and discarding >> the result. I think it should be yielding the results to its caller. >> That fix gives me 7 sections in total. > > Thanks, M! > > Some further reading on generators has helped clarify the issue for me. > I had forgotten that the initial call to a generator only sets it up, > and then returns the generator function itself, which then needs to be > iterated through. > > Thanks for the reminder! > > -- > ~Ethan~ > > Still early in the morning for me, so just in case I didn't phrase it > well, my thanks are sincere. > > PS > My apologies if this shows up twice, I haven't seen my other post yet > and it's been 27 hours. > That's probably because you sent it directly to me. From ethan at stoneleaf.us Fri Sep 17 13:49:37 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 10:49:37 -0700 Subject: it doesn't work ;) [class recursive function] In-Reply-To: <4C93A52D.5060008@mrabarnett.plus.com> References: <4C915568.3080007@stoneleaf.us> <4C915E64.50308@mrabarnett.plus.com> <4C939D6F.4040606@stoneleaf.us> <4C93A52D.5060008@mrabarnett.plus.com> Message-ID: <4C93AA31.6010009@stoneleaf.us> MRAB wrote: > On 17/09/2010 17:55, Ethan Furman wrote: >> MRAB wrote: >>> On 16/09/2010 00:23, Ethan Furman wrote: >> >> PS >> My apologies if this shows up twice, I haven't seen my other post yet >> and it's been 27 hours. >> > That's probably because you sent it directly to me. That would explain it -- like I said, it was still early for me! :) -- ~Ethan~ From ethan at stoneleaf.us Fri Sep 17 13:53:28 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 10:53:28 -0700 Subject: The trouble with "dynamic attributes". In-Reply-To: <4c93a06c$1@dnews.tpgi.com.au> References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4c93a06c$1@dnews.tpgi.com.au> Message-ID: <4C93AB18.2080500@stoneleaf.us> Lie Ryan wrote: [snip] > And even dict-syntax is not perfect for accessing XML file, e.g.: > > > foo > bar > > > should a['b'] be 'foo' or 'bar'? Attribute style access would also fail in this instance -- how is this worked-around? -- ~Ethan~ From joncle at googlemail.com Fri Sep 17 14:21:30 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 17 Sep 2010 11:21:30 -0700 (PDT) Subject: re.sub: escaping capture group followed by numeric(s) Message-ID: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> Hi All, (I reckon this is probably a question for MRAB and is not really Python specific, but anyhow...) Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1') I've been searching around and I'm sure it'll be obvious when it's pointed out, but how do I use the above to replace 1 with 11? Obviously I can't use r'\11' because there is no group 11. I know I can use a function to do it, but it seems to me there must be a way without. Can I escape r'\11' somehow so that it's group 1 with a '1' after it (not group 11). Cheers, Jon. From jojo.mwebaze at gmail.com Fri Sep 17 14:48:36 2010 From: jojo.mwebaze at gmail.com (Jojo Mwe) Date: Fri, 17 Sep 2010 11:48:36 -0700 (PDT) Subject: recording input/outputs, attributes and parameters of modules Message-ID: i would like to track all inputs/output to modules/functions -if a module retrieved and used files and run some analysis on them and produced other files in return, i would like to take not of this. i.e what i want is to record all input sand outputs to a module. and also to record all parameters, attribute vaules used by the same module and also would like to know how one module calls another whether it instantiates classes from one module etc Any help will be highly appreciated.. Jojo From mrjean1 at gmail.com Fri Sep 17 14:54:41 2010 From: mrjean1 at gmail.com (MrJean1) Date: Fri, 17 Sep 2010 11:54:41 -0700 (PDT) Subject: SimpleHTTPServer, external CSS, and Google Chrome References: <057af264-995d-4e60-9887-d053b93bd988@m17g2000prl.googlegroups.com> Message-ID: <2079bf56-6c19-4233-97d9-418b7e9d0190@a4g2000prm.googlegroups.com> FWIW, There is a blue text on a red background in all 4 browsers Google Chrome 6.0.472.59, Safari 5.0.1 (7533.17.8), FireFox 3.6.9 and IE 6.0.2900.5512.... with Python 2.7 serving that page on my Windows XP SP 3 machine. /Jean On Sep 16, 11:59?pm, Justin Ezequiel wrote: > I am running "python -m SimpleHTTPServer 80" on Windows XP Pro SP 3 > (Python 2.5.4) > > browsinghttp://localhost/using IE8 and FireFox 3.6, I get blue text > on red background > on Google Chrome 6.0 however, I get blue text on white background > placing index.htm and styles.css (see below) under IIS, I get blue > text on red background for all browsers, > including Google Chrome 6.0. > > I get exactly the same results when browsing from another machine. > what's wrong? what do I need to change in SimpleHTTPServer? > > index.htm > -------------- > ? ?"http://www.w3.org/TR/html4/strict.dtd"> > > > your title > > > > >

foo bar

> > > -------------- > > styles.css > -------------- > body { > ? ? background-color: red;} > > -------------- From python at mrabarnett.plus.com Fri Sep 17 14:56:37 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 19:56:37 +0100 Subject: re.sub: escaping capture group followed by numeric(s) In-Reply-To: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> References: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> Message-ID: <4C93B9E5.4050000@mrabarnett.plus.com> On 17/09/2010 19:21, Jon Clements wrote: > Hi All, > > (I reckon this is probably a question for MRAB and is not really > Python specific, but anyhow...) > > Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1') > > I've been searching around and I'm sure it'll be obvious when it's > pointed out, but how do I use the above to replace 1 with 11? > Obviously I can't use r'\11' because there is no group 11. I know I > can use a function to do it, but it seems to me there must be a way > without. Can I escape r'\11' somehow so that it's group 1 with a '1' > after it (not group 11). > re.sub(r'(\d+)', r'\g<1>', 'string1') From __peter__ at web.de Fri Sep 17 14:59:13 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 17 Sep 2010 20:59:13 +0200 Subject: re.sub: escaping capture group followed by numeric(s) References: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> Message-ID: Jon Clements wrote: > (I reckon this is probably a question for MRAB and is not really > Python specific, but anyhow...) > > Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1') > > I've been searching around and I'm sure it'll be obvious when it's > pointed out, but how do I use the above to replace 1 with 11? > Obviously I can't use r'\11' because there is no group 11. I know I > can use a function to do it, but it seems to me there must be a way > without. Can I escape r'\11' somehow so that it's group 1 with a '1' > after it (not group 11). Quoting http://docs.python.org/library/re.html#re.sub """ In addition to character escapes and backreferences as described above, \g will use the substring matched by the group named name, as defined by the (?P...) syntax. \g uses the corresponding group number; \g<2> is therefore equivalent to \2, but isn?t ambiguous in a replacement such as \g<2>0. \20 would be interpreted as a reference to group 20, not a reference to group 2 followed by the literal character '0'. The backreference \g<0> substitutes in the entire substring matched by the RE. """ Peter From joncle at googlemail.com Fri Sep 17 15:00:58 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 17 Sep 2010 12:00:58 -0700 (PDT) Subject: re.sub: escaping capture group followed by numeric(s) References: <208f3cc6-ecf6-4d02-aaaa-1793a61b74f8@v23g2000vbi.googlegroups.com> Message-ID: <516ef370-7b28-40eb-a0c6-2c176cbc85c5@t3g2000vbb.googlegroups.com> On 17 Sep, 19:59, Peter Otten <__pete... at web.de> wrote: > Jon Clements wrote: > > (I reckon this is probably a question for MRAB and is not really > > Python specific, but anyhow...) > > > Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1') > > > I've been searching around and I'm sure it'll be obvious when it's > > pointed out, but how do I use the above to replace 1 with 11? > > Obviously I can't use r'\11' because there is no group 11. I know I > > can use a function to do it, but it seems to me there must be a way > > without. Can I escape r'\11' somehow so that it's group 1 with a '1' > > after it (not group 11). > > Quoting > > http://docs.python.org/library/re.html#re.sub > > """ > In addition to character escapes and backreferences as described above, > \g will use the substring matched by the group named name, as defined > by the (?P...) syntax. \g uses the corresponding group number; > \g<2> is therefore equivalent to \2, but isn?t ambiguous in a replacement > such as \g<2>0. \20 would be interpreted as a reference to group 20, not a > reference to group 2 followed by the literal character '0'. The > backreference \g<0> substitutes in the entire substring matched by the RE. > """ > > Peter Thanks Peter and MRAB. I must have been through the docs half a dozen times and missed that - what a muppet! One of those days I guess... Cheers, Jon. From philip at semanchuk.com Fri Sep 17 15:08:16 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 17 Sep 2010 15:08:16 -0400 Subject: self-closing window with wxPython In-Reply-To: References: Message-ID: <05E2E665-4777-4F72-B1BC-852887260D22@semanchuk.com> On Sep 17, 2010, at 12:05 PM, Jabba Laci wrote: > Hi, > > I'd like to create a simple alarm application that shows an alarm > window. The application should shut down automatically after 5 > seconds. The problem is the following: > * If I keep the mouse outside of the window, the application keeps > running. Somehow self.Destroy() is not taken into account. > * If the mouse is over the window and I keep moving it, the window closes. > > I'm using Ubuntu Linux with wxPython 2.8. Below you can find what I have so far. Hi Laszlo, It's difficult to help without a complete working example. But I have a few suggestions. 1) Why not call self.parent.Close()? It seems a bit more polite than .Destroy(). 2) I saw this in the documentation for Destroy() -- "Frames and dialogs are not destroyed immediately when this function is called -- they are added to a list of windows to be deleted on idle time, when all the window's events have been processed." That might be consistent with what you're seeing. The window you're trying to destroy has no events in its queue. WHen you move the mouse over it, the window processes those mouse events and then wx realizes, "Hey, this window has processed all of its events, and it's on the list of windows to be destroyed. I'd better get rid of it." If you're interested in experimenting, find a non-mouse way to force that window to process an event and I'll bet that would have the same effect as moving the mouse over it. 3) Both the wxPython and wxWidgets mailing lists are probably better places to ask for help on wxPython. Good luck Philip > > ========== > > class MyThread(threading.Thread): > def __init__(self, parent): > self.parent = parent > threading.Thread.__init__(self) > > def run(self): > print time.time() # appears on stdout > time.sleep(5) > print time.time() # appears on stdout > > self.parent.Destroy() # ??? doesn't work if the mouse is > outside of the application window > > class Alarm(wx.Frame): > def __init__(self, title, *args): > wx.Frame.__init__(self, None, -1, title, pos=(0, 0), > size=(800, 600), *args) > > self.sleepThread = MyThread(self) > self.sleepThread.start() > > self.Bind(wx.EVT_CLOSE, self.on_close) > > def on_close(self, event): > self.Destroy() > > ========== > > To call it: > > class Main(wx.PySimpleApp): > def OnInit(self): > self.frame = alarm.Alarm("Alarm 0.1") > self.SetTopWindow(self.frame) > self.SetExitOnFrameDelete(True) > self.frame.Show() > return True > > a = Main() > a.MainLoop() > > ===== > -- > http://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Fri Sep 17 15:16:15 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 12:16:15 -0700 Subject: parsing compact index files (*.cdx) Message-ID: <4C93BE7F.3050203@stoneleaf.us> Greetings! Does anybody have any pointers, tips, web-pages, already written routines, etc, on parsing *.cdx files? I have found the pages on MS's sight for Foxpro, but they neglect to describe the compaction algorithm used, and my Google-fu has failed to find any sites with that information. Any and all help greatly appreciated! -- ~Ethan~ From ethan at stoneleaf.us Fri Sep 17 15:34:42 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 12:34:42 -0700 Subject: parsing compact index files (*.cdx) In-Reply-To: <4C93BE7F.3050203@stoneleaf.us> References: <4C93BE7F.3050203@stoneleaf.us> Message-ID: <4C93C2D2.3020608@stoneleaf.us> Ethan Furman wrote: > Greetings! > > Does anybody have any pointers, tips, web-pages, already written > routines, etc, on parsing *.cdx files? I have found the pages on MS's > sight for Foxpro, but they neglect to describe the compaction algorithm > used, and my Google-fu has failed to find any sites with that information. > > Any and all help greatly appreciated! > > -- > ~Ethan~ Oops -- compact index files are *.idx; compound index files are *.cdx; I believe they use the same algorithm, though, at least for Foxpro. -- ~Ethan~ From python at mrabarnett.plus.com Fri Sep 17 15:37:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Sep 2010 20:37:34 +0100 Subject: parsing compact index files (*.cdx) In-Reply-To: <4C93BE7F.3050203@stoneleaf.us> References: <4C93BE7F.3050203@stoneleaf.us> Message-ID: <4C93C37E.30803@mrabarnett.plus.com> On 17/09/2010 20:16, Ethan Furman wrote: > Greetings! > > Does anybody have any pointers, tips, web-pages, already written > routines, etc, on parsing *.cdx files? I have found the pages on MS's > sight for Foxpro, but they neglect to describe the compaction algorithm > used, and my Google-fu has failed to find any sites with that information. > > Any and all help greatly appreciated! > Have you seen this: http://www.archive.org/web/researcher/cdx_file_format.php From ethan at stoneleaf.us Fri Sep 17 16:00:48 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Sep 2010 13:00:48 -0700 Subject: parsing compact index files (*.cdx) In-Reply-To: <4C93C37E.30803@mrabarnett.plus.com> References: <4C93BE7F.3050203@stoneleaf.us> <4C93C37E.30803@mrabarnett.plus.com> Message-ID: <4C93C8F0.6050205@stoneleaf.us> MRAB wrote: > On 17/09/2010 20:16, Ethan Furman wrote: >> Greetings! >> >> Does anybody have any pointers, tips, web-pages, already written >> routines, etc, on parsing *.cdx files? I have found the pages on MS's >> sight for Foxpro, but they neglect to describe the compaction algorithm >> used, and my Google-fu has failed to find any sites with that >> information. >> >> Any and all help greatly appreciated! >> > Have you seen this: > > http://www.archive.org/web/researcher/cdx_file_format.php I had not. Unfortunately what I need are cdx files that are for dbf files. Thanks anyway! -- ~Ethan~ From usenot at geekmail.INVALID Fri Sep 17 16:01:54 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 17 Sep 2010 16:01:54 -0400 Subject: Too much code - slicing References: Message-ID: <20100917160154.570ce164@geekmail.INVALID> On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > I also like this construct that works, I think, since 2.6: > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > I wonder when this construct will finally start to look good. /W -- INVALID? DE! From isaacrc82 at gmail.com Fri Sep 17 16:07:15 2010 From: isaacrc82 at gmail.com (Ariel) Date: Fri, 17 Sep 2010 16:07:15 -0400 Subject: How to make a web services in python ??? Message-ID: Hi everybody, I need some help to find documentation about how to implements web services in python, could you help me please ??? Regards Thanks in advance Ariel -------------- next part -------------- An HTML attachment was scrubbed... URL: From jabba.laci at gmail.com Fri Sep 17 17:00:54 2010 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 17 Sep 2010 17:00:54 -0400 Subject: self-closing window with wxPython In-Reply-To: <05E2E665-4777-4F72-B1BC-852887260D22@semanchuk.com> References: <05E2E665-4777-4F72-B1BC-852887260D22@semanchuk.com> Message-ID: Hi, > 2) I saw this in the documentation for Destroy() -- "Frames and dialogs are not destroyed immediately when this function is called -- they are added to a list of windows to be deleted on idle time, when all the window's events have been processed." That might be consistent with what you're seeing. The window you're trying to destroy has no events in its queue. WHen you move the mouse over it, the window processes those mouse events and then wx realizes, "Hey, this window has processed all of its events, and it's on the list of windows to be destroyed. I'd better get rid of it." > > If you're interested in experimenting, find a non-mouse way to force that window to process an event and I'll bet that would have the same effect as moving the mouse over it. Thanks for the hint, I could solve the problem. After Destroy() I added an extra event: self.parent.Destroy() self.parent.dc.SetFocus() As you suggested, the extra event triggers the queue processing and when it becomes empty the window gets destroyed. Thanks, Laszlo From cs at zip.com.au Fri Sep 17 17:07:41 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 18 Sep 2010 07:07:41 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: <4C93AB18.2080500@stoneleaf.us> References: <4C93AB18.2080500@stoneleaf.us> Message-ID: <20100917210741.GA1674@cskk.homeip.net> On 17Sep2010 10:53, Ethan Furman wrote: | Lie Ryan wrote: | [snip] | >And even dict-syntax is not perfect for accessing XML file, e.g.: | > | > | > foo | > bar | > | > | >should a['b'] be 'foo' or 'bar'? | | Attribute style access would also fail in this instance -- how is | this worked-around? I'd be inclined to go for ('foo', 'bar'), though that makes all the single occurence nodes into sequences too, a bit cumbersome:-( -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ alt.skunks A newsgroup for enthusiasts of skunks and other mustelidae. From ian.g.kelly at gmail.com Fri Sep 17 17:15:04 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 17 Sep 2010 15:15:04 -0600 Subject: self-closing window with wxPython In-Reply-To: References: <05E2E665-4777-4F72-B1BC-852887260D22@semanchuk.com> Message-ID: On Fri, Sep 17, 2010 at 3:00 PM, Jabba Laci wrote: > Hi, > > > 2) I saw this in the documentation for Destroy() -- "Frames and dialogs > are not destroyed immediately when this function is called -- they are added > to a list of windows to be deleted on idle time, when all the window's > events have been processed." That might be consistent with what you're > seeing. The window you're trying to destroy has no events in its queue. WHen > you move the mouse over it, the window processes those mouse events and then > wx realizes, "Hey, this window has processed all of its events, and it's on > the list of windows to be destroyed. I'd better get rid of it." > > > > If you're interested in experimenting, find a non-mouse way to force that > window to process an event and I'll bet that would have the same effect as > moving the mouse over it. > > Thanks for the hint, I could solve the problem. After Destroy() I > added an extra event: > > self.parent.Destroy() > self.parent.dc.SetFocus() > > As you suggested, the extra event triggers the queue processing and > when it becomes empty the window gets destroyed. > You could also implement the alarm with a wxTimer instance that triggers a wxTimerEvent, rather than creating a new thread for no good reason. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hidura at gmail.com Fri Sep 17 17:35:56 2010 From: hidura at gmail.com (Hidura) Date: Fri, 17 Sep 2010 18:35:56 -0300 Subject: How to make a web services in python ??? In-Reply-To: References: Message-ID: What kind of web-service you have in mind???? 2010/9/17, Ariel : > Hi everybody, I need some help to find documentation about how to implements > web services in python, could you help me please ??? > Regards > Thanks in advance > Ariel > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From jaksonaquino at gmail.com Fri Sep 17 19:04:51 2010 From: jaksonaquino at gmail.com (Jakson A. Aquino) Date: Fri, 17 Sep 2010 20:04:51 -0300 Subject: SendKeys and Python 2.7 In-Reply-To: References: <4c8e752d$0$5432$ba4acef3@reader.news.orange.fr> Message-ID: > On Mon, Sep 13, 2010 at 4:02 PM, Michel Claveau - MVP > wrote: >> Sorry for time, but I am very busy... >> >> With Python + Pywin32, you can force the activation of a window (before >> send some keys...) >> See: >> ?win32gui.SetForegroundWindow(w_handle) >> >> or >> ?win32gui.SetActiveWindow(w_handle) >> >> >> >> For to find a windows (and his handle), see: >> ?win32gui.EnumWindows() >> ?win32gui.GetWindowTex() >> or >> ?win32gui.FindWindowEx() I ended up using Dispatch("WScript.Shell") and AppActivate("R Console") of the win32com.client module because they are higher level functions. I guess that your code runs faster, but I don't have an old machine to compare the performance of the two codes. I still may switch to your code in the future, when I have easy access to a real machine running Windows to make some tests. The released version of the plugin is here: http://www.vim.org/scripts/script.php?script_id=2628 Thanks for your help! Jakson Aquino From nkrumm at gmail.com Fri Sep 17 19:10:39 2010 From: nkrumm at gmail.com (Nik Krumm) Date: Fri, 17 Sep 2010 16:10:39 -0700 (PDT) Subject: [OS X 10.5] hitting TAB inserts ./ in interactive mode ? Message-ID: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Hi all, Thanks for your help. I installed python 2.7 on my Mac OS X 10.5.8 machine: nik$ python Python 2.7 (r27:82508, Jul 3 2010, 21:12:11) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. and now, when I hit TAB or paste in a code snippet with tabs in them, the interpreter tries to autocomplete a path, or inserts "./" if the line is blank (just as readline would in the shell environment). It does *not* try to autocomplete function (as readline would in python-- importing readline does turn on this functionality). And it does *not* insert a tab, as I would like it to! If i start my old python 2.5 which came with the OS, this is not a problem. I've tried setting a PYTHONIOENCODING, but that doesn't seem to be doing the job. Any ideas? Thanks in advance. ~Nik From wegwerp at gmail.com Fri Sep 17 19:30:56 2010 From: wegwerp at gmail.com (Bas) Date: Fri, 17 Sep 2010 16:30:56 -0700 (PDT) Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> Message-ID: <96057530-3d0d-4e78-b7a3-12425a7c7f83@i17g2000vbq.googlegroups.com> On Sep 17, 10:01?pm, Andreas Waldenburger wrote: > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > > > I also like this construct that works, I think, since 2.6: > > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > I wonder when this construct will finally start to look good. Using IFs is just plain ugly. Why not go for the much more pythonic code = (lambda s:dir[slice(*(s*int(num),None)[::s])])(cmp('o',side)) Much easier on the eyes and no code duplication ... ;) Bas From sumerc at gmail.com Fri Sep 17 19:57:15 2010 From: sumerc at gmail.com (k3xji) Date: Fri, 17 Sep 2010 16:57:15 -0700 (PDT) Subject: Porting PEP 3148 to 2.x series Message-ID: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> Hi, Is there any work on porting PEP 3148 back to 2.x series. That is a wonderful PEP, any many long-running applications are really in need of some stable library for handling stuff in async way just as proposed in this PEP. Thanks, From ben+python at benfinney.id.au Fri Sep 17 21:21:10 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 18 Sep 2010 11:21:10 +1000 Subject: Porting PEP 3148 to 2.x series References: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> Message-ID: <8762y37sop.fsf@benfinney.id.au> k3xji writes: > Is there any work on porting PEP 3148 back to 2.x series. That is a > wonderful PEP, any many long-running applications are really in need > of some stable library for handling stuff in async way just as > proposed in this PEP. Better would be to port those applications that would benefit to Python 3.x. -- \ ?To stay young requires unceasing cultivation of the ability to | `\ unlearn old falsehoods.? ?Robert Anson Heinlein | _o__) | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Fri Sep 17 21:50:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Sep 2010 01:50:59 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> Message-ID: <4c941b03$0$28657$c3e8da3@news.astraweb.com> On Fri, 17 Sep 2010 16:01:54 -0400, Andreas Waldenburger wrote: > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > >> I also like this construct that works, I think, since 2.6: >> >> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] >> > I wonder when this construct will finally start to look good. It looks good to me. It follows a common English idiom: "What are you doing tonight?" "I'll be going to the movies, if I finish work early, otherwise I'll stay home and watch a DVD." -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Sep 17 23:12:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Sep 2010 03:12:15 GMT Subject: Why IterableUserDict? Message-ID: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> I was writing some tests for a mapping class I have made, and I decided to run those same tests over dict and UserDict. The built-in dict passed all the tests, but UserDict failed one: class SimpleMappingTest(unittest.TestCase): type2test = UserDict.UserDict def test_iter(self): k, v = [0, 1, 2, 3], 'abcd' m = self.type2test(zip(k, v)) it = iter(m) self.assert_(iter(it) is it) self.assertEquals(sorted(it), k) # This line fails. # many more tests To cut a long story short, the problem is that UserDict doesn't support the modern iteration protocol. Python falls back on the old-fashioned __getitem__ iteration protocol, but since it expects IndexError rather than KeyError, iteration fails for UserDict once it hits key=4. If I look at the source code for the UserDict module, I discover that there's a second mapping class, IterableUserDict, specifically to make UserDict iterable. To do this requires a single one-line method: class IterableUserDict(UserDict): def __iter__(self): return iter(self.data) This class was apparently added to the module in 2.2 -- it doesn't exist in 2.1. Now that boggles my brain. Why was support for iteration added as a subclass, instead of simply adding the __iter__ method to UserDict? UserDict is supposed to be a drop-in replacement for dict (although the use-cases for it are much fewer now that we can inherit from dict), so it doesn't make sense to me to have a non-iterable UserDict plus a subclass which is iterable. Can anyone shed any light on this apparently bizarre design decision? -- Steven From nad at acm.org Sat Sep 18 00:01:47 2010 From: nad at acm.org (Ned Deily) Date: Fri, 17 Sep 2010 21:01:47 -0700 Subject: [OS X 10.5] hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Message-ID: In article <431250b2-391e-4a1f-ba72-08afb7159d65 at l25g2000prn.googlegroups.com>, Nik Krumm wrote: > Thanks for your help. I installed python 2.7 on my Mac OS X 10.5.8 > machine: > > > nik$ python > Python 2.7 (r27:82508, Jul 3 2010, 21:12:11) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > > and now, when I hit TAB or paste in a code snippet with tabs in them, > the interpreter tries to autocomplete a path, or inserts "./" if the > line is blank (just as readline would in the shell environment). It > does *not* try to autocomplete function (as readline would in python-- > importing readline does turn on this functionality). And it does *not* > insert a tab, as I would like it to! See the rlcompleter module in the standard library: http://docs.python.org/library/rlcompleter.html In my .bashrc file, I have a line: [ -f ~/.pythonrc ] && export PYTHONSTARTUP=~/.pythonrc and in the .pythonrc file, I include: try: import readline except ImportError: print("Module readline not available.") else: import rlcompleter readline.parse_and_bind("tab: complete") Note the print() form which works with either Python 2 or 3. -- Ned Deily, nad at acm.org From ldo at geek-central.gen.new_zealand Sat Sep 18 01:03:23 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 18 Sep 2010 17:03:23 +1200 Subject: WMI in Python References: <257b2d99-03d4-491b-8f8b-dccd2bc102a7@p22g2000pre.googlegroups.com> <210f30c4-22da-405f-ad4b-cc46841ca686@p22g2000pre.googlegroups.com> Message-ID: In message <210f30c4-22da-405f-ad4b-cc46841ca686 at p22g2000pre.googlegroups.com>, alex23 wrote: > Lawrence D'Oliveiro wrote: > >> Because machine-generated >> code has no place in a source file to be maintained by a human. > > Endlessly repeating your bigotry doesn't make it any more true. The point is that it is machine-generated from an input command, therefore it makes sense from a maintenance viewpoint to keep the input command, not the machine-generated output, in the source file, and simply generate the latter from the former as part of the build process. From ldo at geek-central.gen.new_zealand Sat Sep 18 01:07:09 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 18 Sep 2010 17:07:09 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message <2f830099-4264-47bc-98ee-31950412ad43 at q21g2000prm.googlegroups.com>, cerr wrote: > I get a socket error "[Errno 98] Address already in use" when i try to > open a socket that got closed before with close(). How come close() > doesn't close the socket properly? The usual case this happens is you have a client connection open at the time, that was not properly terminated. Then the TCP stack goes through a holdoff period (2 minutes, I believe it is), to make absolutely sure all packets destined for the old connection have completely disappeared off the entire Internet, before it will let you open a socket on the same port again. From brian at sweetapp.com Sat Sep 18 01:53:20 2010 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 18 Sep 2010 15:53:20 +1000 Subject: Porting PEP 3148 to 2.x series In-Reply-To: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> References: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> Message-ID: <3BD26867-EDDE-442B-948A-A8FBB636904E@sweetapp.com> On 18 Sep 2010, at 09:57, k3xji wrote: > Hi, > > Is there any work on porting PEP 3148 back to 2.x series. That is a > wonderful PEP, any many long-running applications are really in need > of some stable library for handling stuff in async way just as > proposed in this PEP. I'll probably port 3148 to Python 2.x after its running happily in Python 3.2. But there is no chance that it will be included with the standard library in the 2.x series. Cheers, Brian From __peter__ at web.de Sat Sep 18 03:42:14 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Sep 2010 09:42:14 +0200 Subject: Why IterableUserDict? References: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I was writing some tests for a mapping class I have made, and I decided > to run those same tests over dict and UserDict. The built-in dict passed > all the tests, but UserDict failed one: > > class SimpleMappingTest(unittest.TestCase): > type2test = UserDict.UserDict > def test_iter(self): > k, v = [0, 1, 2, 3], 'abcd' > m = self.type2test(zip(k, v)) > it = iter(m) > self.assert_(iter(it) is it) > self.assertEquals(sorted(it), k) # This line fails. > # many more tests > > To cut a long story short, the problem is that UserDict doesn't support > the modern iteration protocol. Python falls back on the old-fashioned > __getitem__ iteration protocol, but since it expects IndexError rather > than KeyError, iteration fails for UserDict once it hits key=4. > > If I look at the source code for the UserDict module, I discover that > there's a second mapping class, IterableUserDict, specifically to make > UserDict iterable. To do this requires a single one-line method: > > class IterableUserDict(UserDict): > def __iter__(self): > return iter(self.data) > > This class was apparently added to the module in 2.2 -- it doesn't exist > in 2.1. > > Now that boggles my brain. Why was support for iteration added as a > subclass, instead of simply adding the __iter__ method to UserDict? > UserDict is supposed to be a drop-in replacement for dict (although the > use-cases for it are much fewer now that we can inherit from dict), so it > doesn't make sense to me to have a non-iterable UserDict plus a subclass > which is iterable. > > Can anyone shed any light on this apparently bizarre design decision? I looked it up for you: http://svn.python.org/view/python/trunk/Lib/UserDict.py?view=log """ Revision 22248 - (view) (download) (as text) (annotate) - [select for diffs] Modified Tue Aug 7 17:40:42 2001 UTC (9 years, 1 month ago) by gvanrossum File length: 1913 byte(s) Diff to previous 21167 Remove the __iter__ method from the UserDict class -- it can silently break old code (in extreme cases). See SF bug #448153. Add a new subclass IterableUserDict that has the __iter__ method. Note that for new projects, unless backwards compatibility with pre-2.2 Python is required, subclassing 'dictionary' is recommended; UserDict might become deprecated. """ The bug report is also interesting: http://bugs.python.org/issue448153 Peter From ldo at geek-central.gen.new_zealand Sat Sep 18 04:04:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 18 Sep 2010 20:04:21 +1200 Subject: [OS X 10.5] hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Message-ID: In message , Ned Deily wrote: > try: > import readline > except ImportError: > print("Module readline not available.") > else: > import rlcompleter > readline.parse_and_bind("tab: complete") > > Note the print() form which works with either Python 2 or 3. You should be writing diagnostics to stderr, not stdout. From vlastimil.brom at gmail.com Sat Sep 18 04:48:44 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 18 Sep 2010 10:48:44 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: <4C92A584.8060303@mrabarnett.plus.com> <4C92B3BC.6090901@mrabarnett.plus.com> Message-ID: 2010/9/18 Dennis Lee Bieber : > On Fri, 17 Sep 2010 10:44:43 +0200, Vlastimil Brom > declaimed the following in > gmane.comp.python.general: > > >> Ok, thanks for confirming my suspicion :-), >> Now I have to decide whether I shall use my custom data structure, >> where I am on my own, or whether using an sql database in such a >> non-standard way has some advantages... >> The main problem indeed seems to be the fact, that I consider the >> tagged texts to be the primary storage format, whereas the database is >> only means for accessing it more conveniently. >> > > ? ? ? ?I suspect part of your difficulty is in trying to fit everything > into a single relation (table). > > ? ? ? ?Looking back at your ancient "format for storing textual data (for > an edition) - formatting and additional info" post, I'd probably move > your so-called tags into one relation -- where the tag type is, itself, > data... > > ? ? ? ?Without seeing an actual data sample (and pseudo-DDL): > > create table texts > ? ? ? ?( > ? ? ? ? ? ? ? ?ID autoincrement primary key, > ? ? ? ? ? ? ? ?text varchar > ? ? ? ?); > > create table tags > ? ? ? ?( > ? ? ? ? ? ? ? ?ID autoincrement primary key, > ? ? ? ? ? ? ? ?textID integer foreign key references texts(ID), > ? ? ? ? ? ? ? ?tagtype char, > ? ? ? ? ? ? ? ?start integer, > ? ? ? ? ? ? ? ?end integer, > ? ? ? ? ? ? ? ?supplement varchar > ? ? ? ?); > > ? ? ? ?I'd really have to see samples (more than one line) of the raw > input, and the desired information... > > -- > ? ? ? ?Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ?wlfraed at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the elaboration, I am sure, I am missing some more advanced features of SQL (would the above also work in sqlite, as there (probably?) are no real type restrictions on data? The "markup" format as well as the requirements haven't change since those old posts, one sample of the tagged text is in one of the follow-up post of that: http://mail.python.org/pipermail/python-list/2008-May/540773.html in principle in the tags are in the form , from that text index on this tag-value combination is assigned - until or arbitrary combinations of the tags including overlapping are possible (nesting of the same tags is not possible in favor of the direct replacement). Different texts may have (partly) differing tags, which I'd prefer to handle generally, without having to adapt the queries directly. After the tagged text is parsed, the plain text and the corresponding "database" are created, which maps the text indices to the tag names with their values. Querying the data should be able to get the "tagset" for the given text index and conversely to find the indices matching the given tag-value combinations. (actually the text ranges matching those criteria would be even better, but these are easily done with bisect) (from the specification, mxTextTools looks similar, but it seemed rather low-level and quite heavyweight for the given task) Thanks in advance for any suggestions, Vlastimil Brom From greg.ewing at canterbury.ac.nz Sat Sep 18 04:54:54 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 18 Sep 2010 20:54:54 +1200 Subject: self-closing window with wxPython In-Reply-To: References: Message-ID: <8fjd3iFhckU1@mid.individual.net> Jabba Laci wrote: > I'd like to create a simple alarm application that shows an alarm > window. The application should shut down automatically after 5 > seconds. Are you sure that's a good idea? What happens if the user gets distracted for 6 seconds and misses the alarm? -- Greg From sumerc at gmail.com Sat Sep 18 06:59:19 2010 From: sumerc at gmail.com (k3xji) Date: Sat, 18 Sep 2010 03:59:19 -0700 (PDT) Subject: Porting PEP 3148 to 2.x series References: <201be7e2-b4ba-451b-9029-90cde059c284@j19g2000vbh.googlegroups.com> Message-ID: <5917be2a-7f4d-4776-89b9-063f6247c9be@a11g2000vbn.googlegroups.com> > I'll probably port 3148 to Python 2.x after its running happily in ? > Python 3.2. Very good news. One idea: Once library becomes reliable enough- of course there are various use cases - but IMHO it perfectly fits the problem domain of implementing an async DB library on top of it. I suppose that will get attention from Web Community. That is why I am asking for the port because various Web applications written in frameworks (e.g Django) that does not have been ported to 3.x series yet. Thanks, From invalid at invalid.invalid Sat Sep 18 08:10:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 18 Sep 2010 12:10:18 +0000 (UTC) Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On 2010-09-18, Lawrence D'Oliveiro wrote: > In message ><2f830099-4264-47bc-98ee-31950412ad43 at q21g2000prm.googlegroups.com>, cerr > wrote: > >> I get a socket error "[Errno 98] Address already in use" when i try to >> open a socket that got closed before with close(). How come close() >> doesn't close the socket properly? > > The usual case this happens is you have a client connection open at the > time, that was not properly terminated. Then the TCP stack goes through a > holdoff period (2 minutes, I believe it is), to make absolutely sure all > packets destined for the old connection have completely disappeared off the > entire Internet, before it will let you open a socket on the same port > again. Even when the connection was properly terminated (from an application's POV), there's a TIME_WAIT period before the TCP stack considered the connection completely gone and will allow re-use of the port. IOW, the TIME_WAIT is actually part of the connection termination (from the TCP stack's POV), and it can takes place after the application considers the connection closed (and may have even exited): http://www.developerweb.net/forum/showthread.php?t=2941 -- Grant From ldo at geek-central.gen.new_zealand Sat Sep 18 08:23:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 00:23:29 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message , Grant Edwards wrote: > Even when the connection was properly terminated (from an > application's POV), there's a TIME_WAIT period before the TCP stack > considered the connection completely gone and will allow re-use of the > port. I?m not so sure about that. I?ve done a bunch of development on a system recently which had a server process written in Python running on a Linux box, accepting connections from a client running under old MacOS 9 (don?t ask) which was, of course, prone to crash. If the client had shut down cleanly, then I could stop and restart the server process without any problems reopening the socket. But if I forgot to close the client, then the server would hit the ?already in use? error. To deal with it, I simply put in an automatic retry at 60-second intervals until it succeeded in reopening the socket. From niklasro at gmail.com Sat Sep 18 11:25:31 2010 From: niklasro at gmail.com (Niklasro) Date: Sat, 18 Sep 2010 08:25:31 -0700 (PDT) Subject: Learning inheritance Message-ID: Hi How can I make the visibility of a variable across many methods or files? To avoid repeating the same line eg url = os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else os.environ['SERVER_NAME'] I repeat for many methods. So declaring it to a super class and inheriting it is my plan. Do you agree or propose otherwise? Thanks Niklas From bruno.desthuilliers at gmail.com Sat Sep 18 12:13:01 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Sat, 18 Sep 2010 09:13:01 -0700 (PDT) Subject: Learning inheritance References: Message-ID: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> On 18 sep, 17:25, Niklasro wrote: > Hi > How can I make the visibility of a variable across many methods or > files? To avoid repeating the same line eg ? ? url = > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > os.environ['SERVER_NAME'] First learn to use Python correctly: url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) => dict.get(key, default=None) Also and FWIW, neither HTTP_HOST not SERVER_NAME are really urls... > I repeat for many methods. So declaring it > to a super class and inheriting it is my plan. Do you agree or propose > otherwise? Not enough background to answer. From ethan at stoneleaf.us Sat Sep 18 12:16:12 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 09:16:12 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> Message-ID: <4C94E5CC.7060809@stoneleaf.us> Carl Karsten wrote: > On Sat, Sep 18, 2010 at 1:11 AM, Ethan Furman wrote: > >>Does anybody have any pointers, tips, web-pages, already written routines, >>etc, on parsing *.cdx files? I have found the pages on MS's sight for >>Foxpro, but they neglect to describe the compaction algorithm used, and my >>Google-fu has failed to find any sites with that information. >> >>Any and all help greatly appreciated! >> > > > "Compound Index File Structure (.cdx)" > > http://msdn.microsoft.com/en-us/library/k35b9hs2%28v=VS.80%29.aspx > > which basiclly links to: > http://msdn.microsoft.com/en-us/library/s8tb8f47%28v=VS.80%29.aspx > > Is that what you need? Thanks for the link, unfortunately I am already familiar with the page. What I need help with is the first sentence of the note at the bottom: Each entry consists of the record number, duplicate byte count and trailing byte count, all compacted. The key text is placed at the logical end of the node, working backwards, allowing for previous key entries. Here's a dump of the last interior node: ----- node type: 2 number of keys: 57 free space: 1 (or 256) (and is this bits, bytes, keys, what?) -- record number mask: c8 0e 40 b0 duplicate byte count mask: 28 trailing byte count mask: 00 -- bits used for record number: 178 bits used for duplicate count: 29 bits used for trail count: 64 bytes used for rec num, dup count, trail count: 192 ----- 12 00 ff 3f 00 00 1f 1f 0e 05 05 03 01 00 c8 0e 40 b0 28 00 b2 1d 40 c0 29 00 d0 42 40 d0 54 80 c0 43 40 a8 14 40 b8 40 40 c8 02 40 d0 08 00 b0 4c 80 b0 3a 40 a0 50 80 d0 3b 40 a8 09 40 b8 0a 80 88 3c 80 c0 2a 00 d8 21 c0 c0 3d 40 c0 4a 80 b0 26 40 b8 2b 40 c0 2c 00 c0 41 40 b8 4d 80 c8 37 00 c0 04 40 c8 44 80 c0 1b 40 c8 15 80 c8 27 40 c8 16 00 a8 2d c0 c8 51 80 b8 2e 40 c0 1e 00 b0 17 40 b8 46 40 b0 2f 80 c8 4f 80 a8 13 00 c8 59 00 c8 31 00 c8 1f 00 a8 3e 40 c0 22 40 a8 07 00 c8 23 80 d0 32 80 b0 52 80 c0 34 80 b0 20 40 b0 24 40 c0 47 80 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4e 44 45 4e 49 44 53 4f 4e 43 43 41 4d 4d 4f 4e 54 54 48 45 57 53 53 4c 45 4e 52 54 49 4e 45 5a 4e 4e 4d 41 47 45 45 49 45 42 45 52 4d 41 4e 45 57 49 4e 53 4c 41 56 45 4e 42 45 52 47 4b 41 56 41 4e 4a 4f 4e 45 53 49 52 49 53 48 53 54 45 54 4c 45 52 52 41 4e 4f 4c 53 54 45 49 4e 45 41 44 4c 45 59 48 41 54 48 41 57 41 59 52 49 4d 45 53 45 41 53 4f 4e 53 53 47 4c 41 44 53 54 4f 4e 45 55 52 52 59 4f 53 54 52 49 4e 4b 52 42 45 53 4f 4c 45 59 46 49 4c 45 4e 45 4e 49 53 4e 47 4c 55 4e 44 45 42 45 52 4c 45 4f 44 53 4f 4e 49 4e 47 4c 45 52 4d 41 52 45 53 54 45 43 4b 45 52 54 4f 4e 44 41 59 57 47 45 52 52 4e 45 49 4c 2d 53 55 4e 44 54 4f 4f 4b 53 45 59 4c 45 4e 44 45 4e 49 4e 55 4e 48 49 41 50 50 45 54 54 41 52 4e 41 48 41 4e 43 41 4c 44 57 45 4c 4c 55 54 54 52 55 43 45 4f 43 41 52 44 45 4c 4f 4f 4d 42 45 52 47 4e 53 45 4c 45 45 52 42 41 43 48 55 47 55 53 54 4e 44 45 52 53 4f 4e 41 4c 4c 41 4e ----- The last half (roughly) consists of last names compressed together, while the first half consists of 57 (in this case) entries of the record number, duplicate byte count and trailing byte count, all compacted -- how do I uncompact them? -- ~Ethan~ From lie.1296 at gmail.com Sat Sep 18 12:35:15 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 19 Sep 2010 02:35:15 +1000 Subject: Making logging.getLogger() simpler Message-ID: <4c94ea0d$1@dnews.tpgi.com.au> I was expecting this to work: import logging logger = logging.getLogger(__name__) logger.warn('this is a warning') instead it produced the error: No handlers could be found for logger "__main__" However, if instead I do: import logging logging.warn('creating logger') logger = logging.getLogger(__name__) logger.warn('this is a warning') then it does work. Is there any reason why getLogger()-created logger shouldn't automatically create a default handler? From carl at personnelware.com Sat Sep 18 13:15:22 2010 From: carl at personnelware.com (Carl Karsten) Date: Sat, 18 Sep 2010 12:15:22 -0500 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: <4C94E5CC.7060809@stoneleaf.us> References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> Message-ID: On Sat, Sep 18, 2010 at 11:16 AM, Ethan Furman wrote: > Carl Karsten wrote: >> >> On Sat, Sep 18, 2010 at 1:11 AM, Ethan Furman wrote: >> >>> Does anybody have any pointers, tips, web-pages, already written >>> routines, >>> etc, on parsing *.cdx files? ?I have found the pages on MS's sight for >>> Foxpro, but they neglect to describe the compaction algorithm used, and >>> my >>> Google-fu has failed to find any sites with that information. >>> >>> Any and all help greatly appreciated! >>> >> >> >> "Compound Index File Structure (.cdx)" >> >> http://msdn.microsoft.com/en-us/library/k35b9hs2%28v=VS.80%29.aspx >> >> which basiclly links to: >> http://msdn.microsoft.com/en-us/library/s8tb8f47%28v=VS.80%29.aspx >> >> Is that what you need? > > Thanks for the link, unfortunately I am already familiar with the page. > ?What I need help with is the first sentence of the note at the bottom: > > Each entry consists of the record number, duplicate byte count and > trailing byte count, all compacted. The key text is placed at the > logical end of the node, working backwards, allowing for previous key > entries. > > Here's a dump of the last interior node: > > ----- > node type: 2 > number of keys: 57 > free space: 1 (or 256) (and is this bits, bytes, keys, what?) > -- > record number mask: c8 0e 40 b0 > duplicate byte count mask: 28 > trailing byte count mask: 00 > -- > bits used for record number: 178 > bits used for duplicate count: 29 > bits used for trail count: 64 > bytes used for rec num, dup count, trail count: 192 > ----- > 12 00 ff 3f 00 00 1f 1f 0e 05 05 03 01 00 c8 0e 40 b0 28 00 > b2 1d 40 c0 29 00 d0 42 40 d0 54 80 c0 43 40 a8 14 40 b8 40 > 40 c8 02 40 d0 08 00 b0 4c 80 b0 3a 40 a0 50 80 d0 3b 40 a8 > 09 40 b8 0a 80 88 3c 80 c0 2a 00 d8 21 c0 c0 3d 40 c0 4a 80 > b0 26 40 b8 2b 40 c0 2c 00 c0 41 40 b8 4d 80 c8 37 00 c0 04 > 40 c8 44 80 c0 1b 40 c8 15 80 c8 27 40 c8 16 00 a8 2d c0 c8 > 51 80 b8 2e 40 c0 1e 00 b0 17 40 b8 46 40 b0 2f 80 c8 4f 80 > a8 13 00 c8 59 00 c8 31 00 c8 1f 00 a8 3e 40 c0 22 40 a8 07 > 00 c8 23 80 d0 32 80 b0 52 80 c0 34 80 b0 20 40 b0 24 40 c0 > 47 80 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 00 4e 44 45 4e 49 44 53 4f 4e 43 43 41 4d 4d 4f 4e 54 54 48 > 45 57 53 53 4c 45 4e 52 54 49 4e 45 5a 4e 4e 4d 41 47 45 45 > 49 45 42 45 52 4d 41 4e 45 57 49 4e 53 4c 41 56 45 4e 42 45 > 52 47 4b 41 56 41 4e 4a 4f 4e 45 53 49 52 49 53 48 53 54 45 > 54 4c 45 52 52 41 4e 4f 4c 53 54 45 49 4e 45 41 44 4c 45 59 > 48 41 54 48 41 57 41 59 52 49 4d 45 53 45 41 53 4f 4e 53 53 > 47 4c 41 44 53 54 4f 4e 45 55 52 52 59 4f 53 54 52 49 4e 4b > 52 42 45 53 4f 4c 45 59 46 49 4c 45 4e 45 4e 49 53 4e 47 4c > 55 4e 44 45 42 45 52 4c 45 4f 44 53 4f 4e 49 4e 47 4c 45 52 > 4d 41 52 45 53 54 45 43 4b 45 52 54 4f 4e 44 41 59 57 47 45 > 52 52 4e 45 49 4c 2d 53 55 4e 44 54 4f 4f 4b 53 45 59 4c 45 > 4e 44 45 4e 49 4e 55 4e 48 49 41 50 50 45 54 54 41 52 4e 41 > 48 41 4e 43 41 4c 44 57 45 4c 4c 55 54 54 52 55 43 45 4f 43 > 41 52 44 45 4c 4f 4f 4d 42 45 52 47 4e 53 45 4c 45 45 52 42 > 41 43 48 55 47 55 53 54 4e 44 45 52 53 4f 4e 41 4c 4c 41 4e > ----- > > The last half (roughly) consists of last names compressed together, > while the first half consists of 57 (in this case) entries of the record > number, duplicate byte count and trailing byte count, all compacted -- > how do I uncompact them? > huh, I see what you mean. What are you working on? I know a few people that may have the answer, but it would help to explain why it is being worked on. -- Carl K From ethan at stoneleaf.us Sat Sep 18 13:44:06 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 10:44:06 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> Message-ID: <4C94FA66.80008@stoneleaf.us> Carl Karsten wrote: > On Sat, Sep 18, 2010 at 11:16 AM, Ethan Furman wrote: > >>Carl Karsten wrote: >> >>>On Sat, Sep 18, 2010 at 1:11 AM, Ethan Furman wrote: >>> >>> >>>>Does anybody have any pointers, tips, web-pages, already written >>>>routines, >>>>etc, on parsing *.cdx files? I have found the pages on MS's sight for >>>>Foxpro, but they neglect to describe the compaction algorithm used, and >>>>my >>>>Google-fu has failed to find any sites with that information. >>>> >>>>Any and all help greatly appreciated! >>>> >>> >>> >>>"Compound Index File Structure (.cdx)" >>> >>>http://msdn.microsoft.com/en-us/library/k35b9hs2%28v=VS.80%29.aspx >>> >>>which basiclly links to: >>>http://msdn.microsoft.com/en-us/library/s8tb8f47%28v=VS.80%29.aspx >>> >>>Is that what you need? >> >>Thanks for the link, unfortunately I am already familiar with the page. >> What I need help with is the first sentence of the note at the bottom: >> >>Each entry consists of the record number, duplicate byte count and >>trailing byte count, all compacted. The key text is placed at the >>logical end of the node, working backwards, allowing for previous key >>entries. >> >>Here's a dump of the last interior node: >> >>----- >>node type: 2 >>number of keys: 57 >>free space: 1 (or 256) (and is this bits, bytes, keys, what?) >>-- >>record number mask: c8 0e 40 b0 >>duplicate byte count mask: 28 >>trailing byte count mask: 00 >>-- >>bits used for record number: 178 >>bits used for duplicate count: 29 >>bits used for trail count: 64 >>bytes used for rec num, dup count, trail count: 192 >>----- >>12 00 ff 3f 00 00 1f 1f 0e 05 05 03 01 00 c8 0e 40 b0 28 00 >>b2 1d 40 c0 29 00 d0 42 40 d0 54 80 c0 43 40 a8 14 40 b8 40 >>40 c8 02 40 d0 08 00 b0 4c 80 b0 3a 40 a0 50 80 d0 3b 40 a8 >>09 40 b8 0a 80 88 3c 80 c0 2a 00 d8 21 c0 c0 3d 40 c0 4a 80 >>b0 26 40 b8 2b 40 c0 2c 00 c0 41 40 b8 4d 80 c8 37 00 c0 04 >>40 c8 44 80 c0 1b 40 c8 15 80 c8 27 40 c8 16 00 a8 2d c0 c8 >>51 80 b8 2e 40 c0 1e 00 b0 17 40 b8 46 40 b0 2f 80 c8 4f 80 >>a8 13 00 c8 59 00 c8 31 00 c8 1f 00 a8 3e 40 c0 22 40 a8 07 >>00 c8 23 80 d0 32 80 b0 52 80 c0 34 80 b0 20 40 b0 24 40 c0 >>47 80 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >>00 4e 44 45 4e 49 44 53 4f 4e 43 43 41 4d 4d 4f 4e 54 54 48 >>45 57 53 53 4c 45 4e 52 54 49 4e 45 5a 4e 4e 4d 41 47 45 45 >>49 45 42 45 52 4d 41 4e 45 57 49 4e 53 4c 41 56 45 4e 42 45 >>52 47 4b 41 56 41 4e 4a 4f 4e 45 53 49 52 49 53 48 53 54 45 >>54 4c 45 52 52 41 4e 4f 4c 53 54 45 49 4e 45 41 44 4c 45 59 >>48 41 54 48 41 57 41 59 52 49 4d 45 53 45 41 53 4f 4e 53 53 >>47 4c 41 44 53 54 4f 4e 45 55 52 52 59 4f 53 54 52 49 4e 4b >>52 42 45 53 4f 4c 45 59 46 49 4c 45 4e 45 4e 49 53 4e 47 4c >>55 4e 44 45 42 45 52 4c 45 4f 44 53 4f 4e 49 4e 47 4c 45 52 >>4d 41 52 45 53 54 45 43 4b 45 52 54 4f 4e 44 41 59 57 47 45 >>52 52 4e 45 49 4c 2d 53 55 4e 44 54 4f 4f 4b 53 45 59 4c 45 >>4e 44 45 4e 49 4e 55 4e 48 49 41 50 50 45 54 54 41 52 4e 41 >>48 41 4e 43 41 4c 44 57 45 4c 4c 55 54 54 52 55 43 45 4f 43 >>41 52 44 45 4c 4f 4f 4d 42 45 52 47 4e 53 45 4c 45 45 52 42 >>41 43 48 55 47 55 53 54 4e 44 45 52 53 4f 4e 41 4c 4c 41 4e >>----- >> >>The last half (roughly) consists of last names compressed together, >>while the first half consists of 57 (in this case) entries of the record >>number, duplicate byte count and trailing byte count, all compacted -- >>how do I uncompact them? >> > > > huh, I see what you mean. > > What are you working on? > > I know a few people that may have the answer, but it would help to > explain why it is being worked on. > > I have a pure-python module to read db3 and vfp 6 dbf files, and I find that I need to read (and write) the idx and cdx index files that foxpro generates. We are in the process of switching from homegrown foxpro apps to homegrown python apps, but I have to support the foxpro file formats until the switch is complete. Once I have the index files down, I'll publish another release of it (an older version can be found on PyPI). Thanks for your help! -- ~Ethan~ From nad at acm.org Sat Sep 18 14:28:57 2010 From: nad at acm.org (Ned Deily) Date: Sat, 18 Sep 2010 11:28:57 -0700 Subject: [OS X 10.5] hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Ned Deily > wrote: > > try: > > import readline > > except ImportError: > > print("Module readline not available.") > > else: > > import rlcompleter > > readline.parse_and_bind("tab: complete") > > > > Note the print() form which works with either Python 2 or 3. > You should be writing diagnostics to stderr, not stdout. In general, sure. Statements in a PYTHONSTARTUP file, like here, are only executed in interactive mode and it isn't likely that someone is going to be redirecting stdout or stderr; that would kind of defeat the purpose of readline completion functions which is what this is all about. But, if you feel strongly about it, I'm sure a contributed patch to improve the rlcompleter documentation would be welcome. -- Ned Deily, nad at acm.org From vlastimil.brom at gmail.com Sat Sep 18 17:00:25 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 18 Sep 2010 23:00:25 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: <4C92A584.8060303@mrabarnett.plus.com> <4C92B3BC.6090901@mrabarnett.plus.com> Message-ID: 2010/9/18 Dennis Lee Bieber : > On Sat, 18 Sep 2010 10:48:44 +0200, Vlastimil Brom > declaimed the following in > gmane.comp.python.general: > >> >> http://mail.python.org/pipermail/python-list/2008-May/540773.html >> > ? ? ? ?Ah, based on that listing you are not worried about embedded tags; > your tags all come at the start of the line (and I presume are > terminated by the end of line). I'd thought you needed actual positions > /in/ the line... You can drop the start/end fields and stuff the tag > attribute into supplement (on SQLite this becomes even simpler since > even if you define supplement to be integer, SQLite will happily store a > text value -- a full type checking RDBM would require either making it a > text field and storing numeric values as text, or using a pair of fields > for numeric vs text). > > ? ? ? ?Tricky part may be how you handle the display markup -- you seem to > have a split over two lines... Is that significant? > >... > ? ? ? ?Of course, all the search terms can be parameterized when > programming... > > cur.execute("""select t.ID, tg.supplement, t.text from texts as t > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?inner join tags as tg > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?on tg.textID = t.ID > ? ? ? ? ? ? ? ? ? ? ? ?where t.text like ? and tg.type = ?""", > ? ? ? ? ? ? ? ? ? ? ? ?("%den%", "VN")) > > results = cur.fetchall() > > should return (a Python list of one tuple, in this case): > > [(1, "rn_1_vers_1", "wi den L...n")] > -- > ? ? ? ?Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ?wlfraed at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ > Thank you very much for detailed hints, I see, I should have mention the specification with my initial post... It is true, that nested tags of the same name aren't supported, but tags may appear anywhere in the text and aren't terminated with newline. The tag-value association is valid from the tag position until the next tag replacing the value or closing tag (like ) or to the end of the text file. Tags beginning at line beginnings are rather frequent, but they can appear anywhere else too. I actually only store the metadata in the database - i.e. the tag-value combinations for the corresponding text indices of the plain text. The database doesn't currently contain the text itself; plain text is used for fulltext regexp search, and it should be possible to find the relevant tags for the matches. I'll have a closer look on joins in sql and maybe redesign the data structure - now the tags data are copied for each text position with some tag change - in order to simplify queries; with multiple tables it could be more efficient to store the tags separately and look it up individually (probably using bisect (unless there is an SQL equivalent ?) Well, I still have many areas to investigate in this context ... regards, Vlastimil Brom From python at bdurham.com Sat Sep 18 17:24:32 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 18 Sep 2010 17:24:32 -0400 Subject: Standard library function to remove folder with files and subfolders? Message-ID: <1284845072.7300.1395698357@webmail.messagingengine.com> Is there a standard library function to remove a folder that may contain files and subfolders? Or must I write a function that walks my folder's children and deletes all files/subfolders first, and then call os.removedirs()? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sat Sep 18 17:36:49 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 18 Sep 2010 17:36:49 -0400 Subject: Standard library function to remove folder with files and subfolders? In-Reply-To: <1284845072.7300.1395698357@webmail.messagingengine.com> References: <1284845072.7300.1395698357@webmail.messagingengine.com> Message-ID: <950D062E-08C7-4190-A67F-241FDEE10EF3@semanchuk.com> On Sep 18, 2010, at 5:24 PM, python at bdurham.com wrote: > Is there a standard library function to remove a folder that may > contain files and subfolders? Or must I write a function that > walks my folder's children and deletes all files/subfolders > first, and then call os.removedirs()? In Python 2.x: shutil.rmtree() Might have moved in Python 3.x. HTH Philip From usenet-nospam at seebs.net Sat Sep 18 18:56:51 2010 From: usenet-nospam at seebs.net (Seebs) Date: 18 Sep 2010 22:56:51 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-18, Steven D'Aprano wrote: > On Fri, 17 Sep 2010 16:01:54 -0400, Andreas Waldenburger wrote: >> On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: >>> I also like this construct that works, I think, since 2.6: >>> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] >> I wonder when this construct will finally start to look good. > It looks good to me. It follows a common English idiom: > "What are you doing tonight?" > "I'll be going to the movies, if I finish work early, otherwise I'll stay > home and watch a DVD." I hate that idiom in English, too. If you're going to give me a forking conditional, I want to know about it early. Basically, I can handle do x if y pretty well, but do x if y else z always breaks my parser. So in English, I might say "I'll go to the store if I have time", but I'd rarely use "I'll go to the store if I have time, otherwise I'll send the house elf"; instead, I'd say "If I have time, I'll go to the store, otherwise I'll send the house elf." -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 Sat Sep 18 19:08:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Sep 2010 19:08:57 -0400 Subject: Why IterableUserDict? In-Reply-To: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> References: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 9/17/2010 11:12 PM, Steven D'Aprano wrote: > I was writing some tests for a mapping class I have made, and I decided > to run those same tests over dict and UserDict. The built-in dict passed > all the tests, but UserDict failed one: You forgot to specify Python version ;-). > > class SimpleMappingTest(unittest.TestCase): > type2test = UserDict.UserDict In 3.x, collections.UserDict > def test_iter(self): > k, v = [0, 1, 2, 3], 'abcd' > m = self.type2test(zip(k, v)) > it = iter(m) > self.assert_(iter(it) is it) > self.assertEquals(sorted(it), k) # This line fails. Not in 3.x import collections k, v = [0, 1, 2, 3], 'abcd' m = collections.UserDict(zip(k, v)) it = iter(m) assert iter(it) is it assert sorted(it) == k runs clean. > If I look at the source code for the UserDict module, I discover that > there's a second mapping class, IterableUserDict, Not any more. One of numerous 3.x cleanups made possible by dropping obsessive back compatibility, which, as Peter explained, wan the reason for the hack. -- Terry Jan Reedy From grahn+nntp at snipabacken.se Sat Sep 18 19:15:05 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 18 Sep 2010 23:15:05 GMT Subject: Learning inheritance References: Message-ID: On Sat, 2010-09-18, Niklasro wrote: > Hi > How can I make the visibility of a variable across many methods or > files? To avoid repeating the same line eg url = > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > os.environ['SERVER_NAME'] I repeat for many methods. So declaring it > to a super class and inheriting it is my plan. Do you agree or propose > otherwise? Inheritance is not the main tool for sharing code. Just make it a function and place it in one of your modules (files): def get_host(): """Return the environment's $HTTP_HOST if it exists, otherwise $SERVER_NAME or (if that doesn't exist either) None. """ ... Perhaps you are focusing too much on inheritance in general. I personally almost never use it in Python -- it has much fewer uses here than in staticaly typed languages. /Jorgen -- // Jorgen Grahn O o . From niklasro at gmail.com Sat Sep 18 19:19:56 2010 From: niklasro at gmail.com (Niklasro) Date: Sat, 18 Sep 2010 16:19:56 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> Message-ID: <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> On Sep 18, 4:13?pm, "bruno.desthuilli... at gmail.com" wrote: > On 18 sep, 17:25, Niklasro wrote: > > > Hi > > How can I make the visibility of a variable across many methods or > > files? To avoid repeating the same line eg ? ? url = > > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > > os.environ['SERVER_NAME'] > > First learn to use Python correctly: > > url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) > > => dict.get(key, default=None) > > Also and FWIW, neither HTTP_HOST not SERVER_NAME are really urls... > > > I repeat for many methods. So declaring it > > to a super class and inheriting it is my plan. Do you agree or propose > > otherwise? > > Not enough background to answer. Thanks for replying and informing correctness. More background is the variable I want accessible for many functions and files either is HTTP_HOST or SERVER_NAME used as beginning of url or resource locator indicated where the software is used. Instead of declaring the variable many times feasibility study is how to minify number of times I declare the same variable. I got 2 files main.py and i18n both with webapp request handlers which I would like access the variable. Thanks Niklas R From grahn+nntp at snipabacken.se Sat Sep 18 19:29:33 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 18 Sep 2010 23:29:33 GMT Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Sat, 2010-09-18, Lawrence D'Oliveiro wrote: > In message > <2f830099-4264-47bc-98ee-31950412ad43 at q21g2000prm.googlegroups.com>, cerr > wrote: > >> I get a socket error "[Errno 98] Address already in use" when i try to >> open a socket that got closed before with close(). How come close() >> doesn't close the socket properly? > > The usual case this happens is you have a client connection open at the > time, that was not properly terminated. Then the TCP stack goes through a > holdoff period (2 minutes, I believe it is), to make absolutely sure all > packets destined for the old connection have completely disappeared off the > entire Internet, before it will let you open a socket on the same port > again. That's why Stevens recommends that all TCP servers use the SO_REUSEADDR socket option. He also noted in his book: "This scenario is one of the most frequently asked questions on Usenet." Possibly I missed something in the question, but it's worth googling for. /Jorgen -- // Jorgen Grahn O o . From andrei.avk at gmail.com Sat Sep 18 19:31:44 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 19:31:44 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C954BE0.700@gmail.com> On 09/18/2010 06:56 PM, Seebs wrote: > On 2010-09-18, Steven D'Aprano wrote: >> On Fri, 17 Sep 2010 16:01:54 -0400, Andreas Waldenburger wrote: >>> On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: >>>> I also like this construct that works, I think, since 2.6: > >>>> code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > >>> I wonder when this construct will finally start to look good. > >> It looks good to me. It follows a common English idiom: > >> "What are you doing tonight?" >> "I'll be going to the movies, if I finish work early, otherwise I'll stay >> home and watch a DVD." > > I hate that idiom in English, too. If you're going to give me a forking > conditional, I want to know about it early. > > Basically, I can handle > do x if y > pretty well, but > do x if y else z > always breaks my parser. > > So in English, I might say "I'll go to the store if I have time", but > I'd rarely use "I'll go to the store if I have time, otherwise I'll send > the house elf"; instead, I'd say "If I have time, I'll go to the store, > otherwise I'll send the house elf." > > -s I actually find the shorter version slightly more readable than full version. I think in English you'd say it in one sentence and that to me feels like it should vaguely correspond to one line in code (perhaps split over more than one line but that'd be due to long var names or complex operations, not inherently). The longer version may be like saying "I'll go to the store. If I have time. If I don't have time. I will send the house elf." It's a bit more readable to me because I can tell at a glance that a single variable gets assigned a value based on a condition. With a longer version it looks like something more complicated it going on, and the eye has to look at all four lines and jump to another ident level. By the way, it also looks far more readable in an editor where if and else would be highlighted vs. all in plain colour. -ak From grahn+nntp at snipabacken.se Sat Sep 18 19:33:58 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 18 Sep 2010 23:33:58 GMT Subject: The trouble with "dynamic attributes". References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4C92A7CC.8000505@mrabarnett.plus.com> <2e749113-5c9f-475e-85e5-f6c787559572@a30g2000vbt.googlegroups.com> Message-ID: On Fri, 2010-09-17, James Mills wrote: > On Fri, Sep 17, 2010 at 11:33 AM, moerchendiser2k3 > wrote: >> I am really sorry, but what are you talking about ? Hmmm, ...I have >> problems to compile Python on SL, I did not ask anything about >> "dynamic attribute". I don't get it... > > You are subscribed to the python mailing list. > > Check your subscription status with the link below. JN's posting was technically a reply to JM's SL question -- a References: header led back to it. That's why he was confused. /Jorgen -- // Jorgen Grahn O o . From usenet-nospam at seebs.net Sat Sep 18 19:38:19 2010 From: usenet-nospam at seebs.net (Seebs) Date: 18 Sep 2010 23:38:19 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-18, AK wrote: > On 09/18/2010 06:56 PM, Seebs wrote: >> Basically, I can handle >> do x if y >> pretty well, but >> do x if y else z >> always breaks my parser. >> So in English, I might say "I'll go to the store if I have time", but >> I'd rarely use "I'll go to the store if I have time, otherwise I'll send >> the house elf"; instead, I'd say "If I have time, I'll go to the store, >> otherwise I'll send the house elf." > I actually find the shorter version slightly more readable than full > version. I think in English you'd say it in one sentence and that to me > feels like it should vaguely correspond to one line in code (perhaps > split over more than one line but that'd be due to long var names or > complex operations, not inherently). I dunno, it always breaks my parser. The condition ends up between the two dependents, and that doesn't work for me. I can have conditions which are leading or trailing, but not infix. > It's a bit more readable to me because I can tell at a glance that a > single variable gets assigned a value based on a condition. With a > longer version it looks like something more complicated it going on, and > the eye has to look at all four lines and jump to another ident level. Ahh! I see. There's several variants that could be discussed. if condition: x = y else: x = z x = y if condition else z And then the one I'm used to from other languages: x = if condition then y else z The other thing, from my point of view, is an ambiguity with a common idiom I'm used to, again from other languages: x = y if condition If !condition, then nothing happens to x. So far as I can tell, that's a syntax error in Python -- I can't use postfix if to modify a sentence, because it's an expression thing. > By the way, it also looks far more readable in an editor where if and > else would be highlighted vs. all in plain colour. I use syntax coloring in programming languages precisely as often, and for precisely the same reasons, that I use it when writing in English. Which is to say, if such a feature exists, I turn it off immediately because it consistently distracts me from following the actual meaning of code. Syntax is the least part of the meaning of code; giving extra weight to syntax is pretty disruptive, IMHO. -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 andrei.avk at gmail.com Sat Sep 18 20:00:32 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 20:00:32 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C9552A0.1060406@gmail.com> On 09/18/2010 07:38 PM, Seebs wrote: > On 2010-09-18, AK wrote: >> On 09/18/2010 06:56 PM, Seebs wrote: >>> Basically, I can handle >>> do x if y >>> pretty well, but >>> do x if y else z >>> always breaks my parser. > >>> So in English, I might say "I'll go to the store if I have time", but >>> I'd rarely use "I'll go to the store if I have time, otherwise I'll send >>> the house elf"; instead, I'd say "If I have time, I'll go to the store, >>> otherwise I'll send the house elf." > >> I actually find the shorter version slightly more readable than full >> version. I think in English you'd say it in one sentence and that to me >> feels like it should vaguely correspond to one line in code (perhaps >> split over more than one line but that'd be due to long var names or >> complex operations, not inherently). > > I dunno, it always breaks my parser. The condition ends up between > the two dependents, and that doesn't work for me. I can have conditions > which are leading or trailing, but not infix. > >> It's a bit more readable to me because I can tell at a glance that a >> single variable gets assigned a value based on a condition. With a >> longer version it looks like something more complicated it going on, and >> the eye has to look at all four lines and jump to another ident level. > > Ahh! I see. There's several variants that could be discussed. > > if condition: > x = y > else: > x = z > > x = y if condition else z > > And then the one I'm used to from other languages: > > x = if condition then y else z > > The other thing, from my point of view, is an ambiguity with a common > idiom I'm used to, again from other languages: > > x = y if condition > > If !condition, then nothing happens to x. So far as I can tell, that's > a syntax error in Python -- I can't use postfix if to modify a sentence, > because it's an expression thing. > >> By the way, it also looks far more readable in an editor where if and >> else would be highlighted vs. all in plain colour. > > I use syntax coloring in programming languages precisely as often, and > for precisely the same reasons, that I use it when writing in English. > Which is to say, if such a feature exists, I turn it off immediately > because it consistently distracts me from following the actual meaning > of code. Syntax is the least part of the meaning of code; giving extra > weight to syntax is pretty disruptive, IMHO. Funny that you should say that, because I thought quite a few times that it would be really awesome if some texts in English had syntax highlighting. Obviously, not Brothers Karamazov, but something like a tutorial, or a manual, or an online article. If key words were highlighted, I'd be able to quickly glance over parts that are not useful to me at the time, and find the interesting bits. For instance, in the above paragraph I'd highlight 'awesome', 'English', 'syntax highlighting', 'tutorial', 'manual', 'online article', 'quickly glance over', 'not useful', 'find', 'interesting bits'. It'd be like speed reading, except real! -ak From ldo at geek-central.gen.new_zealand Sat Sep 18 20:27:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 12:27:08 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message , Jorgen Grahn wrote: > That's why Stevens recommends that all TCP servers use the > SO_REUSEADDR socket option. I don?t think I?ve ever used that. It seems to defeat a safety mechanism which was put in for a reason. From usenet-nospam at seebs.net Sat Sep 18 20:35:14 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 00:35:14 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, AK wrote: > Funny that you should say that, because I thought quite a few times that > it would be really awesome if some texts in English had syntax > highlighting. Obviously, not Brothers Karamazov, but something like a > tutorial, or a manual, or an online article. If key words were > highlighted, I'd be able to quickly glance over parts that are not > useful to me at the time, and find the interesting bits. That wouldn't be *syntax* highlighting, that'd be *semantic* highlighting. Which people often do -- notice that I did it twice in that paragraph. But that's the point -- you need to know what it *means* to make sensible decisions about what to highlight. Syntax highlighting is precisely the opposite, highlighting things for reasons that have nothing to do with their semantic content. It distracts from the actual meaning of the code. In short, syntax highlighting would be like writing: FUNNY *that* _you_ *should* /say/ *that*. > It'd be like speed reading, except real! I don't understand this. So far as I know, the phrase "speed reading" refers to various methods of reading much faster than most people read, and is real but not exceptionally interesting. -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 pavlovevidence at gmail.com Sat Sep 18 20:35:14 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 18 Sep 2010 17:35:14 -0700 (PDT) Subject: Learning inheritance References: Message-ID: <77705adb-48d5-4b3d-9398-feb27dee16b7@y32g2000prc.googlegroups.com> On Sep 18, 4:15?pm, Jorgen Grahn wrote: > On Sat, 2010-09-18, Niklasro wrote: > > Hi > > How can I make the visibility of a variable across many methods or > > files? To avoid repeating the same line eg ? ? url = > > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > > os.environ['SERVER_NAME'] I repeat for many methods. So declaring it > > to a super class and inheriting it is my plan. Do you agree or propose > > otherwise? > > Inheritance is not the main tool for sharing code. That statement might be a little too general to be true. Inheritance is a (or the) main tool for different objects to share behavior, which is implemented by code. So when your program is organized around objects, it is the (or a) main tool. You are right that you shouldn't rework your code into an OO style simply because you want to share code. I think that's what you meant. > Just make it a > function and place it in one of your modules (files): Or even just make it a global variable in the module (which would work in this case, unless you plan to update the environment within the program). Carl Banks From andrei.avk at gmail.com Sat Sep 18 21:58:58 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 21:58:58 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C956E62.4070001@gmail.com> On 09/18/2010 08:35 PM, Seebs wrote: > On 2010-09-19, AK wrote: >> Funny that you should say that, because I thought quite a few times that >> it would be really awesome if some texts in English had syntax >> highlighting. Obviously, not Brothers Karamazov, but something like a >> tutorial, or a manual, or an online article. If key words were >> highlighted, I'd be able to quickly glance over parts that are not >> useful to me at the time, and find the interesting bits. > > That wouldn't be *syntax* highlighting, that'd be *semantic* highlighting. In case of programming, the effect is similar. I find that it allows me to look quickly through code, scanning for something specific, e.g. the next function, the next if/else block. If I'm looking for a print statement, for example, I can quickly scan a whole screenful, looking for a first highlighted long word (all the other highlighted keywords will usually be if, else, and for). On the other hand, if I know I'm looking for a variable, my eyes will filter out all the highlighted text - strings and keywords. English is of course much less formal so you have to understand the text to do useful highlighting. Anyway, I find it very odd that anyone would not find it extremely useful (in code)! > > Which people often do -- notice that I did it twice in that paragraph. But > that's the point -- you need to know what it *means* to make sensible > decisions about what to highlight. Syntax highlighting is precisely the > opposite, highlighting things for reasons that have nothing to do with > their semantic content. It distracts from the actual meaning of the > code. I'm not always looking for meaning *immediately*. If I know there's a single print statement in a function, I don't need to understand its meaning to know that's the one print statement I need. (Or, if there's two, I might know that I need the first one or at least I'll have 2 lines to look at instead of 75). > > In short, syntax highlighting would be like writing: > > FUNNY *that* _you_ *should* /say/ *that*. > >> It'd be like speed reading, except real! > > I don't understand this. So far as I know, the phrase "speed reading" > refers to various methods of reading much faster than most people read, > and is real but not exceptionally interesting. Afaik the idea is that you can read a novel at the speed of half a page a second or so and understand it to the same extent as people who'd read at a normal rate. Woody Allen joke: "I learned speed reading and read War&Peace"; - it involves Russia. -ak From pavlovevidence at gmail.com Sat Sep 18 22:00:09 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 18 Sep 2010 19:00:09 -0700 (PDT) Subject: ctypes and buffers Message-ID: I am creating a ctypes buffer from an existing non-ctypes object that supports buffer protocol using the following code: from ctypes import * PyObject_AsReadBuffer = pythonapi.PyObject_AsReadBuffer PyObject_AsReadBuffer.argtypes = [py_object,POINTER(c_void_p),POINTER(c_size_t)] PyObject_AsReadBuffer.restype = None def ctypes_buffer_from_buffer(buf): cbuf = c_void_p() size = c_size_t() PyObject_AsReadBuffer(buf,byref(cbuf),byref(size)) return cbuf It works, but is there a standard way to do this in ctypes? I couldn't find anything in the documentation. Python 2.6 for now. Thanks. Carl Banks From andrei.avk at gmail.com Sat Sep 18 22:04:26 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 22:04:26 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4C9552A0.1060406@gmail.com> Message-ID: <4C956FAA.2020401@gmail.com> On 09/18/2010 09:08 PM, Dennis Lee Bieber wrote: > On Sat, 18 Sep 2010 20:00:32 -0400, AK declaimed > the following in gmane.comp.python.general: > > >> Funny that you should say that, because I thought quite a few times that >> it would be really awesome if some texts in English had syntax >> highlighting. Obviously, not Brothers Karamazov, but something like a >> tutorial, or a manual, or an online article. If key words were >> highlighted, I'd be able to quickly glance over parts that are not >> useful to me at the time, and find the interesting bits. >> >> For instance, in the above paragraph I'd highlight 'awesome', 'English', >> 'syntax highlighting', 'tutorial', 'manual', 'online article', >> 'quickly glance over', 'not useful', 'find', 'interesting bits'. >> > > Syntax highlighting is more likely to identify: be, if, had, but, > like, or, were, are, not, and. That is, the (relatively) fixed > connectors between arbitrary nouns and concepts. > > be if had. > not, but like, or. If > were are not, and Yes, I didn't mean that it's exactly the same, of course. Python being much more formal than English means automatic syntax highlight can be useful, as obviously many people find it; although this gave me an interesting idea: if you had a long text that you wished to read quickly, it might be more efficient to do syntax highlight of all verbs, quickly scan through the text, then syntax highlight of all nouns, do another quick scan, and then turn off syntax highlight and concentrate on the parts that you did not understand while scanning. Is there a program that'd do something like that? -ak From pavlovevidence at gmail.com Sat Sep 18 22:09:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> Message-ID: <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> On Sep 17, 1:01?pm, Andreas Waldenburger wrote: > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > > > I also like this construct that works, I think, since 2.6: > > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > I wonder when this construct will finally start to look good. I don't know if it'll ever look good, per se, but it looks better when it's used in rule-exception sort of case: something = rule if condition else exception Then the "tacked-on" feel the "if condition else exception" part works because it is actually tacked on. Apart from occasions like this and throwaway one-liners I use regular if-then statements. If Python had added the C-like a ? b : c, then I'd use it a lot more, since that version is not inherently unbalanced. Carl Banks From usenet-nospam at seebs.net Sat Sep 18 22:12:58 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 02:12:58 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, AK wrote: > On 09/18/2010 08:35 PM, Seebs wrote: >> That wouldn't be *syntax* highlighting, that'd be *semantic* highlighting. > In case of programming, the effect is similar. I have not found that to be the case. It's been exactly the same as syntax highlighting in English would be -- it's wasting bandwidth telling me things I already know, which slows down my perception of the things I'm trying to find out. Hmm. Actually, one thing -- I think I sometimes find it useful for a couple of days on a new language I don't know yet. It's helpful then, but once I've got my parser trained, it's a distraction. > Anyway, I find it > very odd that anyone would not find it extremely useful (in code)! Yes, and I find it inexplicable that people find it useful. News flash: Not all people think the same way. Film at 11. :) I've tried to use syntax coloring editors, and I've always found that they end up making me slower and less accurate at reading things, because what they're highlighting isn't waht what I need to know. >> I don't understand this. So far as I know, the phrase "speed reading" >> refers to various methods of reading much faster than most people read, >> and is real but not exceptionally interesting. > Afaik the idea is that you can read a novel at the speed of half a page > a second or so and understand it to the same extent as people who'd read > at a normal rate. Woody Allen joke: "I learned speed reading and > read War&Peace"; - it involves Russia. I dunno about that speed, but as I recall, my default reading speed for English is about the range that people advertise in "speed reading" courses, and I end up understanding text about as well as other people do. -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 fridge at micro.com Sat Sep 18 22:23:15 2010 From: fridge at micro.com (fridge) Date: Sun, 19 Sep 2010 12:23:15 +1000 Subject: Plz comment on this code Message-ID: <4c957412$0$3036$afc38c87@news.optusnet.com.au> # bigdigits2.py import sys zero=["***", "* *", "***"] one=["***", " * ", "***"] digits=[zero,one,zero,one,zero,one,zero,one,zero,one] inputted_digit=sys.argv[1] column_max=len(inputted_digit) row_max=3 r=0 while r<3: line="" c=0 while c From wuwei23 at gmail.com Sat Sep 18 22:31:39 2010 From: wuwei23 at gmail.com (alex23) Date: Sat, 18 Sep 2010 19:31:39 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> Message-ID: Niklasro wrote: > I got 2 files main.py and i18n both with > webapp request handlers which I would like access the variable. I'd probably use a module for this. Create a third file, called something like shared.py, containing the line that bruno gave above: url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) Then from within both main & i18n you can 'import shared' and access the variable as 'shared.url'. Python only actually executes a module the first time it's imported, every other import will be given a reference to the same module object. This also lets you share temporary data between modules. Any module that imports 'shared' can add an attribute to it ('shared.foo = "barbaz"') that will be visible to all other modules that have (or will have) imported it. From andrei.avk at gmail.com Sat Sep 18 22:49:29 2010 From: andrei.avk at gmail.com (AK) Date: Sat, 18 Sep 2010 22:49:29 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4C957A39.6070105@gmail.com> On 09/18/2010 10:12 PM, Seebs wrote: > On 2010-09-19, AK wrote: >> On 09/18/2010 08:35 PM, Seebs wrote: News flash: Not all people think the same way. Film at 11. :) > > I've tried to use syntax coloring editors, and I've always found that > they end up making me slower and less accurate at reading things, > because what they're highlighting isn't waht what I need to know. The way I see it, it's not meant to tell you something, it's punctuation, it's as if you'd argue against periods and spaces at the end of sentencesBecause the next sentence is capitalized anyway, so you already know the last sentence ended. In the same way, in many cases other punctuation is not absolutely necessary for understanding. The other thing is of course that it helps you not to name your variables using keywords and spot misspelled keywords. -ak From jason.swails at gmail.com Sat Sep 18 22:52:05 2010 From: jason.swails at gmail.com (Jason Swails) Date: Sat, 18 Sep 2010 22:52:05 -0400 Subject: Plz comment on this code In-Reply-To: <4c957412$0$3036$afc38c87@news.optusnet.com.au> References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: On Sat, Sep 18, 2010 at 10:23 PM, fridge wrote: > # bigdigits2.py > ^ Here is the comment > > import sys > > zero=["***", > "* *", > "***"] > one=["***", > " * ", > "***"] > digits=[zero,one,zero,one,zero,one,zero,one,zero,one] > > inputted_digit=sys.argv[1] > column_max=len(inputted_digit) > row_max=3 > > r=0 > while r<3: > line="" > c=0 > while c digit_i=int(inputted_digit[c]) > digit=digits[digit_i] > line+=digit[r] > line+=" " > c+=1 > print(line) > r+=1 > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Sep 18 23:01:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 03:01:59 GMT Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: <4c957d27$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 12:23:15 +1000, fridge wrote: > # bigdigits2.py [snip code] It looks like Python. Did you have a specific question? P.S. Please don't send HTML to non-binary news groups, it's very annoying. And if you're sending it by email, your mail client appears to be broken, because it's just dumping the HTML code after the plain text. > > > [and much more HTML junk] P.P.S. If you can't even be bothered to spell "Please" in full, you probably shouldn't expect many people to be bothered to read your code in detail and comment extensively. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Sep 18 23:20:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 03:20:38 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> Message-ID: <4c958185$0$11113$c3e8da3@news.astraweb.com> On Sat, 18 Sep 2010 19:09:33 -0700, Carl Banks wrote: > Apart from occasions like this and throwaway one-liners I use regular > if-then statements. If Python had added the C-like a ? b : c, then I'd > use it a lot more, since that version is not inherently unbalanced. Define "unbalanced". Putting aside the over-use of punctuation, The C syntax feels unbalanced to me. You have: condition IF true-clause ELSE false-clause so both clauses follow the test, that is, they're on the same side: ?-- This looks unbalanced to me. And it reads like something Yoda would say, or Forth code. But the Python syntax looks balanced to me: true-clause IF condition ELSE false-clause which is not only plain English, but perfectly balanced, with a clause on either side of the test: -?- Python's ternary-if puts the emphasis on the true-clause, while C's ternary-if puts the emphasis on the test. I'm not convinced that this is necessarily a better choice than Python's. It's a *valid* choice, but better? I don't think so, but I accept that at least partially boils down to subjective factors. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Sep 18 23:28:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 03:28:48 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c958370$0$11113$c3e8da3@news.astraweb.com> On Sat, 18 Sep 2010 21:58:58 -0400, AK wrote: >> I don't understand this. So far as I know, the phrase "speed reading" >> refers to various methods of reading much faster than most people read, >> and is real but not exceptionally interesting. > > Afaik the idea is that you can read a novel at the speed of half a page > a second or so and understand it to the same extent as people who'd read > at a normal rate. Woody Allen joke: "I learned speed reading and read > War&Peace"; - it involves Russia. My wife can read scarily fast. It's very something to watch her reading pages as fast as she can turn them, and a few years ago she read the entire Harry Potter series (to date) in one afternoon, and could gives a blow-by-blow account of the plots, including a detailed critique of the writing style and characters. But then, she feels that reading the Potter series is a chore to be completed as fast as possible, rather than a pleasure to be savored. She'll sometimes drag a new Terry Pratchett or Stephen King novel out for as much as two days. -- Steven From ethan at stoneleaf.us Sun Sep 19 00:23:21 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 21:23:21 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> Message-ID: <4C959039.5070700@stoneleaf.us> Vernon Cole wrote: > Ethan: > I cannot see where you mentioned your operating system, I am assuming > Windows. > > Perhaps you have already investigated this ... I have no way to test it > ... but you might try: > ADO can access almost any data source, and a quick look seems to show > that .dbf is supported using the JET driver or a FoxPro driver. > > 1) upload pywin32 > 2) import adodbapi > 3) find an appropriate connection string for your data source > http://connectionstrings.com suggests that perhaps: > Driver={Microsoft Visual FoxPro > Driver};SourceType=DBF;SourceDB=c:\myvfpdbfolder;Exclusive=No; > Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO; > may be a good sample to start with -- there are other variations, check > their site. > 4) do your data input/output using standard Python db-api calls. > > see python\lib\site-packages\adodbapi\test\ for usage examples > > You can get pywin32 from http://sourceforge.net/projects/pywin32 Thanks for the suggestion, but I don't want to be tied to Foxpro, which means I need to be able to parse these files directly. I have the dbf files, now I need the idx and cdx files. -- ~Ethan~ From carl at personnelware.com Sun Sep 19 00:36:54 2010 From: carl at personnelware.com (Carl Karsten) Date: Sat, 18 Sep 2010 23:36:54 -0500 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: <4C959039.5070700@stoneleaf.us> References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> <4C959039.5070700@stoneleaf.us> Message-ID: On Sat, Sep 18, 2010 at 11:23 PM, Ethan Furman wrote: > Vernon Cole wrote: >> >> Ethan: >> I cannot see where you mentioned your operating system, I am assuming >> Windows. >> >> Perhaps you have already investigated this ... I have no way to test it >> ... but you might try: >> ADO can access almost any data source, and a quick look seems to show that >> .dbf is supported using the JET driver or a FoxPro driver. >> >> 1) upload pywin32 >> 2) import adodbapi >> 3) find an appropriate connection string for your data source >> http://connectionstrings.com suggests that perhaps: >> Driver={Microsoft Visual FoxPro >> Driver};SourceType=DBF;SourceDB=c:\myvfpdbfolder;Exclusive=No; >> Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO; >> may be a good sample to start with -- there are other variations, check >> their site. >> 4) do your data input/output using standard Python db-api calls. >> >> see python\lib\site-packages\adodbapi\test\ for usage examples >> >> You can get pywin32 from http://sourceforge.net/projects/pywin32 > > Thanks for the suggestion, but I don't want to be tied to Foxpro, which > means I need to be able to parse these files directly. ?I have the dbf > files, now I need the idx and cdx files. What do you mean "tied" ? -- Carl K From ldo at geek-central.gen.new_zealand Sun Sep 19 00:46:33 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 16:46:33 +1200 Subject: This Is International =?UTF-8?B?RG9u4oCZdC1TcXVhd2stTGlrZS1BLVBhcnJvdA==?= Day Message-ID: Do your bit to help stamp out parrocy. Thank you. From ethan at stoneleaf.us Sun Sep 19 00:51:56 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 21:51:56 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> Message-ID: <4C9596EC.40906@stoneleaf.us> Dennis Lee Bieber wrote: > On Sat, 18 Sep 2010 10:44:06 -0700, Ethan Furman > declaimed the following in gmane.comp.python.general: > > >>I have a pure-python module to read db3 and vfp 6 dbf files, and I find >>that I need to read (and write) the idx and cdx index files that foxpro >>generates. We are in the process of switching from homegrown foxpro >>apps to homegrown python apps, but I have to support the foxpro file >>formats until the switch is complete. Once I have the index files down, >>I'll publish another release of it (an older version can be found on PyPI). >> > > Seems odd that you'd have to do all that low-level processing... Do > you have the VFP ODBC driver on the systems? That would permit just > using ODBC queries to operate on the data. Hmmm. I may look at that. When I first started this project, I was brand new to Python and unaware of all the cool stuff out there. It was a great learning project -- iterators, magic methods, emulating sequences and attributes, properties, class methods, inheritence, packages... it has been quite an adventure! It's probably a safe bet that I don't /need/ to, but I certainly /want/ to. It would be a finished project, and a sense of accomplishment. Thanks for the suggestion. -- ~Ethan~ From ethan at stoneleaf.us Sun Sep 19 01:10:16 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 18 Sep 2010 22:10:16 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> <4C959039.5070700@stoneleaf.us> Message-ID: <4C959B38.3040108@stoneleaf.us> Carl Karsten wrote: > On Sat, Sep 18, 2010 at 11:23 PM, Ethan Furman wrote: >>Thanks for the suggestion, but I don't want to be tied to Foxpro, which >>means I need to be able to parse these files directly. I have the dbf >>files, now I need the idx and cdx files. > > > > What do you mean "tied" ? I meant having to have Foxpro installed. I just learned from another reply that I may not have to have Foxpro installed as long as I have the Foxpro ODBC driver, because then I could use odbc instead of fiddling with the files directly. While I may switch over to odbc in the future, I would still like to have the idx/cdx components. -- ~Ethan~ From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 01:25:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 05:25:48 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c959edc$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 00:35:14 +0000, Seebs wrote: > On 2010-09-19, AK wrote: >> Funny that you should say that, because I thought quite a few times >> that it would be really awesome if some texts in English had syntax >> highlighting. Obviously, not Brothers Karamazov, but something like a >> tutorial, or a manual, or an online article. If key words were >> highlighted, I'd be able to quickly glance over parts that are not >> useful to me at the time, and find the interesting bits. > > That wouldn't be *syntax* highlighting, that'd be *semantic* > highlighting. > > Which people often do -- notice that I did it twice in that paragraph. > But that's the point -- you need to know what it *means* to make > sensible decisions about what to highlight. Syntax highlighting is > precisely the opposite, highlighting things for reasons that have > nothing to do with their semantic content. It distracts from the actual > meaning of the code. I'm not entirely sure I agree with you here... you can't ignore syntax in order to understand the meaning of code. Unless you understand the syntax, even a simple line like: x = y is impossible to understand. Is it an assignment? If so, which way (does it assign the value of x to the variable y, or y to x)? Or is it a comparison? The term "syntax highlighting" for what editors I've seen do is actually misleading -- they don't highlight *syntax*, they try to highlight *semantics*. When your editor highlights the function len() in the expression "x = len(y) + spam(z)" but not the function spam(), you know it has nothing to do with syntax. len() is singled out because of its semantics, namely the fact that it's a built-in. In English, the meaning of the some sentences do benefit by syntax highlighting, and in fact that's partly what punctuation is for: English partly uses punctuation marks as tags to break the sentence structure into sub-sentences, clauses and terms (particularly when the sentence would otherwise be ambiguous). An extreme example is the infamous "buffalo" sentence, which is grammatically valid and semantically meaningful but rather difficult to decipher: http://en.wikipedia.org/wiki/Buffalo_buffalo_Buffalo_buffalo_buffalo_buffalo_Buffalo_buffalo Of course this is an extreme example, but English is often ambiguous, and some sort of syntax highlighting could potentially be useful: "Woman shoots man with crossbow" Was it the man armed with a crossbow, or the woman? If we could somehow group the clause "with crossbow" with "woman" or "man" by something *other* than proximity, we could remove the ambiguity. In ordinary English, not only does punctuation sometimes play the role of syntax highlighting, but so do otherwise meaningless words like "the", "a", "which", "that", "also", and so forth. Bringing it back to Python, that's why punctuation like : are useful. They're syntax highlighting. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 01:26:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Sep 2010 05:26:58 GMT Subject: Why IterableUserDict? References: <4c942e0f$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c959f21$0$11113$c3e8da3@news.astraweb.com> On Sat, 18 Sep 2010 09:42:14 +0200, Peter Otten wrote: [...] >> Now that boggles my brain. Why was support for iteration added as a >> subclass, instead of simply adding the __iter__ method to UserDict? >> UserDict is supposed to be a drop-in replacement for dict (although the >> use-cases for it are much fewer now that we can inherit from dict), so >> it doesn't make sense to me to have a non-iterable UserDict plus a >> subclass which is iterable. >> >> Can anyone shed any light on this apparently bizarre design decision? > > I looked it up for you: > > http://svn.python.org/view/python/trunk/Lib/UserDict.py?view=log [...] > The bug report is also interesting: > > http://bugs.python.org/issue448153 Oh my. Guido is more forgiving than me. I would have left __iter__ in UserDict and treated the bug report as a "will not fix". Thanks for that. -- Steven From nobody at nowhere.com Sun Sep 19 01:36:19 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 19 Sep 2010 06:36:19 +0100 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Sun, 19 Sep 2010 12:27:08 +1200, Lawrence D'Oliveiro wrote: >> That's why Stevens recommends that all TCP servers use the >> SO_REUSEADDR socket option. > > I don?t think I?ve ever used that. It seems to defeat a safety mechanism > which was put in for a reason. It was put in for the benefit of clients, to prevent them from selecting a port which they won't be able to use. At the point that the program calls bind(), the kernel doesn't know whether the program will call connect() or listen() next (i.e. whether it's a client or a server). Even if you set SO_REUSEADDR, you cannot create a connection which could be confused with an existing connection, i.e. one with the same source and destination address and port (BSD allows this provided that the previous connection is closed and the initial sequence number of the new connection exceeds the final sequence number of the previous connection). For a client, re-using the port would mean that any attempt to connect to the same port and address as an existing TIME_WAIT connection will fail with EADDRINUSE, so it should choose another port. This scenario is quite likely, as a client for a particular protocol will tend to connect to a specific remote port, and often to a small set of servers. But a server often has to use a specific port, and its clients will typically connect from ephemeral ports. Even if some clients insist on trying to use a specific source port (which will fail so long as the TIME_WAIT connections exist), the server can still serve other clients. From ldo at geek-central.gen.new_zealand Sun Sep 19 02:42:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 18:42:51 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message , Nobody wrote: > On Sun, 19 Sep 2010 12:27:08 +1200, Lawrence D'Oliveiro wrote: > >>> That's why Stevens recommends that all TCP servers use the >>> SO_REUSEADDR socket option. >> >> I don?t think I?ve ever used that. It seems to defeat a safety mechanism >> which was put in for a reason. > > It was put in for the benefit of clients, to prevent them from selecting > a port which they won't be able to use. But clients typically don?t care what port they use?they let the system pick a port for them, so this kind of option is unnecessary. From lie.1296 at gmail.com Sun Sep 19 02:47:26 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 19 Sep 2010 16:47:26 +1000 Subject: The trouble with "dynamic attributes". In-Reply-To: References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4c93a06c$1@dnews.tpgi.com.au> Message-ID: <4c95b1c3$1@dnews.tpgi.com.au> On 09/18/10 03:53, Ethan Furman wrote: > Lie Ryan wrote: > [snip] >> And even dict-syntax is not perfect for accessing XML file, e.g.: >> >> >> foo >> bar >> >> >> should a['b'] be 'foo' or 'bar'? > > Attribute style access would also fail in this instance -- how is this > worked-around? By not having multiple b in the first place! However, if you cannot avoid having duplicates, then you would have to use a different approach: SAX (Simple API for XML; Java has a weird sense of simplicity): import xml.sax as sax from xml.sax.handler import ContentHandler class MyHandler(ContentHandler): def __init__(self): self.inB = False def startElement(self, name, attrs): if name == 'b': self.inB = True def characters(self, ch): if self.inB: print ch def endElement(self, name): if name == 'b': self.inB = False data = 'FooEvilBar' sax.parseString(data, MyHandler()) or in ElementTree: import xml.etree.ElementTree as et data = 'FooEvilBar' a = et.fromstring(data) for elem in a.findall('b'): print elem.text From martin at v.loewis.de Sun Sep 19 03:09:04 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 19 Sep 2010 09:09:04 +0200 Subject: compile Py2.6 on SL In-Reply-To: References: Message-ID: <4C95B710.8060605@v.loewis.de> Am 16.09.2010 17:34, schrieb moerchendiser2k3: > Hi, > > I have some trouble with Python on Snow Leopard (10.6.3). I compile > Python as a framework(for 32/64bit) without any problems. > But implementing the lib in my C app, I get the following error on > linking: > > Undefined symbols: > "_Py_InitModule4_64", referenced from: > RegisterModule_BPY(char const*, PyMethodDef*, char const*, > _object*, int)in i_moduleobject.o > ld: symbol(s) not found > > I read a lot of stuff about this problem, but nothing helped me. My > app is in 64-bit and I compiled Python for 32/64bit. I'm skeptical that you did - if you really *had* compiled Python for AMD64, this error would not have occured. Please use file/lipo to verify that the Python library really is available as 64-bit code. Regards, Martin From niklasro at gmail.com Sun Sep 19 03:13:04 2010 From: niklasro at gmail.com (Niklasro) Date: Sun, 19 Sep 2010 00:13:04 -0700 (PDT) Subject: Learning inheritance References: Message-ID: On Sep 18, 11:15?pm, Jorgen Grahn wrote: > On Sat, 2010-09-18, Niklasro wrote: > > Hi > > How can I make the visibility of a variable across many methods or > > files? To avoid repeating the same line eg ? ? url = > > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > > os.environ['SERVER_NAME'] I repeat for many methods. So declaring it > > to a super class and inheriting it is my plan. Do you agree or propose > > otherwise? > > Inheritance is not the main tool for sharing code. Just make it a > function and place it in one of your modules (files): > > def get_host(): > ? ?"""Return the environment's $HTTP_HOST if > ? ?it exists, otherwise $SERVER_NAME or (if that > ? ?doesn't exist either) None. > ? ?""" > ? ?... > > Perhaps you are focusing too much on inheritance in general. > I personally almost never use it in Python -- it has much fewer > uses here than in staticaly typed languages. > > /Jorgen > > -- > ? // Jorgen Grahn \X/ ? ? snipabacken.se> ? O ?o ? . Thanks for sharing the knowledge. I alternatively think about declaring the variable in a setting.py file and import it. It doesn't create many objects but I want to learn more professional code conventions than same test repeated. Sincerely, Niklas R From niklasro at gmail.com Sun Sep 19 03:14:42 2010 From: niklasro at gmail.com (Niklasro) Date: Sun, 19 Sep 2010 00:14:42 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> Message-ID: On Sep 19, 2:31?am, alex23 wrote: > Niklasro wrote: > > I got 2 files main.py and i18n both with > > webapp request handlers which I would like access the variable. > > I'd probably use a module for this. Create a third file, called > something like shared.py, containing the line that bruno gave above: > > url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) > > Then from within both main & i18n you can 'import shared' and access > the variable as 'shared.url'. > > Python only actually executes a module the first time it's imported, > every other import will be given a reference to the same module > object. This also lets you share temporary data between modules. Any > module that imports 'shared' can add an attribute to it ('shared.foo = > "barbaz"') that will be visible to all other modules that have (or > will have) imported it. I try a file setting.py declaring it like this just loose in the file not knowing much theory about it thinking it's easy and intuitive. Thanks Niklas From __peter__ at web.de Sun Sep 19 03:22:41 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 19 Sep 2010 09:22:41 +0200 Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: fridge wrote: > # bigdigits2.py > > import sys > > zero=["***", > "* *", > "***"] > one=["***", > " * ", > "***"] > digits=[zero,one,zero,one,zero,one,zero,one,zero,one] > > inputted_digit=sys.argv[1] > column_max=len(inputted_digit) > row_max=3 > > r=0 > while r<3: > line="" > c=0 > while c digit_i=int(inputted_digit[c]) > digit=digits[digit_i] > line+=digit[r] > line+=" " > c+=1 > print(line) > r+=1 - Add a docstring at the beginning of the script explaining what it is meant to do. - Use four-space indent; add a space between names and operators. - Replace the while-loops with for-loops. You can iterate over numbers and characters: >>> for i in range(3): ... print(i) ... 0 1 2 >>> for c in "abc": ... print(c) ... a b c Peter From niklasro at gmail.com Sun Sep 19 03:22:49 2010 From: niklasro at gmail.com (Niklasro) Date: Sun, 19 Sep 2010 00:22:49 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> Message-ID: <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> It works but I don't know whether it's formally inheritance or class variable. Before code was url = os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else os.environ['SERVER_NAME'] if url.find('niklas') > 0: and now the change saves me from repeating myself! util.py: url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) #declared as class variable(?) And viola just test if util.url.find('niklas') > 0: Exactly what I wanted to do with your experienced guidance. Many thanks Happy refactored From usenet-nospam at seebs.net Sun Sep 19 03:31:18 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 07:31:18 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, Steven D'Aprano wrote: > Define "unbalanced". I'm not sure that's the word I'd use. I'm not even sure what it would mean here. > Putting aside the over-use of punctuation, The C syntax feels unbalanced > to me. You have: > condition IF true-clause ELSE false-clause > so both clauses follow the test, that is, they're on the same side: ?-- Yes. Just like: if condition: foo else: bar The condition is the primary, the clauses are secondary to it. So I like that form because it matches what I'd write if I were writing things out more verbosely for some reason. > But the Python syntax looks balanced to me: > true-clause IF condition ELSE false-clause > which is not only plain English, but perfectly balanced, with a clause on > either side of the test: -?- It may be balanced, but it requires you to reevaluate what you're reading after you've already read something that seemed to have a clear meaning. Basically, think of what happens as I read each symbol: x = x + 1 if condition else x - 1 Up through the '1', I have a perfectly ordinary assignment of a value. The, suddenly, it retroactively turns out that I have misunderstood everything I've been reading. I am actually reading a conditional, and the things I've been seeing which looked like they were definitely part of the flow of evaluation may in fact be completely skipped. It's even more confusing if I'm familiar with the postfix-if as seen in, say, perl or ruby. > Python's ternary-if puts the emphasis on the true-clause, while C's > ternary-if puts the emphasis on the test. I'm not convinced that this is > necessarily a better choice than Python's. It's a *valid* choice, but > better? I don't think so, but I accept that at least partially boils down > to subjective factors. I would usually think it better, just because most often, the *fact* of there being a test is the first thing you have to know about the expression to make sense of it. If I am given the right framework first, and the information to fill into it second, I don't have to throw away parsing I'd already done. If I'm given information, then later retroactively told to move it into a slot in a framework I didn't even know I was going to need, I have to do a lot of reworking. Consider the following lovely hypothetical syntax: foo bar baz if condition else: blah blah blah And there, at least you have some cue that you're about to see something happen. -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 Sep 19 03:36:11 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 07:36:11 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, Steven D'Aprano wrote: > I'm not entirely sure I agree with you here... you can't ignore syntax in > order to understand the meaning of code. No, but the syntax should be invisible. When I read English, I don't have to think about nouns and verbs and such unless something is very badly written. The syntax is handled automatically at a lower level without conscious intervention, as it should be. Calling my conscious attention to it is disruptive. > The term "syntax highlighting" for what editors I've seen do is actually > misleading -- they don't highlight *syntax*, they try to highlight > *semantics*. I've never seen this. I've seen things highlight comments and keywords and operators and constants and identifiers differently. > When your editor highlights the function len() in the > expression "x = len(y) + spam(z)" but not the function spam(), you know > it has nothing to do with syntax. len() is singled out because of its > semantics, namely the fact that it's a built-in. Eww. (I had not yet gotten to the point of finding out that whether something was "built-in" or not substantially affected its semantics.) > In English, the meaning of the some sentences do benefit by syntax > highlighting, and in fact that's partly what punctuation is for: English > partly uses punctuation marks as tags to break the sentence structure > into sub-sentences, clauses and terms (particularly when the sentence > would otherwise be ambiguous). Punctuation is very different from highlighting, IMHO. That said, I find punctuation very effective at being small and discrete, clearly not words, and easy to pick out. Color cues are not nearly as good at being inobtrusive but automatically parsed. > "Woman shoots man with crossbow" > Was it the man armed with a crossbow, or the woman? If we could somehow group the > clause "with crossbow" with "woman" or "man" by something *other* than > proximity, we could remove the ambiguity. Yes. But syntax highlighting won't help you here -- at least, I've never yet seen any editor that showed precedence relations or anything similar in its coloring. > Bringing it back to Python, that's why punctuation like : are useful. > They're syntax highlighting. I don't think they are, though. I think punctuation is fundamentally different in intent and purpose from colorizing things based on whether they're, say, constants or identifiers or comments or keywords. The punctuation is *itself* part of the syntax -- it's not being highlighted. Syntax highlighting is putting all the punctuation in green so you know it's punctuation. -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 thomas at jollans.com Sun Sep 19 04:12:52 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 19 Sep 2010 10:12:52 +0200 Subject: Learning inheritance In-Reply-To: <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> Message-ID: <4C95C604.4020801@jollans.com> On 2010-09-19 09:22, Niklasro wrote: > util.py: > url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) #declared > as class variable(?) > There is no class here, so this is no class variable, and you're not inheriting anything. You're simply using a module. > And viola just test if util.url.find('niklas') > 0: > > Exactly what I wanted to do with your experienced guidance. > > Many thanks > Happy refactored > From niklasro at gmail.com Sun Sep 19 04:18:44 2010 From: niklasro at gmail.com (Niklasro) Date: Sun, 19 Sep 2010 01:18:44 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> Message-ID: <8632bf75-3963-4e85-99f3-684dcde99589@i17g2000vbq.googlegroups.com> On Sep 19, 8:12?am, Thomas Jollans wrote: > On 2010-09-19 09:22, Niklasro wrote:> util.py: > > url = os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"]) #declared > > as class variable(?) > > There is no class here, so this is no class variable, and you're not > inheriting anything. You're simply using a module. > > > And viola just test if util.url.find('niklas') > 0: > > > Exactly what I wanted to do with your experienced guidance. > > > Many thanks > > Happy refactored > > Good to learn what I'm doing :-) since important being able to explain choices taken farther than "doing it because it works". I understand the concept of modules may not correspond to java programming where I come from. Sincerely with thanks for the help, Niklas From alex at moreati.org.uk Sun Sep 19 06:54:18 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Sun, 19 Sep 2010 03:54:18 -0700 (PDT) Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: Your code works (assuming digits gets populated fully), but it's the absolute bare minimum that would. To be brutally honest it's: - unpythonic - you've not used the core features of Python at all, such as for loops over a sequence - poorly formatted - Please read the python style guide and follow it - not reusable - Your code can only be called from the command line, it should be usable as a module - not documented - There is no indication what this code does, other than mentally running it - Fragile - There is no error checking on user input There are other ways to write what you have more concisely (e.g. list comprehensions, iterators) but those can wait for another time. Here is a start at improving your code wrt to the above points: #!/usr/bin/env python3 # bigdigits2.py ZERO = ["***", # NB Constants are by convention ALL_CAPS "* *", "***"] ONE = ["** ", " * ", "***"] # TODO Define and populate digits 2-9 DIGITS = [ZERO, ONE, ZERO, ONE, ZERO, ONE, ZERO, ONE, ZERO, ONE] def big_digits(str_of_digits): """Return a list of lines representing the digits using 3x3 blocks of "*" """ banner = [] # Accumulate results in this # Loop over the rows/lines of the result # TODO Replace hard coded block size with global constant or measured size for row in range(3): line_parts = [] # Assemble the current line from the current row of each big digit for digit in str_of_digits: big_digit = DIGITS[int(digit)] line_parts.append(big_digit[row]) # Create a string for the current row and add it to the result line = " ".join(line_parts) banner.append(line) return banner def usage(): print("Usage: bigdigit.py ", file=sys.stderr) sys.exit(1) if __name__ == "__main__": import sys # Check that an argument was passed # NB This will ignore additional arguments if len(sys.argv) >= 2: input_string = sys.argv[1] else: usage() # Check that only digits were passed if not input_string.isnumeric(): usage() # All is well, print the output for line in big_digits(input_string): print(line) Here are some suggested further improvements: - Map directly from a digit to it's big digit with a dictionary, rather than indexing into a list: BIG_DIGITS = { "1": ["** ", " * ", "***"], # ... } - Is input_string.isnumeric() the right test? Can you find a character it would not correctly flag as invalid input? - What if I wanted to use my own 4x4 big digits? Could the big_digits() function accept it as an argument? From mal at egenix.com Sun Sep 19 07:04:40 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Sun, 19 Sep 2010 13:04:40 +0200 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: <4C959B38.3040108@stoneleaf.us> References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> <4C959039.5070700@stoneleaf.us> <4C959B38.3040108@stoneleaf.us> Message-ID: <4C95EE48.2030303@egenix.com> Ethan Furman wrote: > Carl Karsten wrote: >> On Sat, Sep 18, 2010 at 11:23 PM, Ethan Furman >> wrote: >>> Thanks for the suggestion, but I don't want to be tied to Foxpro, which >>> means I need to be able to parse these files directly. I have the dbf >>> files, now I need the idx and cdx files. >> >> >> >> What do you mean "tied" ? > > I meant having to have Foxpro installed. I just learned from another > reply that I may not have to have Foxpro installed as long as I have the > Foxpro ODBC driver, because then I could use odbc instead of fiddling > with the files directly. > > While I may switch over to odbc in the future, I would still like to > have the idx/cdx components. If you are working on Windows, you can install the MS MDAC package to get a hold of the MS FoxPro ODBC drivers. They are usually already installed in Vista and 7, in XP they comes with MS SQL Server and MS Office as well. mxODBC can then provide Python access on Windows, mxODBC Connect on other platforms. If you want direct files access on other platforms, you can use http://pypi.python.org/pypi/dbf/ or http://dbfpy.sourceforge.net/. If you want to add support for index files (which the above two don't support), you could also have a look at this recipe for some inspiration: http://code.activestate.com/recipes/362715-dbf-reader-and-writer/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 19 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 ldo at geek-central.gen.new_zealand Sun Sep 19 07:20:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 23:20:13 +1200 Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: In message , Alex Willmer wrote: > # NB Constants are by convention ALL_CAPS SAYS_WHO? From ldo at geek-central.gen.new_zealand Sun Sep 19 07:23:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 23:23:21 +1200 Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: In message <4c957412$0$3036$afc38c87 at news.optusnet.com.au>, fridge wrote: > digits=[zero,one,zero,one,zero,one,zero,one,zero,one] digits = [zero, one] * 5 > row_max=3 Defined but never used. > digit_i=int(inputted_digit[c]) > digit=digits[digit_i] > line+=digit[r] > line+=" " Too many intermediate variables only defined and used once. Do this all on one line. From ldo at geek-central.gen.new_zealand Sun Sep 19 07:26:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 23:26:26 +1200 Subject: Cross Compiling Python for ARM References: <4c911670$0$41115$e4fe514c@news.xs4all.nl> Message-ID: In message <4c911670$0$41115$e4fe514c at news.xs4all.nl>, Hans Mulder wrote: > The most popular way to get the latter problem is to write the script > on a Windows box and then upload it to Unix box using FTP in binary > mode (or some other transport that doesn't adjust the line endings). I always thought it was a misfeature that the Linux kernel doesn?t recognize all the common conventions for ending the shebang line. All reading of text files should be similarly tolerant. From ldo at geek-central.gen.new_zealand Sun Sep 19 07:29:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 19 Sep 2010 23:29:44 +1200 Subject: program organization question for web development with python References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> Message-ID: In message <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29 at w15g2000pro.googlegroups.com>, Hans wrote: > print """%s""" % > (record[0],table_name,cursor_name,record1) I would recommend avoiding filename extensions in your URLs wherever possible. For executables, in particular, leaving out the ?.py? or ?.pl? or whatever makes it easier to switch languages, should you need to in future. From alex at moreati.org.uk Sun Sep 19 07:34:17 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Sun, 19 Sep 2010 04:34:17 -0700 (PDT) Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: On Sep 19, 12:20?pm, Lawrence D'Oliveiro wrote: > In message > , Alex > > Willmer wrote: > > # NB Constants are by convention ALL_CAPS > > SAYS_WHO? Says PEP 8: Constants Constants are usually declared on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL. -- http://www.python.org/dev/peps/pep-0008/ From python.list at tim.thechases.com Sun Sep 19 07:37:23 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 19 Sep 2010 06:37:23 -0500 Subject: This Is International =?windows-1252?Q?Don=92t-Squawk-Like-A?= =?windows-1252?Q?-Parrot_Day?= In-Reply-To: References: Message-ID: <4C95F5F3.7050408@tim.thechases.com> On 09/18/10 23:46, Lawrence D'Oliveiro wrote: > Do your bit to help stamp out parrocy. Did you send this by mistake? It looks like a parroty-error. I think it's a bit off... -tkc From thomas at jollybox.de Sun Sep 19 08:10:39 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 19 Sep 2010 14:10:39 +0200 Subject: ctypes and buffers In-Reply-To: References: Message-ID: <201009191410.40186.thomas@jollybox.de> On Sunday 19 September 2010, it occurred to Carl Banks to exclaim: > I am creating a ctypes buffer from an existing non-ctypes object that > supports buffer protocol using the following code: > > > from ctypes import * > > PyObject_AsReadBuffer = pythonapi.PyObject_AsReadBuffer > PyObject_AsReadBuffer.argtypes = > [py_object,POINTER(c_void_p),POINTER(c_size_t)] > PyObject_AsReadBuffer.restype = None > > def ctypes_buffer_from_buffer(buf): > cbuf = c_void_p() > size = c_size_t() > PyObject_AsReadBuffer(buf,byref(cbuf),byref(size)) > return cbuf > If I understand what you are doing correctly, you're referencing a Python buffer object and returning a pointer wrapped in some ctypes thingy. hmm. I see some problems in your code: * You're not passing the size along. In the name of sanity, why on earth not?! The pointer cannot be safely used without knowing how long the area of memory referenced is! * You're using the old buffer protocol. You might rather implement this with the one introduced with Python 3.0, and supported in 2.6 as well. > > It works, but is there a standard way to do this in ctypes? I > couldn't find anything in the documentation. Python 2.6 for now. > Thanks. > > > Carl Banks From aahz at pythoncraft.com Sun Sep 19 09:11:20 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 06:11:20 -0700 Subject: C++ - Python API References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: In article , Thomas Jollans wrote: >On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: >> >> So the feature overview: > >First, the obligatory things you don't want to hear: Have you had >a look at similar efforts? A while ago, Aahz posted something very >similar on this very list. You should be able to find it in any of the >archives without too much trouble. You almost certainly have me confused with someone else -- I wouldn't touch C++ with a ten-meter pole if I could possibly help it. (The last time I dealt with C++ code, about a decade ago, I just rewrote it in C.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From philip at semanchuk.com Sun Sep 19 09:11:50 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 19 Sep 2010 09:11:50 -0400 Subject: =?windows-1252?Q?Re:_This_Is_International_Don=92t-Squawk-Like-A?= =?windows-1252?Q?-Parrot_Day?= In-Reply-To: <4C95F5F3.7050408@tim.thechases.com> References: <4C95F5F3.7050408@tim.thechases.com> Message-ID: <302A823C-C163-4FF2-B492-1398B2B1BDE5@semanchuk.com> On Sep 19, 2010, at 7:37 AM, Tim Chase wrote: > On 09/18/10 23:46, Lawrence D'Oliveiro wrote: >> Do your bit to help stamp out parrocy. > > Did you send this by mistake? It looks like a parroty-error. I think it's a bit off... What an aaaawkward thing to say. Are you crackers? From aahz at pythoncraft.com Sun Sep 19 09:11:55 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 06:11:55 -0700 Subject: This Is International =?windows-1252?Q?Don=92t-Squawk-Like-A?= =?windows-1252?Q?-Parrot_Day?= References: Message-ID: In article , Tim Chase wrote: >On 09/18/10 23:46, Lawrence D'Oliveiro wrote: >> >> Do your bit to help stamp out parrocy. > >Did you send this by mistake? It looks like a parroty-error. I >think it's a bit off... Arrrrgh! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From aahz at pythoncraft.com Sun Sep 19 09:16:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 06:16:49 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: In article , geremy condra wrote: >On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking > wrote: >> >> I've been working with Python now for about a year using it primarily for >> scripting in the Puredata graphical programming environment. I'm working on >> a project where I have been given a 1000 by 1000 cell excel spreadsheet and >> I would like to be able to access the data using Python. Does anyone know >> of a way that I can do this? > >http://tinyurl.com/2eqqjxv Please don't use tinyurl -- it's opaque and provides zero help to anyone who might later want to look it up (and also no accessibility if tinyurl ever goes down). At the very least, include the original URL for reference. (Yes, I realize this is probably a joke given the smiley I excised, but too many people do just post tinyurl.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From thomas at jollybox.de Sun Sep 19 10:28:41 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 19 Sep 2010 16:28:41 +0200 Subject: C++ - Python API In-Reply-To: References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: <201009191628.42036.thomas@jollybox.de> On Sunday 19 September 2010, it occurred to Aahz to exclaim: > In article , > > Thomas Jollans wrote: > >On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: > >> So the feature overview: > >First, the obligatory things you don't want to hear: Have you had > >a look at similar efforts? A while ago, Aahz posted something very > >similar on this very list. You should be able to find it in any of the > >archives without too much trouble. > > You almost certainly have me confused with someone else -- I wouldn't > touch C++ with a ten-meter pole if I could possibly help it. (The last > time I dealt with C++ code, about a decade ago, I just rewrote it in C.) Sorry about that. From andrei.avk at gmail.com Sun Sep 19 10:29:10 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 10:29:10 -0400 Subject: Too much code - slicing In-Reply-To: <4c958370$0$11113$c3e8da3@news.astraweb.com> References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C961E36.5010606@gmail.com> On 09/18/2010 11:28 PM, Steven D'Aprano wrote: > On Sat, 18 Sep 2010 21:58:58 -0400, AK wrote: > >>> I don't understand this. So far as I know, the phrase "speed reading" >>> refers to various methods of reading much faster than most people read, >>> and is real but not exceptionally interesting. >> >> Afaik the idea is that you can read a novel at the speed of half a page >> a second or so and understand it to the same extent as people who'd read >> at a normal rate. Woody Allen joke: "I learned speed reading and read >> War&Peace"; - it involves Russia. > > My wife can read scarily fast. It's very something to watch her reading > pages as fast as she can turn them, and a few years ago she read the > entire Harry Potter series (to date) in one afternoon, and could gives a > blow-by-blow account of the plots, including a detailed critique of the > writing style and characters. But then, she feels that reading the Potter > series is a chore to be completed as fast as possible, rather than a > pleasure to be savored. She'll sometimes drag a new Terry Pratchett or > Stephen King novel out for as much as two days. > > That's pretty impressive. I used to get somewhat close to that speed when, years ago, I'd read a lot of trashy scifi. The way it would work is that I'd sense in advance that there's a passage where the hero with his team is going through a desert area and I'd know that a 30-40 page section will be punctuated by two battles and one friendly encounter. I would be able to read at different speeds depending on what's going on, slowing down a bit where a twist is presented or a crucial plot point is revealed, both would be telegraphed well in advance. In other spots, I'd be able to scan a few words at the top of page, a few in the middle and at the bottom and I'd know what's going on, generally. I would also be able to give a detailed account of the plot and writing style and characters but this would be entirely due to predictability of writing and following tropes. Interestingly, I've also read LoTR in the same way when I was younger because I was interested in battles and skipped the dull parts. I tried a few times to read Potter book 3 but couldn't bear it.. spoiled too much by Barrie and Grahame. When I was reading The book of the new sun, though, I could stop and read a single sentence a few times over and reflect on it for a minute. -ak From andrei.avk at gmail.com Sun Sep 19 10:44:59 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 10:44:59 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C9621EB.6040304@gmail.com> On 09/19/2010 03:31 AM, Seebs wrote: > On 2010-09-19, Steven D'Aprano wrote: >> Define "unbalanced". > > I'm not sure that's the word I'd use. I'm not even sure what it would mean > here. > >> Putting aside the over-use of punctuation, The C syntax feels unbalanced >> to me. You have: > >> condition IF true-clause ELSE false-clause > >> so both clauses follow the test, that is, they're on the same side: ?-- > > Yes. > > Just like: > if condition: > foo > else: > bar > > The condition is the primary, the clauses are secondary to it. To me, the problem with C ternary is, why is true condition first and false second? It could just as well be the other way around. With if and else, the meaning is direct, x if y else z, or if y: x; else: z. > > It may be balanced, but it requires you to reevaluate what you're reading > after you've already read something that seemed to have a clear meaning. > > Basically, think of what happens as I read each symbol: > > x = x + 1 if condition else x - 1 > > Up through the '1', I have a perfectly ordinary assignment of a value. > The, suddenly, it retroactively turns out that I have misunderstood > everything I've been reading. I am actually reading a conditional, and > the things I've been seeing which looked like they were definitely > part of the flow of evaluation may in fact be completely skipped. That's absolutely not how I read code. For example, if you have a line like: x = x + 1 ASF!@#$!@$ASFASF!@#$!@$#ADFASDF!@# Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is this?". I would read it like "there's something wrong at the end of line", before I even see it as an assignment. That's where syntax highlighting comes in, as well. What I see, at the same time (i.e. not in sequence): .. = .. if .. else .. The second thing I see is what variable is being assigned to. Of couse, this might change if I'm looking for that particular variable, then I might see: x ................ or x = ................ > > > Consider the following lovely hypothetical syntax: > > foo > bar > baz > if condition else: > blah > blah > blah > > And there, at least you have some cue that you're about to see something > happen. After some time getting used to it, I'd end up seeing this as: . . . if .. else: . . . at first and then processing everything else. Again, syntax highlighting would help here. The only issue is that it'd be hard to separate the beginning from other code, for me that'd be the primary reason why this is not a good construct. -ak From andrei.avk at gmail.com Sun Sep 19 10:56:06 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 10:56:06 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C962486.3020901@gmail.com> On 09/19/2010 03:36 AM, Seebs wrote: > On 2010-09-19, Steven D'Aprano wrote: >> I'm not entirely sure I agree with you here... you can't ignore syntax in >> order to understand the meaning of code. > > No, but the syntax should be invisible. When I read English, I don't have > to think about nouns and verbs and such unless something is very badly > written. The syntax is handled automatically at a lower level without > conscious intervention, as it should be. Calling my conscious attention > to it is disruptive. The interesting thing is that syntax highlight for me *is* handled at a lower level. What you're describing is exactly the same as when I try a highlight scheme with colours that are too strong, or have a background. I would rather use no highlighting at all than a theme with garish colours. When I read code, I filter out colours when I don't need them and filter out non-coloured text when I'm looking for a particular structure. So, with x = y if a else z, I might see . = . if . else . and then immediately see x . y . a . z, already with knowledge of what is the structure surrounding vars. > Punctuation is very different from highlighting, IMHO. That said, I > find punctuation very effective at being small and discrete, clearly not > words, and easy to pick out. Color cues are not nearly as good at > being inobtrusive but automatically parsed. Seems like the difference of how you process colours vs. how I do, for me they work precisely in the same way as punctuation might, but adding an additional layer which may be used but never gets in the way. -ak From mahaboobnisha at gmail.com Sun Sep 19 11:49:41 2010 From: mahaboobnisha at gmail.com (roshini begum) Date: Sun, 19 Sep 2010 08:49:41 -0700 (PDT) Subject: comp.lang.python Message-ID: <3d6e88f4-13ed-4c8d-bce0-79350d60b7a8@n7g2000vbo.googlegroups.com> http://127760.blogspot.com From kevin.p.dwyer at gmail.com Sun Sep 19 12:35:10 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 19 Sep 2010 16:35:10 +0000 (UTC) Subject: Making logging.getLogger() simpler References: <4c94ea0d$1@dnews.tpgi.com.au> Message-ID: On Sun, 19 Sep 2010 02:35:15 +1000, Lie Ryan wrote: > I was expecting this to work: > > import logging > logger = logging.getLogger(__name__) > logger.warn('this is a warning') > > instead it produced the error: > > No handlers could be found for logger "__main__" > > > However, if instead I do: > > import logging > logging.warn('creating logger') > logger = logging.getLogger(__name__) > logger.warn('this is a warning') > > then it does work. > > Is there any reason why getLogger()-created logger shouldn't > automatically create a default handler? Hello Lie, Calling logging.warn(), or logging.debug() etc. before handlers have been assigned to the root logger will result in logging.basicConfig() being called automatically. By default a StreamHandler will be created on the root logger and your logger inherits the StreamHandler. So you can avoid the "No handlers..." warning by calling logging.basicConfig() before your program does any logging. I don't know why getLogger() doesn't so something similar when it's called. Perhaps so that the logger is explicitly initialised with basic, file or dictConfig? Cheers, Kev From nobody at nowhere.com Sun Sep 19 13:19:19 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 19 Sep 2010 18:19:19 +0100 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Sun, 19 Sep 2010 18:42:51 +1200, Lawrence D'Oliveiro wrote: >>>> That's why Stevens recommends that all TCP servers use the >>>> SO_REUSEADDR socket option. >>> >>> I don?t think I?ve ever used that. It seems to defeat a safety mechanism >>> which was put in for a reason. >> >> It was put in for the benefit of clients, to prevent them from selecting >> a port which they won't be able to use. > > But clients typically don?t care what port they use?they let the > system pick a port for them, so this kind of option is unnecessary. If they use an ephemeral port, the kernel won't pick a port which has any connections in the TIME_WAIT state. However, some clients choose their own source ports. E.g. rlogin/rsh use privileged (low-numbered) ports, and you can't get the kernel to choose a random privileged port for you. If you're writing a server which listens on a known port, you *should* be using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel will automatically reject packets relating to stale connections, and your server should be accepting any new connections ASAP. From mafeusek at gmail.com Sun Sep 19 13:37:47 2010 From: mafeusek at gmail.com (mafeusek at gmail.com) Date: Sun, 19 Sep 2010 19:37:47 +0200 Subject: newbie: class and __dict__ variable. Message-ID: Hallo Group Members. From time to time I see in python code following notation that (as I believe) extends namespace of MyClass. class MyClass: def __init__(self): self.__dict__["maci"]=45 myCl2 = MyClass2() print myCl2.maci I am guessing that there must be some difference between the one above and the one below, because otherwise no one would probably use the one above. Do YOu know that difference? class MyClass2: def __init__(self): self.maci=45 myCl = MyClass() print myCl.maci best regards, Pawel From hunguponcontent at gmail.com Sun Sep 19 13:55:43 2010 From: hunguponcontent at gmail.com (Default User) Date: Sun, 19 Sep 2010 12:55:43 -0500 Subject: develop for Windows on GNU/Linux, using Python Message-ID: Consider: Can someone do development of programs for use on Windows systems, but developed totally on a GNU/Linux system, using standard, contemporary 32 and / or 64-bit PC hardware? This would be for someone who can not or will not use Windows, but wants to create software for those who do. This might not include the use of VM for developing on GNU/Linux, as that would seem to require a Windows installation disk, which the developer may not be able or willing to obtain and use. Is the correct answer: 1) no. 2) yes. 3) yes, a "Hello World" program will run just fine on the Windows Python interpreter. 4) other. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sebastianthegreatful at gmail.com Sun Sep 19 14:08:22 2010 From: sebastianthegreatful at gmail.com (Seb) Date: Sun, 19 Sep 2010 11:08:22 -0700 (PDT) Subject: http2https proxy Message-ID: I'd like to open a ssl connection to a https server, done Create a socket and bind it to a local port, done Connect the two in such a way that everything read or written to the local port is actually read or written to the https server. In other words I want a http2https proxy. ideas? best regards, Seb From usenet-nospam at seebs.net Sun Sep 19 14:21:12 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 18:21:12 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, AK wrote: > On 09/19/2010 03:31 AM, Seebs wrote: >> Just like: >> if condition: >> foo >> else: >> bar >> The condition is the primary, the clauses are secondary to it. > To me, the problem with C ternary is, why is true condition first and > false second? It could just as well be the other way around. Again, look at the long-form "if/else" above; it's always "if a then b otherwise c". > With if and > else, the meaning is direct, x if y else z, or if y: x; else: z. The latter still has condition, true, false. >> Basically, think of what happens as I read each symbol: >> >> x = x + 1 if condition else x - 1 >> >> Up through the '1', I have a perfectly ordinary assignment of a value. >> The, suddenly, it retroactively turns out that I have misunderstood >> everything I've been reading. I am actually reading a conditional, and >> the things I've been seeing which looked like they were definitely >> part of the flow of evaluation may in fact be completely skipped. > That's absolutely not how I read code. For example, if you have a line > like: > x = x + 1 ASF!@#$!@$ASFASF!@#$!@$#ADFASDF!@# > Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is > this?". Not for something that big and visible. But the if/else stuff is just ordinary blocks of text. > That's where syntax highlighting comes in, as well. So basically, if we use syntax highlighting to make up for the legibility problems of a given syntax, then the syntax is okay, but people who don't use syntax highlighting to make up for its legibility problems are wrong. I see. This does seem self-contained; you like syntax highlighting because you like constructs which are hard to read without it. You like those constructs because they let you show off syntax highlighting. > After some time getting used to it, I'd end up seeing this as: > . > . > . > if .. else: > . > . > . > at first and then processing everything else. Assuming that the if/else was on the same page. :) > Again, syntax highlighting > would help here. The only issue is that it'd be hard to separate the > beginning from other code, for me that'd be the primary reason why this > is not a good construct. No matter how long I'd been using that construct, I'd still have the problem that, mechanically, I'm going to see the opening few lines first, and that means that those lines are going to get parsed first. I read largely in order. I do have some lookahead, but no matter how much I use the lookahead, I'm already parsing the first things I see, and that's top-down-left-right. -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 kevin.p.dwyer at gmail.com Sun Sep 19 14:36:04 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 19 Sep 2010 18:36:04 +0000 (UTC) Subject: develop for Windows on GNU/Linux, using Python References: Message-ID: On Sun, 19 Sep 2010 12:55:43 -0500, Default User wrote: > Consider: > > Can someone do development of programs for use on Windows systems, but > developed totally on a GNU/Linux system, using standard, contemporary 32 > and / or 64-bit PC hardware? > > This would be for someone who can not or will not use Windows, but wants > to create software for those who do. > > This might not include the use of VM for developing on GNU/Linux, as > that would seem to require a Windows installation disk, which the > developer may not be able or willing to obtain and use. > > Is the correct answer: > 1) no. > 2) yes. > 3) yes, a "Hello World" program will run just fine on the Windows Python > interpreter. > 4) other. Hello, The answer is "it depends", or 4 on your list of responses. You can write pure python on a Linux machine and it will run fine on Windows as long as you've taken care to program in a portable fashion. However, writing the code isn't everything. To be confident that your code is good you need to test it on a Windows box (we all test, right?). If you want to distribute your application to non-developers you'll need to wrap it in a Windows installer; if you have C-extensions in your code you'll need to compile them over Windows. If you want to program against the Windows API you'll need access to a Windows box. So, if you really want to develop code for Windows (or cross-platform code) I think you need to bite the bullet and get access to a Windows (virtual) machine. Cheers, Kev PS - You might be able to get away with using an emulator like WINE, but given the ubiquity of Windows in business/home computing I think you're better of testing on the real thing. From ethan at stoneleaf.us Sun Sep 19 14:45:54 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 19 Sep 2010 11:45:54 -0700 Subject: [DB-SIG] dbf files and compact indices In-Reply-To: <4C95EE48.2030303@egenix.com> References: <4C9457F5.2070303@stoneleaf.us> <4C94E5CC.7060809@stoneleaf.us> <4C94FA66.80008@stoneleaf.us> <4C959039.5070700@stoneleaf.us> <4C959B38.3040108@stoneleaf.us> <4C95EE48.2030303@egenix.com> Message-ID: <4C965A62.3040804@stoneleaf.us> M.-A. Lemburg wrote: > If you are working on Windows, you can install the MS MDAC package to > get a hold of the MS FoxPro ODBC drivers. They are usually already installed > in Vista and 7, in XP they comes with MS SQL Server and MS Office as > well. mxODBC can then provide Python access on Windows, mxODBC Connect > on other platforms. > > If you want direct files access on other platforms, you can use > http://pypi.python.org/pypi/dbf/ ^--- I'm the author if this package :) > or http://dbfpy.sourceforge.net/. ^--- from the quick skim of the code, I think mine does more at this point (memos, adding/deleting/renaming fields in existing tables, in-memory indexes, unicode support, export to csv,tab,fixed formats, field access via attribute/dictionary/index style (e.g. table.fullname or table['fullname'] or table[0] if fullname is the first field), very rudimentary sql support, etc.) > If you want to add support for index files (which the above two don't > support), you could also have a look at this recipe for some > inspiration: > > http://code.activestate.com/recipes/362715-dbf-reader-and-writer/ I didn't see anything regarding the .idx or .cdx files in this recipe. :( Thanks for your time, though! -- ~Ethan~ From vinay_sajip at yahoo.co.uk Sun Sep 19 14:52:59 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 19 Sep 2010 11:52:59 -0700 (PDT) Subject: Making logging.getLogger() simpler References: <4c94ea0d$1@dnews.tpgi.com.au> Message-ID: <19a4cbe4-d0df-4e85-886b-7ef2feedde03@s19g2000vbr.googlegroups.com> On Sep 18, 5:35?pm, Lie Ryan wrote: > I was expecting this to work: > > ? importlogging > ? logger =logging.getLogger(__name__) > ? logger.warn('this is a warning') > > instead it produced the error: > > ? No handlers could be found for logger "__main__" > > However, if instead I do: > > ? importlogging > ?logging.warn('creating logger') > ? logger =logging.getLogger(__name__) > ? logger.warn('this is a warning') > > then it does work. > > Is there any reason why getLogger()-created logger shouldn't > automatically create a default handler? There is a good reason why a getLogger()-created logger doesn't add a default handler. Imagine if it did, and the code you were writing was a library module that was used in an application being written by another developer. Imagine if there were several other libraries which also declared loggers (and therefore several default handlers). Then the result of running the application would be to get a whole bunch of unexpected messages from those libraries, including yours. This would annoy the application developer no end, and rightly so. For simple uses of logging (where you are writing a utility script, for example, when you are the application developer) you can call logging.warning() etc. which will (for your convenience) add a handler to write to the console for you, if there isn't a handler already. If you are doing something more involved, you will need to configure logging to do whatever it is you want, and when you run your program your log will contain messages from your application as well as third- party libraries you use, all playing well together and with no unpleasant surprises. If you are writing a library, you will typically: 1. Add a NullHandler to your top-level logger. 2. If you want to force your users (application developers) to add handlers explicitly to their loggers, set your top-level logger's propagate flag to False. 3. If you want to have a specific verbosity on your loggers, which is different from the default (WARNING), you need to set that level on your top-level logger, or on individual loggers for which you want that specific, non-default verbosity. I hope that helps, Vinay Sajip From vinay_sajip at yahoo.co.uk Sun Sep 19 14:55:34 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 19 Sep 2010 11:55:34 -0700 (PDT) Subject: Making logging.getLogger() simpler References: <4c94ea0d$1@dnews.tpgi.com.au> <19a4cbe4-d0df-4e85-886b-7ef2feedde03@s19g2000vbr.googlegroups.com> Message-ID: On Sep 19, 7:52?pm, Vinay Sajip wrote: > If you are writing a library, you will typically: > 2. If you want to force your users (application developers) to add > handlers explicitly to their loggers, set your top-level logger's > propagate flag to False. Sorry, in the above text, where it says "their loggers" it should say "your loggers" Regards, Vinay Sajip From user at example.net Sun Sep 19 15:31:30 2010 From: user at example.net (J.O. Aho) Date: Sun, 19 Sep 2010 21:31:30 +0200 Subject: develop for Windows on GNU/Linux, using Python In-Reply-To: References: Message-ID: <8fn6ojF783U1@mid.individual.net> Kev Dwyer wrote: > On Sun, 19 Sep 2010 12:55:43 -0500, Default User wrote: > >> Consider: >> >> Can someone do development of programs for use on Windows systems, but >> developed totally on a GNU/Linux system, using standard, contemporary 32 >> and / or 64-bit PC hardware? >> >> This would be for someone who can not or will not use Windows, but wants >> to create software for those who do. >> >> This might not include the use of VM for developing on GNU/Linux, as >> that would seem to require a Windows installation disk, which the >> developer may not be able or willing to obtain and use. >> >> Is the correct answer: >> 1) no. >> 2) yes. >> 3) yes, a "Hello World" program will run just fine on the Windows Python >> interpreter. >> 4) other. > > Hello, > > The answer is "it depends", or 4 on your list of responses. > > You can write pure python on a Linux machine and it will run fine on > Windows as long as you've taken care to program in a portable fashion. And not use modules not yet converted to microsoft, seems to happen from time to time. > if you have C-extensions in > your code you'll need to compile them over Windows. If you want to > program against the Windows API you'll need access to a Windows box. You can always cross compile, not only over OS but even CPU architecture, but of course testing will be more difficult, on x86 based Linux you can use wine or similar to test, but can give you some differences to run on a native or virtualized instance. -- //Aho From goran.novosel at gmail.com Sun Sep 19 15:43:28 2010 From: goran.novosel at gmail.com (Goran Novosel) Date: Sun, 19 Sep 2010 12:43:28 -0700 (PDT) Subject: Python and unicode Message-ID: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> Hi everybody. I've played for few hours with encoding in py, but it's still somewhat confusing to me. So I've written a test file (encoded as utf-8). I've put everything I think is true in comment at the beginning of script. Could you check if it's correct (on side note, script does what I intended it to do). One more thing, is there some mechanism to avoid writing all the time 'something'.decode('utf-8')? Some sort of function call to tell py interpreter that id like to do implicit decoding with specified encoding for all string constants in script? Here's my script: ------------------- # vim: set encoding=utf-8 : """ ----- encoding and py ----- - 1st (or 2nd) line tells py interpreter encoding of file - if this line is missing, interpreter assumes 'ascii' - it's possible to use variations of first line - the first or second line must match the regular expression "coding[:=]\s*([-\w.]+)" (PEP-0263) - some variations: ''' # coding= ''' ''' #!/usr/bin/python # -*- coding: -*- ''' ''' #!/usr/bin/python # vim: set fileencoding= : ''' - this version works for my vim: ''' # vim: set encoding=utf-8 : ''' - constants can be given via str.decode() method or via unicode constructor - if locale is used, it shouldn't be set to 'LC_ALL' as it changes encoding """ import datetime, locale #locale.setlocale(locale.LC_ALL,'croatian') # changes encoding locale.setlocale(locale.LC_TIME,'croatian') # sets correct date format, but encoding is left alone print 'default locale:', locale.getdefaultlocale() s='abcdef ??????????'.decode('utf-8') ss=unicode('ab ?????','utf-8') # date part of string is decoded as cp1250, because it's default locale all=datetime.date(2000,1,6).strftime("'%d.%m.%Y.', %x, %A, %B, ").decode('cp1250')+'%s, %s' % (s, ss) print all ------------------- From martin at v.loewis.de Sun Sep 19 16:01:00 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 19 Sep 2010 22:01:00 +0200 Subject: Python and unicode In-Reply-To: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> Message-ID: <4C966BFC.3070806@v.loewis.de> > One more thing, is there some mechanism to avoid writing all the time > 'something'.decode('utf-8')? Yes, use u'something' instead (i.e. put the letter u before the literal, to make it a unicode literal). Since Python 2.6, you can also put from __future__ import unicode_literals at the top of the file to make all string literals Unicode objects. Since Python 3.0, this is the default (i.e. all string literals *are* unicode objects). Regards, Martin From andrei.avk at gmail.com Sun Sep 19 16:29:52 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 16:29:52 -0400 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C9672C0.4080202@gmail.com> On 09/19/2010 02:21 PM, Seebs wrote: > On 2010-09-19, AK wrote: >> On 09/19/2010 03:31 AM, Seebs wrote: >>> Just like: >>> if condition: >>> foo >>> else: >>> bar > >>> The condition is the primary, the clauses are secondary to it. > >> To me, the problem with C ternary is, why is true condition first and >> false second? It could just as well be the other way around. > > Again, look at the long-form "if/else" above; it's always "if a then b > otherwise c". Because that's what 'if' and 'else' mean. I have no problem with '?' separating condition from possible outcomes.. The most natural reading of that construct is that depending on condition, there are two possible outcomes, separated by a ':' and you have to remember that first outcome corresponds to true condition. x = y if a else z is much more pythonic because 'else' is explicitly saying what happens on false condition. Explicit is better than implicit. > >> That's absolutely not how I read code. For example, if you have a line >> like: > >> x = x + 1 ASF!@#$!@$ASFASF!@#$!@$#ADFASDF!@# > >> Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is >> this?". > > Not for something that big and visible. But the if/else stuff is > just ordinary blocks of text. Not with syntax highlighting they're not ;) Seriously though, my guess is even without syntax highlighting I'd still prefer it because I do enough look-ahead and in 95% of cases the first 'if' is close enough to the beginning of the line. In fact, most often plain assignments will be much shorter than this construct so you can figure it out by combination of line length and the 'if' keyword. It still has the advantage over the more verbose version that I mentioned before: you can see immediately that there's an assignment to a single variable, and the logic flows like a single sentence in a natural language. > >> That's where syntax highlighting comes in, as well. > > So basically, if we use syntax highlighting to make up for the legibility > problems of a given syntax, then the syntax is okay, but people who don't > use syntax highlighting to make up for its legibility problems are wrong. That's not really true, it merely makes a given syntax easier to read even when it's already a preferable syntax. It's like this, if someone gives you five dollars for nothing, and then later gives you three dollars, you don't complain that the latter amount is less than former :). > > I see. > > This does seem self-contained; you like syntax highlighting because you > like constructs which are hard to read without it. You like those constructs > because they let you show off syntax highlighting. Well, you're exaggerating this out of all proportion just to prove a point. I like syntax highlighting in all of python and, in fact, in all languages I've used. Even in crontab files! This is a single construct I can think of, which, being already very readable, explicit, and succinct, *on top of that*, gains even more in readability due to syntax highlight. So, as you can see, I'd like syntax highlight just fine if this construct was not present in Python, and in fact I did. Conversely, I'd prefer it to the longer version if there was no syntax highlight at all. > >> After some time getting used to it, I'd end up seeing this as: > >> . >> . >> . >> if .. else: >> . >> . >> . > >> at first and then processing everything else. > > Assuming that the if/else was on the same page. :) I'll concede you one point in this case: if the statement 'x = .. if .. else .. ' is split over two pages, I would at least seriously consider the 'if: .. else: ' version. ;) -ak From usenet-nospam at seebs.net Sun Sep 19 17:32:29 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 21:32:29 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, AK wrote: > Because that's what 'if' and 'else' mean. My point is, I don't want the order of the clauses in if/else to change. If it is sometimes "if else ", then it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, then false clause. If it's sometimes "if condition true-clause else false-clause", and sometimes "true-clause if condition else false-clause", that's a source of extra complexity. > I have no problem with '?' > separating condition from possible outcomes.. The most natural reading > of that construct is that depending on condition, there are two possible > outcomes, separated by a ':' and you have to remember that first outcome > corresponds to true condition. Exactly as it ALWAYS does. That's the point. > x = y if a else z is much more pythonic > because 'else' is explicitly saying what happens on false condition. > Explicit is better than implicit. Is it "more pythonic" to shuffle the orders of clauses in precisely analagous constructs? I'm not arguing against the use of the *words* "if" and "else". I'm arguing that the shuffling of the orders of the clauses creates confusion. > It still has the advantage over the more verbose version that I > mentioned before: you can see immediately that there's an assignment to > a single variable, and the logic flows like a single sentence in a > natural language. I'm getting frustrated here because I really felt my point was pretty clearly expressed, and yet, every time you respond, you respond to things TOTALLY DIFFERENT from what I am saying. The syntax I like for this kind of thing is: x = if condition then true-clause else false-clause This is because it follows the same *ordering* as the multi-line if/else, so it preserves the logical flow. Condition, then true clause, then false clause. Always. The only way in which this is more verbose than the inverted one is the "then", and you don't even need that if you stick with a python-style colon: x = if condition: true-clause else false-clause But this is *always* easier to follow because it follows the same logical structure. Leave poetic inversion to the poets. > That's not really true, it merely makes a given syntax easier to read > even when it's already a preferable syntax. Except that it's *NOT PREFERABLE* to me, because it is BACKWARDS. Have I somehow failed to express this? Is there some magical rule that it is not pythonic for you to react in any way to the actual comparison I'm making, rather than to totally unrelated comparisons? I gave the example of what an if/else statement looks like, not because I think it is always better to use statements and blocks instead of expressions, but to point out the LOGICAL ORDER. You were asking why I preferred the condition to come first. My answer is, because the condition comes first in an if/else statement normally, and I like to preserve the logical flow. Instead, you're off ranting about how that's too long. But that's not my point. My point was *only* that the logical flow is consistent between if/else and the way various languages have done if/else expressions: Condition first, then true clause, then false clause. Doesn't matter whether it's ruby or C or lua or even bourne shell, in every other language I use that lets me use an if/else as part of an expression, it follows the SAME logical flow as the regular if/else statement. In Python, it's inverted. You were arguing that this inversion is better and more intuitive, and that there is no reason to expect the condition to come first. But there is! The condition comes first in regular if/else statements. This establishes a pattern -- if/else things are introduced by their condition, then you get the true clause and then you get the false clause. > Well, you're exaggerating this out of all proportion just to prove a > point. No, I'm not. > This is a single construct I > can think of, which, being already very readable, explicit, and > succinct, *on top of that*, gains even more in readability due to syntax > highlight. But it's *not readable to me*. Because it's backwards. > So, as you can see, I'd like syntax highlight just fine if this > construct was not present in Python, and in fact I did. Conversely, I'd > prefer it to the longer version if there was no syntax highlight at all. And again, NO ONE HAS SUGGESTED THE LONGER VERSION. AT ALL. EVER. I don't understand why you keep contrasting this with the longer version when the only reason that was brought up was to COMPARE it in terms of *logical flow*. I pointed out the *PARALLELS* between conditional expressions and conditional statements. I did not suggest that the longer version should be preferred in all cases, or even in all that many. > I'll concede you one point in this case: if the statement 'x = .. if .. > else .. ' is split over two pages, I would at least seriously consider > the 'if: .. else: ' version. ;) Okay, one more time: I am not proposing the use of multi-line statements as superior to conditional expressions. I am *ONLY* stating that I find the "true-clause if condition else false-clause" form confusing because it inverts the LOGICAL FLOW of multi-line if/else statements. By the nature of programming, I'm going to have to use if/else statements a lot. So I'm going to be used to the way they flow -- condition, true, false. Condition, true, false. Condition, true, false. It goes in that order every time, in every language I use, both when working with statements and when working with expressions. EXCEPT. That in one specific language, when doing expressions (but not statements), it is "True, condition, false." That's all I'm talking about. I am not arguing whether conditional expressions are better or worse than conditional statements. I am not arguing whether conditional expressions should exist at all. I am only pointing out that I find it much clearer when conditional expressions follow the same pattern as other conditional things. Condition, true, false. Is there something horribly unusual about wanting to take advantage of the fact that my brain has a much easier time processing things when they follow consistent patterns? -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 python at mrabarnett.plus.com Sun Sep 19 17:46:38 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 19 Sep 2010 22:46:38 +0100 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C9684BE.1040002@mrabarnett.plus.com> On 19/09/2010 22:32, Seebs wrote: > On 2010-09-19, AK wrote: >> Because that's what 'if' and 'else' mean. > > My point is, I don't want the order of the clauses in if/else to change. > If it is sometimes "if else", then > it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, > then false clause. If it's sometimes "if condition true-clause else > false-clause", and sometimes "true-clause if condition else false-clause", > that's a source of extra complexity. > [snip] Have you read PEP 308? There was a lot of discussion about it. From kwatford+python at gmail.com Sun Sep 19 17:59:38 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Sun, 19 Sep 2010 17:59:38 -0400 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) In-Reply-To: References: Message-ID: On Sun, Sep 19, 2010 at 9:16 AM, Aahz wrote: > In article , > geremy condra ? wrote: >>On Wed, Sep 1, 2010 at 4:35 PM, patrick mcnameeking >> wrote: >>> >>> I've been working with Python now for about a year using it primarily for >>> scripting in the Puredata graphical programming environment. I'm working on >>> a project where I have been given a 1000 by 1000 cell excel spreadsheet and >>> I would like to be able to access the data using Python. Does anyone know >>> of a way that I can do this? >> >>http://tinyurl.com/2eqqjxv > > Please don't use tinyurl -- it's opaque and provides zero help to anyone > who might later want to look it up (and also no accessibility if tinyurl > ever goes down). ?At the very least, include the original URL for > reference. > > (Yes, I realize this is probably a joke given the smiley I excised, but > too many people do just post tinyurl.) Not that I disagree with you, but you might find this helpful: http://tinyurl.com/preview.php From contact at xavierho.com Sun Sep 19 18:05:07 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 08:05:07 +1000 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) In-Reply-To: References: Message-ID: On 20 September 2010 07:59, Ken Watford > wrote: > > Not that I disagree with you, but you might find this helpful: > http://tinyurl.com/preview.php > -- > http://mail.python.org/mailman/listinfo/python-list > I don't think the OP wants a preview feature. The fact that you still have to go through tinyurl (which by the way, the short link itself in the email has no information on where it is whatsoever), and it makes searching through the archives difficult, too. We don't have a 140 character limit like Twitter. There's no reason we can't post the full link for reference purposes. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sun Sep 19 18:35:43 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 19 Sep 2010 15:35:43 -0700 (PDT) Subject: ctypes and buffers References: Message-ID: On Sep 19, 5:10?am, Thomas Jollans wrote: > On Sunday 19 September 2010, it occurred to Carl Banks to exclaim: > > I am creating a ctypes buffer from an existing non-ctypes object that > > supports buffer protocol using the following code: > > > from ctypes import * > > > PyObject_AsReadBuffer = pythonapi.PyObject_AsReadBuffer > > PyObject_AsReadBuffer.argtypes = > > [py_object,POINTER(c_void_p),POINTER(c_size_t)] > > PyObject_AsReadBuffer.restype = None > > > def ctypes_buffer_from_buffer(buf): > > ? ? cbuf = c_void_p() > > ? ? size = c_size_t() > > ? ? PyObject_AsReadBuffer(buf,byref(cbuf),byref(size)) > > ? ? return cbuf > > If I understand what you are doing correctly, you're referencing a Python > buffer object and returning a pointer wrapped in some ctypes thingy. hmm. I > see some problems in your code: > > ?* You're not passing the size along. In the name of sanity, why on earth > ? ?not?! The pointer cannot be safely used without knowing how long the area > ? ?of memory referenced is! How D'Olivero of you to overreact this way. A. No, and B. I already know the size of the object > ?* You're using the old buffer protocol. You might rather implement this with > ? ?the one introduced with Python 3.0, and supported in 2.6 as well. Hmm, I didn't know they got that into 2.6. Maybe I'll do that, thanks. Carl Banks From ben+python at benfinney.id.au Sun Sep 19 19:09:31 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Sep 2010 09:09:31 +1000 Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> Message-ID: <87k4mh5o0k.fsf@benfinney.id.au> Goran Novosel writes: > # vim: set encoding=utf-8 : This will help Vim, but won't help Python. Use the PEP 263 encoding declaration to let Python know the encoding of the program source file. # -*- coding: utf-8 -*- You can use the bottom of the file for editor hints. > s='abcdef ??????????'.decode('utf-8') > ss=unicode('ab ?????','utf-8') In Python 2.x, those string literals are created as byte strings, which is why you're having to decode them. Instead, tell Python explicitly that you want a string literal to be a Unicode text string: s = u'abcdef ??????????' ss = u'ab ?????' Learn more from the documentation . -- \ ?He that would make his own liberty secure must guard even his | `\ enemy from oppression.? ?Thomas Paine | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Sun Sep 19 19:18:57 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 20 Sep 2010 11:18:57 +1200 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> Message-ID: <8fnk3qFk0bU1@mid.individual.net> AK wrote: > Afaik the idea is that you can read a novel at the speed of half a page > a second or so and understand it to the same extent as people who'd read > at a normal rate. I've never understood why anyone would *want* to read a novel that fast, though. For me at least, reading a novel is something done for pleasure, so reading it at ten times normal speed would waste 90% of the benefit. -- Greg From usenet-nospam at seebs.net Sun Sep 19 19:30:32 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 23:30:32 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-19, MRAB wrote: > On 19/09/2010 22:32, Seebs wrote: >> On 2010-09-19, AK wrote: >>> Because that's what 'if' and 'else' mean. >> My point is, I don't want the order of the clauses in if/else to change. >> If it is sometimes "if else", then >> it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, >> then false clause. If it's sometimes "if condition true-clause else >> false-clause", and sometimes "true-clause if condition else false-clause", >> that's a source of extra complexity. > > [snip] > Have you read PEP 308? There was a lot of discussion about it. Interesting, in the historical section we see: The original version of this PEP proposed the following syntax: if else The out-of-order arrangement was found to be too uncomfortable for many of participants in the discussion; especially when is long, it's easy to miss the conditional while skimming. But apparently those objections were either unknown or disregarded when the syntax was later adopted. -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 Sep 19 19:32:09 2010 From: usenet-nospam at seebs.net (Seebs) Date: 19 Sep 2010 23:32:09 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: On 2010-09-19, Gregory Ewing wrote: > AK wrote: >> Afaik the idea is that you can read a novel at the speed of half a page >> a second or so and understand it to the same extent as people who'd read >> at a normal rate. > I've never understood why anyone would *want* to read a > novel that fast, though. For me at least, reading a novel > is something done for pleasure, so reading it at ten times > normal speed would waste 90% of the benefit. I get pleasure from the story, not from the time spent. Reading faster means I get more stories. Same thing, to some extent, with programming. I could easily spend much more time writing some programs by switching to a language ill-suited to them (say, using C for heavy string manipulation, or PHP for anything), but that wouldn't mean I had more fun, it would mean my fun was spread out over a longer period of time, and might well cross over to no-longer-fun. -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 Sun Sep 19 20:00:41 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 12:00:41 +1200 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: In message , Nobody wrote: > However, some clients choose their own source ports. E.g. rlogin/rsh use > privileged (low-numbered) ports, and you can't get the kernel to choose a > random privileged port for you. But nobody uses rlogin/rsh any more, and who would attach any trustworthy meaning to a connection coming from a remote low-numbered source port? > If you're writing a server which listens on a known port, you *should* be > using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel > will automatically reject packets relating to stale connections, and your > server should be accepting any new connections ASAP. That makes it sound like SO_REUSEADDR should really be a superfluous option. But it?s not. From ldo at geek-central.gen.new_zealand Sun Sep 19 20:02:28 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 12:02:28 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: In message , Aahz wrote: > Please don't use tinyurl -- it's opaque and provides zero help to anyone > who might later want to look it up (and also no accessibility if tinyurl > ever goes down). At the very least, include the original URL for > reference. +1 from someone who has seen URL-shortening used even in reader comments on websites which allow HTML links. From wuwei23 at gmail.com Sun Sep 19 20:33:53 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 19 Sep 2010 17:33:53 -0700 (PDT) Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> Message-ID: <46c489ec-2028-4a53-a184-f9f0afeb2ee6@h40g2000pro.googlegroups.com> AK wrote: > When I was reading The book of the new sun, though, I could stop and > read a single sentence a few times over and reflect on it for a minute. Totally understandable, Wolfe is a far, far greater writer than Rowling :) From andrei.avk at gmail.com Sun Sep 19 20:38:16 2010 From: andrei.avk at gmail.com (AK) Date: Sun, 19 Sep 2010 20:38:16 -0400 Subject: Too much code - slicing In-Reply-To: <8fnk3qFk0bU1@mid.individual.net> References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: <4C96ACF8.5000104@gmail.com> On 09/19/2010 07:18 PM, Gregory Ewing wrote: > AK wrote: > >> Afaik the idea is that you can read a novel at the speed of half a page >> a second or so and understand it to the same extent as people who'd read >> at a normal rate. > > I've never understood why anyone would *want* to read a > novel that fast, though. For me at least, reading a novel > is something done for pleasure, so reading it at ten times > normal speed would waste 90% of the benefit. > One definite advantage would be that if, say, it takes you 70 pages of a given novel to figure out whether you like it enough to continue, you'd want to read those pages in 2 minutes rather than an hour. Unfortunately, beginning of a novel is where I have to read at the slowest rate because I'm not used to author's style and pacing yet and I don't want to miss something crucial. -ak From tjreedy at udel.edu Sun Sep 19 20:38:49 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Sep 2010 20:38:49 -0400 Subject: newbie: class and __dict__ variable. In-Reply-To: References: Message-ID: On 9/19/2010 1:37 PM, mafeusek at gmail.com wrote: > > Hallo Group Members. From time to time I see in python code following > notation that (as I believe) extends namespace of MyClass. No, it does not affect MyClass, just the instance dict. > class MyClass: > def __init__(self): > self.__dict__["maci"]=45 Have you seen exactly this usage? > > myCl2 = MyClass2() > print myCl2.maci > > > I am guessing that there must be some difference between the one above > and the one below, because otherwise no one would probably use the one > above. Do YOu know that difference? > > class MyClass2: > def __init__(self): > self.maci=45 If the class has a .__setattr__ method, the first bypasses that method, the second results in it being called. The direct __dict__ access is most useful within a .__setattr__ method to avoid infinite recursion. > myCl = MyClass() > print myCl.maci -- Terry Jan Reedy From philip at semanchuk.com Sun Sep 19 20:54:35 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 19 Sep 2010 20:54:35 -0400 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) In-Reply-To: References: Message-ID: On Sep 19, 2010, at 6:05 PM, Xavier Ho wrote: > On 20 September 2010 07:59, Ken Watford > >> wrote: > >> >> Not that I disagree with you, but you might find this helpful: >> http://tinyurl.com/preview.php >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > I don't think the OP wants a preview feature. The fact that you still have > to go through tinyurl (which by the way, the short link itself in the email > has no information on where it is whatsoever), and it makes searching > through the archives difficult, too. > > We don't have a 140 character limit like Twitter. There's no reason we can't > post the full link for reference purposes. Some email systems still insert hard line breaks around the 72 or 80 column mark and as a result long URLs get broken. I hope anyone on this list would be able to surgically repair a broken URL, but I email plenty of people who can't and tinyurl & friends are really helpful in that context. bye P From usenet-nospam at seebs.net Sun Sep 19 21:36:14 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 01:36:14 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> <46c489ec-2028-4a53-a184-f9f0afeb2ee6@h40g2000pro.googlegroups.com> Message-ID: On 2010-09-20, alex23 wrote: > AK wrote: >> When I was reading The book of the new sun, though, I could stop and >> read a single sentence a few times over and reflect on it for a minute. > Totally understandable, Wolfe is a far, far greater writer than > Rowling :) Certainly true. On the other hand, I found it frustrating when I *had* to re-read a passage a couple of times to figure out what had just happened. :) ... Not that rereading books is necessarily a bad thing. -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 john at castleamber.com Sun Sep 19 22:32:17 2010 From: john at castleamber.com (John Bokma) Date: Sun, 19 Sep 2010 21:32:17 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: <87vd6116xa.fsf@castleamber.com> AK writes: > On 09/19/2010 07:18 PM, Gregory Ewing wrote: >> AK wrote: >> >>> Afaik the idea is that you can read a novel at the speed of half a page >>> a second or so and understand it to the same extent as people who'd read >>> at a normal rate. >> >> I've never understood why anyone would *want* to read a >> novel that fast, though. For me at least, reading a novel >> is something done for pleasure, so reading it at ten times >> normal speed would waste 90% of the benefit. >> > > One definite advantage would be that if, say, it takes you 70 pages of a > given novel to figure out whether you like it enough to continue, you'd > want to read those pages in 2 minutes rather than an hour. Heh, to me speed reading those 70 pages in a very short while, concluding that it's a good book, and start over again would be quite the spoiler. Do you fast forward movies as well? I do speed read but not the books I read for pleasure. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From pavlovevidence at gmail.com Sun Sep 19 22:32:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 19 Sep 2010 19:32:33 -0700 (PDT) Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> Message-ID: On Sep 19, 4:09?pm, Ben Finney wrote: > Goran Novosel writes: > > # vim: set encoding=utf-8 : > > This will help Vim, but won't help Python. Use the PEP 263 encoding > declaration to let Python > know the encoding of the program source file. That's funny because I went to PEP 263 and the line he used was listed there. Apparently, you're the one that needs to read PEP 263. Carl Banks From usenet-nospam at seebs.net Sun Sep 19 22:50:21 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 02:50:21 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> Message-ID: On 2010-09-20, John Bokma wrote: > Heh, to me speed reading those 70 pages in a very short while, > concluding that it's a good book, and start over again would be quite > the spoiler. I rarely encounter substantive spoilers in the first 70 pages or so of a book. That said, I'm pretty much immune to spoilers; while I'm reading, I'm usually ignoring anything I might have previously known about a story, so it all works even if I've read it before. > Do you fast forward movies as well? Amusingly, I can't generally watch movies at normal speed. They're too boring. Luckily, computers are finally advancing to a point where "1.2x faster, but no chipmunks" is an available setting in some software. -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 Sun Sep 19 22:57:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 19:57:16 -0700 Subject: C++ - Python API References: <416a98d9-f113-472b-b6e5-414cfa46a20c@v41g2000yqv.googlegroups.com> Message-ID: In article , Thomas Jollans wrote: >On Sunday 19 September 2010, it occurred to Aahz to exclaim: >> In article , >> Thomas Jollans wrote: >>>On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim: >>>> >>>> So the feature overview: >>> >>>First, the obligatory things you don't want to hear: Have you had >>>a look at similar efforts? A while ago, Aahz posted something very >>>similar on this very list. You should be able to find it in any of the >>>archives without too much trouble. >> >> You almost certainly have me confused with someone else -- I wouldn't >> touch C++ with a ten-meter pole if I could possibly help it. (The last >> time I dealt with C++ code, about a decade ago, I just rewrote it in C.) > >Sorry about that. No biggie, just wanted to prevent further confusion. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From aahz at pythoncraft.com Sun Sep 19 23:00:39 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Sep 2010 20:00:39 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: In article , Philip Semanchuk wrote: > >Some email systems still insert hard line breaks around the 72 or 80 >column mark and as a result long URLs get broken. I hope anyone on this >list would be able to surgically repair a broken URL, but I email plenty >of people who can't and tinyurl & friends are really helpful in that >context. There's no reason you can't cater to that problem by using tinyurl *in* *addition* to the full regular URL. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 23:36:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 03:36:42 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: <4c96d6ca$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 11:18:57 +1200, Gregory Ewing wrote: > AK wrote: > >> Afaik the idea is that you can read a novel at the speed of half a page >> a second or so and understand it to the same extent as people who'd >> read at a normal rate. > > I've never understood why anyone would *want* to read a novel that fast, > though. For me at least, reading a novel is something done for pleasure, > so reading it at ten times normal speed would waste 90% of the benefit. Or reduce the pain by 90%, depending on the book... -- Steven From justin.mailinglists at gmail.com Sun Sep 19 23:38:46 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Sun, 19 Sep 2010 20:38:46 -0700 (PDT) Subject: SimpleHTTPServer, external CSS, and Google Chrome References: <057af264-995d-4e60-9887-d053b93bd988@m17g2000prl.googlegroups.com> <2079bf56-6c19-4233-97d9-418b7e9d0190@a4g2000prm.googlegroups.com> Message-ID: <66c6c94a-9022-494d-8cce-04086f7106fb@v35g2000prn.googlegroups.com> On Sep 18, 2:54?am, MrJean1 wrote: > FWIW, > > There is a blue text on a red background in all 4 browsers Google > Chrome 6.0.472.59, Safari 5.0.1 (7533.17.8), FireFox 3.6.9 and IE > 6.0.2900.5512.... with Python 2.7 serving that page on my Windows XP > SP 3 machine. > > /Jean > Hmm. Will download and install newer python versions to re-check then. Thanks. From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 23:42:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 03:42:30 GMT Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> Message-ID: <4c96d826$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 09:09:31 +1000, Ben Finney wrote: > Goran Novosel writes: > >> # vim: set encoding=utf-8 : > > This will help Vim, but won't help Python. It will actually -- the regex Python uses to detect encoding lines is documented, and Vim-style declarations are allowed as are Emacs style. In fact, something as minimal as: # coding=utf-8 will do the job. > Use the PEP 263 encoding > declaration to let Python > know the encoding of the program source file. While PEPs are valuable, once accepted or rejected they become historical documents. They don't necessarily document the current behaviour of the language. See here for documentation on encoding declarations: http://docs.python.org/reference/lexical_analysis.html#encoding-declarations -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Sep 19 23:43:01 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 03:43:01 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: <4c96d845$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 06:16:49 -0700, Aahz wrote: > Please don't use tinyurl -- it's opaque and provides zero help to anyone > who might later want to look it up (and also no accessibility if tinyurl > ever goes down). At the very least, include the original URL for > reference. Do you have something against tinyurl in particular, or would any URL shortener service also get your ire? -- Steven From usenet-nospam at seebs.net Sun Sep 19 23:53:06 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 03:53:06 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Steven D'Aprano wrote: > On Sun, 19 Sep 2010 06:16:49 -0700, Aahz wrote: >> Please don't use tinyurl -- it's opaque and provides zero help to anyone >> who might later want to look it up (and also no accessibility if tinyurl >> ever goes down). At the very least, include the original URL for >> reference. > Do you have something against tinyurl in particular, or would any URL > shortener service also get your ire? I'd assume all of them have the same essential problems: * No hint as to what site you'll be getting redirected to. * No cues from URL as to what the link is to. * If the service ever goes away, the links become pure noise. -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 andrei.avk at gmail.com Mon Sep 20 00:03:48 2010 From: andrei.avk at gmail.com (AK) Date: Mon, 20 Sep 2010 00:03:48 -0400 Subject: Too much code - slicing In-Reply-To: <87vd6116xa.fsf@castleamber.com> References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> Message-ID: <4C96DD24.3020400@gmail.com> On 09/19/2010 10:32 PM, John Bokma wrote: > AK writes: > >> On 09/19/2010 07:18 PM, Gregory Ewing wrote: >>> AK wrote: >>> >>>> Afaik the idea is that you can read a novel at the speed of half a page >>>> a second or so and understand it to the same extent as people who'd read >>>> at a normal rate. >>> >>> I've never understood why anyone would *want* to read a >>> novel that fast, though. For me at least, reading a novel >>> is something done for pleasure, so reading it at ten times >>> normal speed would waste 90% of the benefit. >>> >> >> One definite advantage would be that if, say, it takes you 70 pages of a >> given novel to figure out whether you like it enough to continue, you'd >> want to read those pages in 2 minutes rather than an hour. > > Heh, to me speed reading those 70 pages in a very short while, > concluding that it's a good book, and start over again would be quite > the spoiler. Do you fast forward movies as well? I honestly doubt it would be a spoiler if it's a good book. Generally I find that poor books rely on twists and turns while better ones rely on the fabric of story-telling. Aside from that, though, it's a very interesting question - I'll try to think of good books and see if they'd be spoiled by peeking in the first 70 pages.. Starting with children's books, Peter Pan and Wind in the Willows, I think, would not be. Don quixote would not be. Crime and punishment - maybe if you get as far as the murder? Same author's the Devils, I would say you can read the last 70 pages and it'd be just as good :). -ak From mahaboobnisha at gmail.com Mon Sep 20 00:15:40 2010 From: mahaboobnisha at gmail.com (roshini begum) Date: Sun, 19 Sep 2010 21:15:40 -0700 (PDT) Subject: www.127760.blogspot.com Message-ID: <22f15036-d560-4bac-bc09-ef3f5fe5e721@g21g2000prn.googlegroups.com> www.127760.blogspot.com From john at castleamber.com Mon Sep 20 01:04:22 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 00:04:22 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> Message-ID: <87vd613t0p.fsf@castleamber.com> AK writes: > On 09/19/2010 10:32 PM, John Bokma wrote: >> AK writes: >> >>> On 09/19/2010 07:18 PM, Gregory Ewing wrote: >>>> AK wrote: >>>> >>>>> Afaik the idea is that you can read a novel at the speed of half a page >>>>> a second or so and understand it to the same extent as people who'd read >>>>> at a normal rate. >>>> >>>> I've never understood why anyone would *want* to read a >>>> novel that fast, though. For me at least, reading a novel >>>> is something done for pleasure, so reading it at ten times >>>> normal speed would waste 90% of the benefit. >>>> >>> >>> One definite advantage would be that if, say, it takes you 70 pages of a >>> given novel to figure out whether you like it enough to continue, you'd >>> want to read those pages in 2 minutes rather than an hour. >> >> Heh, to me speed reading those 70 pages in a very short while, >> concluding that it's a good book, and start over again would be quite >> the spoiler. Do you fast forward movies as well? > > I honestly doubt it would be a spoiler if it's a good book. Generally I > find that poor books rely on twists and turns while better ones rely on > the fabric of story-telling. Aside from that, though, it's a very > interesting question - I'll try to think of good books and see if they'd > be spoiled by peeking in the first 70 pages.. Starting with children's > books, Peter Pan and Wind in the Willows, I think, would not be. Don > quixote would not be. Crime and punishment - maybe if you get as far as > the murder? Same author's the Devils, I would say you can read the last > 70 pages and it'd be just as good :). -ak I didn't mean that there are spoilers in the first 70 pages, just that to me the excercise would spoil the book, so, I wouldn't do it. I consider a book like a meal, I wouldn't gobble down food, regurgitate it, and eat it again at a slower pace. Books, movies, family, walks are the things I prefer to do at a normal mudane pace, or even slower, if I can bring myself to it. My favourite books I try to read slow, and enjoy. ;-). Too much of my life is already in overdrive. -- 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 Sep 20 01:06:03 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 05:06:03 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Seebs wrote: > On 2010-09-20, Steven D'Aprano wrote: >> On Sun, 19 Sep 2010 06:16:49 -0700, Aahz wrote: >>> Please don't use tinyurl -- it's opaque and provides zero help to anyone >>> who might later want to look it up (and also no accessibility if tinyurl >>> ever goes down). At the very least, include the original URL for >>> reference. > >> Do you have something against tinyurl in particular, or would any URL >> shortener service also get your ire? > > I'd assume all of them have the same essential problems: > > * No hint as to what site you'll be getting redirected to. Tinyurl, in particular, allows you to preview the url if you choose to do so. Other URL shortning services have a similar feature. > * No cues from URL as to what the link is to. Same point as above. Same solution. > * If the service ever goes away, the links become pure noise. This happens a lot on the web anyway. Do you have any idea how many pieces of free software are first hosted on university servers to disappear when the author graduates/moves to another school or free shared host servers that have to be moved due to lack of scalability? Sourceforge solved much of this problem; but, then if sourceforge should ever disappear, all of its links will be pure noise as well. The simple fact is that the Internet changes. It changed before URL shortening services came into the mainstream and it will be true long after they have left. From usenet-nospam at seebs.net Mon Sep 20 01:06:47 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 05:06:47 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> <87vd613t0p.fsf@castleamber.com> Message-ID: On 2010-09-20, John Bokma wrote: > I didn't mean that there are spoilers in the first 70 pages, just that > to me the excercise would spoil the book, so, I wouldn't do it. I > consider a book like a meal, I wouldn't gobble down food, regurgitate > it, and eat it again at a slower pace. Books, movies, family, walks are > the things I prefer to do at a normal mudane pace, or even slower, if I > can bring myself to it. My favourite books I try to read slow, and > enjoy. ;-). Too much of my life is already in overdrive. Now that you explain it like this, that makes a fair bit of sense. I often wonder whether reading slowly would be more pleasant. I have no idea how to do it, so the question remains theoretical. -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 Sep 20 01:10:05 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 05:10:05 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Tim Harig wrote: > On 2010-09-20, Seebs wrote: >> * No hint as to what site you'll be getting redirected to. > Tinyurl, in particular, allows you to preview the url if you choose to do > so. Other URL shortning services have a similar feature. I have no idea how. If I see a "tinyurl" URL, and I paste it into a browser, last I tried it, I ended up on whatever page it redirected to. >> * No cues from URL as to what the link is to. > Same point as above. Same solution. I'm not reading news in a web browser. I don't want to have to cut and paste and go look at a page in order to determine whether I want to switch to my browser. >> * If the service ever goes away, the links become pure noise. > This happens a lot on the web anyway. True. > Do you have any idea how many > pieces of free software are first hosted on university servers to > disappear when the author graduates/moves to another school or free > shared host servers that have to be moved due to lack of scalability? > Sourceforge solved much of this problem; but, then if sourceforge should > ever disappear, all of its links will be pure noise as well. This is true. But two points of failure strikes me as worse than one. :) > The simple fact is that the Internet changes. It changed before URL > shortening services came into the mainstream and it will be true long > after they have left. Oh, certainly. I'm not particularly convinced that these are *significant* complaints about URL-shorteners. But I will say, of the last couple hundred links I've followed from Usenet posts, precisely zero of them were through URL redirectors. If I can't at least look at the URL to get some initial impression of what it's a link to, I'm not going to the trouble of swapping to a web browser to find out. -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 gavcomedy at gmail.com Mon Sep 20 01:17:45 2010 From: gavcomedy at gmail.com (gavino) Date: Sun, 19 Sep 2010 22:17:45 -0700 (PDT) Subject: compiling python 3.1.2 with local readline fails to get readline - help! References: Message-ID: On Sep 15, 6:41?pm, James Mills wrote: > On Thu, Sep 16, 2010 at 11:10 AM, gavino wrote: > > I am comiling 3.1.2. > > I am not root but a user. > > I compiled readline and it did not complain. > > gdb and zlib ?and some other modules also were not found. > > Like I said earlier in my previous post, is the readline line that > you compiled and installed to your home directory actually > working and can you actually compile any C programs that > use this custom readline ? > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" I don't know how to test readline. It compiled without complaint. I guess my questions boils down to how to point the python compile to the readline lib? I don't have root. From jeblanton at crimson.ua.edu Mon Sep 20 01:46:34 2010 From: jeblanton at crimson.ua.edu (Jordan Blanton) Date: Mon, 20 Sep 2010 00:46:34 -0500 Subject: programming Message-ID: I am in a computer science class in which I am supposed to be creating a program involving a sine wave and some other functions. I understand the concept of the problem, but I don't understand any of the "lingo" being used. The directions might as well be written in a different language. Is there anyone on here that might be able to help me in understanding what certain things mean? -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Mon Sep 20 01:46:38 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 05:46:38 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Seebs wrote: > On 2010-09-20, Tim Harig wrote: >> On 2010-09-20, Seebs wrote: >>> * No hint as to what site you'll be getting redirected to. > >> Tinyurl, in particular, allows you to preview the url if you choose to do >> so. Other URL shortning services have a similar feature. > > I have no idea how. If I see a "tinyurl" URL, and I paste it into > a browser, last I tried it, I ended up on whatever page it redirected > to. 1. Don't bother to manually paste when you can use something like urlview to lauch directly. 2. tinyurl addresses can be previewed by adding the "preview" subdomain to the tinyurl. For example, the address that started this subthread would become: http://preview.tinyurl.com/2eqqjxv If you want this behavior by default, you can easily wrap urlview to automatically add the prefix. >>> * If the service ever goes away, the links become pure noise. > >> This happens a lot on the web anyway. > > True. > >> Do you have any idea how many >> pieces of free software are first hosted on university servers to >> disappear when the author graduates/moves to another school or free >> shared host servers that have to be moved due to lack of scalability? >> Sourceforge solved much of this problem; but, then if sourceforge should >> ever disappear, all of its links will be pure noise as well. > > This is true. > > But two points of failure strikes me as worse than one. :) I question first whether most tinyurl links are really of such an intransient nature that they need to be long lasting. I personally use them most when writing paper notes. They only need to last long enough for me, or whoever I made the note for, to get back to them. In theory, something like this adds the possibilty of adding another level of indirection; which could make the system more robust if used properly. Just think of how much resiliency is gained by using DNS, which can be redirected, as opposed to IP addresses which you cannot take with you if you move. This is academic as tinyurl addresses cannot be changed; but, it does point out that simple logic such as two points of failure must be worse then one isn't always correct. >> The simple fact is that the Internet changes. It changed before URL >> shortening services came into the mainstream and it will be true long >> after they have left. > > I'm not particularly convinced that these are *significant* complaints > about URL-shorteners. But I will say, of the last couple hundred links > I've followed from Usenet posts, precisely zero of them were through > URL redirectors. If I can't at least look at the URL to get some > initial impression of what it's a link to, I'm not going to the trouble > of swapping to a web browser to find out. But why should the rest of us be penalized because you make the choice not to use (or not take full advantage of) all of the tools that are available to you? From debatem1 at gmail.com Mon Sep 20 01:50:34 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 19 Sep 2010 22:50:34 -0700 Subject: programming In-Reply-To: References: Message-ID: On Sun, Sep 19, 2010 at 10:46 PM, Jordan Blanton wrote: > I am in a computer science class in which I am supposed to be creating a > program involving a sine wave and some other functions. I understand the > concept of the problem, but I don't understand any of the "lingo" being > used. The directions might as well be written in a different language. Is > there anyone on here that might be able to help me in understanding what > certain things mean? Yes. Geremy Condra From haring at preypacer.com Mon Sep 20 02:08:09 2010 From: haring at preypacer.com (Ralf Haring) Date: Sun, 19 Sep 2010 23:08:09 -0700 (PDT) Subject: visual studio 2010 question Message-ID: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> After running into the error "Setup script exited with error: Unable to find vcvarsall.bat" when trying to use easy_install / setuptools a little digging showed that the MS compiler files in distutils only support up to Studio 2008. Does anyone know if there is a timetable for when Studio 2010 will be supported? I am using python 2.6.5, but web searching seemed to show that 2.7 or 3.X didn't support it yet either. -Ralf Haring From contact at xavierho.com Mon Sep 20 02:18:03 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 16:18:03 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 15:46, Jordan Blanton wrote: > I am in a computer science class in which I am supposed to be creating a > program involving a sine wave and some other functions. I understand the > concept of the problem, but I don't understand any of the "lingo" being > used. The directions might as well be written in a different language. Is > there anyone on here that might be able to help me in understanding what > certain things mean? > If you can tell us what terms you don't understand, we may be able to provide you some explanations. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Mon Sep 20 02:22:18 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 06:22:18 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Tim Harig wrote: > 1. Don't bother to manually paste when you can use something like urlview > to lauch directly. I don't know that this would actually be better than what I currently do, which is grab text and middle-click in another window. > If you want this behavior by default, you can easily wrap urlview > to automatically add the prefix. True, but since my news reading is not on the machine my web browser is on, it seems like it might get annoying. > I question first whether most tinyurl links are really of such an > intransient nature that they need to be long lasting. I personally use > them most when writing paper notes. They only need to last long enough > for me, or whoever I made the note for, to get back to them. By default, I assume that Usenet posts are for the longer term, and a Usenet post which relies for its content on tinyurl is thus somewhat more vulnerable than one which doesn't. In particular, consider things like archive.org; they may well be able to find a long-dead web page, but not a long-dead tinyurl link. > This is academic as tinyurl addresses cannot be changed; but, it > does point out that simple logic such as two points of failure must be > worse then one isn't always correct. Not always correct, but I think it is in this case. > But why should the rest of us be penalized because you make the choice > not to use (or not take full advantage of) all of the tools that are > available to you? For about the same reason that I should be penalized because someone else wanted things done differently. Which is to say, it's a tradeoff, the right choice to make depends on what your goals are. If you want a piece of information to have maximal longevity, something like tinyurl is probably a bad way to transmit it. If you want something small that survives line wrapping, it's probably a good way. FWIW, the browsers I use automatically Do The Right Thing if you paste in a multiline URL. -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 Mon Sep 20 02:22:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 06:22:41 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 05:46:38 +0000, Tim Harig wrote: >> I'm not particularly convinced that these are *significant* complaints >> about URL-shorteners. But I will say, of the last couple hundred links >> I've followed from Usenet posts, precisely zero of them were through >> URL redirectors. If I can't at least look at the URL to get some >> initial impression of what it's a link to, I'm not going to the trouble >> of swapping to a web browser to find out. > > But why should the rest of us be penalized because you make the choice > not to use (or not take full advantage of) all of the tools that are > available to you? I'm with Aahz... best practice is to post both the full and shortened URL, unless the URL is less that 78 characters, in which case just post the full version. Similarly, if I'm posting a link to some URL that looks like this: http://blah blah blah/link=useful-bit&noise&rubbish&crap&crap&crap&more- crap&lots-more-crap-for-three-more-lines I try editing the URL to http://blah blah blah/link=useful-bit and if the link still works, I just post that. Google search results, I'm looking at you. (Although they're not even *close* to the worst.) Personally, I think that any professional business or government site that exposes URLs filled with parameters, without giving a shortened "permalink" version, is full of Fail. -- Steven From justin.mailinglists at gmail.com Mon Sep 20 02:26:11 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Sun, 19 Sep 2010 23:26:11 -0700 (PDT) Subject: SimpleHTTPServer, external CSS, and Google Chrome References: <057af264-995d-4e60-9887-d053b93bd988@m17g2000prl.googlegroups.com> <2079bf56-6c19-4233-97d9-418b7e9d0190@a4g2000prm.googlegroups.com> <66c6c94a-9022-494d-8cce-04086f7106fb@v35g2000prn.googlegroups.com> Message-ID: LOL. twas http://bugs.python.org/issue839496 From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 02:26:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 06:26:20 GMT Subject: [OT] Speed-reading [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c96fe8b$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 10:29:10 -0400, AK wrote: > On 09/18/2010 11:28 PM, Steven D'Aprano wrote: [...] >> My wife can read scarily fast. It's very something to watch her reading >> pages as fast as she can turn them, and a few years ago she read the >> entire Harry Potter series (to date) in one afternoon, and could gives >> a blow-by-blow account of the plots, including a detailed critique of >> the writing style and characters. But then, she feels that reading the >> Potter series is a chore to be completed as fast as possible, rather >> than a pleasure to be savored. She'll sometimes drag a new Terry >> Pratchett or Stephen King novel out for as much as two days. >> >> >> > That's pretty impressive. I used to get somewhat close to that speed > when, years ago, I'd read a lot of trashy scifi. [...] > In other spots, I'd > be able to scan a few words at the top of page, a few in the middle and > at the bottom and I'd know what's going on, generally. I don't know about how other people speed-read, but I can assure you that when my wife speed-reads, she's not just scanning a few words and interpolating between them. She can give you a detailed summary of what *actually* happened, not just a good guess. Including pointing out any spelling or grammatical errors and clumsy writing. *Especially* the spelling errors, they have about the same effect on her reading speed as a tree trunk lying across a Formula 1 race track. -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 02:29:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 06:29:57 GMT Subject: [OT] Syntax highlighting [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c96ff65$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 07:36:11 +0000, Seebs wrote: > On 2010-09-19, Steven D'Aprano > wrote: >> I'm not entirely sure I agree with you here... you can't ignore syntax >> in order to understand the meaning of code. > > No, but the syntax should be invisible. When I read English, I don't > have to think about nouns and verbs and such unless something is very > badly written. That's almost certainly because you've been listening to, speaking, reading and writing English since you were a small child, and the syntax and grammar of English is buried deep in your brain. And you certainly do think about nouns and verbs, you just don't *consciously* think about them. If I write: "Susan blooged the mobblet." you will probably recognise "bloog" as the verb and "mobblet" as the noun, even though you've almost certainly never seen those words before and have no idea what they mean. But if I write this: "Susan is mobblet the blooged." you'll probably give a double-take. The words don't look right for English grammar and syntax. I've been reading, writing and thinking in Python for well over a decade. The syntax and grammar is almost entirely invisible to me too. No surprise there -- they are relatively close to that of the human languages I'm used to (English). But if I were a native Chinese or Arabic speaker, I'd probably find Python much less "natural" and *would* need to explicitly think about the syntax more. [...] >> The term "syntax highlighting" for what editors I've seen do is >> actually misleading -- they don't highlight *syntax*, they try to >> highlight *semantics*. > > I've never seen this. I've seen things highlight comments and keywords > and operators and constants and identifiers differently. Exactly. Things are highlighted because of *what* they are, not because of the syntax they use or because of the grammatical role they play. In a Python expression like: y = none or None an editor might colour "None" green because it's a known keyword, but "none" black because it's a variable. If you change the syntax: y = None if [none][0] is None else {None: none}[None] the colours remain the same. None is coloured green not because of *where* it is in the syntax tree, but because of *what* it is. Calling this "syntax highlighting" is misleading, or at least incomplete. >> When your editor highlights the function len() in the expression "x = >> len(y) + spam(z)" but not the function spam(), you know it has nothing >> to do with syntax. len() is singled out because of its semantics, >> namely the fact that it's a built-in. > > Eww. (I had not yet gotten to the point of finding out that whether > something was "built-in" or not substantially affected its semantics.) In some languages, built-in functions truly are special, e.g. they are reserved words. That's not the case for Python. Nevertheless, the editors I've used treat built-ins as "pseudo-reserved words" and colourise them. >> In English, the meaning of the some sentences do benefit by syntax >> highlighting, and in fact that's partly what punctuation is for: >> English partly uses punctuation marks as tags to break the sentence >> structure into sub-sentences, clauses and terms (particularly when the >> sentence would otherwise be ambiguous). > > Punctuation is very different from highlighting, IMHO. That said, I > find punctuation very effective at being small and discrete, clearly not > words, and easy to pick out. Color cues are not nearly as good at being > inobtrusive but automatically parsed. Well that surely depends on the colour scheme you have. My editor is fairly restrained -- it uses a handful of colours (although of course you can customize it and go nuts), and I've made it even more subtle. To my eyes, the feature of syntax highlighting that alone makes it worthwhile, its killer feature, is that I can set comments and docstrings to grey. When I'm scanning code, being able to slide my eyes over greyed- out comments and docstrings and ignore them with essentially zero effort is a huge help. That's the thing I most miss, more than anything else, when using a dumb editor. >> "Woman shoots man with crossbow" > >> Was it the man armed with a crossbow, or the woman? If we could somehow >> group the clause "with crossbow" with "woman" or "man" by something >> *other* than proximity, we could remove the ambiguity. > > Yes. But syntax highlighting won't help you here -- at least, I've > never yet seen any editor that showed precedence relations or anything > similar in its coloring. Just because nobody has done it yet doesn't mean that some sufficiently intelligent software in the future couldn't do it :) -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 02:30:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 06:30:30 GMT Subject: The trouble with "dynamic attributes". References: <4c929052$0$1601$742ec2ed@news.sonic.net> <4c93a06c$1@dnews.tpgi.com.au> <4c95b1c3$1@dnews.tpgi.com.au> Message-ID: <4c96ff85$0$11113$c3e8da3@news.astraweb.com> On Sun, 19 Sep 2010 16:47:26 +1000, Lie Ryan wrote: > On 09/18/10 03:53, Ethan Furman wrote: >> Lie Ryan wrote: >> [snip] >>> And even dict-syntax is not perfect for accessing XML file, e.g.: >>> >>> >>> foo >>> bar >>> >>> >>> should a['b'] be 'foo' or 'bar'? >> >> Attribute style access would also fail in this instance -- how is this >> worked-around? > > By not having multiple b in the first place! Which works just as well for dict access. Given that attribute access is nothing but syntactic sugar for dict access, there is nothing you can do with attribute access that can't be done with dict access. However, the same does not apply in reverse -- there are many things you can't do with attribute access that work fine with dict access. -- Steven From contact at xavierho.com Mon Sep 20 02:34:16 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 16:34:16 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 16:25, Jordan Blanton wrote: > its not specific terms that i dont understand. its general directions. but > when i dont understand one or two key points in a sentence, its hard to > understand what the directions are telling me to do. Is it possible for you to share the sentence / description with us? My psychic powers have its limits. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From contact at xavierho.com Mon Sep 20 02:34:16 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 16:34:16 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 16:25, Jordan Blanton wrote: > its not specific terms that i dont understand. its general directions. but > when i dont understand one or two key points in a sentence, its hard to > understand what the directions are telling me to do. Is it possible for you to share the sentence / description with us? My psychic powers have its limits. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From cournape at gmail.com Mon Sep 20 02:39:34 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 20 Sep 2010 15:39:34 +0900 Subject: visual studio 2010 question In-Reply-To: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> References: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> Message-ID: On Mon, Sep 20, 2010 at 3:08 PM, Ralf Haring wrote: > > After running into the error "Setup script exited with error: Unable > to find vcvarsall.bat" when trying to use easy_install / setuptools a > little digging showed that the MS compiler files in distutils only > support up to Studio 2008. Does anyone know if there is a timetable > for when Studio 2010 will be supported? > > I am using python 2.6.5, but web searching seemed to show that 2.7 or > 3.X didn't support it yet either. You should use VS 2008 - the lack of distutils support is only the first of a long list of issues if you want to use another compiler to build python extensions. Unless you really know what you are doing, you are better off with VS 2008, cheers, David From contact at xavierho.com Mon Sep 20 02:39:57 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 16:39:57 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 16:38, Jordan Blanton wrote: > Honestly, if I knew what was being said, then yes. I posted the directions > to the project and what I've done so far but I have no idea if what I'm > doing is right at all. > > Jordan, correct me if I'm mistaken, but you didn't post the directions to the project, nor what you've done so far - at least not on Python-list. Double check your emails that you didn't just reply to specifically someone, and not the whole list? Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From mafeusek at gmail.com Mon Sep 20 02:42:30 2010 From: mafeusek at gmail.com (mafeusek at gmail.com) Date: Mon, 20 Sep 2010 08:42:30 +0200 Subject: newbie: class and __dict__ variable. In-Reply-To: (Terry Reedy's message of "Sun, 19 Sep 2010 20:38:49 -0400") References: Message-ID: Terry, thank You very much for Your answer. Very helpfull! > Have you seen exactly this usage? NO, i just wrote an example, but the trick is quite frequent, thus it will be easy to check out the existence of .__setattr__ in such a case. best regards, Pawel From usenet-nospam at seebs.net Mon Sep 20 02:51:52 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 06:51:52 GMT Subject: [OT] Speed-reading [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> <4c96fe8b$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Steven D'Aprano wrote: > I don't know about how other people speed-read, but I can assure you that > when my wife speed-reads, she's not just scanning a few words and > interpolating between them. She can give you a detailed summary of what > *actually* happened, not just a good guess. Including pointing out any > spelling or grammatical errors and clumsy writing. *Especially* the > spelling errors, they have about the same effect on her reading speed as > a tree trunk lying across a Formula 1 race track. Yeah. I think it's because the entire trick is to have a nice smooth pipeline, and the error-checking mechanism has to be pretty alert for that to work -- you have to know if something went wrong. And a spelling error in the text is initially indistinguishable from a reading error in the eye... -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 Sep 20 03:02:23 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 07:02:23 GMT Subject: [OT] Syntax highlighting [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> <4c96ff65$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Steven D'Aprano wrote: > On Sun, 19 Sep 2010 07:36:11 +0000, Seebs wrote: >> No, but the syntax should be invisible. When I read English, I don't >> have to think about nouns and verbs and such unless something is very >> badly written. > That's almost certainly because you've been listening to, speaking, > reading and writing English since you were a small child, and the syntax > and grammar of English is buried deep in your brain. Yes. But I've been programming long enough that I seem to get similar results in most languages pretty quickly. > And you certainly do think about nouns and verbs, you just don't > *consciously* think about them. Well, yes. But it's conscious think time that's the limiting resource for the most part -- so if I can avoid things that require conscious thought, that frees up more for thinking about the problem. > you will probably recognise "bloog" as the verb and "mobblet" as the > noun, even though you've almost certainly never seen those words before > and have no idea what they mean. But if I write this: > "Susan is mobblet the blooged." > you'll probably give a double-take. The words don't look right for > English grammar and syntax. Well, actually, at that point I just assume you missed the capital m on what is apparently a proper noun. :) > I've been reading, writing and thinking in Python for well over a decade. > The syntax and grammar is almost entirely invisible to me too. No > surprise there -- they are relatively close to that of the human > languages I'm used to (English). But if I were a native Chinese or Arabic > speaker, I'd probably find Python much less "natural" and *would* need to > explicitly think about the syntax more. That's a fascinating question. I don't think that would be the case, though. Or at least. If you've used more than a couple of programming languages that much, I wouldn't expect it to be the case. I'm not a native speaker of Chinese, but after a year in China, I stopped perceiving grammar and just heard sentences. (Sadly, I've mostly since lost the vocabulary, leaving me with the annoyance of a language I can think in grammatically but can't express much of anything in.) >> I've never seen this. I've seen things highlight comments and keywords >> and operators and constants and identifiers differently. > Exactly. Things are highlighted because of *what* they are, not because > of the syntax they use or because of the grammatical role they play. Hmm, interesting point. e.g., a function name is likely to be highlighted the same whether I'm calling it or referring to it as an object. (I'm very new to Python, so I'm not 100% sure functions are a kind of an object, but I seem to recall they were.) I guess that's a point; "syntax coloring" is perhaps not the right word either for what they do. > In a Python expression like: > y = none or None > an editor might colour "None" green because it's a known keyword, but > "none" black because it's a variable. If you change the syntax: > y = None if [none][0] is None else {None: none}[None] > the colours remain the same. None is coloured green not because of > *where* it is in the syntax tree, but because of *what* it is. Calling > this "syntax highlighting" is misleading, or at least incomplete. This strikes me as correct. But it's not exactly semantics, either. It's... I dunno what to call it. >> Eww. (I had not yet gotten to the point of finding out that whether >> something was "built-in" or not substantially affected its semantics.) > In some languages, built-in functions truly are special, e.g. they are > reserved words. That's not the case for Python. Nevertheless, the editors > I've used treat built-ins as "pseudo-reserved words" and colourise them. Interesting. I wonder why. I guess just because if you meant to name a variable with one of those words, maybe you'd want the reminder. >> Punctuation is very different from highlighting, IMHO. That said, I >> find punctuation very effective at being small and discrete, clearly not >> words, and easy to pick out. Color cues are not nearly as good at being >> inobtrusive but automatically parsed. > Well that surely depends on the colour scheme you have. Only partially. The big thing, I think, is that punctuation is separate things next to words, not attributes of words. Come to think of it, that may be why I sometimes like to see keywords and other times punctuation. I like {} better than do/end, for the same reason I prefer parentheticals in English to something like: And this is a digression contrived end digression example. I much prefer: And this is a (contrived) example. > To my eyes, the feature of syntax highlighting that alone makes it > worthwhile, its killer feature, is that I can set comments and docstrings > to grey. When I'm scanning code, being able to slide my eyes over greyed- > out comments and docstrings and ignore them with essentially zero effort > is a huge help. That's the thing I most miss, more than anything else, > when using a dumb editor. That makes some sense. In sh/python/Ruby/lua, I don't have any troubles with it because the comment mechanism is fairly unambiguous. I'm fine in C as long as people remember the * on the left hand side of long comments. Omit that, and I get fussy. :) > Just because nobody has done it yet doesn't mean that some sufficiently > intelligent software in the future couldn't do it :) True. It raises a curious question. Imagine that you had the option of having color highlighting to show precedence and/or grouping in complicated expressions. Would that be better or worse than parentheses? For instance, consider the classic: x + y * z In many programming languages, this is equivalent to: x + (y * z) But would it be clearer to just have the unpunctuated text, with the "y * z" in, say, a slightly lighter or darker shade? I don't *think* so, but I'm honestly not totally sure. -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 contact at xavierho.com Mon Sep 20 03:13:33 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 17:13:33 +1000 Subject: programming In-Reply-To: References: Message-ID: Thanks Jordan. My reply will be in Blue. I apologise if this ever gets hard to read, but it's beginning to. On 20 September 2010 16:51, Jordan Blanton wrote: > "And so he started on a module that estimated the length of a sine wave. > Here is what he wrote: " > ok. what is a module? A Python module is a .py file. Nothing more. > Create a *project0* directory off of your *cs150* directory and move into > *project0*. > > Name your main python file *stopping.py*. Provide one more file named * > support.py* Dr. Lusth's code should go into the *support.py* file. The > main function in *stopping.py* should call a function that prompts the > user of your program for the following information, in the order given. > > - amplitude of the sine wave (in feet) > - period of the sine wave (in feet) > - distance to the stop sign (in feet) > - distance needed to stop without using hand brakes (in feet) > > Ok. is there a difference between my main file and the "one more file"? Yeah, they are two different files. > Do I create these by going into the project0 directory and typing "touch > support.py" and "touch stopping.py"? Well, I generally just open up a text editor and save it as (for example) support.py. If you're on Linux, gedit will do the trick. They're just plain text files. > What does is mean when is says that the main function in stopping.py should > *call* a function that prompts the user of your program......? > It means the main function in stopping.py should ask for user input in the terminal. In other words, your program need to be able to read from console input (stdin in C, or use the input() function in Python) and save them for calculation. > "Your main function should call at least one of the functions in the > support file. You will need to import these functions into your main program > by placing this line at the top of *stopping.py*. > Also, your *stopping.py* file should have two function definitions in it, > the definition of *main* and the definition of a function that obtains > information from the user. " > ok. how do i import functions into my main program? what exactly is my main > program? stopping.py? and how do i define my main program? > Ironically, Python doesn't have a "main" function. But it's a generally accepted practice that you would define something like this: def main(): # Do something here if __name__ == '__main__': main() The first bit is the main function definition, in which you should program what it is supposed to do. The second bit tells Python to run main() when the module is run directly (like calling "python stopping.py" without the quotes to run your program in the terminal.) > > Here is part of what is given in the directions: These are codes > provided... > > import math > # > # A module for approximating the length of the path traced out > > # by a sine wave. > # > # written by John C. Lusth > # > > # > # compute the length of the wavy line traced out by a sine wave > > # via approximation. The value of 'step' controls the accuracy of > # the approximation > > > # > > def sineLength(amplitude,period,xDistance,step): > x = 0.0 > total = 0.0 > lastx = 0 > lasty = 0 > > while x <= xDistance + (step / 2): > y = amplitude * math.sin(2 * math.pi / period * x) > > > d = distance(lastx,lasty,x,y) > #print(" distance from (",lastx,",",lasty,") to (",x,",",y,") is",d) > > total = total + d > lastx = x > > > lasty = y > x = x + step > return total > > # > # compute the distance between point (a,b) and point (b,c) > # > > def distance(a,b,c,d): > > return > > What do all the #'s mean? > > You really should start by doing some Python tutorials. How to Think Like a Computer Scientistis a good one. I'm not sure if you're prepared enough to do this project on your own. In short, # is a commet in the file. Same as // in C or Java, if you have done them before. They're ignored by the compiler, so you can put notes in there. > Why are all the values set at 0? > > Because that's how you initialise (and declare) variables in Python. This way, you can use them later. The initial value in your case is not very relevant, except for the total. > What should follow "return" at the very end? > > The function calculates the distance between Point (a, b) and Point (c, d). I think that's a typo in the comment for that function. Besides, it should have been a proper doc comment. Tell your instructor to code like Python, not like C. You'll want something like: def distance(a, b, c, d): '''Returns the distance between point(a, b) and point(c, d).''' # Use Pythagorean Theoremhere # return the distance you calculated ' Note how I commented the function. This is the standard Python convention, and you can later on use help(distance) to extract that documentation if needed. Seriously, though, do yourself a favour and do some Python tutorial first. You seem pretty new to Python. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From goran.novosel at gmail.com Mon Sep 20 03:23:48 2010 From: goran.novosel at gmail.com (Goran Novosel) Date: Mon, 20 Sep 2010 00:23:48 -0700 (PDT) Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <4C966BFC.3070806@v.loewis.de> Message-ID: <8910136c-04f0-4d65-9b52-82318c83ccd3@k11g2000vbf.googlegroups.com> Can't believe I missed something as simple as u'smt', and I even saw that on many occasions... Thank you. From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 03:27:25 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 09:27:25 +0200 Subject: newbie: class and __dict__ variable. In-Reply-To: References: Message-ID: <4c970cdd$0$21775$426a74cc@news.free.fr> Terry Reedy a ?crit : > On 9/19/2010 1:37 PM, mafeusek at gmail.com wrote: >> >> Hallo Group Members. From time to time I see in python code following >> notation that (as I believe) extends namespace of MyClass. > > No, it does not affect MyClass, just the instance dict. > >> class MyClass: >> def __init__(self): >> self.__dict__["maci"]=45 > > Have you seen exactly this usage? > >> >> myCl2 = MyClass2() >> print myCl2.maci >> >> >> I am guessing that there must be some difference between the one above >> and the one below, because otherwise no one would probably use the one >> above. Do YOu know that difference? >> >> class MyClass2: >> def __init__(self): >> self.maci=45 > > If the class has a .__setattr__ method, the first bypasses that method, It also bypasses object.__setattribute__ and - as a consequence - any binding descriptor by the same name as the attribute being set. >> myCl = MyClass() >> print myCl.maci > From contact at xavierho.com Mon Sep 20 03:29:30 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 17:29:30 +1000 Subject: programming In-Reply-To: References: Message-ID: Okay, it looks like you're doing well. I'm just going through your second email now, and it seems many of my comments in the first email is irrelavent to you anymore, because you already knew how to do it. =] Let's have a look. Again, my reply is in Blue. . *And what I've attempted to do so far.... *so far, i have gone into the cs150 directory as instructed and created a project0 directory. in that directory i typed in touch support.py and touch stopping.py to create the support and stopping files. is that correct so far? then i typed in vim support.py to edit the support.py file. I believe in vim you can save your file, too, anyway, so the touch part is probably unnecessary, but won't hurt. def distance(a,b,c,d): return sqrt(a**2+b**2), sqrt(c**2+d**2) That won't do. You're returning the distance between the origin and (a, b), and another distance between the origin and (c, d). Think about this again. If I understand this correctly, you should be only returning one value (not two, which is what you're doing now), that is the distance between (a, b) and (c, d). from support import* from support import * Note the space before *. It makes things more pleasant, even when your version compiles. def main(): def getinfo(): amplitude=eval(input(" Amplitude of the sine wave (in feet): ")) period=eval(input("Period of the sine wave (in feet): ")) xDistance=eval(input("Distance to the stop sign (in feet): ")) distance2=eval(input("Distance needed to stop without using brakes (in feet): ")) return amplitude,period,xDistance,distance2 amplitude,period,xDistance,distance2=getinfo() s=sineLength(amplitude,period,xDistance,1) print(xDistance,distance2,s) I'm almost 100% certain your instructor wanted you to have getinfo() outside of main(). It's valid to have a function inside a function, but there's not much point to it. Secondly, that doesn't even compile. Nor does xDistance=eval(input("Distance to the stop sign (in feet): ")) by itself. Without going into how slobby the use of eval() is in your case, you can fix it and make it syntax-legal by adding another quotes around your input function. xDistance = eval('input("Distance to the stop sign (in feet): ")') main() It's okay to run your main() method that way, as long as you're sure stopping.py isn't going to be imported by anyone else. I realize this is probably elementary, but I've never done anything like this, and kind of got thrown into it. It's very much a teach-yourself-course, so I guess if you don't really understand the lingo, it's easy to fall behind. You're doing well as far as I can tell. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From contact at xavierho.com Mon Sep 20 03:32:49 2010 From: contact at xavierho.com (Xavier Ho) Date: Mon, 20 Sep 2010 17:32:49 +1000 Subject: programming In-Reply-To: References: Message-ID: On 20 September 2010 17:29, Xavier Ho wrote: > Secondly, that doesn't even compile. Nor does > > xDistance=eval(input("Distance to the stop sign (in feet): ")) > Just correcting myself here. It compiles, but generates an error when you give it a number, which still fails. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Mon Sep 20 03:33:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 19:33:45 +1200 Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: In message , Alex Willmer wrote: > On Sep 19, 12:20 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message >> , Alex >> >> Willmer wrote: >> > # NB Constants are by convention ALL_CAPS >> >> SAYS_WHO? > > Says PEP 8: > > Constants > > Constants are usually declared on a module level and written in all > capital letters with underscores separating words. Examples include > MAX_OVERFLOW and TOTAL. > > -- http://www.python.org/dev/peps/pep-0008/ WHAT_IF_SOMETHING_IS_INITIALLY_CONSTANT,_BUT_LATER_BECOMES_A_CONFIG_VARIABLE,_OR_VICE_VERSA,_DOES_IT_NEED_TO_CHANGE_ITS_NAME? From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 03:34:23 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 09:34:23 +0200 Subject: Learning inheritance In-Reply-To: References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> Message-ID: <4c970e7f$0$21775$426a74cc@news.free.fr> alex23 a ?crit : > > Python only actually executes a module the first time it's imported, Beware of multithreading and modules imported under different names... There can be issues with both in some web frameowrks. From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 03:39:14 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 09:39:14 +0200 Subject: Learning inheritance In-Reply-To: <8632bf75-3963-4e85-99f3-684dcde99589@i17g2000vbq.googlegroups.com> References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> <8632bf75-3963-4e85-99f3-684dcde99589@i17g2000vbq.googlegroups.com> Message-ID: <4c970fa2$0$7946$426a74cc@news.free.fr> Niklasro a ?crit : > Good to learn what I'm doing :-) since important being able to explain > choices taken farther than "doing it because it works". > I understand the concept of modules may not correspond to java > programming where I come from. Coming from Java - and specially if you only have experience with Java -, you'll have to unlearn quite a few things. Python is 100% object - in that everything you can bind to a name is an object, including classes, functions, methods, and even modules - but it doesn't try to force you into using classes when you don't need them. From zooko at zooko.com Mon Sep 20 03:49:34 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Mon, 20 Sep 2010 01:49:34 -0600 Subject: announcing pycryptopp-0.5.20 Message-ID: Folks: pycryptopp is a Python crypto library, so it could be considered an alternative to PyCrypto. However, pycryptopp offers very few algorithms. In fact, it only offers RSA, AES, and SHA-256. So if that's all you need, then great. I just released a new version of pycryptopp. http://tahoe-lafs.org/trac/pycryptopp 2010-09-18 -- pycryptopp v0.5.20 The following things are new in this release: * fix bugs in assembly implementation of SHA-256 from Crypto++ * fix it to compile on *BSD (#39) * improve doc strings * add a quick start-up-self-test of SHA256 (#43) * execute the quick start-up-self-tests of AES and SHA256 on module import Regards, Zooko From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 03:58:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 07:58:09 GMT Subject: Back on topic [was [OT] Syntax highlighting] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> <4c96ff65$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c971411$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 07:02:23 +0000, Seebs wrote: > I'm > very new to Python, so I'm not 100% sure functions are a kind of an > object, but I seem to recall they were. Yes, functions are objects. *Everything* in Python is an object (apart from statements, but they're not actually *things* in Python). >>> def f(): ... return f.x ... >>> f.x = 2 >>> f() 2 >>> f.x = -1 >>> f() -1 For some interesting glimpse at how Python works, create a function f and then look at dir(f). -- Steven From gh at gregor-horvath.com Mon Sep 20 04:45:46 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Mon, 20 Sep 2010 10:45:46 +0200 Subject: Encode HTML CDATA name token Message-ID: <20100920104546.3699e919@valun> Hi, ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). [1] Is there a encoder / decoder in Python that can convert arbitrary text to and from this encoding in an readable manner? base64 is not readable: In [31]: base64.encodestring("/TEST") Out[31]: 'L1RFU1Q=\n' quopri does not encode for example "/". In [25]: quopri.encodestring("/test") Out[25]: '/test' Anything else? -- Greg [1] http://www.w3.org/TR/html4/types.html#type-cdata From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 04:50:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 08:50:46 GMT Subject: newbie: class and __dict__ variable. References: <4c970cdd$0$21775$426a74cc@news.free.fr> Message-ID: <4c972065$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 09:27:25 +0200, Bruno Desthuilliers wrote: >> If the class has a .__setattr__ method, the first bypasses that method, > > It also bypasses object.__setattribute__ and - as a consequence - any > binding descriptor by the same name as the attribute being set. __setattribute__ ? >>> object.__setattribute__ Traceback (most recent call last): File "", line 1, in AttributeError: type object 'object' has no attribute '__setattribute__' -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 04:52:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 08:52:19 GMT Subject: Plz comment on this code References: <4c957412$0$3036$afc38c87@news.optusnet.com.au> Message-ID: <4c9720c3$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 19:33:45 +1200, Lawrence D'Oliveiro wrote: > WHAT_IF_SOMETHING_IS_INITIALLY_CONSTANT,_BUT_LATER_BECOMES_A > _CONFIG_VARIABLE,_OR_VICE_VERSA,_DOES_IT_NEED_TO_CHANGE_ITS_NAME? If you want to be compliant with PEP 8, then yes. -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 05:02:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 09:02:40 GMT Subject: Encode HTML CDATA name token References: <20100920104546.3699e919@valun> Message-ID: <4c972330$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 10:45:46 +0200, Gregor Horvath wrote: > Hi, > > ID and NAME tokens must begin with a letter ([A-Za-z]) and may be > followed by any number of letters, digits ([0-9]), hyphens ("-"), > underscores ("_"), colons (":"), and periods ("."). [1] > > Is there a encoder / decoder in Python that can convert arbitrary text > to and from this encoding in an readable manner? What is "this encoding" called? The article you link to describes a specification, not an encoding. What makes you think that you should be able to convert arbitrary text to strings suitable for use as ID or NAME tokens? What would you expect this encoding to do with these strings? "1234" "?*(#@!+{})" " " -- Steven From rihad at mail.ru Mon Sep 20 05:10:06 2010 From: rihad at mail.ru (rihad) Date: Mon, 20 Sep 2010 02:10:06 -0700 (PDT) Subject: Is "python -W ignore" the default? Message-ID: $ mkdir foo $ python Python 2.7 (r27:82500, Sep 1 2010, 22:10:47) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 Type "help", "copyright", "credits" or "license" for more information. >>> dir() ['__builtins__', '__doc__', '__name__', '__package__'] >>> import foo Traceback (most recent call last): File "", line 1, in ImportError: No module named foo >>> dir() ['__builtins__', '__doc__', '__name__', '__package__', '__warningregistry__'] >>> __warningregistry__.items() [(("Not importing directory 'foo': missing __init__.py", , 1), True)] >>> $ (...went to read some "man python"...) $ python -W default Python 2.7 (r27:82500, Sep 1 2010, 22:10:47) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 Type "help", "copyright", "credits" or "license" for more information. >>> import foo __main__:1: ImportWarning: Not importing directory 'foo': missing __init__.py Traceback (most recent call last): File "", line 1, in ImportError: No module named foo >>> $ The problem isn't easily spotted unless run with -W default. How come "default" is not on by default? :) From ldo at geek-central.gen.new_zealand Mon Sep 20 05:33:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 21:33:47 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: Message-ID: In message , Philip Semanchuk wrote: > Some email systems still insert hard line breaks around the 72 or 80 > column mark and as a result long URLs get broken. That?s why content transfer encodings (quoted-printable, base64) are a standard part of MIME. From dotancohen at gmail.com Mon Sep 20 05:35:03 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Mon, 20 Sep 2010 11:35:03 +0200 Subject: Python and unicode In-Reply-To: <4c96d826$0$11113$c3e8da3@news.astraweb.com> References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> <4c96d826$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Mon, Sep 20, 2010 at 05:42, Steven D'Aprano wrote: >> Use the PEP 263 encoding >> declaration to let Python >> know the encoding of the program source file. > > While PEPs are valuable, once accepted or rejected they become historical > documents. They don't necessarily document the current behaviour of the > language. > > See here for documentation on encoding declarations: > > http://docs.python.org/reference/lexical_analysis.html#encoding-declarations > > This is the first time that I've read the PEP document regarding Unicode / UTF-8. I see that it mentions that the declaration must be on the second or first line of the file. Is this still true in Python 3? I have been putting it further down (still before all python code, but after some comments) in code that I write (for my own use, not commercial code). -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ldo at geek-central.gen.new_zealand Mon Sep 20 05:36:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 20 Sep 2010 21:36:46 +1200 Subject: Encode HTML CDATA name token References: <20100920104546.3699e919@valun> Message-ID: In message <20100920104546.3699e919 at valun>, Gregor Horvath wrote: > Is there a encoder / decoder in Python that can convert arbitrary text > to and from this encoding in an readable manner? Not sure if this is already in Python, but . From usernet at ilthio.net Mon Sep 20 05:48:41 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 09:48:41 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Seebs wrote: > On 2010-09-20, Tim Harig wrote: >> 1. Don't bother to manually paste when you can use something like urlview >> to lauch directly. > > I don't know that this would actually be better than what I currently do, > which is grab text and middle-click in another window. I don't know. Personally, I almost never use a mouse, so if I take my hands off of my keyboard, it really annoys me. >> If you want this behavior by default, you can easily wrap urlview >> to automatically add the prefix. > > True, but since my news reading is not on the machine my web browser is > on, it seems like it might get annoying. You could simply place the filter in slrn; then, any urls that you see in your reader would already be shown with the preview prefix suitable for cut and paste mechanisms. If you wanted, you can even have your script download the preview and automatically convert it back to the full origional URL. >> I question first whether most tinyurl links are really of such an >> intransient nature that they need to be long lasting. I personally use >> them most when writing paper notes. They only need to last long enough >> for me, or whoever I made the note for, to get back to them. > > By default, I assume that Usenet posts are for the longer term, and a > Usenet post which relies for its content on tinyurl is thus somewhat > more vulnerable than one which doesn't. In particular, consider things > like archive.org; they may well be able to find a long-dead web page, > but not a long-dead tinyurl link. I assume just the opposite. Once the post has been removed from the server, it is gone to me. I am not fond of the various archives that are otherwise available on the web. Those who should be using them never do and when I searching for the answer to a serious problem, I find myself inundated with thousands of posts that never would have been asked had the poster simply RTFM from mailing lists, web forums, and usernet that are difficult to filter out because they happen to contain the same basic subject matter that I am looking for. Google is particulary bad about this. Often the top posts have high ranks because they have been around so long that they are considered the definitive source; however the information in them is no longer accurate or even relevant. No, I tend to think is is much better that posts simply expire by their use by date. >> But why should the rest of us be penalized because you make the choice >> not to use (or not take full advantage of) all of the tools that are >> available to you? > > For about the same reason that I should be penalized because someone else > wanted things done differently. Which is to say, it's a tradeoff, the > right choice to make depends on what your goals are. If you want a > piece of information to have maximal longevity, something like tinyurl > is probably a bad way to transmit it. If you want something small that > survives line wrapping, it's probably a good way. I don't personally any problem with either mechanism -- especially in usernet where I have full control over how my client displays posts. Other media are less flexible. Nevertheless, I do have a problem with the constant nagging sentiment that tinyurl and kin are totally immoral to use. If this was something that was forced upon you, then I might have some sympathy; however, I see it as the poster's right to do what he thinks will make his post more effective. If that turns out to by tinyurl, then so be it. If you don't like tinyurls then you are free to filter them out in your newsreader or simply ignore the post. From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 05:51:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 11:51:53 +0200 Subject: newbie: class and __dict__ variable. In-Reply-To: <4c972065$0$11113$c3e8da3@news.astraweb.com> References: <4c970cdd$0$21775$426a74cc@news.free.fr> <4c972065$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c972eb9$0$12598$426a34cc@news.free.fr> Steven D'Aprano a ?crit : > On Mon, 20 Sep 2010 09:27:25 +0200, Bruno Desthuilliers wrote: > >>> If the class has a .__setattr__ method, the first bypasses that method, >> It also bypasses object.__setattribute__ and - as a consequence - any >> binding descriptor by the same name as the attribute being set. > > __setattribute__ ? > > >>>> object.__setattribute__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: type object 'object' has no attribute '__setattribute__' > Duh... Brain fart, sorry, shouldn't post before I get my dose of coffee :( Let's do it again: Terry Reedy a ?crit : > If the class has a .__setattr__ method, the first bypasses that > method, All new-style classes have a __setattr__ method - whether inherited from object or overridden. object.__setattr__ implements the support for binding descriptors, so bypassing it will also bypass all binding descriptors. The right way to avoid infinite recursion when overriding __setattr__ is to call on the superclass __setattr__, unless of course you *really* know what you're doing... class BarDescriptor(object): def __init__(self): self.val = None def __set__(self, instance, value): print "stores value elsewhere and trigger some required behaviour" self.val = value * 2 def __get__(self, instance, cls=None): if instance is None: return self print "retrieve value from elsewhere and trigger some required behaviour" return self.val # well behaved class Foo(object): bar = BarDescriptor() def __init__(self): self.bar = 42 def __setattr__(self, name, value): print "override __setattr_ for some reason" super(Foo, self).__setattr__(name, value) # ugly mess class Baaz(Foo): bar = BarDescriptor() def __init__(self): self.__dict__['bar'] = 42 def __setattr__(self, name, value): print "override __setattr_ for some reason" self.__dict__[name] == value >>> f = Foo() override __setattr_ for some reason stores value elsewhere and trigger some required behaviour >>> f.bar retrieve value from elsewhere and trigger some required behaviour 84 >>> f.__dict__ {} >>> f.bar = 33 override __setattr_ for some reason stores value elsewhere and trigger some required behaviour >>> f.bar retrieve value from elsewhere and trigger some required behaviour 66 >>> f.__dict__ {} >>> b = Baaz() >>> b.__dict__ {'bar': 42} >>> b.bar retrieve value from elsewhere and trigger some required behaviour >>> b.bar = 33 override __setattr_ for some reason >>> b.bar retrieve value from elsewhere and trigger some required behaviour >>> b.__dict__ {'bar': 42} >>> From usernet at ilthio.net Mon Sep 20 05:59:20 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 09:59:20 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Steven D'Aprano wrote: > On Mon, 20 Sep 2010 05:46:38 +0000, Tim Harig wrote: > >>> I'm not particularly convinced that these are *significant* complaints >>> about URL-shorteners. But I will say, of the last couple hundred links >>> I've followed from Usenet posts, precisely zero of them were through >>> URL redirectors. If I can't at least look at the URL to get some >>> initial impression of what it's a link to, I'm not going to the trouble >>> of swapping to a web browser to find out. >> >> But why should the rest of us be penalized because you make the choice >> not to use (or not take full advantage of) all of the tools that are >> available to you? > > I'm with Aahz... best practice is to post both the full and shortened > URL, unless the URL is less that 78 characters, in which case just post > the full version. Posting two URLs rather defeats the purpose of using a URL shortening service in the first place; but, if that is what you feel is effective, then by all means, do so. You are the master of your posts and you have the right to post them using whatever methods and formating that you feel is most effect; but, other people should have the same priviledge. Many people find tinyurl and kin to be useful tools. If you do not, then are free to rewrite them in your reader, ignore posts using these services, or even add a rule blocking them to your score/kill file so that you do not have to view their ugliness. From usernet at ilthio.net Mon Sep 20 06:01:07 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 10:01:07 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Tim Harig wrote: > On 2010-09-20, Seebs wrote: >> On 2010-09-20, Tim Harig wrote: >>> If you want this behavior by default, you can easily wrap urlview >>> to automatically add the prefix. >> >> True, but since my news reading is not on the machine my web browser is >> on, it seems like it might get annoying. > > You could simply place the filter in slrn; then, any urls that you see in > your reader would already be shown with the preview prefix suitable for cut > and paste mechanisms. If you wanted, you can even have your script > download the preview and automatically convert it back to the full > origional URL. I should add that there are browser extensions that do just this. From __peter__ at web.de Mon Sep 20 06:20:34 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 20 Sep 2010 12:20:34 +0200 Subject: Python and unicode References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> <4c96d826$0$11113$c3e8da3@news.astraweb.com> Message-ID: Dotan Cohen wrote: > On Mon, Sep 20, 2010 at 05:42, Steven D'Aprano > wrote: >>> Use the PEP 263 encoding >>> declaration to let Python >>> know the encoding of the program source file. >> >> While PEPs are valuable, once accepted or rejected they become historical >> documents. They don't necessarily document the current behaviour of the >> language. >> >> See here for documentation on encoding declarations: >> >> http://docs.python.org/reference/lexical_analysis.html#encoding- declarations >> >> > > This is the first time that I've read the PEP document regarding > Unicode / UTF-8. I see that it mentions that the declaration must be > on the second or first line of the file. Is this still true in Python > 3? Yes > I have been putting it further down (still before all python code, > but after some comments) in code that I write (for my own use, not > commercial code). It may work by accident, if you declare it as UTF-8, because that is also the default in Python 3. Peter From gh at gregor-horvath.com Mon Sep 20 06:37:48 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Mon, 20 Sep 2010 12:37:48 +0200 Subject: Encode HTML CDATA name token References: <20100920104546.3699e919@valun> Message-ID: <20100920123748.6f3a5264@valun> Am Mon, 20 Sep 2010 21:36:46 +1200 schrieb Lawrence D'Oliveiro : > In message <20100920104546.3699e919 at valun>, Gregor Horvath wrote: > > > Is there a encoder / decoder in Python that can convert arbitrary > > text to and from this encoding in an readable manner? > > Not sure if this is already in Python, but > . Thanks for the suggestion. Yes it is in Python: base64.b32encode 2 Problems: a) "=" is used as padding char b) The special case of a base32 encoding with a leading digit is not handled. c) It's not readbale But I can easly work around this. Thanks. -- Greg From dotancohen at gmail.com Mon Sep 20 06:57:35 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Mon, 20 Sep 2010 12:57:35 +0200 Subject: Python and unicode In-Reply-To: References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> <4c96d826$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Mon, Sep 20, 2010 at 12:20, Peter Otten <__peter__ at web.de> wrote: > It may work by accident, if you declare it as UTF-8, because that is also > the default in Python 3. > That does seem to be the case. Thank you for the enlightenment and information. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 07:11:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 11:11:51 GMT Subject: Overriding dict constructor Message-ID: <4c974177$0$11113$c3e8da3@news.astraweb.com> I have a dict subclass that associates extra data with each value of the key/value items: class MyDict(dict): def __setitem__(self, key, value): super(MyDict, self).__setitem__(key, (value, "extra_data")) def __getitem__(self, key): return super(MyDict, self).__getitem__(key)[0] # plus extra methods This works fine for item access, updates, etc: >>> d = MyDict() >>> d[0] = 'a'; d[1] = 'b' >>> d[1] 'b' But if I try to create a regular dict from this, dict() doesn't call my __getitem__ method: >>> dict(d) {0: ('a', 'extra_data'), 1: ('b', 'extra_data')} instead of {0: 'a', 1: 'b'} as I expected. How can I fix this? -- Steven From yoavglazner at gmail.com Mon Sep 20 07:17:53 2010 From: yoavglazner at gmail.com (Glazner) Date: Mon, 20 Sep 2010 04:17:53 -0700 (PDT) Subject: Python Monitoring Message-ID: <4d1cbff7-af15-4ec8-bb24-0cbd616ca594@q9g2000vbd.googlegroups.com> Hi, I'm will be writing a distributed program with parallel python and i would like to if there are any good monitoring utilities for python. I would like each remote server to post messages and to see the messages in a web-broweser or such. I googled python monitoring and found pymon but it seems a bit outdated. any tips will be great! Many Thanks, Yoav Glazner From dirknbr at gmail.com Mon Sep 20 07:36:42 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Mon, 20 Sep 2010 04:36:42 -0700 (PDT) Subject: Numpy on 2.7 Message-ID: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> I am trying to install Numpy on Python 2.7 but it only looks for 2.6 folder, how can I change that? Dirk From duncan.booth at invalid.invalid Mon Sep 20 07:53:48 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Sep 2010 11:53:48 GMT Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I have a dict subclass that associates extra data with each value of the > key/value items: > > class MyDict(dict): > def __setitem__(self, key, value): > super(MyDict, self).__setitem__(key, (value, "extra_data")) > def __getitem__(self, key): > return super(MyDict, self).__getitem__(key)[0] > # plus extra methods > > > This works fine for item access, updates, etc: > >>>> d = MyDict() >>>> d[0] = 'a'; d[1] = 'b' >>>> d[1] > 'b' > > > But if I try to create a regular dict from this, dict() doesn't call my > __getitem__ method: > >>>> dict(d) > {0: ('a', 'extra_data'), 1: ('b', 'extra_data')} > > > instead of {0: 'a', 1: 'b'} as I expected. > > How can I fix this? > > I was going to suggest overriding items() (or iteritems() for Python 2.x), but while that is another hole that your values leak out it isn't the hole used by the dict constructor. It might be simpler to duck the issue entirely and store the extra data in another dict alongside the main one: class MyDict(dict): def __init__(self, *args, **kw): self._extra = {} super(MyDict, self).__init__(*args, **kw) for k in self: self._extra[k] = "extra_data" def __setitem__(self, key, value): super(MyDict, self).__setitem__(key, value) self._extra[key] = "extra_data" # plus extra methods then you only have to worry about catching all the mutators but not the accessors. -- Duncan Booth http://kupuguy.blogspot.com From john at castleamber.com Mon Sep 20 08:00:09 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 07:00:09 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: <878w2wsjzq.fsf@castleamber.com> Tim Harig writes: > I question first whether most tinyurl links are really of such an > intransient nature that they need to be long lasting. I personally use > them most when writing paper notes. They only need to last long enough > for me, or whoever I made the note for, to get back to them. As an additional note: tinyurl allows one to enter a postfix to use, so instead of /xc4ax7 you can have /something-more-readable. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From lists at cheimes.de Mon Sep 20 08:00:58 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 20 Sep 2010 14:00:58 +0200 Subject: Overriding dict constructor In-Reply-To: <4c974177$0$11113$c3e8da3@news.astraweb.com> References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: Am 20.09.2010 13:11, schrieb Steven D'Aprano: > I have a dict subclass that associates extra data with each value of the > key/value items: [...] > How can I fix this? Since the dict class is crucial to the overall performance of Python, the dict class behaves bit different than other classes. I don't know if this is documented somewhere. Dict methods call the PyDict_GetItem function directly instead of going through the type's struct. You have two options to get the desired behavior. Either implement all functions that call the methods you want to overwrite, or subclass from something like DictMixin or the appropriate ABC. Christian From john at castleamber.com Mon Sep 20 08:04:47 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 07:04:47 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> <87vd613t0p.fsf@castleamber.com> Message-ID: <874odksjs0.fsf@castleamber.com> Seebs writes: > On 2010-09-20, John Bokma wrote: >> I didn't mean that there are spoilers in the first 70 pages, just that >> to me the excercise would spoil the book, so, I wouldn't do it. I >> consider a book like a meal, I wouldn't gobble down food, regurgitate >> it, and eat it again at a slower pace. Books, movies, family, walks are >> the things I prefer to do at a normal mudane pace, or even slower, if I >> can bring myself to it. My favourite books I try to read slow, and >> enjoy. ;-). Too much of my life is already in overdrive. > > Now that you explain it like this, that makes a fair bit of sense. I > often wonder whether reading slowly would be more pleasant. I have no > idea how to do it, so the question remains theoretical. By practicing ;-). I have it worse with movies, but in my case, for several reasons, it's really important (to me) that I watch the movie at it's normal pace and try to enjoy it at that speed. Talking about reading: if you have any suggestions, feel free to email me (since this is already way off topic). I read mostly in my second language, English, and live in a country where English books are hard to find, so browsing in bookshops is not much of an option :-(. And most of my (online) friends don't read much, if at all. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 08:15:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Sep 2010 12:15:02 GMT Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c975046$0$11113$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 11:53:48 +0000, Duncan Booth wrote: > I was going to suggest overriding items() (or iteritems() for Python > 2.x), but while that is another hole that your values leak out it isn't > the hole used by the dict constructor. Yes, I already override items(), keys(), values(), their iter... versions, and just about every damn method that dicts have :/ I suspect that the dict() constructor is just grabbing the key/value pairs directly from the underlying hash table. If that's the case, my choices are to not inherit from dict at all, or take your suggestion and keep an auxiliary dict alongside the main one. -- Steven From john at castleamber.com Mon Sep 20 08:31:05 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 07:31:05 -0500 Subject: [OT] Speed-reading References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c958370$0$11113$c3e8da3@news.astraweb.com> <4c96fe8b$0$11113$c3e8da3@news.astraweb.com> Message-ID: <87wrqgr3zq.fsf@castleamber.com> Steven D'Aprano writes: > spelling or grammatical errors and clumsy writing. *Especially* the > spelling errors, they have about the same effect on her reading speed as > a tree trunk lying across a Formula 1 race track. Spelling errors are a disaster, somehow they stand out like they use Comic Sans Bold and red ink. Most likely because they break the pattern. I seem to find them more and more often in the books I read, maybe because I use English (my second language) more and more. As for speed reading, there are many levels to do this: one can call scanning a page really fast left-right, moving as fast to the bottom as possible speed-reading, or reading each and every sentence just as fast as possible speed reading. The faster one goes, the more is lost. The total # of pages in Harry Potter seems to be just over 4000 [1]. If an afternoon is 4 hrs, this means 1000 pages an hour, or 17 pages/minute. One has to do skimming to read that fast. With 250 words/page the reading speed would be over 4K words/minute, which would make your wife a serious competitor for Anna Jones (4.7K words/minute, 67% comprehension, see [2]) In my native language I read just above 1 page a minute, if the pages are not too dense I can do sometimes 2. In English I can often get close to 1 page a minute, except with books that are quite dense (think fantasy). So I guess around 300-350 wpm in Dutch, 250 wpm in English (normal pace). [1] http://wiki.answers.com/Q/What_is_the_total_number_of_pages_in_the_%27Harry_Potter%27_series [2] http://en.wikipedia.org/wiki/Speed_reading#Claims_of_speed_readers -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From pekka.niiranen at pp5.inet.fi Mon Sep 20 08:46:34 2010 From: pekka.niiranen at pp5.inet.fi (Pekka Niiranen) Date: Mon, 20 Sep 2010 15:46:34 +0300 Subject: Numpy on 2.7 In-Reply-To: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> References: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> Message-ID: On 9/20/10 2:36 PM, Dirk Nachbar wrote: > I am trying to install Numpy on Python 2.7 but it only looks for 2.6 > folder, how can I change that? > > Dirk http://sourceforge.net/projects/numpy/files/NumPy/1.5.0/numpy-1.5.0-win32-superpack-python2.7.exe/download From ian at ianhobson.co.uk Mon Sep 20 09:00:19 2010 From: ian at ianhobson.co.uk (Ian Hobson) Date: Mon, 20 Sep 2010 14:00:19 +0100 Subject: Encoding problem - or bug in couchdb-0.8-py2.7.egg?? Message-ID: <4C975AE3.6070703@ianhobson.co.uk> Hi all, I have hit a problem and I don't know enough about python to diagnose things further. Trying to use couchDB from Python. This script:- # coding=utf8 import couchdb from couchdb.client import Server server = Server() dbName = 'python-tests' try: db = server.create(dbName) except couchdb.PreconditionFailed: del server[dbName] db = server.create(dbName) doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) Gives this traceback:- D:\work\C-U-B>python tes1.py Traceback (most recent call last): File "tes1.py", line 11, in doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\client.py", line 407, in save _, _, data = func(body=doc, **options) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", line 399, in post_json status, headers, data = self.post(*a, **k) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", line 381, in post **params) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", line 419, in _request credentials=self.credentials) File "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", line 310, in request raise ServerError((status, error)) couchdb.http.ServerError: (400, ('bad_request', 'invalid UTF-8 JSON')) D:\work\C-U-B> Why? I've tried adding u to the strings, and removing the # coding line, and I still get the same error. Thanks for any help. Ian From oswald.harry at gmail.com Mon Sep 20 10:02:27 2010 From: oswald.harry at gmail.com (harryos) Date: Mon, 20 Sep 2010 07:02:27 -0700 (PDT) Subject: elementwise multiplication of 2 lists of numbers Message-ID: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> hi I have 2 lists of numbers,say x=[2,4,3,1] y=[5,9,10,6] I need to create another list containing z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] I did not want to use numpy or any Array types.I tried to implement this in python .I tried the following z=[] for a,b in zip(x,y): z.append(a*b) This gives me the correct result.Still,Is this the correct way? Or can this be done in a better way? Any pointers most welcome, harry From hniksic at xemacs.org Mon Sep 20 10:15:22 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 20 Sep 2010 16:15:22 +0200 Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: <87ocbsbix1.fsf@xemacs.org> Christian Heimes writes: > Am 20.09.2010 13:11, schrieb Steven D'Aprano: >> I have a dict subclass that associates extra data with each value of the >> key/value items: > [...] >> How can I fix this? > > Since the dict class is crucial to the overall performance of Python, > the dict class behaves bit different than other classes. I don't know if > this is documented somewhere. Dict methods call the PyDict_GetItem > function directly instead of going through the type's struct. Normally where this kind of optimization is necessary Python is careful to use PyFoo_CheckExact to find out if it is dealing with an instance of the class or a subclass, and only goes through the fast path for the former case. That PyDict_Merge (called by dict_init) doesn't do this could be considered a bug because it constrains dict subclass in a way that is hard to work around, and without a clear gain in performance compared to using an exact check. dict_fromkeys is an example in the same file that uses PyDict_CheckExact. From hunguponcontent at gmail.com Mon Sep 20 10:16:56 2010 From: hunguponcontent at gmail.com (Default User) Date: Mon, 20 Sep 2010 09:16:56 -0500 Subject: develop for Windows on GNU/Linux, using Python In-Reply-To: <8fn6ojF783U1@mid.individual.net> References: <8fn6ojF783U1@mid.individual.net> Message-ID: On Sun, Sep 19, 2010 at 14:31, J.O. Aho wrote: > Kev Dwyer wrote: > > On Sun, 19 Sep 2010 12:55:43 -0500, Default User wrote: > > > >> Consider: > >> > >> Can someone do development of programs for use on Windows systems, but > >> developed totally on a GNU/Linux system, using standard, contemporary 32 > >> and / or 64-bit PC hardware? > >> > >> This would be for someone who can not or will not use Windows, but wants > >> to create software for those who do. > >> > >> This might not include the use of VM for developing on GNU/Linux, as > >> that would seem to require a Windows installation disk, which the > >> developer may not be able or willing to obtain and use. > >> > >> Is the correct answer: > >> 1) no. > >> 2) yes. > >> 3) yes, a "Hello World" program will run just fine on the Windows Python > >> interpreter. > >> 4) other. > > > > Hello, > > > > The answer is "it depends", or 4 on your list of responses. > > > > You can write pure python on a Linux machine and it will run fine on > > Windows as long as you've taken care to program in a portable fashion. > > And not use modules not yet converted to microsoft, seems to happen from > time > to time. > > > > if you have C-extensions in > > your code you'll need to compile them over Windows. If you want to > > program against the Windows API you'll need access to a Windows box. > > You can always cross compile, not only over OS but even CPU architecture, > but > of course testing will be more difficult, on x86 based Linux you can use > wine > or similar to test, but can give you some differences to run on a native or > virtualized instance. > > > < sigh > . . . Well, that's about what I expected, unfortunately. But thanks for the honest replies. [OT] So what's the alternative -- use the end user's browser as an interpreter for JavaScript or HTML5? [/OT] -- > > //Aho > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Mon Sep 20 10:26:36 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 20 Sep 2010 07:26:36 -0700 Subject: elementwise multiplication of 2 lists of numbers In-Reply-To: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: <4C976F1C.6020008@islandtraining.com> On 09/20/2010 07:02 AM, harryos wrote: > hi > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > z.append(a*b) > This gives me the correct result.Still,Is this the correct way? > Or can this be done in a better way? > > Any pointers most welcome, > harry > List comprehension might be considered better by some, but that's a subjective judgment. (One with which I agree.) List comprehension may also be faster, but you'd have to test to know for sure. >>> x=[2,4,3,1] >>> y=[5,9,10,6] >>> z = [a*b for a,b in zip(x,y)] >>> print z [10, 36, 30, 6] Gary Herron From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 20 10:28:12 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 20 Sep 2010 16:28:12 +0200 Subject: elementwise multiplication of 2 lists of numbers In-Reply-To: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: <4c976f7b$0$23949$426a74cc@news.free.fr> harryos a ?crit : > hi > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > z.append(a*b) > This gives me the correct result.Still,Is this the correct way? If it gives the expected results then it's at least *a* correct way !-) > Or can this be done in a better way? A list comp comes to mind, as well as using itertools.izip if your lists are a bit on the huge side. from itertools import izip z = [a * b for a, b in izip(x, y)] From giacomo.boffi at polimi.it Mon Sep 20 10:39:34 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Mon, 20 Sep 2010 16:39:34 +0200 Subject: elementwise multiplication of 2 lists of numbers References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: <86iq20fpi1.fsf@aiuole.stru.polimi.it> harryos writes: > hi > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > z.append(a*b) > This gives me the correct result.Still,Is this the correct way? > Or can this be done in a better way? what you've done is correct, rather than in better ways this can be done in different ways first, there is list comprehension >>> [x*y for x,y in zip([2,4,3,1],[5,9,10,6])] [10, 36, 30, 6] >>> if you feel that "zip" looks like an artifact, python has some functional bit >>> map(lambda x,y: x*y, [2,4,3,1],[5,9,10,6]) [10, 36, 30, 6] >>> if you feel that "lambda" looks like an artifact, >>> from operator import mul >>> map(mul, [2,4,3,1],[5,9,10,6]) [10, 36, 30, 6] >>> hth, -- > In tutti noi c'? un lato interista Lato perlopi? nascosto dalle mutande. --- Basil Fawlty, a reti unificate (IFQ+ISC) From oswald.harry at gmail.com Mon Sep 20 10:40:04 2010 From: oswald.harry at gmail.com (harryos) Date: Mon, 20 Sep 2010 07:40:04 -0700 (PDT) Subject: elementwise multiplication of 2 lists of numbers References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> <4c976f7b$0$23949$426a74cc@news.free.fr> Message-ID: <1a1339ca-5925-4b8e-a438-9f582d1d38a4@k1g2000prl.googlegroups.com> On Sep 20, 7:28?pm, Bruno wrote: >> A list comp comes to mind, as well as using itertools.izip thanks Bruno,thanks Gary.. Should have thought of list comprehension.. Thanks for the pointer about izip harry From robert.kern at gmail.com Mon Sep 20 10:58:18 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 20 Sep 2010 09:58:18 -0500 Subject: Numpy on 2.7 In-Reply-To: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> References: <56805153-9023-4d15-b749-3a9ed7b25c07@f26g2000vbm.googlegroups.com> Message-ID: On 9/20/10 6:36 AM, Dirk Nachbar wrote: > I am trying to install Numpy on Python 2.7 but it only looks for 2.6 > folder, how can I change that? You should ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists -- 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 isaacrc82 at gmail.com Mon Sep 20 11:09:13 2010 From: isaacrc82 at gmail.com (Ariel) Date: Mon, 20 Sep 2010 11:09:13 -0400 Subject: How to make a web services in python ??? In-Reply-To: References: Message-ID: Soap web services I think. On Fri, Sep 17, 2010 at 5:35 PM, Hidura wrote: > What kind of web-service you have in mind???? > > 2010/9/17, Ariel : > > Hi everybody, I need some help to find documentation about how to > implements > > web services in python, could you help me please ??? > > Regards > > Thanks in advance > > Ariel > > > > -- > Enviado desde mi dispositivo m?vil > > Diego I. Hidalgo D. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From et1ssgmiller at gmail.com Mon Sep 20 11:15:00 2010 From: et1ssgmiller at gmail.com (Greg Miller) Date: Mon, 20 Sep 2010 08:15:00 -0700 (PDT) Subject: catching WM_TIMER message Message-ID: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> I'm trying to get the following code converted to Python.......and am stuck if(GetMessage(&msg.NULL,NULL,NULL)) { if(msg.message == WM_TIMER) { TranslateMEssage(&msg); DispatchMessage(&msg); } } I think GetMessage is a canned C or C++ function, and I'm not sure how to catch a message from WM_TIMER. Anyone who could help me get this loop converted to Python I would really appreciate it!!!! From mail at timgolden.me.uk Mon Sep 20 11:30:32 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 20 Sep 2010 16:30:32 +0100 Subject: catching WM_TIMER message In-Reply-To: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> References: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> Message-ID: <4C977E18.7090802@timgolden.me.uk> On 20/09/2010 16:15, Greg Miller wrote: > I'm trying to get the following code converted to Python.......and am > stuck > > if(GetMessage(&msg.NULL,NULL,NULL)) > { > if(msg.message == WM_TIMER) > { > TranslateMEssage(&msg); > DispatchMessage(&msg); > } > } > > I think GetMessage is a canned C or C++ function, and I'm not sure how > to catch a message from WM_TIMER. Anyone who could help me get this > loop converted to Python I would really appreciate it!!!! Goodness. You're going in at the deep end, slightly. What you're seeing there is a typical part of the standard Windows message loop which retrieves messages from the message queue of a Window (or thread) and then dispatches as your code does above. You *can* do this in Python, either using core Python only and making use of the ctypes module, or by employing the pywin32 packages which wrap the functions above. There's a thread-based example here which uses ctypes: http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html It should be readily adaptable to a WM_TIMER situation. Or you can see a (more complex) window-based example here which uses the pywin32 package: http://timgolden.me.uk/python/win32_how_do_i/detect-device-insertion.html If all you needed was the simplest code to catch a WM_TIMER message then the earlier example is probably a better fit. If this is part of a wider setup involving windows and other messages then you'll need (something like) the latter. TJG From homeusenet4 at brianhv.org Mon Sep 20 11:49:15 2010 From: homeusenet4 at brianhv.org (Brian Victor) Date: Mon, 20 Sep 2010 15:49:15 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: Tim Harig wrote: > Posting two URLs rather defeats the purpose of using a URL shortening > service in the first place; but, if that is what you feel is effective, > then by all means, do so. You are the master of your posts and you have > the right to post them using whatever methods and formating that you > feel is most effect; but, other people should have the same priviledge. The thing I haven't seen anyone make explicit in this conversation is that URL shorteners remove all the information from a URL. When someone posts a URL, I very frequently find one of the following is true: * I've already read the article or doc page being linked to * I haven't read it, but I recognize the domain name and can guess what it says based on what I know about the author. * I haven't read it, but the title (which is often a slug in the URL) tells me that it's not relevant to my problem. In any of those cases, I don't even have to click the link, much less copy and paste and add "preview" to the URL to see if it's something I care to read. Given this, I concur that URL shortening makes sense as an addition to a full URL if you're concerned about line-breaking, but feels like a needless obstacle when presented alone. And as a datapoint on the topic of archiving, I search usenet archives regularly when faced with a problem. -- Brian From deets at web.de Mon Sep 20 12:00:17 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 18:00:17 +0200 Subject: Encoding problem - or bug in couchdb-0.8-py2.7.egg?? References: Message-ID: <87iq201k32.fsf@web.de> Ian Hobson writes: > Hi all, > > I have hit a problem and I don't know enough about python to diagnose > things further. Trying to use couchDB from Python. This script:- > > # coding=utf8 > import couchdb > from couchdb.client import Server > server = Server() > dbName = 'python-tests' > try: > db = server.create(dbName) > except couchdb.PreconditionFailed: > del server[dbName] > db = server.create(dbName) > doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) > > Gives this traceback:- > > D:\work\C-U-B>python tes1.py > Traceback (most recent call last): > File "tes1.py", line 11, in > doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\client.py", > line 407, in save > _, _, data = func(body=doc, **options) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", > line 399, in post_json > status, headers, data = self.post(*a, **k) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", > line 381, in post > **params) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", > line 419, in _request > credentials=self.credentials) > File > "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", > line 310, in request > raise ServerError((status, error)) > couchdb.http.ServerError: (400, ('bad_request', 'invalid UTF-8 JSON')) > > D:\work\C-U-B> > > Why? I've tried adding u to the strings, and removing the # coding > line, and I still get the same error. Sounds cargo-cultish. I suggest you read the python introduction on unicode. http://docs.python.org/howto/unicode.html For your actual problem, I have difficulties seeing how it can happen with the above data - frankly because there is nothing outside the ascii-range of data, so there is no reason why anything could be wrong encoded. But googling the error-message reveals that there seem to be totally unrelated reasons for this: http://sindro.me/2010/4/3/couchdb-invalid-utf8-json Maybe using something like tcpmon or ethereal to capture the actual HTTP-request helps to see where the issue comes from. Diez From deets at web.de Mon Sep 20 12:03:10 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 18:03:10 +0200 Subject: Python Monitoring References: <4d1cbff7-af15-4ec8-bb24-0cbd616ca594@q9g2000vbd.googlegroups.com> Message-ID: <87eico1jy9.fsf@web.de> Glazner writes: > Hi, > > I'm will be writing a distributed program with parallel python and i > would like to if there are any good monitoring utilities for python. > I would like each remote server to post messages and to see the > messages in a web-broweser or such. > > I googled python monitoring and found pymon but it seems a bit > outdated. It's not exactly what you asked for, but the supervisord written in Python is not only capable of watching a process (admittedly always on the machine it is supposed to run), but can also be configured to have XMLRPC based (and I think even other) interfaces that a central server could poll & see the status of specific processes. I admit though that it needs more configuration. Just wanted to mention it, because process management might be on your list as well. Diez From arnodel at gmail.com Mon Sep 20 12:17:40 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 20 Sep 2010 09:17:40 -0700 (PDT) Subject: elementwise multiplication of 2 lists of numbers References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: On Sep 20, 3:02?pm, harryos wrote: > hi > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ?ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > ? ? ? ? z.append(a*b) > This gives me the correct result.Still,Is this the correct way? > Or can this be done in a better way? > > Any pointers most welcome, > harry In addition to what others have said, you can use the map builtin as follows: In Python 2.x: >>> map(int.__mul__, [2, 4, 3, 1], [5, 9, 10, 6]) [10, 36, 30, 6] If you don't know the list only contain ints use operator.mul. In Python 3.x you need to wrap it in list() as map returns an iterator. HTH -- Arnaud From __peter__ at web.de Mon Sep 20 12:33:30 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 20 Sep 2010 18:33:30 +0200 Subject: elementwise multiplication of 2 lists of numbers References: <806eb124-5f4b-4e7d-945b-96b57e1bf4cc@p37g2000pra.googlegroups.com> Message-ID: harryos wrote: > I have 2 lists of numbers,say > x=[2,4,3,1] > y=[5,9,10,6] > I need to create another list containing > z=[2*5, 4*9, 3*10, 1*6] ie =[10,36,30,6] > > I did not want to use numpy or any Array types.I tried to implement > this in python .I tried the following > > z=[] > for a,b in zip(x,y): > z.append(a*b) > This gives me the correct result.Still,Is this the correct way? > Or can this be done in a better way? > > Any pointers most welcome, Finally, if you have a lot of data that you want to process efficiently consider using numpy arrays instead of lists: >>> import numpy >>> x = numpy.array([2,4,3,1]) >>> y = numpy.array([5,9,10,6]) >>> x*y array([10, 36, 30, 6]) Peter From et1ssgmiller at gmail.com Mon Sep 20 12:41:33 2010 From: et1ssgmiller at gmail.com (Greg Miller) Date: Mon, 20 Sep 2010 09:41:33 -0700 (PDT) Subject: catching WM_TIMER message References: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> Message-ID: <0f445259-11e5-410b-bdab-2cdb26919d83@c16g2000vbp.googlegroups.com> On Sep 20, 11:30?am, Tim Golden wrote: > On 20/09/2010 16:15, Greg Miller wrote: > > > I'm trying to get the following code converted to Python.......and am > > stuck > > > if(GetMessage(&msg.NULL,NULL,NULL)) > > { > > ? ? ? if(msg.message == WM_TIMER) > > ? ? ? { > > ? ? ? ? ? ?TranslateMEssage(&msg); > > ? ? ? ? ? ?DispatchMessage(&msg); > > ? ? ? } > > } > > > I think GetMessage is a canned C or C++ function, and I'm not sure how > > to catch a message from WM_TIMER. ?Anyone who could help me get this > > loop converted to Python I would really appreciate it!!!! > > Goodness. You're going in at the deep end, slightly. > > What you're seeing there is a typical part of the standard > Windows message loop which retrieves messages from the > message queue of a Window (or thread) and then dispatches > as your code does above. You *can* do this in Python, either > using core Python only and making use of the ctypes module, > or by employing the pywin32 packages which wrap the functions > above. > > There's a thread-based example here which uses ctypes: > > http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkey... > > It should be readily adaptable to a WM_TIMER situation. > > Or you can see a (more complex) window-based example here which > uses the pywin32 package: > > ? ?http://timgolden.me.uk/python/win32_how_do_i/detect-device-insertion.... > > If all you needed was the simplest code to catch a WM_TIMER > message then the earlier example is probably a better fit. > If this is part of a wider setup involving windows and other > messages then you'll need (something like) the latter. > > TJG Thank you for the assist! Quick question though, using the first example is there any need to register for WM_TIMER, ( instead of registering for WM_HOTKEY ), or is extracting the "home grown Windows message loop" enough and just run with that? et1ssgmiller From thomas at jollybox.de Mon Sep 20 12:46:07 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Mon, 20 Sep 2010 18:46:07 +0200 Subject: develop for Windows on GNU/Linux, using Python In-Reply-To: References: <8fn6ojF783U1@mid.individual.net> Message-ID: <201009201846.08296.thomas@jollybox.de> On Monday 20 September 2010, it occurred to Default User to exclaim: > On Sun, Sep 19, 2010 at 14:31, J.O. Aho wrote: > > Kev Dwyer wrote: > > > if you have C-extensions in > > > your code you'll need to compile them over Windows. If you want to > > > program against the Windows API you'll need access to a Windows box. > > > > You can always cross compile, not only over OS but even CPU architecture, > > but > > of course testing will be more difficult, on x86 based Linux you can use > > wine > > or similar to test, but can give you some differences to run on a native > > or virtualized instance. > > < sigh > . . . > > Well, that's about what I expected, unfortunately. But thanks for the > honest replies. > > [OT] > So what's the alternative -- use the end user's browser as an interpreter > for JavaScript or HTML5? > [/OT] Umn, what? Python makes it rather easy to write portable code. But you still need to test it properly on all platforms you want to support, because maybe there's some platform-specific glitch you weren't aware of. If you use web technologies, then you really have to test against browsers such as Opera, Safari, and Microsoft IE. Same difference, really. If you're doing something that requires C extensions to Python, things get more complicated, and probably impossible with web technologies. From simon at brunningonline.net Mon Sep 20 12:46:22 2010 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 20 Sep 2010 17:46:22 +0100 Subject: How to make a web services in python ??? In-Reply-To: References: Message-ID: On 20 September 2010 16:09, Ariel wrote: > Soap web services I think. I think the cool kids would be using , but for the fact that the cool kids all build REST () rather than SOAP these days. -- Cheers, Simon B. From usernet at ilthio.net Mon Sep 20 13:25:09 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Sep 2010 17:25:09 +0000 (UTC) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Brian Victor wrote: > Tim Harig wrote: >> Posting two URLs rather defeats the purpose of using a URL shortening >> service in the first place; but, if that is what you feel is effective, >> then by all means, do so. You are the master of your posts and you have >> the right to post them using whatever methods and formating that you >> feel is most effect; but, other people should have the same priviledge. > > The thing I haven't seen anyone make explicit in this conversation is > that URL shorteners remove all the information from a URL. When someone > posts a URL, I very frequently find one of the following is true: Actually, its been a central point in this conversation. > In any of those cases, I don't even have to click the link, much less > copy and paste and add "preview" to the URL to see if it's something I > care to read. I have already stated in my thread with Seebs that all of this can be done automatically including converting the tinyurl back to a full url if you choose to do so. If you really wanted to, you could bring back the and other meta headers that would give you even more information about the page tinyurl redirects to. > Given this, I concur that URL shortening makes sense as an addition to a > full URL if you're concerned about line-breaking, but feels like a > needless obstacle when presented alone. Yes, it makes sense for you to do so and I support your right to do so. Personally, I would find two urls annoying. I also support the grandparent's right to post just the tinyurl. I don't make use of it much when posting myself; but, I do understand why some people find it useful. Its his post and he can do it how he wants. You have the right to do the same for your posts. > And as a datapoint on the topic of archiving, I search usenet archives > regularly when faced with a problem. Usernet users also have the right to use the X-No-Archive header field. Does the fact that *you* happen to search usenet archives make using this field immoral? Shouldn't the poster have to right to determine for themselves whether they care about the long term persistance of their posts and be able to balance that against other factors? From nkrumm at gmail.com Mon Sep 20 13:26:18 2010 From: nkrumm at gmail.com (Nik Krumm) Date: Mon, 20 Sep 2010 10:26:18 -0700 (PDT) Subject: hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> Message-ID: <7b7f018e-b429-448b-94c1-2a812c5f3436@h37g2000pro.googlegroups.com> On Sep 18, 11:28?am, Ned Deily wrote: > In article , > ?Lawrence D'Oliveiro wrote: > > > In message , Ned Deily > > wrote: > > > ? ? try: > > > ? ? ? ? importreadline > > > ? ? except ImportError: > > > ? ? ? ? print("Modulereadlinenot available.") > > > ? ? else: > > > ? ? ? ? import rlcompleter > > > ? ? ? ?readline.parse_and_bind("tab: complete") > > > > Note the print() form which works with either Python 2 or 3. > > You should be writing diagnostics to stderr, not stdout. > > In general, sure. ? Statements in a PYTHONSTARTUP file, like here, are > only executed in interactive mode and it isn't likely that someone is > going to be redirecting stdout or stderr; that would kind of defeat the > purpose ofreadlinecompletion functions which is what this is all > about. ?But, if you feel strongly about it, I'm sure a contributed patch > to improve the rlcompleter documentation would be welcome. > > -- > ?Ned Deily, > ?n... at acm.org Hi, Thanks for the replies. The issue isn't with readline. The readline module or rlcompleter module are both available, and loading them has no effect on the behavior of tab: >>> import readline [Now i hit tab...] >>> ./ File "", line 1 ./ ^ SyntaxError: invalid syntax [Hit tab twice...] >>> ./ ./.bash_history ./.bash_profile ./.bash_profile.pysave ./.CFUserTextEncoding ./.cups ./.dropbox ./.DS_Store ./.fontconfig ./.ipython ./.lesshst ./.ssh ./.subversion ./.Trash ./.Xauthority ./ Desktop ./Documents ./ Downloads ./inputrc ./Library ./Movies ./ Music ./Pictures ./ Public ./python ./Sites >>> ./ >>> import rlcompleter >>> pri[TAB]--> completes >>> if testvar: ... [one TAB: nothing], [two TABs: "Display all 179 possibilities y/ n?"] (Note: here i need it to insert a tab, just as it should!) So this ostensibly makes it very hard to write or paste any code into the command line! any further ideas? Thanks again ~N From Antoon.Pardon at rece.vub.ac.be Mon Sep 20 13:28:49 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 20 Sep 2010 19:28:49 +0200 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <20100920172849.GA3388@rcpc42.vub.ac.be> On Sun, Sep 19, 2010 at 11:30:32PM +0000, Seebs wrote: > On 2010-09-19, MRAB wrote: > > On 19/09/2010 22:32, Seebs wrote: > >> On 2010-09-19, AK wrote: > >>> Because that's what 'if' and 'else' mean. > > >> My point is, I don't want the order of the clauses in if/else to change. > >> If it is sometimes "if else", then > >> it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, > >> then false clause. If it's sometimes "if condition true-clause else > >> false-clause", and sometimes "true-clause if condition else false-clause", > >> that's a source of extra complexity. > > > > [snip] > > Have you read PEP 308? There was a lot of discussion about it. > > Interesting, in the historical section we see: > > The original version of this PEP proposed the following syntax: > > if else > > The out-of-order arrangement was found to be too uncomfortable > for many of participants in the discussion; especially when > is long, it's easy to miss the conditional while > skimming. > > But apparently those objections were either unknown or disregarded when > the syntax was later adopted. Not necessarily. Some of us have the impression that Guido deliberatly chose an ugly format for the ternary operator. Guido has alwasys been against a ternary operator but the requests kept coming. So eventually he introduced one. But the impression is that he chose an ugly format in the hope of discouraging people to use it. -- Antoon Pardon From hobson42 at gmaiil.com Mon Sep 20 13:30:22 2010 From: hobson42 at gmaiil.com (Ian) Date: Mon, 20 Sep 2010 18:30:22 +0100 Subject: Encoding problem - or bug in couchdb-0.8-py2.7.egg?? In-Reply-To: <87iq201k32.fsf@web.de> References: <87iq201k32.fsf@web.de> Message-ID: <4C979A2E.5050505@gmaiil.com> Thanks Diez, Removing, rebooting and installing the latest version solved the problem. :) Your google-foo is better than mine. Google had not turned that up for me. Thanks again Regards Ian On 20/09/2010 17:00, Diez B. Roggisch wrote: > Ian Hobson writes: > >> Hi all, >> >> I have hit a problem and I don't know enough about python to diagnose >> things further. Trying to use couchDB from Python. This script:- >> >> # coding=utf8 >> import couchdb >> from couchdb.client import Server >> server = Server() >> dbName = 'python-tests' >> try: >> db = server.create(dbName) >> except couchdb.PreconditionFailed: >> del server[dbName] >> db = server.create(dbName) >> doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) >> >> Gives this traceback:- >> >> D:\work\C-U-B>python tes1.py >> Traceback (most recent call last): >> File "tes1.py", line 11, in >> doc_id, doc_rev = db.save({'type': 'Person', 'name': 'John Doe'}) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\client.py", >> line 407, in save >> _, _, data = func(body=doc, **options) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", >> line 399, in post_json >> status, headers, data = self.post(*a, **k) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", >> line 381, in post >> **params) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", >> line 419, in _request >> credentials=self.credentials) >> File >> "C:\Python27\lib\site-packages\couchdb-0.8-py2.7.egg\couchdb\http.py", >> line 310, in request >> raise ServerError((status, error)) >> couchdb.http.ServerError: (400, ('bad_request', 'invalid UTF-8 JSON')) >> >> D:\work\C-U-B> >> >> Why? I've tried adding u to the strings, and removing the # coding >> line, and I still get the same error. > Sounds cargo-cultish. I suggest you read the python introduction on > unicode. > > http://docs.python.org/howto/unicode.html > > For your actual problem, I have difficulties seeing how it can happen > with the above data - frankly because there is nothing outside the > ascii-range of data, so there is no reason why anything could be wrong > encoded. I came to the same conclusion. > But googling the error-message reveals that there seem to be totally > unrelated reasons for this: > > http://sindro.me/2010/4/3/couchdb-invalid-utf8-json > > Maybe using something like tcpmon or ethereal to capture the actual > HTTP-request helps to see where the issue comes from. > > Diez From mail at timgolden.me.uk Mon Sep 20 13:35:54 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 20 Sep 2010 18:35:54 +0100 Subject: catching WM_TIMER message In-Reply-To: <0f445259-11e5-410b-bdab-2cdb26919d83@c16g2000vbp.googlegroups.com> References: <289977bb-a24f-4a35-9072-2d784789cdfc@e20g2000vbn.googlegroups.com> <0f445259-11e5-410b-bdab-2cdb26919d83@c16g2000vbp.googlegroups.com> Message-ID: <4C979B7A.1090500@timgolden.me.uk> On 20/09/2010 5:41 PM, Greg Miller wrote: > Thank you for the assist! Quick question though, using the first > example is there any need to register for WM_TIMER, ( instead of > registering for WM_HOTKEY ), or is extracting the "home grown Windows > message loop" enough and just run with that? In short: no need to register (although the WM_TIMER will have to come from somewhere, ie your process will have to initiated a SetTimer call. If you aren't familiar with this area, it's worth your reading up on the way in which Windows message queues and timers work. There are oodles of examples /tutorials. This is pretty much the canonical starting point: http://msdn.microsoft.com/en-us/library/ms644928%28VS.85%29.aspx but obviously YMMV. TJG From hobson42 at gmaiil.com Mon Sep 20 13:36:50 2010 From: hobson42 at gmaiil.com (Ian) Date: Mon, 20 Sep 2010 18:36:50 +0100 Subject: How to make a web services in python ??? In-Reply-To: References: Message-ID: <4C979BB2.4020809@gmaiil.com> On 20/09/2010 16:09, Ariel wrote: > Soap web services I think. > > On Fri, Sep 17, 2010 at 5:35 PM, Hidura > wrote: > > What kind of web-service you have in mind???? > > 2010/9/17, Ariel >: > > Hi everybody, I need some help to find documentation about how > to implements > > web services in python, could you help me please ??? > > Regards > > Thanks in advance > > Ariel > > > > Hi Ariel, There are a few pages on creating a TCP server and a Threaded server in Chapters 18 and 19 of "Rapid GUI Programming with Python and Qt" by Mark Summerfield. It shows you how to handle sockets, threading , and the locking of shared data constructs. Regards Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From yoavglazner at gmail.com Mon Sep 20 14:10:58 2010 From: yoavglazner at gmail.com (Glazner) Date: Mon, 20 Sep 2010 11:10:58 -0700 (PDT) Subject: Python Monitoring References: <4d1cbff7-af15-4ec8-bb24-0cbd616ca594@q9g2000vbd.googlegroups.com> <87eico1jy9.fsf@web.de> Message-ID: <0c2c9d7f-9c5b-40d8-8eef-53c5842d09dd@u13g2000vbo.googlegroups.com> On Sep 20, 6:03?pm, de... at web.de (Diez B. Roggisch) wrote: > Glazner writes: > > Hi, > > > I'm will be writing a distributed program with parallel python and i > > would like to if there are any good monitoring utilities for python. > > I would like each remote server to post messages and to see the > > messages in a web-broweser or such. > > > I googled python monitoring and found pymon but it seems a bit > > outdated. > > It's not exactly what you asked for, but the supervisord written in > Python is not only capable of watching a process (admittedly always on > the machine it is supposed to run), but can also be configured to have > XMLRPC based (and I think even other) interfaces that a central server > could poll & see the status of specific processes. I admit though that > it needs more configuration. Just wanted to mention it, because process > management might be on your list as well. > > Diez mmm... , windows not supported :( I need windows (cross platform is important) From usenet-nospam at seebs.net Mon Sep 20 14:14:34 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 18:14:34 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Tim Harig wrote: > You could simply place the filter in slrn; then, any urls that you see in > your reader would already be shown with the preview prefix suitable for cut > and paste mechanisms. If you wanted, you can even have your script > download the preview and automatically convert it back to the full > origional URL. This would require me to do a lot more work. :) > I assume just the opposite. Once the post has been removed from the > server, it is gone to me. I am not fond of the various archives that are > otherwise available on the web. Huh. I find the old usenet archives amusing, at the very least, and often very informative. > No, I tend to think is is much better that posts simply expire by > their use by date. I prefer data to be around as long as possible, since it at least potentially reduces effort. > If this was something that was forced upon you, then I might have some > sympathy; however, I see it as the poster's right to do what he thinks will > make his post more effective. I agree. On the other hand, many people are simply unaware of some of the reasons for which tinyurl and the like can make their message less effective to at least some users, so mentioning this to them may be useful. In theory, you have the right to indent your Python code however you want. In practice, if you don't use four spaces, you'll run into various problems interoperating with other people. Telling people this if they don't know it or are ignoring it is probably useful, even though ultimately the decision remains up to 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 tjreedy at udel.edu Mon Sep 20 14:23:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Sep 2010 14:23:45 -0400 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) In-Reply-To: <4c96d845$0$11113$c3e8da3@news.astraweb.com> References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 9/19/2010 11:43 PM, Steven D'Aprano wrote: > On Sun, 19 Sep 2010 06:16:49 -0700, Aahz wrote: > >> Please don't use tinyurl -- it's opaque and provides zero help to anyone >> who might later want to look it up (and also no accessibility if tinyurl >> ever goes down). At the very least, include the original URL for >> reference. > > Do you have something against tinyurl in particular, or would any URL > shortener service also get your ire? All of them. For mail/news without a 140 char limit, read with a mail/news reader, there is usually no point to using them. All pain, no gain. I almost never click on them. (This is quite different from ephemeral photo storage sites, where the short url is *the* one and only url.) Most long urls have a bunch of unneeded garbage at the end. When I create or search for a tracker issue, resulting url in the browser bar is about 2/3rds unnecessary stuff. When posting such links, I only cut and paste the needed part: http://bugs.python.org/issue#### and leave off the rest. I may also include the title separately. Anyone reading that can know just what they will find. -- Terry Jan Reedy From chris at simplistix.co.uk Mon Sep 20 14:29:44 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 20 Sep 2010 19:29:44 +0100 Subject: sqlalchemy: how to define association object with declarative style? In-Reply-To: References: Message-ID: <4C97A818.5070409@simplistix.co.uk> Hi Jerry, For SQLAlchemy questions, you're better off asking on sqlalchemy at googlegroups.com. On 07/09/2010 10:39, Jerry Fleming wrote: > class GroupUser(DeclarativeBase, Tablename, TimestampMixin): > id = Column(Integer, Sequence('group_user_id_seq'), primary_key=True) > user = Column(Integer, ForeignKey('user.id'), index=True), > group = Column(Integer, ForeignKey('group.id'), index=True) > > I was wondering how to associate User and Group with GroupUser with > GroupUser as the association object/proxy? The sqlalchemy docs only > mention only mention association tables, or non-declarative manual mapping. Yes, declarative doesn't currently work like this. The functionality could probably be added, but Michael Bayer would be the man to decide how to do that :-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From tjreedy at udel.edu Mon Sep 20 14:30:08 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Sep 2010 14:30:08 -0400 Subject: newbie: class and __dict__ variable. In-Reply-To: <4c972eb9$0$12598$426a34cc@news.free.fr> References: <4c970cdd$0$21775$426a74cc@news.free.fr> <4c972065$0$11113$c3e8da3@news.astraweb.com> <4c972eb9$0$12598$426a34cc@news.free.fr> Message-ID: On 9/20/2010 5:51 AM, Bruno Desthuilliers wrote: > Steven D'Aprano a ?crit : >> On Mon, 20 Sep 2010 09:27:25 +0200, Bruno Desthuilliers wrote: >> >>>> If the class has a .__setattr__ method, the first bypasses that method, >>> It also bypasses object.__setattribute__ and - as a consequence - any >>> binding descriptor by the same name as the attribute being set. >> >> __setattribute__ ? >> >> >>>>> object.__setattribute__ >> Traceback (most recent call last): >> File "", line 1, in >> AttributeError: type object 'object' has no attribute '__setattribute__' >> > > Duh... > Brain fart, sorry, shouldn't post before I get my dose of coffee :( > > Let's do it again: > > Terry Reedy a ?crit : > > If the class has a .__setattr__ method, the first bypasses that > > method, > > All new-style classes have a __setattr__ method - whether inherited from > object or overridden. object.__setattr__ implements the support for > binding descriptors, so bypassing it will also bypass all binding > descriptors. > > The right way to avoid infinite recursion when overriding __setattr__ is > to call on the superclass __setattr__, unless of course you *really* > know what you're doing... In the 3.x doc, this is now the recommended method. The self.__dict__ idiom predates new-style classes, object, and super. To the OP. It is possible that you have seem bad (useless, redundant) uses as well as uses that were necessary with old-style user classes. > class BarDescriptor(object): > def __init__(self): > self.val = None > > def __set__(self, instance, value): > print "stores value elsewhere and trigger some required behaviour" > self.val = value * 2 > > def __get__(self, instance, cls=None): > if instance is None: > return self > print "retrieve value from elsewhere and trigger some required behaviour" > return self.val > > # well behaved > class Foo(object): > bar = BarDescriptor() > > def __init__(self): > self.bar = 42 > > def __setattr__(self, name, value): > print "override __setattr_ for some reason" > super(Foo, self).__setattr__(name, value) > > > # ugly mess > class Baaz(Foo): > bar = BarDescriptor() > > def __init__(self): > self.__dict__['bar'] = 42 > > def __setattr__(self, name, value): > print "override __setattr_ for some reason" > self.__dict__[name] == value > > >>> f = Foo() > override __setattr_ for some reason > stores value elsewhere and trigger some required behaviour > >>> f.bar > retrieve value from elsewhere and trigger some required behaviour > 84 > >>> f.__dict__ > {} > >>> f.bar = 33 > override __setattr_ for some reason > stores value elsewhere and trigger some required behaviour > >>> f.bar > retrieve value from elsewhere and trigger some required behaviour > 66 > >>> f.__dict__ > {} > >>> b = Baaz() > >>> b.__dict__ > {'bar': 42} > >>> b.bar > retrieve value from elsewhere and trigger some required behaviour > >>> b.bar = 33 > override __setattr_ for some reason > >>> b.bar > retrieve value from elsewhere and trigger some required behaviour > >>> b.__dict__ > {'bar': 42} -- Terry Jan Reedy From tjreedy at udel.edu Mon Sep 20 14:43:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Sep 2010 14:43:31 -0400 Subject: Too much code - slicing In-Reply-To: <4C96DD24.3020400@gmail.com> References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> <4C96DD24.3020400@gmail.com> Message-ID: > On 09/19/2010 10:32 PM, John Bokma wrote: >> the spoiler. Do you fast forward movies as well? I sometimes watch movies (or parts thereof) on 1.5x, especially if it has a lot of 'filler' scenes. But only when my wife is not watching, as she hates it. -- Terry Jan Reedy From chris at simplistix.co.uk Mon Sep 20 14:45:37 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 20 Sep 2010 19:45:37 +0100 Subject: os.path.normcase rationale? In-Reply-To: <87lj727lu7.fsf@benfinney.id.au> References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <4C97ABD1.5090506@simplistix.co.uk> On 15/09/2010 22:12, Ben Finney wrote: > Chris Withers writes: > >> I'm curious as to why, with a file called "Foo.txt" >> os.path.normcase('FoO.txt') will return "foo.txt" rather than >> "Foo.txt"? > > What kind of answer are you looking for? > > A direct answer would be: it does that because on case-insensitive > filesystems, it doesn't matter what the case is, so there's no need for > anything more complex than all lowercase. Well, no, that doesn't feel right. Normalisation of case, for me, means "give me the case as the filesystem thinks it should be", not "just lowercase it all". This makes a difference; I hit it by way of version pinning in buildout, the culprit being setuptools calling normcase on distributions found on the filesystem on Windows. Buildout's version pinning is case sensitive (arguably a bug) and so doesn't work when setuptools's use of normcase ends up with he distribution name being lowercased, even though the case is correct on the file system... >> Yes, I know the behaviour is documented > > The docstring is fairly poor, IMO. You might want to submit a bug report > to improve it. I think it would have been a lot more confusing had it not been mentioned that it was just lowercasing everything... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Mon Sep 20 14:46:39 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 20 Sep 2010 19:46:39 +0100 Subject: os.path.normcase rationale? In-Reply-To: <8fd2c1FvvhU1@mid.individual.net> References: <87lj727lu7.fsf@benfinney.id.au> <8fd2c1FvvhU1@mid.individual.net> Message-ID: <4C97AC0F.9090108@simplistix.co.uk> On 16/09/2010 00:14, Gregory Ewing wrote: > Ben Finney wrote: >> it doesn't matter what the case is, so there's no need for >> anything more complex than all lowercase. > > Also doing what was suggested would require looking at > what's in the file system, which would be a lot of bother > to go to for no good reason, and would fail for paths > that don't correspond to an existing file. .lower() is shorter to type, if that's what you want... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From usenet-nospam at seebs.net Mon Sep 20 14:47:50 2010 From: usenet-nospam at seebs.net (Seebs) Date: 20 Sep 2010 18:47:50 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-20, Antoon Pardon wrote: > Not necessarily. Some of us have the impression that Guido deliberatly > chose an ugly format for the ternary operator. Guido has alwasys been > against a ternary operator but the requests kept coming. So eventually > he introduced one. But the impression is that he chose an ugly format > in the hope of discouraging people to use it. If true, that is an *awesome* etymology for a hunk of a programming 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 chris at simplistix.co.uk Mon Sep 20 14:48:40 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 20 Sep 2010 19:48:40 +0100 Subject: os.path.normcase rationale? In-Reply-To: References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <4C97AC88.5080207@simplistix.co.uk> On 17/09/2010 03:35, Nobody wrote: > os.path.normcase(path) > Normalize the case of a pathname. On Unix and Mac OS X, this returns > the path unchanged; on case-insensitive filesystems, it converts the > path to lowercase. On Windows, it also converts forward slashes to > backward slashes. > > It implies that the behaviour depends upon the actual filesystem, which > isn't the case. It only depends upon the platform, i.e. it assumes that > all filenames are case-sensitive on Unix systems and case-insensitive on > Windows. But Unix systems can access FAT/SMBFS/etc filesystems which are > case-insensitive. Right, so in its current form it seems pretty useless ;-) What I expected it to mean was "give me what the filesystem thinks this file path is", which doesn't seem unreasonable and would be a lot more useful, no matter the platform... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rudikk99 at yahoo.com Mon Sep 20 14:58:09 2010 From: rudikk99 at yahoo.com (rudikk00) Date: Mon, 20 Sep 2010 11:58:09 -0700 (PDT) Subject: match pattern Message-ID: Hi all, I remember perl has a match function =~/H/ --> which searches if there is "H" pattern in line. Is there a reasonable analog of it in python? thanks! Alex From ian.g.kelly at gmail.com Mon Sep 20 15:15:30 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 13:15:30 -0600 Subject: match pattern In-Reply-To: References: Message-ID: On Mon, Sep 20, 2010 at 12:58 PM, rudikk00 wrote: > Hi all, > > I remember perl has a match function =~/H/ --> which searches if there > is "H" pattern in line. Is there a reasonable analog of it in python? > Yes, have a look at the re module in the standard library. If all you're interested in is exact matches and not regular expressions, you can also use the "in" operator: if "H" in my_string: do_something() Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Sep 20 15:22:47 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 13:22:47 -0600 Subject: Too much code - slicing In-Reply-To: <20100920172849.GA3388@rcpc42.vub.ac.be> References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <20100920172849.GA3388@rcpc42.vub.ac.be> Message-ID: On Mon, Sep 20, 2010 at 11:28 AM, Antoon Pardon < Antoon.Pardon at rece.vub.ac.be> wrote: > > Not necessarily. Some of us have the impression that Guido deliberatly > chose an ugly format for the ternary operator. Guido has alwasys been > against a ternary operator but the requests kept coming. So eventually > he introduced one. But the impression is that he chose an ugly format > in the hope of discouraging people to use it. > If that was indeed the intention, then it worked, at least in my case. Hmm, perhaps we should also add goto to the language, but we'll call it something cumbersome like "slitherto" and give it the side effect of reformatting the hard drive. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Mon Sep 20 16:19:37 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 20 Sep 2010 22:19:37 +0200 Subject: Python and unicode In-Reply-To: References: <1c0c76e3-e608-4264-9dfe-faae92d1a4fe@k9g2000vbo.googlegroups.com> <87k4mh5o0k.fsf@benfinney.id.au> <4c96d826$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4C97C1D9.6070202@v.loewis.de> Am 20.09.2010 12:57, schrieb Dotan Cohen: > On Mon, Sep 20, 2010 at 12:20, Peter Otten <__peter__ at web.de> wrote: >> It may work by accident, if you declare it as UTF-8, because that is also >> the default in Python 3. >> > > That does seem to be the case. > > Thank you for the enlightenment and information. It's as Peter says. Python really will ignore any encoding declaration on the third or later line. This was added to the spec on explicit request from Guido van Rossum. It's still the case today. However, in Python 3, in the absence of an encoding declaration, the file encoding is assumed to be UTF-8 (producing an error if it actually is not). So it worked for you by accident. Regards, Martin From deets at web.de Mon Sep 20 16:40:58 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 22:40:58 +0200 Subject: match pattern References: Message-ID: rudikk00 writes: > I remember perl has a match function =~/H/ --> which searches if there > is "H" pattern in line. Is there a reasonable analog of it in python? It's called a regular expression, which can be matched or searched in a string. Take a look at the module "re" in python. http://docs.python.org/library/re.html Diez From deets at web.de Mon Sep 20 16:45:20 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 22:45:20 +0200 Subject: Python Monitoring References: <4d1cbff7-af15-4ec8-bb24-0cbd616ca594@q9g2000vbd.googlegroups.com> <87eico1jy9.fsf@web.de> <0c2c9d7f-9c5b-40d8-8eef-53c5842d09dd@u13g2000vbo.googlegroups.com> Message-ID: Glazner writes: > On Sep 20, 6:03?pm, de... at web.de (Diez B. Roggisch) wrote: >> Glazner writes: >> > Hi, >> >> > I'm will be writing a distributed program with parallel python and i >> > would like to if there are any good monitoring utilities for python. >> > I would like each remote server to post messages and to see the >> > messages in a web-broweser or such. >> >> > I googled python monitoring and found pymon but it seems a bit >> > outdated. >> >> It's not exactly what you asked for, but the supervisord written in >> Python is not only capable of watching a process (admittedly always on >> the machine it is supposed to run), but can also be configured to have >> XMLRPC based (and I think even other) interfaces that a central server >> could poll & see the status of specific processes. I admit though that >> it needs more configuration. Just wanted to mention it, because process >> management might be on your list as well. >> >> Diez > > mmm... , windows not supported :( > I need windows (cross platform is important) Ah. Poor you. Well, there is also pyro. It should run on all OS, and it comes with a name-service. With this, it's actually possible and probably quite easy to have all your respective clients/workers/agents connect themselves to central monitoring instance, and posting more or less accurately their state. The configuration needed should be minimal, and depending on your network setup even trivial because there is some broadcasting detection ala bonjour available. The worst that can happen is that you have to spread knowledge of a specific pyro server through a string like pyro:/// or some such. Diez From fazzitron at gmail.com Mon Sep 20 16:54:56 2010 From: fazzitron at gmail.com (Seth Leija) Date: Mon, 20 Sep 2010 13:54:56 -0700 (PDT) Subject: Combinations or Permutations Message-ID: I need to know how to generate a list of combinations/permutations (can't remember which it is). Say I have a list of variables: [a,b,c,d,...,x,y,z] I am curious if there is an optimized way to generate this: [[a,b],[a,c],[a,d],...,[x,z],[y,z]] I currently have an iteration that does this: #list.py from math import * list1=['a','b','c','d','e'] list2=[] length=len(list1) for it1 in range(0 ,length): for it2 in range(it1+1, length): list2.append([list1[it1],list1[it2]]) print list2 However, this is one of the slowest parts of my function (beaten only by variable instantiation). I posted this on another forum looking to see if there was a different method completely. They said that my method was about as simple as it could get, but I might be able to find out how to optimize my code here. Thanks in advance. From deets at web.de Mon Sep 20 16:54:59 2010 From: deets at web.de (Diez B. Roggisch) Date: Mon, 20 Sep 2010 22:54:59 +0200 Subject: visual studio 2010 question References: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> Message-ID: David Cournapeau writes: > On Mon, Sep 20, 2010 at 3:08 PM, Ralf Haring wrote: >> >> After running into the error "Setup script exited with error: Unable >> to find vcvarsall.bat" when trying to use easy_install / setuptools a >> little digging showed that the MS compiler files in distutils only >> support up to Studio 2008. Does anyone know if there is a timetable >> for when Studio 2010 will be supported? >> >> I am using python 2.6.5, but web searching seemed to show that 2.7 or >> 3.X didn't support it yet either. > > You should use VS 2008 - the lack of distutils support is only the > first of a long list of issues if you want to use another compiler to > build python extensions. Unless you really know what you are doing, > you are better off with VS 2008, Forgive my ignorance, but AFAIK mingw can be used to build extensions for standard python distributions. After all, it's C we're talking here, not C++. So I have difficulties imagining VS2010 is that much of a problem. So - which problems you expect? Diez From ckaynor at zindagigames.com Mon Sep 20 17:00:35 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 20 Sep 2010 14:00:35 -0700 Subject: Combinations or Permutations In-Reply-To: References: Message-ID: The itertools module (http://docs.python.org/library/itertools.html) has both permutations and combinations functionality. Chris On Mon, Sep 20, 2010 at 1:54 PM, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > I currently have an iteration that does this: > > #list.py > > from math import * > > list1=['a','b','c','d','e'] > list2=[] > length=len(list1) > > for it1 in range(0 ,length): > for it2 in range(it1+1, length): > list2.append([list1[it1],list1[it2]]) > > print list2 > > However, this is one of the slowest parts of my function (beaten only > by variable instantiation). I posted this on another forum looking to > see if there was a different method completely. They said that my > method was about as simple as it could get, but I might be able to > find out how to optimize my code here. > > Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Sep 20 17:02:33 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 15:02:33 -0600 Subject: Combinations or Permutations In-Reply-To: References: Message-ID: On Mon, Sep 20, 2010 at 2:54 PM, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > In Python 2.6 or newer: >>> from itertools import combinations >>> import string >>> print list(combinations(string.lowercase, 2)) Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Sep 20 17:07:03 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Sep 2010 22:07:03 +0100 Subject: Too much code - slicing In-Reply-To: <20100920172849.GA3388@rcpc42.vub.ac.be> References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <20100920172849.GA3388@rcpc42.vub.ac.be> Message-ID: On 20/09/2010 18:28, Antoon Pardon wrote: > On Sun, Sep 19, 2010 at 11:30:32PM +0000, Seebs wrote: >> On 2010-09-19, MRAB wrote: >>> On 19/09/2010 22:32, Seebs wrote: >>>> On 2010-09-19, AK wrote: >>>>> Because that's what 'if' and 'else' mean. >> >>>> My point is, I don't want the order of the clauses in if/else to change. >>>> If it is sometimes "if else", then >>>> it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause, >>>> then false clause. If it's sometimes "if condition true-clause else >>>> false-clause", and sometimes "true-clause if condition else false-clause", >>>> that's a source of extra complexity. >>> >>> [snip] >>> Have you read PEP 308? There was a lot of discussion about it. >> >> Interesting, in the historical section we see: >> >> The original version of this PEP proposed the following syntax: >> >> if else >> >> The out-of-order arrangement was found to be too uncomfortable >> for many of participants in the discussion; especially when >> is long, it's easy to miss the conditional while >> skimming. >> >> But apparently those objections were either unknown or disregarded when >> the syntax was later adopted. > > Not necessarily. Some of us have the impression that Guido deliberatly > chose an ugly format for the ternary operator. Guido has alwasys been > against a ternary operator but the requests kept coming. So eventually > he introduced one. But the impression is that he chose an ugly format > in the hope of discouraging people to use it. > I very much like the format of the Python ternary operator, but I've never actually used it myself :) Cheers Mark Lawrence. From breamoreboy at yahoo.co.uk Mon Sep 20 17:08:53 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Sep 2010 22:08:53 +0100 Subject: Combinations or Permutations In-Reply-To: References: Message-ID: On 20/09/2010 21:54, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > I currently have an iteration that does this: > > #list.py > > from math import * > > list1=['a','b','c','d','e'] > list2=[] > length=len(list1) > > for it1 in range(0 ,length): > for it2 in range(it1+1, length): > list2.append([list1[it1],list1[it2]]) > > print list2 > > However, this is one of the slowest parts of my function (beaten only > by variable instantiation). I posted this on another forum looking to > see if there was a different method completely. They said that my > method was about as simple as it could get, but I might be able to > find out how to optimize my code here. > > Thanks in advance. Check the docs for the itertools module. Cheers. Mark Lawrence. From robert.kern at gmail.com Mon Sep 20 17:11:01 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 20 Sep 2010 16:11:01 -0500 Subject: visual studio 2010 question In-Reply-To: References: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> Message-ID: On 9/20/10 3:54 PM, Diez B. Roggisch wrote: > David Cournapeau writes: > >> On Mon, Sep 20, 2010 at 3:08 PM, Ralf Haring wrote: >>> >>> After running into the error "Setup script exited with error: Unable >>> to find vcvarsall.bat" when trying to use easy_install / setuptools a >>> little digging showed that the MS compiler files in distutils only >>> support up to Studio 2008. Does anyone know if there is a timetable >>> for when Studio 2010 will be supported? >>> >>> I am using python 2.6.5, but web searching seemed to show that 2.7 or >>> 3.X didn't support it yet either. >> >> You should use VS 2008 - the lack of distutils support is only the >> first of a long list of issues if you want to use another compiler to >> build python extensions. Unless you really know what you are doing, >> you are better off with VS 2008, > > Forgive my ignorance, but AFAIK mingw can be used to build extensions > for standard python distributions. After all, it's C we're talking here, > not C++. So I have difficulties imagining VS2010 is that much of a > problem. So - which problems you expect? VS2010 uses a different C runtime DLL than VS2008 and Python 2.6, and I believe this cannot be changed. This will cause errors for a variety of Python extension modules. mingw can be retargeted to link against one of several different C runtimes, including the one VS2008 uses. -- 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 astley.lejasper at gmail.com Mon Sep 20 17:42:26 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Mon, 20 Sep 2010 14:42:26 -0700 (PDT) Subject: Grouping pairs - suggested tools Message-ID: I have a list of tuples that indicate a relationship, ie a is related to b, b is related to c etc etc. What I want to do is cluster these relationships into groups. An item will only be associated with a single cluster. Before I started, I wondered if there was any particular tool within Python I should be looking at. I don't expect anyone to code this for me, just say ... "you need to look at using x". I was going to use populate a dictionary and Sorry for being so vague. Example Data: [(a,b) (a,c) (a,d) (b,c) (b,d) (c,d) (e,f) (e,g) (f,g) (h,i)] Output (grouping id, item ref) (1,a), (1,b), (1,c), (1,d), (2,e), (2,f), (2,g), (3,h), (3,i) From nad at acm.org Mon Sep 20 17:49:47 2010 From: nad at acm.org (Ned Deily) Date: Mon, 20 Sep 2010 14:49:47 -0700 Subject: hitting TAB inserts ./ in interactive mode ? References: <431250b2-391e-4a1f-ba72-08afb7159d65@l25g2000prn.googlegroups.com> <7b7f018e-b429-448b-94c1-2a812c5f3436@h37g2000pro.googlegroups.com> Message-ID: In article <7b7f018e-b429-448b-94c1-2a812c5f3436 at h37g2000pro.googlegroups.com>, Nik Krumm wrote: > The issue isn't with readline. The readline module or rlcompleter > module are both available, and loading them has no effect on the > behavior of tab: > > >>> import readline > [Now i hit tab...] > >>> ./ > File "", line 1 > ./ > ^ > SyntaxError: invalid syntax > > [Hit tab twice...] > >>> ./ > ./.bash_history ./.bash_profile ./.bash_profile.pysave [...] > So this ostensibly makes it very hard to write or paste any code into > the command line! Ah, thanks, I get it now. It turns out this is a bug seen for the first time with the new-style (32-/64-, 10.5+) python.org 2.7 installer build because it links with the Apple-supplied editline library rather than the GNU readline library as in other installers. I've opened an issue for this: http://bugs.python.org/issue9907 As noted there, two workarounds come to mind. Either switch to using the old-style (32-only, 10.3+) 2.7 installer; or, add or modify a PYTHONSTARTUP file to force the desired TAB behavior, so something like this: $ cat > $HOME/.pystartup import readline if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I ed-insert") ^D $ export PYTHONSTARTUP=$HOME/.pystartup Thanks for reporting this! -- Ned Deily, nad at acm.org From fazzitron at gmail.com Mon Sep 20 17:57:48 2010 From: fazzitron at gmail.com (Seth Leija) Date: Mon, 20 Sep 2010 14:57:48 -0700 (PDT) Subject: Combinations or Permutations References: Message-ID: <044f3958-d3e6-4ad8-b60b-67fb363cc542@a4g2000prm.googlegroups.com> On Sep 20, 3:08?pm, Mark Lawrence wrote: > On 20/09/2010 21:54, Seth Leija wrote: > > > > > > > I need to know how to generate a list of combinations/permutations > > (can't remember which it is). Say I have a list of variables: > > > [a,b,c,d,...,x,y,z] > > > I am curious if there is an optimized way to generate this: > > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > > I currently have an iteration that does this: > > > #list.py > > > from math import * > > > list1=['a','b','c','d','e'] > > list2=[] > > length=len(list1) > > > for it1 in range(0 ,length): > > ? ? ?for it2 in range(it1+1, length): > > ? ? ? ? ?list2.append([list1[it1],list1[it2]]) > > > print list2 > > > However, this is one of the slowest parts of my function (beaten only > > by variable instantiation). I posted this on another forum looking to > > see if there was a different method completely. They said that my > > method was about as simple as it could get, but I might be able to > > find out how to optimize my code here. > > > Thanks in advance. > > Check the docs for the itertools module. > > Cheers. > > Mark Lawrence. That works! That made my function significantly faster! It's still slower than I would like it, but this is enough for now. Thank you so much! From glenn.pringle at gmail.com Mon Sep 20 18:47:32 2010 From: glenn.pringle at gmail.com (Glenn Pringle) Date: Mon, 20 Sep 2010 15:47:32 -0700 (PDT) Subject: Arrays and CTYPE Message-ID: <824d1ec2-93ee-4a81-ad95-19560fabe9e4@r10g2000vbc.googlegroups.com> Ok. I ran into a problem here. I have been dabbling with Python and I thought that this would be a good exercise but I got stuck. I have a DLL and one of the functions(getState) in that DLL returns an array. I'm having a hard time getting access to the contents of that array. Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import ctypes >>> hold = ctypes.CDLL('Dinamap.dll') >>> print hold.checkReadiness() 1 >>> print hold.getBufferLength() 1400 >>> print hold.resetMonitor() 1 >>> print hold.getState() 42607516 >>> Would greatly appreciate if somebody points me in the right direction. Thanks, Glenn From clp2 at rebertia.com Mon Sep 20 18:59:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 20 Sep 2010 15:59:31 -0700 Subject: Arrays and CTYPE In-Reply-To: <824d1ec2-93ee-4a81-ad95-19560fabe9e4@r10g2000vbc.googlegroups.com> References: <824d1ec2-93ee-4a81-ad95-19560fabe9e4@r10g2000vbc.googlegroups.com> Message-ID: On Mon, Sep 20, 2010 at 3:47 PM, Glenn Pringle wrote: > Ok. I ran into a problem here. I have been dabbling with Python and I > thought that this would be a good exercise but I got stuck. > > I have a DLL and one of the functions(getState) in that DLL returns an > array. I'm having a hard time getting access to the contents of that > array. > > Python 2.7 (r27:82525, Jul ?4 2010, 09:01:59) [MSC v.1500 32 bit > (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> import ctypes >>>> hold = ctypes.CDLL('Dinamap.dll') >>>> print hold.checkReadiness() > 1 >>>> print hold.getBufferLength() > 1400 >>>> print hold.resetMonitor() > 1 >>>> print hold.getState() > 42607516 >>>> > > Would greatly appreciate if somebody points me in the right direction. Set hold.getState.restype appropriately. Read the fine docs: http://docs.python.org/library/ctypes.html#return-types http://docs.python.org/library/ctypes.html#fundamental-data-types Cheers, Chris -- http://blog.rebertia.com From alf.p.steinbach+usenet at gmail.com Mon Sep 20 19:09:09 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 21 Sep 2010 01:09:09 +0200 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: * Astley Le Jasper, on 20.09.2010 23:42: > I have a list of tuples that indicate a relationship, ie a is related > to b, b is related to c etc etc. What I want to do is cluster these > relationships into groups. An item will only be associated with a > single cluster. > > Before I started, I wondered if there was any particular tool within > Python I should be looking at. I don't expect anyone to code this for > me, just say ... "you need to look at using x". I was going to use > populate a dictionary and > > Sorry for being so vague. > > Example Data: > [(a,b) > (a,c) > (a,d) > (b,c) > (b,d) > (c,d) > (e,f) > (e,g) > (f,g) > (h,i)] > > Output (grouping id, item ref) > (1,a), > (1,b), > (1,c), > (1,d), > (2,e), > (2,f), > (2,g), > (3,h), > (3,i) It seems to be the same problem as "equivalence sets". This problem was solved early on because e.g. Fortran compilers had to construct such sets (equivalence partitions of a set). I though I'd just say "Google it!", because I know there's a standard algorithm but I can't recall the name. However, googling it I found no mention of that algorithm. Not even in the Wikipedia articles on equivalence sets. A number of approaches spring to mind: Approach 1: Multi-pass. Originally you assign a distinct set number to each symbol. In each pass through the symbols you replace one number with another as per one of the equivalence specs. Stop when no replacements are done. Approach 2: Merging. For each new equivalence A=B you check whether A has been assigned to a set, if not you create a new one, call that S1, and ditto for B, S2. Merge S1 and S2, e.g. move all elements of S2 to S1. Approach 3: In a first pass convert the data to more explicit form, linking each symbol to the symbols it's directly equivalent to. Then in second pass simply drag out each equivalence group (recurse on each symbol's list of equivalences). Approaches 1 and 2 seem to be pretty inefficient for a large number of symbols, but I think approach 1 may be a practical option for a small number of symbols. Cheers & hth., - Alf -- blog at From cmpython at gmail.com Mon Sep 20 19:10:13 2010 From: cmpython at gmail.com (CM) Date: Mon, 20 Sep 2010 16:10:13 -0700 (PDT) Subject: develop for Windows on GNU/Linux, using Python References: <8fn6ojF783U1@mid.individual.net> Message-ID: On Sep 20, 12:46?pm, Thomas Jollans wrote: > On Monday 20 September 2010, it occurred to Default User to exclaim: > > > > > On Sun, Sep 19, 2010 at 14:31, J.O. Aho wrote: > > > Kev Dwyer wrote: > > > > if you have C-extensions in > > > > your code you'll need to compile them over Windows. ?If you want to > > > > program against the Windows API you'll need access to a Windows box. > > > > You can always cross compile, not only over OS but even CPU architecture, > > > but > > > of course testing will be more difficult, on x86 based Linux you can use > > > wine > > > or similar to test, but can give you some differences to run on a native > > > or virtualized instance. > > > < sigh > . . . > > > Well, that's about what I expected, unfortunately. ? But thanks for the > > honest replies. > > > [OT] > > So what's the alternative -- use the end user's browser as an interpreter > > for JavaScript or HTML5? > > [/OT] > > Umn, what? > > Python makes it rather easy to write portable code. But you still need to test > it properly on all platforms you want to support, because maybe there's some > platform-specific glitch you weren't aware of. My guess is, if the application the person is writing uses basic features of Python and is more like a utility that one runs from the command line, there will not be that many concerns--maybe none. He might get lucky and it will just work on Windows. But if it is a GUI app and he uses, say, wxPython, I know there can be fairly significant differences in appearance between the two platforms, sometimes deal- breakingly so (but definitely able to be worked around). A lot depends on how complex/fancy the GUI is. From davea at ieee.org Mon Sep 20 19:21:05 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 20 Sep 2010 19:21:05 -0400 Subject: Combinations or Permutations In-Reply-To: References: Message-ID: <4C97EC61.2030005@ieee.org> On 2:59 PM, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > I currently have an iteration that does this: > > #list.py > > from math import * > > list1=['a','b','c','d','e'] > list2=[] > length=len(list1) > > for it1 in range(0 ,length): > for it2 in range(it1+1, length): > list2.append([list1[it1],list1[it2]]) > > print list2 > > However, this is one of the slowest parts of my function (beaten only > by variable instantiation). I posted this on another forum looking to > see if there was a different method completely. They said that my > method was about as simple as it could get, but I might be able to > find out how to optimize my code here. > > Thanks in advance. > You're apparently looking for combinations. You're asking for all the combinations of items from the original list, taken two at a time. Permutations would also include the reverse of each item, so it would be exactly twice the size. For the specific case of two, your approach is about as simple as it can get. However, generalizing the code to handle 'r' at a time is pretty tricky. There's a library function for it in Python 2.6 and later, as mentioned by others, and the docs show a sample implementation. Clearly making a single function call is optimized in one sense. However, if you're looking for speed, chances are you could improve on your own function by changing the two loops. (tested in python 2.6) Consider: list1=['a','b','c','d','e'] list2=[] for it1, val1 in enumerate(list1): for val2 in list1[it1+1:]: list2.append([val1, val2]) print list2 DaveA From peter.milliken at gmail.com Mon Sep 20 19:44:31 2010 From: peter.milliken at gmail.com (Peter) Date: Mon, 20 Sep 2010 16:44:31 -0700 (PDT) Subject: Customising Tk widgets Message-ID: <805f1248-9217-4688-9731-4a1868cf06c3@x20g2000pro.googlegroups.com> I am using Windoze, I suspect the appearance attributes I am asking about here are platform dependent? Using Tkinter, I would like to generate a Checkbutton that is filled in with a solid colour rather than a tick mark when selected. Could somebody provide some pointers as to how I could achieve this? Also, John Shipman's Tkinter reference shows the Radiobutton drawn as a diamond and yet when I create one in Windows I get a circle - again, how and where do I need to look to change this behaviour? Thanks Peter From ian.g.kelly at gmail.com Mon Sep 20 20:00:26 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 18:00:26 -0600 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: On Mon, Sep 20, 2010 at 5:09 PM, Alf P. Steinbach /Usenet < alf.p.steinbach+usenet at gmail.com >wrote: > It seems to be the same problem as "equivalence sets". > > This problem was solved early on because e.g. Fortran compilers had to > construct such sets (equivalence partitions of a set). > > I though I'd just say "Google it!", because I know there's a standard > algorithm but I can't recall the name. However, googling it I found no > mention of that algorithm. Not even in the Wikipedia articles on equivalence > sets. > I don't recall the name either, but the standard algorithm represents the equivalence sets as trees, with the canonical name of each set being whatever happens to be at the root of tree. To find the set containing any given node, you just recurse up to the root of its tree (and then repoint the links to the root on the way back down, to optimize for the next lookup). Merging two sets is then just a matter of hanging the root of one set from the root of the other. If memory serves, this algorithm is amortized O(n) if the optimization is performed, where n is the total number of merge and lookup operations. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Sep 20 20:00:26 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Sep 2010 18:00:26 -0600 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: On Mon, Sep 20, 2010 at 5:09 PM, Alf P. Steinbach /Usenet < alf.p.steinbach+usenet at gmail.com >wrote: > It seems to be the same problem as "equivalence sets". > > This problem was solved early on because e.g. Fortran compilers had to > construct such sets (equivalence partitions of a set). > > I though I'd just say "Google it!", because I know there's a standard > algorithm but I can't recall the name. However, googling it I found no > mention of that algorithm. Not even in the Wikipedia articles on equivalence > sets. > I don't recall the name either, but the standard algorithm represents the equivalence sets as trees, with the canonical name of each set being whatever happens to be at the root of tree. To find the set containing any given node, you just recurse up to the root of its tree (and then repoint the links to the root on the way back down, to optimize for the next lookup). Merging two sets is then just a matter of hanging the root of one set from the root of the other. If memory serves, this algorithm is amortized O(n) if the optimization is performed, where n is the total number of merge and lookup operations. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 20:02:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 00:02:49 GMT Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <4c97f629$0$28658$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 19:45:37 +0100, Chris Withers wrote: > Well, no, that doesn't feel right. Normalisation of case, for me, means > "give me the case as the filesystem thinks it should be", What do you mean "the filesystem"? If I look at the available devices on my system now, I see: 2 x FAT-32 filesystems 1 x ext2 filesystem 3 x ext3 filesystems 1 x NTFS filesystem 1 x UDF filesystem and if I ever get my act together to install Basilisk II, as I've been threatening to do for the last five years, there will also be at least one 1 x HFS filesystem. Which one is "the" filesystem? If you are suggesting that os.path.normcase(filename) should determine which filesystem actually applies to filename at runtime, and hence work out what rules apply, what do you suggest should happen if the given path doesn't actually exist? What if it's a filesystem that the normpath developers haven't seen or considered before? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 20:07:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 00:07:07 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c97f72b$0$28658$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: > Not necessarily. Some of us have the impression that Guido deliberatly > chose an ugly format for the ternary operator. If he did, then he must have changed his mind, because there is nothing ugly about the ternary operator we ended up with. > Guido has alwasys been > against a ternary operator but the requests kept coming. So eventually > he introduced one. But the impression is that he chose an ugly format in > the hope of discouraging people to use it. That's sheer and unadulterated nonsense. The fact is that Guido changed his mind about ternary if after discovering that the work-around true-clause and condition or false-clause is buggy -- it gives the wrong answer if true-clause happens to be a false value like [], 0 or None. If I recall correctly, the bug bit Guido himself. The and-or hack, which was *very* common in Python code for many years and many versions, follows the same pattern as ternary if: true-clause if condition else false-clause It astounds me how the Python community changed it's collective mind from admiration of the elegance and simplicity of the expression when it was a buggy hack, to despising it when it became a bug-free language feature. Go figure. -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Sep 20 20:09:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 00:09:51 GMT Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 17:25:09 +0000, Tim Harig wrote: >> And as a datapoint on the topic of archiving, I search usenet archives >> regularly when faced with a problem. > > Usernet users also have the right to use the X-No-Archive header field. They do? Is that right enshrined by law somewhere? Can I go to jail for human rights abuses if I archive X-No-Archive posts? > Does the fact that *you* happen to search usenet archives make using > this field immoral? Immoral and ineffective. > Shouldn't the poster have to right to determine for > themselves whether they care about the long term persistance of their > posts and be able to balance that against other factors? If you don't want your post to be read by people in six months, don't post it. It may be that news posts are, in the long term, ephemeral. But in the long term, the sun will expand and destroy the earth. In the meantime, X-No-Archive is an attempt to revise history by covering up what the poster said publicly. -- Steven From ben+python at benfinney.id.au Mon Sep 20 20:12:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 21 Sep 2010 10:12:27 +1000 Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> Message-ID: <87bp7s5504.fsf@benfinney.id.au> Chris Withers writes: > What I expected it to mean was "give me what the filesystem thinks > this file path is", which doesn't seem unreasonable and would be a lot > more useful, no matter the platform... Two problems with that. One is that the entry specified by the path may not exist on the filesystem, but the function shouldn't care about that. It's for ?normalising? a path, whether the entry referred to exists or not. Another is that filesystems don't have a standard way of determining whether they are case-sensitive. The operating system's driver for that particular filesystem knows, but Python doesn't. So in this case you'll simply have to adjust your expectations. -- \ ?I prayed for twenty years but received no answer until I | `\ prayed with my legs.? ?Frederick Douglass, escaped slave | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Mon Sep 20 20:16:19 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 21 Sep 2010 12:16:19 +1200 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> Message-ID: <8fqbrdF7t7U1@mid.individual.net> AK wrote: > One definite advantage would be that if, say, it takes you 70 pages of a > given novel to figure out whether you like it enough to continue, If there was that much doubt, I would give up long before reaching the 70 page mark, regardless of reading speed. If I'm not hooked by the first page, things are unlikely to get better later. -- Greg From usenet-nospam at seebs.net Mon Sep 20 20:41:31 2010 From: usenet-nospam at seebs.net (Seebs) Date: 21 Sep 2010 00:41:31 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-21, Steven D'Aprano wrote: > On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: >> Not necessarily. Some of us have the impression that Guido deliberatly >> chose an ugly format for the ternary operator. > If he did, then he must have changed his mind, because there is nothing > ugly about the ternary operator we ended up with. Empirically, looking at the commentary on the PEP, there is something about it which a large number of participants found awkward or dislikeable. I'm not sure I'd say "ugly", but I would say that the net result is that it is likely more error-prone than an arrangement which put the conditions and clauses in the order they're in for other conditionals. > It astounds me how the Python community changed it's collective mind from > admiration of the elegance and simplicity of the expression when it was a > buggy hack, to despising it when it became a bug-free language feature. > Go figure. Well, if I had to point at an explanation, I'd guess it's the inversion. That, and things of the general form "x or y" are found in several other scripting languages, so it's a more familiar idiom. But I suspect some of it is just that, well, a number of people as of the original PEP discussion on the conditional operator disliked the "new" proposal of "x if y else z", and if they still dislike it, they'll find the conditional operator unpleasant even if it's bug-free. This may come as a total shock, but in modern scripting languages, people are often substantially concerned with style, not just with whether or not something works. :) I would probably tend to avoid the Python conditional as it currently exists because I know that a fair number of people will find it mildly confusing. Not that they won't be able to parse it, but... It's like phrasing tests negatively. It adds one chunk to the cognitive load of reading something. It increases the likelihood of the user making mistakes -- and no amount of polish and debugging of the engine can prevent users from making mistakes. The implementation in the language engine may be bug-free, but I'd be less optimistic about code which used the construct. -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 john at castleamber.com Mon Sep 20 21:03:58 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 20:03:58 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <8fnk3qFk0bU1@mid.individual.net> <87vd6116xa.fsf@castleamber.com> <4C96DD24.3020400@gmail.com> Message-ID: <87eicnx5z5.fsf@castleamber.com> Terry Reedy writes: >> On 09/19/2010 10:32 PM, John Bokma wrote: > >>> the spoiler. Do you fast forward movies as well? > > I sometimes watch movies (or parts thereof) on 1.5x, especially if it > has a lot of 'filler' scenes. But only when my wife is not watching, > as she hates it. Heh, my question was somewhat rhetorical. I watch movies to slow myself down, so 1.5x is not an option. Same reason I read books slow (well, at a normal pace). If I don't I end up not being able to sleep and things go downhill from there. Also, I notice that if I want to run everything on 1.5x (or more) that I become quite annoying to the rest of my family and I want to enjoy them now, when I can. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From ckaynor at zindagigames.com Mon Sep 20 21:06:34 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 20 Sep 2010 18:06:34 -0700 Subject: Combinations or Permutations In-Reply-To: <4C97EC61.2030005@ieee.org> References: <4C97EC61.2030005@ieee.org> Message-ID: One of the advantages of using itertools is that it is written in C rather than Python (at least for CPython) and thus should run significantly faster than a pure Python implementation. Chris On Mon, Sep 20, 2010 at 4:21 PM, Dave Angel wrote: > On 2:59 PM, Seth Leija wrote: > >> I need to know how to generate a list of combinations/permutations >> (can't remember which it is). Say I have a list of variables: >> >> [a,b,c,d,...,x,y,z] >> >> I am curious if there is an optimized way to generate this: >> >> [[a,b],[a,c],[a,d],...,[x,z],[y,z]] >> >> I currently have an iteration that does this: >> >> #list.py >> >> from math import * >> >> list1=['a','b','c','d','e'] >> list2=[] >> length=len(list1) >> >> for it1 in range(0 ,length): >> for it2 in range(it1+1, length): >> list2.append([list1[it1],list1[it2]]) >> >> print list2 >> >> However, this is one of the slowest parts of my function (beaten only >> by variable instantiation). I posted this on another forum looking to >> see if there was a different method completely. They said that my >> method was about as simple as it could get, but I might be able to >> find out how to optimize my code here. >> >> Thanks in advance. >> >> You're apparently looking for combinations. You're asking for all the > combinations of items from the original list, taken two at a time. > > Permutations would also include the reverse of each item, so it would be > exactly twice the size. > > For the specific case of two, your approach is about as simple as it can > get. However, generalizing the code to handle 'r' at a time is pretty > tricky. There's a library function for it in Python 2.6 and later, as > mentioned by others, and the docs show a sample implementation. > > Clearly making a single function call is optimized in one sense. However, > if you're looking for speed, chances are you could improve on your own > function by changing the two loops. (tested in python 2.6) > > Consider: > > > list1=['a','b','c','d','e'] > list2=[] > > for it1, val1 in enumerate(list1): > for val2 in list1[it1+1:]: > list2.append([val1, val2]) > > print list2 > > > DaveA > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Sep 20 21:12:01 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 20:12:01 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> Message-ID: <87aanbx5lq.fsf@castleamber.com> Steven D'Aprano writes: > On Mon, 20 Sep 2010 17:25:09 +0000, Tim Harig wrote: > >>> And as a datapoint on the topic of archiving, I search usenet archives >>> regularly when faced with a problem. >> >> Usernet users also have the right to use the X-No-Archive header field. > > They do? Is that right enshrined by law somewhere? Can I go to jail for > human rights abuses if I archive X-No-Archive posts? I think they do have the right to use it as you have the right to ignore it ;-) I never saw the point of the whole X-No-Archive: Yes thing. What happens if I quote such a message? It's archived, right? -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From wuwei23 at gmail.com Mon Sep 20 21:30:41 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 20 Sep 2010 18:30:41 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <4c970e7f$0$21775$426a74cc@news.free.fr> Message-ID: <65e3f364-3b47-407e-a0d4-326c5a3b2f6b@k17g2000prf.googlegroups.com> Bruno Desthuilliers wrote: > alex23 a ?crit : > > Python only actually executes a module the first time it's imported, > > Beware of multithreading and modules imported under different names... > There can be issues with both in some web frameowrks. Good points, Bruno, thank you. Niklasro, a good example of Bruno's second point: running a module as a script and then importing it elsewhere later will execute the module in the second import, creating two module objects - '__main__' and ''. The issue with threading is the more important one of which to be aware. From nandytemp at gmail.com Mon Sep 20 21:36:12 2010 From: nandytemp at gmail.com (Nandy) Date: Mon, 20 Sep 2010 18:36:12 -0700 (PDT) Subject: Executing wctp script in python 2.7 for windows. Message-ID: Ok, it could be that im exhausted but I cant figure out how to execute this script in python2.7 for windows. The short: I got the file from here: http://sourceforge.net/projects/wctpxml-python/files/ and I want to execute it to send a text to my att pager using wctp via port 80. I have a commercial application that does just that but it is on demo mode and once the demo expires im not using it anymore. Any help will be greatly appreciated. The long: I have a need to get a page every time I get a notice from a system. I have work on this application and it is working great using a commercial application that uses wctp to send messages to my pager taking the unit number and the message via a command line. It goes like wctp.bat 1231234567 "you are needed". I cant use snpp or email as those ports are close but wctp is wide open. I do a bit of tcl but I have not found a viable script for this. I have only found scripts in perl and python so im going for python and if I can get this to work maybe I will have to start writing my little projects on python. So for now all I need is to learn how to execute the above script on my windows xp os, then I will edit what I need to make it work for my pager. After that is done I will try to convert that script to a windows execute so I can use it in other pc's. Last stop will be to do some html parsing to get some information off the notification. But that is at the end, for now I will be happy if someone can help me with getting the script to work and send the page... Thanks, many thanks!!!! From lie.1296 at gmail.com Mon Sep 20 21:41:42 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 21 Sep 2010 11:41:42 +1000 Subject: Too much code - slicing In-Reply-To: References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c980cdb$1@dnews.tpgi.com.au> On 09/19/10 17:31, Seebs wrote: > Basically, think of what happens as I read each symbol: > > x = x + 1 if condition else x - 1 > > Up through the '1', I have a perfectly ordinary assignment of a value. > The, suddenly, it retroactively turns out that I have misunderstood > everything I've been reading. I am actually reading a conditional, and > the things I've been seeing which looked like they were definitely > part of the flow of evaluation may in fact be completely skipped. Seems like you've got a much more complicated parser than I do. You can read code from top-down, bottom-left; doing that would require keeping a mental stack of the contexts of code all the time; that's something I can't do. What I normally do when reading code is to first scan the overall structure first, then zoom in to the interesting parts until I get to an atomic structure (something I can understand in a quick glance). I'd then agglutinate some of the atoms into bigger chunks that I don't read in detail anymore. Reading code left-right is too difficult for me since then, you'd have to keep a stack that tracks how many logical parentheses (i.e. how deep in the code structure) you've seen and their types. From python.list at tim.thechases.com Mon Sep 20 21:52:24 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 20 Sep 2010 20:52:24 -0500 Subject: Down with tinyurl! In-Reply-To: <87aanbx5lq.fsf@castleamber.com> References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <4C980FD8.7070804@tim.thechases.com> On 09/20/10 20:12, John Bokma wrote: > Steven D'Aprano writes: >> On Mon, 20 Sep 2010 17:25:09 +0000, Tim Harig wrote: >>> Usernet users also have the right to use the X-No-Archive header field. >> >> They do? Is that right enshrined by law somewhere? Can I go to jail for >> human rights abuses if I archive X-No-Archive posts? > > I think they do have the right to use it as you have the right to ignore > it ;-) > > I never saw the point of the whole X-No-Archive: Yes thing. What happens > if I quote such a message? It's archived, right? The point? It's much shorter than "X-Stick-your-fingers-in-your-ears-close-your-eyes-and-yell-la-la-la-ignorantly-hoping-people-will-delete-this-message-after-some-arbitrary-period-of-time: Yes". -tkc From lie.1296 at gmail.com Mon Sep 20 21:55:23 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 21 Sep 2010 11:55:23 +1000 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: <4c98100d$1@dnews.tpgi.com.au> On 09/20/10 19:59, Tim Harig wrote: > On 2010-09-20, Steven D'Aprano wrote: >> On Mon, 20 Sep 2010 05:46:38 +0000, Tim Harig wrote: >> >>>> I'm not particularly convinced that these are *significant* complaints >>>> about URL-shorteners. But I will say, of the last couple hundred links >>>> I've followed from Usenet posts, precisely zero of them were through >>>> URL redirectors. If I can't at least look at the URL to get some >>>> initial impression of what it's a link to, I'm not going to the trouble >>>> of swapping to a web browser to find out. >>> >>> But why should the rest of us be penalized because you make the choice >>> not to use (or not take full advantage of) all of the tools that are >>> available to you? >> >> I'm with Aahz... best practice is to post both the full and shortened >> URL, unless the URL is less that 78 characters, in which case just post >> the full version. > > Posting two URLs rather defeats the purpose of using a URL shortening > service in the first place; but, if that is what you feel is effective, > then by all means, do so. You are the master of your posts and you have > the right to post them using whatever methods and formating that you > feel is most effect; but, other people should have the same priviledge. > > Many people find tinyurl and kin to be useful tools. If you do not, > then are free to rewrite them in your reader, ignore posts using these > services, or even add a rule blocking them to your score/kill file so > that you do not have to view their ugliness. IMO, url-shortener are most (only?) useful in presentations or printed materials. When you instead have a full-fledged computer, using which you can just click on the link or copy paste; they're unnecessary and counter-productive. From debatem1 at gmail.com Mon Sep 20 22:35:03 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 20 Sep 2010 19:35:03 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: <4c98100d$1@dnews.tpgi.com.au> References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On Mon, Sep 20, 2010 at 6:55 PM, Lie Ryan wrote: > On 09/20/10 19:59, Tim Harig wrote: >> On 2010-09-20, Steven D'Aprano wrote: >>> On Mon, 20 Sep 2010 05:46:38 +0000, Tim Harig wrote: >>> >>>>> I'm not particularly convinced that these are *significant* complaints >>>>> about URL-shorteners. ?But I will say, of the last couple hundred links >>>>> I've followed from Usenet posts, precisely zero of them were through >>>>> URL redirectors. ?If I can't at least look at the URL to get some >>>>> initial impression of what it's a link to, I'm not going to the trouble >>>>> of swapping to a web browser to find out. >>>> >>>> But why should the rest of us be penalized because you make the choice >>>> not to use (or not take full advantage of) all of the tools that are >>>> available to you? >>> >>> I'm with Aahz... best practice is to post both the full and shortened >>> URL, unless the URL is less that 78 characters, in which case just post >>> the full version. >> >> Posting two URLs rather defeats the purpose of using a URL shortening >> service in the first place; but, if that is what you feel is effective, >> then by all means, do so. ?You are the master of your posts and you have >> the right to post them using whatever methods and formating that you >> feel is most effect; but, other people should have the same priviledge. >> >> Many people find tinyurl and kin to be useful tools. ?If you do not, >> then are free to rewrite them in your reader, ignore posts using these >> services, or even add a rule blocking them to your score/kill file so >> that you do not have to view their ugliness. > > IMO, url-shortener are most (only?) useful in presentations or printed > materials. When you instead have a full-fledged computer, using which > you can just click on the link or copy paste; they're unnecessary and > counter-productive. I use them when I want to conceal the target of the link. Usually here that just means its a letmegooglethatforyou.com link, which I find more amusing than is probably healthy. Geremy Condra From ethan at stoneleaf.us Mon Sep 20 22:39:21 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 20 Sep 2010 19:39:21 -0700 Subject: os.path.normcase rationale? In-Reply-To: <4c97f629$0$28658$c3e8da3@news.astraweb.com> References: <87lj727lu7.fsf@benfinney.id.au> <4c97f629$0$28658$c3e8da3@news.astraweb.com> Message-ID: <4C981AD9.3060102@stoneleaf.us> Steven D'Aprano wrote: > On Mon, 20 Sep 2010 19:45:37 +0100, Chris Withers wrote: > > >>Well, no, that doesn't feel right. Normalisation of case, for me, means >>"give me the case as the filesystem thinks it should be", > > > What do you mean "the filesystem"? Well, if it were me, it would be either the filesystem in the path that's being norm'ed, or if no path is explicity stated, the filesystem that is hosting the current directory. > If I look at the available devices on my system now, I see: > > 2 x FAT-32 filesystems > 1 x ext2 filesystem > 3 x ext3 filesystems > 1 x NTFS filesystem > 1 x UDF filesystem > > and if I ever get my act together to install Basilisk II, as I've been > threatening to do for the last five years, there will also be at least > one 1 x HFS filesystem. Which one is "the" filesystem? > > If you are suggesting that os.path.normcase(filename) should determine > which filesystem actually applies to filename at runtime, and hence work > out what rules apply, what do you suggest should happen if the given path > doesn't actually exist? What if it's a filesystem that the normpath > developers haven't seen or considered before? Something along those lines seems to be happening now. Observe what happens on my XP machine with an NTFS drive. --> import foo Traceback (most recent call last): File "", line 1, in ImportError: No module named foo --> import FOO Traceback (most recent call last): File "", line 1, in ImportError: No module named FOO --> import fOo Traceback (most recent call last): File "", line 1, in ImportError: No module named fOo --> import Foo Foo has been imported! ~Ethan~ From ldo at geek-central.gen.new_zealand Mon Sep 20 22:55:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 14:55:49 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: In message , geremy condra wrote: > Usually here that just means its a letmegooglethatforyou.com link, which I > find more amusing than is probably healthy. Why hold back, I also use fuckinggoogleit.com. :) From john at castleamber.com Mon Sep 20 23:00:27 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 22:00:27 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <87r5gn3ino.fsf@castleamber.com> Tim Chase writes: > On 09/20/10 20:12, John Bokma wrote: >> Steven D'Aprano writes: >>> On Mon, 20 Sep 2010 17:25:09 +0000, Tim Harig wrote: >>>> Usernet users also have the right to use the X-No-Archive header field. >>> >>> They do? Is that right enshrined by law somewhere? Can I go to jail for >>> human rights abuses if I archive X-No-Archive posts? >> >> I think they do have the right to use it as you have the right to ignore >> it ;-) >> >> I never saw the point of the whole X-No-Archive: Yes thing. What happens >> if I quote such a message? It's archived, right? > > The point? It's much shorter than > "X-Stick-your-fingers-in-your-ears-close-your-eyes-and-yell-la-la-la-ignorantly-hoping-people-will-delete-this-message-after-some-arbitrary-period-of-time: > Yes". Well, X-Archive: No is even shorter ;-). What I mean is, it's just a request, nothing more and nothing less. DejaNews honored it, and Google still does. But it doesn't stop other people from archiving posts. I can imagine that for some automatic generated messages someone might think XNA is a good thing. But for human written messages, I just don't see the point. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From usenet-nospam at seebs.net Mon Sep 20 23:01:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 21 Sep 2010 03:01:53 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On 2010-09-21, geremy condra wrote: > I use them when I want to conceal the target of the link. Usually here > that just means its a letmegooglethatforyou.com link, which I find > more amusing than is probably healthy. I thought the idea was funny at first. Then I posted a question on an IRC channel. I had done a ton of searching already, and I started by explaining the top three near-solutions I'd found and why each of them wasn't actually a solution to my problem. And someone handed me a URL... which was to lmgtfy on the first search terms I tried. And this caused me to realize just how amazingly insulting that can be when done to someone who *did* already do the research. While certainly there's plenty of people who didn't do their own searching, there's also a fair number who are asking a question because they DID try searching and there was some problem with one or more of the answers. -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 jerry.fleming at saybot.com Mon Sep 20 23:21:55 2010 From: jerry.fleming at saybot.com (Jerry Fleming) Date: Tue, 21 Sep 2010 11:21:55 +0800 Subject: re and locale/unicode Message-ID: Hi, Having the following python code: import locale import re locale.setlocale(locale.LC_ALL, 'zh_CN.utf8') re.findall('(?uL)\s+', u'\u2001\u3000\x20', re.U|re.L) re.findall('\s+', u'\u2001\u3000\x20', re.U|re.L) re.findall('(?uL)\s+', u'\u2001\u3000\x20') I was wondering why doesn't it find the unicode space chars \u2001 and \u3000? The python docs for re module says: When the LOCALE and UNICODE flags are not specified, matches any whitespace character; this is equivalent to the set [ \t\n\r\f\v]. With LOCALE, it will match this set plus whatever characters are defined as space for the current locale. If UNICODE is set, this will match the characters [ \t\n\r\f\v] plus whatever is classified as space in the Unicode character properties database. which doesn't seem to work. Any ideas? From john at castleamber.com Mon Sep 20 23:25:18 2010 From: john at castleamber.com (John Bokma) Date: Mon, 20 Sep 2010 22:25:18 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: <87mxrb3hi9.fsf@castleamber.com> Seebs writes: > And this caused me to realize just how amazingly insulting that can be when > done to someone who *did* already do the research. Exactly. I hate lmgtfy links hidden in a tiny url. It's not only insulting to the OP but also to people who try to learn something and end up on a google search page they could've come up with themselves. > While certainly there's plenty of people who didn't do their own searching, > there's also a fair number who are asking a question because they DID try > searching and there was some problem with one or more of the answers. Yup, exactly. Or people who did a lot of searching but somehow were not able to compile a good query. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From debatem1 at gmail.com Mon Sep 20 23:26:18 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 20 Sep 2010 20:26:18 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On Mon, Sep 20, 2010 at 7:55 PM, Lawrence D'Oliveiro wrote: > In message , geremy > condra wrote: > >> Usually here that just means its a letmegooglethatforyou.com link, which I >> find more amusing than is probably healthy. > > Why hold back, I also use fuckinggoogleit.com. :) Yeah, I need to start using that- a shocking number of people don't seem to realize that lmgtfy is a joke. I had a person a few months ago seriously thank me for giving them a link that did the typing for them. Light a man a fire and he'll be warm for an hour, light a man *on* fire and he'll be warm for the rest of his life... Geremy Condra From debatem1 at gmail.com Mon Sep 20 23:55:57 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 20 Sep 2010 20:55:57 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On Mon, Sep 20, 2010 at 8:01 PM, Seebs wrote: > On 2010-09-21, geremy condra wrote: >> I use them when I want to conceal the target of the link. Usually here >> that just means its a letmegooglethatforyou.com link, which I find >> more amusing than is probably healthy. > > I thought the idea was funny at first. > > Then I posted a question on an IRC channel. ?I had done a ton of searching > already, and I started by explaining the top three near-solutions I'd found > and why each of them wasn't actually a solution to my problem. ?And someone > handed me a URL... which was to lmgtfy on the first search terms I tried. > > And this caused me to realize just how amazingly insulting that can be when > done to someone who *did* already do the research. > > While certainly there's plenty of people who didn't do their own searching, > there's also a fair number who are asking a question because they DID try > searching and there was some problem with one or more of the answers. It's a joke. Admittedly it's a bit pointed, but it's a joke nonetheless, and it does at least provide what I consider to be two valuable pieces of information: that you should have googled this before asking, and what you should have googled for. If I miss and you've done your homework already, well, at least you get the smug satisfaction of knowing that I was too stupid to understand your question. Geremy Condra From python at mrabarnett.plus.com Mon Sep 20 23:57:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 21 Sep 2010 04:57:21 +0100 Subject: re and locale/unicode In-Reply-To: References: Message-ID: <4C982D21.2070406@mrabarnett.plus.com> On 21/09/2010 04:21, Jerry Fleming wrote: > Hi, > > Having the following python code: > > > import locale > import re > > locale.setlocale(locale.LC_ALL, 'zh_CN.utf8') > re.findall('(?uL)\s+', u'\u2001\u3000\x20', re.U|re.L) > re.findall('\s+', u'\u2001\u3000\x20', re.U|re.L) > re.findall('(?uL)\s+', u'\u2001\u3000\x20') > > > I was wondering why doesn't it find the unicode space chars \u2001 and > \u3000? The python docs for re module says: > > When the LOCALE and UNICODE flags are not specified, matches any > whitespace character; this is equivalent to the set [ \t\n\r\f\v]. With > LOCALE, it will match this set plus whatever characters are defined as > space for the current locale. If UNICODE is set, this will match the > characters [ \t\n\r\f\v] plus whatever is classified as space in the > Unicode character properties database. > > which doesn't seem to work. Any ideas? Use the regex module? ;-) http://pypi.python.org/pypi/regex BTW, LOCALE is for locale-specific bytestrings. Basically the choice is between ASCII (bytestring) (default in Python 2), LOCALE (bytestring) and UNICODE (Unicode string), so don't bother combining them. From steve-REMOVE-THIS at cybersource.com.au Tue Sep 21 01:01:45 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 05:01:45 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: <4c983c38$0$11089$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 03:01:53 +0000, Seebs wrote: > On 2010-09-21, geremy condra wrote: >> I use them when I want to conceal the target of the link. Usually here >> that just means its a letmegooglethatforyou.com link, which I find more >> amusing than is probably healthy. > > I thought the idea was funny at first. > > Then I posted a question on an IRC channel. I had done a ton of > searching already, and I started by explaining the top three > near-solutions I'd found and why each of them wasn't actually a solution > to my problem. And someone handed me a URL... which was to lmgtfy on > the first search terms I tried. Yeah, some people are just self-righteous dicks. Hey, that would be an *awesome* google bombing project... to get lmgtfy to come up as the first link for "self-righteous dicks". 4chan, where are you when we need you??? > And this caused me to realize just how amazingly insulting that can be > when done to someone who *did* already do the research. Yes, although in fairness people aren't mind readers. If you (generic you) don't give any indication of doing the research, you can expect to be ignored or told to RTFM. Google is just the new FM. Personally, I found LMGTFY to be amusing for about 1.3 microseconds, followed by annoying. The joke also falls flat when you send somebody there, and they have Javascript turned off. I prefer the old fashioned version: "Google Is Your Friend" followed by a URL to the appropriate google's search results page. Or even more to the point: "Did you bother to google for the answer first? Because the very first page that comes up gives exactly the answer you want." Although sometimes people genuinely don't know what search terms they should be using, or if they're too generic. -- Steven From usenet-nospam at seebs.net Tue Sep 21 01:11:37 2010 From: usenet-nospam at seebs.net (Seebs) Date: 21 Sep 2010 05:11:37 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-21, Steven D'Aprano wrote: > On Tue, 21 Sep 2010 03:01:53 +0000, Seebs wrote: >> On 2010-09-21, geremy condra wrote: >> Then I posted a question on an IRC channel. I had done a ton of >> searching already, and I started by explaining the top three >> near-solutions I'd found and why each of them wasn't actually a solution >> to my problem. And someone handed me a URL... which was to lmgtfy on >> the first search terms I tried. > Yes, although in fairness people aren't mind readers. If you (generic > you) don't give any indication of doing the research, you can expect to > be ignored or told to RTFM. Google is just the new FM. See above -- "I started by explaining..." > Although sometimes people genuinely don't know what search terms they > should be using, or if they're too generic. Yes. A few of my friends periodically ask me to search for something because somehow my pick of search terms tends to work better than theirs. We're not actually sure why. -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-REMOVE-THIS at cybersource.com.au Tue Sep 21 01:43:09 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 21 Sep 2010 05:43:09 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: <4c9845ed$0$11089$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 05:11:37 +0000, Seebs wrote: > On 2010-09-21, Steven D'Aprano > wrote: >> On Tue, 21 Sep 2010 03:01:53 +0000, Seebs wrote: >>> On 2010-09-21, geremy condra wrote: Then I posted >>> a question on an IRC channel. I had done a ton of searching already, >>> and I started by explaining the top three near-solutions I'd found and >>> why each of them wasn't actually a solution to my problem. And >>> someone handed me a URL... which was to lmgtfy on the first search >>> terms I tried. > >> Yes, although in fairness people aren't mind readers. If you (generic >> you) don't give any indication of doing the research, you can expect to >> be ignored or told to RTFM. Google is just the new FM. > > See above -- "I started by explaining..." Yes, I know that. I sympathized with your experience and explicitly said I was talking about "generic you". -- Steven From usenet-nospam at seebs.net Tue Sep 21 01:49:03 2010 From: usenet-nospam at seebs.net (Seebs) Date: 21 Sep 2010 05:49:03 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> <4c9845ed$0$11089$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-21, Steven D'Aprano wrote: > Yes, I know that. I sympathized with your experience and explicitly said > I was talking about "generic you". Hah! Then it was *I* who wasn't reading carefully enough! I bet you didn't expect *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 alf.p.steinbach+usenet at gmail.com Tue Sep 21 02:19:48 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 21 Sep 2010 08:19:48 +0200 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: * Alf P. Steinbach /Usenet, on 21.09.2010 01:09: > * Astley Le Jasper, on 20.09.2010 23:42: >> I have a list of tuples that indicate a relationship, ie a is related >> to b, b is related to c etc etc. What I want to do is cluster these >> relationships into groups. An item will only be associated with a >> single cluster. >> >> Before I started, I wondered if there was any particular tool within >> Python I should be looking at. I don't expect anyone to code this for >> me, just say ... "you need to look at using x". I was going to use >> populate a dictionary and >> >> Sorry for being so vague. >> >> Example Data: >> [(a,b) >> (a,c) >> (a,d) >> (b,c) >> (b,d) >> (c,d) >> (e,f) >> (e,g) >> (f,g) >> (h,i)] >> >> Output (grouping id, item ref) >> (1,a), >> (1,b), >> (1,c), >> (1,d), >> (2,e), >> (2,f), >> (2,g), >> (3,h), >> (3,i) > > It seems to be the same problem as "equivalence sets". > > This problem was solved early on because e.g. Fortran compilers had to construct > such sets (equivalence partitions of a set). > > I though I'd just say "Google it!", because I know there's a standard algorithm > but I can't recall the name. However, googling it I found no mention of that > algorithm. Not even in the Wikipedia articles on equivalence sets. > > A number of approaches spring to mind: > > Approach 1: > Multi-pass. Originally you assign a distinct set number to each symbol. > In each pass through the symbols you replace one number with another as > per one of the equivalence specs. Stop when no replacements are done. > > Approach 2: > Merging. For each new equivalence A=B you check whether A has been assigned > to a set, if not you create a new one, call that S1, and ditto for B, S2. > Merge S1 and S2, e.g. move all elements of S2 to S1. > > Approach 3: > In a first pass convert the data to more explicit form, linking each symbol > to the symbols it's directly equivalent to. Then in second pass simply drag > out each equivalence group (recurse on each symbol's list of equivalences). > > Approaches 1 and 2 seem to be pretty inefficient for a large number of symbols, > but I think approach 1 may be a practical option for a small number of symbols. Uhm, thinking about it (it must have been my unconscious mind doing the work, it just popped into my head), if you first sort each individual equivalence relation so that you never have e.g. C=A but only A=C and so on, and then sort the list of equivalences, then it should reduce to walking the list and just starting a new set whenever a symbol is encountered that isn't yet in a set. class Attributes: pass sym = Attributes() for name in ("a", "b", "c", "d", "e", "f", "g", "h", "i"): setattr( sym, name, name ) eq_specs = [ (sym.a, sym.d), (sym.b, sym.a), (sym.b, sym.c), (sym.b, sym.d), (sym.c, sym.d), (sym.c, sym.a), (sym.e, sym.f), (sym.e, sym.g), (sym.f, sym.g), (sym.h, sym.i), ] equalities = [] for eq in eq_specs: sorted_eq = eq if eq[0] <= eq[1] else (eq[1], eq[0]) equalities.append( sorted_eq ) equalities.sort() eq_sets = {} eq_set_ids = {} current_eq_set_id = 0 for eq in equalities: if eq_set_ids.get( eq[0] ) is None: current_eq_set_id += 1 eq_set_ids[eq[0]] = current_eq_set_id eq_sets[current_eq_set_id] = set( eq[0] ) eq_set_id = eq_set_ids[eq[0]] eq_set_ids[eq[1]] = eq_set_id eq_sets[eq_set_id].add( eq[1] ) for eq_set_id in eq_sets.keys(): for sym_name in eq_sets[eq_set_id]: print( "{}, {}".format( eq_set_id, sym_name ) ) 1, a 1, c 1, b 1, d 2, e 2, g 2, f 3, i 3, h Disclaimer: for me it's pretty late in day/night. Cheers & hth., - Alf -- blog at From ian.g.kelly at gmail.com Tue Sep 21 02:49:48 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Sep 2010 00:49:48 -0600 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: On Tue, Sep 21, 2010 at 12:19 AM, Alf P. Steinbach /Usenet < alf.p.steinbach+usenet at gmail.com >wrote: > Uhm, thinking about it (it must have been my unconscious mind doing the > work, it just popped into my head), if you first sort each individual > equivalence relation so that you never have e.g. C=A but only A=C and so on, > and then sort the list of equivalences, then it should reduce to walking the > list and just starting a new set whenever a symbol is encountered that isn't > yet in a set. > This won't work for all inputs. Consider the input: [('a', 'd'), ('b', 'c'), ('c', 'd')] Expected Output: 1, a 1, b 1, c 1, d Actual Output: 1, a 1, d 2, c 2, b 2, d Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Sep 21 03:01:07 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 21 Sep 2010 00:01:07 -0700 (PDT) Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: On Sep 20, 12:25?pm, Tim Harig wrote: > On 2010-09-20, Brian Victor wrote: > Usernet users also have the right to use the X-No-Archive header field. > Does the fact that *you* happen to search usenet archives make using this > field immoral? ?Shouldn't the poster have to right to determine for > themselves whether they care about the long term persistance of their posts > and be able to balance that against other factors? X No Archive should have never been allowed and should be removed immediately and forever. What is the point of posting when your words will be gone form memory in a short time? Why not save your fingers an painful and early demise and go watch wheel of fortune instead? Heck, i can't tell you how much enjoyment i get from reading over some of my old posts. Actually i think i get more enjoyment reading over them then when creating them. Besides, when people X-No_Archive it makes me a bit suspicious of their true intentions. Are they just trolling or maybe blowing hot air from an alter ego? Or, are they paranoid nitwits with twenty-two bolt locks on their front door who sleep with wads of cotton balls crammed in their ear canals for fear of carnivorous ear wigs? Do they carefully craft tin foil hats in agonizing 3d detail using solid works to maximize the defecting efficiency of each and every facet in an effort to ward off the ever present mind altering signals emanating from cell phone towers in an overly ambitious attempt to rebel against the interplanetary borg-ish assimilation's ever increasing empirical expansion? 8-O ...Or, who knows, maybe they just shy? From rantingrick at gmail.com Tue Sep 21 03:12:48 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 21 Sep 2010 00:12:48 -0700 (PDT) Subject: Customising Tk widgets References: <805f1248-9217-4688-9731-4a1868cf06c3@x20g2000pro.googlegroups.com> Message-ID: <8716f5a1-b5b5-4c34-9962-94bd49e97ef7@w4g2000vbh.googlegroups.com> On Sep 20, 6:44?pm, Peter wrote: > I am using Windoze, I suspect the appearance attributes I am asking > about here are platform dependent? not really. > Using Tkinter, I would like to generate a Checkbutton that is filled > in with a solid colour rather than a tick mark when selected. Why, who cares if it's a check or solid box. > Could somebody provide some pointers as to how I could achieve this? Ok, Ok, if you *really* need to see this just create a custom widget using either the canvas or a couple of Label widgets. (psst: i would use the canvas) For extra credit you could create a custom "ChoiceBox" widget. Which is a scrollable box containing an unlimited number of check buttons. > Also, John Shipman's Tkinter reference shows the Radiobutton drawn as > a diamond and yet when I create one in Windows I get a circle - again, > how and where do I need to look to change this behaviour? Hmm, me thinks John ist using Linistz, at least me thinks? From duncan.booth at invalid.invalid Tue Sep 21 03:37:33 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Sep 2010 07:37:33 GMT Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> <4c975046$0$11113$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Mon, 20 Sep 2010 11:53:48 +0000, Duncan Booth wrote: > >> I was going to suggest overriding items() (or iteritems() for Python >> 2.x), but while that is another hole that your values leak out it isn't >> the hole used by the dict constructor. > > Yes, I already override items(), keys(), values(), their iter... > versions, and just about every damn method that dicts have :/ > > I suspect that the dict() constructor is just grabbing the key/value > pairs directly from the underlying hash table. If that's the case, my > choices are to not inherit from dict at all, or take your suggestion and > keep an auxiliary dict alongside the main one. > >From Python 2.x sources that I have lying around (sorry I have no idea if the code for 3.x has changed much): dict_init calls dict_update_common which does: if (PyObject_HasAttrString(arg, "keys")) result = PyDict_Merge(self, arg, 1); else result = PyDict_MergeFromSeq2(self, arg, 1); PyDict_Merge says: /* We accept for the argument either a concrete dictionary object, * or an abstract "mapping" object. For the former, we can do * things quite efficiently. For the latter, we only require that * PyMapping_Keys() and PyObject_GetItem() be supported. */ which basically boils down to "if PyDict_Check() is true then iterate directly over the structure and use the existing key, hash and value fields to insert into the new dict". If PyDict_Check() is false then it iterates over the keys and calls PyObject_GetItem(). -- Duncan Booth http://kupuguy.blogspot.com From rantingrick at gmail.com Tue Sep 21 03:37:58 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 21 Sep 2010 00:37:58 -0700 (PDT) Subject: Syntax highlighting [was Re: Too much code - slicing] References: <20100917160154.570ce164@geekmail.INVALID> <4c941b03$0$28657$c3e8da3@news.astraweb.com> <4c959edc$0$11113$c3e8da3@news.astraweb.com> <4c96ff65$0$11113$c3e8da3@news.astraweb.com> Message-ID: <74717128-54ef-4de3-a18e-f7e921a2aa97@q26g2000vbn.googlegroups.com> On Sep 20, 1:29?am, Steven D'Aprano wrote: > To my eyes, the feature of syntax highlighting that alone makes it > worthwhile, its killer feature, is that I can set comments and docstrings > to grey. When I'm scanning code, being able to slide my eyes over greyed- > out comments and docstrings and ignore them with essentially zero effort > is a huge help. That's the thing I most miss, more than anything else, > when using a dumb editor. Well dumb editors use syntax highlighting also... specifically the ones that default to bright (attention grabbing!) colors for comments and/or docstrings... like the color RED! Gawd i hate that! Never should a comment be a bright color, and RED is the worst choice of all! Grey for comments, orange for keywords, purple for builtins, and green for strings is pure bliss. Save red for scary things like global variables and such. That way you know where the hemorrhaging is coming from! From duncan.booth at invalid.invalid Tue Sep 21 04:17:00 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Sep 2010 08:17:00 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > That's sheer and unadulterated nonsense. The fact is that Guido changed > his mind about ternary if after discovering that the work-around > > true-clause and condition or false-clause > > is buggy -- it gives the wrong answer if true-clause happens to be a > false value like [], 0 or None. If I recall correctly, the bug bit Guido > himself. > > The and-or hack, which was *very* common in Python code for many years > and many versions, follows the same pattern as ternary if: > > true-clause if condition else false-clause > I guess you have worked hard to forget the and-or hack. It was actually: condition and true-clause or false-clause so its not quite the same pattern. Of course there's also the bug fixed version which I suspect was so ugly it was the real trigger for getting a real ternary operator: (condition and [true-clause] or [false-clause])[0] -- Duncan Booth http://kupuguy.blogspot.com From ldo at geek-central.gen.new_zealand Tue Sep 21 04:32:32 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:32:32 +1200 Subject: This Is International =?UTF-8?B?RG9u4oCZdC1TcXVhd2stTGlrZS1BLVBhcnJvdA==?= Day References: Message-ID: Next we need an International Surfin? Bird day, a day to go around and tell everybody that the bird bird bird, the bird is the word. (Yes, *that* FG episode was just on earlier.) From ldo at geek-central.gen.new_zealand Tue Sep 21 04:36:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:36:05 +1200 Subject: develop for Windows on GNU/Linux, using Python References: Message-ID: In message , Kev Dwyer wrote: > To be confident that your code is good you need to test it on a Windows > box (we all test, right?). Preferably more than one. Test with Seven as well as Vista (yes, there are still some Vista users out there). What about the difference between Starter versus Home Basic versus Home Premium versus Professional versus Ultimate versus whatever? To be 100% safe, you probably need to test with all those as well. Test on machines running the various major antivirus packages, because you have no idea how they might screw things up. In other words, with Windows the guideline is: test till it hurts. Then test some more. From arndt.roger at addcom.de Tue Sep 21 04:37:11 2010 From: arndt.roger at addcom.de (Arndt Roger Schneider) Date: Tue, 21 Sep 2010 10:37:11 +0200 Subject: Customising Tk widgets References: <805f1248-9217-4688-9731-4a1868cf06c3@x20g2000pro.googlegroups.com> Message-ID: Peter schrieb: > I am using Windoze, I suspect the appearance attributes I am asking > about here are platform dependent? > > Using Tkinter, I would like to generate a Checkbutton that is filled > in with a solid colour rather than a tick mark when selected. > tk = Tk() tk.option_add("*Checkbutton.inidcatorOn", 0) > Could somebody provide some pointers as to how I could achieve this? > > Also, John Shipman's Tkinter reference shows the Radiobutton drawn as > a diamond and yet when I create one in Windows I get a circle - again, > how and where do I need to look to change this behaviour? > > Thanks > Peter Shipman's screenshots are made under Tk 8.4/X11, featureing the motif look-a-like. Tk 8.4 follows the windows user style guide (windows95) under windows. You could still get the motif look under windows: Tk 8.5 is bundled with a theming engine ttk, this engine uses the built-in theming engine under windows xp and later, but also allows you to supplant this engine. The related ttk theme is called "classic". -roger From ldo at geek-central.gen.new_zealand Tue Sep 21 04:46:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:46:53 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: In message , geremy condra wrote: > ... a shocking number of people don't seem to realize that lmgtfy is a > joke. I had a person a few months ago seriously thank me for giving them a > link that did the typing for them. Tell them to tell all their friends about it. :) From ldo at geek-central.gen.new_zealand Tue Sep 21 04:49:25 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:49:25 +1200 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> <87r5gn3ino.fsf@castleamber.com> Message-ID: In message <87r5gn3ino.fsf at castleamber.com>, John Bokma wrote: > Well, X-Archive: No is even shorter ;-). X-No-Bananas: Yes From ldo at geek-central.gen.new_zealand Tue Sep 21 04:50:33 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:50:33 +1200 Subject: Down with tinyurl! (was Re: importing excel data into a python matrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> Message-ID: In message , rantingrick wrote: > X No Archive should have never been allowed and should be removed > immediately and forever. What is the point of posting when your words > will be gone form memory in a short time? My words are for now. All I think are fleeting thoughts; Tomorrow I am dust. From arnodel at gmail.com Tue Sep 21 04:51:38 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 21 Sep 2010 01:51:38 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: On Sep 20, 10:42?pm, Astley Le Jasper wrote: > I have a list of tuples that indicate a relationship, ie a is related > to b, b is related to c etc etc. What I want to do is cluster these > relationships into groups. ?An item will only be associated with a > single cluster. > > Before I started, I wondered if there was any particular tool within > Python I should be looking at. I don't expect anyone to code this for > me, just say ... "you need to look at using x". I was going to use > populate a dictionary and > > Sorry for being so vague. > > Example Data: > [(a,b) > (a,c) > (a,d) > (b,c) > (b,d) > (c,d) > (e,f) > (e,g) > (f,g) > (h,i)] > > Output (grouping id, item ref) > (1,a), > (1,b), > (1,c), > (1,d), > (2,e), > (2,f), > (2,g), > (3,h), > (3,i) What you are doing is finding the connected components of a graph. There aren't any tools in the standard library to do this. But for example python-graph [1] has a connected_components function. Probably other packages will. If you don't want a dependency, it is not too hard to implement if you think about it. [1] http://code.google.com/p/python-graph/ -- Arnaud From ldo at geek-central.gen.new_zealand Tue Sep 21 04:53:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:53:46 +1200 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: In message , Dennis Lee Bieber wrote: > On Mon, 20 Sep 2010 20:12:01 -0500, John Bokma > declaimed the following in gmane.comp.python.general: > > >> I never saw the point of the whole X-No-Archive: Yes thing. What happens >> if I quote such a message? It's archived, right? > > Compliant clients (like Agent) will echo the X-No-Archive: Yes in > YOUR reply -- so it too will be deleted at some point in time. Words said once, and then Never to be heard again. Fuck posterity! From ldo at geek-central.gen.new_zealand Tue Sep 21 04:54:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 21 Sep 2010 20:54:20 +1200 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: In message <87aanbx5lq.fsf at castleamber.com>, John Bokma wrote: > I never saw the point of the whole X-No-Archive: Yes thing. What happens > if I quote such a message? It's archived, right? Where did they come from? Posting fragments, followed up-- Originals? No more. From bob.aalsma at aalsmacons.nl Tue Sep 21 04:56:27 2010 From: bob.aalsma at aalsmacons.nl (BobAalsma) Date: Tue, 21 Sep 2010 01:56:27 -0700 (PDT) Subject: Newbie: plist & control characters? Message-ID: <9082a271-5f9c-49e4-8f83-3957184e7b92@j2g2000vbo.googlegroups.com> I'm trying to modify a plist file. The modification works properly, but I'm having difficulties in finding the proper way to restore. The file contains HTML strings like "$#226;" and either this gets replaced by "?" (which I don't want) but the programme completes or the program fails when I try to use the data wrapper. I must be doing something wrong, but can't find what (and this includes Google searches). Please help. Failing text: def omkattenAgents(AANGRIJPINGSPUNT, KLANTNAAM_OUT, KLANTNAAM_IN, ZOEKSET1_OUT, ZOEKSET1_IN, ZOEKSET2_OUT, ZOEKSET2_IN): tussentekst = plistlib.Data(plistlib.readPlist(os.path.join(root,bestandsnaam))) tussenblok = tussentekst.data ding = tussenblok['RepresentedObject'] tekststring = ding.get('Name') tekststring_0 = tekststring.replace(KLANTNAAM_OUT,KLANTNAAM_IN) tekststring_1 = tekststring_0.replace(ZOEKSET1_OUT,ZOEKSET1_IN) tekststring_2 = tekststring_1.replace(ZOEKSET2_OUT,ZOEKSET2_IN) tekststring_3 = tekststring_2.replace(ZOEKSET1_OUT_LOWER,ZOEKSET1_IN_LOWER) tekststring_4 = tekststring_3.replace(ZOEKSET2_OUT_LOWER,ZOEKSET2_IN_LOWER) ding['Name'] = tekststring_4 tussenblok['RepresentedObject'] = ding tussentekst.data = tussenblok plistlib.Data(plistlib.writePlist(tussentekst, os.path.join(root,bestandsnaam))) Text in Terminal: File "LeadDevice_klant_nieuw_aanmaken.py", line 66, in omkattenAgents(AANGRIJPINGSPUNT, KLANTNAAM_OUT, KLANTNAAM_IN, ZOEKSET1_OUT, ZOEKSET1_IN, ZOEKSET2_OUT, ZOEKSET2_IN) File "/Volumes/LeadDevice-2/LeadDevice/Programmatuur/Python/ LeadDeviceProductie/LeadDevice_klant_nieuw_naamcorrectie_intern.py", line 162, in omkattenAgents plistlib.Data(plistlib.writePlist(tussentekst, os.path.join(root,bestandsnaam))) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 94, in writePlist writer.writeValue(rootObject) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 254, in writeValue self.writeData(value) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 267, in writeData for line in data.asBase64(maxlinelength).split("\n"): File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 379, in asBase64 return _encodeBase64(self.data, maxlinelength) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/plistlib.py", line 361, in _encodeBase64 chunk = s[i : i + maxbinsize] TypeError: unhashable type The difference between failure and completion with replacing HTML is the statement tussentekst.data = tussenblok (failure) tussentekst = tussenblok (completion with replacing) Regards, Bob From astley.lejasper at gmail.com Tue Sep 21 05:07:59 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Tue, 21 Sep 2010 02:07:59 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: Thanks for the feedback both. I'll have a look at these. One of the frustrating things I find about python is that there are so many modules. There have been times when I've spend ages doing something and then some has said, "Oh yeah, there is a module for that". Anyway. Nearly finished. Cheers ALJ From stef.mientki at gmail.com Tue Sep 21 05:08:27 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 21 Sep 2010 11:08:27 +0200 Subject: utf-8 coding sometimes it works, most of the time it don't work. Message-ID: <4C98760B.8070400@gmail.com> hello, I've a pyjamas application (python to javascript translator), that can be run (as pure python) in MSHTML (IE Com interface) . When running this python application from the command line ( or launched from another Python program), the wrong character encoding (probably windows-1252) is used. When I run this program from PyScripter ( either internal engine or remote engine), MSHTML shows the correct character encoding, perfect! In the main file, and in the major files that constains strings I've added the following 2 lines: # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals >From the Pyjamas and PyScripter group I've no answer untill now. any clues where to look for the problem ? thanks, Stef Mientki From arnodel at gmail.com Tue Sep 21 05:13:06 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 21 Sep 2010 02:13:06 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: <3463624f-405e-483f-9c21-52989d9a874f@k9g2000vbo.googlegroups.com> On Sep 21, 7:19?am, "Alf P. Steinbach /Usenet" wrote: > * Alf P. Steinbach /Usenet, on 21.09.2010 01:09: > > > > > > > * Astley Le Jasper, on 20.09.2010 23:42: > >> I have a list of tuples that indicate a relationship, ie a is related > >> to b, b is related to c etc etc. What I want to do is cluster these > >> relationships into groups. An item will only be associated with a > >> single cluster. > > >> Before I started, I wondered if there was any particular tool within > >> Python I should be looking at. I don't expect anyone to code this for > >> me, just say ... "you need to look at using x". I was going to use > >> populate a dictionary and > > >> Sorry for being so vague. > > >> Example Data: > >> [(a,b) > >> (a,c) > >> (a,d) > >> (b,c) > >> (b,d) > >> (c,d) > >> (e,f) > >> (e,g) > >> (f,g) ? > >> (h,i)] > > >> Output (grouping id, item ref) > >> (1,a), > >> (1,b), > >> (1,c), > >> (1,d), > >> (2,e), > >> (2,f), > >> (2,g), > >> (3,h), > >> (3,i) > > > It seems to be the same problem as "equivalence sets". > > > This problem was solved early on because e.g. Fortran compilers had to construct > > such sets (equivalence partitions of a set). > > > I though I'd just say "Google it!", because I know there's a standard algorithm > > but I can't recall the name. However, googling it I found no mention of that > > algorithm. Not even in the Wikipedia articles on equivalence sets. > > > A number of approaches spring to mind: > > > Approach 1: > > Multi-pass. Originally you assign a distinct set number to each symbol. > > In each pass through the symbols you replace one number with another as > > per one of the equivalence specs. Stop when no replacements are done. > > > Approach 2: > > Merging. For each new equivalence A=B you check whether A has been assigned > > to a set, if not you create a new one, call that S1, and ditto for B, S2. > > Merge S1 and S2, e.g. move all elements of S2 to S1. > > > Approach 3: > > In a first pass convert the data to more explicit form, linking each symbol > > to the symbols it's directly equivalent to. Then in second pass simply drag > > out each equivalence group (recurse on each symbol's list of equivalences). > > > Approaches 1 and 2 seem to be pretty inefficient for a large number of symbols, > > but I think approach 1 may be a practical option for a small number of symbols. > > Uhm, thinking about it (it must have been my unconscious mind doing the work, it > just popped into my head), if you first sort each individual equivalence > relation so that you never have e.g. C=A but only A=C and so on, and then sort > the list of equivalences, then it should reduce to walking the list and just > starting a new set whenever a symbol is encountered that isn't yet in a set. > > > class Attributes: pass > > sym = Attributes() > for name in ("a", "b", "c", "d", "e", "f", "g", "h", "i"): > ? ? ?setattr( sym, name, name ) > > eq_specs = [ > ? ? ?(sym.a, sym.d), > ? ? ?(sym.b, sym.a), > ? ? ?(sym.b, sym.c), > ? ? ?(sym.b, sym.d), > ? ? ?(sym.c, sym.d), > ? ? ?(sym.c, sym.a), > ? ? ?(sym.e, sym.f), > ? ? ?(sym.e, sym.g), > ? ? ?(sym.f, sym.g), > ? ? ?(sym.h, sym.i), > ? ? ?] > > equalities = [] > for eq in eq_specs: > ? ? ?sorted_eq = eq if eq[0] <= eq[1] else (eq[1], eq[0]) > ? ? ?equalities.append( sorted_eq ) > equalities.sort() > > eq_sets = {} > eq_set_ids = {} > current_eq_set_id = 0 > for eq in equalities: This would make the body of the loop easier to read: for x, y in equalities: > ? ? ?if eq_set_ids.get( eq[0] ) is None: Why not simply: if eq[0] in eq_set_ids: > ? ? ? ? ?current_eq_set_id += 1 > ? ? ? ? ?eq_set_ids[eq[0]] = current_eq_set_id > ? ? ? ? ?eq_sets[current_eq_set_id] = set( eq[0] ) > ? ? ?eq_set_id = eq_set_ids[eq[0]] > ? ? ?eq_set_ids[eq[1]] = eq_set_id > ? ? ?eq_sets[eq_set_id].add( eq[1] ) > > for eq_set_id in eq_sets.keys(): > ? ? ?for sym_name in eq_sets[eq_set_id]: > ? ? ? ? ?print( "{}, {}".format( eq_set_id, sym_name ) ) > > > > 1, a > 1, c > 1, b > 1, d > 2, e > 2, g > 2, f > 3, i > 3, h > > > Disclaimer: for me it's pretty late in day/night. > > Cheers & hth., > > - Alf > > -- > blog at I think this won't work with the following graph: eq_specs = [('a', 'c'), ('b', 'd'), ('c', 'd')] Note that it is already sorted according to your sorting method. I don't have a Python machine to check this but I believe it will output: 1, a 1, c 1, d 2, b The flaw is that you fail to consider that the two vertices in the current pair may already be part of a (partial) connected component. -- Arnaud From alf.p.steinbach+usenet at gmail.com Tue Sep 21 05:41:46 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 21 Sep 2010 11:41:46 +0200 Subject: Grouping pairs - suggested tools In-Reply-To: <3463624f-405e-483f-9c21-52989d9a874f@k9g2000vbo.googlegroups.com> References: <3463624f-405e-483f-9c21-52989d9a874f@k9g2000vbo.googlegroups.com> Message-ID: * Arnaud Delobelle, on 21.09.2010 11:13: > On Sep 21, 7:19 am, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: >> * Alf P. Steinbach /Usenet, on 21.09.2010 01:09: >> >> >> >> >> >>> * Astley Le Jasper, on 20.09.2010 23:42: >>>> I have a list of tuples that indicate a relationship, ie a is related >>>> to b, b is related to c etc etc. What I want to do is cluster these >>>> relationships into groups. An item will only be associated with a >>>> single cluster. >> >>>> Before I started, I wondered if there was any particular tool within >>>> Python I should be looking at. I don't expect anyone to code this for >>>> me, just say ... "you need to look at using x". I was going to use >>>> populate a dictionary and >> >>>> Sorry for being so vague. >> >>>> Example Data: >>>> [(a,b) >>>> (a,c) >>>> (a,d) >>>> (b,c) >>>> (b,d) >>>> (c,d) >>>> (e,f) >>>> (e,g) >>>> (f,g) >>>> (h,i)] >> >>>> Output (grouping id, item ref) >>>> (1,a), >>>> (1,b), >>>> (1,c), >>>> (1,d), >>>> (2,e), >>>> (2,f), >>>> (2,g), >>>> (3,h), >>>> (3,i) >> >>> It seems to be the same problem as "equivalence sets". >> >>> This problem was solved early on because e.g. Fortran compilers had to construct >>> such sets (equivalence partitions of a set). >> >>> I though I'd just say "Google it!", because I know there's a standard algorithm >>> but I can't recall the name. However, googling it I found no mention of that >>> algorithm. Not even in the Wikipedia articles on equivalence sets. >> >>> A number of approaches spring to mind: >> >>> Approach 1: >>> Multi-pass. Originally you assign a distinct set number to each symbol. >>> In each pass through the symbols you replace one number with another as >>> per one of the equivalence specs. Stop when no replacements are done. >> >>> Approach 2: >>> Merging. For each new equivalence A=B you check whether A has been assigned >>> to a set, if not you create a new one, call that S1, and ditto for B, S2. >>> Merge S1 and S2, e.g. move all elements of S2 to S1. >> >>> Approach 3: >>> In a first pass convert the data to more explicit form, linking each symbol >>> to the symbols it's directly equivalent to. Then in second pass simply drag >>> out each equivalence group (recurse on each symbol's list of equivalences). >> >>> Approaches 1 and 2 seem to be pretty inefficient for a large number of symbols, >>> but I think approach 1 may be a practical option for a small number of symbols. >> >> Uhm, thinking about it (it must have been my unconscious mind doing the work, it >> just popped into my head), if you first sort each individual equivalence >> relation so that you never have e.g. C=A but only A=C and so on, and then sort >> the list of equivalences, then it should reduce to walking the list and just >> starting a new set whenever a symbol is encountered that isn't yet in a set. >> >> >> class Attributes: pass >> >> sym = Attributes() >> for name in ("a", "b", "c", "d", "e", "f", "g", "h", "i"): >> setattr( sym, name, name ) >> >> eq_specs = [ >> (sym.a, sym.d), >> (sym.b, sym.a), >> (sym.b, sym.c), >> (sym.b, sym.d), >> (sym.c, sym.d), >> (sym.c, sym.a), >> (sym.e, sym.f), >> (sym.e, sym.g), >> (sym.f, sym.g), >> (sym.h, sym.i), >> ] >> >> equalities = [] >> for eq in eq_specs: >> sorted_eq = eq if eq[0]<= eq[1] else (eq[1], eq[0]) >> equalities.append( sorted_eq ) >> equalities.sort() >> >> eq_sets = {} >> eq_set_ids = {} >> current_eq_set_id = 0 >> for eq in equalities: > > This would make the body of the loop easier to read: > > for x, y in equalities: > >> if eq_set_ids.get( eq[0] ) is None: > > Why not simply: > > if eq[0] in eq_set_ids: > >> current_eq_set_id += 1 >> eq_set_ids[eq[0]] = current_eq_set_id >> eq_sets[current_eq_set_id] = set( eq[0] ) >> eq_set_id = eq_set_ids[eq[0]] >> eq_set_ids[eq[1]] = eq_set_id >> eq_sets[eq_set_id].add( eq[1] ) >> >> for eq_set_id in eq_sets.keys(): >> for sym_name in eq_sets[eq_set_id]: >> print( "{}, {}".format( eq_set_id, sym_name ) ) >> >> >> >> 1, a >> 1, c >> 1, b >> 1, d >> 2, e >> 2, g >> 2, f >> 3, i >> 3, h >> >> >> Disclaimer: for me it's pretty late in day/night. >> >> Cheers& hth., >> >> - Alf >> >> -- >> blog at > > I think this won't work with the following graph: > > eq_specs = [('a', 'c'), ('b', 'd'), ('c', 'd')] > > Note that it is already sorted according to your sorting method. I > don't have a Python machine to check this but I believe it will > output: > > 1, a > 1, c > 1, d > 2, b > > The flaw is that you fail to consider that the two vertices in the > current pair may already be part of a (partial) connected component. Yeah, thanks. I think the three general methods I listed will nicely work, though. Moral: don't post insights from dream-world... ;-) Cheers, - Alf -- blog at From __peter__ at web.de Tue Sep 21 06:13:56 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Sep 2010 12:13:56 +0200 Subject: Grouping pairs - suggested tools References: Message-ID: Astley Le Jasper wrote: > I have a list of tuples that indicate a relationship, ie a is related > to b, b is related to c etc etc. What I want to do is cluster these > relationships into groups. An item will only be associated with a > single cluster. > > Before I started, I wondered if there was any particular tool within > Python I should be looking at. I don't expect anyone to code this for > me, just say ... "you need to look at using x". I was going to use > populate a dictionary and > > Sorry for being so vague. > > Example Data: > [(a,b) > (a,c) > (a,d) > (b,c) > (b,d) > (c,d) > (e,f) > (e,g) > (f,g) > (h,i)] > > Output (grouping id, item ref) > (1,a), > (1,b), > (1,c), > (1,d), > (2,e), > (2,f), > (2,g), > (3,h), > (3,i) A straightforward implementation: $ cat group_edges.py def find_groups(edges): lookup = {} # node --> group groups = {} # id(group) --> group for a, b in edges: if a in lookup: if b in lookup: ga = lookup[a] gb = lookup[b] if ga is not gb: # merge groups if len(ga) < len(gb): # always update the smaller group ga, gb = gb, ga del groups[id(gb)] ga.update(gb) for k in gb: lookup[k] = ga else: # add b to a's group ga = lookup[a] ga.add(b) lookup[b] = ga elif b in lookup: # add a to b's group gb = lookup[b] gb.add(a) lookup[a] = gb else: # create new group g = set((a, b)) groups[id(g)] = g lookup[a] = lookup[b] = g return groups.values() def show_groups(edges): groups = sorted(sorted(g) for g in find_groups(edges)) for i, group in enumerate(groups, 1): for node in sorted(group): print i, node if __name__ == "__main__": edges = [ ('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'), ('c', 'd'), ('e', 'f'), ('e', 'g'), ('f', 'g'), ('h', 'i'), ("lonesome john", "lonesome john")] show_groups(edges) print show_groups([('a', 'c'), ('b', 'd'), ('c', 'd')]) $ python group_edges.py 1 a 1 b 1 c 1 d 2 e 2 f 2 g 3 h 3 i 4 lonesome john 1 a 1 b 1 c 1 d Untested. Peter From raoulbia at gmail.com Tue Sep 21 06:25:14 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 21 Sep 2010 03:25:14 -0700 (PDT) Subject: basic 2 player wordgame Message-ID: <0f3ae081-cab9-43d9-9ddd-2f3f6926dc9d@a11g2000vbn.googlegroups.com> Hi I am working on a simple wordgame exercise: 2 players form a word by alternating turns saying a letter, which is added on to the end of the word fragment. I am familiar with loops, iterations etc but i need a hint as to how to approach alternating turns when writing this code? exercise source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset5.pdf thanks Baba From cournape at gmail.com Tue Sep 21 07:17:46 2010 From: cournape at gmail.com (David Cournapeau) Date: Tue, 21 Sep 2010 20:17:46 +0900 Subject: visual studio 2010 question In-Reply-To: References: <1c165c02-6056-4209-a1d3-91e132bf86e6@y3g2000vbm.googlegroups.com> Message-ID: On Tue, Sep 21, 2010 at 5:54 AM, Diez B. Roggisch wrote: > David Cournapeau writes: > >> On Mon, Sep 20, 2010 at 3:08 PM, Ralf Haring wrote: >>> >>> After running into the error "Setup script exited with error: Unable >>> to find vcvarsall.bat" when trying to use easy_install / setuptools a >>> little digging showed that the MS compiler files in distutils only >>> support up to Studio 2008. Does anyone know if there is a timetable >>> for when Studio 2010 will be supported? >>> >>> I am using python 2.6.5, but web searching seemed to show that 2.7 or >>> 3.X didn't support it yet either. >> >> You should use VS 2008 - the lack of distutils support is only the >> first of a long list of issues if you want to use another compiler to >> build python extensions. Unless you really know what you are doing, >> you are better off with VS 2008, > > Forgive my ignorance, but AFAIK mingw can be used to build extensions > for standard python distributions. Yes, mingw may be used - I assumed that the OP was interesting in MS compilers. > After all, it's C we're talking here, > not C++. So I have difficulties imagining VS2010 is that much of a > problem. So - which problems you expect? The ones described by Robert, David From nobody at nowhere.com Tue Sep 21 08:02:01 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 21 Sep 2010 13:02:01 +0100 Subject: socket.error: [Errno 98] Address already in use References: <2f830099-4264-47bc-98ee-31950412ad43@q21g2000prm.googlegroups.com> Message-ID: On Mon, 20 Sep 2010 12:00:41 +1200, Lawrence D'Oliveiro wrote: >> However, some clients choose their own source ports. E.g. rlogin/rsh use >> privileged (low-numbered) ports, and you can't get the kernel to choose a >> random privileged port for you. > > But nobody uses rlogin/rsh any more, They did when the bind() and SO_REUSEADDR semantics were developed. If they were doing it now, chances are that SO_REUSEADDR would be enabled by default. > and who would attach any trustworthy > meaning to a connection coming from a remote low-numbered source port? If you receive a connection with a low-numbered source port and it *isn't* legitimate, then someone has got root (in which case any other authentication mechanism isn't safe either) or someone has hijacked the IP address (you do know that low-numbered ports are only meaningful for systems under your control, right?). Using a firewall rule which only allows connections from a low port on specific IP addresses certainly isn't any worse than a rule which only allows connections from any port on specific IP addresses. That's true regardless of whether the protocol includes other authentication mechanisms. >> If you're writing a server which listens on a known port, you *should* be >> using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel >> will automatically reject packets relating to stale connections, and your >> server should be accepting any new connections ASAP. > > That makes it sound like SO_REUSEADDR should really be a superfluous option. > But it?s not. Well it is mostly superfluous. It should always be enabled for a server listening on a known port, and doesn't matter for a client which uses ephemeral ports. From nobody at nowhere.com Tue Sep 21 08:10:08 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 21 Sep 2010 13:10:08 +0100 Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> <87bp7s5504.fsf@benfinney.id.au> Message-ID: On Tue, 21 Sep 2010 10:12:27 +1000, Ben Finney wrote: > Another is that filesystems don't have a standard way of determining > whether they are case-sensitive. The operating system's driver for that > particular filesystem knows, I'm not even sure that's true; with a networked filesytem, some parts of it may be case-sensitive and others case-insensitve (e.g. if you export a Linux filesystem which includes Windows filesystems mounted beneath the root of the export). From nobody at nowhere.com Tue Sep 21 08:29:04 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 21 Sep 2010 13:29:04 +0100 Subject: Arrays and CTYPE References: <824d1ec2-93ee-4a81-ad95-19560fabe9e4@r10g2000vbc.googlegroups.com> Message-ID: On Mon, 20 Sep 2010 15:47:32 -0700, Glenn Pringle wrote: > Ok. I ran into a problem here. I have been dabbling with Python and I > thought that this would be a good exercise but I got stuck. > > I have a DLL and one of the functions(getState) in that DLL returns an > array. If the DLL was written in C (or C++), it can't return an array; it will return a pointer instead. > I'm having a hard time getting access to the contents of that > array. Set getState.restype to a pointer type, e.g.: hold.getState.restype = POINTER(c_int) Pointer types can be indexed with [], as in C. From antroy at gmail.com Tue Sep 21 08:29:30 2010 From: antroy at gmail.com (Ant) Date: Tue, 21 Sep 2010 05:29:30 -0700 (PDT) Subject: Python in Linux - barrier to Python 3.x Message-ID: Hi all, I've just seen this: http://sheddingbikes.com/posts/1285063820.html Whatever you think of Zed Shaw (author of the Mongrel Ruby server and relatively recent Python convert), he has a very good point in this. I run Fedora 12 on my home computers, and find it far too much hassle to try to get Python 3 installed. Even the 2.x's are behind - IIRC think it currently uses 2.5. So I really think this is a barrier to entry to Python 3 that we could do without - it's the only reason I do all of my Python work in 2.x, I would jump at migrating to Python 3 if it was easily available on Fedora. Is there a solution to this that anyone knows of? Has Zed jumped to conclusions? Have I? From mwilson at the-wire.com Tue Sep 21 08:39:00 2010 From: mwilson at the-wire.com (Mel) Date: Tue, 21 Sep 2010 08:39 -0400 Subject: basic 2 player wordgame References: <0f3ae081-cab9-43d9-9ddd-2f3f6926dc9d@a11g2000vbn.googlegroups.com> Message-ID: Baba wrote: > I am working on a simple wordgame exercise: 2 players form a word by > alternating turns saying a letter, which is added on to the end of the > word fragment. > > I am familiar with loops, iterations etc but i need a hint as to how > to approach alternating turns when writing this code? One way (not tested): thisplayer = Player() otherplayer = Player() while not_won: thisplayer.take_turn() thisplayer, otherplayer = otherplayer, thisplayer Mel. From vineetdaniel at gmail.com Tue Sep 21 08:49:38 2010 From: vineetdaniel at gmail.com (vineet daniel) Date: Tue, 21 Sep 2010 05:49:38 -0700 (PDT) Subject: creating python daemon ? Message-ID: Hi I have succesfully created daemon with python script and as next step I am trying to give input to that python script daemon from Apache Logs....here I have got stuck and I have even checked IRC python channel for solution. Apache is able to call the file but fails to execute it properly and I get this error continuosly : piped log program '/var/www/html/test.py' failed unexpectedly How do I rectify the above error and make adjustment to the code so that it takes input from apache. code that I am using is as follows : #! /usr/bin/env python import sys,os pid = os.fork() os.chdir("/var/www/html/") os.setsid() os.umask(0) #this line will read apache log in real time as redirected from the CustomLog directive of Apache. log = sys.stdin.readlines() f = open('/var/www/logmongo.txt','a') # append log to this text file f.write(log) I'd appreciate if anybody could share the code that they used for daemon or used with Apache CustomLog directive. From __peter__ at web.de Tue Sep 21 09:03:35 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Sep 2010 15:03:35 +0200 Subject: Python in Linux - barrier to Python 3.x References: Message-ID: Ant wrote: > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. Once you remove the Zedshawisms the article's claim boils down to - If you want to install and run a python script on a wide range of Linux distributions you have to stay compatible with Python 2.4. - Users of languages competing with Python tend to avoid applications that use Python, even if that usage is mostly under the hood -- but they don't mind using a program written in C. > So I really think this is a barrier to entry to Python 3 that we could > do without - it's the only reason I do all of my Python work in 2.x, I > would jump at migrating to Python 3 if it was easily available on > Fedora. > > Is there a solution to this that anyone knows of? More practical people than Zed (or his online persona) don't see it as a problem. > Has Zed jumped to conclusions? He jumped indeed, to another language, and he will do it again, but not without telling the world. > Have I? I think migration from 2.x to 3.x will be hard for large infrastructures but that doesn't seem to be your concern. Peter PS: Is the Paul Graham quote real? From philip at semanchuk.com Tue Sep 21 09:04:03 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 21 Sep 2010 09:04:03 -0400 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: References: Message-ID: <01306838-6ACB-4566-8931-7D469F319CEA@semanchuk.com> On Sep 21, 2010, at 8:29 AM, Ant wrote: > Hi all, > > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. Don't know about Python 3 on Fedora (I use a Mac), but distrowatch.org reports that Fedora has been using Python >= 2.6 since Fedora 11 which was released in June of 2009. http://distrowatch.com/table.php?distribution=fedora bye Philip From philip at semanchuk.com Tue Sep 21 09:10:51 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 21 Sep 2010 09:10:51 -0400 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: References: Message-ID: <5074C910-3249-413E-A1CA-A1192ABD9425@semanchuk.com> On Sep 21, 2010, at 8:29 AM, Ant wrote: > Hi all, > > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. Don't know about Python 3 on Fedora (I use a Mac), but distrowatch.org reports that Fedora has been using Python >= 2.6 since Fedora 11 which was released in June of 2009. http://distrowatch.com/table.php?distribution=fedora bye Philip From deets at web.de Tue Sep 21 09:23:42 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 15:23:42 +0200 Subject: Python in Linux - barrier to Python 3.x References: Message-ID: <874odj1b8h.fsf@web.de> Ant writes: > Hi all, > > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. > > So I really think this is a barrier to entry to Python 3 that we could > do without - it's the only reason I do all of my Python work in 2.x, I > would jump at migrating to Python 3 if it was easily available on > Fedora. > > Is there a solution to this that anyone knows of? Has Zed jumped to > conclusions? Have I? I think he has a very valid point. I've been arguing quite a few times here that e.g. the stupid splitting up of python and python-dev packages that a great deal of people trip over should go away. But usually people here seem to think that other package management systems are the way to go, and python itself must integrate with them. E.g. providing dependency information compatible to them and their policies. I think that's bonkers. You can't support every new kid on the block claiming to be the shizzle in package management. Or the next distro with it's own packaging policies. And of course the overall release planning that says "we use that ancient stable version not supported for years anymore, because it's true & tested for us". IMHO the solution to this is the way Apple does it: they have a System Python. Don't mess with it. Seriously. Don't. But you can install as many other Python versions as you want, or even bundle one with your own app that depends on it. People object to this usually for two reasons: - additional waste of disk-space. Seriously? A thorough visit of youporn.com most probably fills your browser cache with more data than all possibly python installations ever can. - security issues through aged libraries. Certainly a valid point, but then this problem is not limited to Python and needs a more universal solution: Meta-information gathering about binary versions of libraries, and (safe) upgrades for these. Maybe. I haven't given much thought to this, but I think it's an OS thing more than a package distro thing. So, in summary, I think if anything, Python should liberate itself from the reigns of distro package management, and fix whatever issues there are with setuptools (or distutils or pip or distribute or whatever the cool kids use these days). And then make people use that to work with Python-packages, potentially even in individual, isolated VirtualEnvs because of package version conflicts. Diez From icanbob at gmail.com Tue Sep 21 10:02:23 2010 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 21 Sep 2010 07:02:23 -0700 (PDT) Subject: basic 2 player wordgame References: <0f3ae081-cab9-43d9-9ddd-2f3f6926dc9d@a11g2000vbn.googlegroups.com> Message-ID: On Sep 21, 6:25 am, Baba wrote: > Hi > > I am working on a simple wordgame exercise: 2 players form a word by > alternating turns saying a letter, which is added on to the end of the > word fragment. > > I am familiar with loops, iterations etc but i need a hint as to how > to approach alternating turns when writing this code? > > exercise source:http://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > thanks > Baba Have a look at the SIMPL toolkit (http://www.icanprogram.com/06py/ lesson1/lesson1.html). This would allow your two players to be split into two separate Python modules. It has the "advantage" that once completed those two players could be deployed across a network, likely without any code changes. bob From michele.simionato at gmail.com Tue Sep 21 10:10:59 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 21 Sep 2010 07:10:59 -0700 (PDT) Subject: Python in Linux - barrier to Python 3.x References: Message-ID: On Sep 21, 2:29?pm, Ant wrote: > Hi all, > > I've just seen this:http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. > > So I really think this is a barrier to entry to Python 3 that we could > do without - it's the only reason I do all of my Python work in 2.x, I > would jump at migrating to Python 3 if it was easily available on > Fedora. > > Is there a solution to this that anyone knows of? Has Zed jumped to > conclusions? Have I? Zed's approach (removing Python when it could just have downgraded to Python 2.4) does not look very smart to me. The post itself is pretty much bullshit. Yes, there are Linux distributions with old Python versions out there. Yes, if you don't want to install a newer Python on such distributions you need to take in account this fact and not to use modern features of Python. But the situation is not different for other languages such as Perl or Ruby. C is free from this problem because it is a very old and stable language. There is no more content in that post and everybody should already know such basic facts. Michele Simionato From Antoon.Pardon at rece.vub.ac.be Tue Sep 21 10:17:48 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 21 Sep 2010 16:17:48 +0200 Subject: Too much code - slicing In-Reply-To: <4c97f72b$0$28658$c3e8da3@news.astraweb.com> References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: <20100921141748.GA8814@rcpc42.vub.ac.be> On Tue, Sep 21, 2010 at 12:07:07AM +0000, Steven D'Aprano wrote: > On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: > > > Not necessarily. Some of us have the impression that Guido deliberatly > > chose an ugly format for the ternary operator. > > If he did, then he must have changed his mind, because there is nothing > ugly about the ternary operator we ended up with. That is a question of taste and the poll and discussion earlier made it clear that this was not the preferred way to have a ternary operator. This form only ranked fourth (or maybe third), with the first three all wanting ar structure with the elelement is this order: condition, true case, false case > > Guido has alwasys been > > against a ternary operator but the requests kept coming. So eventually > > he introduced one. But the impression is that he chose an ugly format in > > the hope of discouraging people to use it. > > That's sheer and unadulterated nonsense. The fact is that Guido changed > his mind about ternary if after discovering that the work-around > > true-clause and condition or false-clause > > is buggy -- it gives the wrong answer if true-clause happens to be a > false value like [], 0 or None. If I recall correctly, the bug bit Guido > himself. Nonsense. That the work around was buggy was known years before the ternary operator was finally introduced. The introduction of list comprehension made a ternary operator that more usefull but every time it came up the supporters of Guido, told us we just had to define a function if we wanted the items to depend on a condition. And we knew about the problem, that is why we discussed bug-free alternatives like: condition and [true-expr] or [false-expr][0] or condition and (lambda: true-expr) or (lambda: false-expr)() > The and-or hack, which was *very* common in Python code for many years > and many versions, follows the same pattern as ternary if: > > true-clause if condition else false-clause No it doesn't. the and-or-hack follows the same pattern as the if statement. condition, true clause, else clause > It astounds me how the Python community changed it's collective mind from > admiration of the elegance and simplicity of the expression when it was a > buggy hack, to despising it when it became a bug-free language feature. It seems that what changed is your memory and not the collective mind of the python community. We had an if statement and a (buggy) hack that followed the same pattern. An earlier discussion and poll had revealed that people n general preferredr to keep that pattern in a conditional expression. So why should you be surprised when people express that they would have preferred a conditional expression with a different pattern than we have now. -- Antoon Pardon From darcy at druid.net Tue Sep 21 10:47:18 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 21 Sep 2010 10:47:18 -0400 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <874odj1b8h.fsf@web.de> References: <874odj1b8h.fsf@web.de> Message-ID: <20100921104718.601a0504.darcy@druid.net> On Tue, 21 Sep 2010 15:23:42 +0200 deets at web.de (Diez B. Roggisch) wrote: > So, in summary, I think if anything, Python should liberate itself from > the reigns of distro package management, and fix whatever issues there > are with setuptools (or distutils or pip or distribute or whatever the > cool kids use these days). And then make people use that to work with > Python-packages, potentially even in individual, isolated VirtualEnvs > because of package version conflicts. Install NetBSD package tools (http://pkgsrc.org/) and install as many versions as you like. A symlink takes care of your default and you can use .pth files to have separate local libraries. Pkgsrc is designed to run on all OSs including Linux distros. -- 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 astley.lejasper at gmail.com Tue Sep 21 11:07:48 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Tue, 21 Sep 2010 08:07:48 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: <79047d2d-4d9a-4e74-b44b-1010cf033525@t11g2000vbc.googlegroups.com> Thanks all. I was playing around with this and came up with another solution using dictionaries (... comfort zone ...!!) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Code >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> from operator import itemgetter def group_stuff(data): group_dic = {} group_id = 0 for line in data: i = 0 for ref in line: if group_dic.get(ref) is None: if group_dic.get(line[1-i]) is not None: group_id = group_dic[line[1-i]] else: group_id +=1 group_dic[ref] = group_id i+=1 group_list = [] for id, group in sorted(group_dic.items(), key=itemgetter(1,0)): group_list.append((group, id)) return group_list if __name__ == '__main__': data = [('a','b'),('a','c'),('a','d'),('b','c'),('b','d'), ('c','d'),('e','f'),('e','g'),('f','g'),('h','i')] grouped = group_stuff(data) print grouped <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Code >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Output: [(1, 'a'), (1, 'b'), (1, 'c'), (1, 'd'), (2, 'e'), (2, 'f'), (2, 'g'), (3, 'h'), (3, 'i')] From cournape at gmail.com Tue Sep 21 11:18:06 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 22 Sep 2010 00:18:06 +0900 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <874odj1b8h.fsf@web.de> References: <874odj1b8h.fsf@web.de> Message-ID: On Tue, Sep 21, 2010 at 10:23 PM, Diez B. Roggisch wrote: > Ant writes: > >> Hi all, >> >> I've just seen this: http://sheddingbikes.com/posts/1285063820.html >> >> Whatever you think of Zed Shaw (author of the Mongrel Ruby server and >> relatively recent Python convert), he has a very good point in this. I >> run Fedora 12 on my home computers, and find it far too much hassle to >> try to get Python 3 installed. Even the 2.x's are behind - IIRC think >> it currently uses 2.5. >> >> So I really think this is a barrier to entry to Python 3 that we could >> do without - it's the only reason I do all of my Python work in 2.x, I >> would jump at migrating to Python 3 if it was easily available on >> Fedora. >> >> Is there a solution to this that anyone knows of? Has Zed jumped to >> conclusions? Have I? > > I think he has a very valid point. I've been arguing quite a few times > here that e.g. the stupid splitting up of python and python-dev packages > that a great deal of people trip over should go away. It is not stupid, it makes a lot of sense when you know the distributions in question. It means you have a consistent behavior independently of the language. So of course if you don't care about the rest of the ecosystem, you will think it is useless overhead. Also, I doubt that the issue is python vs python-dev - of course, given that the exact issues are not explained, we can only play guess games. > > But usually people here seem to think that other package management > systems are the way to go, and python itself must integrate with > them. E.g. providing dependency information compatible to them and their policies. > > I think that's bonkers. You can't support every new kid on the block > claiming to be the shizzle in package management. Or the next distro > with it's own packaging policies. And of course the overall release > planning that says "we use that ancient stable version not supported for > years anymore, because it's true & tested for us". > > IMHO the solution to this is the way Apple does it: they have a System > Python. Don't mess with it. Seriously. Don't. Apple's python have caused more issues than all distributions altogether for Numpy and scipy, at least as far as python itself is concerned. It is very confusing for many end-users. > So, in summary, I think if anything, Python should liberate itself from > the reigns of distro package management, and fix whatever issues there > are with setuptools (or distutils or pip or distribute or whatever the > cool kids use these days). And then make people use that to work with > Python-packages, potentially even in individual, isolated VirtualEnvs > because of package version conflicts. This kind of thinking mostly shows a poor understanding of complex deployment scenario. If everybody worked like that, you would quickly be unable to build anything stable. True, conflicts are sometimes unavoidable, but if every library keeps changing your only solution is isolated environments, you quickly have a mess of a system where many combinations of libraries are not possible. The fact is that if you need to assemble softwares from many sources, you need proper engineering. Isolated environments do not help you much with that. Maybe you should consider that distros have an experience that you don't, cheers, David From __peter__ at web.de Tue Sep 21 11:31:32 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Sep 2010 17:31:32 +0200 Subject: Grouping pairs - suggested tools References: <79047d2d-4d9a-4e74-b44b-1010cf033525@t11g2000vbc.googlegroups.com> Message-ID: Astley Le Jasper wrote: > Thanks all. I was playing around with this and came up with another > solution using dictionaries (... comfort zone ...!!) > from operator import itemgetter > > def group_stuff(data): > > group_dic = {} > group_id = 0 > > for line in data: > i = 0 > for ref in line: > if group_dic.get(ref) is None: > if group_dic.get(line[1-i]) is not None: > group_id = group_dic[line[1-i]] > else: > group_id +=1 > group_dic[ref] = group_id > i+=1 > > group_list = [] > for id, group in sorted(group_dic.items(), key=itemgetter(1,0)): > group_list.append((group, id)) > > return group_list > > if __name__ == '__main__': > data = [('a','b'),('a','c'),('a','d'),('b','c'),('b','d'), > ('c','d'),('e','f'),('e','g'),('f','g'),('h','i')] > grouped = group_stuff(data) > print grouped > Output: [(1, 'a'), (1, 'b'), (1, 'c'), (1, 'd'), (2, 'e'), (2, 'f'), > (2, 'g'), (3, 'h'), (3, 'i')] I think you have the same bug as Alf's code, you never merge existing groups. Have you tried Arnaud's counterexample? By the way, are ('a', 'b') and ('b', 'a') to be considered equivalent for your problem? Peter From ndbecker2 at gmail.com Tue Sep 21 11:32:16 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 21 Sep 2010 11:32:16 -0400 Subject: Python in Linux - barrier to Python 3.x References: Message-ID: Ant wrote: > Hi all, > > I've just seen this: http://sheddingbikes.com/posts/1285063820.html > > Whatever you think of Zed Shaw (author of the Mongrel Ruby server and > relatively recent Python convert), he has a very good point in this. I > run Fedora 12 on my home computers, and find it far too much hassle to > try to get Python 3 installed. Even the 2.x's are behind - IIRC think > it currently uses 2.5. > > So I really think this is a barrier to entry to Python 3 that we could > do without - it's the only reason I do all of my Python work in 2.x, I > would jump at migrating to Python 3 if it was easily available on > Fedora. > > Is there a solution to this that anyone knows of? Has Zed jumped to > conclusions? Have I? Current fedora release (13) has python3 available. From deets at web.de Tue Sep 21 11:59:27 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 17:59:27 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> Message-ID: <87zkvbytnk.fsf@web.de> David Cournapeau writes: > On Tue, Sep 21, 2010 at 10:23 PM, Diez B. Roggisch wrote: >> Ant writes: >> >>> Hi all, >>> >>> I've just seen this: http://sheddingbikes.com/posts/1285063820.html >>> >>> Whatever you think of Zed Shaw (author of the Mongrel Ruby server and >>> relatively recent Python convert), he has a very good point in this. I >>> run Fedora 12 on my home computers, and find it far too much hassle to >>> try to get Python 3 installed. Even the 2.x's are behind - IIRC think >>> it currently uses 2.5. >>> >>> So I really think this is a barrier to entry to Python 3 that we could >>> do without - it's the only reason I do all of my Python work in 2.x, I >>> would jump at migrating to Python 3 if it was easily available on >>> Fedora. >>> >>> Is there a solution to this that anyone knows of? Has Zed jumped to >>> conclusions? Have I? >> >> I think he has a very valid point. I've been arguing quite a few times >> here that e.g. the stupid splitting up of python and python-dev packages >> that a great deal of people trip over should go away. > > It is not stupid, it makes a lot of sense when you know the > distributions in question. It means you have a consistent behavior > independently of the language. So of course if you don't care about > the rest of the ecosystem, you will think it is useless overhead. The point is that the distro doesn't care about the python eco system. Which is what I care about, and a lot of people who want to ship software. Don't get me wrong: I'm a Linux user for way over a decade, I enjoy the package management in providing a consistent distribution. What I'm talking about here are 3rd-party developers/companies/whatever, and people who want to install software that requires recent versions of packages *not* provided by their distros. I should have made that point clearer I guess. > > Also, I doubt that the issue is python vs python-dev - of course, > given that the exact issues are not explained, we can only play guess > games. The problems explained are simply outdated and crippled python versions. And to me, a python version installed that has not the distutils module is *crippled*. You can rationalize that as much as you want through some package philosophy saying "we don't ship development related files", but to me a simple installation instruction that says "run 'python setup.py install'" which fails because of such a (debatable) decision sucks. Yes, there are corner-cases when you need GCC to compile an extension. But that's still catering to the 80% or even more (I'm guessing here) of pure-python packages. Of course, in a ideal world, distutils would hook into the distros dependency system + simply say "please install python-dev first". But I'm not convinced that putting the weight here on the shoulders of the python-communtiy to deal with arbirtray decisions of the dozen or how many distros + packaging schemes out there is possible - and helpful. >> But usually people here seem to think that other package management >> systems are the way to go, and python itself must integrate with >> them. E.g. providing dependency information compatible to them and their policies. >> >> I think that's bonkers. You can't support every new kid on the block >> claiming to be the shizzle in package management. Or the next distro >> with it's own packaging policies. And of course the overall release >> planning that says "we use that ancient stable version not supported for >> years anymore, because it's true & tested for us". >> >> IMHO the solution to this is the way Apple does it: they have a System >> Python. Don't mess with it. Seriously. Don't. > > Apple's python have caused more issues than all distributions > altogether for Numpy and scipy, at least as far as python itself is > concerned. It is very confusing for many end-users. Exactly. My point is that I can safely install a second version besides it, and don't use the system's python that is there and kept stable for the system's own belongings. >> So, in summary, I think if anything, Python should liberate itself from >> the reigns of distro package management, and fix whatever issues there >> are with setuptools (or distutils or pip or distribute or whatever the >> cool kids use these days). And then make people use that to work with >> Python-packages, potentially even in individual, isolated VirtualEnvs >> because of package version conflicts. > > This kind of thinking mostly shows a poor understanding of complex > deployment scenario. If everybody worked like that, you would quickly > be unable to build anything stable. True, conflicts are sometimes > unavoidable, but if every library keeps changing your only solution is > isolated environments, you quickly have a mess of a system where many > combinations of libraries are not possible. And now you are already in a mess of a system where many combinations of libraries are not possible. And the thinking of "one version set to rule them all" shows a poor understanding of the need for legacy code's specific version requirements, as well as the need for fluctuating, (sometimes cutting edge) libraries. Does that suck? Sure. But the answer can't be a system that ties you in with *outdated* software for *years*. And it can't be Python's or it's communities burden to provide the solutions for the mass of distro providers. I *am* in the situation to need to deploy a TurboGears2 application every day on a debian lenny machine. Guess what that means: root at web01 / 15:55:43 # aptitude install python-turbogears -Vs Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done Reading task descriptions... Done The following NEW packages will be installed: python-cheetah{a} [2.0.1-2] python-cherrypy{a} [2.3.0-1] python-configobj{a} [4.5.2-1] python-crypto{a} [2.0.1+dfsg1-2.3+lenny0] python-decoratortools{a} [1.7-1] python-dispatch{a} [0.5a.svn20080510-1] python-dns{a} [2.3.3-2] python-elementtree{a} [1.2.6-12] python-elixir{a} [0.6.0-1] python-flup{a} [1.0-1] python-formencode{a} [1.0.1-1] python-kid{a} [0.9.6-1] python-mysqldb{a} [1.2.2-7] python-nose{a} [0.10.3-1] python-openid{a} [2.2.1-2] python-openssl{a} [0.7-2] python-paste{a} [1.7.1-1] python-pastedeploy{a} [1.3.2-1] python-pastescript{a} [1.6.3-1] python-pkg-resources{a} [0.6c8-4] python-protocols{a} [1.0a.svn20070625-2] python-pysqlite2{a} [2.4.1-1] python-scgi{a} [1.12-0.2] python-setuptools{a} [0.6c8-4] python-simplejson{a} [1.9.2-1] python-sqlalchemy{a} [0.4.7p1-2] python-sqlobject{a} [0.10.2-3] python-turbogears [1.0.4.4-1] python-turbojson{a} [1.1.2-1] python-turbokid{a} [1.0.4-2] python-webpy{a} [0.230-1] 0 packages upgraded, 31 newly installed, 0 to remove and 0 not upgraded. Need to get 4936kB/5188kB of archives. After unpacking 29.3MB will be used. Turbogears 1.0.4? Thank you - can't use that. > The fact is that if you need to assemble softwares from many sources, > you need proper engineering. Isolated environments do not help you > much with that. Maybe you should consider that distros have an > experience that you don't, I don't deny them their experience. Do you deny the experience of other people with *other* needs? As I already said: I don't propose to ditch the package management. I'm all fine with a distro that carefully selects it's packages and dependencies. I'm proposing that it should be able to have "system_python" and "current_python" or whatever you call it on one machine, and then let them live as happy co-existing eco-systems. This is not a well planned out thing. And it would certainly help to have a central meta-information registry to know exactly *where* and *which* version of all dependend libraries are installed. And thus make it possible to say "ok, we upgrade all system copies of openssl, and btw. you have these additional locations where you should do that as well." Or something like this. But the current state of affairs forces me to use customized versions of python on my machines, with virtualenvs including specific versions of libraries, bypassing the distro anyway. Why not try and make this more standardized & thus manageable? Diez From garyr at fidalgo.net Tue Sep 21 12:04:55 2010 From: garyr at fidalgo.net (garyr) Date: Tue, 21 Sep 2010 09:04:55 -0700 Subject: Python 2.6 & bsddb Message-ID: I recently installed ActivePython 2.6.6 and my programs that use anydbm or shelve generate import errors because bsddb is missing. I installed bsddb3 (bsddb3-5.0.0.win32-py2.6.exe) but that didn't change anything. What more do I need to do? From solipsis at pitrou.net Tue Sep 21 12:13:19 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 21 Sep 2010 18:13:19 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: <20100921181319.1f8d73ef@pitrou.net> On Tue, 21 Sep 2010 17:59:27 +0200 deets at web.de (Diez B. Roggisch) wrote: > > The problems explained are simply outdated and crippled python > versions. > > And to me, a python version installed that has not the > distutils module is *crippled*. You can rationalize that as much as you > want through some package philosophy saying "we don't ship development > related files", but to me a simple installation instruction that says comp.lang.python doesn't handle Linux packaging, so why don't you complain to your distro instead? Ranting on this group has zero chance of fixing the problem. Thank you Antoine. From robin at reportlab.com Tue Sep 21 12:18:40 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 21 Sep 2010 17:18:40 +0100 Subject: weird error with python 2.7 installer under windows 7 Message-ID: <4C98DAE0.2010100@chamonix.reportlab.co.uk> A colleague gets this error while testing a bdist wininst installer under windows 7 professional. This is on the page where the Post install script output appears. In the upper part I see "Postinstall script finished. Click the Finish button to exit the setup wizard." In the bottom panel where we normally see output about the created scripts I see this "close failed in file object destructor: Error in sys.excepthook: Original exception was:" I have tried the same installer with a Win XP Sp3 machine and it doesn't cause any problems. Any ideas? -- Robin Becker From usenot at geekmail.INVALID Tue Sep 21 12:26:29 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 21 Sep 2010 12:26:29 -0400 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> Message-ID: <20100921122629.4a1ff844@geekmail.INVALID> On Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Carl Banks wrote: > On Sep 17, 1:01?pm, Andreas Waldenburger > wrote: > > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: > > > > > I also like this construct that works, I think, since 2.6: > > > > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > > > I wonder when this construct will finally start to look good. > > I don't know if it'll ever look good, per se, but it looks better when > it's used in rule-exception sort of case: > > something = rule if condition else exception > Spot on. I (more or less) like it when used that way, too. But it seems to invite crackers like the example above, and that irks me. /W -- INVALID? DE! From cournape at gmail.com Tue Sep 21 12:38:21 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 22 Sep 2010 01:38:21 +0900 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <87zkvbytnk.fsf@web.de> References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: On Wed, Sep 22, 2010 at 12:59 AM, Diez B. Roggisch wrote: > David Cournapeau writes: > >> On Tue, Sep 21, 2010 at 10:23 PM, Diez B. Roggisch wrote: >>> Ant writes: >>> >>>> Hi all, >>>> >>>> I've just seen this: http://sheddingbikes.com/posts/1285063820.html >>>> >>>> Whatever you think of Zed Shaw (author of the Mongrel Ruby server and >>>> relatively recent Python convert), he has a very good point in this. I >>>> run Fedora 12 on my home computers, and find it far too much hassle to >>>> try to get Python 3 installed. Even the 2.x's are behind - IIRC think >>>> it currently uses 2.5. >>>> >>>> So I really think this is a barrier to entry to Python 3 that we could >>>> do without - it's the only reason I do all of my Python work in 2.x, I >>>> would jump at migrating to Python 3 if it was easily available on >>>> Fedora. >>>> >>>> Is there a solution to this that anyone knows of? Has Zed jumped to >>>> conclusions? Have I? >>> >>> I think he has a very valid point. I've been arguing quite a few times >>> here that e.g. the stupid splitting up of python and python-dev packages >>> that a great deal of people trip over should go away. >> >> It is not stupid, it makes a lot of sense when you know the >> distributions in question. It means you have a consistent behavior >> independently of the language. So of course if you don't care about >> the rest of the ecosystem, you will think it is useless overhead. > > The point is that the distro doesn't care about the python eco > system. Which is what I care about, and a lot of people who want to ship > software. > > Don't get me wrong: I'm a Linux user for way over a decade, I enjoy the > package management in providing a consistent distribution. > > What I'm talking about here are 3rd-party > developers/companies/whatever, and people who want to install software > that requires recent versions of packages *not* provided by their > distros. I should have made that point clearer I guess. > >> >> Also, I doubt that the issue is python vs python-dev - of course, >> given that the exact issues are not explained, we can only play guess >> games. > > The problems explained are simply outdated and crippled python > versions. > > And to me, a python version installed that has not the > distutils module is *crippled*. You can rationalize that as much as you > want through some package philosophy saying "we don't ship development > related files", but to me a simple installation instruction that says > > "run 'python setup.py install'" > > which fails because of such a (debatable) decision sucks. Yes, there are > corner-cases when you need GCC to compile an extension. But that's still > catering to the 80% or even more (I'm guessing here) of pure-python packages. > > Of course, in a ideal world, distutils would hook into the distros > dependency system + simply say "please install python-dev first". > > But I'm not convinced that putting the weight here on the shoulders of > the python-communtiy to deal with arbirtray decisions of the dozen or > how many distros + packaging schemes out there is possible - and helpful. > >>> But usually people here seem to think that other package management >>> systems are the way to go, and python itself must integrate with >>> them. E.g. providing dependency information compatible to them and their policies. >>> >>> I think that's bonkers. You can't support every new kid on the block >>> claiming to be the shizzle in package management. Or the next distro >>> with it's own packaging policies. And of course the overall release >>> planning that says "we use that ancient stable version not supported for >>> years anymore, because it's true & tested for us". >>> >>> IMHO the solution to this is the way Apple does it: they have a System >>> Python. Don't mess with it. Seriously. Don't. >> >> Apple's python have caused more issues than all distributions >> altogether for Numpy and scipy, at least as far as python itself is >> concerned. It is very confusing for many end-users. > > Exactly. My point is that I can safely install a second version besides > it, and don't use the system's python that is there and kept stable for > the system's own belongings. > >>> So, in summary, I think if anything, Python should liberate itself from >>> the reigns of distro package management, and fix whatever issues there >>> are with setuptools (or distutils or pip or distribute or whatever the >>> cool kids use these days). And then make people use that to work with >>> Python-packages, potentially even in individual, isolated VirtualEnvs >>> because of package version conflicts. >> >> This kind of thinking mostly shows a poor understanding of complex >> deployment scenario. If everybody worked like that, you would quickly >> be unable to build anything stable. True, conflicts are sometimes >> unavoidable, but if every library keeps changing your only solution is >> isolated environments, you quickly have a mess of a system where many >> combinations of libraries are not possible. > > And now you are already in a mess of a system where many combinations of > libraries are not possible. And the thinking of "one version set to rule > them all" shows a poor understanding of the need for legacy code's > specific version requirements, as well as the need for fluctuating, > (sometimes cutting edge) libraries. > > Does that suck? Sure. But the answer can't be a system that ties you in > with *outdated* software for *years*. And it can't be Python's or it's > communities burden to provide the solutions for the mass of distro providers. > > I *am* in the situation to need to deploy > a TurboGears2 application every day on a debian lenny machine. Guess > what that means: > > root at web01 / 15:55:43 # aptitude install python-turbogears -Vs > Reading package lists... Done > Building dependency tree > Reading state information... Done > Reading extended state information > Initializing package states... Done > Reading task descriptions... Done > The following NEW packages will be installed: > ?python-cheetah{a} [2.0.1-2] ?python-cherrypy{a} [2.3.0-1] ?python-configobj{a} [4.5.2-1] ?python-crypto{a} [2.0.1+dfsg1-2.3+lenny0] ?python-decoratortools{a} [1.7-1] > ?python-dispatch{a} [0.5a.svn20080510-1] ?python-dns{a} [2.3.3-2] ?python-elementtree{a} [1.2.6-12] ?python-elixir{a} [0.6.0-1] ?python-flup{a} [1.0-1] ?python-formencode{a} [1.0.1-1] > ?python-kid{a} [0.9.6-1] ?python-mysqldb{a} [1.2.2-7] ?python-nose{a} [0.10.3-1] ?python-openid{a} [2.2.1-2] ?python-openssl{a} [0.7-2] ?python-paste{a} [1.7.1-1] ?python-pastedeploy{a} [1.3.2-1] > ?python-pastescript{a} [1.6.3-1] ?python-pkg-resources{a} [0.6c8-4] ?python-protocols{a} [1.0a.svn20070625-2] ?python-pysqlite2{a} [2.4.1-1] ?python-scgi{a} [1.12-0.2] > ?python-setuptools{a} [0.6c8-4] ?python-simplejson{a} [1.9.2-1] ?python-sqlalchemy{a} [0.4.7p1-2] ?python-sqlobject{a} [0.10.2-3] ?python-turbogears [1.0.4.4-1] ?python-turbojson{a} [1.1.2-1] > ?python-turbokid{a} [1.0.4-2] ?python-webpy{a} [0.230-1] > 0 packages upgraded, 31 newly installed, 0 to remove and 0 not upgraded. > Need to get 4936kB/5188kB of archives. After unpacking 29.3MB will be used. > > Turbogears 1.0.4? Thank you - can't use that. > >> The fact is that if you need to assemble softwares from many sources, >> you need proper engineering. Isolated environments do not help you >> much with that. Maybe you should consider that distros have an >> experience that ?you don't, > > I don't deny them their experience. Do you deny the experience of other > people with *other* needs? As I already said: I don't propose to ditch > the package management. I'm all fine with a distro that carefully > selects it's packages and dependencies. In your previous email, you were "suggesting" that we should make people use a specific set of python-specific tools. That does not sound very consistent with the idea of letting people choose what they want to use. FWIW, I think those tools are already pushed too aggressively, confusing many people who use pip, virtualenv, etc... for dubious reasons ("I read somewhere that I should use this"), and causing numerous bug reports on the numpy/scipy mailing lists. David From deets at web.de Tue Sep 21 12:44:20 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 18:44:20 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: <87vd5zyrkr.fsf@web.de> Antoine Pitrou writes: > On Tue, 21 Sep 2010 17:59:27 +0200 > deets at web.de (Diez B. Roggisch) wrote: >> >> The problems explained are simply outdated and crippled python >> versions. >> >> And to me, a python version installed that has not the >> distutils module is *crippled*. You can rationalize that as much as you >> want through some package philosophy saying "we don't ship development >> related files", but to me a simple installation instruction that says > > comp.lang.python doesn't handle Linux packaging, so why don't you > complain to your distro instead? Ranting on this group has zero chance > of fixing the problem. comp.lang.python frequently deals with problems caused by this and other distro-related issues. Your are welcome to not participate on these discussions. The state of affairs isn't ideal, and there is improvement options on all sides. I'm just astonished that people seem to think that distros in general are better and should be left alone, than what a more python centric solution could be. Diez From deets at web.de Tue Sep 21 12:47:08 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 18:47:08 +0200 Subject: creating python daemon ? References: Message-ID: <87r5gnyrg3.fsf@web.de> vineet daniel writes: > Hi > > I have succesfully created daemon with python script and as next step > I am trying to give input to that python script daemon from Apache > Logs....here I have got stuck and I have even checked IRC python > channel for solution. Apache is able to call the file but fails to > execute it properly and I get this error continuosly : > > piped log program '/var/www/html/test.py' failed unexpectedly > > How do I rectify the above error and make adjustment to the code so > that it takes input from apache. > > code that I am using is as follows : > > #! /usr/bin/env python > import sys,os > pid = os.fork() > os.chdir("/var/www/html/") > os.setsid() > os.umask(0) > #this line will read apache log in real time as redirected from the > CustomLog directive of Apache. > log = sys.stdin.readlines() > f = open('/var/www/logmongo.txt','a') # append log to this text file > f.write(log) > > I'd appreciate if anybody could share the code that they used for > daemon or used with Apache CustomLog directive. The above code looks errornous - you don't check for the return-value of PID & take appropriate action. Like There is a daemonization recipe on active-state, which works nicely for me. http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way/ Diez From sridharr at activestate.com Tue Sep 21 12:58:32 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Tue, 21 Sep 2010 09:58:32 -0700 Subject: Python 2.6 & bsddb In-Reply-To: References: Message-ID: On 2010-09-21, at 9:04 AM, garyr wrote: > I recently installed ActivePython 2.6.6 and my programs that use anydbm or > shelve generate import errors because bsddb is missing. I installed bsddb3 > (bsddb3-5.0.0.win32-py2.6.exe) but that didn't change anything. What more do > I need to do? You may have to change the imports. Maybe from "import bsddb" to "import bsddb3". The API may be different. Read the bsddb3 documentation. -srid From deets at web.de Tue Sep 21 13:06:56 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 21 Sep 2010 19:06:56 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: <87mxrbyqj3.fsf@web.de> David Cournapeau writes: >> >> I don't deny them their experience. Do you deny the experience of other >> people with *other* needs? As I already said: I don't propose to ditch >> the package management. I'm all fine with a distro that carefully >> selects it's packages and dependencies. > > In your previous email, you were "suggesting" that we should make > people use a specific set of python-specific tools. That does not > sound very consistent with the idea of letting people choose what they > want to use. > > FWIW, I think those tools are already pushed too aggressively, > confusing many people who use pip, virtualenv, etc... for dubious > reasons ("I read somewhere that I should use this"), and causing > numerous bug reports on the numpy/scipy mailing lists. What I suggested was that there is a python-centric solution for managing dependencies for users of Linux, Windows and OSX alike. And which offers recent versions of python to anybody. A lot of wishful thinking, admittedly. But less than trying to deal with *all* the diffences in code, style and politics of various distributions. I was not suggesting that this solution itself be manifold. The sad truth is that there currently seem to be various attempts to improve or even fix perceived or real shortcomings of of distutils or probably even more setuptools, and this is from an outside perspective a waste. But then, the survival of the fittest, so to speak, requires the death of some that are unfit. It's hard to say which approach will "win". So we seem to be stuck with that at least for a while. zc.buildout, btw, seems to be going into the general direction of doing a lot (if not everything) itself. Including complete 3rd-party-packages and their builds. http://pypi.python.org/pypi/zc.buildout#buildout-examples For historic reasons I personally haven't used it yet. But it seems to scratch an itch, don't you think? Regarding the "dubiousness" of these reasons - I'm happy if you don't feel the pain. Good for you. I do, and frankly virtualenv is a life-saver for me in many situations. I wish it was part of core python, to create isolated environments. It sure is better than the Java-way of relying on environment-variables or giant sized commandline argument lists to specify specific version sets. However, *both* solutions cater to the obvious need of something other than pre-packaged versions in the distro. Is that such an abnorm wish? Amazing. Diez From t.koziara at civil.gla.ac.uk Tue Sep 21 13:17:30 2010 From: t.koziara at civil.gla.ac.uk (Tomasz Koziara) Date: Tue, 21 Sep 2010 18:17:30 +0100 Subject: naming the main module in embedded Python Message-ID: Hi I am embedding Python as an interpret in my code. Now, whenever my code or Python itself issues an error/warning message I am getting something like: File "", line 1, in or __main__:46: RuntimeWarning: My warning message I am using PyRun_SimpleString to load part of the code and the I call: sprintf (line, "execfile ('%s')", path); error = PyRun_SimpleString (line). The question is: how can I set up the module name or input file name so that my error/warning messages output them rather than the above default values? Thanks Tomek From john at castleamber.com Tue Sep 21 13:53:01 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 12:53:01 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: <8739t3m1aa.fsf@castleamber.com> geremy condra writes: > It's a joke. Admittedly it's a bit pointed, but it's a joke > nonetheless, and it does at least provide what I consider to be two > valuable pieces of information: that you should have googled this > before asking, and what you should have googled for. If I miss and > you've done your homework already, well, at least you get the smug > satisfaction of knowing that I was too stupid to understand your > question. It makes you a patronizing fuck in my book. And no, that's not a joke. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Tue Sep 21 13:57:34 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 12:57:34 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: <87y6avkmi9.fsf@castleamber.com> Steven D'Aprano writes: > I prefer the old fashioned version: > > "Google Is Your Friend" > > followed by a URL to the appropriate google's search results page. Or > even more to the point: > > "Did you bother to google for the answer first? Because the very first > page that comes up gives exactly the answer you want." > > Although sometimes people genuinely don't know what search terms they > should be using, or if they're too generic. Yes, exactly. I agree 100% with you (including the microsecond amusement value of lmgtfy). Besides the link to the SERP I also provide a link to what I consider the best result found on that page. Sometimes people were able to find the result, and thought it was not right. Or were not able to find the best solution out of the hundreds offered by Google. And some people are ashamed of telling that they have used Google, and couldn't find it. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Tue Sep 21 14:00:54 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 13:00:54 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: <87tyljkmcp.fsf@castleamber.com> Dennis Lee Bieber writes: > On 21 Sep 2010 05:01:45 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > >> Hey, that would be an *awesome* google bombing project... to get lmgtfy >> to come up as the first link for "self-righteous dicks". 4chan, where are >> you when we need you??? >> > I think the news reports are that they are wasting time on a DDoS > attack on the RIAA... > > While I don't agree with the RIAA's methods, I also think a DDoS is > definitely NOT an action to endear one to that one's views... It is/was, from what I understand, a "back at ya" since the RIAA hired a company in India to DDoS torrent related sites. The Indian company is/was also under DDoS. I do agree that it's somewhat pointless. They better could block access to movie theaters all over the world by chaining themselves to the entry. But, hey, then they have to get out of the couch and get out of the house. And their moms might start to ask questions... -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Tue Sep 21 14:04:46 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 13:04:46 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <87pqw7km69.fsf@castleamber.com> Dennis Lee Bieber writes: > On Mon, 20 Sep 2010 20:12:01 -0500, John Bokma > declaimed the following in gmane.comp.python.general: > > >> I never saw the point of the whole X-No-Archive: Yes thing. What happens >> if I quote such a message? It's archived, right? > > Compliant clients (like Agent) will echo the X-No-Archive: Yes in > YOUR reply -- so it too will be deleted at some point in time. Ouch, while asking me first, I hope? -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Tue Sep 21 14:05:44 2010 From: john at castleamber.com (John Bokma) Date: Tue, 21 Sep 2010 13:05:44 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <87lj6vkm4n.fsf@castleamber.com> Lawrence D'Oliveiro writes: > In message <87aanbx5lq.fsf at castleamber.com>, John Bokma wrote: > >> I never saw the point of the whole X-No-Archive: Yes thing. What happens >> if I quote such a message? It's archived, right? > > Where did they come from? > Posting fragments, followed up-- > Originals? No more. L a s p ENTER -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From emile at fenx.com Tue Sep 21 14:22:09 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 21 Sep 2010 11:22:09 -0700 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: References: Message-ID: On 9/21/2010 5:29 AM Ant said... > Is there a solution to this that anyone knows of? Has Zed jumped to > conclusions? Have I? I'd say the error was in selecting something other that the lowest common subset of python functions when designing and writing a python version dependent Mongrel2. There are certainly ways (and perhaps compatibility libraries as well) to write python at a 2.4 (or 2.2) level to sidestep installation issues related to python versions. Targeting a wide range of installation platforms without taking that into account is the problem. When you issue a 2.5 dependent version and find it easier to convert it all to C rather than write the (relatively minor) python fixes, it speaks to the level of python competency as well. What if I wrote a 64bit app and complained that in 32bit environments it didn't do the right thing? Emile From vineetdaniel at gmail.com Tue Sep 21 14:32:26 2010 From: vineetdaniel at gmail.com (vineet daniel) Date: Tue, 21 Sep 2010 11:32:26 -0700 (PDT) Subject: creating python daemon ? References: <87r5gnyrg3.fsf@web.de> Message-ID: <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> On Sep 21, 9:47?pm, de... at web.de (Diez B. Roggisch) wrote: > vineet daniel writes: > > Hi > > > I have succesfully created daemon with python script and as next step > > I am trying to give input to that python script daemon from Apache > > Logs....here I have got stuck and I have even checked IRC python > > channel for solution. Apache is able to call the file but fails to > > execute it properly and I get this error continuosly : > > > piped log program '/var/www/html/test.py' failed unexpectedly > > > How do I rectify the above error and make adjustment to the code so > > that it takes input from apache. > > > code that I am using is as follows : > > > #! /usr/bin/env python > > import sys,os > > pid = os.fork() > > os.chdir("/var/www/html/") > > os.setsid() > > os.umask(0) > > #this line will read apache log in real time as redirected from the > > CustomLog directive of Apache. > > log = sys.stdin.readlines() > > f = open('/var/www/logmongo.txt','a') # append log to this text file > > f.write(log) > > > I'd appreciate if anybody could share the code that they used for > > daemon or used with Apache CustomLog directive. > > The above code looks errornous - you don't check for the return-value of > PID & take appropriate action. Like > > There is a daemonization recipe on active-state, which works nicely for > me. > > http://code.activestate.com/recipes/278731-creating-a-daemon-the-pyth... > > Diez Hi Diez Thanks for pointing that out. Ever tried giving input to such python daemons from a dynamic source like Apache logs which get generated in real time. I want apache to directly write to this python daemon which in turn will process the logs the way I want. Any help will help me immensely. From debatem1 at gmail.com Tue Sep 21 14:32:42 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 21 Sep 2010 11:32:42 -0700 Subject: Down with tinyurl! In-Reply-To: <8739t3m1aa.fsf@castleamber.com> References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <8739t3m1aa.fsf@castleamber.com> Message-ID: On Tue, Sep 21, 2010 at 10:53 AM, John Bokma wrote: > geremy condra writes: > >> It's a joke. Admittedly it's a bit pointed, but it's a joke >> nonetheless, and it does at least provide what I consider to be two >> valuable pieces of information: that you should have googled this >> before asking, and what you should have googled for. If I miss and >> you've done your homework already, well, at least you get the smug >> satisfaction of knowing that I was too stupid to understand your >> question. > > It makes you a patronizing fuck in my book. And no, that's not a joke. so you've said before. It still doesn't bother me, although it does make me wonder how you're reading my posts- I was under the impression that you'd killfiled me at some point. Geremy Condra From tobias.koeck at gmail.com Tue Sep 21 14:35:14 2010 From: tobias.koeck at gmail.com (joblack) Date: Tue, 21 Sep 2010 11:35:14 -0700 (PDT) Subject: polymorphic function question Message-ID: <93d149a0-5d66-422f-ae5b-39fceff5f531@a11g2000vbn.googlegroups.com> Let's say I've got a function with def doesSomething(A='bla'): ... and I try to call it with a non existent variable with doesSomething(DoesNotExist) What will happen? Will it throw an exception or will it take the defautl value? From emile at fenx.com Tue Sep 21 14:38:11 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 21 Sep 2010 11:38:11 -0700 Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) In-Reply-To: References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> Message-ID: On 9/20/2010 7:55 PM Lawrence D'Oliveiro said... > In message, geremy > condra wrote: > >> Usually here that just means its a letmegooglethatforyou.com link, which I >> find more amusing than is probably healthy. > > Why hold back, I also use fuckinggoogleit.com. :) more than just a joke fuckinggoogleit.com is still an answer :) Emile From gh at gregor-horvath.com Tue Sep 21 14:39:08 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Tue, 21 Sep 2010 20:39:08 +0200 Subject: polymorphic function question References: <93d149a0-5d66-422f-ae5b-39fceff5f531@a11g2000vbn.googlegroups.com> Message-ID: <20100921203908.32c359ee@valun> Am Tue, 21 Sep 2010 11:35:14 -0700 (PDT) schrieb joblack : > Let's say I've got a function with > > def doesSomething(A='bla'): > ... > > and I try to call it with a non existent variable with > > doesSomething(DoesNotExist) > > What will happen? Will it throw an exception or will it take the > defautl value? The interpreter is omniscient, just ask him: Python 2.6.6 (r266:84292, Aug 29 2010, 12:36:23) [GCC 4.4.5 20100824 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def doesSomething(A='bla'): ... pass ... >>> doesSomething(DoesNotExist) Traceback (most recent call last): File "", line 1, in NameError: name 'DoesNotExist' is not defined -- Greg From astley.lejasper at gmail.com Tue Sep 21 14:41:04 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Tue, 21 Sep 2010 11:41:04 -0700 (PDT) Subject: Grouping pairs - suggested tools References: <79047d2d-4d9a-4e74-b44b-1010cf033525@t11g2000vbc.googlegroups.com> Message-ID: <0e2d95a1-af00-4f2a-acf8-dfa7ef1da80c@c32g2000vbq.googlegroups.com> > I think you have the same bug as Alf's code, you never merge existing > groups. Have you tried Arnaud's counterexample? > > By the way, are ('a', 'b') and ('b', 'a') to be considered equivalent for > your problem? > > Peter Hi Peter, Yes. I realise that this doesn't take into account existing relationships/groupings. For the particular situation that I am looking at this is unlikely to happen and/or not critical. However, I understand that generally you would want to potentially assign an item to one or more groups. In my case the ('a','b') and ('b','a') are equivalent. Perhaps for anyone else looking at this, I can elaborate on the problem to make it a bit more concrete. I have a very long listing of customer details and am trying to clean the data. In particular I am looking for duplicates: << Core Data >> id, Name, Address a, Acme Ltd, 1 Main Street b, Acme Limited, 1 Main St c, Acme L'td, 1 Main Street d, Smiths, 22 Upper Road e, Smyths, 22 Upper Rd f, Smiths ltd, 22 Upperrd g, Apple Empire, 222 Lower Way h, Apple Emp, 222 Lower Way Obviously this is oversimplified. The actual dataset has thousands of records. I am using the difflib module and comparing each item against all those below it, and where the items are similar they are stored in a paired table << Paired Data >> id1, id2, relationship_strength a, b, 0.8 a, c, 0.88 b, c, 0.8 d, e, 0.75 d, f, 0.88 e, f, 0.87 g, h, 0.77 However, these pairing aren't so easy to read and I want to include the full address and account information so it's easier for the lucky person who is going to clean the data. And this is where the grouping cluster comes in. << Grouped Data >> group_id, id 1, a 1, b 1, c 2, d 2, e 2, f 3, g 3, h So in my situation those records that are very similar to each other will be clustered together. Thanks again. ALJ From nad at acm.org Tue Sep 21 14:42:53 2010 From: nad at acm.org (Ned Deily) Date: Tue, 21 Sep 2010 11:42:53 -0700 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: In article <87zkvbytnk.fsf at web.de>, deets at web.de (Diez B. Roggisch) wrote: > The point is that the distro doesn't care about the python eco > system. Which is what I care about, and a lot of people who want to ship > software. I don't think that is totally accurate or fair. There is regular participation in the python-dev group by packagers from various distros. For example, Matthias Klose is not only the primary Debian Python maintainer, he is also has commit privileges for Python itself and he regularly contributes patches. Currently, I see current Python 2.6.6 and 3.1.2 packages in Debian testing with current Python 2.7 and Python 3.2 alpha coming along in Debian experimental. -- Ned Deily, nad at acm.org From brian.curtin at gmail.com Tue Sep 21 14:56:36 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 21 Sep 2010 13:56:36 -0500 Subject: develop for Windows on GNU/Linux, using Python In-Reply-To: References: Message-ID: On Tue, Sep 21, 2010 at 03:36, Lawrence D'Oliveiro wrote: > In message , Kev > Dwyer > wrote: > > > To be confident that your code is good you need to test it on a Windows > > box (we all test, right?). > > Preferably more than one. Test with Seven as well as Vista (yes, there are > still some Vista users out there). What about the difference between > Starter > versus Home Basic versus Home Premium versus Professional versus Ultimate > versus whatever? To be 100% safe, you probably need to test with all those > as well. > > Test on machines running the various major antivirus packages, because you > have no idea how they might screw things up. > > In other words, with Windows the guideline is: test till it hurts. Then > test > some more. Testing with every single Win7 SKU is not necessary. The Windows API is the same on all of them, the file system is the same, they are the same underlying operating system, but they are equipped with different types of tools. For example, at one of those levels they enable Terminal Server, something that should not affect your project (unless your project is a Terminal Server related tool, of course). For CPython, we test with XP (Win32 API version 5.1) and 7 (ver 6.1, same as Server 2008 R2). I have previously done a lot of my development on Server 2003 (ver 5.2, same as XP x64), although there is no buildbot slave running for that OS. If I need anything tested for Vista (ver 6.0, same as Server 2008), another OS without a buildbot slave, I know of a Vista user that can usually lend a hand. There would be no benefit to us to test CPython on all available releases of each OS -- it would be more of a burden, actually. As for antivirus screwing things up, that may be of interest to some projects, mainly those opening and then deleting files very quickly. The CPython test suite occasionally runs into issues deleting temporary files because the AV tools that some users have installed try to scan them in the very small time frame the file is intended to exist. TortoiseSVN also latches on long enough that handles to the file exist when a test tries to clean up after itself, thus causing seemingly random test failures. There's an open issue to fix that, though. -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Tue Sep 21 15:34:17 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 21 Sep 2010 12:34:17 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: On 21 Sep, 11:13, Peter Otten <__pete... at web.de> wrote: [...] > > A straightforward implementation: > > $ cat group_edges.py > def find_groups(edges): > ? ? lookup = {} # node --> group > ? ? groups = {} # id(group) --> group > ? ? for a, b in edges: ? ? ? ? ? ? ? > ? ? ? ? if a in lookup: ? ? ? ? ? ? ? > ? ? ? ? ? ? if b in lookup: ? ? ? ? ? > ? ? ? ? ? ? ? ? ga = lookup[a] ? ? ? > ? ? ? ? ? ? ? ? gb = lookup[b] ? ? ? > ? ? ? ? ? ? ? ? if ga is not gb: ? ? > ? ? ? ? ? ? ? ? ? ? # merge groups ? > ? ? ? ? ? ? ? ? ? ? if len(ga) < len(gb): > ? ? ? ? ? ? ? ? ? ? ? ? # always update the smaller group > ? ? ? ? ? ? ? ? ? ? ? ? ga, gb = gb, ga ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? del groups[id(gb)] ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ga.update(gb) ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? for k in gb: ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? lookup[k] = ga ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? # add b to a's group ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ga = lookup[a] > ? ? ? ? ? ? ? ? ga.add(b) > ? ? ? ? ? ? ? ? lookup[b] = ga > ? ? ? ? elif b in lookup: > ? ? ? ? ? ? # add a to b's group > ? ? ? ? ? ? gb = lookup[b] > ? ? ? ? ? ? gb.add(a) > ? ? ? ? ? ? lookup[a] = gb > ? ? ? ? else: > ? ? ? ? ? ? # create new group > ? ? ? ? ? ? g = set((a, b)) > ? ? ? ? ? ? groups[id(g)] = g > ? ? ? ? ? ? lookup[a] = lookup[b] = g > ? ? return groups.values() > > def show_groups(edges): > ? ? groups = sorted(sorted(g) for g in find_groups(edges)) > ? ? for i, group in enumerate(groups, 1): > ? ? ? ? for node in sorted(group): > ? ? ? ? ? ? print i, node > I think I would go for the two-step approach of constructing the graph first and then recursively building connected components. It sounds more complicated at first but when you implement it it turns out quite simple: from collections import defaultdict from itertools import count def build_groups(edges): neighbors = defaultdict(set) for x, y in edges: neighbors[x].add(y) neighbors[y].add(x) groups, group_indices = {}, count(1) def set_group(x, group_index): groups[x] = group_index for y in neighbors[x]: if y not in groups: set_group(y, group_index) for x in neighbors: if x not in groups: set_group(x, group_indices.next()) return groups if __name__ == "__main__": def print_groups(edges): print " ".join(edges) groups = build_groups(edges) for x, i in sorted(groups.items()): print i, x print examples = [ ['ab', 'bc', 'ad', 'ef', 'gf', 'hi'], ['ac', 'bd', 'cd'], ] for edges in examples: print_groups(edges) $ python connected.py ab bc ad ef gf hi 1 a 1 b 1 c 1 d 2 e 2 f 2 g 3 h 3 i ac bd cd 1 a 1 b 1 c 1 d -- Arnaud From python at rcn.com Tue Sep 21 15:41:40 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 21 Sep 2010 12:41:40 -0700 (PDT) Subject: Combinations or Permutations References: Message-ID: <88b36889-e55b-415e-8a12-9611304683c1@l25g2000prn.googlegroups.com> On Sep 20, 1:54?pm, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] Try this: >>> from itertools import combinations >>> list(combinations('abcde', 2)) [('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'), ('b', 'c'), ('b', 'd'), ('b', 'e'), ('c', 'd'), ('c', 'e'), ('d', 'e')] Raymond From raoulbia at gmail.com Tue Sep 21 16:35:09 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 21 Sep 2010 13:35:09 -0700 (PDT) Subject: basic 2 player wordgame References: <0f3ae081-cab9-43d9-9ddd-2f3f6926dc9d@a11g2000vbn.googlegroups.com> Message-ID: On Sep 21, 1:39?pm, Mel wrote: > Baba wrote: > > I am working on a simple wordgame exercise: 2 players form a word by > > alternating turns saying a letter, which is added on to the end of the > > word fragment. > > > I am familiar with loops, iterations etc but i need a hint as to how > > to approach alternating turns when writing this code? > > One way (not tested): > > thisplayer = Player() > otherplayer = Player() > while not_won: > ? ? thisplayer.take_turn() > ? ? thisplayer, otherplayer = otherplayer, thisplayer > > ? ? ? ? Mel. Hi Mel, Thank you very much. Your suggestion works like a charm :) def alternating_turns(): hand = [] thisPlayer = 'player1' otherPlayer = 'player2' while len(hand) < 3: print 'turn %s: ' %(thisPlayer) letter = raw_input('enter letter: ') hand.append(letter) thisPlayer, otherPlayer = otherPlayer, thisPlayer print hand alternating_turns() thanks again! much appreciated. this was a first for me where i have learned a practical way to apply mutation. Baba From antroy at gmail.com Tue Sep 21 16:54:55 2010 From: antroy at gmail.com (Ant) Date: Tue, 21 Sep 2010 13:54:55 -0700 (PDT) Subject: Python in Linux - barrier to Python 3.x References: Message-ID: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> On Sep 21, 2:04?pm, Philip Semanchuk wrote: > On Sep 21, 2010, at 8:29 AM, Ant wrote: > Don't know about Python 3 on Fedora (I use a Mac), but distrowatch.org reports that Fedora has been using Python >= 2.6 since Fedora 11 which was released in June of 2009. Yes you are right - I've checked on my home machine, and it is indeed 2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading an OS in order to get the latest version of one package is a bit much! I know that this is a distribution issue, and not strictly a Python one, but the issue exists primarily because python is such a successful language it has become deeply embedded in linux distributions, and so there is now a lot of work involved in checking that a python upgrade doesn't break things. Some solution involving virtualenv is perhaps a possibility. From magawake at gmail.com Tue Sep 21 18:04:24 2010 From: magawake at gmail.com (Mag Gam) Date: Tue, 21 Sep 2010 18:04:24 -0400 Subject: ncurses pad question Message-ID: I am having some trouble understanding how padding/windowing works for Python curses. According to this example on http://docs.python.org/howto/curses.html I see: pad = curses.newpad(100, 100) # These loops fill the pad with letters; this is # explained in the next section for y in range(0, 100): for x in range(0, 100): try: pad.addch(y,x, ord('a') + (x*x+y*y) % 26 ) except curses.error: pass # Displays a section of the pad in the middle of the screen pad.refresh( 0,0, 5,5, 20,75) Now if I want another pad, lets call it: pad1=curses.newpad(100,300) pad1.addch(0,0,ord('X')) pad1.refresh(0,0,120,120,110,130) For some reason I get, pad1.refresh(0,0,120,130,140,180) _curses.error:prefresh() return ERR Any ideas? From jsf80238 at gmail.com Tue Sep 21 18:06:00 2010 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 21 Sep 2010 15:06:00 -0700 Subject: Subprocess does not return for longer-running process Message-ID: Hello, The Popen call does not return if the underlying OS call runs longish, as the example below shows. Although, if the underlying OS call is merely "sleep N" it will return even after quite a long time. wikiuser at dvprwiki1:~> python --version Python 2.6.4 wikiuser at dvprwiki1:~> time /opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space TIS --user cli --password cli | head -1 132 pages in list real??? 0m1.245s user??? 0m1.482s sys???? 0m0.153s wikiuser at dvprwiki1:~> time /opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space Oncall --user cli --password cli | head -1 19645 pages in list real??? 0m14.425s user??? 0m9.866s sys???? 0m1.110s wikiuser at dvprwiki1:~> cat $HOME/scripts/subprocess_test.py #!/usr/bin/env python import os, sys from subprocess import Popen, PIPE def execute(command_list=["sleep", "1"]): ??? process = Popen(command_list, shell=False, stdout=PIPE) ??? (pid, exit_code) = os.waitpid(process.pid, 0) ??? if process.stdout != None: ??????? print process.stdout.read() ??? if process.stderr != None: ??????? print process.stderr.read() ??? return exit_code if __name__ == "__main__": ??? if len(sys.argv) > 1: ??????? execute(sys.argv[1].split()) ??? else: ??????? execute() wikiuser at dvprwiki1:~> time $HOME/scripts/subprocess_test.py "/opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space TIS --user cli --password cli" | head -1 132 pages in list real??? 0m1.233s user??? 0m1.437s sys???? 0m0.169s wikiuser at dvprwiki1:~> time $HOME/scripts/subprocess_test.py "/opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space Oncall --user cli --password cli" | head -1 Traceback (most recent call last): ? File "$HOME/scripts/subprocess_test.py", line 18, in ??? execute(sys.argv[1].split()) ? File "$HOME/scripts/subprocess_test.py", line 9, in execute ??? (pid, exit_code) = os.waitpid(process.pid, 0) KeyboardInterrupt real??? 1m25.306s user??? 0m0.021s sys???? 0m0.035s (Note I killed this last command with CNTL-C.) From burton at userful.com Tue Sep 21 18:26:33 2010 From: burton at userful.com (Burton Samograd) Date: Tue, 21 Sep 2010 16:26:33 -0600 Subject: naming the main module in embedded Python References: Message-ID: Tomasz Koziara writes: > I am embedding Python as an interpret in my code. Now, whenever my > code or Python itself issues an error/warning message I am getting > something like: > > File "", line 1, in > > or > > __main__:46: RuntimeWarning: My warning message > > I am using PyRun_SimpleString to load part of the code and the I call: > > sprintf (line, "execfile ('%s')", path); > error = PyRun_SimpleString (line). > > The question is: how can I set up the module name or input file name > so that my error/warning messages output them rather than the above > default values? Use this rather than execfile: exec compile(code, filename, "exec") You'll have to read the contents of the file into the string 'code' first (unless compile will take a file object, which I'm not sure about). -- Burton Samograd From mail at hellmutweber.de Tue Sep 21 18:31:04 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Wed, 22 Sep 2010 00:31:04 +0200 Subject: how to get partition information of a hard disk with python Message-ID: <4C993228.4000201@hellmutweber.de> Hi list, I'm looking for a possibility to access the partiton inforamtion of a hard disk of my computer from within a python program. Googling I found the module 'parted' but didn't see any possibility to get the desired information. Is there any reasonable documentation for the parted module? Any idea is appreciated ;-) TIA Hellmut -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From raoulbia at gmail.com Tue Sep 21 18:39:05 2010 From: raoulbia at gmail.com (Baba) Date: Tue, 21 Sep 2010 15:39:05 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) Message-ID: Hi query level: beginner as part of a learning exercise i have written code that: a) asks for a single letter input (assumption: only 1 letter wil be entered) b) adds that letter to list1 and then goes through list2 and checks: 1) if any item in list2 starts with list1 > if False: break 2) if list1 == any item in list2 > if True: break c) start again until 2) is True wordlist = ['hello', 'bye'] handlist = [] letter = raw_input('enter letter: ') handlist.append(letter) hand = "".join(handlist) for item in wordlist: if item.startswith(hand): while item.startswith(hand): if hand not in wordlist: letter = raw_input('enter letter: ') handlist.append(letter) hand = "".join(handlist) else: break else: break print 'you loose' this code works but can it be optimised? i have the feeling that my nesting of IF, WHILE and FOR statements is overkill? inspired by part IV of http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset5.pdf thanks Baba From python at bdurham.com Tue Sep 21 19:10:42 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 21 Sep 2010 19:10:42 -0400 Subject: Iterate through a single iterator from multiple places in a loop Message-ID: <1285110642.16994.1396217467@webmail.messagingengine.com> Is there a pythonic way to loop through a single iterator from multiple places in a loop? Here's pseudo code for what I would like to do: for char in some_long_string: if char == some_char: for char in some_long_string: <--- using same iterator as above # continue to pull chars from some_long_string # until some conditions are met # repeat above pattern again several times in the loop, # with iterator access potentially nested One solution might be to convert some_long_string into a generator that pops of a single character at a time? Is there a simple way wrap a string as a generator or do I need to create a custom function for this? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Sep 21 19:14:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Sep 2010 00:14:30 +0100 Subject: how to get partition information of a hard disk with python In-Reply-To: <4C993228.4000201@hellmutweber.de> References: <4C993228.4000201@hellmutweber.de> Message-ID: <4C993C56.2050005@mrabarnett.plus.com> On 21/09/2010 23:31, Hellmut Weber wrote: > Hi list, > I'm looking for a possibility to access the partiton inforamtion of a > hard disk of my computer from within a python program. > > Googling I found the module 'parted' but didn't see any possibility to > get the desired information. > Is there any reasonable documentation for the parted module? > > Any idea is appreciated ;-) > Did you see this: http://www.gnu.org/software/parted/manual/ From deets at web.de Tue Sep 21 19:16:18 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 22 Sep 2010 01:16:18 +0200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: Ned Deily writes: > In article <87zkvbytnk.fsf at web.de>, deets at web.de (Diez B. Roggisch) > wrote: >> The point is that the distro doesn't care about the python eco >> system. Which is what I care about, and a lot of people who want to ship >> software. > > I don't think that is totally accurate or fair. There is regular > participation in the python-dev group by packagers from various distros. > For example, Matthias Klose is not only the primary Debian Python > maintainer, he is also has commit privileges for Python itself and he > regularly contributes patches. Currently, I see current Python 2.6.6 > and 3.1.2 packages in Debian testing with current Python 2.7 and Python > 3.2 alpha coming along in Debian experimental. I'm sorry, this was worded stronger than appropriate. Let me rephrase: The distros have their own (perfectly reasonable) agenda. Yet this may still conflict with the needs of users regarding e.g. contemporary package availability. I already mentioned in another post that the current debian stable features TurboGears 1.0.4. Which is by itself a problem, but also ties a lot of dependencies to "ancient" versions. So frankly, if I want to run (which in fact I do) a perfecly fine TurboGears2 system on lenny, I'm *forced* to use virtualenv and consorts. In other words: I think that the goals of a linux distribution don't necessarily are the same than those of a python package maintainer. In an ideal world, they would be congruent. But they aren't. My wish would be that unless that this congruency is achieved (which isn't feasible I fear), a python-only package management solution can be implemented and be adopted even by the distros without neglecting their own issues. Diez From ben+python at benfinney.id.au Tue Sep 21 19:19:12 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 22 Sep 2010 09:19:12 +1000 Subject: creating python daemon ? References: Message-ID: <87tyli4rdb.fsf@benfinney.id.au> vineet daniel writes: > I'd appreciate if anybody could share the code that they used for > daemon or used with Apache CustomLog directive. I don't know about using Apache's CustomLog, but the ?python-daemon? library is specifically intended for creating a well-behaved Unix daemon . -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but if they called them ?Sad Meals?, kids wouldn't buy | _o__) them!? ?_Pinky and The Brain_ | Ben Finney From python at mrabarnett.plus.com Tue Sep 21 19:27:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Sep 2010 00:27:25 +0100 Subject: Iterate through a single iterator from multiple places in a loop In-Reply-To: <1285110642.16994.1396217467@webmail.messagingengine.com> References: <1285110642.16994.1396217467@webmail.messagingengine.com> Message-ID: <4C993F5D.4090205@mrabarnett.plus.com> On 22/09/2010 00:10, python at bdurham.com wrote: > Is there a pythonic way to loop through a single iterator from > multiple places in a loop? > > Here's pseudo code for what I would like to do: > > for char in some_long_string: > if char == some_char: > for char in some_long_string: <--- using same iterator as above > # continue to pull chars from some_long_string > # until some conditions are met > > # repeat above pattern again several times in the loop, > # with iterator access potentially nested > > One solution might be to convert some_long_string into a generator > that pops of a single character at a time? > > Is there a simple way wrap a string as a generator or do I need to > create a custom function for this? it = iter(some_long_string) for char in it: if char == some_char: for char in it: # continue to pull chars from some_long_string # until some conditions are met # repeat above pattern again several times in the loop, # with iterator access potentially nested From python at bdurham.com Tue Sep 21 19:46:39 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 21 Sep 2010 19:46:39 -0400 Subject: Thank-you (Re: Iterate through a single iterator from multiple places in a loop) In-Reply-To: <4C993F5D.4090205@mrabarnett.plus.com> References: <1285110642.16994.1396217467@webmail.messagingengine.com> <4C993F5D.4090205@mrabarnett.plus.com> Message-ID: <1285112799.24980.1396223079@webmail.messagingengine.com> MRAB, > it = iter(some_long_string) Well, that was easy! :) Thanks for your help. Malcolm ----- Original message ----- From: "MRAB" To: python-list at python.org Date: Wed, 22 Sep 2010 00:27:25 +0100 Subject: Re: Iterate through a single iterator from multiple places in a loop On 22/09/2010 00:10, python at bdurham.com wrote: > Is there a pythonic way to loop through a single iterator from > multiple places in a loop? > > Here's pseudo code for what I would like to do: > > for char in some_long_string: > if char == some_char: > for char in some_long_string: <--- using same iterator as above > # continue to pull chars from some_long_string > # until some conditions are met > > # repeat above pattern again several times in the loop, > # with iterator access potentially nested > > One solution might be to convert some_long_string into a generator > that pops of a single character at a time? > > Is there a simple way wrap a string as a generator or do I need to > create a custom function for this? it = iter(some_long_string) for char in it: if char == some_char: for char in it: # continue to pull chars from some_long_string # until some conditions are met # repeat above pattern again several times in the loop, # with iterator access potentially nested -- http://mail.python.org/mailman/listinfo/python-list From nad at acm.org Tue Sep 21 20:17:59 2010 From: nad at acm.org (Ned Deily) Date: Tue, 21 Sep 2010 17:17:59 -0700 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: In article , deets at web.de (Diez B. Roggisch) wrote: > Ned Deily writes: > > In article <87zkvbytnk.fsf at web.de>, deets at web.de (Diez B. Roggisch) > > wrote: > >> The point is that the distro doesn't care about the python eco > >> system. Which is what I care about, and a lot of people who want to ship > >> software. > > I don't think that is totally accurate or fair. There is regular > > participation in the python-dev group by packagers from various distros. > > For example, Matthias Klose is not only the primary Debian Python > > maintainer, he is also has commit privileges for Python itself and he > > regularly contributes patches. Currently, I see current Python 2.6.6 > > and 3.1.2 packages in Debian testing with current Python 2.7 and Python > > 3.2 alpha coming along in Debian experimental. > > I'm sorry, this was worded stronger than appropriate. Let me rephrase: > The distros have their own (perfectly reasonable) agenda. Yet this may > still conflict with the needs of users regarding e.g. contemporary > package availability. I already mentioned in another post that the > current debian stable features TurboGears 1.0.4. Which is by itself a > problem, but also ties a lot of dependencies to "ancient" versions. So > frankly, if I want to run (which in fact I do) a perfecly fine > TurboGears2 system on lenny, I'm *forced* to use virtualenv and > consorts. > > In other words: I think that the goals of a linux distribution don't > necessarily are the same than those of a python package maintainer. In > an ideal world, they would be congruent. But they aren't. My wish would > be that unless that this congruency is achieved (which isn't feasible I > fear), a > python-only package management solution can be implemented and be > adopted even by the distros without neglecting their own issues. Thanks for the clarification. While I too wish such a general python-only package management solution existed, the big blocker is and will remain the effort required to manage the package quirks (local patches), package dependencies, platform differences, unit testing, unit testing across multiple platforms, system testing (packages with their dependencies - think Django or Zope), packaging and distribution. In short think of all the steps and infrastructure that go into, say, the Debian development process, which - not to slight the others out there - I consider to be the most mature and rigorous of the large open source integration projects. While much of it can be (and, to some extent, already is) automated, there is still a strong human involvement required at nearly all stages. Repeatable and predictable does not necessarily mean totally automated or scalable. Getting to where Debian is today has required an almost superhuman and ongoing effort and dedication over many years by many people. Having been intimately involved over the years in various software release processes most involving hundreds of people, I remain somewhat awestruck in what they have accomplished. I'm not optimistic that the resources or leadership are available in the community to make something similar happen for Python packages. It's an enormous task. -- Ned Deily, nad at acm.org From clp2 at rebertia.com Tue Sep 21 20:33:25 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 21 Sep 2010 17:33:25 -0700 Subject: Subprocess does not return for longer-running process In-Reply-To: References: Message-ID: On Tue, Sep 21, 2010 at 3:06 PM, Jason Friedman wrote: > Hello, > > The Popen call does not return if the underlying OS call runs longish, > as the example below shows. > wikiuser at dvprwiki1:~> time $HOME/scripts/subprocess_test.py > "/opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space > Oncall --user cli --password cli" | head -1 > Traceback (most recent call last): > ? File "$HOME/scripts/subprocess_test.py", line 18, in > ??? execute(sys.argv[1].split()) > ? File "$HOME/scripts/subprocess_test.py", line 9, in execute > ??? (pid, exit_code) = os.waitpid(process.pid, 0) > KeyboardInterrupt > > real??? 1m25.306s > user??? 0m0.021s > sys???? 0m0.035s > > (Note I killed this last command with CNTL-C.) As your Traceback clearly indicates, the Popen() call has already completed; it's *the os.waitpid() call* that's blocking, but that's entirely to be expected given its defined behavior. If you don't want to wait around for the process to die, then don't call waitpid() on it in the first place! Cheers, Chris From rplasson at gmail.com Tue Sep 21 22:38:06 2010 From: rplasson at gmail.com (=?ISO-8859-1?Q?Rapha=EBl_Plasson?=) Date: Tue, 21 Sep 2010 19:38:06 -0700 (PDT) Subject: Best way for rotating a matrix of data? Message-ID: <3207b8a9-a566-478d-a5db-859db162b8e4@p24g2000pra.googlegroups.com> Hello, after some computations, I obtain a 2D matrix of data, in a numpy array. I can easily plot them using pyplot, and can easily extract either vertical or horizontal slices by plotting a row or a column of this matrix. I would like to be able to plot slices form this data array, but with an arbitrary angle. Thus my question: what is the best way to do so? For the moment the solution I am using is to go through image transformation, using PIL, by a function returning : array(Image.fromarray().rotate(,resample=Image.BICUBIC)) In short, I convert the array in an image object, I rotate it, and then convert it back to an array. Not very clean, rather a work around than a solution, indeed. Actually, I more precisely extract my 2D array from much higher dimensions data (i.e. 10-20 fields of different data in 3 dimensions of space+1 dimension of time), contained in a hdf5 file. I typically would like to extract arbitrary slices of any of the fields from the 3+1D space... and I don't really know how this can be simply done. I can only extract an "orthogonal" 2D space from this space, and rotate it with the above method. Is there a more direct way to extract arbitrary slices directly from 2/3/4D arrays? Which python modules would be able to do the job? Thank you, Raphael From gburdell1 at gmail.com Tue Sep 21 23:03:42 2010 From: gburdell1 at gmail.com (gburdell1 at gmail.com) Date: Tue, 21 Sep 2010 20:03:42 -0700 (PDT) Subject: Expanding a vector by replicating elements individually Message-ID: Given m=numpy.array([[1, 2, 3]]) I want to obtain array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) One way I've found to do this is: numpy.reshape(numpy.tile(m,(4,1)),(12,1),'f').T Another way is: numpy.reshape(numpy.tile(m,(4,1)).flatten(1),(1,12)) Is there a simpler way to do this, without having to go jump through so many hoops? From kushal.kumaran at gmail.com Tue Sep 21 23:28:31 2010 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Wed, 22 Sep 2010 08:58:31 +0530 Subject: [OT] apache customlog (was Re: creating python daemon ?) Message-ID: On 9/21/10, vineet daniel wrote: > Hi > > I have succesfully created daemon with python script and as next step > I am trying to give input to that python script daemon from Apache > Logs....here I have got stuck and I have even checked IRC python > channel for solution. Apache is able to call the file but fails to > execute it properly and I get this error continuosly : > > piped log program '/var/www/html/test.py' failed unexpectedly > > How do I rectify the above error and make adjustment to the code so > that it takes input from apache. > > >From a quick look at the CustomLog docs, it doesn't seem that you need a daemon. Apache will simply run your program and send logging directives to your program's stdin. In fact, a daemon, which from apache's perspective just exits immediately, will give you the behaviour you're seeing. Googling around should result in some examples. -- regards, kushal From python at rcn.com Wed Sep 22 00:38:40 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 21 Sep 2010 21:38:40 -0700 (PDT) Subject: Overriding dict constructor References: <4c974177$0$11113$c3e8da3@news.astraweb.com> Message-ID: <27971e53-c135-443c-bece-d1535bc2ff62@g6g2000pro.googlegroups.com> [Steven D'Aprano] > But if I try to create a regular dict from this, dict() doesn't call my > __getitem__ method: > > >>> dict(d) > > {0: ('a', 'extra_data'), 1: ('b', 'extra_data')} > > instead of {0: 'a', 1: 'b'} as I expected. > > How can I fix this? Try using dict(d.items()). Raymond From __peter__ at web.de Wed Sep 22 02:30:42 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Sep 2010 08:30:42 +0200 Subject: Expanding a vector by replicating elements individually References: Message-ID: gburdell1 at gmail.com wrote: > Given > > m=numpy.array([[1, 2, 3]]) > > I want to obtain > > array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) >>> numpy.array([1,2,3]).repeat(4) array([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) Peter From nagle at animats.com Wed Sep 22 02:46:20 2010 From: nagle at animats.com (John Nagle) Date: Tue, 21 Sep 2010 23:46:20 -0700 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: <4c99a64e$0$1651$742ec2ed@news.sonic.net> On 9/21/2010 11:42 AM, Ned Deily wrote: > In article<87zkvbytnk.fsf at web.de>, deets at web.de (Diez B. Roggisch) > wrote: >> The point is that the distro doesn't care about the python eco >> system. Which is what I care about, and a lot of people who want to ship >> software. > > I don't think that is totally accurate or fair. There is regular > participation in the python-dev group by packagers from various distros. > For example, Matthias Klose is not only the primary Debian Python > maintainer, he is also has commit privileges for Python itself and he > regularly contributes patches. Currently, I see current Python 2.6.6 > and 3.1.2 packages in Debian testing with current Python 2.7 and Python > 3.2 alpha coming along in Debian experimental. Debian seems to have a well worked out Python policy: http://www.debian.org/doc/packaging-manuals/python-policy/ They address the need to have multiple versions of Python on the same machine in a reasonably clean way. So do the ActiveState people, although their way is different than the Debian way. Trying to make Python play well with distros is probably more useful than trying to make distros play well with Python. Rather than fancier "distutils" or "eggs", I'd suggest developing tools that take in "setup.py" files and make Windows installers, RPMs, or whatever the platform likes. John Nagle From eckhardt at satorlaser.com Wed Sep 22 03:16:12 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 22 Sep 2010 09:16:12 +0200 Subject: utf-8 coding sometimes it works, most of the time it don't work. References: Message-ID: Stef Mientki wrote: > When running this python application from the command line ( or launched > from another Python program), the wrong character encoding (probably > windows-1252) is used. Rule #1: If you know the correct encoding, set it yourself. This particularly applies to files you open yourself (use the codec module). In the case of your program, I guess the stream with the faulty encoding is stdin/stdout, who's encoding is guessed by Python, but which you can override. Check sys.stdin.encoding. > When I run this program from PyScripter ( either internal engine or remote > engine), MSHTML shows the correct character encoding, > perfect! Interesting, I would say that PyScripter sets up the environment differently, so that Python guesses a different encoding. Also make sure both are calling the same Python, I get 'cp850' or 'US-ASCII' depending on whether I call the native MS Windows Python or the Cygwin Python. > In the main file, and in the major files that constains strings I've added > the following 2 lines: > # -*- coding: utf-8 -*- > from __future__ import absolute_import, unicode_literals This shouldn't matter. This just tells Python that the sourcecode itself is encoded in UTF-8 and that you want to use Unicode names in your string literals, it doesn't affect the output of your program. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Wed Sep 22 03:30:42 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Sep 2010 09:30:42 +0200 Subject: Grouping pairs - suggested tools References: Message-ID: Arnaud Delobelle wrote: > I think I would go for the two-step approach of constructing the graph > first and then recursively building connected components. It sounds > more complicated at first but when you implement it it turns out quite > simple: > > from collections import defaultdict > from itertools import count > > def build_groups(edges): > neighbors = defaultdict(set) > for x, y in edges: > neighbors[x].add(y) > neighbors[y].add(x) > > groups, group_indices = {}, count(1) > def set_group(x, group_index): > groups[x] = group_index > for y in neighbors[x]: > if y not in groups: > set_group(y, group_index) > > for x in neighbors: > if x not in groups: > set_group(x, group_indices.next()) > return groups That looks a little less like legwork than mine. My only objection is that you may hit Python's low recursion limit. Peter From bruno.42.desthuilliers at websiteburo.invalid Wed Sep 22 03:59:13 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 22 Sep 2010 09:59:13 +0200 Subject: This Is International =?UTF-8?B?RG9u4oCZdC1TcXVhd2stTGlrZS1B?= =?UTF-8?B?LVBhcnJvdCBEYXk=?= In-Reply-To: References: Message-ID: <4c99b745$0$9306$426a34cc@news.free.fr> Lawrence D'Oliveiro a ?crit : > Next we need an International Surfin? Bird day, a day to go around and tell > everybody that the bird bird bird, the bird is the word. +1 From stef.mientki at gmail.com Wed Sep 22 04:15:30 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 22 Sep 2010 10:15:30 +0200 Subject: utf-8 coding sometimes it works, most of the time it don't work. In-Reply-To: References: Message-ID: hello Uli, thanks, I think you hit the nail on it's head, PyScripter indeed changes default encoding but .. On Wed, Sep 22, 2010 at 9:16 AM, Ulrich Eckhardt wrote: > Stef Mientki wrote: > > When running this python application from the command line ( or launched > > from another Python program), the wrong character encoding (probably > > windows-1252) is used. > > Rule #1: If you know the correct encoding, set it yourself. This > particularly applies to files you open yourself (use the codec module). In > the case of your program, I guess the stream with the faulty encoding is > stdin/stdout, who's encoding is guessed by Python, but which you can > override. Check sys.stdin.encoding. > None, So I guess it's using the windows default, which is windows-1252, and it's ReadOnly so I can't change it. Can you tell me how I change the default Python encoding, or how to set the encoding in Popen, this is the statement I use to launch my program subprocess.Popen ( [ 'python', Filename ] ) thanks, Stef Mientki > > > When I run this program from PyScripter ( either internal engine or > remote > > engine), MSHTML shows the correct character encoding, > > perfect! > > Interesting, I would say that PyScripter sets up the environment > differently, so that Python guesses a different encoding. Also make sure > both are calling the same Python, I get 'cp850' or 'US-ASCII' depending on > whether I call the native MS Windows Python or the Cygwin Python. > > > In the main file, and in the major files that constains strings I've > added > > the following 2 lines: > > # -*- coding: utf-8 -*- > > from __future__ import absolute_import, unicode_literals > > This shouldn't matter. This just tells Python that the sourcecode itself is > encoded in UTF-8 and that you want to use Unicode names in your string > literals, it doesn't affect the output of your program. > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Wed Sep 22 04:29:53 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 22 Sep 2010 01:29:53 -0700 (PDT) Subject: Grouping pairs - suggested tools References: Message-ID: On Sep 22, 8:30?am, Peter Otten <__pete... at web.de> wrote: > Arnaud Delobelle wrote: > > I think I would go for the two-step approach of constructing the graph > > first and then recursively building connected components. ?It sounds > > more complicated at first but when you implement it it turns out quite > > simple: > > > from collections import defaultdict > > from itertools import count > > > def build_groups(edges): > > ? ? neighbors = defaultdict(set) > > ? ? for x, y in edges: > > ? ? ? ? neighbors[x].add(y) > > ? ? ? ? neighbors[y].add(x) > > > ? ? groups, group_indices = {}, count(1) > > ? ? def set_group(x, group_index): > > ? ? ? ? groups[x] = group_index > > ? ? ? ? for y in neighbors[x]: > > ? ? ? ? ? ? if y not in groups: > > ? ? ? ? ? ? ? ? set_group(y, group_index) > > > ? ? for x in neighbors: > > ? ? ? ? if x not in groups: > > ? ? ? ? ? ? set_group(x, group_indices.next()) > > ? ? return groups > > That looks a little less like legwork than mine. My only objection is that > you may hit Python's low recursion limit. > > Peter True. One could setrecursionlimit() temporarily to work around this. Or here is an alternative set_group() function: def set_group(x, group_index): group = [x] for y in group: groups[y] = group_index group.extend(z for z in neighbors[y] if z not in groups]) It's untested! -- Arnaud From deets at web.de Wed Sep 22 05:20:59 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 22 Sep 2010 11:20:59 +0200 Subject: creating python daemon ? References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> Message-ID: <87fwx2yw04.fsf@web.de> vineet daniel writes: > On Sep 21, 9:47?pm, de... at web.de (Diez B. Roggisch) wrote: >> vineet daniel writes: >> > Hi >> >> > I have succesfully created daemon with python script and as next step >> > I am trying to give input to that python script daemon from Apache >> > Logs....here I have got stuck and I have even checked IRC python >> > channel for solution. Apache is able to call the file but fails to >> > execute it properly and I get this error continuosly : >> >> > piped log program '/var/www/html/test.py' failed unexpectedly >> >> > How do I rectify the above error and make adjustment to the code so >> > that it takes input from apache. >> >> > code that I am using is as follows : >> >> > #! /usr/bin/env python >> > import sys,os >> > pid = os.fork() >> > os.chdir("/var/www/html/") >> > os.setsid() >> > os.umask(0) >> > #this line will read apache log in real time as redirected from the >> > CustomLog directive of Apache. >> > log = sys.stdin.readlines() >> > f = open('/var/www/logmongo.txt','a') # append log to this text file >> > f.write(log) >> >> > I'd appreciate if anybody could share the code that they used for >> > daemon or used with Apache CustomLog directive. >> >> The above code looks errornous - you don't check for the return-value of >> PID & take appropriate action. Like >> >> There is a daemonization recipe on active-state, which works nicely for >> me. >> >> http://code.activestate.com/recipes/278731-creating-a-daemon-the-pyth... >> >> Diez > > Hi Diez > > Thanks for pointing that out. > Ever tried giving input to such python daemons from a dynamic source > like Apache logs which get generated in real time. I want apache to > directly write to this python daemon which in turn will process the > logs the way I want. Any help will help me immensely. I don't understand the question. How is that input produced? How shall the two processes interact? Through some logfile one writes, the other reads? Through RPC-mechanisms? Sockets? Pipes? The fact that process B is a daemon or not has nothing to do with this whatsoever, btw. Diez From arunmohan.c at gmail.com Wed Sep 22 07:35:41 2010 From: arunmohan.c at gmail.com (AMC) Date: Wed, 22 Sep 2010 04:35:41 -0700 (PDT) Subject: Error installing cx_Oracle Message-ID: <7e622b5f-1715-472e-aa47-ea145305fa36@k22g2000prb.googlegroups.com> Hi, >From last months I am using Python for making small but useful tools for my team members. I am doing my development in windows machine and running the program in Solaris machine where Python 2.6.2 is installed. In one of my program file I had to use the module "cx_Oracle".For that I have installed the module in my windows machine and done the programming. But the finished program does not run in Solaris machine, may be because "cx_Oracle" was not installed there.Following is the error shown. root at access1:/home/amohan/python/work/broadcast_report/bin$ ./ runsql.py Traceback (most recent call last): File "./runsql.py", line 3, in import cx_Oracle ImportError: ld.so.1: isapython2.6: fatal: /opt/webstack/python/lib/ python2.6/site-packages/cx_Oracle.so: wrong ELF class: ELFCLASS64 root at access1:/home/amohan/python/work/broadcast_report/bin$ I tried installing "cx_Oracle" with easy_install utility (I am not strong in Solaris). While installing I am getting some error as shown below. root at access1:/$ easy_install cx_Oracle Searching for cx-Oracle Reading http://pypi.python.org/simple/cx_Oracle/ Reading http://cx-oracle.sourceforge.net Reading http://starship.python.net/crew/atuining Best match: cx-Oracle 5.0.4 Downloading http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4.tar.gz?download Processing cx_Oracle-5.0.4.tar.gz Running cx_Oracle-5.0.4/setup.py -q bdist_egg --dist-dir /tmp/ easy_install-FkDQn5/cx_Oracle-5.0.4/egg-dist-tmp-Ogg94s "SessionPool.c", line 200: warning: integer overflow detected: op "<<" ld: fatal: library -lpython2.6: not found ld: fatal: File processing errors. No output written to build/ lib.solaris-2.10-i86pc-2.6-10g/cx_Oracle.so error: Setup script exited with error: command '/opt/webstack/python/ lib/python2.6/pycc' failed with exit status 1 root at access1:/$ I have searched for a solution everywhere and tried many things but didn't work. Can somebody help me in this? Thanks, AMC. From saruviel at hotmail.com Wed Sep 22 09:52:58 2010 From: saruviel at hotmail.com (saruviel) Date: Wed, 22 Sep 2010 06:52:58 -0700 (PDT) Subject: Life Message-ID: <46df27ef-26ee-423e-aaa7-e75351a7e743@a7g2000prb.googlegroups.com> Life By Daniel Daly A series of, perhaps random thoughts, or if you take the time to try and make some coherent sense of the whole, perhaps something deeper. But probably not. I was inspired to start this task by the book ?By the Waters of Galilee? by Fr Luke Fay of Catholic faith. I had read the first two chapters, was enjoying it, and started thinking. And I thought of a work called ?Life? with a similar cover to the cover of Fr Fay?s work. And the idea was simply a writing of life. Perhaps the closest thing that was to come to it was a self-help book, but in its purest form I intended it to not even be that. Perhaps philosophy, but I am not trying to be philosophical, yet it probably is philosophy, even though that is not my intent. I simply wanted to write thoughts on life, thoughts about a positive moral life, which might make it almost a religious or spiritual text, but that was not the intent. It is simply to be about life, not a novel, not a work of science, but just thoughts on life. Perhaps I should be dramatic and write lovely poetical language about the wonders of creation in true King David style. King David wrote some of the Psalms in the Holy Bible and wrote about creation a bit. At least, the psalms are recorded as being written by King David, but some people (Funk of the Historical Jesus) says no to that from memory. I suppose as this work unfolds I will write about nature, but if I was perfectly honest I am no King David. I know I really should care about the plight of the whales and that Japan are really naughty, but I think they just like whale meat, so to hell with that. How about the oil spill off the American coast. Thank God its over there is probably the bottom line for this shallow environmentalist. Anyway, enough with current affairs. Actually, no, I will write on some current affairs. I prayed, a while back, for Kevin Rudd to be Prime Minister for 21 years. I am keeping the faith on that prayer, as I am a left wing idealist. My friend Adrian Chan is not the biggest fan of politicians, but I assume they generally have good intentions, and that the demands of satisfying everyone means they aggravate a lot of people. But that is only life after all. I like listening to music. I have schizophrenia so often go on mad rampages and destroy half of my cd collection in a fit of psychosis. But psychosis affects a lot of people, so I am not alone. I was at the pool recently and I thought up some ideas for a whacky book called ?Zen I?. The dialogue goes something like this. Zen Zen I Zen I Zen I Zen I Zen I Zen I Zen I Zen Zen Zen Zen I I I I Zen I Zen I Zen I Zen I Zen I Zen Zen Zen I Zen Zen I Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen Zen Zen Zen Zen Zen Zen Zen I Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen Zen Zen Zen Zen Zen Zen Zen I Zen I Zen I Zen Zen I Zen I Zen I Zen Zen I Zen I Zen Zen Zen Zen Zen Zen Zen Zen I I I I I Zen Zen I Zen Zen Zen I Zen I Zen I Zen I & so on and so forth in about 40 pages of a little hardback anthology. On the final page the last line goes: Zen Zen I Zen I Zen I Zen Zen (4XQR#) Zen I Zen I Zen I It is non stop Zen I until that line. I don?t know why, it just is. Heh. I reckon Madonna should go into the studio with a compilation of new songs written by songwriters she has hired. She should do an album a day for 3 years straight ? over 1000 albums ? just doing one or two takes of each song, and being filmed all the time, and with video workers simply making videos for all the songs for her from the ongoing video of her singing. Just one to two takes of the song, get the album finished, and released. And do this every day for 3 years. She can hire countless mixers and producers for the stuff and just realease a shitload of albums and videos. Overkill in the most extreme, and it really doesn?t matter if they sell that much, because there will be enough diehards who will buy all of them and she will sell tonnes. She is a hard worker, could get the job done, and it would get her the highest album sales of all time after a while. Someone with her fame and wealth could do that, and I would if I could sing, had her fame and her money. 4 + 4 = 8 8 + 8 = 16 16 + 16 = 32 Mathematics is a very entertaining subject for intellectuals. You see, intellectuals are what they call in classic American schoolyard jargon, the nerds. And the nerds like Maths, English, Science, and putting computer systems together. I hope to be a fully qualified nerd upon retirement. Think of all the dollar bills they end up getting, hey. I mean look at Billy Gates. Come up with Microsoft and what the Trillions role in. But apparently the kids don?t get a cent, and have to work for themselves. Now that?s a responsible parent. Intellectuals also like philosophy, sneering at religious people who believe in creationism (which I do), and listening to classical or alternative music and disdaining all things commercial. Heavy Metal has a similar attitude, especially back in the day. I mean, if you were a metalhead and listened to the Spice Girls it was a death penalty offense or excommunication from the headbangers ball. And if you touched Boyzone they would torture you first. Heavy Metal gurus are another bunch of pseudo-intellectual snobs. Parading their Black Sabbath albums, saying that Led Zeppelin are gods, and that such and such a band ? their current fave ? has reinvented heavy metal forever. They love to give ratings in heavy metal mags, but rolling stone does that too. And people honestly take an interest in these ratings. But if there is one thing I have discovered is that tastes are often very subjective ? they vary widely from person to person ? and an album that somebody may rate very poorly, another set of persons might enjoy tremendously. Especially poppy commercial stuff which is, again, sneered at, but which usually sells the most because the kids have enough sense to buy albums which are actually fun and not laden down with depressing angst and bullshit feelings of a so-called contemplated soul. Intelligent albums SUCK unless there is a quality of music which is attractive, melodic and memorable. Michael Jackson, for example, may be on many supposedly serious music critics hate list for his pop classic ?Thriller?, but he is at number one because he knows what the kids like. And, funnily enough, these commercial artists who sell the most end up being the ?Beatles? of their era, and end up very respected. It happens to them with time and age. Mozart was an upstart to some to start with, despite his brilliance (apparently). Justin Beiber, for example, would be laughed at by a supposedly serious music critic, but the kids are not dumb. He sings a song which perfectly captures their vibe as teenagers, and is entirely appropriate and critically excellent for his target audience. He doesn?t have to produce Amy Lee or Bob Dylan. That is not his audience, and would be stupid to suggest it is. But that is what people often fall into with age ? they forget the younger generation are learning, and that they too once liked such stuff. Oh, and as a confirmed Noahide, I don?t really mind if the Beatles thought they were bigger than Jesus for a while. They possibly were. When I was younger I felt it important to develop religious morality to be a perfect person. I still think that somewhat, but don?t worry as much anymore. Jesus says in the gospels ?Be Ye Perfect as your Father in Heaven is Perfect.? A challenge to Christians I suppose. You know, there are a hell of a lot of those 2 billion Christians (I have seen the statistics ? approx 1 bill Catholics and 1 bill non- catholic Christians) who work there assess of spiritually to give Jesus a hell of a witness for the continued growth and establishment of his church of Glory. As a Noahide I view Jesus as an ambitious Jewish man, dedicated to his own glory, by and large. Now, as a Christian most of you view Jesus as God. But he isn?t. He wasn?t. And he never will be. He was just a bloke. If you don?t believe me ask God the father (ie Yahweh). These days he might possibly inform you upon the answer to that question, as he is severely pro-Israel from all my personal observations. Anyway, in current rankings of the all time most popular human beings, the rankings approximately come up like this. Number One ? Jesus of Nazareth Number Two ? Muhammed Number Three ? Jesus mother, Mary Number Four ? Buddha Number Five ? Moses, I think Number Six ? Apostle Paul Number Seven ? The current number seven is either Taylor Swift or Miley Cyrus on current myspace page hits. This might surprise you, but this is their era and the current ?Cult of Personality? has HUGE fanbases. Really fucking HUGE fanbases. Anyway Miley and Taylor edge out Apostle Peter, King David, Abraham, Jacob, Adolph Hitler, and Justin Beiber for the present, but he is in the top 20 all time just about. I know that is recent, but you don?t know the power of the current fame monster, as Gaga puts it, with the ever expanding human population. Mao Tse Tung, Joseph Stalin, Karl Marx, Shakespeare, Robert Pattinson, Daniel Radcliffe, Angelina Jolie, Brad Pitt, Victoria Beckham, George Washington, J K Rowling, J R R Tolkien, Marilyn Monroe, Elvis Presley, Winston Churchill & Emma Watson are some of the very big names, likely in the top thirty to forty all time. Add on Wolfgang Amadeus Mozart and Ludwig Van Beethoven who are currently the two number ones in the classical scene ? they share the honour. But number one is the carpenter from Nazareth. Still caining after 2000 years. Believe me, that takes some effort, but with the beloved ?Cross? at his disposal, which the faithful were around their necks with pride, the ?Christ Child? isn?t letting go of the number one slot any time soon. Hey, people think he is actually God himself, and that takes a lot to compete with. But somebody?s got to do it. Probably 666 will show up, some dude or dudette thinking that might work for a while, and take on the JC fellow. Bad news at the moment, though, because most humans are patently aware that the mark of the beast is bad news on judgement day. But, fucking hell, Iron Maiden released ?Number of the Beast? and sold a shitload. I guess the Antichrist is a keen competitor to the big fellow. You never know, he might grab the top slot for a while. What was that? Seven years says my pentecostal friend? Tribulation glory, but it won?t last? Aye Carumba. So how did Jesus get to the top slot? I have written on that before, but lets just say this much. If you can win somebody?s respect, and then start a religious cult, and then have that cult evangelize their socks off for 2000 years, it sure as hell helps. So how do you potential wannabes start a religious cult then? In Christianity every tom dick and harry started a church for a while. They were called protestants. So, to be a protestant, it is simple. Tell your current pastoral overlord to take a running jump, and start preaching those doctrines you have always wanted to preach, and evangelize. Evangelization is easy. First, do up a free website on angelfire, and post your church doctrines and teachings. Go to the library and print off 100 pages of A4 flyers, 4 flyers to a page, and cut them into 4s and make sure you put the name of the church and the website link and email address. And then, if you really want to build wonderchurch, make it your hobby to go to carparks, put flyers on car windows, and do this for 20 years. Its slow, but it works. Now, for you lateral thinkers, Christianity is basically covered. Try something new. L Ron Hubbard did. He called it scientology, and the freaks practically worship him. So go for something pseudo spiritual, a catchy name, special key teachings on enlightenment, and stick to your guns. Oh, and be dramatic. It helps. Those thoughts will do for now. I might continue this some time. Oh, and one last thing. I want to plug a few books which are truly excellent. Hugh Cook ? the 10 Volume epic ?Chronicles of an Age of Darkness?. Intense, weird, novel, original and exciting. David Eddings ? The Eternal ?Belgariad? series. I have SEEN the Harry Potters, but Edding?s, while currently still very popular, deserves to reach J K Rowling numbers in sales. Raymond E Feist ? Magician. The ultimate fantasy epic, and the first volume of the Riftwar saga. Hugely popular, and deserves to be, and really you should read it. And one last plug: My favourite all time rock album ? Bon Jovi ?New Jersey? My favourite all time pop album ? Rihanna ?Good Girl Gone Bad? My favourite all time Christian album ? Susan Ashton ?A Distant Call? Daniel http://noahidebooks.angelfire.com From pruebauno at latinmail.com Wed Sep 22 10:38:12 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 22 Sep 2010 07:38:12 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: Message-ID: <1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com> On Sep 21, 6:39?pm, Baba wrote: > Hi > > query level: beginner > > as part of a learning exercise i have written code that: > > a) asks for a single letter input (assumption: only 1 letter wil be > entered) > b) adds that letter to list1 and then goes through list2 and checks: > > ? ? 1) if any item in list2 starts with list1 > if False: break > ? ? 2) if list1 == any item in list2 > if True: break > > c) start again until 2) is True > > wordlist = ['hello', 'bye'] > handlist = [] > letter = raw_input('enter letter: ') > handlist.append(letter) > hand = "".join(handlist) > for item in wordlist: > ? ? if item.startswith(hand): > ? ? ? ? while item.startswith(hand): > ? ? ? ? ? ? if hand not in wordlist: > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > ? ? ? ? ? ? ? ? handlist.append(letter) > ? ? ? ? ? ? ? ? hand = "".join(handlist) > ? ? ? ? ? ? else: break > ? ? ? ? else: break > print 'you loose' > > this code works but can it be optimised? i have the feeling that my > nesting of IF, WHILE and FOR statements is overkill? > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > thanks > Baba Yes it is overkill. Especially the else:break from the while loop makes it difficult to follow the logic. Also the program breaks down if I use the following word list: wordlist = ['hello', 'hamburger', 'bye'] >>> enter letter: h enter letter: a you loose I am not going to post any spoilers but I wrote your program using one while loop and one generator expression for a total of 5 lines. My version might be a bit too advanced but you should still be able to do it using only one while, one for and one if instead. From nobody at nowhere.com Wed Sep 22 12:38:28 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 22 Sep 2010 17:38:28 +0100 Subject: Subprocess does not return for longer-running process References: Message-ID: On Tue, 21 Sep 2010 23:54:04 -0700, Dennis Lee Bieber wrote: >> As your Traceback clearly indicates, the Popen() call has already >> completed; it's *the os.waitpid() call* that's blocking, but that's >> entirely to be expected given its defined behavior. If you don't want >> to wait around for the process to die, then don't call waitpid() on it >> in the first place! >> > And a likely reason the waitpid() if blocking is that the > sub-process is blocking trying to write to pipe that is full. Which is why you should always use the .communicate() method if you redirect two or more of std{in,out,err} to a pipe (this is why the Unix popen() function only lets you redirect one of the standard descriptors). And I can't think of any reason why you should use os.waitpid() or similar; use the .wait() method. From nobody at nowhere.com Wed Sep 22 12:41:34 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 22 Sep 2010 17:41:34 +0100 Subject: how to get partition information of a hard disk with python References: Message-ID: On Wed, 22 Sep 2010 00:31:04 +0200, Hellmut Weber wrote: > I'm looking for a possibility to access the partiton inforamtion of a > hard disk of my computer from within a python program. Have you considered parsing /proc/partitions? From xahlee at gmail.com Wed Sep 22 12:42:50 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 22 Sep 2010 09:42:50 -0700 (PDT) Subject: HTML6 proposal (Re: sexp xml syntax transformation) References: <2bebbf7e-e30d-41a7-bed5-72a132d9de79@z30g2000prg.googlegroups.com> <30bd8745-ef6a-4c5c-8f30-fbbbf8a9bd91@l32g2000prn.googlegroups.com> Message-ID: cleaned up the previous post. ? ?HTML6, Your HTML/XML Simplified? http://xahlee.org/comp/html6.html plain text version follows -------------------------------------------------- HTML6, Your HTML/XML Simplified Xah Lee, 2010-09-21 Tired of the standard bodies telling us what to do and change their altitude? Tired of the SGML/HTML/XML/XHTML/HTML5 changes? Tire no more, here's a new proposal that will make life easier. Introducing HTML6 HTML6 is based on HTML5, XML, and a rectified LISP syntax. More specifically, it is derived from existing work on this, the SXML. http://okmij.org/ftp/Scheme/SXML.html, except that there is complete regularity at syntax level, and is not considered or compatible with lisp readers. The syntax can be specified by 3 short lines of parsing expression grammar. The aim is far more simpler syntax, 100% regularity, and leaner. but with a far simpler, and more strict, format. First of all, no error is accepted, ever. If a source code has incorrect syntax, that page is not displayed. Example Here's a standard ATOM webfeed XML file. Xah's Emacs Blog Emacs, Emacs, Emacs 2010-09-19T14:53:08-07:00 Xah Lee http://xahlee.org/ http://xahlee.org/emacs/blog.html http://xahlee.org/ics/sum.png ? 2009, 2010 Xah Lee Using Emacs's Abbrev Mode for Abbreviation tag:xahlee.org,2010-09-19:215308 2010-09-19T14:53:08-07:00 tutorial Here's how it looks like in html6: ??xml ?version ?1.0? encoding ?utf-8??? ?feed ?xmlns ?http://www.w3.org/2005/Atom? xml:base ?http://xahlee.org/ emacs/?? ?title Xah's Emacs Blog? ?subtitle Emacs, Emacs, Emacs? ?link ?rel ?self? href ?http://xahlee.org/emacs/blog.xml??? ?link ?rel ?alternate? href ?http://xahlee.org/emacs/blog.html??? ?updated 2010-09-19T14:53:08-07:00? ?author ?name Xah Lee? ?uri http://xahlee.org/? ? ?id http://xahlee.org/emacs/blog.html? ?icon http://xahlee.org/ics/sum.png? ?rights ? 2009, 2010 Xah Lee? ?entry ?title Using Emacs's Abbrev Mode for Abbreviation? ?id tag:xahlee.org,2010-09-19:215308? ?updated 2010-09-19T14:53:08-07:00? ?summary tutorial? ?link ?rel ?alternate? href ?http://xahlee.org/emacs/ emacs_abbrev_mode.html??? ? ? Simple Matching Pairs For Tag Delimiters The standard xml markup bracket is simplified using simple lisp style matching pairs. For example, this code:

HTML6

Is written as: ?h1 HTML6? The delimiter used is: Character Unicode Code Point Unicode Name ? U+3014 LEFT TORTOISE SHELL BRACKET ? U+3015 RIGHT TORTOISE SHELL BRACKET XML Properties and Attributes Syntax In xml:

HTML6

In html6: ?h1?id ?xyz? class ?abc??HTML6? The attributes are specified by matching corner brackets. Items inside are a sequence of pairs. The value must be quoted by curly double quotes. Escape Mechanisms To include the ?tortoise shell? delimiters in data, use ?〔? and ?〕?, similarly for the ?corner brackets?. Unicode; No More CD Data and Entities ?&? There's no Entities. Except the unicode in hexadecimal format ?&#x?unicode code point hexidecimal??. For example, ?&? is not allowed. Treatment of Whitespace Basically identical to XML. Char Encoding; UTF8 and UTF16 Only Source code must be UTF8 or UTF16, only. Nothing else. File Name Extension File name extension is ?.xml6? or ?.html6?. Semantics The semantics should follow xhtml5. Questions and Answers What's wrong with xhtml/html5 exactly? The politics of standard body changes, and their attitude about what is correct also changes whimsically. In around 2000, we are told that XML and XHTML will change society, or, at least, make the web correct and valid and far more easier to develop and flexible. Now it's a decade later. Sure the web has improved, but as far as html/xhtml and browser rendering goes, it's still a syntax soup with extreme complexities. 99.99% of web pages are still not valid, and nobody cares. Major browsers still don't agree on their rendering behavior. Web dev is actually far more complex, involving tens or hundreds of tech that hardly a person even knows about (ajax, jason, lots xml variations). It's hard to say if it is better at all than the HTML3 days with ?font? and ?table? tags and gazillion tricks. The best practical approach is still trial n error with browsers. And, now HTML5 comes alone, from a newfangled hip group primarily from current big corporations Google and Apple, with a attitude that validation is overrated ? a insult to the face about the XML mantra from w3c, just when there starts to be more and more sites with correct XHTML and Microsoft's Internet Explorer getting on track about correctness. XML is break from SGML, with many justifications why it needs be, and with some backward compatible trade-offs, and now HTML5 is a break from both SGML and XML. See also: (Google Earth) KML Validation Fuckup Google's ?rel="nofollow"? Rule HTML Correctness and Validators Why not just adopt SXML from the lisp world? Lisp's SXML is not a stand-alone syntax for the need of the web. Lisp's format typically are made in a way to follow lisp's traditions, and often has quirks of its own. The syntax is not 100% regular of nested parens. SXML is easy for lispers to adopt, but harder for other languages and communities. For lisp's syntax irregularities, see: Fundamental Problems of Lisp. For example, the xml as textual representation of a tree has a quirk, in that each node has this special thing called ?attributes? (aka ?properties?). The ?attribute? is not a node of the tree, but rather, is info attached to a node. The standard lisp syntax (aka sexp) to represent attributes is this, e.g.. (h1 :id "xyz" :class "abc" ...) Syntactically, each of ?:id?, ?"xyz"? etc are not distinguishable from a node/branch in the tree. Only semantically, after lisp reader parsed the special character ?:? in a node's name, then it is considered a property name, and that the next element in the expression is being considered as a value for that property. Another way to represent xml's attribute is this: (h1 ((id . "xyz") (class . "abc")) ...) This too, have syntactical ambiguity. The whole ?((id . "xyz") (class . "abc"))? can be interpreted as a node by itself, where the first element is again a node. But also here, it uses lisp's special ?cons? syntax ?(id . "xyz")? which is itself ambiguous at the syntax level. e.g. it can be considered as a node named ?id? with 2 branches ?.? and ?"xyz"?, or it can be considered as a node named ?cons? with 2 branches ?id? and ?"xyz"?. Another common lisp syntax for attributes is this: (h1 (@ (id . "xyz") (class . "abc")) ...) Again, this whole ?(@ ...)? part at the syntax level is simply a node named ?@?. Only at the semantic level, that it is taken as properties of a node due to semantics attached to the head string ?@?. So, in conceiving html6, i thought a solution for getting rid of syntax ambiguity for node vs attributes is to use a special bracket for properties/attributes of a node. e.g. ??h1?id ?xyz? class ?abc??...??. Why use weird Unicode characters for matching pair? Unicode has become widely adopted today. (See: Unicode Popularity On Web.) Unicode also has a lot proper matching pairs. (See: Matching Brackets in Unicode.) It seems today is the right time to adopt the wide range of proper characters instead of keep relying on the very limited number of ASCII characters. The straight quote character " is not a matching pair, and in code it present several problems. For example, it is difficult to know which quote matches which. Also, it is difficult to recover from a missing quote. (this problem is especially pronounced in text editors for syntax highlighting.) A proper matching pair allow programs and editors to more easily correctly determine the quoted content, and for easily navigating the tree. The unicode characters ?? and ?? may be difficult to input. Possibly, they can be replaced by () and {} for html6. Though, that also means a lot ugly escape will need to happen in text, and if not escaped, that means incorrect syntax. One thing about this html6 is that it is intentionally separate from being a valid sexp of the lisp world. The core idea is that the syntax of html6 is designed specifically as a 2-dimentional textual representation of a tree, and with a attribute quote that attaches a limited form of info (pairs sequence) to any node to fit existing structure of XML. The advantage of this is that it should be extremely easy to parse, in perhaps just 3 lines of parsing expression grammar. And can be easily done in perl, python, ruby... without entailing lisp quirks, and can be trivially tranformed into legal lisp syntax by lisps as well. Any thoughts about flaws? Xah ? xahlee.org ? From nobody at nowhere.com Wed Sep 22 12:50:21 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 22 Sep 2010 17:50:21 +0100 Subject: Best way for rotating a matrix of data? References: <3207b8a9-a566-478d-a5db-859db162b8e4@p24g2000pra.googlegroups.com> Message-ID: On Tue, 21 Sep 2010 19:38:06 -0700, Rapha?l Plasson wrote: > Actually, I more precisely extract my 2D array from much higher > dimensions data (i.e. 10-20 fields of different data in 3 dimensions > of space+1 dimension of time), contained in a hdf5 file. I typically > would like to extract arbitrary slices of any of the fields from the > 3+1D space... and I don't really know how this can be simply done. I > can only extract an "orthogonal" 2D space from this space, and rotate > it with the above method. > > Is there a more direct way to extract arbitrary slices directly from > 2/3/4D arrays? Which python modules would be able to do the job? You can use arrays as indices, so applying a transformation to a set of index arrays (e.g. np.indices) then using those as indices is equivalent to applying a spatial transform to the data. Also: scipy.ndimage. From python at mrabarnett.plus.com Wed Sep 22 13:06:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Sep 2010 18:06:17 +0100 Subject: Grouping pairs - suggested tools In-Reply-To: References: Message-ID: <4C9A3789.9050702@mrabarnett.plus.com> On 20/09/2010 22:42, Astley Le Jasper wrote: > I have a list of tuples that indicate a relationship, ie a is related > to b, b is related to c etc etc. What I want to do is cluster these > relationships into groups. An item will only be associated with a > single cluster. > > Before I started, I wondered if there was any particular tool within > Python I should be looking at. I don't expect anyone to code this for > me, just say ... "you need to look at using x". I was going to use > populate a dictionary and > > Sorry for being so vague. > [snip] I thought I'd join in. I've used repr to ensure that I have something that's hashable: def show_groups(pairs): groups = {} items = {} for x, y in pairs: x_repr, y_repr = repr(x), repr(y) items[x_repr] = x items[y_repr] = y x_group = groups.setdefault(x_repr, set([x_repr])) y_group = groups.setdefault(y_repr, set([y_repr])) union = set() for m in x_group | y_group: union |= groups[m] for m in union: groups[m] = union indexes = {} for s in groups.values(): indexes.setdefault(frozenset(s), len(indexes) + 1) indexes = sorted(indexes.items(), key=lambda pair: pair[1]) for s, i in indexes: for m in sorted(s): print("{0} {1}".format(i, items[m])) if __name__ == "__main__": edges = [ ('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'), ('c', 'd'), ('e', 'f'), ('e', 'g'), ('f', 'g'), ('h', 'i'), ] show_groups(edges) print() show_groups([('a', 'c'), ('b', 'd'), ('c', 'd')]) From tjreedy at udel.edu Wed Sep 22 13:30:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Sep 2010 13:30:47 -0400 Subject: Expanding a vector by replicating elements individually In-Reply-To: References: Message-ID: On 9/21/2010 11:03 PM, gburdell1 at gmail.com wrote: > Given > > m=numpy.array([[1, 2, 3]]) > > I want to obtain > > array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) > > One way I've found to do this is: > > numpy.reshape(numpy.tile(m,(4,1)),(12,1),'f').T > > Another way is: > > numpy.reshape(numpy.tile(m,(4,1)).flatten(1),(1,12)) > > Is there a simpler way to do this, without having to go jump through > so many hoops? With a Python list >>> l = [] >>> for rep in [[i]*4 for i in [1,2,3]]: l.extend(rep) >>> l [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3] or >>> list(chain(*[[i]*4 for i in [1,2,3]])) [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3] Can you adapt that with numpy.array instead of list? Might be slower though -- Terry Jan Reedy From dani.valverde at gmail.com Wed Sep 22 13:46:24 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Wed, 22 Sep 2010 19:46:24 +0200 Subject: SetGridCursor not working? Message-ID: <4C9A40F0.9040102@gmail.com> Hello! I have a table with some rows and cells (code at the end), and created a function which searches for text inside the cells and returns the row number where the text is (to simplify the example, only English Name is working). Then, it should set the grid cursor focus to that row (I want to use the wx.grid.Grid.SelectRows style when created the wx.Grid, but to reduce the number of variables I don't use it in the example). To set the cursor focus, I am using def OnSearch(self, event): CommonName = self.CommonNameTXT.GetValue() if CommonName != '': ind = self.parent.EnglishNameList.index(CommonName) self.parent.SpeciesGrid.SetGridCursor(ind, 0) self.parent.SpeciesGrid.MakeCellVisible(ind,0) Theoretically, it should work using only the SetGridCursor method, however somewhere I have read that it will not work unless you also use the MaceCellVisible method as well. Anyway, it does not work at all. Can anyone help? Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From dani.valverde at gmail.com Wed Sep 22 14:07:11 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Wed, 22 Sep 2010 20:07:11 +0200 Subject: Auto size wx.StaticText Message-ID: <4C9A45CF.4090400@gmail.com> Hello! Is there a way to automatically set the size of a wx.StaticText to fit its content? Cheers! Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From invalid at invalid.invalid Wed Sep 22 14:38:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 22 Sep 2010 18:38:34 +0000 (UTC) Subject: Auto size wx.StaticText References: Message-ID: On 2010-09-22, Dani Valverde wrote: > Is there a way to automatically set the size of a wx.StaticText to fit > its content? According to the docs, it should do that by default: http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.StaticText.html Window Styles Window Style Description wx.ALIGN_LEFT Align the text to the left wx.ALIGN_RIGHT Align the text to the right wx.ALIGN_CENTRE Center the text (horizontally) wx.ST_NO_AUTORESIZE By default, the control will adjust its size to exactly fit to the size of the text when SetLabel is called. If this style flag is given, the control will not change its size (this style is especially useful with controls which also have wx.ALIGN_RIGHT or wx.ALIGN_CENTER style because otherwise they won't make sense any longer after a call to SetLabel) -- Grant Edwards grant.b.edwards Yow! PUNK ROCK!! DISCO at DUCK!! BIRTH CONTROL!! gmail.com From martin at v.loewis.de Wed Sep 22 14:59:05 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 22 Sep 2010 20:59:05 +0200 Subject: weird error with python 2.7 installer under windows 7 In-Reply-To: References: Message-ID: > Any ideas? Try running the postinstall script by hand. Regards, Martin From brenNOSPAMbarn at NObrenSPAMbarn.net Wed Sep 22 15:46:14 2010 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Wed, 22 Sep 2010 19:46:14 +0000 (UTC) Subject: Playing sounds at time indexes Message-ID: I'm looking for an audio library for Python. I googled and found a few, but none of them seem to have a simple way to play a particular sound file from a particular start-time to an end-time. Like, I'd want to load a file and say "Play the section of this file from 10.25 seconds to 11.73 seconds." Is there a library that makes this easy in Python? Thanks, -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From jayryan.thompson at gmail.com Wed Sep 22 16:13:47 2010 From: jayryan.thompson at gmail.com (jay thompson) Date: Wed, 22 Sep 2010 13:13:47 -0700 Subject: ctypes Message-ID: Hello, I posted in regard to this in the past but it didn't go very far, no ones fault, but I'm again atempting to make this work and could use some help. I would like to use libraw.dll (http://www.libraw.org/ version 0.10) from python and can access all the functions fine and produce images but there is a structure that holds all the process settings that I cannot access with ctypes. I'm sure it's because I'm going about it the wrong way. I was wondering if there was anyone in this list with experience with this sort of thing that could point me in the right direction. Thanks! jt -- "It's quite difficult to remind people that all this stuff was here for a million years before people. So the idea that we are required to manage it is ridiculous. What we are having to manage is us." ...Bill Ballantine, marine biologist. -------------- next part -------------- An HTML attachment was scrubbed... URL: From raoulbia at gmail.com Wed Sep 22 16:18:18 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 22 Sep 2010 13:18:18 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com Message-ID: On Sep 22, 3:38?pm, nn wrote: > On Sep 21, 6:39?pm, Baba wrote: > > > > > Hi > > > query level: beginner > > > as part of a learning exercise i have written code that: > > > a) asks for a single letter input (assumption: only 1 letter wil be > > entered) > > b) adds that letter to list1 and then goes through list2 and checks: > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > ? ? 2) if list1 == any item in list2 > if True: break > > > c) start again until 2) is True > > > wordlist = ['hello', 'bye'] > > handlist = [] > > letter = raw_input('enter letter: ') > > handlist.append(letter) > > hand = "".join(handlist) > > for item in wordlist: > > ? ? if item.startswith(hand): > > ? ? ? ? while item.startswith(hand): > > ? ? ? ? ? ? if hand not in wordlist: > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > ? ? ? ? ? ? ? ? handlist.append(letter) > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > ? ? ? ? ? ? else: break > > ? ? ? ? else: break > > print 'you loose' > > > this code works but can it be optimised? i have the feeling that my > > nesting of IF, WHILE and FOR statements is overkill? > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > thanks > > Baba > > Yes it is overkill. Especially the else:break from the while loop > makes it difficult to follow the logic. Also the program breaks down > if I use the following word list: > > wordlist = ['hello', 'hamburger', 'bye'] > > enter letter: h > enter letter: a > you loose > > I am not going to post any spoilers but I wrote your program using one > while loop and one generator expression for a total of 5 lines. My > version might be a bit too advanced but you should still be able to do > it using only one while, one for and one if instead. Hi nn, i wasn't expecting my code to fail with an additional word in it. While i was conscious that the whole construct was heavy i thought the reasoning worked. I keep looking at it but can't figure out the problem Can you give me a hint? In the meantime i found out that it is actually possible to populate a string (just like a list, a dictionary or a tuple). Here's what i've got now: wordlist = ['hello', 'bye'] hand = '' for item in wordlist: if item.startswith(hand): while item.startswith(hand): if hand not in wordlist: hand += raw_input('enter letter: ') print hand else: break else: break print 'you loose' But i can't figure out why it won't work when adding the extra word. Thanks by the way, it taught me not to be too confident when things SEEM to work... Why does it work when i use the built-in function any(iterable)?? To me using the any(iterable) function seems just like regrouping 3 lines into one... wordlist = ['hello','hamburger', 'bye', 'cello'] hand = '' while any(item.startswith(hand) for item in wordlist): if hand not in wordlist: hand += raw_input('enter letter: ') else: break print 'you loose' thanks Baba From robert.kern at gmail.com Wed Sep 22 16:28:27 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 22 Sep 2010 15:28:27 -0500 Subject: Expanding a vector by replicating elements individually In-Reply-To: References: Message-ID: On 9/21/10 10:03 PM, gburdell1 at gmail.com wrote: > Given > > m=numpy.array([[1, 2, 3]]) > > I want to obtain > > array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]]) > > One way I've found to do this is: > > numpy.reshape(numpy.tile(m,(4,1)),(12,1),'f').T > > Another way is: > > numpy.reshape(numpy.tile(m,(4,1)).flatten(1),(1,12)) > > Is there a simpler way to do this, without having to go jump through > so many hoops? Peter Otten gave you the correct answer. If you have more numpy questions, you should ask on the numpy mailing list: http://www.scipy.org/Mailing_Lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From cmpython at gmail.com Wed Sep 22 18:27:52 2010 From: cmpython at gmail.com (CM) Date: Wed, 22 Sep 2010 15:27:52 -0700 (PDT) Subject: Auto size wx.StaticText References: Message-ID: On Sep 22, 2:38?pm, Grant Edwards wrote: > On 2010-09-22, Dani Valverde wrote: > > > Is there a way to automatically set the size of a wx.StaticText to fit > > its content? > > According to the docs, it should do that by default: > > ? ?http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.StaticText.html > > Window Styles > > ? Window Style ? ? ? ? ?Description > > ? wx.ALIGN_LEFT ? ? ? ? Align the text to the left > > ? wx.ALIGN_RIGHT ? ? ? ?Align the text to the right > > ? wx.ALIGN_CENTRE ? ? ? Center the text (horizontally) > > ? wx.ST_NO_AUTORESIZE ? By default, the control will adjust its size to > ? ? ? ? ? ? ? ? ? ? ? ? exactly fit to the size of the text when > ? ? ? ? ? ? ? ? ? ? ? ? SetLabel is called. If this style flag is > ? ? ? ? ? ? ? ? ? ? ? ? given, the control will not change its size > ? ? ? ? ? ? ? ? ? ? ? ? (this style is especially useful with controls > ? ? ? ? ? ? ? ? ? ? ? ? which also have wx.ALIGN_RIGHT or > ? ? ? ? ? ? ? ? ? ? ? ? wx.ALIGN_CENTER style because otherwise they > ? ? ? ? ? ? ? ? ? ? ? ? won't make sense any longer after a call > ? ? ? ? ? ? ? ? ? ? ? ? to SetLabel) > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! PUNK ROCK!! ?DISCO > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? DUCK!! ?BIRTH CONTROL!! > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ? Yes, just make sure, OP, that you don't pass a size to the wx.StaticText when constructing it. Or you can give the size as size=wx.Size(-1,-1), which means default size. Che From raoulbia at gmail.com Wed Sep 22 18:39:54 2010 From: raoulbia at gmail.com (Baba) Date: Wed, 22 Sep 2010 15:39:54 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com Message-ID: <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> On Sep 22, 9:18?pm, Baba wrote: > On Sep 22, 3:38?pm, nn wrote: > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > Hi > > > > query level: beginner > > > > as part of a learning exercise i have written code that: > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > entered) > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > c) start again until 2) is True > > > > wordlist = ['hello', 'bye'] > > > handlist = [] > > > letter = raw_input('enter letter: ') > > > handlist.append(letter) > > > hand = "".join(handlist) > > > for item in wordlist: > > > ? ? if item.startswith(hand): > > > ? ? ? ? while item.startswith(hand): > > > ? ? ? ? ? ? if hand not in wordlist: > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > ? ? ? ? ? ? else: break > > > ? ? ? ? else: break > > > print 'you loose' > > > > this code works but can it be optimised? i have the feeling that my > > > nesting of IF, WHILE and FOR statements is overkill? > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > thanks > > > Baba > > > Yes it is overkill. Especially the else:break from the while loop > > makes it difficult to follow the logic. Also the program breaks down > > if I use the following word list: > > > wordlist = ['hello', 'hamburger', 'bye'] > > > enter letter: h > > enter letter: a > > you loose > > > I am not going to post any spoilers but I wrote your program using one > > while loop and one generator expression for a total of 5 lines. My > > version might be a bit too advanced but you should still be able to do > > it using only one while, one for and one if instead. > > Hi nn, > > i wasn't expecting my code to fail with an additional word in it. > While i was conscious that the whole construct was heavy i thought the > reasoning worked. I keep looking at it but can't figure out the > problem Can you give me a hint? > > In the meantime i found out that it is actually possible to populate a > string (just like a list, a dictionary or a tuple). Here's what i've > got now: > > wordlist = ['hello', 'bye'] > hand = '' > for item in wordlist: > ? ? if item.startswith(hand): > ? ? ? ? while item.startswith(hand): > ? ? ? ? ? ? if hand not in wordlist: > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > ? ? ? ? ? ? ? ? print hand > ? ? ? ? ? ? else: break > ? ? ? ? else: break > print 'you loose' > > But i can't figure out why it won't work when adding the extra word. > Thanks by the way, it taught me not to be too confident when things > SEEM to work... > > Why does it work when i use the built-in function any(iterable)?? To > me using the any(iterable) function seems just like regrouping 3 lines > into one... > > wordlist = ['hello','hamburger', 'bye', 'cello'] > hand = '' > while any(item.startswith(hand) for item in wordlist): > ? ? if hand not in wordlist: > ? ? ? ? hand += raw_input('enter letter: ') > ? ? else: break > print 'you loose' > > thanks > > Baba Hi nn, looking at my original code again i realise that having a raw_input inside a FOR loop is flawed per se (at least for my purposes) so i will just assume that i was taking the wrong approach initially. No point in analysing it further. Thanks for your help. Baba From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 19:12:39 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Sep 2010 23:12:39 GMT Subject: Down with tinyurl! (was Re: importing excel data into a pythonmatrix?) References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> Message-ID: <4c9a8d66$0$11123$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 00:51:20 -0700, Dennis Lee Bieber wrote: > On 21 Sep 2010 05:01:45 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > >> Hey, that would be an *awesome* google bombing project... to get lmgtfy >> to come up as the first link for "self-righteous dicks". 4chan, where >> are you when we need you??? >> > I think the news reports are that they are wasting time on a DDoS > attack on the RIAA... Heh, it's not a waste of time if you're enjoying yourself :) > While I don't agree with the RIAA's methods, I also think a DDoS > is definitely NOT an action to endear one to that one's views... "The customer is always right, unless they're unhappy with us." You know, I'd give my right arm -- well, perhaps somebody else's right arm -- for the opportunity to some day to be interviewing an ex-RIAA executive, just so I can say: "I see from your CV that you took millions of customers and made them so mad at you that not only did they break the law to give you the finger, but they promised to never, ever pay a cent for your products again. So tell me, how did that business strategy work out for you?" -- Steven From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 19:25:28 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Sep 2010 23:25:28 GMT Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c97f7cf$0$28658$c3e8da3@news.astraweb.com> <87aanbx5lq.fsf@castleamber.com> Message-ID: <4c9a9068$0$11123$c3e8da3@news.astraweb.com> On Mon, 20 Sep 2010 23:17:54 -0700, Dennis Lee Bieber wrote: > On Mon, 20 Sep 2010 20:12:01 -0500, John Bokma > declaimed the following in gmane.comp.python.general: > > >> I never saw the point of the whole X-No-Archive: Yes thing. What >> happens if I quote such a message? It's archived, right? > > Compliant clients (like Agent) will echo the X-No-Archive: Yes in > YOUR reply -- so it too will be deleted at some point in time. WHAT??? That's just wrong in every possible way. Just because I'm replying to somebody who wants X-No-Archive doesn't mean I want that foolishness to infect my post. Thank goodness that my client isn't compliant with that truly awful behaviour. Some standards are just *bad*. -- Steven From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 19:30:42 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Sep 2010 23:30:42 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: <4c9a91a2$0$11123$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 08:17:00 +0000, Duncan Booth wrote: > I guess you have worked hard to forget the and-or hack. It was actually: > > condition and true-clause or false-clause > > so its not quite the same pattern. So I did. Oops. Thanks for the correction. -- Steven From afffg33 at gmail.com Wed Sep 22 19:49:08 2010 From: afffg33 at gmail.com (fcgffj) Date: Wed, 22 Sep 2010 16:49:08 -0700 (PDT) Subject: Here is your chance to make the big bucks and enjoy life. http://salesuper.com/ Message-ID: <0a12c815-f96b-4cc0-b3ee-ea42ea877b6c@t7g2000vbj.googlegroups.com> Here is your chance to make the big bucks and enjoy life. http://salesuper.com/ shows everyone how to become rich. Go and check out what they have to say. ----------http://salesuper.com/--------- ----------http://salesuper.com/--------- From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 20:23:22 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 23 Sep 2010 00:23:22 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> Message-ID: <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 16:17:48 +0200, Antoon Pardon wrote: > On Tue, Sep 21, 2010 at 12:07:07AM +0000, Steven D'Aprano wrote: >> On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: >> >> > Not necessarily. Some of us have the impression that Guido >> > deliberatly chose an ugly format for the ternary operator. >> >> If he did, then he must have changed his mind, because there is nothing >> ugly about the ternary operator we ended up with. > > That is a question of taste Yes, it certainly is. Describing it as "an ugly format" is also a matter of taste -- taste which in my opinion simply isn't justified by anything other than familiarity. > and the poll and discussion earlier made it > clear that this was not the preferred way to have a ternary operator. "Not preferred" != "ugly" > This form only ranked fourth (or maybe third), with the first three all > wanting ar structure with the elelement is this order: condition, true > case, false case > >> > Guido has alwasys been >> > against a ternary operator but the requests kept coming. So >> > eventually he introduced one. But the impression is that he chose an >> > ugly format in the hope of discouraging people to use it. >> >> That's sheer and unadulterated nonsense. The fact is that Guido changed >> his mind about ternary if after discovering that the work-around >> >> true-clause and condition or false-clause >> >> is buggy -- it gives the wrong answer if true-clause happens to be a >> false value like [], 0 or None. If I recall correctly, the bug bit >> Guido himself. > > Nonsense. That the work around was buggy was known years before the > ternary operator was finally introduced. But people kept forgetting it, and it bit the right person one time too many. > The introduction of list > comprehension made a ternary operator that more usefull but every time > it came up the supporters of Guido, told us we just had to define a > function if we wanted the items to depend on a condition. A function can't do the job, because it isn't lazy: def ifte(condition, x, y): if condition: return x else: return y n = 0 ifte(n != 0, 100/n, -1) will fail. This was perhaps *the* killer argument for a ternary-if operator. [...] > It seems that what changed is your memory and not the collective mind of > the python community. Fair call. -- Steven From ldo at geek-central.gen.new_zealand Wed Sep 22 20:25:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 23 Sep 2010 12:25:53 +1200 Subject: Subprocess does not return for longer-running process References: Message-ID: In message , Nobody wrote: > And I can't think of any reason why you should use os.waitpid() or > similar; use the .wait() method. I have used WNOHANG to poll for completion of a subprocess while providing progress updates to the user. From vlastimil.brom at gmail.com Wed Sep 22 20:28:24 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 23 Sep 2010 02:28:24 +0200 Subject: data structure suggestion (native python datatypes or sqlite; compound select) In-Reply-To: References: <4C92A584.8060303@mrabarnett.plus.com> <4C92B3BC.6090901@mrabarnett.plus.com> Message-ID: 2010/9/19 Dennis Lee Bieber : > On Sat, 18 Sep 2010 23:00:25 +0200, Vlastimil Brom > declaimed the following in > gmane.comp.python.general: > >> Thank you very much for detailed hints, I see, I should have mention >> the specification with my initial post... >> It is true, that nested tags of the same name aren't supported, but >> tags may appear anywhere in the text and aren't terminated with >> newline. The tag-value association is valid from the tag position >> until the next tag replacing the value or closing tag (like ) or > > ? ? ? ?Okay... Then put the start/end fields back into the database > > ? ? ? ?Also, if the data can span lines, using a foreign key to a table > having the lines is meaningless... I'd probably generate a plain text > file (one that does not contain any tags), and record the start/end > positions for the tags based as a pure character count from start of > file. Optional if you strip new-lines from this file so it is just a > long line of text... > > ? ? ? ?Parsing may need to be recursive so you can determine the end points > for outer tags and generate the full record (type, start, end, > supplement) {I didn't list ID, though my standard practice is to always > have an auto-increment ID field in a table -- it simplifies later > updates}. > > ? ? ? ?Do the tags form a hierarchy? That is, does a "higher level" tag > force a closure of all unclosed lower levels? > >> I'll have a closer look on joins in sql and maybe redesign the data >> structure - now the tags data are copied for each text position with >> some tag change - in order to simplify queries; with multiple tables >> it could be more efficient to store the tags separately and look it up >> individually (probably using bisect (unless there is an SQL equivalent >> ?) > > ? ? ? ?I'm not sure of how you mean "bisect" but I do suggest that you look > up a lesson on "database normalization" (emphasis on first, second, and > third normal forms; the others are rather esoteric). > > ? ? ? ?What I'm pretty sure you do NOT want to do is create a table for > each tag TYPE. The type is just another data value, as in my sample > tables. That makes queries much simpler since you don't run into the > problem of having to generate queries where you change the schema > entities ("schema" is the technical term for the layout of the database > -- the fixed items rather than the data; end users should never directly > enter schema items in an application [you can present a menu of schema > items and let the user pick one, but the selection is never used as-is, > it has to be restricted to a list you generate, and returns values from > your list; look up "sql injection"]) > > ? ? ? ?With the actual text in a plain file, the joins I was using are not > needed -- you'd use the start/end results to seek/read the file as a > separate step. > > ? ? ? ?However, you might have some complex queries that use subselects if > you need to retrieve a passage inside a passage (poor phrasing). > > ? ? ? ?That is, a subselect that specifies you want the start/end range of > a tag with a particular attribute, and you use the start/end as >, < > comparisons to find a different tag. Off the top of my head (hence may > not be valid SQL) > > select t1.type, t1.supplement, t1.start, t1.end from tags as t1 > ? ? ? ?inner join > ? ? ? ? ? ? ? ?(select start, end from tags > ? ? ? ? ? ? ? ? ? ? ? ?where type = "some type" > ? ? ? ? ? ? ? ? ? ? ? ?and supplement = "some value") as t2 > ? ? ? ?where t1.start >= t2.start and t1.end <= t2.end > > -- > ? ? ? ?Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ?wlfraed at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks all for the pointers and recommendations! After some tests I eventually found, that I am (for now) probably better off with nested (default)dict and set data; while querying tags for a given index was very elegant even with a very simple database design, I wasn't able to get the other query (text interval(s) for given combination of tag-values) with a comparably straightforward solution. It seems, that in order to handle tag combinations of arbitrary length either programmatically created queries or maybe recursion or some kind of postprocessing database data using interval arithmetic would be needed (or probably some database features, I am not getting :) In any case the initial custom datastructure seems to meet the requirements after all. Thanks again, Vlastimil Brom From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 20:33:28 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 23 Sep 2010 00:33:28 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> Message-ID: <4c9aa057$0$11123$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 12:26:29 -0400, Andreas Waldenburger wrote: > On Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Carl Banks > wrote: > >> On Sep 17, 1:01?pm, Andreas Waldenburger >> wrote: >> > On Thu, 16 Sep 2010 16:20:33 -0400 AK wrote: >> > >> > > I also like this construct that works, I think, since 2.6: >> > >> > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] >> > >> > I wonder when this construct will finally start to look good. >> >> I don't know if it'll ever look good, per se, but it looks better when >> it's used in rule-exception sort of case: >> >> something = rule if condition else exception >> > Spot on. I (more or less) like it when used that way, too. But it seems > to invite crackers like the example above, and that irks me. I don't see that one of these is more of a cracker than the other: code = if side == 'l' then dir[int(num):] else dir[:-1*int(num)] code = side == 'l' if dir[int(num):] else dir[:-1*int(num)] code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] If you ask me, the *least* hard to read is the last. Unary and binary operators are natural in a language which is parsed in a single dimension (left-to-right in the case of English). There is no entirely natural way to parse a ternary operator, because you need to fit three operands into two slots. That's why mathematicians often use two dimensions when they need a ternary operator, like sum: ? ? expr i=0 -- Steven From flebber.crue at gmail.com Wed Sep 22 20:41:12 2010 From: flebber.crue at gmail.com (flebber) Date: Wed, 22 Sep 2010 17:41:12 -0700 (PDT) Subject: Python Macros's Not the Power in OOo they should be ? Message-ID: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> I have recently been looking at openoffice because I saw it had support to use python Macro's. I thought this would provide OOo with a great advantage a fully powerful high level language as compared to VBA in Excel. I have found few docs on the subject. http://wiki.services.openoffice.org/wiki/Python_as_a_macro_language http://development.openoffice.org/ http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework Doesn't appear at the moment Python doesn't have the power in OOo it should. Has anyone had much success with python macro's. Or developing powerful macro's in an language? From flebber.crue at gmail.com Wed Sep 22 21:26:50 2010 From: flebber.crue at gmail.com (flebber) Date: Wed, 22 Sep 2010 18:26:50 -0700 (PDT) Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: <8d412c32-d997-40ce-b201-b26ba2f63349@13g2000prf.googlegroups.com> On Sep 23, 10:41?am, flebber wrote: > I have recently been looking at openoffice because I saw it had > support to use python Macro's. I thought this would provide OOo with a > great advantage a fully powerful high level language as compared to > VBA in Excel. > > I have found few docs on the subject.http://wiki.services.openoffice.org/wiki/Python_as_a_macro_languagehttp://development.openoffice.org/http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Scrip... > > Doesn't appear at the moment Python doesn't have the power in OOo it > should. Has anyone had much success with python macro's. Or developing > powerful macro's in an language? I sort of expected they might have had jpython or javascript version of the excel VBA editor. From john at castleamber.com Wed Sep 22 21:37:12 2010 From: john at castleamber.com (John Bokma) Date: Wed, 22 Sep 2010 20:37:12 -0500 Subject: Down with tinyurl! References: <4c96d845$0$11113$c3e8da3@news.astraweb.com> <4c96fdb0$0$11113$c3e8da3@news.astraweb.com> <4c98100d$1@dnews.tpgi.com.au> <4c983c38$0$11089$c3e8da3@news.astraweb.com> <4c9a8d66$0$11123$c3e8da3@news.astraweb.com> Message-ID: <87r5glme9j.fsf@castleamber.com> Steven D'Aprano writes: > You know, I'd give my right arm -- well, perhaps somebody else's right > arm -- for the opportunity to some day to be interviewing an ex-RIAA > executive, just so I can say: > > "I see from your CV that you took millions of customers and made them so > mad at you that not only did they break the law to give you the finger, > but they promised to never, ever pay a cent for your products again. So > tell me, how did that business strategy work out for you?" I guess he will smile at you and blind you with his diamond teeth :-D. Also, the RIAA has been breaking the law as well. They do it via hired sneeky companies, but in my book they are still responsible. (dDOS of torrent sites/clients) -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Wed Sep 22 21:45:55 2010 From: john at castleamber.com (John Bokma) Date: Wed, 22 Sep 2010 20:45:55 -0500 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> <4c9aa057$0$11123$c3e8da3@news.astraweb.com> Message-ID: <87k4mdmdv0.fsf@castleamber.com> Steven D'Aprano writes: For completeness sake: code = side == 'l' ? dir[int(num):] : dir[:-1*int(num)] > code = if side == 'l' then dir[int(num):] else dir[:-1*int(num)] > code = side == 'l' if dir[int(num):] else dir[:-1*int(num)] > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > > If you ask me, the *least* hard to read is the last. For me the (newly added) first one, because it has (for me) less noise. But I can certainly live with the last one. Or all for that matter. Or maybe: since the results are already somewhat complex (or noisy) I probably would use a "normal" if else. What surprises me is that this is still discussed. It's like argueing about significant whitespace. :-) -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From usenet-nospam at seebs.net Wed Sep 22 21:49:44 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 01:49:44 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-23, Steven D'Aprano wrote: > Yes, it certainly is. Describing it as "an ugly format" is also a matter > of taste -- taste which in my opinion simply isn't justified by anything > other than familiarity. It may not be convincing to other people, but the logical inversion strikes me as a taste issue which goes beyond mere familiarity. It is not unreasonable to continue to dislike something which breaks a general principle even after long familiarity. So I think there is a real issue. There are arguments going the other way, and while they don't fit my sense of aesthetics, I guess they aren't strictly required to. But I do think it's unfair to dismiss it as purely a matter of baby duck syndrome. Consistency in ordering of corresponding idioms seems a reasonable goal. -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 prologic at shortcircuit.net.au Wed Sep 22 22:55:07 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 23 Sep 2010 12:55:07 +1000 Subject: Error installing cx_Oracle In-Reply-To: <7e622b5f-1715-472e-aa47-ea145305fa36@k22g2000prb.googlegroups.com> References: <7e622b5f-1715-472e-aa47-ea145305fa36@k22g2000prb.googlegroups.com> Message-ID: On Wed, Sep 22, 2010 at 9:35 PM, AMC wrote: > Hi, > > >From last months I am using Python for making small but useful tools > for my team members. I am doing my development in windows machine and > running the program in Solaris machine where Python 2.6.2 is > installed. > > In one of my program file I had to use the module "cx_Oracle".For that > I have installed the module in my windows machine and done the > programming. But the finished program does not run in Solaris machine, > may be because "cx_Oracle" was not installed there.Following is the > error shown. > > root at access1:/home/amohan/python/work/broadcast_report/bin$ ./ > runsql.py > Traceback (most recent call last): > ?File "./runsql.py", line 3, in > ? ?import cx_Oracle > ImportError: ld.so.1: isapython2.6: fatal: /opt/webstack/python/lib/ > python2.6/site-packages/cx_Oracle.so: wrong ELF class: ELFCLASS64 > root at access1:/home/amohan/python/work/broadcast_report/bin$ > > I tried installing "cx_Oracle" with easy_install utility (I am not > strong in Solaris). While installing I am getting some error as shown > below. > > root at access1:/$ easy_install cx_Oracle > Searching for cx-Oracle > Reading http://pypi.python.org/simple/cx_Oracle/ > Reading http://cx-oracle.sourceforge.net > Reading http://starship.python.net/crew/atuining > Best match: cx-Oracle 5.0.4 > Downloading http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4.tar.gz?download > Processing cx_Oracle-5.0.4.tar.gz > Running cx_Oracle-5.0.4/setup.py -q bdist_egg --dist-dir /tmp/ > easy_install-FkDQn5/cx_Oracle-5.0.4/egg-dist-tmp-Ogg94s > "SessionPool.c", line 200: warning: integer overflow detected: op "<<" > ld: fatal: library -lpython2.6: not found > ld: fatal: File processing errors. No output written to build/ > lib.solaris-2.10-i86pc-2.6-10g/cx_Oracle.so > error: Setup script exited with error: command '/opt/webstack/python/ > lib/python2.6/pycc' failed with exit status 1 > root at access1:/$ > > I have searched for a solution everywhere and tried many things but > didn't work. Can somebody help me in this? Install the python development libraries. cheers James -- -- James Mills -- -- "Problems are solved by method" From ldo at geek-central.gen.new_zealand Wed Sep 22 23:45:19 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 23 Sep 2010 15:45:19 +1200 Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: In message <4d76a2ad-bf85-472e-8c63-ef16f320a411 at t11g2000vbc.googlegroups.com>, flebber wrote: > Has anyone had much success with python macro's. Or developing powerful > macro's in an language? I did an application for my own use recently, involving automatically generating invoices in editable OOWriter format from my billing database. I gave up on all the PyUNO stuff, and used ODFPY instead?so much easier to generate ODF directly, without having to go through OpenOffice code. And OpenOffice has been able to open the results for final tweaking just fine. From steve-REMOVE-THIS at cybersource.com.au Wed Sep 22 23:49:50 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 23 Sep 2010 03:49:50 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> Message-ID: <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> On Thu, 23 Sep 2010 01:49:44 +0000, Seebs wrote: > But I do think it's unfair to dismiss it as purely a matter of baby duck > syndrome. Consistency in ordering of corresponding idioms seems a > reasonable goal. I don't see anyone bitching about: for x in seq: if x: f(x) vs [f(x) for x in seq if x] -- Steven From usenet-nospam at seebs.net Wed Sep 22 23:54:52 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 03:54:52 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-23, Steven D'Aprano wrote: > On Thu, 23 Sep 2010 01:49:44 +0000, Seebs wrote: >> But I do think it's unfair to dismiss it as purely a matter of baby duck >> syndrome. Consistency in ordering of corresponding idioms seems a >> reasonable goal. > I don't see anyone bitching about: > for x in seq: > if x: > f(x) > vs > [f(x) for x in seq if x] In my case, that's because I only ran into that syntax about an hour and a half ago. I have the same basic objection to it. If it were: [for x in seq: if x: f(x)] I'd find it substantially easier to understand. I don't generally like constructs where important structural information comes late in the construct. In the trivial case, I don't suppose it makes a huge difference, but think about the case where seq starts with a ( and x ends with one: [f(x) for x in (1, 2, 3) if foo(x)] As the expressions get complicated, that gets harder to see. IMHO. I dunno. I like the "next if /^$/" idiom, but anything more complicated for either the condition or the thing conditionalized and I tend to prefer to jump back to an explicit if statement. -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 john at castleamber.com Thu Sep 23 00:21:28 2010 From: john at castleamber.com (John Bokma) Date: Wed, 22 Sep 2010 23:21:28 -0500 Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> Message-ID: <877hidm6nr.fsf@castleamber.com> Seebs writes: > I dunno. I like the "next if /^$/" idiom, I don't (as a Perl programmer), I prefer: $line =~ /^$/ and next; Or: $line ne '' or next; which I read as: line must not be empty -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From usenet-nospam at seebs.net Thu Sep 23 00:48:57 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 04:48:57 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> <877hidm6nr.fsf@castleamber.com> Message-ID: On 2010-09-23, John Bokma wrote: > Seebs writes: >> I dunno. I like the "next if /^$/" idiom, > I don't (as a Perl programmer), I prefer: Huh, those are actually nicer. I didn't know that was possible; it wouldn't have occurred to me to try to put "next" (which I think of as a statement) into an expression. Basically, I can live with a postfix "if" as long as everything involved is trivial. Past that... I'd rather see the condition up front. -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 cbrown at cbrownsystems.com Thu Sep 23 01:22:11 2010 From: cbrown at cbrownsystems.com (cbrown at cbrownsystems.com) Date: Wed, 22 Sep 2010 22:22:11 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> Message-ID: <09773509-53c8-43ec-9b13-d91df8bc4cf4@q40g2000prg.googlegroups.com> On Sep 22, 3:39?pm, Baba wrote: > On Sep 22, 9:18?pm, Baba wrote: > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > Hi > > > > > query level: beginner > > > > > as part of a learning exercise i have written code that: > > > wordlist = ['hello', 'bye'] > > hand = '' > > for item in wordlist: > > ? ? if item.startswith(hand): > > ? ? ? ? while item.startswith(hand): > > ? ? ? ? ? ? if hand not in wordlist: > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > ? ? ? ? ? ? ? ? print hand > > ? ? ? ? ? ? else: break > > ? ? ? ? else: break > > print 'you loose' > > > But i can't figure out why it won't work when adding the extra word. > > Thanks by the way, it taught me not to be too confident when things > > SEEM to work... > > looking at my original code again i realise that having a raw_input > inside a FOR loop is flawed per se (at least for my purposes) so i > will just assume that i was taking the wrong approach initially. No > point in analysing it further. Thanks for your help. > Yes, the overall structure using the 'for' loop was a bit awkward, and your second attempt using 'any' is much clearer; but I'd say it's still worth seeing how your original logic failed. It has to do with the action of the 'break's. Ask yourself, which code block does the 'if <> else: break' contained /within/ your while loop, break you out of? And which code block does the 'while <> else: break' break you out of? One other thing... it's 'you LOSE', not 'you LOOSE'!!!!! (personal pet peeve ;-) ) Cheers - Chas From vineetdaniel at gmail.com Thu Sep 23 01:30:56 2010 From: vineetdaniel at gmail.com (vineet daniel) Date: Wed, 22 Sep 2010 22:30:56 -0700 (PDT) Subject: creating python daemon ? References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> <87fwx2yw04.fsf@web.de> Message-ID: <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> On Sep 22, 2:20?pm, de... at web.de (Diez B. Roggisch) wrote: > vineet daniel writes: > > On Sep 21, 9:47?pm, de... at web.de (Diez B. Roggisch) wrote: > >> vineet daniel writes: > >> > Hi > > >> > I have succesfully created daemon with python script and as next step > >> > I am trying to give input to that python script daemon from Apache > >> > Logs....here I have got stuck and I have even checked IRC python > >> > channel for solution. Apache is able to call the file but fails to > >> > execute it properly and I get this error continuosly : > > >> > piped log program '/var/www/html/test.py' failed unexpectedly > > >> > How do I rectify the above error and make adjustment to the code so > >> > that it takes input from apache. > > >> > code that I am using is as follows : > > >> > #! /usr/bin/env python > >> > import sys,os > >> > pid = os.fork() > >> > os.chdir("/var/www/html/") > >> > os.setsid() > >> > os.umask(0) > >> > #this line will read apache log in real time as redirected from the > >> > CustomLog directive of Apache. > >> > log = sys.stdin.readlines() > >> > f = open('/var/www/logmongo.txt','a') # append log to this text file > >> > f.write(log) > > >> > I'd appreciate if anybody could share the code that they used for > >> > daemon or used with Apache CustomLog directive. > > >> The above code looks errornous - you don't check for the return-value of > >> PID & take appropriate action. Like > > >> There is a daemonization recipe on active-state, which works nicely for > >> me. > > >>http://code.activestate.com/recipes/278731-creating-a-daemon-the-pyth... > > >> Diez > > > Hi Diez > > > Thanks for pointing that out. > > Ever tried giving input to such python daemons from a dynamic source > > like Apache logs which get generated in real time. I want apache to > > directly write to this python daemon which in turn will process the > > logs the way I want. Any help will help me immensely. > > I don't understand the question. How is that input produced? How shall > the two processes interact? Through some logfile one writes, the other > reads? Through RPC-mechanisms? Sockets? Pipes? > > The fact that process B is a daemon or not has nothing to do with this > whatsoever, btw. > > Diez Hi Diez There is a directive in Apache - CustomLog which can redirect logs to a script or another file by using Pipe. I googled about it and came to know that this works flawlessly with Perl as Apache treats Perl scripts as daemon, for Python to take input from Apache, it needs to work as daemon. Apache will then push its logs lines to this daemon as input. Perl takes this input as but python's stdin is not working as expected it just takes the file name as given in CustomLog directive using Pipe i.e if I use CustomLog '|/var/wwww/script.py' combined, what script reads is just the file name, how and why I am not able to figure it out. And thats the reason I am here. I hope you've got what I am trying to do. From usernet at ilthio.net Thu Sep 23 01:58:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Sep 2010 05:58:59 +0000 (UTC) Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: On 2010-09-23, Lawrence D'Oliveiro wrote: > In message ><4d76a2ad-bf85-472e-8c63-ef16f320a411 at t11g2000vbc.googlegroups.com>, flebber > wrote: > >> Has anyone had much success with python macro's. Or developing powerful >> macro's in an language? > > I did an application for my own use recently, involving automatically > generating invoices in editable OOWriter format from my billing database. I > gave up on all the PyUNO stuff, and used ODFPY instead???so much easier to > generate ODF directly, without having to go through OpenOffice code. Much agreed. The UNO architecture seems to have been rather mishandled. While the general idea was nice, the implementation seems to be overly complicated and poorly documented. The ODF format itself is rather easy to figure out manipulate directly. For those who do not know, the file is just a jar archive with the content and style information all formatted as xml files. I will use the ODF spreadsheet file as an example. ) 00:40,501$ ls demo.ods typescript ) ) 00:40,502$ /usr/lib64/java/bin/jar -xf demo.ods ) ) 00:40,503$ ls ) Configurations2 META-INF Thumbnails content.xml demo.ods ) meta.xml mimetype settings.xml styles.xml typescript ) ) 00:40,504$ xmlformat < content.xml | fmt ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) This is cell A1 ) ) 8 ) ) 64 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) 00:41,505$ exit From simon at brunningonline.net Thu Sep 23 03:28:05 2010 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 23 Sep 2010 08:28:05 +0100 Subject: ctypes In-Reply-To: References: Message-ID: On 22 September 2010 21:13, jay thompson wrote: > Hello, > > I posted in regard to this in the past but it didn't go very far, no ones > fault, but I'm again atempting to make this work and could use some help. > > I would like to use libraw.dll (http://www.libraw.org/? version 0.10) from > python and can access all the functions fine and produce images but there is > a structure that holds all the process settings that I cannot access with > ctypes. I'm sure it's because I'm going about it the wrong way. I was > wondering if there was anyone in this list with experience with this sort of > thing that could point me in the right direction. A good start would be to tell us what you've tried, and what goes wrong when you try it. -- Cheers, Simon B. From shaflich at gmail.com Thu Sep 23 04:18:32 2010 From: shaflich at gmail.com (smh) Date: Thu, 23 Sep 2010 01:18:32 -0700 (PDT) Subject: HTML6 proposal (Re: sexp xml syntax transformation) References: <2bebbf7e-e30d-41a7-bed5-72a132d9de79@z30g2000prg.googlegroups.com> <30bd8745-ef6a-4c5c-8f30-fbbbf8a9bd91@l32g2000prn.googlegroups.com> Message-ID: <1e9d517f-d6d3-4264-8388-66b52cdee0f1@b14g2000pro.googlegroups.com> The following is not exactly what you are looking for, but you might find it interesting. http://www.franz.com/support/tech_corner/xml-generator-blurb.html This blurb is an example of a self-embedding document. I've used this XML generator in many applications, and it is usually elegant to use the structural parallel between an XML tree and the Lisp code that generates it. I haven't thought whether it could be reasonable to port it to scheme. Anyone who wants to think about it has my blessing! From bborcic at gmail.com Thu Sep 23 05:12:20 2010 From: bborcic at gmail.com (Boris Borcic) Date: Thu, 23 Sep 2010 11:12:20 +0200 Subject: Python Macros's Not the Power in OOo they should be ? In-Reply-To: References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > flebber wrote: > >> Has anyone had much success with python macro's. Or developing powerful >> macro's in an language? > > I did an application for my own use recently, involving automatically > generating invoices in editable OOWriter format from my billing database. I > gave up on all the PyUNO stuff, and used ODFPY instead?so much easier to > generate ODF directly, without having to go through OpenOffice code. > > And OpenOffice has been able to open the results for final tweaking just > fine. A nice package to manipulate Ooo text documents with python is the pod module of the appy framework. It uses the same approach with a twist. From xahlee at gmail.com Thu Sep 23 07:33:37 2010 From: xahlee at gmail.com (Xah Lee) Date: Thu, 23 Sep 2010 04:33:37 -0700 (PDT) Subject: HTML6 proposal (Re: sexp xml syntax transformation) References: <2bebbf7e-e30d-41a7-bed5-72a132d9de79@z30g2000prg.googlegroups.com> <30bd8745-ef6a-4c5c-8f30-fbbbf8a9bd91@l32g2000prn.googlegroups.com> <1e9d517f-d6d3-4264-8388-66b52cdee0f1@b14g2000pro.googlegroups.com> Message-ID: <19ce074c-803e-43ad-983a-8d40b69668ae@s17g2000prh.googlegroups.com> On Sep 23, 1:18?am, smh wrote: > The following is not exactly what you are looking for, but you might > find it interesting. > > http://www.franz.com/support/tech_corner/xml-generator-blurb.html > > This blurb is an example of a self-embedding document. > I've used this XML generator in many applications, and it is usually > elegant to use the structural parallel between an XML tree and the > Lisp code that generates it. Thanks. Very interesting. i guess that's like lisp's PHP. > I haven't thought whether it could be reasonable to port it to > scheme. ?Anyone who wants to think about it has my blessing! just curious, i can't believe if there's not already something similar in scheme lisp. Xah ? xahlee.org ? From nn.roh1 at gmail.com Thu Sep 23 07:50:42 2010 From: nn.roh1 at gmail.com (n.a.s) Date: Thu, 23 Sep 2010 14:50:42 +0300 Subject: problem in Gasp ! Message-ID: Hi, I want to ask about graphics using Gasp .Attached is exercise 10 (houses at night) ,if i call the draw_house function once it will work properly ,but more than one call,windows and doors disappear from some houses . Any one can advice? Thanks, Nada -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: house.pyw Type: application/octet-stream Size: 1398 bytes Desc: not available URL: From ldo at geek-central.gen.new_zealand Thu Sep 23 08:31:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 00:31:22 +1200 Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: In message , Tim Harig wrote: > The UNO architecture seems to have been rather mishandled. While the > general idea was nice, the implementation seems to be overly complicated > and poorly documented. For an example of a much nicer way of doing things, compare the Python support in Blender: it?s a lot easier to get something simple working, and there are loads of scripts already written by others that you can refer to. Of course, they?ve completely reworked the scripting API in 2.5, but I think that?s for the better. From funthyme at gmail.com Thu Sep 23 08:50:23 2010 From: funthyme at gmail.com (John Pinner) Date: Thu, 23 Sep 2010 05:50:23 -0700 (PDT) Subject: Python Macros's Not the Power in OOo they should be ? References: <4d76a2ad-bf85-472e-8c63-ef16f320a411@t11g2000vbc.googlegroups.com> Message-ID: On Sep 23, 10:12?am, Boris Borcic wrote: > Lawrence D'Oliveiro wrote: > > flebber wrote: > > >> Has anyone had much success with python macro's. Or developing powerful > >> macro's in an language? > > > I did an application for my own use recently, involving automatically > > generating invoices in editable OOWriter format from my billing database. I > > gave up on all the PyUNO stuff, and used ODFPY instead?so much easier to > > generate ODF directly, without having to go through OpenOffice code. > > > And OpenOffice has been able to open the results for final tweaking just > > fine. > > A nice package to manipulate Ooo text documents with python is the pod module of > the appy framework. It uses the same approach with a twist. One of our guys, David Chan, has done something you may find useful, 'OpenDocMill': http://www.troi.org/opendoc-mill.html We use it to produce some quite complicated documents, for example Engineering Reports, Invoices, Certificates. Best wishes, John -- From jldunn2000 at gmail.com Thu Sep 23 10:34:15 2010 From: jldunn2000 at gmail.com (loial) Date: Thu, 23 Sep 2010 07:34:15 -0700 (PDT) Subject: Scheduling in python Message-ID: I want to enable my end users to be able to schedule a task(actually running another python or shell script). Rather than scheduling it directly in cron, are there any python modules I could use? From pruebauno at latinmail.com Thu Sep 23 10:56:21 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 23 Sep 2010 07:56:21 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> Message-ID: <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> On Sep 22, 6:39?pm, Baba wrote: > On Sep 22, 9:18?pm, Baba wrote: > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > Hi > > > > > query level: beginner > > > > > as part of a learning exercise i have written code that: > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > entered) > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > c) start again until 2) is True > > > > > wordlist = ['hello', 'bye'] > > > > handlist = [] > > > > letter = raw_input('enter letter: ') > > > > handlist.append(letter) > > > > hand = "".join(handlist) > > > > for item in wordlist: > > > > ? ? if item.startswith(hand): > > > > ? ? ? ? while item.startswith(hand): > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > ? ? ? ? ? ? else: break > > > > ? ? ? ? else: break > > > > print 'you loose' > > > > > this code works but can it be optimised? i have the feeling that my > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > thanks > > > > Baba > > > > Yes it is overkill. Especially the else:break from the while loop > > > makes it difficult to follow the logic. Also the program breaks down > > > if I use the following word list: > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > enter letter: h > > > enter letter: a > > > you loose > > > > I am not going to post any spoilers but I wrote your program using one > > > while loop and one generator expression for a total of 5 lines. My > > > version might be a bit too advanced but you should still be able to do > > > it using only one while, one for and one if instead. > > > Hi nn, > > > i wasn't expecting my code to fail with an additional word in it. > > While i was conscious that the whole construct was heavy i thought the > > reasoning worked. I keep looking at it but can't figure out the > > problem Can you give me a hint? > > > In the meantime i found out that it is actually possible to populate a > > string (just like a list, a dictionary or a tuple). Here's what i've > > got now: > > > wordlist = ['hello', 'bye'] > > hand = '' > > for item in wordlist: > > ? ? if item.startswith(hand): > > ? ? ? ? while item.startswith(hand): > > ? ? ? ? ? ? if hand not in wordlist: > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > ? ? ? ? ? ? ? ? print hand > > ? ? ? ? ? ? else: break > > ? ? ? ? else: break > > print 'you loose' > > > But i can't figure out why it won't work when adding the extra word. > > Thanks by the way, it taught me not to be too confident when things > > SEEM to work... > > > Why does it work when i use the built-in function any(iterable)?? To > > me using the any(iterable) function seems just like regrouping 3 lines > > into one... > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > hand = '' > > while any(item.startswith(hand) for item in wordlist): > > ? ? if hand not in wordlist: > > ? ? ? ? hand += raw_input('enter letter: ') > > ? ? else: break > > print 'you loose' > > > thanks > > > Baba > > Hi nn, > > looking at my original code again i realise that having a raw_input > inside a FOR loop is flawed per se (at least for my purposes) so i > will just assume that i was taking the wrong approach initially. No > point in analysing it further. Thanks for your help. > > Baba Since you seem to have figured it out I will post my version (python 3): wordlist = ['hello', 'hamburger', 'bye'] inp='' while any(word.startswith(inp) and word!=inp for word in wordlist): inp += input('enter letter: ') print('you lose') The reason why your original version didn't work was because each time you add a letter you have to go again over all words (in reality only a subset is required) and find a new one. Your version would find one word using the first letter and then exit. From jldunn2000 at gmail.com Thu Sep 23 11:08:50 2010 From: jldunn2000 at gmail.com (loial) Date: Thu, 23 Sep 2010 08:08:50 -0700 (PDT) Subject: Check whether file is being written to Message-ID: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> How can I check whether a file is being written to by another process before I access it? Platform is unix. From pruebauno at latinmail.com Thu Sep 23 11:17:06 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 23 Sep 2010 08:17:06 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> Message-ID: <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> On Sep 23, 10:56?am, nn wrote: > On Sep 22, 6:39?pm, Baba wrote: > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > Hi > > > > > > query level: beginner > > > > > > as part of a learning exercise i have written code that: > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > entered) > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > c) start again until 2) is True > > > > > > wordlist = ['hello', 'bye'] > > > > > handlist = [] > > > > > letter = raw_input('enter letter: ') > > > > > handlist.append(letter) > > > > > hand = "".join(handlist) > > > > > for item in wordlist: > > > > > ? ? if item.startswith(hand): > > > > > ? ? ? ? while item.startswith(hand): > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > ? ? ? ? ? ? else: break > > > > > ? ? ? ? else: break > > > > > print 'you loose' > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > thanks > > > > > Baba > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > makes it difficult to follow the logic. Also the program breaks down > > > > if I use the following word list: > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > enter letter: h > > > > enter letter: a > > > > you loose > > > > > I am not going to post any spoilers but I wrote your program using one > > > > while loop and one generator expression for a total of 5 lines. My > > > > version might be a bit too advanced but you should still be able to do > > > > it using only one while, one for and one if instead. > > > > Hi nn, > > > > i wasn't expecting my code to fail with an additional word in it. > > > While i was conscious that the whole construct was heavy i thought the > > > reasoning worked. I keep looking at it but can't figure out the > > > problem Can you give me a hint? > > > > In the meantime i found out that it is actually possible to populate a > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > got now: > > > > wordlist = ['hello', 'bye'] > > > hand = '' > > > for item in wordlist: > > > ? ? if item.startswith(hand): > > > ? ? ? ? while item.startswith(hand): > > > ? ? ? ? ? ? if hand not in wordlist: > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > ? ? ? ? ? ? ? ? print hand > > > ? ? ? ? ? ? else: break > > > ? ? ? ? else: break > > > print 'you loose' > > > > But i can't figure out why it won't work when adding the extra word. > > > Thanks by the way, it taught me not to be too confident when things > > > SEEM to work... > > > > Why does it work when i use the built-in function any(iterable)?? To > > > me using the any(iterable) function seems just like regrouping 3 lines > > > into one... > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > hand = '' > > > while any(item.startswith(hand) for item in wordlist): > > > ? ? if hand not in wordlist: > > > ? ? ? ? hand += raw_input('enter letter: ') > > > ? ? else: break > > > print 'you loose' > > > > thanks > > > > Baba > > > Hi nn, > > > looking at my original code again i realise that having a raw_input > > inside a FOR loop is flawed per se (at least for my purposes) so i > > will just assume that i was taking the wrong approach initially. No > > point in analysing it further. Thanks for your help. > > > Baba > > Since you seem to have figured it out I will post my version (python > 3): > > wordlist = ['hello', 'hamburger', 'bye'] > inp='' > while any(word.startswith(inp) and word!=inp for word in wordlist): > ? ? inp += input('enter letter: ') > print('you lose') > > The reason why your original version didn't work was because each time > you add a letter you have to go again over all words (in reality only > a subset is required) and find a new one. Your version would find one > word using the first letter and then exit. Actually my version isn't right (for some values of right): wordlist = ['hello', 'hamburger', 'bye'] inp='' while any(word.startswith(inp) for word in wordlist) and (inp not in wordlist): inp += input('enter letter: ') print('you lose') An explanation of how this changes the rules of the wordgame is left as an exercise to the reader. From usenet-nospam at seebs.net Thu Sep 23 11:20:07 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 15:20:07 GMT Subject: Check whether file is being written to References: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> Message-ID: On 2010-09-23, loial wrote: > How can I check whether a file is being written to by another process > before I access it? You mean "written to" or "open for possible writing"? It may be possible (with sufficient privileges) to determine that a file has been opened for writing. I don't think you can detect being-written-to. More importantly, though, the question is irrelevant, because even if you absolutely, conclusively, prove that a file is not open nor being written to, before your next machine instruction loads, the file could be opened and rewritten multiple times by whole new processes that weren't even running when you checked. I suggest you look into advisory locks. -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 thomas at jollybox.de Thu Sep 23 11:26:09 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 23 Sep 2010 17:26:09 +0200 Subject: Check whether file is being written to In-Reply-To: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> References: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> Message-ID: <201009231726.10000.thomas@jollybox.de> On Thursday 23 September 2010, it occurred to loial to exclaim: > How can I check whether a file is being written to by another process > before I access it? > > Platform is unix. As such, you can't. But you can lock the file using the functions in the fcntl module. From thomas at jollybox.de Thu Sep 23 11:30:21 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 23 Sep 2010 17:30:21 +0200 Subject: Scheduling in python In-Reply-To: References: Message-ID: <201009231730.21829.thomas@jollybox.de> On Thursday 23 September 2010, it occurred to loial to exclaim: > I want to enable my end users to be able to schedule a task(actually > running another python or shell script). Rather than scheduling it > directly in cron, are there any python modules I could use? If you have a "master" process running -- it strongly depends on how that process is structured. Is there a main loop? What does it look like? Is it provided by some toolkit? Maybe that toolkit has an alarm event? In the end, there isn't much too it: periodically check if "it's time", and then possibly do something. I doubt there's a package to do this. The basics are trivial to implement, and everything depends strongly on the program structure, which could vary greatly. From usenot at geekmail.INVALID Thu Sep 23 11:38:33 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 23 Sep 2010 11:38:33 -0400 Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> Message-ID: <20100923113833.58a04826@geekmail.INVALID> On 23 Sep 2010 03:54:52 GMT Seebs wrote: > On 2010-09-23, Steven D'Aprano > wrote: > [snip] > > I don't see anyone bitching about: > > > for x in seq: > > if x: > > f(x) > > > vs > > > [f(x) for x in seq if x] > > In my case, that's because I only ran into that syntax about an hour > and a half ago. I have the same basic objection to it. If it were: > > [for x in seq: if x: f(x)] > > I'd find it substantially easier to understand. > > I don't generally like constructs where important structural > information comes late in the construct. [snip] I think that is precisely the reason that the elements of the list come *first* in the list comprehension expression. The foremost idea of list comprehensions is "build a list", while the idea of a for-loop is "iterate over something". /W -- INVALID? DE! From paul.nospam at rudin.co.uk Thu Sep 23 11:39:41 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 23 Sep 2010 16:39:41 +0100 Subject: Scheduling in python References: Message-ID: <87r5gkbhaa.fsf@rudin.co.uk> loial writes: > I want to enable my end users to be able to schedule a task(actually > running another python or shell script). Rather than scheduling it > directly in cron, are there any python modules I could use? First hit when googling "python schedule"? From usenot at geekmail.INVALID Thu Sep 23 11:40:55 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 23 Sep 2010 11:40:55 -0400 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> <4c9aa057$0$11123$c3e8da3@news.astraweb.com> Message-ID: <20100923114055.11443545@geekmail.INVALID> On 23 Sep 2010 00:33:28 GMT Steven D'Aprano wrote: > On Tue, 21 Sep 2010 12:26:29 -0400, Andreas Waldenburger wrote: > > > On Sat, 18 Sep 2010 19:09:33 -0700 (PDT) Carl Banks > > wrote: > > > >> On Sep 17, 1:01?pm, Andreas Waldenburger > >> wrote: > >> > On Thu, 16 Sep 2010 16:20:33 -0400 AK > >> > wrote: > >> > > >> > > I also like this construct that works, I think, since 2.6: > >> > > >> > > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > >> > > >> > I wonder when this construct will finally start to look good. > >> > >> I don't know if it'll ever look good, per se, but it looks better > >> when it's used in rule-exception sort of case: > >> > >> something = rule if condition else exception > >> > > Spot on. I (more or less) like it when used that way, too. But it > > seems to invite crackers like the example above, and that irks me. > > > I don't see that one of these is more of a cracker than the other: > > > code = if side == 'l' then dir[int(num):] else dir[:-1*int(num)] > code = side == 'l' if dir[int(num):] else dir[:-1*int(num)] > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)] > > > If you ask me, the *least* hard to read is the last. > I agree again. I wasn't really talking about the specific order of the ternary operator but rather about the whole idea. It invites messiness. /W -- INVALID? DE! From gslindstrom at gmail.com Thu Sep 23 11:41:41 2010 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Thu, 23 Sep 2010 10:41:41 -0500 Subject: Distributing Packages Message-ID: I am not intending to start anything, here, but would like to know if any consensus has been reached in how to distribute Python modules. Specifically, I'd like to use something to install packages on various machines in our enterprise (mostly Linux, but some windows boxes, too). I've read up on distutils, but also recall hearing about Python eggs and sitting in on a talk or two at PyCon (US) that seemed to indicate that the community was in a state of flux over how to distribute things. What are the current thoughts on the subject? Thanks, --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenot at geekmail.INVALID Thu Sep 23 11:42:25 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 23 Sep 2010 11:42:25 -0400 Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> <4c9aa057$0$11123$c3e8da3@news.astraweb.com> <87k4mdmdv0.fsf@castleamber.com> Message-ID: <20100923114225.32f7253e@geekmail.INVALID> On Wed, 22 Sep 2010 20:45:55 -0500 John Bokma wrote: > What surprises me is that this is still discussed. It's like argueing > about significant whitespace. :-) Which is evil! /W -- INVALID? DE! From thomas at jollybox.de Thu Sep 23 11:52:18 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 23 Sep 2010 17:52:18 +0200 Subject: Playing sounds at time indexes In-Reply-To: References: Message-ID: <201009231752.18822.thomas@jollybox.de> On Wednesday 22 September 2010, it occurred to OKB (not okblacke) to exclaim: > I'm looking for an audio library for Python. I googled and found a > few, but none of them seem to have a simple way to play a particular > sound file from a particular start-time to an end-time. Like, I'd want > to load a file and say "Play the section of this file from 10.25 seconds > to 11.73 seconds." Is there a library that makes this easy in Python? platform? From deets at web.de Thu Sep 23 11:55:52 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 23 Sep 2010 17:55:52 +0200 Subject: Check whether file is being written to References: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> Message-ID: <87bp7ozc6v.fsf@web.de> Thomas Jollans writes: > On Thursday 23 September 2010, it occurred to loial to exclaim: >> How can I check whether a file is being written to by another process >> before I access it? >> >> Platform is unix. > > As such, you can't. But you can lock the file using the functions in the fcntl > module. Last time I checked, file-locking in unix was co-operative. Diez From usenet-nospam at seebs.net Thu Sep 23 12:01:04 2010 From: usenet-nospam at seebs.net (Seebs) Date: 23 Sep 2010 16:01:04 GMT Subject: Too much code - slicing References: <4c958185$0$11113$c3e8da3@news.astraweb.com> <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> <4c9ace5d$0$28668$c3e8da3@news.astraweb.com> <20100923113833.58a04826@geekmail.INVALID> Message-ID: On 2010-09-23, Andreas Waldenburger wrote: > On 23 Sep 2010 03:54:52 GMT Seebs wrote: >> I don't generally like constructs where important structural >> information comes late in the construct. [snip] > I think that is precisely the reason that the elements of the list come > *first* in the list comprehension expression. The foremost idea of list > comprehensions is "build a list", while the idea of a for-loop is > "iterate over something". Interesting! I tend to think of "building a list" as more like a for loop than like a data item with a qualifier. If the first word inside the [] were "for", that would tell me that the list was going to have some kind of looping or generating going on, while if it's an expression, especially a complicated expression, I don't know that right away. But I can see it making sense either way for the loop, just because of the similarity to mathematical notation. -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 burton at userful.com Thu Sep 23 12:16:50 2010 From: burton at userful.com (Burton Samograd) Date: Thu, 23 Sep 2010 10:16:50 -0600 Subject: Playing sounds at time indexes References: Message-ID: "OKB (not okblacke)" writes: > I'm looking for an audio library for Python. I googled and found a > few, but none of them seem to have a simple way to play a particular > sound file from a particular start-time to an end-time. Like, I'd want > to load a file and say "Play the section of this file from 10.25 seconds > to 11.73 seconds." Is there a library that makes this easy in Python? You might want to check out this question on StackOverflow: http://stackoverflow.com/questions/108848/python-music-library -- Burton Samograd From c_barret at qualcomm.com Thu Sep 23 12:28:15 2010 From: c_barret at qualcomm.com (David A. Barrett) Date: Thu, 23 Sep 2010 09:28:15 -0700 Subject: collections.namedtuple: conflicting instances? Message-ID: <4C9B801F.6070304@qualcomm.com> I've noticed that it's possible to create conflicting instances of the collections.namedtuple class: from collections import namedtuple as nt IX = nt('X', 'a b') IY = nt('Y', 'c d') x = IX(0, 1) y = IY(2, 3) The above are non-conflicting class instances and of two distinct namedtuple classes and distinct instances of those classes, but what happens with this? IX2 = nt('X', 'g') z = IX2(10) It looks like IX and IX2 are two distinct classes, which makes sense, but what is the classname parameter passed to the constructor used for? Is it an error to construct two distinct classes with the same value? I was wondering if it's useful to allow duplicate (consistant) constructions, but have them simply return the same class instance. Should inconsistant constructions with the same name raise and exception? From nobody at nowhere.com Thu Sep 23 13:17:59 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 23 Sep 2010 18:17:59 +0100 Subject: Subprocess does not return for longer-running process References: Message-ID: On Thu, 23 Sep 2010 12:25:53 +1200, Lawrence D'Oliveiro wrote: >> And I can't think of any reason why you should use os.waitpid() or >> similar; use the .wait() method. > > I have used WNOHANG to poll for completion of a subprocess while providing > progress updates to the user. This can be done via the .poll() method. From ahz001 at gmail.com Thu Sep 23 13:22:33 2010 From: ahz001 at gmail.com (Andrew Z.) Date: Thu, 23 Sep 2010 10:22:33 -0700 (PDT) Subject: Parsing error for ConfigParser Message-ID: <0c7a4de7-9a1b-40c6-a84f-726295cb311a@w4g2000vbh.googlegroups.com> Is there a way to parse RealPlayer's realplayerrc in Python? I need to support Python 2.5 - 2.7 Example code import urllib2 import ConfigParser f = urllib2.urlopen('http://pastebin.com/download.php?i=N1AcUg3w') config = ConfigParser.RawConfigParser() config.readfp(f) Error Traceback (most recent call last): File "test_config_parser_real_player.py", line 6, in config.readfp(f) File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp self._read(fp, filename) File "/usr/lib/python2.6/ConfigParser.py", line 510, in _read raise e ConfigParser.ParsingError: File contains parsing errors: [line 31]: '%0aCopyright (c) 1995-2000 Macromedia, Inc. All rights reserved.\r\n' [line 34]: '%0a\r\n' From nobody at nowhere.com Thu Sep 23 13:23:34 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 23 Sep 2010 18:23:34 +0100 Subject: Check whether file is being written to References: <0b3fef8a-eb59-4960-bcde-b95d8dd831cc@s19g2000vbr.googlegroups.com> <87bp7ozc6v.fsf@web.de> Message-ID: On Thu, 23 Sep 2010 17:55:52 +0200, Diez B. Roggisch wrote: > Last time I checked, file-locking in unix was co-operative. Linux supports mandatory locking, but it's seldom enabled. From raoulbia at gmail.com Thu Sep 23 13:25:27 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 23 Sep 2010 10:25:27 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> Message-ID: On Sep 23, 4:17?pm, nn wrote: > On Sep 23, 10:56?am, nn wrote: > > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > Hi > > > > > > > query level: beginner > > > > > > > as part of a learning exercise i have written code that: > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > entered) > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > c) start again until 2) is True > > > > > > > wordlist = ['hello', 'bye'] > > > > > > handlist = [] > > > > > > letter = raw_input('enter letter: ') > > > > > > handlist.append(letter) > > > > > > hand = "".join(handlist) > > > > > > for item in wordlist: > > > > > > ? ? if item.startswith(hand): > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > ? ? ? ? ? ? else: break > > > > > > ? ? ? ? else: break > > > > > > print 'you loose' > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > thanks > > > > > > Baba > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > if I use the following word list: > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > enter letter: h > > > > > enter letter: a > > > > > you loose > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > version might be a bit too advanced but you should still be able to do > > > > > it using only one while, one for and one if instead. > > > > > Hi nn, > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > While i was conscious that the whole construct was heavy i thought the > > > > reasoning worked. I keep looking at it but can't figure out the > > > > problem Can you give me a hint? > > > > > In the meantime i found out that it is actually possible to populate a > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > got now: > > > > > wordlist = ['hello', 'bye'] > > > > hand = '' > > > > for item in wordlist: > > > > ? ? if item.startswith(hand): > > > > ? ? ? ? while item.startswith(hand): > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > ? ? ? ? ? ? ? ? print hand > > > > ? ? ? ? ? ? else: break > > > > ? ? ? ? else: break > > > > print 'you loose' > > > > > But i can't figure out why it won't work when adding the extra word. > > > > Thanks by the way, it taught me not to be too confident when things > > > > SEEM to work... > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > into one... > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > hand = '' > > > > while any(item.startswith(hand) for item in wordlist): > > > > ? ? if hand not in wordlist: > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > ? ? else: break > > > > print 'you loose' > > > > > thanks > > > > > Baba > > > > Hi nn, > > > > looking at my original code again i realise that having a raw_input > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > will just assume that i was taking the wrong approach initially. No > > > point in analysing it further. Thanks for your help. > > > > Baba > > > Since you seem to have figured it out I will post my version (python > > 3): > > > wordlist = ['hello', 'hamburger', 'bye'] > > inp='' > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > ? ? inp += input('enter letter: ') > > print('you lose') > > > The reason why your original version didn't work was because each time > > you add a letter you have to go again over all words (in reality only > > a subset is required) and find a new one. Your version would find one > > word using the first letter and then exit. > > Actually my version isn't right (for some values of right): > > wordlist = ['hello', 'hamburger', 'bye'] > inp='' > while any(word.startswith(inp) for word in wordlist) and (inp not in > wordlist): > ? ? inp += input('enter letter: ') > print('you lose') > > An explanation of how this changes the rules of the wordgame is left > as an exercise to the reader. Hi, for now i will stick to Python2.7 but thank you for sharing. for learning purposes i still want to figure out a way to solve this without built-in function ('any' in this case). My understanding was that in programming almost anything can be done with IF, FOR and WHILE statements. However i turn in circles...:( i understand that in my original code my while loop locked me into the first word hello if the first letter was 'h' and therefore if the next letter was 'a' it would break...so far so good but this appears really tricky to solve...here is what i have come up with but it will not exit if for example i enter 'x' ... wordlist = ['hello', 'bye'] hand = '' while hand not in wordlist: hand += raw_input('enter letter: ') print hand for item in wordlist: if not item.startswith(hand): break print 'you lose' but no matter how i turn this around i can't find the magic approach...i was thinking about starting the code with something like "while (something) is True" ... would that be a right approach? Baba From crebert at ucsd.edu Thu Sep 23 13:40:12 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Thu, 23 Sep 2010 10:40:12 -0700 Subject: collections.namedtuple: conflicting instances? In-Reply-To: <4C9B801F.6070304@qualcomm.com> References: <4C9B801F.6070304@qualcomm.com> Message-ID: On Thu, Sep 23, 2010 at 9:28 AM, David A. Barrett wrote: > ?I've noticed that it's possible to create conflicting instances of the > collections.namedtuple class: > > ?from collections ?import namedtuple as nt > ?IX = nt('X', 'a b') > ?IY = nt('Y', 'c d') > ?x = IX(0, 1) > ?y = IY(2, 3) > > The above are non-conflicting class instances and of two distinct namedtuple > classes and distinct instances of those classes, but what happens with this? > > ?IX2 = nt('X', 'g') > ?z = IX2(10) > > It looks like IX and IX2 are two distinct classes, which makes sense, but > what is the classname parameter passed to the constructor used for? Documentation for human readers (the .__name__ class attribute). As your example shows, the name you pass in doesn't have to match the name you assign the resulting class to and actually use (i.e. "X" vs. "IX"); it's rather like how you were able to use "nt" instead of "namedtuple". >?Is it > an error to construct two distinct classes with the same value? Of course not. Otherwise, classes would have to have *globally unique* names, and stuff like the following wouldn't be possible (which would be bad): # mechanical.py class Engineer(object): '''Models a mechanical engineer.''' # ... # trains.py class Engineer(object): '''Models a person who drives a train.''' # ... # main.py # Models a train company and associated repair yard. import mechanical import trains # ... > Should > inconsistant constructions with the same name raise and exception? Probably not (see answer to previous sentence); showing a warning /might/ be appropriate. Cheers, Chris -- http://blog.rebertia.com From pruebauno at latinmail.com Thu Sep 23 13:55:36 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 23 Sep 2010 10:55:36 -0700 (PDT) Subject: collections.namedtuple: conflicting instances? References: <4C9B801F.6070304@qualcomm.com> Message-ID: On Sep 23, 1:40?pm, Chris Rebert wrote: > On Thu, Sep 23, 2010 at 9:28 AM, David A. Barrett wrote: > > > > > ?I've noticed that it's possible to create conflicting instances of the > > collections.namedtuple class: > > > ?from collections ?import namedtuple as nt > > ?IX = nt('X', 'a b') > > ?IY = nt('Y', 'c d') > > ?x = IX(0, 1) > > ?y = IY(2, 3) > > > The above are non-conflicting class instances and of two distinct namedtuple > > classes and distinct instances of those classes, but what happens with this? > > > ?IX2 = nt('X', 'g') > > ?z = IX2(10) > > > It looks like IX and IX2 are two distinct classes, which makes sense, but > > what is the classname parameter passed to the constructor used for? > > Documentation for human readers (the .__name__ class attribute). As > your example shows, the name you pass in doesn't have to match the > name you assign the resulting class to and actually use (i.e. "X" vs. > "IX"); it's rather like how you were able to use "nt" instead of > "namedtuple". > > >?Is it > > an error to construct two distinct classes with the same value? > > Of course not. Otherwise, classes would have to have *globally unique* > names, and stuff like the following wouldn't be possible (which would > be bad): > > # mechanical.py > class Engineer(object): > ? ? '''Models a mechanical engineer.''' > ? ? # ... > > # trains.py > class Engineer(object): > ? ? '''Models a person who drives a train.''' > ? ? # ... > > # main.py > # Models a train company and associated repair yard. > import mechanical > import trains > # ... > > > Should > > inconsistant constructions with the same name raise and exception? > > Probably not (see answer to previous sentence); showing a warning > /might/ be appropriate. > > Cheers, > Chris > --http://blog.rebertia.com This parallels another wrinkle: >>> A=type('X',(),{'a':''}) >>> B=type('X',(),{'z':''}) >>> A >>> B >>> i=A() >>> j=B() >>> i <__main__.X object at 0x013A63F0> >>> j <__main__.X object at 0x013A6ED0> >>> dir(i) ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a'] >>> dir(j) ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'z'] >>> The first parameter to type and namedtuple looks redundant to me. class A: pass should be the equivalent to A=type((),{}) my guess is that it has to do with Python's internals: the function probably has no way to know what variable name it is being assigned to and anonymous classes are not wanted. From ron.eggler at gmail.com Thu Sep 23 14:10:55 2010 From: ron.eggler at gmail.com (cerr) Date: Thu, 23 Sep 2010 11:10:55 -0700 (PDT) Subject: upload file using post to https server Message-ID: hi, I've been unsucessfully trying to upload a file using POST to an https server. I've succesfully logged in and gotten to read something from the server.. I have come up with something like this: authinfo = urllib2.HTTPBasicAuthHandler() authinfo.add_password(realm='Configuration Software', uri=url, user='admin', passwd='******') opener = urllib2.build_opener(authinfo) pagePtr = opener.open(url) dataRead = str(pagePtr.read()) #Look for 'Software Upload' in the page if( "Software Upload" in dataRead ): print "FOUND Software Upload in string...
" else: print "Software Upload page not found. Exiting..." sys.exit() values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' } try: data = urllib.urlencode( values ) req = urllib2.Request( url, data ) #response = urllib2.urlopen( req ) response = opener.open( req ) the_page = response.read() #print the_page except Exception,detail: print "err ",detail #Look for 'file must be efs' in the page if( "file must be efs" in the_page ): print "file must be efs. Exiting..." sys.exit() else: print "OK" But the file doesn't seem to get there correctly. What I wanna do, is mocking the upload from the html site with my python script.... the html looks something like this:
  
Thanks for your hints and suggestions on how I have to go about this! Ron From pruebauno at latinmail.com Thu Sep 23 15:13:13 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 23 Sep 2010 12:13:13 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> Message-ID: <6d8a9aac-817c-4c1d-a175-fce403ccebba@t11g2000vbc.googlegroups.com> On Sep 23, 1:25?pm, Baba wrote: > On Sep 23, 4:17?pm, nn wrote: > > > > > On Sep 23, 10:56?am, nn wrote: > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > > Hi > > > > > > > > query level: beginner > > > > > > > > as part of a learning exercise i have written code that: > > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > > entered) > > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > > c) start again until 2) is True > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > handlist = [] > > > > > > > letter = raw_input('enter letter: ') > > > > > > > handlist.append(letter) > > > > > > > hand = "".join(handlist) > > > > > > > for item in wordlist: > > > > > > > ? ? if item.startswith(hand): > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > > ? ? ? ? ? ? else: break > > > > > > > ? ? ? ? else: break > > > > > > > print 'you loose' > > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > > thanks > > > > > > > Baba > > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > > if I use the following word list: > > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > > enter letter: h > > > > > > enter letter: a > > > > > > you loose > > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > > version might be a bit too advanced but you should still be able to do > > > > > > it using only one while, one for and one if instead. > > > > > > Hi nn, > > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > > While i was conscious that the whole construct was heavy i thought the > > > > > reasoning worked. I keep looking at it but can't figure out the > > > > > problem Can you give me a hint? > > > > > > In the meantime i found out that it is actually possible to populate a > > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > > got now: > > > > > > wordlist = ['hello', 'bye'] > > > > > hand = '' > > > > > for item in wordlist: > > > > > ? ? if item.startswith(hand): > > > > > ? ? ? ? while item.startswith(hand): > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > > ? ? ? ? ? ? ? ? print hand > > > > > ? ? ? ? ? ? else: break > > > > > ? ? ? ? else: break > > > > > print 'you loose' > > > > > > But i can't figure out why it won't work when adding the extra word. > > > > > Thanks by the way, it taught me not to be too confident when things > > > > > SEEM to work... > > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > > into one... > > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > > hand = '' > > > > > while any(item.startswith(hand) for item in wordlist): > > > > > ? ? if hand not in wordlist: > > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > > ? ? else: break > > > > > print 'you loose' > > > > > > thanks > > > > > > Baba > > > > > Hi nn, > > > > > looking at my original code again i realise that having a raw_input > > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > > will just assume that i was taking the wrong approach initially. No > > > > point in analysing it further. Thanks for your help. > > > > > Baba > > > > Since you seem to have figured it out I will post my version (python > > > 3): > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > inp='' > > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > > ? ? inp += input('enter letter: ') > > > print('you lose') > > > > The reason why your original version didn't work was because each time > > > you add a letter you have to go again over all words (in reality only > > > a subset is required) and find a new one. Your version would find one > > > word using the first letter and then exit. > > > Actually my version isn't right (for some values of right): > > > wordlist = ['hello', 'hamburger', 'bye'] > > inp='' > > while any(word.startswith(inp) for word in wordlist) and (inp not in > > wordlist): > > ? ? inp += input('enter letter: ') > > print('you lose') > > > An explanation of how this changes the rules of the wordgame is left > > as an exercise to the reader. > > Hi, > > for now i will stick to Python2.7 but thank you for sharing. > > for learning purposes i still want to figure out a way to solve this > without built-in function ('any' in this case). My understanding was > that in programming almost anything can be done with IF, FOR and WHILE > statements. However i turn in circles...:( i understand that in my > original code my while loop locked me into the first word hello if the > first letter was 'h' and therefore if the next letter was 'a' it would > break...so far so good but this appears really tricky to solve...here > is what i have come up with but it will not exit if for example i > enter 'x' ... > > wordlist = ['hello', 'bye'] > hand = '' > while hand not in wordlist: > ? ? hand += raw_input('enter letter: ') > ? ? print hand > ? ? for item in wordlist: > ? ? ? ? if not item.startswith(hand): > ? ? ? ? ? ? break > print 'you lose' > > but no matter how i turn this around i can't find the magic > approach...i was thinking about starting the code with something like > "while (something) is True" ... would that be a right approach? > > Baba This program has 2 problems: 1.) the break only exits one level: i.e. the for loop 2.) your logic is backwards. You stop checking as soon as you find the first mismatch. It should be the other way around: it is invalid only after testing with all words and not finding any match. And yes all of this can be done using just using while, for and if. I just wrote another version with 1 while, 1 for, 2 ifs, 0 breaks, 0 any, 0 genexp. This is like doing algebra: you add 2 here, substract 2 there and the same result comes out. There is an infinite number of programs that can be written to generate the same output. From jayryan.thompson at gmail.com Thu Sep 23 15:16:12 2010 From: jayryan.thompson at gmail.com (jay thompson) Date: Thu, 23 Sep 2010 12:16:12 -0700 Subject: ctypes In-Reply-To: References: Message-ID: My apologies! I worte the email while doing 3 other things. I haven't really tried anything to access this struct other than trying to find different elements with ctypes.c_int.in_dll(dll, 'symbol') and access the elements in the same way I do in C. I didn't think either of these would work but hoped I would get some type of return that would give me a little more info. I have been using a cli to access the library from python and would just send the image data via stdin and the parameters of the struct as command line args. From C the struct is easily accessible through the class instance (libraw::imgdata) and I tried similar variations with ctypes but just get 'function not found'. Makes sense though. this works: lr = ctypes.cdll.LoadLibrary(libraw) handle = lr.libraw_init(0) lr.libraw_open_buffer(handle, buf, len(buf)) # buf is an image read by python lr.libraw_unpack(handle, buf, len(buf)) # imgdata attampt. returns "function 'imgdata' not found" #lr.imgdata.params.bright(2) lr.libraw_dcraw_process(handle) lr.libraw_dcraw_ppm_tiff_writer(handle,'test.ppm') lr.libraw_close(handle) These are the 'exposed' functions, if that is the right term, and will produce an rgb image. There are a few other functions but they are not important atm. I know I don't know what I'm doing with this but it will be worth it if I can struggle through. Is there a way I can access this struct via python? Alternatively I could also write a new function in libraw that can access this struct and be exposed to ctypes. jt On Thu, Sep 23, 2010 at 12:28 AM, Simon Brunning wrote: > On 22 September 2010 21:13, jay thompson > wrote: > > Hello, > > > > I posted in regard to this in the past but it didn't go very far, no ones > > fault, but I'm again atempting to make this work and could use some help. > > > > I would like to use libraw.dll (http://www.libraw.org/ version 0.10) > from > > python and can access all the functions fine and produce images but there > is > > a structure that holds all the process settings that I cannot access with > > ctypes. I'm sure it's because I'm going about it the wrong way. I was > > wondering if there was anyone in this list with experience with this sort > of > > thing that could point me in the right direction. > > A good start would be to tell us what you've tried, and what goes > wrong when you try it. > > -- > Cheers, > Simon B. > -- "It's quite difficult to remind people that all this stuff was here for a million years before people. So the idea that we are required to manage it is ridiculous. What we are having to manage is us." ...Bill Ballantine, marine biologist. -- "It's quite difficult to remind people that all this stuff was here for a million years before people. So the idea that we are required to manage it is ridiculous. What we are having to manage is us." ...Bill Ballantine, marine biologist. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthias.guentert at gmail.com Thu Sep 23 15:41:19 2010 From: matthias.guentert at gmail.com (Matthias Guentert) Date: Thu, 23 Sep 2010 21:41:19 +0200 Subject: Raw Sockets - IP-Encapsulation Message-ID: Hello list members I would like to create an IP tunnel using the IP protocol type 4 (socket.IPPROTO_IPIP) on a Linux host. (I also would be happy if I could create a GRE tunnel) The thing is, I just don't understand how I such a socket could be created and then later on handled. Regarding to help(socket.socke()) the constructor looks like this: | socket([family[, type[, proto]]]) -> socket object | | Open a socket of the given type. The family argument specifies the | address family; it defaults to AF_INET. The type argument specifies | whether this is a stream (SOCK_STREAM, this is the default) | or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0, | specifying the default protocol. Keyword arguments are accepted. This means to create a simple UDP socket I can do the following where the last argument is optional. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP) So to create an IP-Encapsulation socket I would have to do this: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IPIP) or for GRE this. s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_GRE) But how can I now set the fields? How do I really encapsulate other data (=sockets?)? Do I need a Raw socket at all? Or should this work somehow like the following to encapsulate UDP payload? s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IPIP) I really would be happy if someone could help me with this and even better could provide some examples on the usage. Thanks in advance, Matthias From philip at semanchuk.com Thu Sep 23 17:55:26 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 23 Sep 2010 17:55:26 -0400 Subject: Parsing error for ConfigParser In-Reply-To: <0c7a4de7-9a1b-40c6-a84f-726295cb311a@w4g2000vbh.googlegroups.com> References: <0c7a4de7-9a1b-40c6-a84f-726295cb311a@w4g2000vbh.googlegroups.com> Message-ID: On Sep 23, 2010, at 1:22 PM, Andrew Z. wrote: > Is there a way to parse RealPlayer's realplayerrc in Python? I need > to support Python 2.5 - 2.7 > > Example code > > import urllib2 > import ConfigParser > f = urllib2.urlopen('http://pastebin.com/download.php?i=N1AcUg3w') > config = ConfigParser.RawConfigParser() > config.readfp(f) > > > Error > Traceback (most recent call last): > File "test_config_parser_real_player.py", line 6, in > config.readfp(f) > File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp > self._read(fp, filename) > File "/usr/lib/python2.6/ConfigParser.py", line 510, in _read > raise e > ConfigParser.ParsingError: File contains parsing errors: > [line 31]: '%0aCopyright (c) 1995-2000 Macromedia, Inc. All > rights reserved.\r\n' > [line 34]: '%0a\r\n' Hi Andrew, Hopefully someone familiar with the topic of RealPlayer file formats will step in, but while you're waiting here's my $.02. Looks like this is an INI file, and since there's no defined standard for INI files, it's hard for anyone to write a parser that is guaranteed to work with all INI files. In this particular case you've got a multiline entry in the INI file which apparently ConfigParser doesn't like. One approach would be to subclass ConfigParser and massage the lines it doesn't like into something ConfigParser finds more palatable. Or if you're not interested in those lines, parse the error message, delete the offending lines and re-run the INI file through ConfigParser. Good luck Philip From python at bdurham.com Thu Sep 23 20:31:05 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 23 Sep 2010 20:31:05 -0400 Subject: Python 2.6: How to turn off cgitb.py's DeprecationWarning: BaseException.message has been deprecated Message-ID: <1285288265.4428.1396613849@webmail.messagingengine.com> Python 2.6: We're using the standard lib's cgitb module to provide diagnostic messages when unexpected exceptions occur. Unfortunately, this module raises a DeprecationWarning like below when it is used: C:\Python26\lib\cgitb.py:245: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 value = pydoc.text.repr(getattr(evalue, name)) Is there some way to disable this specific warning message (our customers find it disconcerting) or do we have to go in and edit the cgitb.py module itself? Also, wondering if this warning has been addressed in Python 2.7/3.x? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From raoulbia at gmail.com Thu Sep 23 20:43:29 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 23 Sep 2010 17:43:29 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> <6d8a9aac-817c-4c1d-a175-fce403ccebba@t11g2000vbc.googlegroups.com> Message-ID: <3c4802f3-4bcf-4c89-aa29-bb922aa4ee05@l17g2000vbf.googlegroups.com> On Sep 23, 8:13?pm, nn wrote: > On Sep 23, 1:25?pm, Baba wrote: > > > > > On Sep 23, 4:17?pm, nn wrote: > > > > On Sep 23, 10:56?am, nn wrote: > > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > > > Hi > > > > > > > > > query level: beginner > > > > > > > > > as part of a learning exercise i have written code that: > > > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > > > entered) > > > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > > > c) start again until 2) is True > > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > > handlist = [] > > > > > > > > letter = raw_input('enter letter: ') > > > > > > > > handlist.append(letter) > > > > > > > > hand = "".join(handlist) > > > > > > > > for item in wordlist: > > > > > > > > ? ? if item.startswith(hand): > > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > > > ? ? ? ? ? ? else: break > > > > > > > > ? ? ? ? else: break > > > > > > > > print 'you loose' > > > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > > > thanks > > > > > > > > Baba > > > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > > > if I use the following word list: > > > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > > > enter letter: h > > > > > > > enter letter: a > > > > > > > you loose > > > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > > > version might be a bit too advanced but you should still be able to do > > > > > > > it using only one while, one for and one if instead. > > > > > > > Hi nn, > > > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > > > While i was conscious that the whole construct was heavy i thought the > > > > > > reasoning worked. I keep looking at it but can't figure out the > > > > > > problem Can you give me a hint? > > > > > > > In the meantime i found out that it is actually possible to populate a > > > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > > > got now: > > > > > > > wordlist = ['hello', 'bye'] > > > > > > hand = '' > > > > > > for item in wordlist: > > > > > > ? ? if item.startswith(hand): > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > > > ? ? ? ? ? ? ? ? print hand > > > > > > ? ? ? ? ? ? else: break > > > > > > ? ? ? ? else: break > > > > > > print 'you loose' > > > > > > > But i can't figure out why it won't work when adding the extra word. > > > > > > Thanks by the way, it taught me not to be too confident when things > > > > > > SEEM to work... > > > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > > > into one... > > > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > > > hand = '' > > > > > > while any(item.startswith(hand) for item in wordlist): > > > > > > ? ? if hand not in wordlist: > > > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > > > ? ? else: break > > > > > > print 'you loose' > > > > > > > thanks > > > > > > > Baba > > > > > > Hi nn, > > > > > > looking at my original code again i realise that having a raw_input > > > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > > > will just assume that i was taking the wrong approach initially. No > > > > > point in analysing it further. Thanks for your help. > > > > > > Baba > > > > > Since you seem to have figured it out I will post my version (python > > > > 3): > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > inp='' > > > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > > > ? ? inp += input('enter letter: ') > > > > print('you lose') > > > > > The reason why your original version didn't work was because each time > > > > you add a letter you have to go again over all words (in reality only > > > > a subset is required) and find a new one. Your version would find one > > > > word using the first letter and then exit. > > > > Actually my version isn't right (for some values of right): > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > inp='' > > > while any(word.startswith(inp) for word in wordlist) and (inp not in > > > wordlist): > > > ? ? inp += input('enter letter: ') > > > print('you lose') > > > > An explanation of how this changes the rules of the wordgame is left > > > as an exercise to the reader. > > > Hi, > > > for now i will stick to Python2.7 but thank you for sharing. > > > for learning purposes i still want to figure out a way to solve this > > without built-in function ('any' in this case). My understanding was > > that in programming almost anything can be done with IF, FOR and WHILE > > statements. However i turn in circles...:( i understand that in my > > original code my while loop locked me into the first word hello if the > > first letter was 'h' and therefore if the next letter was 'a' it would > > break...so far so good but this appears really tricky to solve...here > > is what i have come up with but it will not exit if for example i > > enter 'x' ... > > > wordlist = ['hello', 'bye'] > > hand = '' > > while hand not in wordlist: > > ? ? hand += raw_input('enter letter: ') > > ? ? print hand > > ? ? for item in wordlist: > > ? ? ? ? if not item.startswith(hand): > > ? ? ? ? ? ? break > > print 'you lose' > > > but no matter how i turn this around i can't find the magic > > approach...i was thinking about starting the code with something like > > "while (something) is True" ... would that be a right approach? > > > Baba > > This program has 2 problems: > 1.) the break only exits one level: i.e. the for loop > 2.) your logic is backwards. You stop checking as soon as you find the > first mismatch. It should be the other way around: it is invalid only > after testing with all words and not finding any match. > > And yes all of this can be done using just using while, for and if. I > just wrote another version with 1 while, 1 for, 2 ifs, 0 breaks, 0 > any, 0 genexp. This is like doing algebra: you add 2 here, substract 2 > there and the same result comes out. There is an infinite number of > programs that can be written to generate the same output. wordlist = ['hello', 'hamburger', 'bye', 'foo'] hand = '' check = True while check == True: check = False hand += raw_input('enter letter: ') for item in wordlist: if item.startswith(hand): check = True break if hand in wordlist: break print 'you lose' pretty long compared to yours but learning objective achieved. Thanks for your help! Baba From raoulbia at gmail.com Thu Sep 23 20:46:25 2010 From: raoulbia at gmail.com (Baba) Date: Thu, 23 Sep 2010 17:46:25 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> <6d8a9aac-817c-4c1d-a175-fce403ccebba@t11g2000vbc.googlegroups.com> Message-ID: On Sep 23, 8:13?pm, nn wrote: > On Sep 23, 1:25?pm, Baba wrote: > > > > > On Sep 23, 4:17?pm, nn wrote: > > > > On Sep 23, 10:56?am, nn wrote: > > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > > > Hi > > > > > > > > > query level: beginner > > > > > > > > > as part of a learning exercise i have written code that: > > > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > > > entered) > > > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > > > c) start again until 2) is True > > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > > handlist = [] > > > > > > > > letter = raw_input('enter letter: ') > > > > > > > > handlist.append(letter) > > > > > > > > hand = "".join(handlist) > > > > > > > > for item in wordlist: > > > > > > > > ? ? if item.startswith(hand): > > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > > > ? ? ? ? ? ? else: break > > > > > > > > ? ? ? ? else: break > > > > > > > > print 'you loose' > > > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > > > thanks > > > > > > > > Baba > > > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > > > if I use the following word list: > > > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > > > enter letter: h > > > > > > > enter letter: a > > > > > > > you loose > > > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > > > version might be a bit too advanced but you should still be able to do > > > > > > > it using only one while, one for and one if instead. > > > > > > > Hi nn, > > > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > > > While i was conscious that the whole construct was heavy i thought the > > > > > > reasoning worked. I keep looking at it but can't figure out the > > > > > > problem Can you give me a hint? > > > > > > > In the meantime i found out that it is actually possible to populate a > > > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > > > got now: > > > > > > > wordlist = ['hello', 'bye'] > > > > > > hand = '' > > > > > > for item in wordlist: > > > > > > ? ? if item.startswith(hand): > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > > > ? ? ? ? ? ? ? ? print hand > > > > > > ? ? ? ? ? ? else: break > > > > > > ? ? ? ? else: break > > > > > > print 'you loose' > > > > > > > But i can't figure out why it won't work when adding the extra word. > > > > > > Thanks by the way, it taught me not to be too confident when things > > > > > > SEEM to work... > > > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > > > into one... > > > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > > > hand = '' > > > > > > while any(item.startswith(hand) for item in wordlist): > > > > > > ? ? if hand not in wordlist: > > > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > > > ? ? else: break > > > > > > print 'you loose' > > > > > > > thanks > > > > > > > Baba > > > > > > Hi nn, > > > > > > looking at my original code again i realise that having a raw_input > > > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > > > will just assume that i was taking the wrong approach initially. No > > > > > point in analysing it further. Thanks for your help. > > > > > > Baba > > > > > Since you seem to have figured it out I will post my version (python > > > > 3): > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > inp='' > > > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > > > ? ? inp += input('enter letter: ') > > > > print('you lose') > > > > > The reason why your original version didn't work was because each time > > > > you add a letter you have to go again over all words (in reality only > > > > a subset is required) and find a new one. Your version would find one > > > > word using the first letter and then exit. > > > > Actually my version isn't right (for some values of right): > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > inp='' > > > while any(word.startswith(inp) for word in wordlist) and (inp not in > > > wordlist): > > > ? ? inp += input('enter letter: ') > > > print('you lose') > > > > An explanation of how this changes the rules of the wordgame is left > > > as an exercise to the reader. > > > Hi, > > > for now i will stick to Python2.7 but thank you for sharing. > > > for learning purposes i still want to figure out a way to solve this > > without built-in function ('any' in this case). My understanding was > > that in programming almost anything can be done with IF, FOR and WHILE > > statements. However i turn in circles...:( i understand that in my > > original code my while loop locked me into the first word hello if the > > first letter was 'h' and therefore if the next letter was 'a' it would > > break...so far so good but this appears really tricky to solve...here > > is what i have come up with but it will not exit if for example i > > enter 'x' ... > > > wordlist = ['hello', 'bye'] > > hand = '' > > while hand not in wordlist: > > ? ? hand += raw_input('enter letter: ') > > ? ? print hand > > ? ? for item in wordlist: > > ? ? ? ? if not item.startswith(hand): > > ? ? ? ? ? ? break > > print 'you lose' > > > but no matter how i turn this around i can't find the magic > > approach...i was thinking about starting the code with something like > > "while (something) is True" ... would that be a right approach? > > > Baba > > This program has 2 problems: > 1.) the break only exits one level: i.e. the for loop > 2.) your logic is backwards. You stop checking as soon as you find the > first mismatch. It should be the other way around: it is invalid only > after testing with all words and not finding any match. > > And yes all of this can be done using just using while, for and if. I > just wrote another version with 1 while, 1 for, 2 ifs, 0 breaks, 0 > any, 0 genexp. This is like doing algebra: you add 2 here, substract 2 > there and the same result comes out. There is an infinite number of > programs that can be written to generate the same output. wordlist = ['hello', 'hamburger', 'bye', 'foo'] hand = '' check = True while check == True: check = False hand += raw_input('enter letter: ') for item in wordlist: if item.startswith(hand): check = True break if hand in wordlist: break print 'you lose' learning objective achieved :) Thanks for your help! Baba From rplasson at gmail.com Thu Sep 23 20:50:01 2010 From: rplasson at gmail.com (=?ISO-8859-1?Q?Rapha=EBl_Plasson?=) Date: Thu, 23 Sep 2010 17:50:01 -0700 (PDT) Subject: Best way for rotating a matrix of data? References: <3207b8a9-a566-478d-a5db-859db162b8e4@p24g2000pra.googlegroups.com> Message-ID: <18eacefa-ec05-4fba-9b35-6e8f938d88dc@z34g2000pro.googlegroups.com> On Sep 23, 1:50?am, Nobody wrote: > You can use arrays as indices, so applying a transformation to a set of > index arrays (e.g. np.indices) then using those as indices is equivalent > to applying a spatial transform to the data. I am not sure that this would do the trick, e.g. for extracting a transversal slice of a 3D array. > Also: scipy.ndimage. But this seems to do exactly what I am looking for, thanks :). There actually may be another solution, that is to use the VTK library. However, it is a much more complex package, much more powerful but maybe too much for what I want to do. The scipy.ndimage module ("Multi- dimensional image processing") is probably the best solution for me. Thank you, Raphael From missive at hotmail.com Thu Sep 23 20:56:50 2010 From: missive at hotmail.com (Lee Harr) Date: Fri, 24 Sep 2010 05:26:50 +0430 Subject: pyqt on portable python? Message-ID: Is it possible / easy to use PyQt with portable python? I've done some googling and found one message that said this is coming in the next version, but I can't find anything on portablepython.com that mentions it. Has anyone done this before? Have any better information on how to set it up, or when it might come to the default version of portable python? Thanks. From jnoller at gmail.com Thu Sep 23 21:31:59 2010 From: jnoller at gmail.com (Jesse Noller) Date: Thu, 23 Sep 2010 21:31:59 -0400 Subject: Call for proposals -- PyCon 2011 Message-ID: Call for proposals -- PyCon 2011 -- =============================================================== Proposal Due date: November 1st, 2010 PyCon is back! With a rocking new website, a great location and more Python hackers and luminaries under one roof than you could possibly shake a stick at. We've also added an "Extreme" talk track this year - no introduction, no fluff - only the pure technical meat! PyCon 2011 will be held March 9th through the 17th, 2011 in Atlanta, Georgia. (Home of some of the best southern food you can possibly find on Earth!) The PyCon conference days will be March 11-13, preceded by two tutorial days (March 9-10), and followed by four days of development sprints (March 14-17). PyCon 2011 is looking for proposals for the formal presentation tracks (this includes "extreme talks"). A request for proposals for poster sessions and tutorials will come separately. Want to showcase your skills as a Python Hacker? Want to have hundreds of people see your talk on the subject of your choice? Have some hot button issue you think the community needs to address, or have some package, code or project you simply love talking about? Want to launch your master plan to take over the world with Python? PyCon is your platform for getting the word out and teaching something new to hundreds of people, face to face. In the past, PyCon has had a broad range of presentations, from reports on academic and commercial projects, tutorials on a broad range of subjects, and case studies. All conference speakers are volunteers and come from a myriad of backgrounds: some are new speakers, some have been speaking for years. Everyone is welcome, so bring your passion and your code! We've had some incredible past PyCons, and we're looking to you to help us top them! Online proposal submission is open now! Proposals will be accepted through November 10th, with acceptance notifications coming out by January 20th. To get started, please see: For videos of talks from previous years - check out: For more information on "Extreme Talks" see: We look forward to seeing you in Atlanta! Please also note - registration for PyCon 2011 will also be capped at a maximum of 1,500 delegates, including speakers. When registration opens (soon), you're going to want to make sure you register early! Speakers with accepted talks will have a guaranteed slot. Important Dates: * November 1st, 2010: Talk proposals due. * December 15th, 2010: Acceptance emails sent. * January 19th, 2010: Early bird registration closes. * March 9-10th, 2011: Tutorial days at PyCon. * March 11-13th, 2011: PyCon main conference. * March 14-17th, 2011: PyCon sprints days. Contact Emails: Van Lindberg (Conference Chair) - van at python.org Jesse Noller (Co-Chair) - jnoller at python.org PyCon Organizers list: pycon-organizers at python.org From skyepn at gmail.com Thu Sep 23 22:31:20 2010 From: skyepn at gmail.com (Skye) Date: Thu, 23 Sep 2010 19:31:20 -0700 (PDT) Subject: Finding email threads with mailbox.mbox Message-ID: <22f7b135-1ba7-4177-aa54-87d23b6fa058@j5g2000vbg.googlegroups.com> Hello, I'm working on a script to read large numbers of mail list archives in mbox format and dump them into a database. I was happy to find mailbox.mbox because I like writing Python =) However I need to find email threads (replies, quoted test, Re: subjects etc) and it doesn't look like anything in the standard Python library will help me with that. I suppose I could yank some code from Mailman's pipermail or something for identifying discussion threads, but I was wondering if anyone had any other suggestions before I reinvent the wheel. Thanks, Skye From ldo at geek-central.gen.new_zealand Thu Sep 23 23:18:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 15:18:47 +1200 Subject: Subprocess does not return for longer-running process References: Message-ID: In message , Nobody wrote: > On Thu, 23 Sep 2010 12:25:53 +1200, Lawrence D'Oliveiro wrote: > >>> And I can't think of any reason why you should use os.waitpid() or >>> similar; use the .wait() method. >> >> I have used WNOHANG to poll for completion of a subprocess while >> providing progress updates to the user. > > This can be done via the .poll() method. And what do you think the poll method uses? From ldo at geek-central.gen.new_zealand Thu Sep 23 23:23:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 15:23:08 +1200 Subject: Python in Linux - barrier to Python 3.x References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> Message-ID: In message <2ab95324-4394-4510-b953-3c8555b0a9bd at q9g2000vbd.googlegroups.com>, Ant wrote: > Still, no Python 3 unless I upgrade to Fedora 13, and upgrading > an OS in order to get the latest version of one package is a bit much! You?re using Fedora, a distro that pretty much demands you upgrade at least every 12 months, and you?re complaining about it? From ldo at geek-central.gen.new_zealand Thu Sep 23 23:28:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 15:28:39 +1200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: In message <87zkvbytnk.fsf at web.de>, Diez B. Roggisch wrote: > Of course, in a ideal world, distutils would hook into the distros > dependency system + simply say "please install python-dev first". > > But I'm not convinced that putting the weight here on the shoulders of > the python-communtiy to deal with arbirtray decisions of the dozen or > how many distros + packaging schemes out there is possible - and helpful. Fair enough. I think the right answer is for the package-management systems to bear the burden of coping with the established installation mechanisms of particular major subsystems. There may be a slight mismatch, in that distutils is source-based, whereas most Linux distros (with the notable exception of Gentoo) expect to distribute and install prebuilt binaries. I suspect this is not insurmountable. From ldo at geek-central.gen.new_zealand Thu Sep 23 23:31:17 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 24 Sep 2010 15:31:17 +1200 Subject: Python in Linux - barrier to Python 3.x References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> Message-ID: In message , Antoine Pitrou wrote: > comp.lang.python doesn't handle Linux packaging [issues] ... Why not? We regularly seem to was^H^H^Hspend a lot of time with Windows- specific packaging problems, installation problems and configuration problems, why not Linux ones as well? From aahz at pythoncraft.com Fri Sep 24 00:56:19 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Sep 2010 21:56:19 -0700 Subject: Help needed with Windows Service in Python References: Message-ID: In article , Ian Hobson wrote: > >I am attempting to create a Windows Service in Python. BTW, you probably want to subscribe to http://mail.python.org/mailman/listinfo/python-win32 -- 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 steve at REMOVE-THIS-cybersource.com.au Fri Sep 24 03:04:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Sep 2010 07:04:47 GMT Subject: Python in Linux - barrier to Python 3.x References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> Message-ID: <4c9c4d8e$0$28657$c3e8da3@news.astraweb.com> On Fri, 24 Sep 2010 15:23:08 +1200, Lawrence D'Oliveiro wrote: > In message > <2ab95324-4394-4510-b953-3c8555b0a9bd at q9g2000vbd.googlegroups.com>, Ant > wrote: > >> Still, no Python 3 unless I upgrade to Fedora 13, and upgrading an OS >> in order to get the latest version of one package is a bit much! > > You?re using Fedora, a distro that pretty much demands you upgrade at > least every 12 months, and you?re complaining about it? "Demands"? I'm using Fedora 7. Obviously the demands have been going to my old address. -- Steven From deluxstar at gmail.com Fri Sep 24 03:05:23 2010 From: deluxstar at gmail.com (deluxstar) Date: Fri, 24 Sep 2010 00:05:23 -0700 (PDT) Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" Message-ID: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> Hi, We have an application working on several servers generally written with Python 2.6 and Twisted 10. The source codes are located in one server and compiled in this server. The compiled files are copied to other server via network and application server works with these compiled files. In this application, I have to write a function to return a value of the caller object that calles this function. The function may be called from several modules of the application. To achieve this goal, I try to use the python inspect module: curframe = inspect.currentframe() calframe = inspect.getouterframes(curframe, 2) calframe[1][0].f_locals['variable'] This sample code works on local development environment both on linux and windows. When checked in to production environment, inspect.currentframe() or inspect.stack() function gives "List index out of range error". When I googled, I found only one clue of copying pyc files: http://forum.webfaction.com/viewtopic.php?pid=16808 Why inspect modules gives this error? OR Is there another way to get the caller objects variable value? Thanks in advance. From steve at REMOVE-THIS-cybersource.com.au Fri Sep 24 03:23:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Sep 2010 07:23:25 GMT Subject: Too much code - slicing References: <20100917160154.570ce164@geekmail.INVALID> <9c67c9e0-8199-4094-9ea8-1296f4a14a6b@x24g2000pro.googlegroups.com> <20100921122629.4a1ff844@geekmail.INVALID> <4c9aa057$0$11123$c3e8da3@news.astraweb.com> <87k4mdmdv0.fsf@castleamber.com> <20100923114225.32f7253e@geekmail.INVALID> Message-ID: <4c9c51ec$0$28657$c3e8da3@news.astraweb.com> On Thu, 23 Sep 2010 11:42:25 -0400, Andreas Waldenburger wrote: > On Wed, 22 Sep 2010 20:45:55 -0500 John Bokma > wrote: > >> What surprises me is that this is still discussed. It's like argueing >> about significant whitespace. :-) > > Which is evil! Iagreethatsignioficantwhitespaceisevil.Pythonshouldbelikeearlyver sionsofFortran,whichhadnosignificantwhitespace.Muchbetter,inmyopi nion. *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Sep 24 03:51:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Sep 2010 07:51:52 GMT Subject: Python in Linux - barrier to Python 3.x References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> Message-ID: <4c9c5897$0$28659$c3e8da3@news.astraweb.com> On Tue, 21 Sep 2010 13:54:55 -0700, Ant wrote: > Yes you are right - I've checked on my home machine, and it is indeed > 2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading an > OS in order to get the latest version of one package is a bit much! Or you could install from source, which takes all of three minutes of effort. Well, maybe four. Eight if you've never done it before. Maybe twelve if you're cautious. Here's a link to get you started: http://www.python.org/download/releases/3.1.2/ The only gotchas you're likely to run into are, you need root, or at least sudo (which you would need for an rpm installation as well), and don't forget to run `make altinstall` instead of `make install`. Read the README for details. You might have a policy of never installing anything that doesn't go through the system packaging system, and that's a perfectly good policy. But that's not Python's responsibility. Go nag the Fedora folks. Or ask around, somebody surely has built an rpm for Python 3.1. > I know that this is a distribution issue, and not strictly a Python > one, It's not a Python issue *at all*. > but the issue exists primarily because python is such a > successful language it has become deeply embedded in linux > distributions, and so there is now a lot of work involved in checking > that a python upgrade doesn't break things. Well, maybe so, but that has nothing to do with the availability of one or more non-system Pythons. My sys admin foo is mediocre at best, but I've had no problems at all with installing Pythons 1.5 through 3.2 inclusive on my system, while leaving 2.5 as the system Python. In my experience installing from source on Fedora systems Just Works. -- Steven From boolegue at gmail.com Fri Sep 24 03:53:22 2010 From: boolegue at gmail.com (antoine) Date: Fri, 24 Sep 2010 00:53:22 -0700 (PDT) Subject: SocketServer: replace network by hard drive Message-ID: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Hello, I would like to create a python server for which the requests are passed by files on the hard drive instead of a network. I am currently looking at the SocketServer python module, hoping for an easy modification. Is it doable at all? If yes, how should it be done? Thanks, Antoine. From wim at go2people.nl Fri Sep 24 03:57:29 2010 From: wim at go2people.nl (Wim Feijen) Date: Fri, 24 Sep 2010 09:57:29 +0200 Subject: feature request: string.contains('...') Message-ID: Hello, I was wondering, how to make a feature request? I would really like having a string.contains('...') function which returns either True or False. I know I can mimick this behaviour by saying string.find('...') != -1 , however, I find this harder to read. string.contains('...') is easier to understand and more closely resembles natural language. Thanks for your help and best regards, Wim Feijen -- Wim Feijen Algemeen directeur wim at go2people.nl 06 11113316 Go2People Keizersgracht 8 1015 CN Amsterdam 020 7370378 www.go2people.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfgang at rohdewald.de Fri Sep 24 04:10:53 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Fri, 24 Sep 2010 10:10:53 +0200 Subject: feature request: string.contains('...') In-Reply-To: References: Message-ID: <201009241010.53578.wolfgang@rohdewald.de> On Freitag 24 September 2010, Wim Feijen wrote: > would really like having a string.contains('...') function > which returns either True or False. I know I can mimick this > behaviour by saying string.find('...') != -1 , however, I > find this harder to read. >>> a = 'xy134' >>> '13' in a True >>> '15' in a False >>> -- Wolfgang From __peter__ at web.de Fri Sep 24 04:21:47 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Sep 2010 10:21:47 +0200 Subject: feature request: string.contains('...') References: Message-ID: Wim Feijen wrote: > I was wondering, how to make a feature request? You can post suggestions to improve python on the python-ideas mailing list or make feature requests on the bugtracker at bugs.python.org > I would really like having a string.contains('...') function which returns > either True or False. I know I can mimick this behaviour by saying > string.find('...') != -1 , however, I find this harder to read. > > string.contains('...') is easier to understand and more closely resembles > natural language. In modern python those functions provided by the string module that are also available as methods should not be used anymore. Instead of string.find(s, substr) write s.find(substr) If you are not interested in the position of the substr use the "in" operator: if substr in s: print "found" else: print "not found" Peter From chris at simplistix.co.uk Fri Sep 24 04:28:47 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 24 Sep 2010 09:28:47 +0100 Subject: os.path.normcase rationale? In-Reply-To: <4c97f629$0$28658$c3e8da3@news.astraweb.com> References: <87lj727lu7.fsf@benfinney.id.au> <4c97f629$0$28658$c3e8da3@news.astraweb.com> Message-ID: <4C9C613F.4000009@simplistix.co.uk> On 21/09/2010 01:02, Steven D'Aprano wrote: > On Mon, 20 Sep 2010 19:45:37 +0100, Chris Withers wrote: > >> Well, no, that doesn't feel right. Normalisation of case, for me, means >> "give me the case as the filesystem thinks it should be", > > What do you mean "the filesystem"? > > If I look at the available devices on my system now, I see: > > 2 x FAT-32 filesystems > 1 x ext2 filesystem > 3 x ext3 filesystems > 1 x NTFS filesystem > 1 x UDF filesystem Right, and each of these will know what it thinks a file's "real" name is, along with potentially accepting as set of synonyms for them... > and if I ever get my act together to install Basilisk II, as I've been > threatening to do for the last five years, there will also be at least > one 1 x HFS filesystem. Which one is "the" filesystem? Whichever one you're getting the file from... > If you are suggesting that os.path.normcase(filename) should determine > which filesystem actually applies to filename at runtime, and hence work > out what rules apply, what do you suggest should happen if the given path > doesn't actually exist? I'd suggest an exception be raised. Really, what's the point of normcase if it's basically just "if os=='win': return path.lower()" > What if it's a filesystem that the normpath > developers haven't seen or considered before? I didn't say it was an easy problem, but the current normpath is a waste of space... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From cournape at gmail.com Fri Sep 24 04:35:38 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 24 Sep 2010 17:35:38 +0900 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <4c9c5897$0$28659$c3e8da3@news.astraweb.com> References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> <4c9c5897$0$28659$c3e8da3@news.astraweb.com> Message-ID: On Fri, Sep 24, 2010 at 4:51 PM, Steven D'Aprano wrote: > On Tue, 21 Sep 2010 13:54:55 -0700, Ant wrote: > >> Yes you are right - I've checked on my home machine, and it is indeed >> 2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading an >> OS in order to get the latest version of one package is a bit much! > > Or you could install from source, which takes all of three minutes of > effort. Well, maybe four. Eight if you've never done it before. Maybe > twelve if you're cautious. That only works if some cases. If you need some additional packages, especially ones which depend on C extensions, that may be difficult or even hopelessly intractable. Typically, if your want to install say matplotlib with pygtk with a custom built python, you are in for a fun ride because you have to rebuild everything. That the cases where you really want something that integrates well with the native packaging system, whatever that ends up to be. cheers, David From matthias.guentert at gmail.com Fri Sep 24 04:38:56 2010 From: matthias.guentert at gmail.com (Matthias Guentert) Date: Fri, 24 Sep 2010 10:38:56 +0200 Subject: Raw Sockets - IP-Encapsulation In-Reply-To: References: Message-ID: Hello list members I would like to create an IP tunnel using the IP protocol type 4 (socket.IPPROTO_IPIP) on a Linux host. (I also would be happy if I could create a GRE tunnel) The thing is, I just don't understand how I such a socket could be created and then later on handled. Regarding to help(socket.socke()) the constructor looks like this: ?| socket([family[, type[, proto]]]) -> socket object ?| ?| ?Open a socket of the given type. ?The family argument specifies the ?| ?address family; it defaults to AF_INET. ?The type argument specifies ?| ?whether this is a stream (SOCK_STREAM, this is the default) ?| ?or datagram (SOCK_DGRAM) socket. ?The protocol argument defaults to 0, ?| ?specifying the default protocol. ?Keyword arguments are accepted. This means to create a simple UDP socket I can do the following where the last argument is optional. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP) So to create an IP-Encapsulation socket I would have to do this: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IPIP) or for GRE this. s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_GRE) But how can I now set the fields? How do I really encapsulate other data (=sockets?)? Do I need a Raw socket at all? Or should this work somehow like the following to encapsulate UDP payload? s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IPIP) I really would be happy if someone could help me with this and even better could provide some examples on the usage. Thanks in advance, Matthias From steve at REMOVE-THIS-cybersource.com.au Fri Sep 24 05:23:33 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Sep 2010 09:23:33 GMT Subject: Python in Linux - barrier to Python 3.x References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> <4c9c5897$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4c9c6e15$0$28659$c3e8da3@news.astraweb.com> On Fri, 24 Sep 2010 17:35:38 +0900, David Cournapeau wrote: > On Fri, Sep 24, 2010 at 4:51 PM, Steven D'Aprano > wrote: >> On Tue, 21 Sep 2010 13:54:55 -0700, Ant wrote: >> >>> Yes you are right - I've checked on my home machine, and it is indeed >>> 2.6. Still, no Python 3 unless I upgrade to Fedora 13, and upgrading >>> an OS in order to get the latest version of one package is a bit much! >> >> Or you could install from source, which takes all of three minutes of >> effort. Well, maybe four. Eight if you've never done it before. Maybe >> twelve if you're cautious. > > That only works if some cases. If you need some additional packages, > especially ones which depend on C extensions, that may be difficult or > even hopelessly intractable. First of all, the issue being raised was Python itself, not third party packages. Just because my distro supports Python 3.1 doesn't mean it supports Some_Random_Package-0.2.1 too. And secondly, if it's hopelessly intractable to install a package from source, it will be hopelessly intractable for your distro packagers to build a package for it too. The difference is that if it's merely inhumanly difficult, the packagers can do it *once*, instead of expecting everyone to do so. > Typically, if your want to install say > matplotlib with pygtk with a custom built python, you are in for a fun > ride because you have to rebuild everything. That's not what I consider a typical case. But I take your point. > That the cases where you > really want something that integrates well with the native packaging > system, whatever that ends up to be. Oh of course. That's the ideal situation. But just because something falls short of the ideal doesn't mean you can't still get it. If you want Python 3.1 and your distro doesn't support it, you don't *have* to change distros. -- Steven From chris at simplistix.co.uk Fri Sep 24 05:27:18 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 24 Sep 2010 10:27:18 +0100 Subject: Distributing Packages In-Reply-To: References: Message-ID: <4C9C6EF6.7010106@simplistix.co.uk> On 23/09/2010 16:41, Greg Lindstrom wrote: > I am not intending to start anything, here, but would like to know if > any consensus has been reached in how to distribute Python modules. Hi Greg, The following shows a pattern that's working well for me: https://secure.simplistix.co.uk/svn/Simplistix/errorhandler/trunk The "work" is in setup.py. The development docs are here: http://packages.python.org/errorhandler/development.html Ignore the sphinx and buildout stuff if you're not using them, although I find both extremely valuable... > Specifically, I'd like to use something to install packages on various > machines in our enterprise (mostly Linux, but some windows boxes, too). With the above, I'd do: python setup.py sdist ...and then put the resulting sdist in a folder served by Apache. To install on a given box, I'd then do: easy_install --find-links=http://yourserver/your/folder yourpackage Using setuptools for the setup.py means you can specify any other packages your need via the install_requires parameter . I'd suggestion buildout or virtualenv for deploying to the servers too, installing into the system python's site-packages is yucky and means all projects on one box have to use the same versions of the same libraries... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From __peter__ at web.de Fri Sep 24 05:39:57 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Sep 2010 11:39:57 +0200 Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> Message-ID: deluxstar wrote: > We have an application working on several servers generally written > with Python 2.6 and Twisted 10. > The source codes are located in one server and compiled in this > server. The compiled files are copied to other server via network and > application server works with these compiled files. > > In this application, I have to write a function to return a value of > the caller object that calles this function. The function may be > called from several modules of the application. To achieve this goal, > I try to use the python inspect module: > > curframe = inspect.currentframe() > calframe = inspect.getouterframes(curframe, 2) > calframe[1][0].f_locals['variable'] > > This sample code works on local development environment both on linux > and windows. When checked in to production environment, > inspect.currentframe() or inspect.stack() function gives "List index > out of range error". > > When I googled, I found only one clue of copying pyc files: > http://forum.webfaction.com/viewtopic.php?pid=16808 > > Why inspect modules gives this error? OR Is there another way to get > the caller objects variable value? Can you provide the actual traceback? Provide a small script that reproduces the error? Add print statements and post their output? print inspect.currentframe > curframe = inspect.currentframe() print curframe > calframe = inspect.getouterframes(curframe, 2) print calframe Peter From geoff.bache at gmail.com Fri Sep 24 05:49:56 2010 From: geoff.bache at gmail.com (Geoff Bache) Date: Fri, 24 Sep 2010 02:49:56 -0700 (PDT) Subject: inspect.getmodulename giving unexpected results Message-ID: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> Hi all, I'm trying to examine some things in my stack. The information I get out of inspect.stack() gives file names and I would like to convert them to module names. I naturally assumes inspect.getmodulename would fix this for me. Unfortunately, it doesn't seem to do that in some cases. Consider the following code: ## file 'inspect_test' #!/usr/bin/env python import logging, inspect print inspect.getmodulename(logging.__file__), inspect.getmodulename(__file__) I hoped that this would print logging __main__ or at least logging inspect_test but instead it prints __init__ None which isn't very helpful, although it could technically be considered correct (I can go to the 'logging' directory and type "import __init__" but nobody ever does) I guess I was hoping to get the names of the modules as they appear in sys.modules. Maybe there is some other way to do that? I can naturally write my own method to do this but wondered if I'm missing something here. Regards, Geoff Bache From cournape at gmail.com Fri Sep 24 05:57:21 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 24 Sep 2010 18:57:21 +0900 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <4c9c6e15$0$28659$c3e8da3@news.astraweb.com> References: <2ab95324-4394-4510-b953-3c8555b0a9bd@q9g2000vbd.googlegroups.com> <4c9c5897$0$28659$c3e8da3@news.astraweb.com> <4c9c6e15$0$28659$c3e8da3@news.astraweb.com> Message-ID: On Fri, Sep 24, 2010 at 6:23 PM, Steven D'Aprano wrote: >> Typically, if your want to install say >> matplotlib with pygtk with a custom built python, you are in for a fun >> ride because you have to rebuild everything. > > That's not what I consider a typical case. But I take your point. It is an acute problem in the numpy/scipy community, and I think it generalizes to any community which depends quite a bit on C extensions. I am convinced that the only solution that can work in those cases is *more* integration with native solutions, not less. That's why I worry when people suggest to *only* focus on making python-only solutions. Of course, python-specific solutions are fine as long as they don't make it more difficult to support the native-integration goal (which sadly has been the trend up to now). cheers, David From premjee07 at gmail.com Fri Sep 24 08:02:08 2010 From: premjee07 at gmail.com (christopher S Sam) Date: Fri, 24 Sep 2010 05:02:08 -0700 (PDT) Subject: Trade easy and double your money in One month,.,..,.,..,.,.., Message-ID: Trading is the best and simple way of making money online,,,,, Know the trick to double your money in a month http://www.fxtradingmoney.com http://www.fxtradingmoney.com http://www.fxtradingmoney.com http://www.fxtradingmoney.com http://www.fxtradingmoney.com From thomas at jollybox.de Fri Sep 24 08:29:55 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 24 Sep 2010 14:29:55 +0200 Subject: inspect.getmodulename giving unexpected results In-Reply-To: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> References: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> Message-ID: <201009241429.56319.thomas@jollybox.de> On Friday 24 September 2010, it occurred to Geoff Bache to exclaim: > Hi all, > > I'm trying to examine some things in my stack. The information I get > out of inspect.stack() gives file names and I would like to convert > them to module names. I naturally assumes inspect.getmodulename would > fix this for me. > > Unfortunately, it doesn't seem to do that in some cases. Consider the > following code: It does behave as documented: it does not find package names, or investigate sys.modules > ## file 'inspect_test' rename this file to "inspect_test.py", and the filename will make sense to inspect.getmodulename, which should *then* return "inspect_test" instead of None. > > #!/usr/bin/env python > > import logging, inspect > > print inspect.getmodulename(logging.__file__), > inspect.getmodulename(__file__) > > I hoped that this would print > logging __main__ > > or at least > logging inspect_test > > but instead it prints > __init__ None > > which isn't very helpful, although it could technically be considered > correct (I can go to the 'logging' directory and type "import > __init__" but nobody ever does) > > I guess I was hoping to get the names of the modules as they appear in > sys.modules. Maybe there is some other way to do that? I can naturally > write my own method to do this but wondered if I'm missing something > here. Not that I know of. From pruebauno at latinmail.com Fri Sep 24 09:14:22 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 24 Sep 2010 06:14:22 -0700 (PDT) Subject: lists and list item matches (ghost wodgame) References: 1471a2d5-9efe-49ef-80a3-57135f07da3f@t11g2000vbc.googlegroups.com <7e3baeea-e316-4f9b-9c27-ba5a7fc807c9@a30g2000vbt.googlegroups.com> <06f0c692-49a2-4ee7-b34b-db0f695c18f8@n7g2000vbo.googlegroups.com> <722d9a0c-12b3-4df1-a031-68c7c335e857@j30g2000vbr.googlegroups.com> <6d8a9aac-817c-4c1d-a175-fce403ccebba@t11g2000vbc.googlegroups.com> Message-ID: <1da382f3-50a5-4e48-b038-4bcb72630ef0@q9g2000vbd.googlegroups.com> On Sep 23, 8:46?pm, Baba wrote: > On Sep 23, 8:13?pm, nn wrote: > > > > > On Sep 23, 1:25?pm, Baba wrote: > > > > On Sep 23, 4:17?pm, nn wrote: > > > > > On Sep 23, 10:56?am, nn wrote: > > > > > > On Sep 22, 6:39?pm, Baba wrote: > > > > > > > On Sep 22, 9:18?pm, Baba wrote: > > > > > > > > On Sep 22, 3:38?pm, nn wrote: > > > > > > > > > On Sep 21, 6:39?pm, Baba wrote: > > > > > > > > > > Hi > > > > > > > > > > query level: beginner > > > > > > > > > > as part of a learning exercise i have written code that: > > > > > > > > > > a) asks for a single letter input (assumption: only 1 letter wil be > > > > > > > > > entered) > > > > > > > > > b) adds that letter to list1 and then goes through list2 and checks: > > > > > > > > > > ? ? 1) if any item in list2 starts with list1 > if False: break > > > > > > > > > ? ? 2) if list1 == any item in list2 > if True: break > > > > > > > > > > c) start again until 2) is True > > > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > > > handlist = [] > > > > > > > > > letter = raw_input('enter letter: ') > > > > > > > > > handlist.append(letter) > > > > > > > > > hand = "".join(handlist) > > > > > > > > > for item in wordlist: > > > > > > > > > ? ? if item.startswith(hand): > > > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > > > ? ? ? ? ? ? ? ? letter = raw_input('enter letter: ') > > > > > > > > > ? ? ? ? ? ? ? ? handlist.append(letter) > > > > > > > > > ? ? ? ? ? ? ? ? hand = "".join(handlist) > > > > > > > > > ? ? ? ? ? ? else: break > > > > > > > > > ? ? ? ? else: break > > > > > > > > > print 'you loose' > > > > > > > > > > this code works but can it be optimised? i have the feeling that my > > > > > > > > > nesting of IF, WHILE and FOR statements is overkill? > > > > > > > > > > inspired by part IV ofhttp://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > > > > > > > > > thanks > > > > > > > > > Baba > > > > > > > > > Yes it is overkill. Especially the else:break from the while loop > > > > > > > > makes it difficult to follow the logic. Also the program breaks down > > > > > > > > if I use the following word list: > > > > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > > > > > enter letter: h > > > > > > > > enter letter: a > > > > > > > > you loose > > > > > > > > > I am not going to post any spoilers but I wrote your program using one > > > > > > > > while loop and one generator expression for a total of 5 lines. My > > > > > > > > version might be a bit too advanced but you should still be able to do > > > > > > > > it using only one while, one for and one if instead. > > > > > > > > Hi nn, > > > > > > > > i wasn't expecting my code to fail with an additional word in it. > > > > > > > While i was conscious that the whole construct was heavy i thought the > > > > > > > reasoning worked. I keep looking at it but can't figure out the > > > > > > > problem Can you give me a hint? > > > > > > > > In the meantime i found out that it is actually possible to populate a > > > > > > > string (just like a list, a dictionary or a tuple). Here's what i've > > > > > > > got now: > > > > > > > > wordlist = ['hello', 'bye'] > > > > > > > hand = '' > > > > > > > for item in wordlist: > > > > > > > ? ? if item.startswith(hand): > > > > > > > ? ? ? ? while item.startswith(hand): > > > > > > > ? ? ? ? ? ? if hand not in wordlist: > > > > > > > ? ? ? ? ? ? ? ? hand += raw_input('enter letter: ') > > > > > > > ? ? ? ? ? ? ? ? print hand > > > > > > > ? ? ? ? ? ? else: break > > > > > > > ? ? ? ? else: break > > > > > > > print 'you loose' > > > > > > > > But i can't figure out why it won't work when adding the extra word. > > > > > > > Thanks by the way, it taught me not to be too confident when things > > > > > > > SEEM to work... > > > > > > > > Why does it work when i use the built-in function any(iterable)?? To > > > > > > > me using the any(iterable) function seems just like regrouping 3 lines > > > > > > > into one... > > > > > > > > wordlist = ['hello','hamburger', 'bye', 'cello'] > > > > > > > hand = '' > > > > > > > while any(item.startswith(hand) for item in wordlist): > > > > > > > ? ? if hand not in wordlist: > > > > > > > ? ? ? ? hand += raw_input('enter letter: ') > > > > > > > ? ? else: break > > > > > > > print 'you loose' > > > > > > > > thanks > > > > > > > > Baba > > > > > > > Hi nn, > > > > > > > looking at my original code again i realise that having a raw_input > > > > > > inside a FOR loop is flawed per se (at least for my purposes) so i > > > > > > will just assume that i was taking the wrong approach initially. No > > > > > > point in analysing it further. Thanks for your help. > > > > > > > Baba > > > > > > Since you seem to have figured it out I will post my version (python > > > > > 3): > > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > > inp='' > > > > > while any(word.startswith(inp) and word!=inp for word in wordlist): > > > > > ? ? inp += input('enter letter: ') > > > > > print('you lose') > > > > > > The reason why your original version didn't work was because each time > > > > > you add a letter you have to go again over all words (in reality only > > > > > a subset is required) and find a new one. Your version would find one > > > > > word using the first letter and then exit. > > > > > Actually my version isn't right (for some values of right): > > > > > wordlist = ['hello', 'hamburger', 'bye'] > > > > inp='' > > > > while any(word.startswith(inp) for word in wordlist) and (inp not in > > > > wordlist): > > > > ? ? inp += input('enter letter: ') > > > > print('you lose') > > > > > An explanation of how this changes the rules of the wordgame is left > > > > as an exercise to the reader. > > > > Hi, > > > > for now i will stick to Python2.7 but thank you for sharing. > > > > for learning purposes i still want to figure out a way to solve this > > > without built-in function ('any' in this case). My understanding was > > > that in programming almost anything can be done with IF, FOR and WHILE > > > statements. However i turn in circles...:( i understand that in my > > > original code my while loop locked me into the first word hello if the > > > first letter was 'h' and therefore if the next letter was 'a' it would > > > break...so far so good but this appears really tricky to solve...here > > > is what i have come up with but it will not exit if for example i > > > enter 'x' ... > > > > wordlist = ['hello', 'bye'] > > > hand = '' > > > while hand not in wordlist: > > > ? ? hand += raw_input('enter letter: ') > > > ? ? print hand > > > ? ? for item in wordlist: > > > ? ? ? ? if not item.startswith(hand): > > > ? ? ? ? ? ? break > > > print 'you lose' > > > > but no matter how i turn this around i can't find the magic > > > approach...i was thinking about starting the code with something like > > > "while (something) is True" ... would that be a right approach? > > > > Baba > > > This program has 2 problems: > > 1.) the break only exits one level: i.e. the for loop > > 2.) your logic is backwards. You stop checking as soon as you find the > > first mismatch. It should be the other way around: it is invalid only > > after testing with all words and not finding any match. > > > And yes all of this can be done using just using while, for and if. I > > just wrote another version with 1 while, 1 for, 2 ifs, 0 breaks, 0 > > any, 0 genexp. This is like doing algebra: you add 2 here, substract 2 > > there and the same result comes out. There is an infinite number of > > programs that can be written to generate the same output. > > wordlist = ['hello', 'hamburger', 'bye', 'foo'] > hand = '' > check = True > while check == True: > ? ? check = False > ? ? hand += raw_input('enter letter: ') > ? ? for item in wordlist: > ? ? ? ? if item.startswith(hand): > ? ? ? ? ? ? check = True > ? ? ? ? ? ? break > ? ? if hand in wordlist: > ? ? ? ? break > print 'you lose' > > learning objective achieved :) Thanks for your help! > > Baba You are welcome. Just for completeness I post my version too: wordlist = ['hello', 'ham', 'hamburger', 'bye'] hand = '' found_start = not_word = True while found_start and not_word: hand += input('enter letter: ') found_start = not_word = False for word in wordlist: if word.startswith(hand): found_start = True if hand not in wordlist: not_word = True print('you lose') From bkjones at gmail.com Fri Sep 24 10:10:12 2010 From: bkjones at gmail.com (Brian Jones) Date: Fri, 24 Sep 2010 10:10:12 -0400 Subject: upload file using post to https server In-Reply-To: References: Message-ID: I just did this yesterday with the 'poster' module after fumbling around with various other ideas, which in the end just produced a lot of code and didn't get me very far. Poster makes this pretty easy, and if you can't install it to the system python path, use 'setup.py install --user' and it'll put it in your home directory under ~/.local. With poster, it's a breeze. Here's what I've done. Hope it helps: #!/usr/bin/env python import random from poster.encode import multipart_encode from poster.streaminghttp import register_openers import urllib2 import threading import time class Requestor(threading.Thread): def __init__(self, port): threading.Thread.__init__(self) self.port = port def run(self): register_openers() post_param1 = 'cheddar' post_param2 = 'leicester' params, headers = multipart_encode({"pic": open("image.jpg"), "param1": post_param1, "param2": post_param2}) request = urllib2.Request("http://mybox:%s/" % self.port, params, headers) curtime = time.time() response = urllib2.urlopen(request).read() perftime = time.time() - curtime print "Query time: %s\n" % perftime if __name__ == "__main__": for i in range(2000): port = random.choice(range(8885,8905)) t = Requestor(port) t.start() This is a basic threaded performance testing script that sends an image, and two other paramters, all in a POST request to a web server that opens multiple ports. If you don't need the threading, you should be able to rip the 'run()' method out of the class and just run it by itself (save an edit or two -- like hard-coding or otherwise replacing self.port). Good luck! brian On Fri, Sep 24, 2010 at 4:23 AM, Dennis Lee Bieber wrote: > On Thu, 23 Sep 2010 11:10:55 -0700 (PDT), cerr > declaimed the following in gmane.comp.python.general: > > > > values = { 'filename' : 'pAce34-7.1.2.3-5189k-efs.bin' } > > > > try: > > data = urllib.urlencode( values ) > > > But the file doesn't seem to get there correctly. What I wanna do, is > > mocking the upload from the html site with my python script.... the > > html looks something like this: > > And are you expecting the server to somehow crawl down the socket > to > your machine to find the file, then suck it up? > > Where do you actually attach the file data to the outgoing response? > > Suggest you reference the RFC that added file upload to HTML: > http://www.faqs.org/rfcs/rfc1867.html > > In particular, section 3.3 > -=-=-=-=-=- > 3.3 use of multipart/form-data > > The definition of multipart/form-data is included in section 7. A > boundary is selected that does not occur in any of the data. (This > selection is sometimes done probabilisticly.) Each field of the form > is sent, in the order in which it occurs in the form, as a part of > the multipart stream. Each part identifies the INPUT name within the > original HTML form. Each part should be labelled with an appropriate > content-type if the media type is known (e.g., inferred from the file > extension or operating system typing information) or as > application/octet-stream. > -=-=-=-=-=- > > You've just supplied the file NAME part of the form, but not the > file data. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Fri Sep 24 10:10:26 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 24 Sep 2010 10:10:26 -0400 Subject: feature request: string.contains('...') In-Reply-To: References: Message-ID: <4C9CB152.2040604@optimum.net> On 9/24/2010 4:21 AM, Peter Otten wrote: > > If you are not interested in the position of the substr use the "in" > operator: > > if substr in s: > print "found" > else: > print "not found" > Another "missing feature" candidate: sublist >>> 'bc' in 'abcde' True >>> list('bc') in list('abcde') False A little Googling indicates that Haskell *does* have this feature: [1] ghci> [2,6] `isInfixOf` [3,1,4,1,5,9,2,6,5,3,5,8,9,7,9] True I haven't located an equivalent Python idiom, though. I took a quick look through numpy, but no luck. Can anyone help? Tx, John [1] http://book.realworldhaskell.org/read/functional-programming.html From gburdell1 at gmail.com Fri Sep 24 10:33:36 2010 From: gburdell1 at gmail.com (gburdell1 at gmail.com) Date: Fri, 24 Sep 2010 07:33:36 -0700 (PDT) Subject: Expanding a vector by replicating elements individually References: Message-ID: <330c1e7d-1340-4090-953f-1068271f3ba7@l17g2000vbf.googlegroups.com> On Sep 22, 1:30?am, Peter Otten <__pete... at web.de> wrote: > > array([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) > > Peter Thanks! From nobody at nowhere.com Fri Sep 24 10:53:46 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 24 Sep 2010 15:53:46 +0100 Subject: Subprocess does not return for longer-running process References: Message-ID: On Fri, 24 Sep 2010 15:18:47 +1200, Lawrence D'Oliveiro wrote: >>>> And I can't think of any reason why you should use os.waitpid() or >>>> similar; use the .wait() method. >>> >>> I have used WNOHANG to poll for completion of a subprocess while >>> providing progress updates to the user. >> >> This can be done via the .poll() method. > > And what do you think the poll method uses? 1. Not relevant; use the defined interface. 2. It currently uses waitpid() on Unix, WaitForSingleObject() on Windows, maybe other functions if subprocess gets ported to other platforms or extended. If you use the .poll() method, you don't need to worry about any of this. More importantly the .poll() method sets the .returncode attribute. Why is this important? Because if the .returncode attribute is None, Popen.__del__ will add the object to the _active list. Not only does this prevent the object from being finalised, it will continue to poll for termination via _cleanup(). But if you have manually reaped the child, its PID becomes available for re-use. This can result in a subsequent _cleanup() reaping some other child process. In the 2.6 implementation, manually setting the .returncode attribute will solve this. In future implementations ... who knows? Again: use the .wait() or .poll() methods. These are portable, can be assumed to do the right thing for subclasses of subprocess.Popen(), and will perform any necessary maintenance of "internal" state. If those methods don't suffice, you can't reliably use subprocess. E.g. if you need to wait until any child terminates, using os.wait() will cause the child to be reaped, which will confuse Popen(). POSIX (and Linux since 2.6.9) has waitid(), which allows you to wait for a child *without* reaping it (via the WNOWAIT flag), but Python doesn't include an interface for this. From geoff.bache at gmail.com Fri Sep 24 11:03:20 2010 From: geoff.bache at gmail.com (Geoff Bache) Date: Fri, 24 Sep 2010 08:03:20 -0700 (PDT) Subject: inspect.getmodulename giving unexpected results References: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> Message-ID: > > Unfortunately, it doesn't seem to do that in some cases. Consider the > > following code: > > It does behave as documented: it does not find package names, or investigate > sys.modules Possibly, although for me "logging" is exposed as a module, and ought to behave as one when requesting the module name. The fact that it's a package internally doesn't seem relevant to me in this context. It's weird to me that when I do import os, logging treating these things as normal modules I can get the right name for "os" but get "__init__" when requesting "logging". Externally, these things appear to be the same. I can accept from the docs that if I did "getmodulename" on "logging.config" I would get "config" back. > > > ## file 'inspect_test' > > rename this file to "inspect_test.py", and the filename will make sense to > inspect.getmodulename, which should *then* return "inspect_test" instead of > None. I realise that, but of course I can't do that in the real code. It's a long-established convention to drop the ".py" from executable programs on UNIX. Regards, Geoff From thomas at jollybox.de Fri Sep 24 11:29:43 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 24 Sep 2010 17:29:43 +0200 Subject: inspect.getmodulename giving unexpected results In-Reply-To: References: <873501cb-c2ef-4bb6-82fd-fa737046fb2f@g18g2000vbn.googlegroups.com> Message-ID: <201009241729.43312.thomas@jollybox.de> On Friday 24 September 2010, it occurred to Geoff Bache to exclaim: > > > Unfortunately, it doesn't seem to do that in some cases. Consider the > > > > > following code: > > It does behave as documented: it does not find package names, or > > investigate sys.modules > > Possibly, although for me "logging" is exposed as a module, and ought > to behave as one when requesting the module name. The fact that it's a > package internally doesn't seem relevant to me in this context. It's > weird to me that when I do > > import os, logging > > treating these things as normal modules I can get the right name for > "os" but get "__init__" when requesting "logging". Externally, these > things appear to be the same. I can accept from the docs that if I did > "getmodulename" on "logging.config" I would get "config" back. > > > > ## file 'inspect_test' > > > > rename this file to "inspect_test.py", and the filename will make sense > > to inspect.getmodulename, which should *then* return "inspect_test" > > instead of None. > > I realise that, but of course I can't do that in the real code. It's a > long-established convention to drop the ".py" from executable programs > on UNIX. Then again, it's a classic trick to put your Python code in ../site-packages/ (or the like) and just put a tiny stub script in bin/ for projects of the same kind of dimensions where anybody would care about the executable having a file extension or not ;-) From nobody at nowhere.com Fri Sep 24 11:51:01 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 24 Sep 2010 16:51:01 +0100 Subject: Raw Sockets - IP-Encapsulation References: Message-ID: On Thu, 23 Sep 2010 21:41:19 +0200, Matthias Guentert wrote: > I would like to create an IP tunnel using the IP protocol type 4 > (socket.IPPROTO_IPIP) on a Linux host. (I also would be happy if I > could create a GRE tunnel) > > The thing is, I just don't understand how I such a socket could be > created and then later on handled. You don't create sockets for IPPROTO_IPIP or IPPROTO_GRE. Outside of the kernel, those identifiers are only likely to be used for specifying protocols when e.g. configuring packet filtering. Tunnelling only involves user-space for configuration. Once a tunnel has been configured, it's just a networking interface, and any traffic is handled by the kernel. Tunnel interfaces are manipulated using the ioctl()s in linux/if_tunnel.h. Refer to the iproute2 source code for clues. If for some reason you wanted perform the encapsulation or decapsulation yourself, you would need to create a packet socket. From thomas at jollybox.de Fri Sep 24 13:25:08 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 24 Sep 2010 19:25:08 +0200 Subject: Python 2.6: How to turn off cgitb.py's DeprecationWarning: BaseException.message has been deprecated In-Reply-To: <1285288265.4428.1396613849@webmail.messagingengine.com> References: <1285288265.4428.1396613849@webmail.messagingengine.com> Message-ID: <201009241925.09168.thomas@jollybox.de> On Friday 24 September 2010, it occurred to python at bdurham.com to exclaim: > Python 2.6: We're using the standard lib's cgitb module to > provide diagnostic messages when unexpected exceptions occur. > > Unfortunately, this module raises a DeprecationWarning like below > when it is used: > > C:\Python26\lib\cgitb.py:245: DeprecationWarning: > BaseException.message has been > deprecated as of Python 2.6 > value = pydoc.text.repr(getattr(evalue, name)) > > Is there some way to disable this specific warning message (our > customers find it disconcerting) or do we have to go in and edit > the cgitb.py module itself? Also, wondering if this warning has > been addressed in Python 2.7/3.x? Yes. Filtering is an important part of the Python warnings framework: http://docs.python.org/library/warnings.html#warnings.filterwarnings http://www.python.org/dev/peps/pep-0230/ From thomas at jollybox.de Fri Sep 24 13:28:45 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Fri, 24 Sep 2010 19:28:45 +0200 Subject: SocketServer: replace network by hard drive In-Reply-To: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: <201009241928.45441.thomas@jollybox.de> On Friday 24 September 2010, it occurred to antoine to exclaim: > Hello, > > I would like to create a python server for which the requests are > passed by files on the hard drive instead of a network. > I am currently looking at the SocketServer python module, hoping for > an easy modification. > > Is it doable at all? > If yes, how should it be done? If you're using UNIX, and you don't actually need the stream to be passed via the hard drive (why would you?), but for some reason want to use the file system, look info UNIX/local sockets. But, really, I'm guessing that local TCP sockets (our old friend 127.0.0.1/8) will work just as well for whatever you're doing (though I may be mistaken), are portable to non-UNIX system, and won't be any slower than UNIX domain sockets on most, if not all, systems. From ethan at stoneleaf.us Fri Sep 24 14:01:27 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 24 Sep 2010 11:01:27 -0700 Subject: feature request: string.contains('...') In-Reply-To: <4C9CB152.2040604@optimum.net> References: <4C9CB152.2040604@optimum.net> Message-ID: <4C9CE777.5030200@stoneleaf.us> John Posner wrote: > Another "missing feature" candidate: sublist > > >>> 'bc' in 'abcde' > True > >>> list('bc') in list('abcde') > False I'm not aware of any idioms, but how about a simple function? def listinlist(list1, list2): "checks if list1 is in list2" if not list1: return True if not list2: return False length = len(list1) pos = 0 while True: try: pos = list2.index(list1[0], pos) except ValueError: return False if list2[pos:pos+length] == list1: return True pos += 1 ~Ethan~ From python.list at tim.thechases.com Fri Sep 24 14:45:26 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 24 Sep 2010 13:45:26 -0500 Subject: feature request: string.contains('...') In-Reply-To: <4C9CE777.5030200@stoneleaf.us> References: <4C9CB152.2040604@optimum.net> <4C9CE777.5030200@stoneleaf.us> Message-ID: <4C9CF1C6.30707@tim.thechases.com> On 09/24/10 13:01, Ethan Furman wrote: > John Posner wrote: >> Another "missing feature" candidate: sublist >> >> >>> 'bc' in 'abcde' >> True >> >>> list('bc') in list('abcde') >> False > > I'm not aware of any idioms, but how about a simple function? > > def listinlist(list1, list2): > "checks if list1 is in list2" > if not list1: > return True > if not list2: > return False > length = len(list1) > pos = 0 > while True: > try: > pos = list2.index(list1[0], pos) > except ValueError: > return False > if list2[pos:pos+length] == list1: > return True > pos += 1 Which I suppose could be rewritten something like def listinlist(l1, l2): len1 = len(l1) offsets_to_consider = 1 + len(l2) - len1 return any( l1 == l2[i:i+len1] for i in xrange(offsets_to_consider) ) Foldable into a one-line version if one's sick enough to use it: list_in_list = lambda l1, l2: any(l1 == l2[i:i+len(l1)] for i in range(1 + len(l2) - len(l1))) -tkc From nagle at animats.com Fri Sep 24 15:22:09 2010 From: nagle at animats.com (John Nagle) Date: Fri, 24 Sep 2010 12:22:09 -0700 Subject: SocketServer: replace network by hard drive In-Reply-To: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: <4c9cfa71$0$1648$742ec2ed@news.sonic.net> On 9/24/2010 12:53 AM, antoine wrote: > Hello, > > I would like to create a python server for which the requests are > passed by files on the hard drive instead of a network. > I am currently looking at the SocketServer python module, hoping for > an easy modification. > > Is it doable at all? > If yes, how should it be done? > > Thanks, > Antoine. Yes, it can be done. But why? ICVERIFY, the first web-based credit card processing system, worked that way. Remember web sites which put up messages like "Wait up to 3 minutes for your credit card transaction to be processed. DO NOT REFRESH THIS PAGE". That's ICverify. The ICVERIFY concept was that the client-facing side created files in an input directory, then waited for response files to appear. The back end drove a farm of dial-up modems, each emulating a 1200 baud credit card terminal. Each back-end process looked for incoming work files, marked them as in use, dialed up the credit card processing system, did the transaction, and wrote a response file. All the process coordination was through files. That was 1995 technology, before the banking system had direct Internet connections. John Nagle From dsrtegle at gmail.com Fri Sep 24 16:59:36 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Fri, 24 Sep 2010 13:59:36 -0700 (PDT) Subject: Pyflakes and IPython does not work for Emacs on Windows? Message-ID: Hi, With Python on Windows, I tried to use Emacs as the programming environment. For syntax checking I installed pyflakes, but flymake always reports "fail to launch. No such file or directory: pyflakes" when opening a Python file. Is pyflakes not for Windows? What Python syntax checking tools work for Emacs on Windows? I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el only works for Linux? Thanks for your comments From benjamin.kaplan at case.edu Fri Sep 24 17:26:29 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 24 Sep 2010 17:26:29 -0400 Subject: Pyflakes and IPython does not work for Emacs on Windows? In-Reply-To: References: Message-ID: On Friday, September 24, 2010, Dsrt Egle wrote: > Hi, > > With Python on Windows, I tried to use Emacs as the programming > environment. For syntax checking I installed pyflakes, but flymake > always reports "fail to launch. No such file or directory: pyflakes" > when opening a Python file. Is pyflakes not for Windows? What Python > syntax checking tools work for Emacs on Windows? > > I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el > only works for Linux? > I don't use emacs but my guess would be that this is a path issue. In Linux, most executables, like ipython, are put into /usr/bin or /usr/local/bin. Both ipod those locations are on the shell's path-the places it look s when you don't specify the full path of a program. On Windows, user-installed programs don't typically get put on the path. Check the path to make sure the directory is on there. It's probably a similar issue with pyflakes- you didn't put the file in the place where flatmate looks for it. > Thanks for your comments > -- > http://mail.python.org/mailman/listinfo/python-list > From jjposner at optimum.net Fri Sep 24 17:31:16 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 24 Sep 2010 17:31:16 -0400 Subject: feature request: string.contains('...') In-Reply-To: References: <4C9CB152.2040604@optimum.net> <4C9CE777.5030200@stoneleaf.us> Message-ID: <4C9D18A4.1070609@optimum.net> On 9/24/2010 2:45 PM, Tim Chase wrote: > On 09/24/10 13:01, Ethan Furman wrote: >> John Posner wrote: >>> Another "missing feature" candidate: sublist >>> >>> >>> 'bc' in 'abcde' >>> True >>> >>> list('bc') in list('abcde') >>> False >> >> I'm not aware of any idioms, but how about a simple function? > > Foldable into a one-line version if one's sick enough to use it: Looking at this a bit more, I can see why the *in* operator applies to strings, but not to lists. Consider the ambiguity in this "heterogeneous" list: mylist = [0, 1, 2, 3, [a, b], 10, 11, 12, a, b, 13] Should the expression *[a, b] in mylist* get a hit at offset 4, or at slice [8:10]? If you know that your lists will be homogeneous ("scalar" values only), or if you're willing to program around the potential ambiguity, then Ethan's function can easily be adapted into a __contains__() method of a *list* subclass. Tx, John From aonlazio at gmail.com Fri Sep 24 18:45:43 2010 From: aonlazio at gmail.com (AON LAZIO) Date: Fri, 24 Sep 2010 18:45:43 -0400 Subject: Regular Expression match Message-ID: Hi, Say I have p = re.compile('a|b') text = 'a' d = p.findall(text) #d -> ['a'] What is the way to find out which pattern p match (the former or latter)? I mean without knowing the outcome of p.findall Thanks -- Aonlazio 'Peace is always the way.' NW -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Fri Sep 24 19:00:01 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 25 Sep 2010 09:00:01 +1000 Subject: os.path.normcase rationale? References: <87lj727lu7.fsf@benfinney.id.au> <4c97f629$0$28658$c3e8da3@news.astraweb.com> Message-ID: <87bp7m4uj2.fsf@benfinney.id.au> Chris Withers writes: > On 21/09/2010 01:02, Steven D'Aprano wrote: > > What do you mean "the filesystem"? > > > > If I look at the available devices on my system now, I see: > > > > 2 x FAT-32 filesystems > > 1 x ext2 filesystem > > 3 x ext3 filesystems > > 1 x NTFS filesystem > > 1 x UDF filesystem > > Right, and each of these will know what it thinks a file's "real" name > is, along with potentially accepting as set of synonyms for them... They will know internally, but Python has no way of asking them AFAICT, short of creating a file on the filesystem. That's far outside the bailiwick of the function in question. > > Which one is "the" filesystem? > > Whichever one you're getting the file from... Who said anything about ?getting the file?? The parameter to the function is a path, which need not already exist, and which need not refer to *any* extant filesystem. > > If you are suggesting that os.path.normcase(filename) should > > determine which filesystem actually applies to filename at runtime, > > and hence work out what rules apply, what do you suggest should > > happen if the given path doesn't actually exist? > > I'd suggest an exception be raised. You really must have an entirely different function in mind. I suggest you look for it by another name, because ?os.path.normcase? already does something entirely different. > I didn't say it was an easy problem, but the current normpath is a > waste of space... This seems to be code for ?it doesn't do what I expected, and now I don't want to use it?. Surely the solution is clear: don't use it. -- \ ?The industrial system is profoundly dependent on commercial | `\ television and could not exist in its present form without it.? | _o__) ?John Kenneth Galbraith, _The New Industrial State_, 1967 | Ben Finney From drobinow at gmail.com Fri Sep 24 19:53:09 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 24 Sep 2010 19:53:09 -0400 Subject: Pyflakes and IPython does not work for Emacs on Windows? In-Reply-To: References: Message-ID: On Fri, Sep 24, 2010 at 4:59 PM, Dsrt Egle wrote: > ... > I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el > only works for Linux? There don't appear to be a lot of ipython.el users on Windows. You may have better look on an emacs list since there appear to be some configuration issues. Does https://bugs.launchpad.net/ipython/+bug/290228 help at all? From vlastimil.brom at gmail.com Fri Sep 24 19:53:12 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 25 Sep 2010 01:53:12 +0200 Subject: Regular Expression match In-Reply-To: References: Message-ID: 2010/9/25 AON LAZIO : > Hi, > ?? Say I have > ?? p???? = re.compile('a|b') > ?? text = 'a' > ?? d???? = p.findall(text) > ?? #d -> ['a'] > ?? What is the way to find out which pattern p match (the former or latter)? > I mean without knowing the outcome of p.findall > ?? Thanks > > -- > Aonlazio > 'Peace is always the way.' NW > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, I am not sure, I understand the task completely, but maybe named subpatterns and the groupdict data for the match objects may help? for m in re.finditer(r"(?PA)|(?PB)", "QABCZ"): print m.group(), m.groupdict() A {'patternB': None, 'patternA': 'A'} B {'patternB': 'B', 'patternA': None} regards, vbr From dsrtegle at gmail.com Fri Sep 24 19:54:07 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Fri, 24 Sep 2010 16:54:07 -0700 (PDT) Subject: Pyflakes and IPython does not work for Emacs on Windows? References: Message-ID: On Sep 24, 2:26?pm, Benjamin Kaplan wrote: > On Friday, September 24, 2010, Dsrt Egle wrote: > > Hi, > > > With Python on Windows, I tried to use Emacs as the programming > > environment. For syntax checking I installed pyflakes, but flymake > > always reports "fail to launch. No such file or directory: pyflakes" > > when opening a Python file. Is pyflakes not for Windows? What Python > > syntax checking tools work for Emacs on Windows? > > > I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el > > only works for Linux? > > I don't use emacs but my guess would be that this is a path issue. In > Linux, most executables, like ipython, are put into /usr/bin or > /usr/local/bin. Both ipod those locations are on the shell's path-the > places it look s when you don't specify the full path of a program. On > Windows, user-installed programs don't typically get put on the path. > Check the path to make sure the directory is on there. It's probably a > similar issue with pyflakes- you didn't put the file in the place > where flatmate looks for it. > > > Thanks for your comments > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Thanks for your reply, Ben. Actually I have the paths "C:\Python25;C: \Python25\Scripts" in the %PATH% variable, and the %PYTHONPATH% has the following: C:\Python25\Lib\site-packages\pyflakes;C:\Python25\Lib\site-packages \Pymacs;C:\Python25\Lib\site-packages\rope;C:\Python25\Lib\site- packages\ropemacs;C:\Python25\Lib\site-packages\ropemode Pymacs, rope, ropemacs, ropemode all work in Emacs, except pyflakes. Looking at the file C:\Python25\Lib\site-packages\pyflakes-0.4.0- py2.5.egg\EGG-INFO\scripts\pyflakes, it shows #!C:\Python25\python.exe from pyflakes.scripts.pyflakes import main main() So this script needs to trigger Python interpreter to run. I can successfully run pyflakes by manually triggering Python like this: C:\>python C:\Python25\Lib\site-packages\pyflakes-0.4.0-py2.5.egg\EGG- INFO\scripts\pyflakes test_new_lib.py test_new_lib.py:13: invalid syntax sa.CoreObj. So pyflakes is running correctly. But it seems Emacs treats pyflakes as an executable program instead of Python script. I include the following in my .emacs file for pyflakes: ;;===== PyFlakes ;; code checking via pyflakes+flymake (when (load "flymake" t) (defun flymake-pyflakes-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "pyflakes" (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pyflakes-init))) (add-hook 'find-file-hook 'flymake-find-file-hook) What should I do to configure Emacs to make pyflakes working? Thank you! From nn.roh1 at gmail.com Sat Sep 25 01:18:26 2010 From: nn.roh1 at gmail.com (n.a.s) Date: Sat, 25 Sep 2010 08:18:26 +0300 Subject: problem in Gasp ! In-Reply-To: References: Message-ID: Hi, I want to ask about graphics using Gasp .Attached is exercise 10 (houses at night) ,if i call the draw_house function once it will work properly ,but more than one call,windows and doors disappear from some houses . Any one can advice? Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: house.pyw Type: application/octet-stream Size: 1398 bytes Desc: not available URL: From brenNOSPAMbarn at NObrenSPAMbarn.net Sat Sep 25 01:58:24 2010 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 25 Sep 2010 05:58:24 +0000 (UTC) Subject: Playing sounds at time indexes References: Message-ID: Thomas Jollans wrote: > On Wednesday 22 September 2010, it occurred to OKB (not okblacke) > to exclaim: >> I'm looking for an audio library for Python. I googled >> and found a >> few, but none of them seem to have a simple way to play a >> particular sound file from a particular start-time to an end-time. >> Like, I'd want to load a file and say "Play the section of this >> file from 10.25 seconds to 11.73 seconds." Is there a library >> that makes this easy in Python? > > platform? Windows XP. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From deluxstar at gmail.com Sat Sep 25 03:53:13 2010 From: deluxstar at gmail.com (deluxstar) Date: Sat, 25 Sep 2010 00:53:13 -0700 (PDT) Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> Message-ID: <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> On 24 Eyl?l, 12:39, Peter Otten <__pete... at web.de> wrote: > deluxstar wrote: > > We have an application working on several servers generally written > > with Python 2.6 and Twisted 10. > > The source codes are located in one server and compiled in this > > server. The compiled files are copied to other server via network and > > application server works with these compiled files. > > > In this application, I have to write a function to return a value of > > the caller object that calles this function. The function may be > > called from several modules of the application. To achieve this goal, > > I try to use the python inspect module: > > > curframe = inspect.currentframe() > > calframe = inspect.getouterframes(curframe, 2) > > calframe[1][0].f_locals['variable'] > > > This sample code works on local development environment both on linux > > and windows. When checked in to production environment, > > inspect.currentframe() or inspect.stack() function gives "List index > > out of range error". > > > When I googled, I found only one clue of copying pyc files: > >http://forum.webfaction.com/viewtopic.php?pid=16808 > > > Why inspect modules gives this error? OR Is there another way to get > > the caller objects variable value? > > Can you provide the actual traceback? Provide a small script that reproduces > the error? Add print statements and post their output? > > print inspect.currentframe> curframe = inspect.currentframe() > print curframe > > calframe = inspect.getouterframes(curframe, 2) > > print calframe > > Peter The traceback is: 2010-09-25 10:50:38+0300 [-] Traceback (most recent call last): 2010-09-25 10:50:38+0300 [-] File "../appsrv/lqcommon.py", line 983, in getPRMS 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", line 931, in getouterframes 2010-09-25 10:50:38+0300 [-] framelist.append((frame,) + getframeinfo(frame, context)) 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", line 906, in getframeinfo 2010-09-25 10:50:38+0300 [-] lines, lnum = findsource(frame) 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", line 568, in findsource 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range It is hard to reproduce the error with a script. I will work and send if I success. If the traceback tells smth, please tell me :) Thnx From lanyjie at yahoo.com Sat Sep 25 04:22:04 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 01:22:04 -0700 (PDT) Subject: sequence multiplied by -1 Message-ID: <299735.67644.qm@web54205.mail.re2.yahoo.com> Hi, I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics. Simply put, a sequence multiplied by -1 can give a reversed sequence. Then for any sequence "seq", and integer n>0, we can have "seq * -n" producing "(seq * -1) * n". Any thoughts? Yingjie From steve at REMOVE-THIS-cybersource.com.au Sat Sep 25 04:25:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Sep 2010 08:25:51 GMT Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> Message-ID: <4c9db20f$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 00:53:13 -0700, deluxstar wrote: > The traceback is: > 2010-09-25 10:50:38+0300 [-] Traceback (most recent call last): > 2010-09-25 10:50:38+0300 [-] File "../appsrv/lqcommon.py", line 983, > in getPRMS > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 931, in getouterframes > 2010-09-25 10:50:38+0300 [-] framelist.append((frame,) + > getframeinfo(frame, context)) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 906, in getframeinfo > 2010-09-25 10:50:38+0300 [-] lines, lnum = findsource(frame) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 568, in findsource > 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break > 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range I'm going to take a wild guess here. My guess is that you've copied the .pyc file onto the server, BUT there is also an *older* version of the .py file there as well. Because the modification date is older than that of the .pyc file, Python executes the compiled code from the .pyc file. But when you search for the source code, the old .py file is discovered -- but it doesn't have the right number of lines, and so you end up with an IndexError. -- Steven From wolfgang at rohdewald.de Sat Sep 25 07:28:33 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Sat, 25 Sep 2010 13:28:33 +0200 Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" In-Reply-To: <4c9db20f$0$28659$c3e8da3@news.astraweb.com> References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> <4c9db20f$0$28659$c3e8da3@news.astraweb.com> Message-ID: <201009251328.33937.wolfgang@rohdewald.de> On Samstag 25 September 2010, Steven D'Aprano wrote: > My guess is that you've copied the .pyc file onto the server, > BUT there is also an older version of the .py file there as > well. Because the modification date is older than that of the > .pyc file, Python executes the compiled code from the .pyc > file. that would be horrible - this is what our own legacy software does. A maintenance nightmare. Think adjusting system time or "cp -a spam.py" Actually the docs say something different: The modification time of the version of spam.py used to create spam.pyc is recorded in spam.pyc, and the .pyc file is ignored if these don?t match. found here: http://docs.python.org/tutorial/modules.html -- Wolfgang From thomas at jollybox.de Sat Sep 25 07:35:09 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 25 Sep 2010 13:35:09 +0200 Subject: Pyflakes and IPython does not work for Emacs on Windows? In-Reply-To: References: Message-ID: <201009251335.10365.thomas@jollybox.de> On Saturday 25 September 2010, it occurred to Dsrt Egle to exclaim: > Thanks for your reply, Ben. Actually I have the paths "C:\Python25;C: > \Python25\Scripts" in the %PATH% variable, and the %PYTHONPATH% has > the following: > > [...] > > Looking at the file C:\Python25\Lib\site-packages\pyflakes-0.4.0- > py2.5.egg\EGG-INFO\scripts\pyflakes, it shows > C:\Python25\Lib\site-packages\pyflakes-0.4.0-py2.5.egg\EGG-INFO\scripts\ doesn't appear to be on your PATH then? Also, the file "pyflakes" won't be executable without a file extension on Windows. I suggest you try either creating a pyflakes.bat file somewhere on your PATH, or using the pyflakes script as pyflakes.py, locates somewhere on the PATH (will this work? I'm not sure) > > #!C:\Python25\python.exe > > from pyflakes.scripts.pyflakes import main > main() > > > So this script needs to trigger Python interpreter to run. I can > successfully run pyflakes by manually triggering Python like this: > > C:\>python C:\Python25\Lib\site-packages\pyflakes-0.4.0-py2.5.egg\EGG- > INFO\scripts\pyflakes test_new_lib.py > test_new_lib.py:13: invalid syntax > sa.CoreObj. > > > > So pyflakes is running correctly. But it seems Emacs treats pyflakes > as an executable program instead of Python script. I include the > following in my .emacs file for pyflakes: > > > > ;;===== PyFlakes > ;; code checking via pyflakes+flymake > > (when (load "flymake" t) > (defun flymake-pyflakes-init () > (let* ((temp-file (flymake-init-create-temp-buffer-copy > 'flymake-create-temp-inplace)) > (local-file (file-relative-name > temp-file > (file-name-directory buffer-file-name)))) > (list "pyflakes" (list local-file)))) > > (add-to-list 'flymake-allowed-file-name-masks > '("\\.py\\'" flymake-pyflakes-init))) > > (add-hook 'find-file-hook 'flymake-find-file-hook) > > > > What should I do to configure Emacs to make pyflakes working? Thank > you! From thomas at jollybox.de Sat Sep 25 07:45:11 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 25 Sep 2010 13:45:11 +0200 Subject: sequence multiplied by -1 In-Reply-To: <299735.67644.qm@web54205.mail.re2.yahoo.com> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: <201009251345.11944.thomas@jollybox.de> On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: > Hi, > > I noticed that in python3k, multiplying a sequence by a negative integer is > the same as multiplying it by 0, and the result is an empty sequence. It > seems to me that there is a more meaningful symantics. Um... for every list l and integer n >= 0: len(l*n) == len(l)*n Multiplying a list by a negative integer should produce a list of negative length, which does not exist. IMHO, the only correct behaviour would be to raise an exception, though one could argue that there are practical benefits for the operation to succeed for any integer operand. > > Simply put, a sequence multiplied by -1 can give a reversed sequence. For that, we have slicing. A negative step value produces a reverse slice of the list. You can't argue that this makes sense, can you >>> [1,2,3,4][::-1] [4, 3, 2, 1] >>> [1,2,3,4][::-2] [4, 2] >>> From lanyjie at yahoo.com Sat Sep 25 08:11:39 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 05:11:39 -0700 (PDT) Subject: sequence multiplied by -1 In-Reply-To: <201009251345.11944.thomas@jollybox.de> Message-ID: <494697.63610.qm@web54206.mail.re2.yahoo.com> --- On Sat, 9/25/10, Thomas Jollans wrote: > for every list l and integer n >= 0: > ? ? len(l*n) == len(l)*n Well, this invariance is indeed broken under my proposal. But it is *already broken* in current python3k. However, the following invariance is maintained under my proposal: len(l*n) == len(l) * abs(n), which is also broken under current python3k. if you think len(..) as a mathematical norm, the above invariance makes perfect sense: || a * b || == ||a|| * |b|, b is real > > > Simply put, a sequence multiplied by -1 can give a > reversed sequence. > > For that, we have slicing. A negative step value produces a > reverse slice of > the list. You can't argue that this makes sense, can you > > >>> [1,2,3,4][::-1] > [4, 3, 2, 1] > >>> [1,2,3,4][::-2] > [4, 2] > >>> Having more than one way of doing things sometimes is good. Slicing is a little more complex, what if you want this: >>> ([1,2,3,4]*2)[::-1] [4, 3, 2, 1, 4, 3, 2, 1] under my new proposal, you simply do this: >>> [1,2,3,4]*-2 [4, 3, 2, 1, 4, 3, 2, 1] Cheers, Yingjie From nobody at nowhere.com Sat Sep 25 08:37:55 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 25 Sep 2010 13:37:55 +0100 Subject: SocketServer: replace network by hard drive References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: On Fri, 24 Sep 2010 19:28:45 +0200, Thomas Jollans wrote: > If you're using UNIX, and you don't actually need the stream to be > passed via the hard drive (why would you?), but for some reason want to > use the file system, look info UNIX/local sockets. But, really, I'm > guessing that local TCP sockets (our old friend 127.0.0.1/8) will work > just as well for whatever you're doing (though I may be mistaken), are > portable to non-UNIX system, and won't be any slower than UNIX domain > sockets on most, if not all, systems. The problem with using the loopback interface is that it's still "network access", which can run into all kinds of issues with security policies, firewalls, etc. From thomas at jollybox.de Sat Sep 25 08:45:29 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sat, 25 Sep 2010 14:45:29 +0200 Subject: SocketServer: replace network by hard drive In-Reply-To: References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: <201009251445.29780.thomas@jollybox.de> On Saturday 25 September 2010, it occurred to Nobody to exclaim: > On Fri, 24 Sep 2010 19:28:45 +0200, Thomas Jollans wrote: > > If you're using UNIX, and you don't actually need the stream to be > > passed via the hard drive (why would you?), but for some reason want to > > use the file system, look info UNIX/local sockets. But, really, I'm > > guessing that local TCP sockets (our old friend 127.0.0.1/8) will work > > just as well for whatever you're doing (though I may be mistaken), are > > portable to non-UNIX system, and won't be any slower than UNIX domain > > sockets on most, if not all, systems. > > The problem with using the loopback interface is that it's still > "network access", which can run into all kinds of issues with security > policies, firewalls, etc. What kind of crappy firewall blocks loopback traffic? Really? From sschwarzer at sschwarzer.net Sat Sep 25 09:19:27 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 25 Sep 2010 15:19:27 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: Message-ID: <4C9DF6DF.6040409@sschwarzer.net> Hi, On 2010-09-25 14:11, Yingjie Lan wrote: > Having more than one way of doing things sometimes is good. In my opinion this _isn't_ a situation where it's good. :) L[::-1] is only marginally longer than -1 * L I think this small gain doesn't justify "violating" this "Python Zen" rule (from `import this`): There should be one-- and preferably only one --obvious way to do it. One could argue that using L[::-1] isn't "obvious" but I believe the rule refers to being obvious to people who have used Python for a while. Besides that, multiplying a list with a negative value to give a reverse list isn't so intuitive either. :-) On 2010-09-25 13:45, Thomas Jollans wrote: > Multiplying a list by a negative integer should produce a list of negative > length, which does not exist. IMHO, the only correct behaviour would be to > raise an exception, though one could argue that there are practical benefits > for the operation to succeed for any integer operand. I agree with raising an exception, probably a ValueError. Stefan From lanyjie at yahoo.com Sat Sep 25 09:54:36 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 06:54:36 -0700 (PDT) Subject: sequence multiplied by -1 In-Reply-To: <4C9DF6DF.6040409@sschwarzer.net> Message-ID: <464007.12232.qm@web54201.mail.re2.yahoo.com> Hi, > > In my opinion this _isn't_ a situation where it's good. :) > > ? ? L[::-1] > > is only marginally longer than > > ? ? -1 * L > > I think this small gain doesn't justify "violating" this > "Python Zen" rule (from `import this`): > > ? ? There should be one-- and preferably only one > --obvious way to do it. > Thanks for the insightful remarks. For the rule above, how about the case to reverse and multiply: >>> L*-3 #L reversed and repeated three times v.s. >>> L[::-1]*3 #L reversed and repeated three times The first one is simpler (4 chars v.s. 9 chars). I thought it was also intuitive because if you multiply a vector by -1, you should get a vector in the reversed direction. But, intuitiveness depends on who you are, what you do, etc.... Regards, Yingjie From lanyjie at yahoo.com Sat Sep 25 09:59:47 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 06:59:47 -0700 (PDT) Subject: solve alphametic puzzles in just 9 lines of code Message-ID: <164829.96277.qm@web54204.mail.re2.yahoo.com> Hi, I am teaching Python this semester and as I am trying to explain the code by Raymond Hettinger, I need to make it simpler (this is an introductory course). And it ends up to be just 9 lines of code. Just for fun. See also: http://diveintopython3.org/advanced-iterators.html Regards, Yingjie ############Code starts here########### import itertools def solve(puzzle): "solve alphametic puzzles in just 9 lines of code." words = [w for w in puzzle.split() if w.isalpha()] nonzeros = {w[0] for w in words} others = {a for a in ''.join(words) if a not in nonzeros} chars = [ord(c) for c in nonzeros]+[ord(c) for c in others] assert len(chars) <= 10, 'Too many letters' for guess in itertools.permutations('0123456789', len(chars)): if '0' not in guess[:len(nonzeros)]: equation = puzzle.translate(dict(zip(chars, guess))) if eval(equation): return equation From sschwarzer at sschwarzer.net Sat Sep 25 11:11:29 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 25 Sep 2010 17:11:29 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: Message-ID: <4C9E1121.2000201@sschwarzer.net> Hi, On 2010-09-25 15:54, Yingjie Lan wrote: > The first one is simpler (4 chars v.s. 9 chars). One thing is whether a certain form is shorter, another thing to take into account is how often you need the functionality. > I thought it was also intuitive because if you multiply > a vector by -1, you should get a vector > in the reversed direction. But, intuitiveness depends > on who you are, what you do, etc.... Sure ... in math, multiplying a vector by -1 gives a vector with all its elements negated: -1 * [1, 2, 3] -> [-1, -2, -3] :-) Stefan From mwilson at the-wire.com Sat Sep 25 12:28:38 2010 From: mwilson at the-wire.com (Mel) Date: Sat, 25 Sep 2010 12:28:38 -0400 Subject: sequence multiplied by -1 References: <4C9E1121.2000201@sschwarzer.net> Message-ID: Stefan Schwarzer wrote: > On 2010-09-25 15:54, Yingjie Lan wrote: >> The first one is simpler (4 chars v.s. 9 chars). >> I thought it was also intuitive because if you multiply >> a vector by -1, you should get a vector >> in the reversed direction. But, intuitiveness depends >> on who you are, what you do, etc.... > > Sure ... in math, multiplying a vector by -1 gives a vector > with all its elements negated: > > -1 * [1, 2, 3] -> [-1, -2, -3] > > :-) And math applies associativity v * (3 - 1) == v * 3 + v * -1 Mel. From tjreedy at udel.edu Sat Sep 25 13:12:07 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Sep 2010 13:12:07 -0400 Subject: inspect.stack() or inspect.currentframe() gives "list index out of range error" In-Reply-To: <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> References: <029bc5a2-9dd4-46b9-a1fa-b6ab7cfef032@c32g2000vbq.googlegroups.com> <97b937a1-5063-4e9e-9c68-e489c2dc3bb3@a4g2000prm.googlegroups.com> Message-ID: On 9/25/2010 3:53 AM, deluxstar wrote: > The traceback is: > 2010-09-25 10:50:38+0300 [-] Traceback (most recent call last): > 2010-09-25 10:50:38+0300 [-] File "../appsrv/lqcommon.py", line 983, > in getPRMS > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 931, in getouterframes > 2010-09-25 10:50:38+0300 [-] framelist.append((frame,) + > getframeinfo(frame, context)) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 906, in getframeinfo > 2010-09-25 10:50:38+0300 [-] lines, lnum = findsource(frame) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 568, in findsource > 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break > 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range > > It is hard to reproduce the error with a script. I will work and send > if I success. > If the traceback tells smth, please tell me :) The traceback is terribly difficult to read with the timestamps added. They are not from Python. In the future, please try to suppress them or use a global search/replace (with nothing) before posting such. -- Terry Jan Reedy From tjreedy at udel.edu Sat Sep 25 13:24:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Sep 2010 13:24:17 -0400 Subject: sequence multiplied by -1 In-Reply-To: <299735.67644.qm@web54205.mail.re2.yahoo.com> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: On 9/25/2010 4:22 AM, Yingjie Lan wrote: > Hi, > > I noticed that in python3k, multiplying a sequence by a negative > integer is the same as multiplying it by 0, and the result is an > empty sequence. This is explicitly documented: "Values of n less than 0 are treated as 0 (which yields an empty sequence of the same type as s).) I would have made this raise a ValueError, but someone must have had a use case for getting an empty sequence. > It seems to me that there is a more meaningful symantics. > Simply put, a sequence multiplied by -1 can give a reversed > sequence. There is already a builtin reversed() function whose output can be multiplied. -- Terry Jan Reedy From emile at fenx.com Sat Sep 25 13:57:35 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 25 Sep 2010 10:57:35 -0700 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: On 9/25/2010 10:24 AM Terry Reedy said... > On 9/25/2010 4:22 AM, Yingjie Lan wrote: >> I noticed that in python3k, multiplying a sequence by a negative >> integer is the same as multiplying it by 0, and the result is an >> empty sequence. > > This is explicitly documented: "Values of n less than 0 are treated as 0 > (which yields an empty sequence of the same type as s).) I would have > made this raise a ValueError, but someone must have had a use case for > getting an empty sequence. At least it's consistent with slicing not generating a ValueError ala ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> ham = range(10) >>> ham[11:21] [] ... which in version 3 behaves differently? ActivePython 3.1.2.3 (ActiveState Software Inc.) based on Python 3.1.2 (r312:79147, Mar 22 2010, 12:20:29) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> ham = range(10) >>> ham[11:21] Traceback (most recent call last): File "", line 1, in TypeError: sequence index must be integer, not 'slice' >>> Oh wait -- it's a range thing... >>> ham[1:3] Traceback (most recent call last): File "", line 1, in TypeError: sequence index must be integer, not 'slice' >>> ham range(0, 10) >>> type(ham) >>> ham = list(range(10)) >>> ham[11:21] [] >>> Well, that's annoying, but it is what xrange did and the docs do say range 3.0 is the old xrange 2.x and that the old range 2.x I've deployed. Stutter-stepping-to-3.x-ly yrs, Emile From jonas at codeazur.com.br Sat Sep 25 15:02:54 2010 From: jonas at codeazur.com.br (Jonas Galvez) Date: Sat, 25 Sep 2010 16:02:54 -0300 Subject: Python2.7 on OSX Message-ID: Just installed Python2.7 on my OSX Leopard with make altinstall. No missing dependencies, but I have one annoying problem: the delete key prints '^H' on the Python shell. Does anyone know how to fix that? Thanks in advance, -- Jonas -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Sep 25 15:05:33 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 26 Sep 2010 00:35:33 +0530 Subject: Python2.7 on OSX In-Reply-To: References: Message-ID: On Sun, Sep 26, 2010 at 12:32 AM, Jonas Galvez wrote: > Just installed Python2.7 on my OSX Leopard with make altinstall. > > No missing dependencies, but I have one annoying problem: the delete key > prints '^H' on the Python shell. > > Does anyone know how to fix that? > > Thanks in advance, > Is readline module installed in yours ? try 'import readline' to check. > > -- Jonas > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From sschwarzer at sschwarzer.net Sat Sep 25 15:54:49 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 25 Sep 2010 21:54:49 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: <4C9E5389.2080103@sschwarzer.net> Hi Terry, On 2010-09-25 19:24, Terry Reedy wrote: > On 9/25/2010 4:22 AM, Yingjie Lan wrote: > There is already a builtin reversed() function whose output can be > multiplied. Seemingly, it can't: $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> L = [1, 2, 3] >>> 3 * reversed(L) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for *: 'int' and 'listreverseiterator' $ python3 Python 3.1.2 (r312:79147, Apr 15 2010, 12:35:07) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> L = [1, 2, 3] >>> 3 * reversed(L) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for *: 'int' and 'list_reverseiterator' You can convert the result of `reversed` to a list though: >>> 3 * list(reversed(L)) [3, 2, 1, 3, 2, 1, 3, 2, 1] Stefan From arnodel at gmail.com Sat Sep 25 16:38:56 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 25 Sep 2010 13:38:56 -0700 (PDT) Subject: sequence multiplied by -1 References: Message-ID: On 25 Sep, 09:22, Yingjie Lan wrote: > Hi, > > I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics. > > Simply put, a sequence multiplied by -1 can give a reversed sequence. > > Then for any sequence "seq", and integer n>0, we can have > > "seq * -n" producing "(seq * -1) * n". > > Any thoughts? > > Yingjie If [1, 2]*-1 is correct, then, arguably, so should be -[1, 2] :) Some answers have invoked mathematics to weigh the value of this proposal, e.g. likening lists to vectors. But the obvious mathematical analogy is that the set of all lists forms a monoid under the operation of concatenation, which (unfortunately?) is performed with the "+" operator in Python. So it is natural that "*" represents repeated concatenation. Now under concatenation, non-empty lists do not have an inverse, i.e. for any non-empty list l, there does not exist a list l' such that l + l' == []. So there is no natural interpretation of -l and therefore of l*-1. However, by using "+" for list (and string) concatenation, Python already breaks the mathematical pledge of commutativity that this operator implies. -- Arnaud From niklasro at gmail.com Sat Sep 25 18:48:56 2010 From: niklasro at gmail.com (Niklasro) Date: Sat, 25 Sep 2010 15:48:56 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <49566c36-1fe1-42d8-8d1e-32e63b510600@k13g2000vbq.googlegroups.com> <8632bf75-3963-4e85-99f3-684dcde99589@i17g2000vbq.googlegroups.com> <4c970fa2$0$7946$426a74cc@news.free.fr> Message-ID: <47bee975-56fa-458b-b191-14252308f7cb@i13g2000yqd.googlegroups.com> On Sep 20, 7:39?am, Bruno Desthuilliers wrote: > Niklasro a ?crit : > > > Good to learn what I'm doing :-) since important being able to explain > > choices taken farther than "doing it because it works". > > I understand the concept of modules may not correspond to java > > programming where I come from. > > Coming from Java - and specially if you only have experience with Java > -, you'll have to unlearn quite a few things. Python is 100% object - in > that everything you can bind to a name is an object, including classes, > functions, methods, and even modules - but it doesn't try to force you > into using classes when you don't need them. Which is good since always questioning the empty declarations Java has we know empty getters and setters forced to a class and interfaces with nothing but names and no logic. With this respect I prefer python solving same problem with ? MB python 30 MB J2EE used to with drawback only that Java had the faster physical response. You can have the buggiest code respond the fastest like a hijacked environment physically boosted you don't want and naturally choosing the slower physical response time in favor of decent development environment. Thanks Niklas From niklasro at gmail.com Sat Sep 25 18:51:45 2010 From: niklasro at gmail.com (Niklasro) Date: Sat, 25 Sep 2010 15:51:45 -0700 (PDT) Subject: Learning inheritance References: <933a5658-5184-4275-b28d-3005440d5bea@t11g2000vbc.googlegroups.com> <99bd0662-c2d4-4dcd-9a20-33d17823deaf@f26g2000vbm.googlegroups.com> <4c970e7f$0$21775$426a74cc@news.free.fr> <65e3f364-3b47-407e-a0d4-326c5a3b2f6b@k17g2000prf.googlegroups.com> Message-ID: <7c50b086-d34d-4813-8a14-99c926c8e240@n3g2000yqb.googlegroups.com> On Sep 21, 1:30?am, alex23 wrote: > Bruno Desthuilliers > wrote: > > > alex23 a ?crit : > > > Python only actually executes a module the first time it's imported, > > > Beware of multithreading and modules imported under different names... > > There can be issues with both in some web frameowrks. > > Good points, Bruno, thank you. > > Niklasro, a good example of Bruno's second point: running a module as > a script and then importing it elsewhere later will execute the module > in the second import, creating two module objects - '__main__' and > ''. > > The issue with threading is the more important one of which to be > aware. I follow it means learning when constructors get called twice. Normally a constructor should get called once only. Many thanks for the insights both solving my problem and referencing important topics From nobody at nowhere.com Sat Sep 25 20:12:45 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 26 Sep 2010 01:12:45 +0100 Subject: SocketServer: replace network by hard drive References: <6edc9db5-c9bb-47a7-9228-4288cf3d103a@w4g2000vbh.googlegroups.com> Message-ID: On Sat, 25 Sep 2010 14:45:29 +0200, Thomas Jollans wrote: >> The problem with using the loopback interface is that it's still >> "network access", which can run into all kinds of issues with security >> policies, firewalls, etc. > > What kind of crappy firewall blocks loopback traffic? Really? The sort that restricts the ability to create sockets rather than filtering traffic. ZoneAlarm works like this. From steve at REMOVE-THIS-cybersource.com.au Sat Sep 25 21:34:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Sep 2010 01:34:34 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: <4c9ea32a$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 13:45:11 +0200, Thomas Jollans wrote: > On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: >> Hi, >> >> I noticed that in python3k, multiplying a sequence by a negative >> integer is the same as multiplying it by 0, and the result is an empty >> sequence. It seems to me that there is a more meaningful symantics. > > Um... > > for every list l and integer n >= 0: > len(l*n) == len(l)*n > > Multiplying a list by a negative integer should produce a list of > negative length, which does not exist. Look at the domain of your invariance. It says nothing about negative n, and nor should it. > IMHO, the only correct behaviour > would be to raise an exception, though one could argue that there are > practical benefits for the operation to succeed for any integer operand. Since lists of negative length don't exist, we're free to set the invariance to something which has a less restrictive domain and is more useful than raising an exception: for every list l and integer n: len(l*n) == len(l)*max(0, n) >> Simply put, a sequence multiplied by -1 can give a reversed sequence. > > For that, we have slicing. A negative step value produces a reverse > slice of the list. You can't argue that this makes sense, can you > >>>> [1,2,3,4][::-1] > [4, 3, 2, 1] >>>> [1,2,3,4][::-2] > [4, 2] Why does it not make sense? I'm more concerned that the simple idiom: # list L must have at least 5 items, so extend it with None if needed L.extend([None]*(5 - len(L)) would suddenly break with this proposal. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Sep 25 22:11:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Sep 2010 02:11:55 GMT Subject: sequence multiplied by -1 References: Message-ID: <4c9eabeb$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 06:54:36 -0700, Yingjie Lan wrote: > For the rule above, how about the > case to reverse and multiply: > >>>> L*-3 #L reversed and repeated three times > > v.s. > >>>> L[::-1]*3 #L reversed and repeated three times > > The first one is simpler (4 chars v.s. 9 chars). I thought it was also > intuitive because if you multiply a vector by -1, you should get a > vector in the reversed direction. Reversing the order of elements in a vector does NOT reverse the vector's direction. Vector multiplication by a scalar does elementwise multiplication. In mathematics and physics: [1, 2, 3]*5 => [5, 10, 15] [1, 2, 3]*-1 => [-1, -2, -3] is a reflection of the vector. It certainly doesn't reverse the order of elements! [1, 2, 3] => [3, 2, 1] is a rotation, not a reflection. Python doesn't treat sequences as vectors, since it's a programming language and sequences are more general. Instead it performs repetition. This is conceptually simple: multiplying a sequence by n *repeats* the sequence n times: L*n = L+L+L+...+L # n times where + is concatenation, not elementwise addition. If n is zero, you get the empty sequence: L*0 = an empty sequence of the same type as L just like you get nothing if you multiply a number by n. If you ask for zero copies of a sequence, you get nothing. The only tricky parts are what to do for fractional values of n, and negative values. For practical reasons, the current behaviour is the most useful thing to do. Once you see sequence multiplication as repetition, then the natural interpretation of multiplication by a negative value *cannot* be reversal, or any other re-ordering or permutation. How many repetitions of [1, 2, 3, 4] does it take to give [1, 4, 2, 3]? Answer -- you can't get any other permutation by repeating the original. Singling out reversal as a privileged permutation is just "tacking on" extra functionality, for no real benefit. It would be like making: sorted(my_list) => sequence in sorted order sorted(my_list, reversed=True) => sequence in reverse sorted order sorted(my_list, reversed=3) => sequence with every element multiplied by 3, then sorted Yes, you could do it, and yes, it might save somebody a line of code somewhere, but WTF??? But even if it wasn't, for reasons of backward compatibility, to say nothing of the moratorium, it isn't going to change. -- Steven From lanyjie at yahoo.com Sat Sep 25 23:07:08 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 20:07:08 -0700 (PDT) Subject: sequence multiplied by -1 In-Reply-To: <4c9eabeb$0$28659$c3e8da3@news.astraweb.com> Message-ID: <143743.27067.qm@web54208.mail.re2.yahoo.com> Hi all, Thanks for considering this proposal seriously and all your discussions shed light on the pro's and cons (well, more cons than pros, to be honest). It occurrs to me that this proposal is not a sound one, for the reasons already well documented in this thread, which I need not repeat. Thanks all for participation! Yingjie From lanyjie at yahoo.com Sat Sep 25 23:35:05 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Sat, 25 Sep 2010 20:35:05 -0700 (PDT) Subject: solve alphametic puzzles in just 9 lines of code In-Reply-To: <164829.96277.qm@web54204.mail.re2.yahoo.com> Message-ID: <56462.44143.qm@web54201.mail.re2.yahoo.com> Sorry, didn't document my code well enough. Here is the code with an example. Yingjie #############Code begins############### from itertools import permutations def solve(puzzle): """solve alphametic puzzles in just 9 lines of code. Make sure each operator is seperated from the words by white-spaces, e.g.: >>> solve('send + more == money') """ words = [w for w in puzzle.split() if w.isalpha()] nonzeros = {w[0] for w in words} others = {a for a in ''.join(words) if a not in nonzeros} chars = [ord(c) for c in nonzeros]+[ord(c) for c in others] assert len(chars) <= 10, 'Too many letters' for guess in permutations('0123456789', len(chars)): if '0' not in guess[:len(nonzeros)]: equation = puzzle.translate(dict(zip(chars, guess))) if eval(equation): return puzzle, equation if __name__ == '__main__': print ('\n'.join(solve("send + more == money"))) From xahlee at gmail.com Sun Sep 26 00:05:13 2010 From: xahlee at gmail.com (Xah Lee) Date: Sat, 25 Sep 2010 21:05:13 -0700 (PDT) Subject: toy list processing problem: collect similar terms Message-ID: here's a interesting toy list processing problem. I have a list of lists, where each sublist is labelled by a number. I need to collect together the contents of all sublists sharing the same label. So if I have the list ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t)) where the first element of each sublist is the label, I need to produce: output: ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) a Mathematica solution is here: http://xahlee.org/UnixResource_dir/writ/notations_mma.html R5RS Scheme lisp solution: http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_gmail.scm by Sourav Mukherjee also, a Common Lisp solution can be found here: http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1ded8824bc750b? anyone care to give a solution in Python, Perl, javascript, or other lang? am guessing the scheme solution can be much improved... perhaps using some lib but that seems to show scheme is pretty weak if the lib is non-standard. Xah ? xahlee.org ? From nagle at animats.com Sun Sep 26 01:08:54 2010 From: nagle at animats.com (John Nagle) Date: Sat, 25 Sep 2010 22:08:54 -0700 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> Message-ID: <4c9ed575$0$1644$742ec2ed@news.sonic.net> On 9/25/2010 4:45 AM, Thomas Jollans wrote: > On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: >> Hi, >> >> I noticed that in python3k, multiplying a sequence by a negative integer is >> the same as multiplying it by 0, and the result is an empty sequence. It >> seems to me that there is a more meaningful symantics. The concept that the multiply operator should be overloaded to do something l33t on sequences was a Python design mistake. It leads to semantics like this: x = 10 y = "10" x*2 20 y*2 '1010' int(y*2) 1010 int(y)*2 20 That's awful. It's the kind of thing a novice C++ programmer would write shortly after they discovered operator overloading. Now, ask yourself, when you get a numeric value back from a database, is it an integer or a string? How about the CSV module? Are you sure? John Nagle From gherron at digipen.edu Sun Sep 26 01:21:48 2010 From: gherron at digipen.edu (Gary Herron) Date: Sat, 25 Sep 2010 22:21:48 -0700 Subject: toy list processing problem: collect similar terms In-Reply-To: References: Message-ID: <4C9ED86C.70807@digipen.edu> On 09/25/2010 09:05 PM, Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > a Mathematica solution is here: > http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > R5RS Scheme lisp solution: > http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_gmail.scm > by Sourav Mukherjee > > also, a Common Lisp solution can be found here: > http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1ded8824bc750b? > > anyone care to give a solution in Python, Perl, javascript, or other > lang? am guessing the scheme solution can be much improved... perhaps > using some lib but that seems to show scheme is pretty weak if the lib > is non-standard. > > Xah ? xahlee.org ? > Python 3: (I have not tried to match the exact format of your output, but I get the right things is the right order.) data = ((0,'a','b'), (1,'c','d'), (2,'e','f'), (3,'g','h'), (1,'i','j'), (2,'k','l'), (4,'m','n'), (2,'o','p'), (4,'q','r'), (5,'s','t')) from collections import OrderedDict r = OrderedDict() for label,*rest in data: r.setdefault(label, []).extend(rest) print(list(r.values())) produces: (['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'], ['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']) -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From abu at software-lab.de Sun Sep 26 01:29:20 2010 From: abu at software-lab.de (Alexander Burger) Date: Sun, 26 Sep 2010 05:29:20 +0000 (UTC) Subject: toy list processing problem: collect similar terms References: Message-ID: In PicoLisp: (mapcar '((X) (apply conc (cdr X))) (group List) ) Cheers, - Alex From no.email at nospam.invalid Sun Sep 26 02:17:23 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 25 Sep 2010 23:17:23 -0700 Subject: toy list processing problem: collect similar terms References: Message-ID: <7xzkv5hvv0.fsf@ruckus.brouhaha.com> Python solution follows (earlier one with an error cancelled). All crossposting removed since crossposting is a standard trolling tactic. from collections import defaultdict def collect(xss): d = defaultdict(list) for xs in xss: d[xs[0]].extend(xs[1:]) return list(v for k,v in sorted(d.items())) y = [[0,'a','b'], [1,'c','d'], [2,'e','f'], [3,'g','h'], [1,'i','j'], [2,'k','l'], [4,'m','n'], [2,'o','p'], [4,'q','r'], [5,'s','t']] print collect(y) From oddron at gmail.com Sun Sep 26 02:19:59 2010 From: oddron at gmail.com (Ronald Guida) Date: Sun, 26 Sep 2010 02:19:59 -0400 Subject: Python 2.7 installation problem Message-ID: Hi, I am trying to perform a user-install of python 2.7 on Ubuntu 10.04, and my installation is failing. This sequence of commands reproduces the failure on my system: $ tar -zxvf Python-2.7.tgz $ cd Python-2.7/ $ ./configure --prefix=$HOME $ make $ ./python Lib/test/test_collections.py doctest (collections) ... 54 tests with zero failures $ make altinstall $ cd $ which python2.7 /home/oddron/bin/python2.7 $ python2.7 Python 2.7 (r27:82500, Sep 26 2010, 01:49:59) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import collections Traceback (most recent call last): File "", line 1, in File "/home/oddron/lib/python2.7/collections.py", line 8, in from _collections import deque, defaultdict ImportError: No module named _collections >>> import sys >>> sys.path ['', '/home/oddron/lib/python27.zip', '/home/oddron/lib/python2.7', '/home/oddron/lib/python2.7/plat-linux2', '/home/oddron/lib/python2.7/lib-tk', '/home/oddron/lib/python2.7/lib-old', '/home/oddron/lib/python2.7/lib-dynload', '/home/oddron/.local/lib/python2.7/site-packages', '/home/oddron/lib/python2.7/site-packages'] >>> Things I have already checked: * My path includes ~/bin * None of PYTHONHOME and friends are set. * I have also tried "make install" instead of "make altinstall", and I get the same failure. Can anyone give me a hint regarding what has gone wrong? Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Sep 26 02:27:00 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Sep 2010 06:27:00 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> Message-ID: <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 22:08:54 -0700, John Nagle wrote: > On 9/25/2010 4:45 AM, Thomas Jollans wrote: >> On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: >>> Hi, >>> >>> I noticed that in python3k, multiplying a sequence by a negative >>> integer is the same as multiplying it by 0, and the result is an empty >>> sequence. It seems to me that there is a more meaningful symantics. > > The concept that the multiply operator should be overloaded to > do something l33t on sequences was a Python design mistake. Repetition is a simple, useful operation, and describing it pejoratively as "l33t" is just silly. > It leads to semantics like this: > > x = 10 > y = "10" > > x*2 > 20 > y*2 > '1010' > int(y*2) > 1010 > int(y)*2 > 20 Yes. Where's the problem? Are you also concerned that int(max("230", "9")) returns 9 but max(int ("230"), int("9")) returns 230? It's obvious that there is no such invariant that int(f(y)) must equal f(int(y)) for arbitrary functions f, so why do you think that the failure of this invariant to hold for the * operator matters in the least? > That's awful. It's the kind of thing a novice C++ > programmer would write shortly after they discovered operator > overloading. So you say. > Now, ask yourself, when you get a numeric value back from > a database, is it an integer or a string? How about the CSV module? > Are you sure? If you're not sure what sort of data you're getting, you've got no business blindly applying functions in some arbitrary order to it in the hope that the result will be sensible. If the data is meant to be an integer, and you might get a string from the database, then convert it to an integer as soon as possible. I'm surprised that you think that you should be able to apply arbitrary mathematical operations to strings *before* turning them into an int and still get sensible results. That boggles my mind. -- Steven From lie.1296 at gmail.com Sun Sep 26 02:44:24 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 26 Sep 2010 16:44:24 +1000 Subject: Python in Linux - barrier to Python 3.x In-Reply-To: <87vd5zyrkr.fsf@web.de> References: <874odj1b8h.fsf@web.de> <87zkvbytnk.fsf@web.de> <87vd5zyrkr.fsf@web.de> Message-ID: <4c9eeb19$1@dnews.tpgi.com.au> On 09/22/10 02:44, Diez B. Roggisch wrote: > Antoine Pitrou writes: > >> On Tue, 21 Sep 2010 17:59:27 +0200 >> deets at web.de (Diez B. Roggisch) wrote: >>> >>> The problems explained are simply outdated and crippled python >>> versions. >>> >>> And to me, a python version installed that has not the >>> distutils module is *crippled*. You can rationalize that as much as you >>> want through some package philosophy saying "we don't ship development >>> related files", but to me a simple installation instruction that says >> >> comp.lang.python doesn't handle Linux packaging, so why don't you >> complain to your distro instead? Ranting on this group has zero chance >> of fixing the problem. > > comp.lang.python frequently deals with problems caused by this and other > distro-related issues. Your are welcome to not participate on these > discussions. > > The state of affairs isn't ideal, and there is improvement options on > all sides. I'm just astonished that people seem to think that distros in > general are better and should be left alone, than what a more python > centric solution could be. If your distro's package management system doesn't provide you with the packages you need, then you have made the wrong choice of distro; it's neither the fault of the distro, package manager, or python; the distro's policies just does not suit your needs, and either you have made the mistake of choosing that distro or the other distros are even worse. Maybe it's time to evaluate whether staying in your current distro is still beneficial, or it's more hassle than its worth, or if you want to fix the distro's package manager in some way. Package Management Triangle reliability / \ / Pick \ / any \ / two \ simplicity ------------ configurability Ubuntu's (and I believe Debian's) apt-get and Add/Remove Program is very easy to use and stable, but there is not much configurability, you get what your package manager gives you. Gentoo's Portage is extremely configurable, it almost always gives you the latest versions and almost all of the valid configurations allowed by upstream developer, but the system is nowhere near simple, and every system you build using Portage is basically untested system. From no.email at nospam.invalid Sun Sep 26 02:46:57 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 25 Sep 2010 23:46:57 -0700 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> Message-ID: <7xd3s1knmm.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > I'm surprised that you think that you should be able to apply > arbitrary mathematical operations to strings *before* turning them > into an int and still get sensible results. That boggles my mind. I think the idea is you should not be able to do mathematical operations on strings, and if you try to do one, Python should raise an exception, rather than using hokey analogies to guess at what you were trying to do. If you want to replicate a sequence, introduce a function with a name like "replicate", rather than overloading an arithmetic operator. From livibetter at gmail.com Sun Sep 26 03:47:23 2010 From: livibetter at gmail.com (livibetter) Date: Sun, 26 Sep 2010 00:47:23 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: Message-ID: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Here is mine for Python: l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], [5, 's', 't']] d = {} for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx] + items if idx in d else items print d.values() Output: [['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'], ['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']] From steve at REMOVE-THIS-cybersource.com.au Sun Sep 26 03:56:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Sep 2010 07:56:59 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> Message-ID: <4c9efccb$0$28659$c3e8da3@news.astraweb.com> On Sat, 25 Sep 2010 23:46:57 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> I'm surprised that you think that you should be able to apply arbitrary >> mathematical operations to strings *before* turning them into an int >> and still get sensible results. That boggles my mind. > > I think the idea is you should not be able to do mathematical operations > on strings, and if you try to do one, Python should raise an exception, > rather than using hokey analogies to guess at what you were trying to > do. If you want to replicate a sequence, introduce a function with a > name like "replicate", rather than overloading an arithmetic operator. But * isn't a mathematical operation on sequences. It's a repetition operator. And repetition isn't a "hokey analogy" of multiplication -- you've got it completely backwards. Multiplication is a generalisation of repetition, and sequence repetition is more fundamental than mathematical multiplication. Long before anyone said 2.3 * 5.7 people were able to talk about "two bags of wheat, and another two bags of wheat, and repeat six more times". That's how multiplication was invented -- from repeated addition. Think of writing numbers as tallies, before the invention of arabic numerals. III groups of II would be IIIIII. The semantics of list.index() and str.index() are not quite the same (string indexing finds substrings, while list indexing does not find sublists). So what? We have classes and modules and namespaces so that you don't need every function to have a unique. It's okay that the index method behaves slightly differently when operating on strings and lists, and it's okay for the * operator to behave slightly differently too. It is true that there's a certain class of coders who apparently like line-noise, and so they overload operators to do arbitrary things with no concern about familiarity with common convention or readability: # sort the sequence by length my_seq ** len But this is bad because there's no convention for exponentiation being related to sorting, and so the code is obscure and unintuitive. Without the comments, you would have no idea what the line did. But that's just the same as doing this: def raise_to_power(alist, key): alist.sort(key=key) return alist This is dumb whether you overload the ** operator or write a function called "raise_to_power". There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", and the fact that it doesn't do the same thing as int("spam")*3 is a foolish argument. -- Steven From chris at simplistix.co.uk Sun Sep 26 04:13:09 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Sun, 26 Sep 2010 09:13:09 +0100 Subject: Checker 1.4 Released! Message-ID: <4C9F0095.7030705@simplistix.co.uk> I'm pleased to announce a new release of Checker. This is a cross-platform, pluggable tool for comparing the configuration of a machine with a known configuration stored in text files in a source control system all written in Python. This release adds a 'command' checker that lets you record and check the output of arbitrary commands. The initial use case was for dealing with the output of 'chkconfig --list' on Red Hat. For more information, please see: http://www.simplistix.co.uk/software/python/checker cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From no.email at nospam.invalid Sun Sep 26 04:16:49 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 26 Sep 2010 01:16:49 -0700 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: <7x4odcc426.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? Should "spam"*2.5 be "spamspamsp"? Should "spam"-"a" be "spm"? What about "spamspam"-"a"? And what about "spam"/2? "sp" be an ok first guess, but "sa" might make more sense (it means (1,2,3,...)/2 would be (1,3,5...)). I say it's all hokey from the get-go ;-). From arnodel at gmail.com Sun Sep 26 04:29:53 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 26 Sep 2010 01:29:53 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Message-ID: <10e80524-3d6e-4655-8b2b-f82e38531966@m15g2000yqm.googlegroups.com> On 26 Sep, 08:47, livibetter wrote: > Here is mine for Python: > > l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, > 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], > [5, 's', 't']] > d = {} > for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx] + items > if idx in d else items > print d.values() > > Output: > [['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'], > ['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']] from itertools import groupby from operator import itemgetter l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], [5, 's', 't']] [ [x for g in gs for x in g[1:]] for _, gs in groupby(sorted(l), itemgetter(0)) ] -- Arnaud From sschwarzer at sschwarzer.net Sun Sep 26 05:20:18 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 26 Sep 2010 11:20:18 +0200 Subject: creating python daemon ? In-Reply-To: <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> <87fwx2yw04.fsf@web.de> <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> Message-ID: <4C9F1052.9050700@sschwarzer.net> Hi Daniel, On 2010-09-23 07:30, vineet daniel wrote: > On Sep 22, 2:20 pm, de... at web.de (Diez B. Roggisch) wrote: >> vineet daniel writes: >>> On Sep 21, 9:47 pm, de... at web.de (Diez B. Roggisch) wrote: >>>> vineet daniel writes: >>>>> code that I am using is as follows : >> >>>>> #! /usr/bin/env python >>>>> import sys,os >>>>> pid = os.fork() >>>>> os.chdir("/var/www/html/") >>>>> os.setsid() >>>>> os.umask(0) >>>>> #this line will read apache log in real time as redirected from the >>>>> CustomLog directive of Apache. >>>>> log = sys.stdin.readlines() >>>>> f = open('/var/www/logmongo.txt','a') # append log to this text file >>>>> f.write(log) I guess you'll need some loop to process the input from Apache. > There is a directive in Apache - CustomLog which can redirect logs to > a script or another file by using Pipe. I googled about it and came to > know that this works flawlessly with Perl as Apache treats Perl > scripts as daemon, for Python to take input from Apache, it needs to > work as daemon. Apache will then push its logs lines to this daemon as > input. Perl takes this input as but python's stdin is not > working as expected it just takes the file name as given in CustomLog > directive using Pipe i.e if I use CustomLog '|/var/wwww/script.py' Are the _four_ ws intentional? > combined, what script reads is just the file name, how and why I am > not able to figure it out. And thats the reason I am here. I hope > you've got what I am trying to do. Do you have a line for the interpreter at the top of your script, like #!/usr/bin/python Is the script executable (e. g. chmod +x script.py)? Stefan From usenet-nospam at seebs.net Sun Sep 26 05:30:08 2010 From: usenet-nospam at seebs.net (Seebs) Date: 26 Sep 2010 09:30:08 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-26, Steven D'Aprano wrote: > On Sat, 25 Sep 2010 23:46:57 -0700, Paul Rubin wrote: >> I think the idea is you should not be able to do mathematical operations >> on strings, and if you try to do one, Python should raise an exception, >> rather than using hokey analogies to guess at what you were trying to >> do. If you want to replicate a sequence, introduce a function with a >> name like "replicate", rather than overloading an arithmetic operator. > But * isn't a mathematical operation on sequences. It's a repetition > operator. I think Paul's point is that "*" is in general a mathematical operation, and discovering that for some types of objects, it's been given a fundamentally unrelated meaning can certainly be a bit of a surprise. I actually sort of like that perl has a separate repetition operator. And really, when you find yourself saying something nice about perl's syntax or punctuation, that's always scary territory to be in. > There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > and the fact that it doesn't do the same thing as int("spam")*3 is a > foolish argument. The languages in which it's surprising are mostly things like perl, where there's a certain amount of implicit coercion going on, so it's ambiguous whether "3"*3 ought to mean "333" or 9. (Except it isn't, because repetition is a separate operator, written "3" x 3 rather than "3" * 3...) People coming from that kind of background may be expecting * to stay an arithmetic operator, rather than having it change form when applied to non-arithmetic objects. I'm not sure either way. I think on the whole, I like the notion of a repetition operator which is distinct from multiplication, but I also definitely prefer the lack of implicit coercion, and without implicit coercion, there's a lot less underlying ambiguity to worry about. >From the top, I guess my analysis is: * It seems clear that, given two sequences x and y, "x + y" ought to be the concatenation of these sequences. * Thus, "x + x" should be x concatenated to itself. * Idiomatically, it is not unreasonable to assert that "x * 2" and "x + x" could be the same value. * It thus makes some sense for * to indicate repetition of the sequence. * Since a string is a kind of a sequence, it also makes sense for * to indicate repetition. So I think I'm pretty much convinced that Python's behavior makes sense, but it makes sense only because I'm going into this expecting operators to be defined by types, so I don't expect every '*' to mean 'multiplication'. Helps, perhaps, that I got exposed to group theory early enough to be used to redefining + and * to be any two operations which have interesting properties*. -s [*] What's purple and commutes? An abelian grape. -- 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 rvtol+usenet at xs4all.nl Sun Sep 26 05:41:23 2010 From: rvtol+usenet at xs4all.nl (Dr.Ruud) Date: Sun, 26 Sep 2010 11:41:23 +0200 Subject: toy list processing problem: collect similar terms In-Reply-To: References: Message-ID: <4c9f1543$0$41105$e4fe514c@news.xs4all.nl> On 2010-09-26 06:05, Xah Lee wrote: > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) The input is a string on STDIN, and the output is a string on STDOUT? Use a hash: perl -MData::Dumper -wle '$Data::Dumper::Sortkeys = 1; my $t = "((0 a b) (1 c d) (2 e f) (3 g h) (1 i j)" . " (2 k l) (4 m n) (2 o p) (4 q r) (5 s t))"; push @{ $h{ $1 } }, $2 while $t =~ /(\w+)([^)]*)/g; # gist print Dumper \%h; ' or an array: perl -wle ' my $t = "((0 a b) (1 c d) (2 e f) (3 g h) (1 i j)" . " (2 k l) (4 m n) (2 o p) (4 q r) (5 s t))"; push @{$a[$1]},$2 while $t =~ /(\w+)\s+([^)]*)/g; # gist.1 print "((".join(") (",map join(" ",@$_), at a )."))"; # gist.2 ' Or if the list is not just a string, but a real data structure in the script: perl -wle' my $t = [ [qw/0 a b/], [qw/1 c d/], [qw/2 e f/], [qw/3 g h/], [qw/1 i j/], [qw/2 k l/], [qw/4 m n/], [qw/2 o p/], [qw/4 q r/], [qw/5 s t/] ]; push @{ $a[ $_->[0] ] }, [ @$_[ 1, 2 ] ] for @$t; # AoAoA printf "((%s))\n", join ") (", map join( " ", map join( " ", @$_ ), @$_ ), @a; ' Etc. -- Ruud From no.email at nospam.invalid Sun Sep 26 06:06:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 26 Sep 2010 03:06:03 -0700 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: <7xtylcx1is.fsf@ruckus.brouhaha.com> Seebs writes: > * It seems clear that, given two sequences x and y, "x + y" ought to > be the concatenation of these sequences. >... > Helps, perhaps, that I got exposed to group theory early enough to be used > to redefining + and * to be any two operations which have interesting > properties*. But groups have only one of those operators, and when it's written as + that usually means the group is commutative. So you wouldn't want + to denote sequence concatenation. If + and * are both present, that sounds like a ring, in which case you'd want "foo"*"bar" to work. It actually seems to me that exponentiation makes more sense than multiplication for turning "a" into "aaa". We think of aaa as what results from writing "a" with "3" in the superscript position. From Tribulations at Paralleles.invalid Sun Sep 26 06:17:38 2010 From: Tribulations at Paralleles.invalid (TP) Date: Sun, 26 Sep 2010 12:17:38 +0200 Subject: equivalent of bash "set -x" in Python Message-ID: <27j3n7-vaj.ln1@rama.universe> Hi everybody, I am interested in having the possibility to print every Python commands in a script (for didactic purpose). So I am looking for some sort of equivalent of bash "set -x". Does it exist? Thanks Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From prologic at shortcircuit.net.au Sun Sep 26 06:28:00 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Sun, 26 Sep 2010 20:28:00 +1000 Subject: equivalent of bash "set -x" in Python In-Reply-To: <27j3n7-vaj.ln1@rama.universe> References: <27j3n7-vaj.ln1@rama.universe> Message-ID: On Sun, Sep 26, 2010 at 8:17 PM, TP wrote: > Hi everybody, > > I am interested in having the possibility to print every Python commands in > a script (for didactic purpose). > So I am looking for some sort of equivalent of bash "set -x". > Does it exist? What do you mean by "command" ? cheers James -- -- James Mills -- -- "Problems are solved by method" From clp2 at rebertia.com Sun Sep 26 06:28:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 26 Sep 2010 03:28:57 -0700 Subject: equivalent of bash "set -x" in Python In-Reply-To: <27j3n7-vaj.ln1@rama.universe> References: <27j3n7-vaj.ln1@rama.universe> Message-ID: On Sun, Sep 26, 2010 at 3:17 AM, TP wrote: > Hi everybody, > > I am interested in having the possibility to print every Python commands in > a script (for didactic purpose). > So I am looking for some sort of equivalent of bash "set -x". > Does it exist? Not exactly. However, defining an appropriate function and passing it to sys.settrace() would be the closest analogue: http://docs.python.org/library/sys.html#sys.settrace You could also step through your code manually using the debugger: http://docs.python.org/library/pdb.html Cheers, Chris -- http://blog.rebertia.com From hobson42 at gmaiil.com Sun Sep 26 06:33:36 2010 From: hobson42 at gmaiil.com (Ian) Date: Sun, 26 Sep 2010 11:33:36 +0100 Subject: sequence multiplied by -1 In-Reply-To: <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4C9F2180.7050903@gmaiil.com> On 26/09/2010 07:27, Steven D'Aprano wrote: > I'm surprised that you think that you > should be able to apply arbitrary mathematical operations to strings > *before* turning them into an int and still get sensible results. That > boggles my mind. > You clearly have not been "spoiled rotten" by php. Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From Tribulations at Paralleles.invalid Sun Sep 26 06:46:12 2010 From: Tribulations at Paralleles.invalid (TP) Date: Sun, 26 Sep 2010 12:46:12 +0200 Subject: equivalent of bash "set -x" in Python References: <27j3n7-vaj.ln1@rama.universe> Message-ID: James Mills wrote: > What do you mean by "command" ? For example, print statements, but it could extend to class definitions, etc. I am going to examine the solution given by Chris. Cheers, Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From bc at freeuk.com Sun Sep 26 08:41:49 2010 From: bc at freeuk.com (BartC) Date: Sun, 26 Sep 2010 13:41:49 +0100 Subject: sequence multiplied by -1 In-Reply-To: References: Message-ID: "Yingjie Lan" wrote in message news:mailman.1050.1285403326.29448.python-list at python.org... > Hi, > > I noticed that in python3k, multiplying a sequence by a negative integer > is the same as multiplying it by 0, and the result is an empty sequence. > It seems to me that there is a more meaningful symantics. > > Simply put, a sequence multiplied by -1 can give a reversed sequence. > > Then for any sequence "seq", and integer n>0, we can have > > "seq * -n" producing "(seq * -1) * n". > > Any thoughts? Gimmicky. Best to define multiplication only by unsigned or positive values. -- Bartc From bkjones at gmail.com Sun Sep 26 08:55:53 2010 From: bkjones at gmail.com (Brian Jones) Date: Sun, 26 Sep 2010 08:55:53 -0400 Subject: creating python daemon ? In-Reply-To: <4C9F1052.9050700@sschwarzer.net> References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> <87fwx2yw04.fsf@web.de> <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> <4C9F1052.9050700@sschwarzer.net> Message-ID: I don't believe you need to be doing all kinds of acrobatics with apache and your python process. On Linux and Unix machines, you can tell the stock syslog daemon that messages sent to a certain syslog facility are to be sent to a named pipe. So, if you tell syslog that, say, the local6 facility should go to a named pipe, then point apache at that to do its logging, then your script becomes as simple as reading from the named pipe. I did something years ago similar to this to get syslog messages sent to my jabber client. It's perl (it predates my conversion to python), but doing the same in python would be way easier :) The code is here: http://linuxlaboratory.org/snippets/2/ And an old article from Linux.com which explains the syslog bits is here: http://www.linux.com/archive/feature/36631 I occasionally still hear from people that all of it still works. hth. brian On Sun, Sep 26, 2010 at 5:20 AM, Stefan Schwarzer wrote: > Hi Daniel, > > On 2010-09-23 07:30, vineet daniel wrote: > > On Sep 22, 2:20 pm, de... at web.de (Diez B. Roggisch) wrote: > >> vineet daniel writes: > >>> On Sep 21, 9:47 pm, de... at web.de (Diez B. Roggisch) wrote: > >>>> vineet daniel writes: > >>>>> code that I am using is as follows : > >> > >>>>> #! /usr/bin/env python > >>>>> import sys,os > >>>>> pid = os.fork() > >>>>> os.chdir("/var/www/html/") > >>>>> os.setsid() > >>>>> os.umask(0) > >>>>> #this line will read apache log in real time as redirected from the > >>>>> CustomLog directive of Apache. > >>>>> log = sys.stdin.readlines() > >>>>> f = open('/var/www/logmongo.txt','a') # append log to this text file > >>>>> f.write(log) > > I guess you'll need some loop to process the input from > Apache. > > > There is a directive in Apache - CustomLog which can redirect logs to > > a script or another file by using Pipe. I googled about it and came to > > know that this works flawlessly with Perl as Apache treats Perl > > scripts as daemon, for Python to take input from Apache, it needs to > > work as daemon. Apache will then push its logs lines to this daemon as > > input. Perl takes this input as but python's stdin is not > > working as expected it just takes the file name as given in CustomLog > > directive using Pipe i.e if I use CustomLog '|/var/wwww/script.py' > > Are the _four_ ws intentional? > > > combined, what script reads is just the file name, how and why I am > > not able to figure it out. And thats the reason I am here. I hope > > you've got what I am trying to do. > > Do you have a line for the interpreter at the top of your > script, like > > #!/usr/bin/python > > Is the script executable (e. g. chmod +x script.py)? > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Brian K. Jones My Blog http://www.protocolostomy.com Follow me http://twitter.com/bkjones -------------- next part -------------- An HTML attachment was scrubbed... URL: From jurgenex at hotmail.com Sun Sep 26 09:53:41 2010 From: jurgenex at hotmail.com (Jürgen Exner) Date: Sun, 26 Sep 2010 06:53:41 -0700 Subject: toy list processing problem: collect similar terms References: Message-ID: <12ku961maljpqr0vpecl4cc1m4r34addt6@4ax.com> Alexander Burger wrote: >In PicoLisp: What the f**** does PicoLisp have to with Perl? jue From jurgenex at hotmail.com Sun Sep 26 09:54:17 2010 From: jurgenex at hotmail.com (Jürgen Exner) Date: Sun, 26 Sep 2010 06:54:17 -0700 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Message-ID: livibetter wrote: >Here is mine for Python: What the f*** does Python have to do with Perl? jue From pjb at informatimago.com Sun Sep 26 10:24:46 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Sun, 26 Sep 2010 16:24:46 +0200 Subject: toy list processing problem: collect similar terms References: Message-ID: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Xah Lee writes: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > a Mathematica solution is here: > http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > R5RS Scheme lisp solution: > http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_gmail.scm > by Sourav Mukherjee > > also, a Common Lisp solution can be found here: > http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1ded8824bc750b? It's too complex. Just write: (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t)))) (mapcar (lambda (class) (reduce (function append) class :key (function rest))) (com.informatimago.common-lisp.list:equivalence-classes list :key (function first))) ) --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) -- __Pascal Bourguignon__ http://www.informatimago.com/ From sherm.pendley at gmail.com Sun Sep 26 10:56:07 2010 From: sherm.pendley at gmail.com (Sherm Pendley) Date: Sun, 26 Sep 2010 10:56:07 -0400 Subject: toy list processing problem: collect similar terms References: <12ku961maljpqr0vpecl4cc1m4r34addt6@4ax.com> Message-ID: J?rgen Exner writes: > Alexander Burger wrote: >>In PicoLisp: > > What the f**** does PicoLisp have to with Perl? It's Xah. He cross-posts in an attempt to start a language feud. Please don't feed the troll. sherm-- -- Sherm Pendley Cocoa Developer From sherm.pendley at gmail.com Sun Sep 26 10:56:48 2010 From: sherm.pendley at gmail.com (Sherm Pendley) Date: Sun, 26 Sep 2010 10:56:48 -0400 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Message-ID: J?rgen Exner writes: > livibetter wrote: >>Here is mine for Python: > > What the f*** does Python have to do with Perl? Xah is a cross-posting troll. Please don't feed the troll. sherm-- -- Sherm Pendley Cocoa Developer From typhoondauntless at gmail.com Sun Sep 26 11:07:22 2010 From: typhoondauntless at gmail.com (=?UTF-8?Q?tayfury=C4=B1lmaz?=) Date: Sun, 26 Sep 2010 08:07:22 -0700 (PDT) Subject: Qt not working o Wing ide 3.2 Message-ID: <650f047f-9ab4-4c17-8728-b31583d18563@28g2000yqm.googlegroups.com> hi everyone ? develop a program with pythoon and qt on wing ide ? use pyqt module in my program bu when ? debug a program,python is not debugging and o.s show a screen for solution.. and solution says python is not debugging. can he/she explain this solve problem.. thanks regards.. From invalid at invalid.invalid Sun Sep 26 11:20:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 26 Sep 2010 15:20:18 +0000 (UTC) Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: On 2010-09-26, Paul Rubin wrote: > Steven D'Aprano writes: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? Because 3 * "spam" == "spam" + "spam" + "spam" Just like 3 * 6 = 6 + 6 + 6 So now I suppose "+" for string concatenation is a bad thing. -- Grant From thomas at jollybox.de Sun Sep 26 11:20:39 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Sun, 26 Sep 2010 17:20:39 +0200 Subject: Qt not working o Wing ide 3.2 In-Reply-To: <650f047f-9ab4-4c17-8728-b31583d18563@28g2000yqm.googlegroups.com> References: <650f047f-9ab4-4c17-8728-b31583d18563@28g2000yqm.googlegroups.com> Message-ID: <201009261720.39427.thomas@jollybox.de> On Sunday 26 September 2010, it occurred to tayfury?lmaz to exclaim: > hi everyone ? develop a program with pythoon and qt on wing ide > ? use pyqt module in my program bu when ? debug a program,python is > not debugging and o.s show a screen for solution.. and solution says > python is not debugging. can he/she explain this solve problem.. > thanks > regards.. Quite frankly, I don't have the faintest idea what you're getting at. You'll have to be a lot clearer and more precise if you want to enable us to offer you useful help. * Minimal example script? * exact output (traceback!) of Python? * possibly, exact output of some other component? Just a thought - if you're using Wing IDE, you probably paid for it? Did you also pay for a support contract? Maybe that's part of the deal? If it is, maybe you should phone them up - they probably know a lot more about Wing IDE than most of us here. From mwilson at the-wire.com Sun Sep 26 11:31:51 2010 From: mwilson at the-wire.com (Mel) Date: Sun, 26 Sep 2010 11:31:51 -0400 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: Grant Edwards wrote: > On 2010-09-26, Paul Rubin wrote: >> Steven D'Aprano writes: >>> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > >> Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > > Because > > 3 * "spam" == "spam" + "spam" + "spam" > > Just like > > 3 * 6 = 6 + 6 + 6 > > So now I suppose "+" for string concatenation is a bad thing. It's awkward for math purists because there's no additive inverse .. hence the original poster's idea to simply create one out of the blue. For string lengths and list lengths we're stuck with non-negative integers, and no hope of general-purpose subtraction. I wouldn't change it. As an idiom, ' '*20 is just too handy a way to get a 20-blank string to give up. Mel. From ben at morrow.me.uk Sun Sep 26 11:39:56 2010 From: ben at morrow.me.uk (Ben Morrow) Date: Sun, 26 Sep 2010 16:39:56 +0100 Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Message-ID: Quoth pjb at informatimago.com (Pascal J. Bourguignon): > > It's too complex. Just write: > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > (2 o p) (4 q r) (5 s t)))) Unless you're going to talk about Perl, please take clpmisc out of the xpost. Ben From Tribulations at Paralleles.invalid Sun Sep 26 12:07:22 2010 From: Tribulations at Paralleles.invalid (TP) Date: Sun, 26 Sep 2010 18:07:22 +0200 Subject: adding a method to an existing builtin class Message-ID: Hi everybody, Today I have learned a bit of the news of Python 3.0 compared to 2.4 version. By the way, I have asked myself if it is possible to add a method to a builtin type as 'unicode': >>> a="foo" >>> type(a) >>> print(dir(a)) ['__add__', ..., 'zfill'] For example, I would like to add a "colorize" method to 'unicode' objects. Is this possible? Or am I compelled to derive the unicode builtin as below: class my_unicode(unicode): def __init__( self, unicode_string ): super( my_unicode, self ).__init__( ) def colorize( self ): return "\x1b[93;102m" + self + "\x1b[0m" my_unicode_string = my_unicode( "coucou" ) print( type( my_unicode_string ) ) print( my_unicode_string.colorize() ) print( my_unicode_string.upper() ) Thanks, Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From clp2 at rebertia.com Sun Sep 26 12:15:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 26 Sep 2010 09:15:29 -0700 Subject: adding a method to an existing builtin class In-Reply-To: References: Message-ID: On Sun, Sep 26, 2010 at 9:07 AM, TP wrote: > Hi everybody, > > Today I have learned a bit of the news of Python 3.0 compared to 2.4 > version. > > By the way, I have asked myself if it is possible to add a method to a > builtin type The built-in types' classes are immutable; you can only add/override their methods via subclassing, like you showed. Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Sun Sep 26 13:13:12 2010 From: nagle at animats.com (John Nagle) Date: Sun, 26 Sep 2010 10:13:12 -0700 Subject: sequence multiplied by -1 In-Reply-To: <7x4odcc426.fsf@ruckus.brouhaha.com> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: <4c9f7f36$0$1666$742ec2ed@news.sonic.net> On 9/26/2010 1:16 AM, Paul Rubin wrote: > Steven D'Aprano writes: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > Should "spam"*2.5 be "spamspamsp"? > Should "spam"-"a" be "spm"? What about "spamspam"-"a"? > And what about "spam"/2? "sp" be an ok first guess, but "sa" might > make more sense (it means (1,2,3,...)/2 would be (1,3,5...)). > > I say it's all hokey from the get-go ;-). I tend to agree. "+" as concatenation is at least associative. Trying to concatenate a string with an integer raises an exception, so that's not going to generate unexpected values. "*" as repetition, on the other hand, is a mixed-mode operation. That's why this is troublesome. Where the type spaces are isolated, overloading isn't so risky. We should have something like "repeat" or "dup" as a string method rather than an overloading of the "*" operator. Strings already have a range of methods which perform basic operations on the string and return a new string, so that's consistent. "xyz".dup(3) is clear enough. And allowing "xyz"*-3 was just lame. What reasonable use case does that have? John Nagle From detlev at die-offenbachs.de Sun Sep 26 14:35:08 2010 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sun, 26 Sep 2010 20:35:08 +0200 Subject: Qt not working o Wing ide 3.2 References: <650f047f-9ab4-4c17-8728-b31583d18563@28g2000yqm.googlegroups.com> Message-ID: Thomas Jollans wrote: > On Sunday 26 September 2010, it occurred to tayfury?lmaz to exclaim: >> hi everyone ? develop a program with pythoon and qt on wing ide >> ? use pyqt module in my program bu when ? debug a program,python is >> not debugging and o.s show a screen for solution.. and solution says >> python is not debugging. can he/she explain this solve problem.. >> thanks >> regards.. > > Quite frankly, I don't have the faintest idea what you're getting at. > You'll have to be a lot clearer and more precise if you want to enable > us to offer you useful help. > > * Minimal example script? > * exact output (traceback!) of Python? > * possibly, exact output of some other component? > > Just a thought - if you're using Wing IDE, you probably paid for it? > Did you also pay for a support contract? Maybe that's part of the deal? > If it is, maybe you should phone them up - they probably know a lot > more about Wing IDE than most of us here. Alternatively I would recommend the eric IDE, which is free and works very well with PyQt (actually it is written in PyQt). And it is available for Python2 and Python3. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From john at castleamber.com Sun Sep 26 14:43:51 2010 From: john at castleamber.com (John Bokma) Date: Sun, 26 Sep 2010 13:43:51 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> Message-ID: <87y6ao9wgo.fsf@castleamber.com> J?rgen Exner writes: > livibetter wrote: >>Here is mine for Python: > > What the f*** does Python have to do with Perl? Clueless fuck. I unsubscribed from comp.lang.perl.misc to avoid the retards like you and now you come in via the backdoor. If you have a problem with Xah report him with Google Groups and with his hosting provider 1&1 like I do. Dreamhost kicked him out that way. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From jonas at codeazur.com.br Sun Sep 26 14:44:50 2010 From: jonas at codeazur.com.br (Jonas Galvez) Date: Sun, 26 Sep 2010 15:44:50 -0300 Subject: Python2.7 on OSX In-Reply-To: References: Message-ID: Bingo, that was it. Thanks! -- Jonas On Sat, Sep 25, 2010 at 4:05 PM, Shashwat Anand wrote: > > > On Sun, Sep 26, 2010 at 12:32 AM, Jonas Galvez wrote: > >> Just installed Python2.7 on my OSX Leopard with make altinstall. >> >> No missing dependencies, but I have one annoying problem: the delete key >> prints '^H' on the Python shell. >> >> Does anyone know how to fix that? >> >> Thanks in advance, >> > > Is readline module installed in yours ? > try 'import readline' to check. > > >> >> -- Jonas >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > ~l0nwlf > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vineetdaniel at gmail.com Sun Sep 26 14:50:09 2010 From: vineetdaniel at gmail.com (vineet daniel) Date: Sun, 26 Sep 2010 11:50:09 -0700 (PDT) Subject: creating python daemon ? References: <87r5gnyrg3.fsf@web.de> <96e61ca6-9798-4f5c-852f-9649c2d802ed@g21g2000prn.googlegroups.com> <87fwx2yw04.fsf@web.de> <0f7eb556-4bc9-47bf-a9fd-762cb34535e1@j30g2000vbr.googlegroups.com> <4C9F1052.9050700@sschwarzer.net> Message-ID: <444fcb6f-c4ae-467a-946f-f60107119c6a@e34g2000prn.googlegroups.com> On Sep 26, 2:20?pm, Stefan Schwarzer wrote: > Hi Daniel, > > On 2010-09-23 07:30, vineet daniel wrote: > > > > > On Sep 22, 2:20 pm, de... at web.de (Diez B. Roggisch) wrote: > >> vineet daniel writes: > >>> On Sep 21, 9:47 pm, de... at web.de (Diez B. Roggisch) wrote: > >>>> vineet daniel writes: > >>>>> code that I am using is as follows : > > >>>>> #! /usr/bin/env python > >>>>> import sys,os > >>>>> pid = os.fork() > >>>>> os.chdir("/var/www/html/") > >>>>> os.setsid() > >>>>> os.umask(0) > >>>>> #this line will read apache log in real time as redirected from the > >>>>> CustomLog directive of Apache. > >>>>> log = sys.stdin.readlines() > >>>>> f = open('/var/www/logmongo.txt','a') # append log to this text file > >>>>> f.write(log) > > I guess you'll need some loop to process the input from > Apache. > > > There is a directive in Apache - CustomLog which can redirect logs to > > a script or another file by using Pipe. I googled about it and came to > > know that this works flawlessly with Perl as Apache treats Perl > > scripts as daemon, for Python to take input from Apache, it needs to > > work as daemon. Apache will then push its logs lines to this daemon as > > input. Perl takes this input as but python's stdin is not > > working as expected it just takes the file name as given in CustomLog > > directive using Pipe i.e if I use CustomLog '|/var/wwww/script.py' > > Are the _four_ ws intentional? > > > combined, what script reads is just the file name, how and why I am > > not able to figure it out. And thats the reason I am here. I hope > > you've got what I am trying to do. > > Do you have a line for the interpreter at the top of your > script, like > > #!/usr/bin/python > > Is the script executable (e. g. chmod +x script.py)? > > Stefan Hi Stefan The four w's is a typo error its just 'www' and using #!/usr/bin/env python.........yes script is executable. From arnodel at gmail.com Sun Sep 26 14:51:02 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 26 Sep 2010 19:51:02 +0100 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7xtylcx1is.fsf@ruckus.brouhaha.com> Message-ID: <871v8gmj8p.fsf@gmail.com> Paul Rubin writes: > Seebs writes: >> * It seems clear that, given two sequences x and y, "x + y" ought to >> be the concatenation of these sequences. >>... >> Helps, perhaps, that I got exposed to group theory early enough to be used >> to redefining + and * to be any two operations which have interesting >> properties*. > > But groups have only one of those operators, and when it's written as + > that usually means the group is commutative. So you wouldn't want + to > denote sequence concatenation. If + and * are both present, that sounds > like a ring, in which case you'd want "foo"*"bar" to work. It actually > seems to me that exponentiation makes more sense than multiplication > for turning "a" into "aaa". We think of aaa as what results from > writing "a" with "3" in the superscript position This is common notation in Computer Science. Word concatenation is often denoted multiplicatively (with the sign generally omitted) and so it follows naturally that exponentiation is used for repeated concatenation of a word with itself. This is also in keeping with group (or rather in in this case, monoid) theory notation where commutative group / monoid composition laws are denoted additively and non-commutative ones multiplicatively. So it would probably have been more in keeping with established mathematical / theoretical CS notation to write: "spam" * "eggs" instead of "spam" + "eggs" and "spam"**3 instead of "spam"*3 However it wouldn't prevent people from thinking about giving a meaning to e.g. "spam"**-2 -- Arnaud From xahlee at gmail.com Sun Sep 26 16:56:52 2010 From: xahlee at gmail.com (Xah Lee) Date: Sun, 26 Sep 2010 13:56:52 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <7xzkv5hvv0.fsf@ruckus.brouhaha.com> Message-ID: 2010-09-26 On Sep 25, 11:17?pm, Paul Rubin wrote: > Python solution follows (earlier one with an error cancelled). ?All > crossposting removed since crossposting is a standard trolling tactic. > > ? ? from collections import defaultdict > > ? ? def collect(xss): > ? ? ? ? d = defaultdict(list) > ? ? ? ? for xs in xss: > ? ? ? ? ? ? d[xs[0]].extend(xs[1:]) > ? ? ? ? return list(v for k,v in sorted(d.items())) > > ? ? y = [[0,'a','b'], [1,'c','d'], [2,'e','f'], [3,'g','h'], [1,'i','j'], > ? ? ? ? ?[2,'k','l'], [4,'m','n'], [2,'o','p'], [4,'q','r'], [5,'s','t']] > > ? ? print collect(y) Hi Paul, thanks for your solution, and thanks to many other who provided solutions. It'll take some time to go thru them. btw, i disagree about your remark on crossposting. For those interested, you can read in the following: ? ?Cross-posting & Language Factions? http://xahlee.org/Netiquette_dir/cross-post.html if anyone wants to argue with me about this, there's a my blog link at the bottom of the page where you can leave a comment. Feel free to use that. i'll go over the solutions and post if i have anything interesting to say. ? Possbly will select some to show on my site with credit of course. Xah ? xahlee.org ? From xahlee at gmail.com Sun Sep 26 17:03:40 2010 From: xahlee at gmail.com (Xah Lee) Date: Sun, 26 Sep 2010 14:03:40 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <12ku961maljpqr0vpecl4cc1m4r34addt6@4ax.com> Message-ID: <8055818b-a78d-4847-b39c-98c1edaa4b49@x20g2000pro.googlegroups.com> On Sep 26, 7:56?am, Sherm Pendley wrote: > J?rgen Exner writes: > > Alexander Burger wrote: > >>In PicoLisp: > > > What the f**** does PicoLisp have to with Perl? > > It's Xah. He cross-posts in an attempt to start a language feud. > > Please don't feed the troll. sorry i disagree. And please don't randomly accuse... I posted the following in reply to Paul Rubin's very valuable post, to comp.lang.python only. But since you cross-posted your accusation, and there are about 3 other posts of similar nature accusing me cross- posted to all groups, so am posting a response to all groups too. -------------------------------------------------- Paul, ... btw, i disagree about your remark on crossposting. For those interested, you can read in the following: ? ?Cross-posting & Language Factions? http://xahlee.org/Netiquette_dir/cross-post.html if anyone wants to argue with me about this, there's a my blog link at the bottom of the page where you can leave a comment. Feel free to use that. i'll go over the solutions and post if i have anything interesting to say. ? Possbly will select some to show on my site with credit of course. Xah ? xahlee.org ? From jbperez at gmail.com Sun Sep 26 17:29:03 2010 From: jbperez at gmail.com (Jon P.) Date: Sun, 26 Sep 2010 14:29:03 -0700 (PDT) Subject: xml.etree - why no HTMLTreeBuilder included? Message-ID: <48bc4eb7-5866-46f1-996c-715c65744a22@n19g2000prf.googlegroups.com> It is great that Fredrik Lundh's ElementTree is now a part of the Python Standard Library. However, Is it correct that if you want to use xml.etree.ElementTree to parse an HTML Document that you will have to install a separate HTMLTreeBuilder (e.g. TidyHTMLTreeBuilder) and that the only TreeBuilder objects that come with the Standard Library is the one for XML source? Seems like some kind of HTMLTreeBuilder ought to be included by default. For a script I'm doing which deals with HTML, I thought I could jettison lxml and use xml.etree instead, but since I would need to have to ask the end-user to install an external library anyways even if I use xml.etree, I switched back to lxml. From usenet at bitblocks.com Sun Sep 26 18:10:46 2010 From: usenet at bitblocks.com (Bakul Shah) Date: Sun, 26 Sep 2010 15:10:46 -0700 Subject: toy list processing problem: collect similar terms In-Reply-To: References: Message-ID: <4C9FC4E6.3030405@bitblocks.com> On 9/25/10 9:05 PM, Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) ... > anyone care to give a solution in Python, Perl, javascript, or other > lang? am guessing the scheme solution can be much improved... perhaps > using some lib but that seems to show scheme is pretty weak if the lib > is non-standard. In Q (from kx.com)[1]: x:((0; "a"; "b");(1; "c"; "d");(2; "e"; "f");(3; "g"; "h");(1; "i"; "j") (2; "k"; "l");(4; "m"; "n");(2; "o"; "p");(4; "q"; "r");(5; "s"; "t")) f:{each [,/] each [each [1 _]] x @ value group x[;0]} f x outputs "ab" "cdij" "efklop" "gh" "mnqr" "st" Note that this is actually a pretty general solution in that *all* the functions used in it operate on a variety of types. - The label could be anything, not just an integer. - What follows a label can be a list of anything. - Everything, except for = (the group function), has to do with *shaping* the output in the way you want. It is all basically cut-n-paste or pulling apart your Lego blocks and constructing a new toy from them! And most languages are really poor at that. *This* is why proponents of various languages should pay attention to such problems. ---- [1] In k3 (an older language from kx.com that you may be able to find online), x is the same but f is as follows: f:{,/'1_''x@=x[;0]} From jurgenex at hotmail.com Sun Sep 26 18:16:24 2010 From: jurgenex at hotmail.com (Jürgen Exner) Date: Sun, 26 Sep 2010 15:16:24 -0700 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> Message-ID: John Bokma wrote: >J?rgen Exner writes: > >> livibetter wrote: >>>Here is mine for Python: >> >> What the f*** does Python have to do with Perl? > >Clueless fuck. I unsubscribed from comp.lang.perl.misc to avoid the >retards like you and now you come in via the backdoor. If you have a >problem with Xah report him with Google Groups and with his hosting >provider 1&1 like I do. Dreamhost kicked him out that way. I have solved my problems with Xah years ago, that's what killfiles are for. And I have no idea why you are bringing up Xah in your current rant. It was livibetter who without any motivation or reasoning posted Python code in CLPM. If at least he had asked something like "How can I write something similar in Perl?" or _ANYTHING_ that would have made this even remotely meaningful for CLPM, then ok. But he didn't. He just dumped 7 lines of Python code to CLPM and his only comment was "Here is mine for Python". Yeah, great comment. Why would anyone in CLPM possibly care about those 7 lines of Phython code? jue jue From xahlee at gmail.com Sun Sep 26 18:20:33 2010 From: xahlee at gmail.com (Xah Lee) Date: Sun, 26 Sep 2010 15:20:33 -0700 (PDT) Subject: Unicode usenet posting. This is a test. References: Message-ID: On Sep 26, 5:40?am, Spiros Bousbouras wrote: > > And just for good measure, some ?European style quotes? and ?balanced smart > > quotes? which I intend some day to try to convince people to start using > > to eliminate the scourge of backslash escapes. ?But that's a topic for > > another day. > > I don't see how they would help to eliminate backslash escapes. Let's > imagine that strings were delimited by ? and ?. If you wanted a > string which contained a ? you would still need to escape it. I thought about these, but ultimately I don't think it is avoidable. However, using matching pairs eliminate many unnecessary escapes. For example in my recent essay about html6, I thought about the escape issue. Ultimately, if your content refers to the language itself, then you will need escapes, unless your language can switch to another quoting mechanism. For example, in perl: "this" 'this' q[this] q(this) q{this} print <<'xyzxyz'; this xyzxyz Are all equivalent. (technically except the last one which contains extra new line) Note that it has variable quoting chars. Similarly with Python. e.g. "this" 'this' """this""" '''this''' In python , the variability is less than perl. Now, suppose, if you need to quote perl code in perl itself or python in python. e.g. suppose you are writing a perl script that parse a perl snippet that contains all perl lang's quoting mechanisms, then, basically you'll start to need escapes. (worse when this is nested. A practical example that happens to me often is when writing a blog in html about using perl to parse html, and the html contains complex javascript or php, which may contain regex string, and you need to show the perl source code in html marked up syntax highlight.) in the study of symbolic logic, this is a form of self reference, and is a unavoidable problem (to not to have to escape chars yet still want the ability to quote the lang itself). the variable quoting chars also introduces some complexity. Namely, your lang at syntax level is no longer simple. e.g. in emacs lisp, whenever the symbol straight double quote appears, it has only one meaning (unless in special cases such as in comments or being escaped). Or, when you need to get strings in a lang, the only char you need to look for is double straight quote. In langs with variable quotes such as perl, this can no longer be true, in one or both ways. doesn't matter which is your philosophy in lang design with regards to quoting mechanism, unicode introduce many proper matching pairs that are helpful, and avoid multiple semantic meanings for a given char. in a similar way, this is one of my pet peeve in math notation and computer lang syntaxes. e.g. In Mathematica, paren is used for one single purpose only, always. Namely, grouping. The square bracket [] has one single purpose only, namely as bracket for function arguments. The curly brackets {} again has one single purpose only, as a syntax sugar for list, e.g. List[1,2] is the same as {1,2}. In traditional math notation and most comp langs, it's all context dependent soup. ? ?Strings in Perl and Python? http://xahlee.org/perl-python/quoting_strings.html ? ?Strings in PHP? http://xahlee.org/php/quoting_strings.html ? ?HTML6, Your HTML/XML Simplified? http://xahlee.org/comp/html6.html ? ?Matching Brackets in Unicode? http://xahlee.org/comp/unicode_matching_brackets.html Xah ? xahlee.org ? From flebber.crue at gmail.com Sun Sep 26 19:10:29 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 16:10:29 -0700 (PDT) Subject: Errors with PyPdf Message-ID: I was trying to use Pypdf following a recipe from the Activestate cookbooks. However I cannot get it too work. Unsure if it is me or it is beacuse sets are deprecated. I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- NET.pdf" You could use anything I was just testing with it. I was using the last script on that page that was most recently updated. I am using python 2.6. http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-converter/ import pyPdf def getPDFContent(path): content = "C:\Components-of-Dot-NET.pdf" # Load PDF into pyPDF pdf = pyPdf.PdfFileReader(file(path, "rb")) # Iterate pages for i in range(0, pdf.getNumPages()): # Extract text from page and add to content content += pdf.getPage(i).extractText() + "\n" # Collapse whitespace content = " ".join(content.replace(u"\xa0", " ").strip().split()) return content print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", "ignore") This is my error. >>> Warning (from warnings module): File "C:\Documents and Settings\Family\Application Data\Python \Python26\site-packages\pyPdf\pdf.py", line 52 from sets import ImmutableSet DeprecationWarning: the sets module is deprecated Traceback (most recent call last): File "C:/Python26/Pdfread", line 15, in print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", "ignore") File "C:/Python26/Pdfread", line 6, in getPDFContent pdf = pyPdf.PdfFileReader(file(path, "rb")) IOError: [Errno 2] No such file or directory: 'Components-of-Dot- NET.pdf' >>> From rhodri at wildebst.demon.co.uk Sun Sep 26 19:19:58 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 27 Sep 2010 00:19:58 +0100 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> Message-ID: On Sun, 26 Sep 2010 23:16:24 +0100, J?rgen Exner wrote: > I have solved my problems with Xah years ago, that's what killfiles are > for. And I have no idea why you are bringing up Xah in your current > rant. > > It was livibetter who without any motivation or reasoning posted Python > code in CLPM. If at least he had asked something like "How can I write > something similar in Perl?" or _ANYTHING_ that would have made this even > remotely meaningful for CLPM, then ok. > But he didn't. He just dumped 7 lines of Python code to CLPM and his > only comment was "Here is mine for Python". Yeah, great comment. Why > would anyone in CLPM possibly care about those 7 lines of Phython code? Check the Newsgroups line: this is a standard Xah "cross-post to everywhere in sight" troll. Hence (a) bringing up Xah, since he originated this thread, and (b) livibetter not thinking to trim the crossposts. Which you didn't either, I note. The only downside to killfiles is that you have to pay attention or you sometimes get bitten by this stuff. -- Rhodri James *-* Wildebeest Herder to the Masses From python at mrabarnett.plus.com Sun Sep 26 19:35:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 27 Sep 2010 00:35:20 +0100 Subject: Errors with PyPdf In-Reply-To: References: Message-ID: <4C9FD8B8.9050805@mrabarnett.plus.com> On 27/09/2010 00:10, flebber wrote: > I was trying to use Pypdf following a recipe from the Activestate > cookbooks. However I cannot get it too work. Unsure if it is me or it > is beacuse sets are deprecated. > The 'sets' module pre-dates the built-in 'set' class. The warning is just to inform you that the module will be removed in due course (it's still in Python 2.7, but not Python 3), so you can still use it in those versions. > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > NET.pdf" You could use anything I was just testing with it. > > I was using the last script on that page that was most recently > updated. I am using python 2.6. > > http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-converter/ > > import pyPdf > > def getPDFContent(path): > content = "C:\Components-of-Dot-NET.pdf" > # Load PDF into pyPDF > pdf = pyPdf.PdfFileReader(file(path, "rb")) > # Iterate pages > for i in range(0, pdf.getNumPages()): > # Extract text from page and add to content > content += pdf.getPage(i).extractText() + "\n" > # Collapse whitespace > content = " ".join(content.replace(u"\xa0", " ").strip().split()) > return content > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > > This is my error. > >>>> > > Warning (from warnings module): > File "C:\Documents and Settings\Family\Application Data\Python > \Python26\site-packages\pyPdf\pdf.py", line 52 > from sets import ImmutableSet > DeprecationWarning: the sets module is deprecated > > Traceback (most recent call last): > File "C:/Python26/Pdfread", line 15, in > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > File "C:/Python26/Pdfread", line 6, in getPDFContent > pdf = pyPdf.PdfFileReader(file(path, "rb")) > IOError: [Errno 2] No such file or directory: 'Components-of-Dot- > NET.pdf' >>>> You put the file in C:\, but you didn't tell Python where it is. You gave just the filename "Components-of-Dot-NET.pdf", and it's looking in the current directory, which probably isn't C:\. Try providing the full pathname: print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", "ignore") From w.g.sneddon at gmail.com Sun Sep 26 19:38:39 2010 From: w.g.sneddon at gmail.com (w.g.sneddon at gmail.com) Date: Sun, 26 Sep 2010 16:38:39 -0700 (PDT) Subject: Errors with PyPdf References: Message-ID: On Sep 26, 7:10?pm, flebber wrote: > I was trying to use Pypdf following a recipe from the Activestate > cookbooks. However I cannot get it too work. Unsure if it is me or it > is beacuse sets are deprecated. > > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > NET.pdf" You could use anything I was just testing with it. > > I was using the last script on that page that was most recently > updated. I am using python 2.6. > > http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > import pyPdf > > def getPDFContent(path): > ? ? content = "C:\Components-of-Dot-NET.pdf" > ? ? # Load PDF into pyPDF > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > ? ? # Iterate pages > ? ? for i in range(0, pdf.getNumPages()): > ? ? ? ? # Extract text from page and add to content > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > ? ? # Collapse whitespace > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > ? ? return content > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > > This is my error. > > > > Warning (from warnings module): > ? File "C:\Documents and Settings\Family\Application Data\Python > \Python26\site-packages\pyPdf\pdf.py", line 52 > ? ? from sets import ImmutableSet > DeprecationWarning: the sets module is deprecated > > Traceback (most recent call last): > ? File "C:/Python26/Pdfread", line 15, in > ? ? print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > ? File "C:/Python26/Pdfread", line 6, in getPDFContent > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot- > NET.pdf' > > > > Looks like a issue with finding the file. how do you pass the path? From es at ertes.de Sun Sep 26 19:41:37 2010 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Mon, 27 Sep 2010 01:41:37 +0200 Subject: toy list processing problem: collect similar terms References: Message-ID: <20100927014137.41627b49@tritium.streitmacht.eu> Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by a number. I > need to collect together the contents of all sublists sharing the same > label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > [...] > > anyone care to give a solution in Python, Perl, javascript, or other > lang? am guessing the scheme solution can be much improved... perhaps > using some lib but that seems to show scheme is pretty weak if the lib > is non-standard. In Haskell the solution looks like this: import qualified Data.Map as M import qualified Data.Set as S import Data.Map (Map) import Data.Set (Set) collect :: (Ord a, Ord k) => [Map k (Set a)] -> Map k (Set a) collect = M.unionsWith S.union Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ From es at ertes.de Sun Sep 26 19:47:59 2010 From: es at ertes.de (Ertugrul =?UTF-8?B?U8O2eWxlbWV6?=) Date: Mon, 27 Sep 2010 01:47:59 +0200 Subject: toy list processing problem: collect similar terms References: <20100927014137.41627b49@tritium.streitmacht.eu> Message-ID: <20100927014759.2ccee77f@tritium.streitmacht.eu> Ertugrul S?ylemez wrote: > In Haskell the solution looks like this: > > [...] And before anyone starts to rant, I didn't pay attention to where I'm X-posting this stuff. Sorry for that. But on the other hand you could say that I'm giving the Perl people (apparently the only people feeling the urge to rant anyway) the chance to come up with a more elegant solution. =) Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ From rjngrj2010 at gmail.com Sun Sep 26 20:31:47 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sun, 26 Sep 2010 17:31:47 -0700 (PDT) Subject: Problems reading tif files Message-ID: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> Hi, I have read several related e-mails dating back as far as 2006. I am quite confused whether PIL can open tif images. Some posts seem to say there isn't yet any support for PIL while there are few posts where PIL has been able to open tif images. So I guess, I have to ask this probably trivial question again. I am just learning python and PIL. I have tiff images which are 8 bit and 16 bit gray scale images. I cannot open them. Here are the errors that I encounter. >> Image.open('filename') >> im.info (640, 480) {'resolution': (1, 1), 'compression': 'raw'} F;32BF TIFF But when I run the im.show() it gives the following error. >>> im.show() Traceback (most recent call last): File "", line 1, in im.show() File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 1483, in show _show(self, title=title, command=command) File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 2123, in _show apply(_showxv, (image,), options) File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 2127, in _showxv apply(ImageShow.show, (image, title), options) File "/usr/lib/python2.6/dist-packages/PIL/ImageShow.py", line 41, in show if viewer.show(image, title=title, **options): File "/usr/lib/python2.6/dist-packages/PIL/ImageShow.py", line 62, in show base = Image.getmodebase(image.mode) File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 245, in getmodebase return ImageMode.getmode(mode).basemode File "/usr/lib/python2.6/dist-packages/PIL/ImageMode.py", line 50, in getmode return _modes[mode] KeyError: 'F;32BF' I have no idea why this happens. I will appreciate a resolution. The file opens with ImageJ and ImageMagick. It is a 8-bit RGB file. I have associated default viewer to be ImageMagick. I am on Lucid Linux, and other programs such as F- spot and Gimp cannot open those files either. I don't yet know how to attach image files to the post so please bear with me till I figure that out. Thanks, gujax From flebber.crue at gmail.com Sun Sep 26 20:39:28 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 17:39:28 -0700 (PDT) Subject: Errors with PyPdf References: Message-ID: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> On Sep 27, 9:38?am, "w.g.sned... at gmail.com" wrote: > On Sep 26, 7:10?pm, flebber wrote: > > > I was trying to use Pypdf following a recipe from the Activestate > > cookbooks. However I cannot get it too work. Unsure if it is me or it > > is beacuse sets are deprecated. > > > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > > NET.pdf" You could use anything I was just testing with it. > > > I was using the last script on that page that was most recently > > updated. I am using python 2.6. > > >http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > > import pyPdf > > > def getPDFContent(path): > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > ? ? # Load PDF into pyPDF > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > ? ? # Iterate pages > > ? ? for i in range(0, pdf.getNumPages()): > > ? ? ? ? # Extract text from page and add to content > > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > > ? ? # Collapse whitespace > > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > ? ? return content > > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > > This is my error. > > > Warning (from warnings module): > > ? File "C:\Documents and Settings\Family\Application Data\Python > > \Python26\site-packages\pyPdf\pdf.py", line 52 > > ? ? from sets import ImmutableSet > > DeprecationWarning: the sets module is deprecated > > > Traceback (most recent call last): > > ? File "C:/Python26/Pdfread", line 15, in > > ? ? print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > ? File "C:/Python26/Pdfread", line 6, in getPDFContent > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> NET.pdf' > > Looks like a issue with finding the file. > how do you pass the path? okay thanks I thought that when I set content here def getPDFContent(path): content = "C:\Components-of-Dot-NET.pdf" that i was defining where it is. but yeah I updated script to below and it works. That is the contents are displayed to the interpreter. How do I output to a .txt file? import pyPdf def getPDFContent(path): content = "C:\Components-of-Dot-NET.pdf" # Load PDF into pyPDF pdf = pyPdf.PdfFileReader(file(path, "rb")) # Iterate pages for i in range(0, pdf.getNumPages()): # Extract text from page and add to content content += pdf.getPage(i).extractText() + "\n" # Collapse whitespace content = " ".join(content.replace(u"\xa0", " ").strip().split()) return content print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", "ignore") From lists at cheimes.de Sun Sep 26 21:19:28 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 27 Sep 2010 03:19:28 +0200 Subject: Problems reading tif files In-Reply-To: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> References: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> Message-ID: Am 27.09.2010 02:31, schrieb gujax: > Hi, > I have read several related e-mails dating back as far as 2006. I am > quite confused whether PIL can open tif images. Some posts seem to say > there isn't yet any support for PIL while there are few posts where > PIL has been able to open tif images. So I guess, I have to ask this > probably trivial question again. I am just learning python and PIL. I > have tiff images which are 8 bit and 16 bit gray scale images. I > cannot open them. Here are the errors that I encounter. PIL only supports a limited subset of TIFF files. Several compression algorithms like G3 and G4 fax compression are not supported yet. PIL may have a problem with partly broken TIFF files, too. > I have no idea why this happens. > I will appreciate a resolution. The file opens with ImageJ and > ImageMagick. It is a 8-bit RGB file. I have associated default viewer > to be ImageMagick. I am on Lucid Linux, and other programs such as F- > spot and Gimp cannot open those files either. > I don't yet know how to attach image files to the post so please bear > with me till I figure that out. Can you please post the output of tiffinfo for the specific file? It may give me a hint what's going wrong. There aren't a lot of good alternatives for image processing in Python. I've evaluated most of them and decided to write my own one for my employer. It's a Cython based library around FreeImage [1] and LCMS2 [2] and works very well. So far we have processed several million TIFF files with more than 100 TB of raw data smoothly. I've permission to release the software as open source but haven't found time to do a proper release. Christian Heimes [1] http://freeimage.sourceforge.net/ [2] http://www.littlecms.com/ From oddron at gmail.com Sun Sep 26 21:25:25 2010 From: oddron at gmail.com (Ronald Guida) Date: Sun, 26 Sep 2010 21:25:25 -0400 Subject: Python 2.7 installation problem In-Reply-To: References: Message-ID: Solved -- "make install" failed to actually install a subset of files. I had to manually copy them instead. Specifics: I started from /home/oddron/installers/python/Python-2.7/ and executed the usual commands: $ ./configure --prefix=$HOME $ make $ make install I have found that the installer failed to install the contents of "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", which contains *.so files. This explains why "import collections" would work from the built python in /home/oddron/installers/python/Python-2.7/, but would fail in the installed python in /home/oddron/bin/ . I manually copied the contents of "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", to /home/oddron/lib/python2.7/ and now everything seems to work. Thank you On Sun, Sep 26, 2010 at 2:19 AM, Ronald Guida wrote: > Hi, > > I am trying to perform a user-install of python 2.7 on Ubuntu 10.04, and my > installation is failing. > > This sequence of commands reproduces the failure on my system: > > $ tar -zxvf Python-2.7.tgz > $ cd Python-2.7/ > $ ./configure --prefix=$HOME > $ make > $ ./python Lib/test/test_collections.py > doctest (collections) ... 54 tests with zero failures > $ make altinstall > $ cd > $ which python2.7 > /home/oddron/bin/python2.7 > $ python2.7 > Python 2.7 (r27:82500, Sep 26 2010, 01:49:59) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import collections > Traceback (most recent call last): > File "", line 1, in > File "/home/oddron/lib/python2.7/collections.py", line 8, in > from _collections import deque, defaultdict > ImportError: No module named _collections > >>> import sys > >>> sys.path > ['', '/home/oddron/lib/python27.zip', '/home/oddron/lib/python2.7', > '/home/oddron/lib/python2.7/plat-linux2', > '/home/oddron/lib/python2.7/lib-tk', '/home/oddron/lib/python2.7/lib-old', > '/home/oddron/lib/python2.7/lib-dynload', > '/home/oddron/.local/lib/python2.7/site-packages', > '/home/oddron/lib/python2.7/site-packages'] > >>> > > > Things I have already checked: > * My path includes ~/bin > * None of PYTHONHOME and friends are set. > * I have also tried "make install" instead of "make altinstall", and I get > the same failure. > > Can anyone give me a hint regarding what has gone wrong? > > Thank you > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oddron at gmail.com Sun Sep 26 21:38:17 2010 From: oddron at gmail.com (Ronald Guida) Date: Sun, 26 Sep 2010 21:38:17 -0400 Subject: Python 2.7 installation problem In-Reply-To: References: Message-ID: Sorry, I have one additional piece of information that might be helpful to others. I have discovered that the *.so files that were not installed, were actually installed to the ~/lib/python2.6/ folder instead of the ~/lib/python2.7/ folder where they belong. On Sun, Sep 26, 2010 at 9:25 PM, Ronald Guida wrote: > Solved -- "make install" failed to actually install a subset of files. I > had to manually copy them instead. > > Specifics: > I started from /home/oddron/installers/python/Python-2.7/ and executed the > usual commands: > $ ./configure --prefix=$HOME > $ make > $ make install > > I have found that the installer failed to install the contents of > "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", > which contains *.so files. This explains why "import collections" would > work from > the built python in /home/oddron/installers/python/Python-2.7/, but would > fail in the installed > python in /home/oddron/bin/ . > > I manually copied the contents of > "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", > to /home/oddron/lib/python2.7/ and now everything seems to work. > > Thank you > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From flebber.crue at gmail.com Sun Sep 26 22:08:28 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 19:08:28 -0700 (PDT) Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> Message-ID: <06b51e31-4ecc-4e51-a323-3649b7dab12e@g21g2000prn.googlegroups.com> On Sep 27, 10:39?am, flebber wrote: > On Sep 27, 9:38?am, "w.g.sned... at gmail.com" > wrote: > > > > > On Sep 26, 7:10?pm, flebber wrote: > > > > I was trying to use Pypdf following a recipe from the Activestate > > > cookbooks. However I cannot get it too work. Unsure if it is me or it > > > is beacuse sets are deprecated. > > > > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > > > NET.pdf" You could use anything I was just testing with it. > > > > I was using the last script on that page that was most recently > > > updated. I am using python 2.6. > > > >http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > > > import pyPdf > > > > def getPDFContent(path): > > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > > ? ? # Load PDF into pyPDF > > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > > ? ? # Iterate pages > > > ? ? for i in range(0, pdf.getNumPages()): > > > ? ? ? ? # Extract text from page and add to content > > > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > > > ? ? # Collapse whitespace > > > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > > ? ? return content > > > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > > "ignore") > > > > This is my error. > > > > Warning (from warnings module): > > > ? File "C:\Documents and Settings\Family\Application Data\Python > > > \Python26\site-packages\pyPdf\pdf.py", line 52 > > > ? ? from sets import ImmutableSet > > > DeprecationWarning: the sets module is deprecated > > > > Traceback (most recent call last): > > > ? File "C:/Python26/Pdfread", line 15, in > > > ? ? print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > > "ignore") > > > ? File "C:/Python26/Pdfread", line 6, in getPDFContent > > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > > ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> NET.pdf' > > > Looks like a issue with finding the file. > > how do you pass the path? > > okay thanks I thought that when I set content here > > def getPDFContent(path): > ? ? content = "C:\Components-of-Dot-NET.pdf" > > that i was defining where it is. > > but yeah I updated script to below and it works. That is the contents > are displayed to the interpreter. How do I output to a .txt file? > > import pyPdf > > def getPDFContent(path): > ? ? content = "C:\Components-of-Dot-NET.pdf" > ? ? # Load PDF into pyPDF > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > ? ? # Iterate pages > ? ? for i in range(0, pdf.getNumPages()): > ? ? ? ? # Extract text from page and add to content > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > ? ? # Collapse whitespace > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > ? ? return content > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > "ignore") I have found far more advanced scripts searching around. But will have to keep trying as I cannot get an output file or specify the path. Edit very strangely whilst searching for examples I found my own post just written here ranking number 5 on google within 2 hours. Bizzare. http://www.eggheadcafe.com/software/aspnet/36237766/errors-with-pypdf.aspx Replicates our thread as thiers. I was searching ggole with "pypdf return to txt file" From flebber.crue at gmail.com Sun Sep 26 22:19:40 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 19:19:40 -0700 (PDT) Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> <06b51e31-4ecc-4e51-a323-3649b7dab12e@g21g2000prn.googlegroups.com> Message-ID: On Sep 27, 12:08?pm, flebber wrote: > On Sep 27, 10:39?am, flebber wrote: > > > > > On Sep 27, 9:38?am, "w.g.sned... at gmail.com" > > wrote: > > > > On Sep 26, 7:10?pm, flebber wrote: > > > > > I was trying to use Pypdf following a recipe from the Activestate > > > > cookbooks. However I cannot get it too work. Unsure if it is me or it > > > > is beacuse sets are deprecated. > > > > > I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > > > > NET.pdf" You could use anything I was just testing with it. > > > > > I was using the last script on that page that was most recently > > > > updated. I am using python 2.6. > > > > >http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > > > > import pyPdf > > > > > def getPDFContent(path): > > > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > > > ? ? # Load PDF into pyPDF > > > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > > > ? ? # Iterate pages > > > > ? ? for i in range(0, pdf.getNumPages()): > > > > ? ? ? ? # Extract text from page and add to content > > > > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > > > > ? ? # Collapse whitespace > > > > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > > > ? ? return content > > > > > print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > > > "ignore") > > > > > This is my error. > > > > > Warning (from warnings module): > > > > ? File "C:\Documents and Settings\Family\Application Data\Python > > > > \Python26\site-packages\pyPdf\pdf.py", line 52 > > > > ? ? from sets import ImmutableSet > > > > DeprecationWarning: the sets module is deprecated > > > > > Traceback (most recent call last): > > > > ? File "C:/Python26/Pdfread", line 15, in > > > > ? ? print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > > > > "ignore") > > > > ? File "C:/Python26/Pdfread", line 6, in getPDFContent > > > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > > > ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> NET.pdf' > > > > Looks like a issue with finding the file. > > > how do you pass the path? > > > okay thanks I thought that when I set content here > > > def getPDFContent(path): > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > > that i was defining where it is. > > > but yeah I updated script to below and it works. That is the contents > > are displayed to the interpreter. How do I output to a .txt file? > > > import pyPdf > > > def getPDFContent(path): > > ? ? content = "C:\Components-of-Dot-NET.pdf" > > ? ? # Load PDF into pyPDF > > ? ? pdf = pyPdf.PdfFileReader(file(path, "rb")) > > ? ? # Iterate pages > > ? ? for i in range(0, pdf.getNumPages()): > > ? ? ? ? # Extract text from page and add to content > > ? ? ? ? content += pdf.getPage(i).extractText() + "\n" > > ? ? # Collapse whitespace > > ? ? content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > ? ? return content > > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > I have found far more advanced scripts searching around. But will have > to keep trying as I cannot get an output file or specify the path. > > Edit very strangely whilst searching for examples I found my own post > just written here ranking number 5 on google within 2 hours. Bizzare. > > http://www.eggheadcafe.com/software/aspnet/36237766/errors-with-pypdf... > > Replicates our thread as thiers. I was searching ggole with "pypdf > return to txt file" Traceback (most recent call last): File "C:/Python26/Pdfread", line 16, in open('x.txt', 'w').write(content) NameError: name 'content' is not defined >>> When i use. import pyPdf def getPDFContent(path): content = "C:\Components-of-Dot-NET.txt" # Load PDF into pyPDF pdf = pyPdf.PdfFileReader(file(path, "rb")) # Iterate pages for i in range(0, pdf.getNumPages()): # Extract text from page and add to content content += pdf.getPage(i).extractText() + "\n" # Collapse whitespace content = " ".join(content.replace(u"\xa0", " ").strip().split()) return content print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", "ignore") open('x.txt', 'w').write(content) From python at mrabarnett.plus.com Sun Sep 26 22:49:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 27 Sep 2010 03:49:21 +0100 Subject: Errors with PyPdf In-Reply-To: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> Message-ID: <4CA00631.8090105@mrabarnett.plus.com> On 27/09/2010 01:39, flebber wrote: > On Sep 27, 9:38 am, "w.g.sned... at gmail.com" > wrote: >> On Sep 26, 7:10 pm, flebber wrote: >> >>> I was trying to use Pypdf following a recipe from the Activestate >>> cookbooks. However I cannot get it too work. Unsure if it is me or it >>> is beacuse sets are deprecated. >> >>> I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- >>> NET.pdf" You could use anything I was just testing with it. >> >>> I was using the last script on that page that was most recently >>> updated. I am using python 2.6. >> >>> http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... >> >>> import pyPdf >> >>> def getPDFContent(path): >>> content = "C:\Components-of-Dot-NET.pdf" >>> # Load PDF into pyPDF >>> pdf = pyPdf.PdfFileReader(file(path, "rb")) >>> # Iterate pages >>> for i in range(0, pdf.getNumPages()): >>> # Extract text from page and add to content >>> content += pdf.getPage(i).extractText() + "\n" >>> # Collapse whitespace >>> content = " ".join(content.replace(u"\xa0", " ").strip().split()) >>> return content >> >>> print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", >>> "ignore") >> >>> This is my error. >> >>> Warning (from warnings module): >>> File "C:\Documents and Settings\Family\Application Data\Python >>> \Python26\site-packages\pyPdf\pdf.py", line 52 >>> from sets import ImmutableSet >>> DeprecationWarning: the sets module is deprecated >> >>> Traceback (most recent call last): >>> File "C:/Python26/Pdfread", line 15, in >>> print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", >>> "ignore") >>> File "C:/Python26/Pdfread", line 6, in getPDFContent >>> pdf = pyPdf.PdfFileReader(file(path, "rb")) >> >> ---> IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> NET.pdf' >> >> Looks like a issue with finding the file. >> how do you pass the path? > > okay thanks I thought that when I set content here > > def getPDFContent(path): > content = "C:\Components-of-Dot-NET.pdf" > > that i was defining where it is. > > but yeah I updated script to below and it works. That is the contents > are displayed to the interpreter. How do I output to a .txt file? > > import pyPdf > > def getPDFContent(path): > content = "C:\Components-of-Dot-NET.pdf" That simply binds to a local name; 'content' is a local variable in the function 'getPDFContent'. > # Load PDF into pyPDF > pdf = pyPdf.PdfFileReader(file(path, "rb")) You're opening a file whose path is in 'path'. > # Iterate pages > for i in range(0, pdf.getNumPages()): > # Extract text from page and add to content > content += pdf.getPage(i).extractText() + "\n" That appends to 'content'. > # Collapse whitespace 'content' now contains the text of the PDF, starting with r"C:\Components-of-Dot-NET.pdf". > content = " ".join(content.replace(u"\xa0", " ").strip().split()) > return content > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > Outputting to a .txt file is simple: open the file for writing using 'open', write the string to it, and then close it. From flebber.crue at gmail.com Sun Sep 26 22:56:40 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Sep 2010 19:56:40 -0700 (PDT) Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> Message-ID: On Sep 27, 12:49?pm, MRAB wrote: > On 27/09/2010 01:39, flebber wrote: > > > > > On Sep 27, 9:38 am, "w.g.sned... at gmail.com" > > wrote: > >> On Sep 26, 7:10 pm, flebber ?wrote: > > >>> I was trying to use Pypdf following a recipe from the Activestate > >>> cookbooks. However I cannot get it too work. Unsure if it is me or it > >>> is beacuse sets are deprecated. > > >>> I have placed a pdf in my C:\ drive. it is called "Components-of-Dot- > >>> NET.pdf" You could use anything I was just testing with it. > > >>> I was using the last script on that page that was most recently > >>> updated. I am using python 2.6. > > >>>http://code.activestate.com/recipes/511465-pure-python-pdf-to-text-co... > > >>> import pyPdf > > >>> def getPDFContent(path): > >>> ? ? ?content = "C:\Components-of-Dot-NET.pdf" > >>> ? ? ?# Load PDF into pyPDF > >>> ? ? ?pdf = pyPdf.PdfFileReader(file(path, "rb")) > >>> ? ? ?# Iterate pages > >>> ? ? ?for i in range(0, pdf.getNumPages()): > >>> ? ? ? ? ?# Extract text from page and add to content > >>> ? ? ? ? ?content += pdf.getPage(i).extractText() + "\n" > >>> ? ? ?# Collapse whitespace > >>> ? ? ?content = " ".join(content.replace(u"\xa0", " ").strip().split()) > >>> ? ? ?return content > > >>> print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > >>> "ignore") > > >>> This is my error. > > >>> Warning (from warnings module): > >>> ? ?File "C:\Documents and Settings\Family\Application Data\Python > >>> \Python26\site-packages\pyPdf\pdf.py", line 52 > >>> ? ? ?from sets import ImmutableSet > >>> DeprecationWarning: the sets module is deprecated > > >>> Traceback (most recent call last): > >>> ? ?File "C:/Python26/Pdfread", line 15, in > >>> ? ? ?print getPDFContent("Components-of-Dot-NET.pdf").encode("ascii", > >>> "ignore") > >>> ? ?File "C:/Python26/Pdfread", line 6, in getPDFContent > >>> ? ? ?pdf = pyPdf.PdfFileReader(file(path, "rb")) > > >> ---> ?IOError: [Errno 2] No such file or directory: 'Components-of-Dot-> ?NET.pdf' > > >> Looks like a issue with finding the file. > >> how do you pass the path? > > > okay thanks I thought that when I set content here > > > def getPDFContent(path): > > ? ? ?content = "C:\Components-of-Dot-NET.pdf" > > > that i was defining where it is. > > > but yeah I updated script to below and it works. That is the contents > > are displayed to the interpreter. How do I output to a .txt file? > > > import pyPdf > > > def getPDFContent(path): > > ? ? ?content = "C:\Components-of-Dot-NET.pdf" > > That simply binds to a local name; 'content' is a local variable in the > function 'getPDFContent'. > > > ? ? ?# Load PDF into pyPDF > > ? ? ?pdf = pyPdf.PdfFileReader(file(path, "rb")) > > You're opening a file whose path is in 'path'. > > > ? ? ?# Iterate pages > > ? ? ?for i in range(0, pdf.getNumPages()): > > ? ? ? ? ?# Extract text from page and add to content > > ? ? ? ? ?content += pdf.getPage(i).extractText() + "\n" > > That appends to 'content'. > > > ? ? ?# Collapse whitespace > > 'content' now contains the text of the PDF, starting with > r"C:\Components-of-Dot-NET.pdf". > > > ? ? ?content = " ".join(content.replace(u"\xa0", " ").strip().split()) > > ? ? ?return content > > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > Outputting to a .txt file is simple: open the file for writing using > 'open', write the string to it, and then close it. Thats what I was trying to do with open('x.txt', 'w').write(content) the rest of the script works it wont output the tect though From timr at probo.com Sun Sep 26 23:12:14 2010 From: timr at probo.com (Tim Roberts) Date: Sun, 26 Sep 2010 20:12:14 -0700 Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> Message-ID: flebber wrote: > >okay thanks I thought that when I set content here > >def getPDFContent(path): > content = "C:\Components-of-Dot-NET.pdf" You have a backslash problem here. You need need to say: content = "C:\\Components-of-Dot-NET.pdf" or content = "C:/Components-of-Dot-NET.pdf" or content = "C:/Components-of-Dot-NET.pdf" -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From research at johnohagan.com Sun Sep 26 23:41:13 2010 From: research at johnohagan.com (John O'Hagan) Date: Mon, 27 Sep 2010 03:41:13 +0000 Subject: Calling an arbitrary function with the right arguments Message-ID: <201009270341.14372.research@johnohagan.com> How to call a function with the right arguments without knowing in advance which function? For example: import random def f1(): pass def f2(foo): pass def f3(foo, bar): pass foo=random.choice((1,2,3)) bar=random.choice((1,2,3)) myfunc=random.choice((f1, f2, f3)) How to call myfunc with the right arguments? I've been doing it this way: f1.args=() f2.args=('foo',) f3.args=('foo', 'bar') args=[vars()[i] for i in myfunc.args] myfunc(*args) But it seems redundant to manually tag the functions with their own arguments' names, and I don't like using vars(). Is there a nicer pattern? Regards, John From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 00:10:46 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 27 Sep 2010 04:10:46 GMT Subject: Calling an arbitrary function with the right arguments References: Message-ID: <4ca01946$0$28670$c3e8da3@news.astraweb.com> On Mon, 27 Sep 2010 03:41:13 +0000, John O'Hagan wrote: > How to call a function with the right arguments without knowing in > advance which function? For example: > > import random > > def f1(): > pass > > def f2(foo): > pass > > def f3(foo, bar): > pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) > > myfunc=random.choice((f1, f2, f3)) > > How to call myfunc with the right arguments? If f1, f2 and f3 require different arguments, it's not sensible to expect them to be interchangeable. The right way to do this is to re-write the functions so they all have the same call signature (even if that is just to ignore unnecessary arguments). Or wrap the functions (perhaps using functools.partial) so they don't need the extra args. f3 = lambda f=f3: f(foo, bar) f2 = lambda f=f2: f(foo) Either way, there's a reason you never see callback functions that accept arbitrary arguments. They always have a standard, fixed argument list. -- Steven From clp2 at rebertia.com Mon Sep 27 00:19:23 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 26 Sep 2010 21:19:23 -0700 Subject: Calling an arbitrary function with the right arguments In-Reply-To: <201009270341.14372.research@johnohagan.com> References: <201009270341.14372.research@johnohagan.com> Message-ID: On Sun, Sep 26, 2010 at 8:41 PM, John O'Hagan wrote: > How to call a function with the right arguments without knowing in advance > which function? For example: > > import random > > def f1(): > ? ?pass > > def f2(foo): > ? ?pass > > def f3(foo, bar): > ? ?pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) > > myfunc=random.choice((f1, f2, f3)) > > How to call myfunc with the right arguments? > I've been doing it this way: > > f1.args=() > f2.args=('foo',) > f3.args=('foo', 'bar') > > args=[vars()[i] for i in myfunc.args] > > myfunc(*args) > > But it seems redundant to manually tag the functions with their own arguments' > names, and I don't like using vars(). Is there a nicer pattern? Yes; as Steven said, just define the functions so they all have the same signature in the first place and simply ignore any inapplicable arguments. However, alternatively, you could use inspect.getargspec() (http://docs.python.org/library/inspect.html#inspect.getargspec ) to figure out what arguments each functions needs. I do not actually recommend this method, but merely mention it for completeness. Cheers, Chris -- http://blog.rebertia.com From rplasson at gmail.com Mon Sep 27 00:20:56 2010 From: rplasson at gmail.com (=?ISO-8859-1?Q?Rapha=EBl_Plasson?=) Date: Sun, 26 Sep 2010 21:20:56 -0700 (PDT) Subject: Simple interface to minidom for creating XML files Message-ID: <2c6116b4-1c7d-4afa-b9a0-38ef6787c446@y32g2000prc.googlegroups.com> Hello, I want to create some XML files, following a simple template. For that purpose, I created a simple interface to minidom. This is simple code, but as I spend a little time for understanding how minidom was working, I thought that this may be useful for someone (not that minidom is complex, but even if simplified from the full XML implementation, it still possesses too many functions for what I simply wanted to do). What you have to do is just to import the class doc, and then: In [258]: xml=doc("toto") In [259]: xml["part1"]=None In [260]: xml["part1"]["1.1"]="coucou" In [261]: xml["part1"]["1.2"]="toto" In [262]: xml["part1"]["1.2"]["1.2.1"]="a" In [263]: xml["part1"]["1.2"]["1.2.2"]="b" In [264]: xml["part2"]="That's all folks!" In [265]: xml["part1"]["1.2"]["1.2.2"]="really b" In [266]: xml["part1"]["cdata"]="This is\nMore complex data\n:-p\n" In [267]: xml.write("test.xml") is sufficient to obtain the following file: <1.1> coucou <1.2> toto <1.2.1> a <1.2.2> really b That's all folks! This piece of code is way too small for being considered as a real package, but it may help someone. Thus, I am just posting it here so that it doesn't get lost. Please feel free to use it and extend it as will (I put a GPL licence in that purpose). If you have some comments/suggestion about this code, I would also be happy to discuss about it :). Rapha?l Here is the code: 8x----------------------------------------------------------------------- x8 # Copyright 2010 Raphael Plasson, rplasson_at_gmail_dot_com # # This program is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from xml.dom.minidom import Document class node: def __init__(self,name,parent,doc): '''Add a node called to the document inside the node ''' self.name=name self.parent=parent self.doc=doc self.element=self.doc.createElement(self.name) self.parent.element.appendChild(self.element) self.children={} def __getitem__(self,key): return self.children[key] def __setitem__(self,key,val): if key=="text": self.set_text(val) elif key=="cdata": self.set_cdata(val) else: tmp=self.set_node(key) if val != None: tmp.set_text(val) def __repr__(self): tmp=self.name+" : " for i in self.children: tmp += i+", " return tmp def __newchild(self,child,name): self.children[name] = child def set_node(self,name): '''Add a node . If a node with the same name already exists, it is simply returned.''' if self.children.has_key(name): return self.children[name] else: tmp=node(name,self,self.doc) self.__newchild(tmp,name) return tmp def set_text(self,text): '''Add or update the node text ''' if self.children.has_key("text"): self.children["text"].data=text else: tmp=self.doc.createTextNode(text) self.__newchild(tmp,"text") self.element.appendChild(tmp) def set_cdata(self,cdata): '''Add or update the node cdata ''' if self.children.has_key("cdata"): self.children["cdata"].data=cdata else: tmp=self.doc.createCDATASection(cdata) self.__newchild(tmp,"cdata") self.element.appendChild(tmp) self.element.appendChild(self.doc.createTextNode("")) # dirty hack for adding newline after CDATA in file def set_attr(self,attr,val): '''Add or set the attribute to ''' self.element.setAttribute(attr,val) def comment(self,comm): '''Add the comment ''' self.element.appendChild(self.doc.createComment(comm)) class doc(node): def __init__(self,name): ''' Create an xml document, with root node ''' self.name=name self.parent=None self.doc=Document() self.element=self.doc.createElement(self.name) self.doc.appendChild(self.element) self.children={} self.text="" def write(self,filename): ''' Write the xml document to ''' out=file(filename,"w") self.doc.writexml(out, newl="\n", addindent=" ") out.close() 8x----------------------------------------------------------------------- x8 From davea at ieee.org Mon Sep 27 00:46:18 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 27 Sep 2010 00:46:18 -0400 Subject: Errors with PyPdf In-Reply-To: References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> <06b51e31-4ecc-4e51-a323-3649b7dab12e@g21g2000prn.googlegroups.com> Message-ID: <4CA0219A.2030601@ieee.org> On 2:59 PM, flebber wrote: > > Traceback (most recent call last): > File "C:/Python26/Pdfread", line 16, in > open('x.txt', 'w').write(content) > NameError: name 'content' is not defined > When i use. > > import pyPdf > > def getPDFContent(path): > content =C:\Components-of-Dot-NET.txt" > # Load PDF into pyPDF > pdf =yPdf.PdfFileReader(file(path, "rb")) > # Iterate pages > for i in range(0, pdf.getNumPages()): > # Extract text from page and add to content > content +=df.getPage(i).extractText() + "\n" > # Collapse whitespace > content = ".join(content.replace(u"\xa0", " ").strip().split()) > return content > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > open('x.txt', 'w').write(content) > There's no global variable content, that was local to the function. So it's lost when the function exits. it does return the value, but you give it to print, and don't save it anywhere. data = getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", "ignore") outfile = open('x.txt', 'w') outfile.write(data) close(outfile) I used a different name to emphasize that this is *not* the same variable as content inside the function. In this case, it happens to have the same value. And if you used the same name, you could be confused about which is which. DaveA From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 00:46:30 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 27 Sep 2010 04:46:30 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: <4ca021a6$0$28670$c3e8da3@news.astraweb.com> On Sun, 26 Sep 2010 01:16:49 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? The first one would be a reasonable design choice, although less useful than what Python does. Instead of: rule = "="*12 you would need to write: rule = ''.join("="*12) which is a pain. The second one is just a lousy design. If you ask for three sheep, you expect three sheep, not three sheep heads, plus three sheep tails, plus three sheep left-front legs, plus... "ssspppaaammm" fails the Principle of Least Surprise. For any positive n, you would expect: "spam" in ("spam"*n) to return True. "ssspppaaammm" fails this test. > Should "spam"*2.5 be "spamspamsp"? Trying to determine a fraction of a string is troublesome... what is 1/100th of "abcde"? Some fraction of the letter "a"? What does that even mean? The question has no sensible answer, in the same way that asking for the real-valued square-root of -1 has no sensible answer. Unlike real numbers, which are easily extended to complex values, there's no obvious extension of strings to include fractions of characters. So the only sensible thing is to say that fractions of strings doesn't have any meaning. When faced with "spam"*2.5, you can either raise an exception (as Python does), or truncate the second argument to an integer value. Which you do is a matter of taste, although I'd argue in favour of truncation. > Should "spam"-"a" be "spm"? What about "spamspam"-"a"? And what about > "spam"/2? "sp" be an ok first guess, but "sa" might make more sense (it > means (1,2,3,...)/2 would be (1,3,5...)). What makes you think that "spam" - "a" should be anything at all? Just because an operator exists doesn't mean it *has* to be defined for every possible data set. You're over-thinking this. Repetition of sequences is simple and straight-forward. Trying to come up with complicated analogues to arbitrary real-number operators is a waste of time and effort. That is exactly the sort of nonsense that I already agreed should be avoided. -- Steven From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 01:17:27 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 27 Sep 2010 05:17:27 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4ca028e6$0$28670$c3e8da3@news.astraweb.com> On Sun, 26 Sep 2010 09:30:08 +0000, Seebs wrote: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", >> and the fact that it doesn't do the same thing as int("spam")*3 is a >> foolish argument. > > The languages in which it's surprising are mostly things like perl, > where there's a certain amount of implicit coercion going on, so it's > ambiguous whether "3"*3 ought to mean "333" or 9. (Except it isn't, > because repetition is a separate operator, written "3" x 3 rather than > "3" * 3...) People coming from that kind of background may be expecting > * to stay an arithmetic operator, rather than having it change form when > applied to non-arithmetic objects. And people with no programming background at all will be surprised that * and x aren't two different symbols for the same operation. > I'm not sure either way. I think on the whole, I like the notion of a > repetition operator which is distinct from multiplication, but I also > definitely prefer the lack of implicit coercion, and without implicit > coercion, there's a lot less underlying ambiguity to worry about. > > From the top, I guess my analysis is: > > * It seems clear that, given two sequences x and y, "x + y" ought to > be the concatenation of these sequences. > * Thus, "x + x" should be x concatenated to itself. * Idiomatically, it > is not unreasonable to assert that "x * 2" and "x + x" > could be the same value. > * It thus makes some sense for * to indicate > repetition of the sequence. > * Since a string is a kind of a sequence, it also makes sense for > * to indicate repetition. My analysis as well, except that I see repetition (repeated concatenation/ addition) as more fundamental than multiplication. Think about being back in primary school, where you learn to do this: 21 21 +21 ---- 63 before you learned this: 21 x3 ---- 63 > So I think I'm pretty much convinced that Python's behavior makes sense, > but it makes sense only because I'm going into this expecting operators > to be defined by types, so I don't expect every '*' to mean > 'multiplication'. Perhaps you should say "real-valued multiplication" rather than just multiplication, because of course matrix multiplication A*B behaves quite differently from integer multiplication a*b as well. > Helps, perhaps, that I got exposed to group theory early enough to be > used to redefining + and * to be any two operations which have > interesting properties*. > > -s > [*] What's purple and commutes? An abelian grape. Heh :) -- Steven From farkmor at gmail.com Mon Sep 27 02:56:11 2010 From: farkmor at gmail.com (Tim Diels) Date: Mon, 27 Sep 2010 08:56:11 +0200 Subject: Python3: API Documentation generator Message-ID: <4CA0400B.7000405@gmail.com> Hi all I've just switched to python3 and it turns out my current API documentation generator (epydoc) no longer works. I am looking for a tool that reads the docstrings of all classes, ... in my project and turns it into HTML documentation. Thanks for your time limyreth From clp2 at rebertia.com Mon Sep 27 03:02:03 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 27 Sep 2010 00:02:03 -0700 Subject: Python3: API Documentation generator In-Reply-To: <4CA0400B.7000405@gmail.com> References: <4CA0400B.7000405@gmail.com> Message-ID: On Sun, Sep 26, 2010 at 11:56 PM, Tim Diels wrote: > ?Hi all > > I've just switched to python3 and it turns out my current API documentation > generator (epydoc) no longer works. I am looking for a tool that reads the > docstrings of all classes, ... in my project and turns it into HTML > documentation. Sphinx (http://sphinx.pocoo.org/ ) is the new gold standard. You'll want to enable the `autodoc` extension: http://sphinx.pocoo.org/ext/autodoc.html Cheers, Chris -- http://blog.rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Mon Sep 27 04:19:19 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 27 Sep 2010 10:19:19 +0200 Subject: Calling an arbitrary function with the right arguments In-Reply-To: References: Message-ID: <4ca05388$0$23138$426a74cc@news.free.fr> John O'Hagan a ?crit : > How to call a function with the right arguments without knowing in advance > which function? (snip) For most use case I can think of, I can only second Steven and Chris - if your functions are interchangeable then they should have a same API. Now there's at least one use case I know where you need to dynamically select a function then build the right arguments set for it: when mapping urls to http request handler functions. There's a good example in Django's url to "view" mapping system. From __peter__ at web.de Mon Sep 27 04:42:02 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 27 Sep 2010 10:42:02 +0200 Subject: Calling an arbitrary function with the right arguments References: Message-ID: John O'Hagan wrote: > How to call a function with the right arguments without knowing in advance > which function? For example: > > import random > > def f1(): > pass > > def f2(foo): > pass > > def f3(foo, bar): > pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) > > myfunc=random.choice((f1, f2, f3)) > > How to call myfunc with the right arguments? > I've been doing it this way: > > f1.args=() > f2.args=('foo',) > f3.args=('foo', 'bar') > > args=[vars()[i] for i in myfunc.args] > > myfunc(*args) > > But it seems redundant to manually tag the functions with their own > arguments' names, and I don't like using vars(). Is there a nicer pattern? You can use inspect.getargspec() to determine the argument names: args = [vars()[argname] for argname in inspect.getargspec(myfunc).args] From jeanmichel at sequans.com Mon Sep 27 05:08:05 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 27 Sep 2010 11:08:05 +0200 Subject: Calling an arbitrary function with the right arguments In-Reply-To: <201009270341.14372.research@johnohagan.com> References: <201009270341.14372.research@johnohagan.com> Message-ID: <4CA05EF5.4040507@sequans.com> John O'Hagan wrote: > How to call a function with the right arguments without knowing in advance > which function? For example: > > import random > > def f1(): > pass > > def f2(foo): > pass > > def f3(foo, bar): > pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) > > myfunc=random.choice((f1, f2, f3)) > > How to call myfunc with the right arguments? > I've been doing it this way: > > f1.args=() > f2.args=('foo',) > f3.args=('foo', 'bar') > > args=[vars()[i] for i in myfunc.args] > > myfunc(*args) > > But it seems redundant to manually tag the functions with their own arguments' > names, and I don't like using vars(). Is there a nicer pattern? > > Regards, > > John > > Hi, func, args = random.choice(((f1, ()), (f2, (foo,)), (f3, (foo, bar)))) func(*args) JM From alexxx.magni at gmail.com Mon Sep 27 05:23:12 2010 From: alexxx.magni at gmail.com (Alessandro) Date: Mon, 27 Sep 2010 02:23:12 -0700 (PDT) Subject: check path.exists() with a "converted" path Message-ID: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Hi, I'm a python newbie with a problem too hard to tackle. I have a string defining a path, were all the spaces have been converted to underscores. How can I find if it corresponds to a real path? e.g. a string like '/some/path_to/directory_1/and_to/directory_2' with a real path: '/some/path_to/directory 1/and_to/directory 2' notice that the real path can contain BOTH spaces and underscores. How can I feed it to os.path.exists() ??? thanks alessandro From clp2 at rebertia.com Mon Sep 27 05:35:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 27 Sep 2010 02:35:24 -0700 Subject: check path.exists() with a "converted" path In-Reply-To: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: On Mon, Sep 27, 2010 at 2:23 AM, Alessandro wrote: > Hi, I'm a python newbie with a problem too hard to tackle. > > I have a string defining a path, were all the spaces have been > converted to underscores. > How can I find if it corresponds to a real path? > > e.g. a string like '/some/path_to/directory_1/and_to/directory_2' > with a real path: '/some/path_to/directory 1/and_to/directory 2' > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ??? Use the `glob` module instead: http://docs.python.org/library/glob.html from glob import glob real_paths = glob(underscored_path.replace('_','[_ ]')) #note: it's possible for there to be multiple matches Cheers, Chris -- http://blog.rebertia.com From paul.nospam at rudin.co.uk Mon Sep 27 05:35:44 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 27 Sep 2010 10:35:44 +0100 Subject: check path.exists() with a "converted" path References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: <87tylbfs0f.fsf@rudin.co.uk> Alessandro writes: > Hi, I'm a python newbie with a problem too hard to tackle. > > I have a string defining a path, were all the spaces have been > converted to underscores. > How can I find if it corresponds to a real path? > > e.g. a string like '/some/path_to/directory_1/and_to/directory_2' > with a real path: '/some/path_to/directory 1/and_to/directory 2' > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ??? If you just have the converted string then you can't know what the original string is, you have no way of knowing which underscores were actually underscores in the original and which where spaces. You could generate all possible candidate original strings and check for file existence, but in general there are many different original strings that will yield the same converted string, possibly more than one of those corresponds to a file that exists. From __peter__ at web.de Mon Sep 27 05:43:49 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 27 Sep 2010 11:43:49 +0200 Subject: check path.exists() with a "converted" path References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: Alessandro wrote: > Hi, I'm a python newbie with a problem too hard to tackle. > > I have a string defining a path, were all the spaces have been > converted to underscores. > How can I find if it corresponds to a real path? > > e.g. a string like '/some/path_to/directory_1/and_to/directory_2' > with a real path: '/some/path_to/directory 1/and_to/directory 2' > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ??? $ mkdir -p aa{\ ,_}aa/bb{\ ,_}b{\ ,_}/c\ c $ tree . |-- aa aa | |-- bb b | | `-- c c | |-- bb b_ | | `-- c c | |-- bb_b | | `-- c c | `-- bb_b_ | `-- c c `-- aa_aa |-- bb b | `-- c c |-- bb b_ | `-- c c |-- bb_b | `-- c c `-- bb_b_ `-- c c 18 directories, 0 files $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import glob >>> path = "aa_aa/bb_b_/c_c" >>> glob.glob(path.replace("_", "[_ ]")) ['aa_aa/bb b_/c c', 'aa_aa/bb_b /c c', 'aa_aa/bb b /c c', 'aa_aa/bb_b_/c c', 'aa aa/bb b_/c c', 'aa aa/bb_b /c c', 'aa aa/bb b /c c', 'aa aa/bb_b_/c c'] I didn't want to throw away my demo just because your question was already anwered ;) Peter From rplasson at gmail.com Mon Sep 27 05:46:08 2010 From: rplasson at gmail.com (=?ISO-8859-1?Q?Rapha=EBl_Plasson?=) Date: Mon, 27 Sep 2010 02:46:08 -0700 (PDT) Subject: check path.exists() with a "converted" path References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: On Sep 27, 6:23?pm, Alessandro wrote: > > I have a string defining a path, were all the spaces have been > converted to underscores. > (...) > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ??? You are losing some information, there is no other choice to test all the combinations. Something like this should do the trick (/!\ quick and dirty solution /!\) def testpath(path): tmp=path.split("_") for i in range(2**(len(tmp)-1)): res="" for j in range(len(tmp)): if j>0: if (i & 2**(j-1))==0: res += " " else: res += "_" res+=tmp[j] if os.path.exists(res): return True return False Raphael From alexxx.magni at gmail.com Mon Sep 27 05:51:07 2010 From: alexxx.magni at gmail.com (Alessandro) Date: Mon, 27 Sep 2010 02:51:07 -0700 (PDT) Subject: check path.exists() with a "converted" path References: <14ddd23a-0870-46c9-bb51-c145acba53f7@t20g2000yqa.googlegroups.com> Message-ID: people, you're great - best newsgroup I've ever been! I think I'll go with the glob suggestion - works like a charm!!! thank you... alessandro From matth at netsight.co.uk Mon Sep 27 06:48:46 2010 From: matth at netsight.co.uk (Matt Hamilton) Date: Mon, 27 Sep 2010 10:48:46 +0000 (UTC) Subject: Plone Conference 2010 schedule published Message-ID: Over 400 attendees are set to meet at the 8th annual Plone Conference for a week-long programme of training, talks and developer sprints from the 25th to 31st October at the Thistle Grand Hotel in Bristol, UK. Plone Conference 2010 registrations are open. Plone, an Open Source Content Management System used throughout the world has a massive following and Plone events are held around the globe. The largest of these is the annual Plone Conference and this year will be held in the UK. Plone is used for developing websites, intranet and portals for corporations, NGOs and the public sector. Organised by Netsight Internet Solutions, it promises to bring together developers, designers, end users and business people. This year an additional event is being planned as a one-day mini-conference on the 26th October called "Plone in Business" which will be aimed specifically at analysts, advisors, evaluators and information professionals looking to find out more about Plone and see a showcase of successful Plone projects from across the sectors. It will also see the launch of the JBoye Plone Community of Practice. The main part of the conference, from the 27th - 29th October, has over 50 scheduled talks from speakers from 19 countries and includes an 'unconference' day in which talks will be proposed by the attendees. Plone Conference 2010 scheduled talks include: * Easier and faster Plone theming with Deliverance * Design and Development with Dexterity * Enterprise Search in Plone with Solr * Boosting productivity with "Plone-driven Plone development" * Brasil.gov.br: Building a digital nation with Plone Alan Runyan, co-founder of Plone and president of Enfold Systems along with Alex Limi, fellow co-founder of Plone and now Firefox User Experience Lead at Mozilla will be delivering a keynote. There will also be a guest keynote by Richard Noble, OBE, project director of the Bloodhound SSC project attempting be build a car to pass the 1,000mph land speed mark. The conference falls at a great time, with the recent release of Plone 4, a product that raises the bar in the Content Management System market with a faster, more user-friendly and more refined version of the product. So far, registrations for the conference have come from over 30 countries around the world. To find out more about the conference and to register, visit http://ploneconf2010.org. -- Matt Hamilton matth at netsight.co.uk Netsight Internet Solutions, Ltd. Business Vision on the Internet http://www.netsight.co.uk +44 (0)117 9090901 Web Design | Zope/Plone Development and Consulting | Co-location | Hosting From Antoon.Pardon at rece.vub.ac.be Mon Sep 27 07:07:49 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 27 Sep 2010 13:07:49 +0200 Subject: Too much code - slicing In-Reply-To: <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> References: <4c97f72b$0$28658$c3e8da3@news.astraweb.com> <4c9a9df9$0$11123$c3e8da3@news.astraweb.com> Message-ID: <20100927110749.GB2272@rcpc42.vub.ac.be> On Thu, Sep 23, 2010 at 12:23:22AM +0000, Steven D'Aprano wrote: > On Tue, 21 Sep 2010 16:17:48 +0200, Antoon Pardon wrote: > > > On Tue, Sep 21, 2010 at 12:07:07AM +0000, Steven D'Aprano wrote: > >> On Mon, 20 Sep 2010 19:28:49 +0200, Antoon Pardon wrote: > >> > >> > Not necessarily. Some of us have the impression that Guido > >> > deliberatly chose an ugly format for the ternary operator. > >> > >> If he did, then he must have changed his mind, because there is nothing > >> ugly about the ternary operator we ended up with. > > > > That is a question of taste > > Yes, it certainly is. Describing it as "an ugly format" is also a matter > of taste -- taste which in my opinion simply isn't justified by anything > other than familiarity. There is the facts that it broke familiarity with a common pattern. > > This form only ranked fourth (or maybe third), with the first three all > > wanting ar structure with the elelement is this order: condition, true > > case, false case > > > >> > Guido has alwasys been > >> > against a ternary operator but the requests kept coming. So > >> > eventually he introduced one. But the impression is that he chose an > >> > ugly format in the hope of discouraging people to use it. > >> > >> That's sheer and unadulterated nonsense. The fact is that Guido changed > >> his mind about ternary if after discovering that the work-around > >> > >> true-clause and condition or false-clause > >> > >> is buggy -- it gives the wrong answer if true-clause happens to be a > >> false value like [], 0 or None. If I recall correctly, the bug bit > >> Guido himself. > > > > Nonsense. That the work around was buggy was known years before the > > ternary operator was finally introduced. > > But people kept forgetting it, and it bit the right person one time too > many. So? That it took years between the knowledge that the work-around failed and a ternary operator finally appearing is still a fact. Which casts doubts that is was this knowledge that made him change his mind. > > The introduction of list > > comprehension made a ternary operator that more usefull but every time > > it came up the supporters of Guido, told us we just had to define a > > function if we wanted the items to depend on a condition. > > A function can't do the job, because it isn't lazy: > > def ifte(condition, x, y): > if condition: return x > else: return y > > n = 0 > ifte(n != 0, 100/n, -1) > > will fail. This was perhaps *the* killer argument for a ternary-if > operator. You really don't seem to remember what happened then. Someone would come with a problem that we can now solve as follows. ls = [ el / 2 if el % 2 == 0 else 3 * el + 1 for el in ls ] and the respons would be that we just needed to write is as follows: def f(el): if el % 2 == 0: return el / 2 else: return 3 * el + 1 ls = [ f(el) for el in ls ] -- Antoon Pardon From dsdale24 at gmail.com Mon Sep 27 09:21:49 2010 From: dsdale24 at gmail.com (Darren Dale) Date: Mon, 27 Sep 2010 06:21:49 -0700 (PDT) Subject: possible circular import problem with python-3, but not python-2 Message-ID: <1c6985e5-26ef-489b-bb4a-0e8d9717d3b5@z28g2000yqh.googlegroups.com> I am attempting to contribute to the h5py project by porting the code for python-3. The code is available in a branch at github: http://github.com/darrendale/h5py/tree/py3k . That code uses cython to wrap the hdf5 library. So far, only a few minor changes have been needed (relative imports, changes concerning strings/bytes), and I have been able to generate the c sources, build and install h5py for py3k. But I can't actually import the library. On Snow Leopard, using the python-3 installed via MacPorts: >>> import h5py Traceback (most recent call last): File "", line 1, in File "/Users/darren/.local/lib/python3.1/site-packages/ h5py-1.3.1.dev-py3.1-macosx-10.6-x86_64.egg/h5py/__init__.py", line 34, in from . import h5, h5a, h5d, h5f, h5fd, h5g, h5l, h5o, h5i, h5p, h5r, h5s, h5t, h5z File "h5t.pxd", line 17, in init h5py.h5a (h5py/h5a.c:5248) File "h5p.pxd", line 23, in init h5py.h5t (h5py/h5t.c:16481) File "h5t.pxd", line 17, in init h5py.h5p (h5py/h5p.c:9297) ImportError: No module named h5t That looks like it might be a circular import problem, but it works fine with python-2.6. I'm at a loss on how to proceed, could anyone please offer a suggestion? Thanks, Darren From flebber.crue at gmail.com Mon Sep 27 10:19:34 2010 From: flebber.crue at gmail.com (flebber) Date: Mon, 27 Sep 2010 07:19:34 -0700 (PDT) Subject: Errors with PyPdf References: <61f95754-36f2-4e60-a506-4c4f59d44ea6@c28g2000prj.googlegroups.com> <06b51e31-4ecc-4e51-a323-3649b7dab12e@g21g2000prn.googlegroups.com> Message-ID: <5fa8234c-fe73-4a49-a714-a6777116e806@u4g2000prn.googlegroups.com> On Sep 27, 2:46?pm, Dave Angel wrote: > On 2:59 PM, flebber wrote: > > > > > Traceback (most recent call last): > > ? ?File "C:/Python26/Pdfread", line 16, in > > ? ? ?open('x.txt', 'w').write(content) > > NameError: name 'content' is not defined > > When i use. > > > import pyPdf > > > def getPDFContent(path): > > ? ? ?content =C:\Components-of-Dot-NET.txt" > > ? ? ?# Load PDF into pyPDF > > ? ? ?pdf =yPdf.PdfFileReader(file(path, "rb")) > > ? ? ?# Iterate pages > > ? ? ?for i in range(0, pdf.getNumPages()): > > ? ? ? ? ?# Extract text from page and add to content > > ? ? ? ? ?content +=df.getPage(i).extractText() + "\n" > > ? ? ?# Collapse whitespace > > ? ? ?content = ".join(content.replace(u"\xa0", " ").strip().split()) > > ? ? ?return content > > > print getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > > "ignore") > > open('x.txt', 'w').write(content) > > There's no global variable content, that was local to the function. ?So > it's lost when the function exits. ?it does return the value, but you > give it to print, and don't save it anywhere. > > data = getPDFContent(r"C:\Components-of-Dot-NET.pdf").encode("ascii", > "ignore") > > outfile = open('x.txt', 'w') > outfile.write(data) > > close(outfile) > > I used a different name to emphasize that this is *not* the same > variable as content inside the function. ?In this case, it happens to > have the same value. ?And if you used the same name, you could be > confused about which is which. > > DaveA Thank You everyone. From xrgtn at yandex.ru Mon Sep 27 10:28:29 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Mon, 27 Sep 2010 17:28:29 +0300 Subject: Raw Sockets - IP-Encapsulation In-Reply-To: References: Message-ID: <20100927142829.GG11974@xrgtn-q40> Hello, On Fri, Sep 24, 2010 at 04:51:01PM +0100, Nobody wrote: > On Thu, 23 Sep 2010 21:41:19 +0200, Matthias > Guentert wrote: > > I would like to create an IP tunnel using the > > IP protocol type 4 (socket.IPPROTO_IPIP) on a > > Linux host. (I also would be happy if I could > > create a GRE tunnel) > > > > The thing is, I just don't understand how I > > such a socket could be created and then later > > on handled. > > You don't create sockets for IPPROTO_IPIP or > IPPROTO_GRE. Outside of the kernel, those > identifiers are only likely to be used for > specifying protocols when e.g. configuring > packet filtering. > > Tunnelling only involves user-space for > configuration. For GRE/IPIP this is true, but with /dev/tun and /dev/tap tunnels it isn't -- userspace program actually reads from/writes to tun/tap device file descriptor. -- With best regards, xrgtn From darragh.ssa at gmail.com Mon Sep 27 11:07:38 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Mon, 27 Sep 2010 08:07:38 -0700 (PDT) Subject: minimal D: need software testers Message-ID: <43bd55e3-e924-40b5-a157-b57ac8544b5f@f25g2000yqc.googlegroups.com> Hey, I've released the second alpha for minimal-D a program I've written in python which should make developing easier. I need people to test the app on bugs and give ideas. It is written in python using the wxPython toolkit and is linux-only. (using on windows is on own risk) You can download a .deb or a .tar.gz from http://launchpad.net/minimal From mirko.vukovic at gmail.com Mon Sep 27 11:18:22 2010 From: mirko.vukovic at gmail.com (Mirko) Date: Mon, 27 Sep 2010 08:18:22 -0700 (PDT) Subject: reduced-tagged (was Re: toy list processing problem: collect similar terms) References: Message-ID: <8e54fd9c-1d6b-433c-b306-288a7341bc98@a36g2000yqc.googlegroups.com> On Sep 26, 12:05?am, Xah Lee wrote: I am hijacking the following post and driving it to Cuba (the Monthy Python fans will know what I refer to). I want to create a `reduce'- like function that can handle similar problems. Xah said: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > stuffed deleted. Here is my Common Lisp (and I only care about Common Lisp answers) attempt to create a `reduce'-like function to handle this kind of a problem (you will see that I am still struggling with the code and the documentation). (defun reduce-tagged (function sequence &key (key-tag #'first) (key-datum #'rest)) "Use a binary operation, `function' to combine a sequence of tagged elements. like-tagged elements are `reduce'd according to `function' and returned in a list ... `sequence' is a sequence of tagged elements. reduce-m will reduce like-tagged-elements. If `key-tag' is supplied it is used to extract the element tag. If `key-tag' is not supplied, the function `first' is used. If `key-datum' is supplied, it is used to extract the element datum. If `key-datum' is not supplied, the function `rest' is used. " (let ((hash (make-hash-table))) (dolist (datum sequence) (let ((tag (funcall key-tag datum)) (values (funcall key-datum datum))) (multiple-value-bind (it present) (gethash tag hash) (if present (setf (gethash tag hash) (apply function (gethash tag hash) values)) (setf (gethash tag hash) values))))) (let (result) (dohash (key value hash) (push (list key value) result)) result))) Comments, improvements? I am looking for a general purpose function like reduce that I can apply in various situations. Thanks, Mirko From mirko.vukovic at gmail.com Mon Sep 27 11:40:45 2010 From: mirko.vukovic at gmail.com (Mirko) Date: Mon, 27 Sep 2010 08:40:45 -0700 (PDT) Subject: reduce-tagged (was Re: toy list processing problem: collect similar terms) References: <8e54fd9c-1d6b-433c-b306-288a7341bc98@a36g2000yqc.googlegroups.com> Message-ID: <99efd0f5-36cd-496e-8941-9e1ba1227929@w4g2000vbh.googlegroups.com> On Sep 27, 11:18?am, Mirko wrote: > On Sep 26, 12:05?am, Xah Lee wrote: > > I am hijacking the following post and driving it to Cuba (the Monthy > Python fans will know what I refer to). ?I want to create a `reduce'- > like function that can handle similar problems. > > Xah said: > > > > > here's a interesting toy list processing problem. > > > I have a list of lists, where each sublist is labelled by > > a number. I need to collect together the contents of all sublists > > sharing > > the same label. So if I have the list > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > r) (5 s t)) > > > where the first element of each sublist is the label, I need to > > produce: > > > output: > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > stuffed deleted. > > Here is my Common Lisp (and I only care about Common Lisp answers) > attempt to create a `reduce'-like function to handle this kind of a > problem (you will see that I am still struggling with the code and the > documentation). > > (defun reduce-tagged (function sequence &key > ? ? ? ? ? ? ? ? ?(key-tag #'first) > ? ? ? ? ? ? ? ? ?(key-datum #'rest)) > ? "Use a binary operation, `function' to combine a sequence of tagged > elements. ?like-tagged elements are `reduce'd according to `function' > and returned in a list ... > > `sequence' is a sequence of tagged elements. ?reduce-m will reduce > like-tagged-elements. > > If `key-tag' is supplied it is used to extract the element tag. ?If > `key-tag' is not supplied, the function `first' is used. > > If `key-datum' is supplied, it is used to extract the element datum. > If `key-datum' is not supplied, the function `rest' is used. > > " > ? (let ((hash (make-hash-table))) > ? ? (dolist (datum sequence) > ? ? ? (let ((tag (funcall key-tag datum)) > ? ? ? ? ? ? (values (funcall key-datum datum))) > ? ? ? ? (multiple-value-bind (it present) > ? ? ? ? ? ? (gethash tag hash) > ? ? ? ? ? (if present > ? ? ? ? ? ? ? (setf (gethash tag hash) > ? ? ? ? ? ? ? ? ? ? (apply function (gethash tag hash) values)) > ? ? ? ? ? ? ? (setf (gethash tag hash) values))))) > ? ? (let (result) > ? ? ? (dohash (key value hash) > ? ? ? ? (push (list key value) result)) > ? ? ? result))) > > Comments, improvements? ?I am looking for a general purpose function > like reduce that I > can apply in various situations. > > Thanks, > > Mirko Correction: the previous code used a non-portable clisp macro `dohash' (looks nice, doesn't it?) Here is the version with maphash: (defun reduce-tagged (function sequence &key (key-tag #'first) (key-datum #'rest)) "Use a binary operation, `function' to combine a sequence of tagged elements. like-tagged elements are `reduce'd according to `function' `sequence' is a sequence of tagged elements. reduce-m will reduce like-tagged-elements. If `key-tag' is supplied it is used to extract the element tag. If `key-tag' is not supplied, the function `first' is used. If `key-datum' is supplied, it is used to extract the element datum. If `key-datum' is not supplied, the function `rest' is used. " (let ((hash (make-hash-table))) (dolist (datum sequence) (let ((tag (funcall key-tag datum)) (values (funcall key-datum datum))) (multiple-value-bind (it present) (gethash tag hash) (declare (ignore it)) (if present (setf (gethash tag hash) (apply function (gethash tag hash) values)) (setf (gethash tag hash) values))))) (let (result) (maphash #'(lambda(key value) (push (list key value) result)) hash) result))) Mirko From marco at gallotta.co.za Mon Sep 27 11:48:06 2010 From: marco at gallotta.co.za (Marco Gallotta) Date: Mon, 27 Sep 2010 17:48:06 +0200 Subject: Introducing Kids to Programming: 2 or 3? Message-ID: Hi there I'm sure you get a lot of "2 or 3" questions, but here's another. Umonya [1] uses Python to introduce school kids to programming. The initiative is only 15 months old and up till now we've been using existing notes and exercises and thus Python 2. But we're at the stage where we can either stick with 2 for the next few years, or go to 3 now. We received a grant from Google to reach 1,000 kids in South Africa with our course in 2011. People have also shown interest in running the course in Croatia, Poland and Egypt. We're also eyeing developing African countries in the long-term. As such, we're taking the time now to write our very own specialised course notes and exercises, and we this is why we need to decide *now* which path to take: 2 or 3? As we will be translating the notes we'll probably stick with out choice for the next few years. Since these are kids, we feel the nice changes in 3 such as removing integer division will help in teaching. It will also remove confusion when they go to download Python and grab the latest version. Since they're just starting, chances are almost none will be hit by the limited library support for at least a year or two. They will, however, be hit by the confusion of seeing Python 2 code all over the web. We're tending towards 3, but I am a little cautious myself. Marco [1] http://umonya.co.za -- Marco Gallotta MSc Student Department of Computer Science, University of Cape Town people.cs.uct.ac.za/~mgallott | marco-za.blogspot.com marco AT gallotta DOT co DOT za | 073 170 4444 | 021 552 2731 From mirko.vukovic at gmail.com Mon Sep 27 11:50:39 2010 From: mirko.vukovic at gmail.com (Mirko) Date: Mon, 27 Sep 2010 08:50:39 -0700 (PDT) Subject: reduce-tagged (was Re: toy list processing problem: collect similar terms) References: <8e54fd9c-1d6b-433c-b306-288a7341bc98@a36g2000yqc.googlegroups.com> <99efd0f5-36cd-496e-8941-9e1ba1227929@w4g2000vbh.googlegroups.com> Message-ID: <319ddef7-1ad0-4913-bded-ddf97bc40476@j18g2000yqd.googlegroups.com> On Sep 27, 11:40?am, Mirko wrote: > On Sep 27, 11:18?am, Mirko wrote: > > > > > On Sep 26, 12:05?am, Xah Lee wrote: > > > I am hijacking the following post and driving it to Cuba (the Monthy > > Python fans will know what I refer to). ?I want to create a `reduce'- > > like function that can handle similar problems. > > > Xah said: > > > > here's a interesting toy list processing problem. > > > > I have a list of lists, where each sublist is labelled by > > > a number. I need to collect together the contents of all sublists > > > sharing > > > the same label. So if I have the list > > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > > r) (5 s t)) > > > > where the first element of each sublist is the label, I need to > > > produce: > > > > output: > > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > > stuffed deleted. > > > Here is my Common Lisp (and I only care about Common Lisp answers) > > attempt to create a `reduce'-like function to handle this kind of a > > problem (you will see that I am still struggling with the code and the > > documentation). > > ... faulty code deleted Aaand one more fix (apply -> funcall) (This version at least produces a close facsimile of the desired output) (defun reduce-tagged (function sequence &key (key-tag #'first) (key-datum #'rest)) "Use a binary operation, `function' to combine a sequence of tagged elements. like-tagged elements are `reduce'd according to `function' `sequence' is a sequence of tagged elements. reduce-m will reduce like-tagged-elements. If `key-tag' is supplied it is used to extract the element tag. If `key-tag' is not supplied, the function `first' is used. If `key-datum' is supplied, it is used to extract the element datum. If `key-datum' is not supplied, the function `rest' is used. " (let ((hash (make-hash-table))) (dolist (datum sequence) (let ((tag (funcall key-tag datum)) (values (funcall key-datum datum))) (multiple-value-bind (it present) (gethash tag hash) (declare (ignore it)) (if present (setf (gethash tag hash) (funcall function (gethash tag hash) values)) (setf (gethash tag hash) values))))) (let (result) (maphash #'(lambda(key value) (push (list key value) result)) hash) result))) From usenot at geekmail.INVALID Mon Sep 27 12:45:44 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 27 Sep 2010 12:45:44 -0400 Subject: Introducing Kids to Programming: 2 or 3? References: Message-ID: <20100927124544.1d9e2ba4@geekmail.INVALID> On Mon, 27 Sep 2010 17:48:06 +0200 Marco Gallotta wrote: > Since these are kids, we feel the nice changes in 3 such as removing > integer division will help in teaching. It will also remove confusion > when they go to download Python and grab the latest version. Since > they're just starting, chances are almost none will be hit by the > limited library support for at least a year or two. That's your answer right there. > They will, however, be hit by the confusion of seeing Python 2 code > all over the web. Good point. Here is may suggestion: Make the kids aware of the 2/3 issue as early as possible, but don't go into detail. Maybe start with the obligatory "Hello world" program, and a few other simple things. Then, when you get to the "how do help myself on the net" part of the course (you're including that, right?), you make strong distinction between Py2 and Py3 and tell them to make absolutely certain that it's Python 3 code they're looking at. Maybe give the "print()" syntax as a hint, but have them rely on more explicit descriptions that come with the code. Later on (once they know more programming constructs to appreciate the differences), include another lecture, specifically on the difference between Python 2 and Python 3. Disclaimer: I'm not an educator. Maybe this is horrible advice. Someone with a better understanding of kids' and learner's minds please debunk any nonsense I may have spouted here. I just like to go by the general rule that, unlike adults, most kids aren't idiots. /W -- INVALID? DE! From seyfisuna at gmail.com Mon Sep 27 12:49:03 2010 From: seyfisuna at gmail.com (Seyfi Suna) Date: Mon, 27 Sep 2010 09:49:03 -0700 (PDT) Subject: Konya - Turkish Company Directory - NEW ! - Seyfi Suna www.een.kso.org.tr Message-ID: <768a62d0-cae2-472e-a6c5-b108464ee2b1@l6g2000yqb.googlegroups.com> Konya - Turkish Company Directory - NEW ! - Seyfi Suna www.een.kso.org.tr http://www.een.kso.org.tr/en/konya-firma-rehberi/ From limyreth at gmail.com Mon Sep 27 13:15:19 2010 From: limyreth at gmail.com (Tim Diels) Date: Mon, 27 Sep 2010 19:15:19 +0200 Subject: Python3: API Documentation generator In-Reply-To: References: <4CA0400B.7000405@gmail.com> Message-ID: On 27/09/2010 09:02, Chris Rebert wrote: > On Sun, Sep 26, 2010 at 11:56 PM, Tim Diels wrote: >> Hi all >> >> I've just switched to python3 and it turns out my current API documentation >> generator (epydoc) no longer works. I am looking for a tool that reads the >> docstrings of all classes, ... in my project and turns it into HTML >> documentation. > > Sphinx (http://sphinx.pocoo.org/ ) is the new gold standard. You'll > want to enable the `autodoc` extension: > http://sphinx.pocoo.org/ext/autodoc.html > > Cheers, > Chris > -- > http://blog.rebertia.com I tried, but it fails to run through python code that's not backwards compatible with older python versions. It fails with: ...autodoc can't import/find module 'pytilities', it reported error: "invalid syntax (overload.py, line 55)"... This is line 55 (runs in python3, not in python): def process_args(self, *args, kwargs={}) Greetings Tim (limyreth) From namekuseijin at gmail.com Mon Sep 27 13:46:32 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 27 Sep 2010 10:46:32 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> Message-ID: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> On 27 set, 05:46, TheFlyingDutchman wrote: > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > wrote: > > RG writes: > > > In article > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, > > > ?TheFlyingDutchman wrote: > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > >> > This might have been mentioned here before, but I just came across it: a > > >> > 2003 essay by Bruce Eckel on how reliable systems can get built in > > >> > dynamically-typed languages. ?It echoes things we've all said here, but > > >> > I think it's interesting because it describes a conversion experience: > > >> > Eckel started out in the strong-typing camp and was won over. > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > >> > -- Scott > > > >> If you are writing a function to determine the maximum of two numbers > > >> passed as arguents in a dynamic typed language, what is the normal > > >> procedure used by Eckel and others to handle someone passing in > > >> invalid values - such as a file handle for one varible and an array > > >> for the other? > > > > The normal procedure is to hit such a person over the head with a stick > > > and shout "FOO". > > > Moreover, the functions returning the maximum may be able to work on > > non-numbers, as long as they're comparable. ?What's more, there are > > numbers that are NOT comparable by the operator you're thinking about!. > > > So to implement your specifications, that function would have to be > > implemented for example as: > > > (defmethod lessp ((x real) (y real)) (< x y)) > > (defmethod lessp ((x complex) (y complex)) > > ? (or (< (real-part x) (real-part y)) > > ? ? ? (and (= (real-part x) (real-part y)) > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > (defun maximum (a b) > > ? (if (lessp a b) b a)) > > > And then the client of that function could very well add methods: > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > and call: > > > (maximum 'hello "WORLD") --> "WORLD" > > > and who are you to forbid it!? > > > -- > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/-Hide quoted text - > > > - Show quoted text - > > in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. If someone > tries to call it incorrectly it is a compile error. > In a dynamic typed language maximum(a, b) can be called with incorrect > datatypes. Even if I make it so it can handle many types as you did > above, it could still be inadvertantly called with a file handle for a > parameter or some other type not provided for. So does Eckel and > others, when they are writing their dynamically typed code advocate > just letting the function blow up or give a bogus answer, or do they > check for valid types passed? If they are checking for valid types it > would seem that any benefits gained by not specifying type are lost by > checking for type. And if they don't check for type it would seem that > their code's error handling is poor. that is a lie. Compilation only makes sure that values provided at compilation-time are of the right datatype. What happens though is that in the real world, pretty much all computation depends on user provided values at runtime. See where are we heading? this works at compilation time without warnings: int m=numbermax( 2, 6 ); this too: int a, b, m; scanf( "%d", &a ); scanf( "%d", &b ); m=numbermax( a, b ); no compiler issues, but will not work just as much as in python if user provides "foo" and "bar" for a and b... fail. What you do if you're feeling insecure and paranoid? Just what dynamically typed languages do: add runtime checks. Unit tests are great to assert those. Fact is: almost all user data from the external words comes into programs as strings. No typesystem or compiler handles this fact all that graceful... From animator333 at gmail.com Mon Sep 27 13:54:28 2010 From: animator333 at gmail.com (King) Date: Mon, 27 Sep 2010 10:54:28 -0700 (PDT) Subject: relative imports and sub-module execution Message-ID: <73156baa-5774-45f9-a92c-50f9573eedd9@p24g2000pra.googlegroups.com> Hi, After reading couple of docs and articles, I have implemented a simple test package with nested modules. When running "main.py", everything is working fine. Some of my sub- modules has some small test routines for debug purpose. It's because I am using relative package imports at the top, I am not able to run these sub modules individually. For example, this works when running from main.py Here is example structure main.py __init__.py core/ __init__.py folder1 __init__.py f1a.py f1b.py folder2 __init__.py f2a.py f2b.py in folder2/f2b.py, I am importing from core.folder1 import f1a print f1a.myvar Now I can't execute 'f2b.py' individually. It's giving an error: ImportError: No module named core.folder2 Is this mean when you have created a package where modules are using relative imports, they can't execute individually? Another solution that I have discovered is using sys.path. Check this: import sys import os sys.path.append(os.path.abspath("../../")) from core.folder1 import f1a print f1a.myvar This works fine and easier too. I can execute modules individually as well as package is also working. Are there any disadvantages when using above technique? Couple of articles suggests that this is a bad practice and should not be used. Need some clarifications. Thanks Prashant From kee at kagi.com Mon Sep 27 14:04:17 2010 From: kee at kagi.com (Kee Nethery) Date: Mon, 27 Sep 2010 11:04:17 -0700 Subject: Introducing Kids to Programming: Scratch In-Reply-To: References: Message-ID: My son has been writing games using MIT's Scratch. It is visual and highly interactive. In an afternoon he can build something that looks cool to him, is interactive, and that he can share with others. It's not Python but he is learning how to make the tools do what he wants and he is getting results. He's 8 years old. http://scratch.mit.edu For introducing kids to programming, I recommend Scratch. Kee Nethery From tjreedy at udel.edu Mon Sep 27 14:13:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Sep 2010 14:13:45 -0400 Subject: Introducing Kids to Programming: 2 or 3? In-Reply-To: References: Message-ID: On 9/27/2010 11:48 AM, Marco Gallotta wrote: > Hi there > > I'm sure you get a lot of "2 or 3" questions, but here's another. > Umonya [1] uses Python to introduce school kids to programming. The > initiative is only 15 months old and up till now we've been using > existing notes and exercises and thus Python 2. But we're at the stage > where we can either stick with 2 for the next few years, or go to 3 > now. > > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. As such, we're taking the time now > to write our very own specialised course notes and exercises, and we > this is why we need to decide *now* which path to take: 2 or 3? As we > will be translating the notes we'll probably stick with out choice for > the next few years. I would absolutely, definitely, move to Python3, with the the intention of using 3.2 when it comes out in a few months. I suspect that most of your exercise code will need little change beyond what 2to3 does for you. > Since these are kids, we feel the nice changes in 3 such as removing > integer division will help in teaching. There are several half-finished transitions in late 2.x. Removal of old-style classes, not only as the default, but completely, removes a source of confusion. The range/xrange confusion is gone. The input/raw_imput confusion is gome. I think most important for an international project is the shift to unicode as the default text type, including for identifiers. Kids who are not masters of English will want to write identifiers in their own language. > It will also remove confusion > when they go to download Python and grab the latest version. Since > they're just starting, chances are almost none will be hit by the > limited library support for at least a year or two. I personally consider this pretty irrelevant for teaching programming to kids. There is a *lot* in the stdlib to work with. And stdlib improvement is getting special emphasis for 3.2. Bug fixes may be backported, feature additions are not. Even if one disagrees, 3rd-party library support is improving and will continue to improve especially after 3.2 is released. For instance, the recent release of numpy for 3.1 enables conversions that were blocked waiting for that. http://sourceforge.net/projects/numpy/files/NumPy/1.5.0/numpy-1.5.0-win32-superpack-python3.1.exe/download For another example, the web-sig appears to have agreed on a minimal, backward-compatible extension to PEP 333 to make wsgi work with Python3. This will be PEP 3333. (It appears the problem was too many choices rather than no choice. Discussion continues on more extensive non-compatible changes.) This will allow existing wsgi tools to both work with Python3 *and* continue to be intercompatible. (The latter was the problem. If each tool made its own non-standard choice for Python3, that latter property would be lost.) -- Terry Jan Reedy From tjreedy at udel.edu Mon Sep 27 14:25:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Sep 2010 14:25:20 -0400 Subject: Python3: API Documentation generator In-Reply-To: References: <4CA0400B.7000405@gmail.com> Message-ID: On 9/27/2010 1:15 PM, Tim Diels wrote: > On 27/09/2010 09:02, Chris Rebert wrote: >> On Sun, Sep 26, 2010 at 11:56 PM, Tim Diels wrote: >>> Hi all >>> >>> I've just switched to python3 and it turns out my current API >>> documentation >>> generator (epydoc) no longer works. I am looking for a tool that >>> reads the >>> docstrings of all classes, ... in my project and turns it into HTML >>> documentation. >> >> Sphinx (http://sphinx.pocoo.org/ ) is the new gold standard. You'll >> want to enable the `autodoc` extension: >> http://sphinx.pocoo.org/ext/autodoc.html >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > I tried, but it fails to run through python code that's not backwards > compatible with older python versions. > > It fails with: ...autodoc can't import/find module 'pytilities', it > reported error: "invalid syntax (overload.py, line 55)"... > > This is line 55 (runs in python3, not in python): > def process_args(self, *args, kwargs={}) Unless the autodoc doc says that it does not work with all Python3 code, that strikes me as a bug (a new 3.x feature that was overlooked) that should be reported. The sphinx tracker is linked on the sphinx homepage http://bitbucket.org/birkenfeld/sphinx/issues/ There is also a link to a google group for sphinx. Does epydoc not work because is does not run on 3.1 or because it also chokes when fed the above code. In the meanwhile, you could change the api ;-). -- Terry Jan Reedy From kwatford+python at gmail.com Mon Sep 27 14:44:08 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Mon, 27 Sep 2010 14:44:08 -0400 Subject: Python3: API Documentation generator In-Reply-To: References: <4CA0400B.7000405@gmail.com> Message-ID: On Mon, Sep 27, 2010 at 1:15 PM, Tim Diels wrote: > On 27/09/2010 09:02, Chris Rebert wrote: >> >> On Sun, Sep 26, 2010 at 11:56 PM, Tim Diels ?wrote: >>> >>> ?Hi all >>> >>> I've just switched to python3 and it turns out my current API >>> documentation >>> generator (epydoc) no longer works. I am looking for a tool that reads >>> the >>> docstrings of all classes, ... in my project and turns it into HTML >>> documentation. >> >> Sphinx (http://sphinx.pocoo.org/ ) is the new gold standard. You'll >> want to enable the `autodoc` extension: >> http://sphinx.pocoo.org/ext/autodoc.html >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > I tried, but it fails to run through python code that's not backwards > compatible with older python versions. > > It fails with: ...autodoc can't import/find module 'pytilities', it reported > error: "invalid syntax (overload.py, line 55)"... > > This is line 55 (runs in python3, not in python): > def process_args(self, *args, kwargs={}) > As far as I'm aware, autodoc works by importing the modules and then reading doctext straight from the __doc__ attributes. So the module in question has to import correctly in whatever interpreter Sphinx is using. You probably need to install Sphinx with python3 to get it to use the right interpreter. If you're using easy_install or pip, check if you have an easy_install-3.1 or pip-3.1 (or similar) script installed. From xahlee at gmail.com Mon Sep 27 15:06:50 2010 From: xahlee at gmail.com (Xah Lee) Date: Mon, 27 Sep 2010 12:06:50 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> Message-ID: <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> 2010-09-27 > For instance, this is far more convenient: > [x+1 for x in [1,2,3,4,5] if x%2==0] > than this: > map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) How about this: LC(func, inputList, P) compared to [func for myVar in inputList if P] the functional form is: ? shorter ? not another idiysyncratic new syntax -------------------- now, a separate issue. Suppose we want some ?list comprehension? feature in a functional lang. Normally, by default this can be done by filter( map(func, inputList), Predicate) but perhaps this usage is so frequent that we want to create a new fuction for it, to make it more convenient, and perhaps easier to make the compiler to optimize more. e.g. LC(func, inputList, Predicate) this is about whether a lang should create a new convenient function that otherwise require 2 function combinations. Common Lisp vs Scheme Lisp are the typical example of extreme opposites. note, there's no new syntax involved. -------------------- Now, let's consider another separated issue related to so-called ?list comprehension?. Suppose we decided that generating list by a filter is so frequently used that it worth it to create a new func for it. LC(func, inputList, Predicate) Now, in functional langs, in general a design principle is that you want to reduce the number of function unless you really need. Because, any combination of list related functions could potentionally be a new function in your lang. So, if we really think LC is useful, we might want to generalize it. e.g. in LC(func, inputList, Predicate) is it worthwhile say to add a 4th param, that says return just the first n? (here we presume the lang doesn't support list of infinite elements) e.g. LC(func, inputList, Predicate, n) what about partition the list to m sublists? LC(func, inputList, Predicate, n, m) what about actualy more generalized partition, by m sublist then by m1 sublist then by m2 sublist? LC(func, inputList, Predicate, n, list(m,m1,m2,...)) what about sorting? maybe that's always used together when you need a list? LC(func, inputList, Predicate, n, list(m,m1,m2,...), sortPredcate) what if actually frequently we want LC to map parallel to branches? e.g. LC(func, inputList, Predicate, n, list(m,m1,m2,...), sortPredcate, mapBranch:True) what if ... you see, each of these or combination of these can be done by default in the lang by sequenceing one or more functions (i.e. composition). But when we create a new function, we really should think a lot about its justification, because otherwise the lang becomes a bag of functions that are non-essential, confusing. In summary: ? ?list comprehension? is a bad jargon. ? The concept of ?list comprehension? is redundant. There's no justification for the concept to exist except historical. ? The syntax of ?list comprehension? in most lang is ad hoc syntax. for those who find imperative lang good, then perhaps ?list comprehension? is good, because it adds another idiosyncratic syntax to the lang, but such is with the tradition of imperative langs. The ad hoc syntax aids in reading code by various syntactical forms and hint words such as ?[... for ... in ...]?. Xah ? xahlee.org ? From namekuseijin at gmail.com Mon Sep 27 15:11:20 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 27 Sep 2010 12:11:20 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> Message-ID: On 27 set, 16:06, Xah Lee wrote: > 2010-09-27 > > > For instance, this is far more convenient: > > [x+1 for x in [1,2,3,4,5] if x%2==0] > > than this: > > map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) > > How about this: [snip] how about this: read before replying. From pjb at informatimago.com Mon Sep 27 15:29:44 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 27 Sep 2010 21:29:44 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> namekuseijin writes: >> in C I can have a function maximum(int a, int b) that will always >> work. Never blow up, and never give an invalid answer. If someone >> tries to call it incorrectly it is a compile error. >> In a dynamic typed language maximum(a, b) can be called with incorrect >> datatypes. Even if I make it so it can handle many types as you did >> above, it could still be inadvertantly called with a file handle for a >> parameter or some other type not provided for. So does Eckel and >> others, when they are writing their dynamically typed code advocate >> just letting the function blow up or give a bogus answer, or do they >> check for valid types passed? If they are checking for valid types it >> would seem that any benefits gained by not specifying type are lost by >> checking for type. And if they don't check for type it would seem that >> their code's error handling is poor. > > that is a lie. > > Compilation only makes sure that values provided at compilation-time > are of the right datatype. > > What happens though is that in the real world, pretty much all > computation depends on user provided values at runtime. See where are > we heading? > > this works at compilation time without warnings: > int m=numbermax( 2, 6 ); > > this too: > int a, b, m; > scanf( "%d", &a ); > scanf( "%d", &b ); > m=numbermax( a, b ); > > no compiler issues, but will not work just as much as in python if > user provides "foo" and "bar" for a and b... fail. > > What you do if you're feeling insecure and paranoid? Just what > dynamically typed languages do: add runtime checks. Unit tests are > great to assert those. > > Fact is: almost all user data from the external words comes into > programs as strings. No typesystem or compiler handles this fact all > that graceful... I would even go further. Types are only part of the story. You may distinguish between integers and floating points, fine. But what about distinguishing between floating points representing lengths and floating points representing volumes? Worse, what about distinguishing and converting floating points representing lengths expressed in feets and floating points representing lengths expressed in meters. If you start with the mindset of static type checking, you will consider that your types are checked and if the types at the interface of two modules matches you'll think that everything's ok. And six months later you Mars mission will crash. On the other hand, with the dynamic typing mindset, you might even wrap your values (of whatever numerical type) in a symbolic expression mentionning the unit and perhaps other meta data, so that when the other module receives it, it may notice (dynamically) that two values are not of the same unit, but if compatible, it could (dynamically) convert into the expected unit. Mission saved! -- __Pascal Bourguignon__ http://www.informatimago.com/ From Scott at ergy.com Mon Sep 27 16:36:39 2010 From: Scott at ergy.com (Scott L. Burson) Date: Mon, 27 Sep 2010 13:36:39 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: Pascal J. Bourguignon wrote: > > On the other hand, with the dynamic typing mindset, you might even wrap > your values (of whatever numerical type) in a symbolic expression > mentionning the unit and perhaps other meta data, so that when the other > module receives it, it may notice (dynamically) that two values are not > of the same unit, but if compatible, it could (dynamically) convert into > the expected unit. Mission saved! In fairness, you could do this statically too, and without the consing required by the dynamic approach. -- Scott From pjb at informatimago.com Mon Sep 27 16:38:17 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 27 Sep 2010 22:38:17 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <877hi6sz0m.fsf@kuiper.lan.informatimago.com> "Scott L. Burson" writes: > Pascal J. Bourguignon wrote: >> >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. Mission saved! > > In fairness, you could do this statically too, and without the consing > required by the dynamic approach. I don't deny it. My point is that it's a question of mindset. -- __Pascal Bourguignon__ http://www.informatimago.com/ From cartercc at gmail.com Mon Sep 27 16:43:37 2010 From: cartercc at gmail.com (ccc31807) Date: Mon, 27 Sep 2010 13:43:37 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: Message-ID: On Sep 26, 12:05?am, Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) Here is a solution in Perl -- the verbose version. Please see my note below. SCRIPT: use strict; use warnings; my %lists; while () { chomp; my ($k, @v) = split(/ /, $_); push(@{$lists{$k}}, @v); } foreach my $k (sort keys %lists) { print "$k - @{$lists{$k}}\n"; } exit(0); __DATA__ 0 a b 1 c d 2 e f 3 g h 1 i j 2 k l 4 m n 2 o p 4 q r 5 s t OUTPUT: >perl lists.plx 0 - a b 1 - c d i j 2 - e f k l o p 3 - g h 4 - m n q r 5 - s t NOTE: I assume that you want an idiomatic solution for the language. I have therefore converted your data into a typical record oriented structure. Perlistas don't use parenthesis. If you want a Lispy solution, use Lisp. Further, Perl was made for exactly this kind of problem, which is simple data munging, taking some input, transforming it, and printing it out -- Practical Extraction and Reporting Language. I know that some Lispers (R.G., are you reading?) will object to a formulation like this: @{$lists{$k}}, but all this says (in Perl) is to spit out the value contained in the hash element $lists{$k} as an array, and is good idiomatic Perl, even if some Lispers aren't quite up to the task of understanding it. CC. From hodgestar at gmail.com Mon Sep 27 17:12:14 2010 From: hodgestar at gmail.com (Simon Cross) Date: Mon, 27 Sep 2010 23:12:14 +0200 Subject: [ctpug] Introducing Kids to Programming: 2 or 3? In-Reply-To: References: Message-ID: On Mon, Sep 27, 2010 at 5:48 PM, Marco Gallotta wrote: > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. As such, we're taking the time now > to write our very own specialised course notes and exercises, and we > this is why we need to decide *now* which path to take: 2 or 3? As we > will be translating the notes we'll probably stick with out choice for > the next few years. If you were going to start running the course tomorrow I'd suggest sticking with Python 2. Python 3 ports are rapidly becoming available but few have had the bugs shaken out of them yet. In three or four months I expect that the important bugs will have been dealt with. Given that 2.x will not receive any new features, I think it is effectively dead. I would explicitly mention the existence of 2.7 and 3.2 [1] to students (perhaps near the end of the first day or whenever they're about to go off and download Python for themselves). One caveat is that web applications may only start to migrate to 3.x late next year. There are a number of reasons for this. First it's not yet clear what form the WSGI standard will take under Python 3 (and if 3.2 is released before this decision is made it will effectively have to wait for 3.3 to be included). Secondly the software stack involved is quite deep in some places. For example, database support might require porting MySQLdb, then SQLAlchemy, then the web framework and only after that the web application itself. [1] Which should hopefully make it out before 2011. :) Schiavo Simon From xahlee at gmail.com Mon Sep 27 17:39:56 2010 From: xahlee at gmail.com (Xah Lee) Date: Mon, 27 Sep 2010 14:39:56 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> Message-ID: <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> On Sep 27, 12:11?pm, namekuseijin wrote: > On 27 set, 16:06, Xah Lee wrote:> 2010-09-27 > > > > For instance, this is far more convenient: > > > [x+1 for x in [1,2,3,4,5] if x%2==0] > > > than this: > > > map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) > > > How about this: > > [snip] > > how about this: ?read before replying. hum??? i read your post quite carefully, and rather thought i replied well. In fact, i really wanted to tell you ?read before replying? before but refrained from making any of that expression. here's 2 previous posts about list compre. http://groups.google.com/group/comp.lang.lisp/msg/145f6ecf29ebbdaf http://groups.google.com/group/comp.lang.lisp/msg/62ca84062c9fcdca Xah From hansyin at gmail.com Mon Sep 27 18:13:28 2010 From: hansyin at gmail.com (Hans) Date: Mon, 27 Sep 2010 15:13:28 -0700 (PDT) Subject: program organization question for web development with python References: <6102316a-d6e6-4cf2-8a1b-ecc5d3247c29@w15g2000pro.googlegroups.com> <14ff2109-cf99-4fb1-b64f-4b1f018b2a86@l38g2000pro.googlegroups.com> <4c933693$0$4439$426a34cc@news.free.fr> Message-ID: On Sep 17, 2:36?am, Bruno Desthuilliers wrote: > Hans a ?crit : > (snip) > > > Maybe I did not make my question clear. I never tried python web > > programing before, so I want to start from CGI. > > You can indeed learn quite a few things doing raw CGI - the most > important one being why frameworks are a good idea !-) > > > I read something about web framework like django, but seems it's a > > little bit complicated. > > Not that much IMHO, but being an early django user I'm probably a bit > biased. Now Python is known as "the language with more web frameworks > than keywords", so you could probably check some lighter framework like > ? web.py (http://webpy.org/) or flask (http://flask.pocoo.org/). > > > my task is actually very simple: get search > > string from input, and then search database, print search result. I > > thought CGI should be good enough to do this. > > CGI is "good enough" to do any web stuff - just like assembler is "good > enough" to write any application !-) > > > > > I don't have any idea about how to organize those cgi codes, so what > > I'm asking is: > > > 1. do I have to have each single file for each hyper-link? Can I put > > them together? how? > > > 2. how can I pass a db_cursor to another file? ? can I use db_cursor as > > a parameter? > > Obviously not. FWIW, both questions show a lack of understanding of the > HTTP protocol, and you can't hope to do anything good in web programming > if you don't understand at least the basics of the HTTP protocol, > specially the request/response cycle. > > Now for a couple more practical answers: > > There are basically two ways to organize your url => code mapping: > 1/ have only one cgi script and use querystring params to tell which > action should be executed. > 2/ have one cgi script per action. > > The choice is up to you. For a simple app like yours, the first solution > is probably the most obvious : always display the seach form, if the > user submitted the form also display the result list. That's how google > works (wrt/ user interface I mean). > > Now if you still need / want to have distinct scripts and want to factor > out some common code, you just put the common code in a module that you > import from each script. Thank you very much! I got your meaning. The choice 1 is definitely what I want, I just cannot think about this idea by myself. Thank you again! From asaferibeiro4 at ymail.com Mon Sep 27 18:28:34 2010 From: asaferibeiro4 at ymail.com (Eduardo Ribeiro) Date: Mon, 27 Sep 2010 15:28:34 -0700 (PDT) Subject: Nautilus Python Message-ID: <262676.77946.qm@web59614.mail.ac4.yahoo.com> I'm a python noob and wrote the following code for a nautilus extension: #!/usr/local/bin/python # -*- coding: utf-8 -*- import urllib import gtk import pygtk import nautilus import gconf import gtk.glade class Slide (nautilus.MenuProvider): f = None def __init__(self): self.client = gconf.client_get_default() self.f = gtk.glade.XML( "papel.glade" ) self.window = self.f.get_widget("window1") gtk.main() def oi (self): self.window.show() def menu_activate_cb(self, menu, file): self.oi() def get_file_items(self, window,files): if len(files) != 1: return item = nautilus.MenuItem('NautilusPython::slide_file_item','Slide','Slide') item.connect('activate', self.menu_activate_cb, files[0]) return item, def get_background_items(self, window, file): item = nautilus.MenuItem('NautilusPython::slide_item','Slide','Slide') item.connect('activate', self.menu_background_activate_cb, file) return item, def menu_background_activate_cb(self, menu, file): self.oi() But it doesn't work. If I comment the lines: self.f = gtk.glade.XML( "papel.glade" ) self.window = self.f.get_widget("window1") gtk.main() the code works but I can't see any problem in those lines. Any help? From sjmachin at lexicon.net Mon Sep 27 19:01:34 2010 From: sjmachin at lexicon.net (John Machin) Date: Tue, 28 Sep 2010 09:01:34 +1000 Subject: strange results from sys.version Message-ID: <4CA1224E.5040101@lexicon.net> I am trying to help a user of my xlrd package who says he is getting anomalous results on his "work computer" but not on his "home computer". Attempts to reproduce his alleged problem in a verifiable manner on his "work computer" have failed, so far ... the only meaning difference in script output is in sys.version User (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc Me : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc I have just now downloaded the Windows x86 msi from www.python.org and reinstalled it on another computer. It gives the same result as on my primary computer (above). User result looks whacked: lower patch number, later date. www.python.org says "Python 2.7 was released on July 3rd, 2010." Is it possible that the "work computer" is using an unofficial release? What other possibilities are there? Thanks in advance ... From afffg33 at gmail.com Mon Sep 27 19:04:41 2010 From: afffg33 at gmail.com (fcgffj) Date: Mon, 27 Sep 2010 16:04:41 -0700 (PDT) Subject: vhttp://www.vipshops.org/ nike air jordan shoe for sale,nike , chanal, gucci, juicy, polo tshirt.adidas and so on.all are free shipping. Message-ID: nike air jordan shoes http://www.vipshops.org/ nike shoes http://www.vipshops.org/ ed hardy http://www.vipshops.org/ SUIT ShortJ ERSEY Jean Jacket Hoody http://www.vipshops.org/ T-ShirtT http://www.vipshops.org/ -Shirt_W http://www.vipshops.org/ Tracksuit_W http://www.vipshops.org/ Skirt_W http://www.vipshops.org/ Short_W http://www.vipshops.org/ Jean sunglass http://www.vipshops.org/ more info http://www.vipshops.org/ ED Hardy_menDG menCOACH_menLV menLacoste manKobe http://www.vipshops.org/ manPuma manTimberland bootRift_man Super http://www.vipshops.org/Size(14_15)Prada_man Nike_shox Nike_Air_Jordan Nike_Air_Force_1 Nike_Air_Dunk Jordan Ring Jordan Fusion Jordan 23 Mixture GucciFashion BOOTBape shoesASCIS Air_max_man ADIDAS SHOE http://www.vipshops.org/ Shoes For Female http://www.vipshops.org/ Woman BootSandal Nike_shox_woman Nike_Air_Jordan_w Jordan_Fusion_w Gucci woman Dunk_Shoe_woman Air_max_woman AF1_Shoe_woman Timberland_WRift_W Puma_WPrada_W LV_W Louboutin_W juicy couture shoe_W DG_WCOACH_W christian louboutin ASCIS_WADIDAS_W Kid Apparel http://www.vipshops.org/ Shoe For KidClothing For Kid Handbag_Wallet http://www.vipshops.org/ Wallet Handbag Other Product http://www.vipshops.org/ Watch Sunglass Software Jewerly Hair Straigher CapBelt ED Hardy_men DG menCOACH_men LV men Lacoste man Kobe man Puma_man Timberland bootRift_man Super Size(14_15)Prada_manNike_shoxNike_Air_JordanNike_Air_Force_1Nike_Air_DunkJordan RingJordan FusionJordan 23 Mixture GucciFashion BOOTBape shoes ASCISAir_max_manADIDAS SHOE more info http://www.vipshops.org/ From robert.kern at gmail.com Mon Sep 27 19:30:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 27 Sep 2010 18:30:02 -0500 Subject: strange results from sys.version In-Reply-To: <4CA1224E.5040101@lexicon.net> References: <4CA1224E.5040101@lexicon.net> Message-ID: On 9/27/10 6:01 PM, John Machin wrote: > I am trying to help a user of my xlrd package who says he is getting anomalous > results on his "work computer" but not on his "home computer". > > Attempts to reproduce his alleged problem in a verifiable manner on his "work > computer" have failed, so far ... the only meaning difference in script output > is in sys.version > > User (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc > Me : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc > > I have just now downloaded the Windows x86 msi from www.python.org and > reinstalled it on another computer. It gives the same result as on my primary > computer (above). > > User result looks whacked: lower patch number, later date. www.python.org says > "Python 2.7 was released on July 3rd, 2010." > > Is it possible that the "work computer" is using an unofficial release? What > other possibilities are there? ActivePython 2.7.0.2 was released on Aug 25: http://downloads.activestate.com/ActivePython/releases/2.7.0.2/ -- 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 sridharr at activestate.com Mon Sep 27 19:36:01 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 27 Sep 2010 16:36:01 -0700 Subject: strange results from sys.version In-Reply-To: References: <4CA1224E.5040101@lexicon.net> Message-ID: <550E2DB8-49FD-462F-B449-E922A12D270D@activestate.com> On 2010-09-27, at 4:30 PM, Robert Kern wrote: > On 9/27/10 6:01 PM, John Machin wrote: >> I am trying to help a user of my xlrd package who says he is getting anomalous >> results on his "work computer" but not on his "home computer". >> >> Attempts to reproduce his alleged problem in a verifiable manner on his "work >> computer" have failed, so far ... the only meaning difference in script output >> is in sys.version >> >> User (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc >> Me : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc >> >> I have just now downloaded the Windows x86 msi from www.python.org and >> reinstalled it on another computer. It gives the same result as on my primary >> computer (above). >> >> User result looks whacked: lower patch number, later date. www.python.org says >> "Python 2.7 was released on July 3rd, 2010." >> >> Is it possible that the "work computer" is using an unofficial release? What >> other possibilities are there? > > ActivePython 2.7.0.2 was released on Aug 25: > > http://downloads.activestate.com/ActivePython/releases/2.7.0.2/ John, If it is ActivePython, the first line of the interactive shell (in credits section) should print something like: ActivePython 2.7.0.2 (ActiveState Software Inc.) Also what is the output of "python -m activestate"? -srid From sridharr at activestate.com Mon Sep 27 19:44:55 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 27 Sep 2010 16:44:55 -0700 Subject: strange results from sys.version In-Reply-To: <4CA1224E.5040101@lexicon.net> References: <4CA1224E.5040101@lexicon.net> Message-ID: <6131A5C1-5DCD-4EE8-8851-91DA2CB13AA1@activestate.com> On 2010-09-27, at 4:01 PM, John Machin wrote: > User (work): sys.version: 2.7 (r27:82500, Aug 23 2010, 17:18:21) etc > Me : sys.version: 2.7 (r27:82525, Jul 4 2010, 09:01:59) etc > > [...] User result looks whacked: lower patch number, later date Perusing http://svn.python.org/view/python/branches/release27-maint/?view=log - the difference in svn versions (there is no difference in patch number) seems insignificant. Both revisions are past the 2.7 final release. Perhaps, the python.org installer was created using a later revision. -srid From namekuseijin at gmail.com Mon Sep 27 19:58:52 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Mon, 27 Sep 2010 16:58:52 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> Message-ID: <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> On 27 set, 18:39, Xah Lee wrote: > On Sep 27, 12:11?pm, namekuseijin wrote: > > > On 27 set, 16:06, Xah Lee wrote:> 2010-09-27 > > > > > For instance, this is far more convenient: > > > > [x+1 for x in [1,2,3,4,5] if x%2==0] > > > > than this: > > > > map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) > > > > How about this: > > > [snip] > > > how about this: ?read before replying. > > hum??? > > i read your post quite carefully, and rather thought i replied well. I don't think so. You completely missed the point where I agreed about filter map being more convenient when calling predefined functions and also the detailed explanation of why do in scheme is not imperative at all. From danny at picolina.net Mon Sep 27 20:07:45 2010 From: danny at picolina.net (Danny Levinson) Date: Mon, 27 Sep 2010 17:07:45 -0700 Subject: Debugger - fails to "continue" with breakpoint set In-Reply-To: <4C914610.5060904@greenberg.org> References: <4C914610.5060904@greenberg.org> Message-ID: <4CA131D1.1080009@picolina.net> Does this describe the problem you are having? http://bugs.python.org/issue5294 From rjngrj2010 at gmail.com Mon Sep 27 21:22:33 2010 From: rjngrj2010 at gmail.com (gujax) Date: Mon, 27 Sep 2010 18:22:33 -0700 (PDT) Subject: Problems reading tif files References: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> Message-ID: <53e93b52-fc29-4643-8d91-4fcad3463540@t11g2000vbc.googlegroups.com> On Sep 26, 9:19?pm, Christian Heimes wrote: > Am 27.09.2010 02:31, schrieb gujax: > > > Hi, > > I have read several related e-mails dating back as far as 2006. I am > > quite confused whether PIL can open tif images. Some posts seem to say > > there isn't yet any support for PIL while there are few posts where > > PIL has been able to open tif images. So I guess, I have to ask this > > probably trivial question again. I am just learning python and PIL. I > > have tiff images which are 8 bit and 16 bit gray scale images. I > > cannot open them. Here are the errors that I encounter. > > PIL only supports a limited subset of TIFF files. Several compression > algorithms like G3 and G4 fax compression are not supported yet. PIL may > have a problem with partly broken TIFF files, too. > > > I have no idea why this happens. > > I will appreciate a resolution. The file opens with ImageJ and > > ImageMagick. It is a 8-bit RGB file. I have associated default viewer > > to be ImageMagick. I am on Lucid Linux, and other programs such as F- > > spot and Gimp cannot open those files either. > > I don't yet know how to attach image files to the post so please bear > > with me till I figure that out. > > Can you please post the output of tiffinfo for the specific file? It may > give me a hint what's going wrong. > > There aren't a lot of good alternatives for image processing in Python. > I've evaluated most of them and decided to write my own one for my > employer. It's a Cython based library around FreeImage [1] and LCMS2 [2] > and works very well. So far we have processed several million TIFF files > with more than 100 TB of raw data smoothly. I've permission to release > the software as open source but haven't found time to do a proper release. > > Christian Heimes > > [1]http://freeimage.sourceforge.net/ > [2]http://www.littlecms.com/ Thanks Christian, Here is the tiffinfo: TIFF Directory at offset 0x8 (8) Subfile Type: (0 = 0x0) Image Width: 640 Image Length: 480 Bits/Sample: 32 Sample Format: IEEE floating point Compression Scheme: None Photometric Interpretation: min-is-black Samples/Pixel: 1 Rows/Strip: 480 Planar Configuration: single image plane ImageDescription: ImageJ=1.44f min=0.0 max=255.0 How do I use freeimage with python. Is there a backend? Can these files be converted to something else such as bmp and then read out? I should have tried it out before asking you, Thanks From rjngrj2010 at gmail.com Mon Sep 27 21:25:45 2010 From: rjngrj2010 at gmail.com (gujax) Date: Mon, 27 Sep 2010 18:25:45 -0700 (PDT) Subject: Problems reading tif files References: <97b8faea-5bde-450c-ae9d-cf01c970399d@m15g2000yqm.googlegroups.com> Message-ID: <2d426eec-9cfa-4e3f-a418-f6f3e8ef77c2@c32g2000vbq.googlegroups.com> Thanks Christian, Here is the info: TIFF Directory at offset 0x8 (8) Subfile Type: (0 = 0x0) Image Width: 640 Image Length: 480 Bits/Sample: 32 Sample Format: IEEE floating point Compression Scheme: None Photometric Interpretation: min-is-black Samples/Pixel: 1 Rows/Strip: 480 Planar Configuration: single image plane ImageDescription: ImageJ=1.44f min=0.0 max=255.0 How can I use freeimage. Can I incorporate it with python? Any idea what do ImageJ or Matlab use. Don't they have a robust imaging toolbox. Unfortunately, I cannot afford Matlab and I am not good at Java programing to be able to implement ImageJ with numerical analysis software. Thanks much, gujax On Sep 26, 9:19?pm, Christian Heimes wrote: > Am 27.09.2010 02:31, schrieb gujax: > > > Hi, > > I have read several related e-mails dating back as far as 2006. I am > > quite confused whether PIL can open tif images. Some posts seem to say > > there isn't yet any support for PIL while there are few posts where > > PIL has been able to open tif images. So I guess, I have to ask this > > probably trivial question again. I am just learning python and PIL. I > > have tiff images which are 8 bit and 16 bit gray scale images. I > > cannot open them. Here are the errors that I encounter. > > PIL only supports a limited subset of TIFF files. Several compression > algorithms like G3 and G4 fax compression are not supported yet. PIL may > have a problem with partly broken TIFF files, too. > > > I have no idea why this happens. > > I will appreciate a resolution. The file opens with ImageJ and > > ImageMagick. It is a 8-bit RGB file. I have associated default viewer > > to be ImageMagick. I am on Lucid Linux, and other programs such as F- > > spot and Gimp cannot open those files either. > > I don't yet know how to attach image files to the post so please bear > > with me till I figure that out. > > Can you please post the output of tiffinfo for the specific file? It may > give me a hint what's going wrong. > > There aren't a lot of good alternatives for image processing in Python. > I've evaluated most of them and decided to write my own one for my > employer. It's a Cython based library around FreeImage [1] and LCMS2 [2] > and works very well. So far we have processed several million TIFF files > with more than 100 TB of raw data smoothly. I've permission to release > the software as open source but haven't found time to do a proper release. > > Christian Heimes > > [1]http://freeimage.sourceforge.net/ > [2]http://www.littlecms.com/ From nagle at animats.com Mon Sep 27 22:14:44 2010 From: nagle at animats.com (John Nagle) Date: Mon, 27 Sep 2010 19:14:44 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <4ca14fa1$0$1595$742ec2ed@news.sonic.net> On 9/27/2010 10:46 AM, namekuseijin wrote: > On 27 set, 05:46, TheFlyingDutchman wrote: >> On Sep 27, 12:58 am, p... at informatimago.com (Pascal J. Bourguignon) >> wrote: >>> RG writes: >>>> In article >>>> <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, >>>> TheFlyingDutchman wrote: >> >>>>> On Sep 22, 10:26 pm, "Scott L. Burson" wrote: >>>>>> This might have been mentioned here before, but I just came across it: a >>>>>> 2003 essay by Bruce Eckel on how reliable systems can get built in >>>>>> dynamically-typed languages. It echoes things we've all said here, but >>>>>> I think it's interesting because it describes a conversion experience: >>>>>> Eckel started out in the strong-typing camp and was won over. >> >>>>>> https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk >> The trouble with that essay is that he's comparing with C++. C++ stands alone as offering hiding without memory safety. No language did that before C++, and no language has done it since. The basic problem with C++ is that it take's C's rather lame concept of "array=pointer" and wallpapers over it with objects. This never quite works. Raw pointers keep seeping out. The mold always comes through the wallpaper. There have been better strongly typed languages. Modula III was quite good, but it was from DEC's R&D operation, which was closed down when Compaq bought DEC. John Nagle From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 22:31:33 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 28 Sep 2010 02:31:33 GMT Subject: Nautilus Python References: Message-ID: <4ca15385$0$28657$c3e8da3@news.astraweb.com> On Mon, 27 Sep 2010 15:28:34 -0700, Eduardo Ribeiro wrote: > But it doesn't work. What do you mean "doesn't work"? - It crashes the operating system; - You get a core dump; - You get an exception; - It hangs forever, never doing anything; - It does something unexpected; - Something else? -- Steven From steve-REMOVE-THIS at cybersource.com.au Mon Sep 27 22:34:39 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 28 Sep 2010 02:34:39 GMT Subject: reduced-tagged (was Re: toy list processing problem: collect similar terms) References: <8e54fd9c-1d6b-433c-b306-288a7341bc98@a36g2000yqc.googlegroups.com> Message-ID: <4ca1543f$0$28657$c3e8da3@news.astraweb.com> On Mon, 27 Sep 2010 08:18:22 -0700, Mirko wrote: > Here is my Common Lisp (and I only care about Common Lisp answers) Good for you. So why are you spamming other newsgroups with your CL solution? Not once, but three times. Replies to /dev/null. -- Steven From usenet-nospam at seebs.net Mon Sep 27 22:43:34 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 02:43:34 GMT Subject: toy list processing problem: collect similar terms References: <7xzkv5hvv0.fsf@ruckus.brouhaha.com> Message-ID: On 2010-09-26, Xah Lee wrote: > On Sep 25, 11:17??pm, Paul Rubin wrote: >> Python solution follows (earlier one with an error cancelled). ??All >> crossposting removed since crossposting is a standard trolling tactic. > btw, i disagree about your remark on crossposting. You're wrong. Crossposting is indeed a standard trolling tactic. This does not prove that all crossposters are trolls, nor does it assert that all crossposters are trolls, but it is absolutely factually correct that it's a standard trolling tactic. -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 Sep 27 22:45:50 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 02:45:50 GMT Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> Message-ID: On 2010-09-26, J?rgen Exner wrote: > It was livibetter who without any motivation or reasoning posted Python > code in CLPM. Not exactly; he posted it in a crossposted thread, which happened to include CLPM and other groups, including comp.lang.python. It is quite possible that he didn't know about the crossposting. However, while I would agree that this would constitute a form of ignorance, I'd think that, especially with how well some newsreading interfaces hide that detail, I don't think it's really worth getting angry over. -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 john at castleamber.com Mon Sep 27 23:29:46 2010 From: john at castleamber.com (John Bokma) Date: Mon, 27 Sep 2010 22:29:46 -0500 Subject: How to Deal with Xah Lee Spam/Abuse (was: toy list processing problem: collect similar terms) References: <7xzkv5hvv0.fsf@ruckus.brouhaha.com> Message-ID: <87bp7i8s0l.fsf_-_@castleamber.com> Seebs writes: > On 2010-09-26, Xah Lee wrote: >> On Sep 25, 11:17??pm, Paul Rubin wrote: >>> Python solution follows (earlier one with an error cancelled). ??All >>> crossposting removed since crossposting is a standard trolling tactic. > >> btw, i disagree about your remark on crossposting. > > You're wrong. FYI: Xah Lee is well known for his abuse of cross posting. Be happy that Google Groups limits the number of groups to crosspost to five. Related: his spamming behaviour has already resulted in Xah Lee having to look for another hosting provider [1]. Currently 1and1 provides him shelter, most likely carefully selected by Xah (as Google Groups) since 1and1 is not known for their spam fighting reputation nor clue. But one can only hope, so if you want to do something about this Xah thing, please report it with 1and1 and abuse at google.com. He won't learn respect from it, but maybe you end up being honored [2] on his collection of drivel [3]. In short: = don't reply to Xah Lee: at best it's a waste of time = if his post is abusive (crossposting to 5 groups just because you can is) report it with /and/ his hosting provider (since most of his posts are copy paste jobs of articles on his site just to drive traffic) and Google Groups (his Usenet provider of choice since they hardly do a thing about spam). [1] http://www.mail-archive.com/python-list at python.org/msg91631.html [2] http://www.google.com/search?q=site%3Axahlee.org%20bokma [3] What's sad is that some of its stuff is actually good/not bad. But tainted: Xah Lee is a spammer and a Usenet abuser. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From john at castleamber.com Mon Sep 27 23:36:27 2010 From: john at castleamber.com (John Bokma) Date: Mon, 27 Sep 2010 22:36:27 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> Message-ID: <877hi68rpg.fsf@castleamber.com> Seebs writes: > On 2010-09-26, J?rgen Exner wrote: >> It was livibetter who without any motivation or reasoning posted Python >> code in CLPM. > > Not exactly; he posted it in a crossposted thread, which happened to include > CLPM and other groups, including comp.lang.python. > > It is quite possible that he didn't know about the crossposting. Oh, he does. It has been Xah's game for years. > while I would agree that this would constitute a form of ignorance, I'd think > that, especially with how well some newsreading interfaces hide that detail, > I don't think it's really worth getting angry over. You think wrong. And Jurgen should have known better than to reply several times (but like too many people in cplm he posts for posting's sake, the main reason why I don't follow that group anymore). Xah has been doing this for many years and most of his posts are just made to drive traffic to his site (hence they are copy paste of articles on his site + link(s) to his site). It's Usenet abuse, on purpose. The reason it pisses off people is that nearly weekly it causes a lot of noise in newsgroups that are really better off without the noise (IMNSHO). See my other post on how to deal with this spammer. If you've missed it: report him for spamming, since that's what he does. It already made him have to move hosting providers once. While it's not going to stop him, it will cost him money. See: http://www.google.com/search?q=site%3Axahlee.org%20bokma While I am named in that article be assured that I was not the only one contacting dreamhost (+10 for doing this, btw). Quite some people contacted me via email that they also talked with Dreamhost. Just keep reporting this spammer, and maybe 1and1 will kick it out. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From prathibhag2k4 at gmail.com Mon Sep 27 23:54:24 2010 From: prathibhag2k4 at gmail.com (Prathibha G) Date: Tue, 28 Sep 2010 09:24:24 +0530 Subject: Example of exec_proxy Message-ID: Hi Team, I am very new to this python world. Below is my problem. I have a "Machine A" where i want to execute some commands(dos commands from command prompt), delete/create some files, delete/create some directories. All this i need to do from my local host. Is there a way which i can do? Can ayone help me in achieving this? I tried using WMI module, but it only starts the processes. It is not allowing me to execute commands/ work with files and directories. I got to see this EXEC_PROXY module but i find no examples of it which is used to connect to remote machine. Could any of you provide that? -- Thank You, Prathibha -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.milliken at gmail.com Mon Sep 27 23:57:09 2010 From: peter.milliken at gmail.com (Peter) Date: Mon, 27 Sep 2010 20:57:09 -0700 (PDT) Subject: Nautilus Python References: <4ca15385$0$28657$c3e8da3@news.astraweb.com> Message-ID: On Sep 28, 12:31?pm, Steven D'Aprano wrote: > On Mon, 27 Sep 2010 15:28:34 -0700, Eduardo Ribeiro wrote: > > But it doesn't work. > > What do you mean "doesn't work"? > > - It crashes the operating system; > - You get a core dump; > - You get an exception; > - It hangs forever, never doing anything; > - It does something unexpected; > - Something else? > > -- > Steven It seems to be a fairly absolute statement - so I would assume all of the above! :-) From usenet-nospam at seebs.net Tue Sep 28 00:18:38 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 04:18:38 GMT Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> Message-ID: On 2010-09-28, John Bokma wrote: > Seebs writes: >> On 2010-09-26, J?rgen Exner wrote: >>> It was livibetter who without any motivation or reasoning posted Python >>> code in CLPM. >> Not exactly; he posted it in a crossposted thread, which happened to include >> CLPM and other groups, including comp.lang.python. >> It is quite possible that he didn't know about the crossposting. > Oh, he does. It has been Xah's game for years. But did "livibetter" know about it? I wasn't defending Xah, who is indeed at the very least clueless and disruptive. But I was sort of defending the poster who was accused of posting Python code in CLPM, because that poster may not have understood the game. -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 john at castleamber.com Tue Sep 28 00:34:22 2010 From: john at castleamber.com (John Bokma) Date: Mon, 27 Sep 2010 23:34:22 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> Message-ID: <874odajxkh.fsf@castleamber.com> Seebs writes: fup set to poster > On 2010-09-28, John Bokma wrote: >> Seebs writes: >>> On 2010-09-26, J?rgen Exner wrote: >>>> It was livibetter who without any motivation or reasoning posted Python >>>> code in CLPM. > >>> Not exactly; he posted it in a crossposted thread, which happened to include >>> CLPM and other groups, including comp.lang.python. > >>> It is quite possible that he didn't know about the crossposting. > >> Oh, he does. It has been Xah's game for years. > > But did "livibetter" know about it? I wasn't defending Xah, who is indeed > at the very least clueless and disruptive. Heh, he's not clueless, the problem is that he knows exactly what he's doing. And like most spammers, very hard to get rid off. > But I was sort of defending > the poster who was accused of posting Python code in CLPM, because that > poster may not have understood the game. Ah, clear. Well, the problem is somewhat also in CLPM where people somehow have to reply to messages like this :-(. And I am sure Xah laughes his ass off each time it happens. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From oswald.harry at gmail.com Tue Sep 28 02:30:43 2010 From: oswald.harry at gmail.com (harryos) Date: Mon, 27 Sep 2010 23:30:43 -0700 (PDT) Subject: tix problem in ubuntu karmic Message-ID: <07faa482-ce42-4297-81f4-8e45aba58a2a@a4g2000prm.googlegroups.com> hi I posted this question in ubuntu users forum but no help was forthcoming.. I hope someone can help me here. I had been using jaunty as o.s and was coding in python 2.6. While using Tix widgets in my code I came across a bug as mentioned in https://bugs.launchpad.net/ubuntu/+source/tix/+bug/371720 Also ,there was a suggested fix http://skriticos.blogspot.com/2009/07/ubuntu-jaunty-904-python-tix-fi... After that I began to get segmentation fault when I ran the code!! So ,I thought upgrading to karmic would help .But even after the upgrade I am getting segmentation fault..I reinstalled python ,tk and tix through synaptic..Still the problem persists. The versions of packages installed are python =2.6.4-0ubuntu3 python-tk =2.6.3-0ubuntu1 tix =8.4.0-6ubuntu1 tix-dev =8.4.0-6ubuntu1 tk8.5 =8.5.7-1 tk8.4 =8.4.19-3 Can someone tell me how I can solve this problem? thanks, harry From wbrehaut at mcsnet.ca Tue Sep 28 02:38:44 2010 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Tue, 28 Sep 2010 00:38:44 -0600 Subject: Nautilus Python References: <4ca15385$0$28657$c3e8da3@news.astraweb.com> Message-ID: On Mon, 27 Sep 2010 20:57:09 -0700 (PDT), Peter wrote: >On Sep 28, 12:31?pm, Steven D'Aprano T... at cybersource.com.au> wrote: >> On Mon, 27 Sep 2010 15:28:34 -0700, Eduardo Ribeiro wrote: >> > But it doesn't work. >> >> What do you mean "doesn't work"? >> >> - It crashes the operating system; >> - You get a core dump; >> - You get an exception; >> - It hangs forever, never doing anything; >> - It does something unexpected; >> - Something else? >> >> -- >> Steven > >It seems to be a fairly absolute statement - so I would assume all of >the above! :-) I assume "None of the above." Each of the above requires doing some work, so if "doesn't work" implies "does no work", then the closest it could come to that is: - It terminates almost immediately* without producing any output. *Required, or it might have been doing some work and just forgot to output the results. wwwayne From wbrehaut at mcsnet.ca Tue Sep 28 03:36:09 2010 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Tue, 28 Sep 2010 01:36:09 -0600 Subject: Introducing Kids to Programming: 2 or 3? References: <20100927124544.1d9e2ba4@geekmail.INVALID> Message-ID: <9h63a6hkui7lq68aogr5js4n4urnaia94j@4ax.com> On Mon, 27 Sep 2010 12:45:44 -0400, Andreas Waldenburger wrote: >On Mon, 27 Sep 2010 17:48:06 +0200 Marco Gallotta > wrote: > >> Since these are kids, we feel the nice changes in 3 such as removing >> integer division will help in teaching. It will also remove confusion >> when they go to download Python and grab the latest version. Since >> they're just starting, chances are almost none will be hit by the >> limited library support for at least a year or two. > >That's your answer right there. > > >> They will, however, be hit by the confusion of seeing Python 2 code >> all over the web. > >Good point. Here is may suggestion: Make the kids aware of the 2/3 >issue as early as possible, but don't go into detail. === 8< === > Later on (once they know more programming constructs to >appreciate the differences), include another lecture, specifically on >the difference between Python 2 and Python 3. > >Disclaimer: I'm not an educator. Maybe this is horrible advice. Someone >with a better understanding of kids' and learner's minds please debunk >any nonsense I may have spouted here. The only obvious bit was assuming one should "lecture" to kids. Everything else sounds good. wwwayne >/W From sensorflo at gmail.com Tue Sep 28 04:10:07 2010 From: sensorflo at gmail.com (Florian Kaufmann) Date: Tue, 28 Sep 2010 01:10:07 -0700 (PDT) Subject: How to match where the search started? Message-ID: >From the documentation: 7.2.4. Regular Expression Objects, search(string[, pos[, endpos]]) ... the '^' pattern character matches at the real beginning of the string and at positions just after a newline, but not necessarily at the index where the search is to start.... But I'd like to do just that. In Emacs regexps, I think the closest equivalent would be \=. Then I could do something like that, and also find directly adjacent matches reo = re.compile( r'(\=|...)...' ); while True mo = reo.search(text,pos) if not mo: break ... Flo From sensorflo at gmail.com Tue Sep 28 04:20:24 2010 From: sensorflo at gmail.com (Florian Kaufmann) Date: Tue, 28 Sep 2010 01:20:24 -0700 (PDT) Subject: How to match where the search started? References: Message-ID: <21a28abc-28e7-4125-b705-41168d5eb419@a9g2000yqg.googlegroups.com> The thing is that the (\=|...) group is not really part of the match. I think this gives you more the idea what I want reo = re.compile( r'(\=|.)...' ); while True mo = reo.search(text,pos) if not mo: break if text[mo.start()] == '\\' # a pseudo match. continue after the backslash else # a real match. continue after the match From sensorflo at gmail.com Tue Sep 28 04:21:17 2010 From: sensorflo at gmail.com (Florian Kaufmann) Date: Tue, 28 Sep 2010 01:21:17 -0700 (PDT) Subject: How to match where the search started? References: Message-ID: The thing is that the (\=|...) group is not really part of the match. I think this gives you more the idea what I want reo = re.compile( r'(\=|.)...' ); while True mo = reo.search(text,pos) if not mo: break if text[mo.start()] == '\\' # a pseudo match. continue after the backslash else # a real match. continue after the match From malcolm.mclean5 at btinternet.com Tue Sep 28 05:13:19 2010 From: malcolm.mclean5 at btinternet.com (Malcolm McLean) Date: Tue, 28 Sep 2010 02:13:19 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <538865ac-87c0-4a2d-81bb-6050c6d5f9df@a9g2000yqg.googlegroups.com> On Sep 27, 7:46?pm, namekuseijin wrote: > On 27 set, 05:46, TheFlyingDutchman wrote: > > Fact is: almost all user data from the external words comes into > programs as strings. No typesystem or compiler handles this fact all > that graceful...- Hide quoted text - > You're right. C should have a much better library than it does for parsing user-supplied string input. The scanf() family of functions is fine for everyday use, but not robust enough for potentially hostile inputs. atoi() had to be replaced by strtol(), but there's a need for a higher-leve function built on strtol(). I wrote a generic commandline parser once, however it's almost impossible to achieve something that is both useable and 100% bulletproof. From alexleewalk at 163.com Tue Sep 28 05:27:31 2010 From: alexleewalk at 163.com (AlexWalk) Date: Tue, 28 Sep 2010 17:27:31 +0800 (CST) Subject: About __class__ of an int literal Message-ID: In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ of an int literal will raise a SyntaxException, while other literals will not. For example. 1.__class__ is an error, while 1.1.__class__ runs ok. I searched the python issue tracker but failed to find relevant reports. I wonder if this is an unreported issue. Alex Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: From malcolm.mclean5 at btinternet.com Tue Sep 28 05:55:19 2010 From: malcolm.mclean5 at btinternet.com (Malcolm McLean) Date: Tue, 28 Sep 2010 02:55:19 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) wrote: > > On the other hand, with the dynamic typing mindset, you might even wrap > your values (of whatever numerical type) in a symbolic expression > mentionning the unit and perhaps other meta data, so that when the other > module receives it, it may notice (dynamically) that two values are not > of the same unit, but if compatible, it could (dynamically) convert into > the expected unit. ?Mission saved! > I'd like to design a language like this. If you add a quantity in inches to a quantity in centimetres you get a quantity in (say) metres. If you multiply them together you get an area, if you divide them you get a dimeionless scalar. If you divide a quantity in metres by a quantity in seconds you get a velocity, if you try to subtract them you get an error. From rgrdev_ at gmail.com Tue Sep 28 06:10:26 2010 From: rgrdev_ at gmail.com (Richard) Date: Tue, 28 Sep 2010 12:10:26 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: Malcolm McLean writes: > On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. ?Mission saved! >> > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. > or simply use c++ etc and simply use overridden operators which pick the correct algorithm.... -- "Avoid hyperbole at all costs, its the most destructive argument on the planet" - Mark McIntyre in comp.lang.c From bc at freeuk.com Tue Sep 28 06:18:41 2010 From: bc at freeuk.com (BartC) Date: Tue, 28 Sep 2010 11:18:41 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: "Malcolm McLean" wrote in message news:1d6e115c-cada-46fc-9444-01e80e0afd75 at c10g2000yqh.googlegroups.com... > On Sep 27, 9:29 pm, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. Mission saved! >> > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. As you suggested in 'Varaibles with units' comp.programming Feb 16 2008? [Yes with that spelling...] I have a feeling that would quickly make programming impossible (if you consider how many combinations of dimensions/units, and operators there might be). One approach I've used is to specify a dimension (ie. unit) only for constant values, which are then immediately converted (at compile time) to a standard unit: a:=sin(60?) # becomes sin(1.047... radians) d:=6 ins # becomes 152.4 mm Here the standard units are radians, and mm. Every other calculation uses implied units. -- Bartc From antonyjeevaraj at gmail.com Tue Sep 28 06:19:39 2010 From: antonyjeevaraj at gmail.com (antony jeevaraj) Date: Tue, 28 Sep 2010 03:19:39 -0700 (PDT) Subject: HOW I MADE $2000 IN WEEKEND WITHOUT INVEST ANYTHING (YOU CAN TOO) Message-ID: HOW I MADE $2000 IN WEEKEND WITHOUT INVEST ANYTHING (YOU CAN TOO) Easy $2 per lead (Free Referral) + Referral Commission Today I receive a email from my friend that inform me about new Pay Per Lead that pay $2 per active member during their prelaunch. Tim bekker?s internet marketing guide is a new innovative, international free Membership system where members will be able to learn new methods to make money online with detailed step by step instructions Best of all this will be totally free, and you will have a chance to Earn extra money by doing Online marketing How do I earn money? At the moment you can earn $2.50 for every active friend you refer to this free internet guide using your personal referral link which can be found at your account. you will see this link in your account after joining this network http://snipurl.com/homeearnings What?s the cost? ?As a Member of this network, you never owe us a dime?that?s our responsibility to you. What?s the Minimum Payout? ?For Pay Pal its $20, for Bank Wire transfer to any country it?s $100 So what are you waiting for ? JOIN NOW!! Discover The Secrets That Earn Me $4,256.37 Everyday! Submit your primary email address below to get FREE money making tips NOW! Start Promote Earn $2.50 Per Lead http://snipurl.com/homeearnings From tfb at tfeb.org Tue Sep 28 06:19:55 2010 From: tfb at tfeb.org (Tim Bradshaw) Date: Tue, 28 Sep 2010 11:19:55 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On 2010-09-28 10:55:19 +0100, Malcolm McLean said: > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. There are several existing systems which do this. The HP48 (and descendants I expect) support "units" which are essentially dimensions. I don't remember if it signals errors for incoherent dimensions. Mathematica also has some units support, and it definitely does not indicate an error: "1 Inch + 1 Second" is fine. There are probably lots of other systems which do similar things. From antonyjeevaraj at gmail.com Tue Sep 28 06:20:33 2010 From: antonyjeevaraj at gmail.com (antony jeevaraj) Date: Tue, 28 Sep 2010 03:20:33 -0700 (PDT) Subject: HOW I MADE $2000 IN WEEKEND WITHOUT INVEST ANYTHING (YOU CAN TOO) Message-ID: <8ce32ff9-8b3d-4984-a48b-9ade3d811476@z28g2000yqh.googlegroups.com> HOW I MADE $2000 IN WEEKEND WITHOUT INVEST ANYTHING (YOU CAN TOO) Easy $2 per lead (Free Referral) + Referral Commission Today I receive a email from my friend that inform me about new Pay Per Lead that pay $2 per active member during their prelaunch. Tim bekker?s internet marketing guide is a new innovative, international free Membership system where members will be able to learn new methods to make money online with detailed step by step instructions Best of all this will be totally free, and you will have a chance to Earn extra money by doing Online marketing How do I earn money? At the moment you can earn $2.50 for every active friend you refer to this free internet guide using your personal referral link which can be found at your account. you will see this link in your account after joining this network http://snipurl.com/homeearnings What?s the cost? ?As a Member of this network, you never owe us a dime?that?s our responsibility to you. What?s the Minimum Payout? ?For Pay Pal its $20, for Bank Wire transfer to any country it?s $100 So what are you waiting for ? JOIN NOW!! Discover The Secrets That Earn Me $4,256.37 Everyday! Submit your primary email address below to get FREE money making tips NOW! Start Promote Earn $2.50 Per Lead http://snipurl.com/homeearnings From mail at timgolden.me.uk Tue Sep 28 06:24:34 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 28 Sep 2010 11:24:34 +0100 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: <4CA1C262.6080504@timgolden.me.uk> On 28/09/2010 10:27, AlexWalk wrote: > In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ of an int literal will raise a SyntaxException, while other literals will not. For example. 1.__class__ is an error, while 1.1.__class__ runs ok. > > > I searched the python issue tracker but failed to find relevant reports. I wonder if this is an unreported issue. It's a little bit subtle. The trouble is that the parser sees a number followed by a dot and assumes that it's looking at a decimal number. When the next thing isn't a number, it raises a SyntaxError exception. You can achieve what you're after by putting a space before the dot: 1 .__class__ TJG From albert at spenarnc.xs4all.nl Tue Sep 28 08:42:40 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 28 Sep 2010 12:42:40 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: In article <87fwwvrnmf.fsf at kuiper.lan.informatimago.com>, Pascal J. Bourguignon wrote: >namekuseijin writes: > >>> in C I can have a function maximum(int a, int b) that will always >>> work. Never blow up, and never give an invalid answer. If someone >>> tries to call it incorrectly it is a compile error. >>> In a dynamic typed language maximum(a, b) can be called with incorrect >>> datatypes. Even if I make it so it can handle many types as you did >>> above, it could still be inadvertantly called with a file handle for a >>> parameter or some other type not provided for. So does Eckel and >>> others, when they are writing their dynamically typed code advocate >>> just letting the function blow up or give a bogus answer, or do they >>> check for valid types passed? If they are checking for valid types it >>> would seem that any benefits gained by not specifying type are lost by >>> checking for type. And if they don't check for type it would seem that >>> their code's error handling is poor. >> >> that is a lie. >> >> Compilation only makes sure that values provided at compilation-time >> are of the right datatype. >> >> What happens though is that in the real world, pretty much all >> computation depends on user provided values at runtime. See where are >> we heading? >> >> this works at compilation time without warnings: >> int m=numbermax( 2, 6 ); >> >> this too: >> int a, b, m; >> scanf( "%d", &a ); >> scanf( "%d", &b ); >> m=numbermax( a, b ); >> >> no compiler issues, but will not work just as much as in python if >> user provides "foo" and "bar" for a and b... fail. >> >> What you do if you're feeling insecure and paranoid? Just what >> dynamically typed languages do: add runtime checks. Unit tests are >> great to assert those. >> >> Fact is: almost all user data from the external words comes into >> programs as strings. No typesystem or compiler handles this fact all >> that graceful... > > >I would even go further. > >Types are only part of the story. You may distinguish between integers >and floating points, fine. But what about distinguishing between >floating points representing lengths and floating points representing >volumes? Worse, what about distinguishing and converting floating >points representing lengths expressed in feets and floating points >representing lengths expressed in meters. When I was at Shell (late eighties) there were people claiming to have done exactly that, statically, in ADA. I would say the dimensional checking is underrated. It must be complemented with a hard and fast rule about only using standard (SI) units internally. Oil output internal : m^3/sec Oil output printed: kbarrels/day > >If you start with the mindset of static type checking, you will consider >that your types are checked and if the types at the interface of two >modules matches you'll think that everything's ok. And six months later >you Mars mission will crash. A mission failure is a failure of management. The Ariadne crash was. Management must take care that engineering mistakes don't lead to mission failure. In the Ariadne case it was not so much engineering mistakes, but management actually standing in the way of good engineering practice. >__Pascal Bourguignon__ http://www.informatimago.com/ Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From malcolm.mclean5 at btinternet.com Tue Sep 28 09:39:27 2010 From: malcolm.mclean5 at btinternet.com (Malcolm McLean) Date: Tue, 28 Sep 2010 06:39:27 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: <4836eb5b-94d8-46b5-8b2f-f5e6a1300464@h7g2000yqn.googlegroups.com> On Sep 28, 12:19?pm, Tim Bradshaw wrote: > > There are several existing systems which do this. ?The HP48 (and > descendants I expect) support "units" which are essentially dimensions. > ?I don't remember if it signals errors for incoherent dimensions. ? > Mathematica also has some units support, and it definitely does not > indicate an error: "1 Inch + 1 Second" is fine. ?There are probably > lots of other systems which do similar things. > The problem is that if you allow expressions rather than terms then the experssions can get arbitrarily complex. sqrt(1 inch + 1 Second), for instance. On the other hand sqrt(4 inches^2) is quite well defined. The question is whether to allow sqrt(1 inch). It means using rationals rather than integers for unit superscripts. (You can argue that you can get things like km^9s^-9g^3 even in a simple units system. The difference is that these won't occur very often in real programs, just when people are messing sbout with the system, and we don't need to make messing about efficient or easy to use). From thomas at jollybox.de Tue Sep 28 10:44:54 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Tue, 28 Sep 2010 16:44:54 +0200 Subject: How to match where the search started? In-Reply-To: References: Message-ID: <201009281644.55411.thomas@jollybox.de> On Tuesday 28 September 2010, it occurred to Florian Kaufmann to exclaim: > >From the documentation: > 7.2.4. Regular Expression Objects, search(string[, pos[, endpos]]) > ... the '^' pattern character matches at the real beginning of the > string and at positions just after a newline, but not necessarily at > the index where the search is to start.... > > But I'd like to do just that. In Emacs regexps, I think the closest > equivalent would be \=. Then I could do something like that, and also > find directly adjacent matches > > reo = re.compile( r'(\=|...)...' ); > while True > mo = reo.search(text,pos) > if not mo: break > ... > > Flo You could prefix your regexp with r'(.*?)' to create a match of stuff that is between the start of search and the start of the first thing you're interested in. (untested...) From tfb at tfeb.org Tue Sep 28 10:55:26 2010 From: tfb at tfeb.org (Tim Bradshaw) Date: Tue, 28 Sep 2010 15:55:26 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <4836eb5b-94d8-46b5-8b2f-f5e6a1300464@h7g2000yqn.googlegroups.com> Message-ID: On 2010-09-28 14:39:27 +0100, Malcolm McLean said: > he problem is that if you allow expressions rather than terms then > the experssions can get arbitrarily complex. sqrt(1 inch + 1 Second), > for instance. I can't imagine a context where 1 inch + 1 second would not be an error, so this is a slightly odd example. Indeed I think that in dimensional analysis summing (or comparing) things with different dimensions is always an error. > > On the other hand sqrt(4 inches^2) is quite well defined. The question > is whether to allow sqrt(1 inch). It means using rationals rather than > integers for unit superscripts. There's a large existing body of knowledge on dimensional analysis (it's a very important tool for physics, for instance), and obviously the answer is to do whatever it does. Raising to any power is fine, I think (but transcendental functions, for instance, are never fine, because they are equivalent to summing things with different dimensions, which is obvious if you think about the Taylor expansion of a transcendental function). --tim From python at mrabarnett.plus.com Tue Sep 28 11:07:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Sep 2010 16:07:47 +0100 Subject: How to match where the search started? In-Reply-To: References: Message-ID: <4CA204C3.903@mrabarnett.plus.com> On 28/09/2010 09:10, Florian Kaufmann wrote: >> From the documentation: > > 7.2.4. Regular Expression Objects, search(string[, pos[, endpos]]) > ... the '^' pattern character matches at the real beginning of the > string and at positions just after a newline, but not necessarily at > the index where the search is to start.... > > But I'd like to do just that. In Emacs regexps, I think the closest > equivalent would be \=. Then I could do something like that, and also > find directly adjacent matches > > reo = re.compile( r'(\=|...)...' ); > while True > mo = reo.search(text,pos) > if not mo: break > ... > If you want to anchor the regex at the start position 'pos' then use the 'match' method instead. From deets at web.de Tue Sep 28 11:11:29 2010 From: deets at web.de (Diez B. Roggisch) Date: Tue, 28 Sep 2010 17:11:29 +0200 Subject: relative imports and sub-module execution References: <73156baa-5774-45f9-a92c-50f9573eedd9@p24g2000pra.googlegroups.com> Message-ID: <874od9q4wu.fsf@web.de> King writes: > Hi, > > After reading couple of docs and articles, I have implemented a simple > test package with nested modules. > When running "main.py", everything is working fine. Some of my sub- > modules has some small test routines for debug purpose. > It's because I am using relative package imports at the top, I am not > able to run these sub modules individually. > > For example, this works when running from main.py > > Here is example structure > > main.py > __init__.py > core/ > __init__.py > folder1 > __init__.py > f1a.py > f1b.py > folder2 > __init__.py > f2a.py > f2b.py > > in folder2/f2b.py, I am importing > > from core.folder1 import f1a > print f1a.myvar > > Now I can't execute 'f2b.py' individually. It's giving an error: > > ImportError: No module named core.folder2 > > Is this mean when you have created a package where modules are using > relative imports, they can't execute individually? The problem is your python-path. Python will put the path of the script that you execute into the sys.path - but not attempt to guess that you actually are deep within a package hierarchy and want the path two up from there in sys.path as well. Which is the reason why you have to do that yourself. My solution to this is to always use setuptools, even for the tiniest of projects, and simply create a setup.py with some minimal information in it, and then do python setup.py develop This will put a EGG-link into the site-packages directory. Usually, for not clobbering my system's python, I use a virtualenv also. With this setup, I can safely import from "core" all the time. Diez From sensorflo at gmail.com Tue Sep 28 12:32:10 2010 From: sensorflo at gmail.com (Florian Kaufmann) Date: Tue, 28 Sep 2010 09:32:10 -0700 (PDT) Subject: How to match where the search started? References: Message-ID: > If you want to anchor the regex at the start position 'pos' then use > the 'match' method instead. The wickedly problem is that matching at position 'pos' is not a requirement, its an option. Look again at my 2nd example, the r'(\=|.)...' part, which (of course wrongly) assumes that \= means 'match at the beginning of the search'. Before the match I am really interested in, there is the start of the search, OR there is any character. From brian.curtin at gmail.com Tue Sep 28 12:33:24 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 28 Sep 2010 11:33:24 -0500 Subject: minimal D: need software testers In-Reply-To: <43bd55e3-e924-40b5-a157-b57ac8544b5f@f25g2000yqc.googlegroups.com> References: <43bd55e3-e924-40b5-a157-b57ac8544b5f@f25g2000yqc.googlegroups.com> Message-ID: On Mon, Sep 27, 2010 at 10:07, Kruptein wrote: > Hey, > > I've released the second alpha for minimal-D a program I've written in > python which should make developing easier. > I need people to test the app on bugs and give ideas. > > It is written in python using the wxPython toolkit and is linux-only. > (using on windows is on own risk) > > You can download a .deb or a .tar.gz from http://launchpad.net/minimal What type of testing do you currently do? -------------- next part -------------- An HTML attachment was scrubbed... URL: From niklas.holsti at tidorum.invalid Tue Sep 28 12:52:43 2010 From: niklas.holsti at tidorum.invalid (Niklas Holsti) Date: Tue, 28 Sep 2010 19:52:43 +0300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <8gekqrFnbnU1@mid.individual.net> Albert van der Horst wrote: > In article <87fwwvrnmf.fsf at kuiper.lan.informatimago.com>, ... >> I would even go further. >> >> Types are only part of the story. You may distinguish between integers >> and floating points, fine. But what about distinguishing between >> floating points representing lengths and floating points representing >> volumes? Worse, what about distinguishing and converting floating >> points representing lengths expressed in feets and floating points >> representing lengths expressed in meters. > > When I was at Shell (late eighties) there were people claiming > to have done exactly that, statically, in ADA. It is cumbersome to do it statically, in the current Ada standard. Doing it by run-time checks in overloaded operators is easier, but of course has some run-time overhead. There are proposals to extend Ada a bit to make a static check of physical units ("dimensions") simpler. See http://www.ada-auth.org/cgi-bin/cvsweb.cgi/acs/ac-00184.txt?rev=1.3&raw=Y and inparticular the part where Edmond Schonberg explains a suggestion for the GNAT Ada compiler. > A mission failure is a failure of management. The Ariadne crash was. Just a nit, the launcher is named "Ariane". -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ . From jeff.hobbs at gmail.com Tue Sep 28 13:24:11 2010 From: jeff.hobbs at gmail.com (Jeff Hobbs) Date: Tue, 28 Sep 2010 10:24:11 -0700 (PDT) Subject: tix problem in ubuntu karmic References: <07faa482-ce42-4297-81f4-8e45aba58a2a@a4g2000prm.googlegroups.com> Message-ID: <2b38fd3e-ee3c-4297-a8ed-43ebaf380987@p24g2000pra.googlegroups.com> On Sep 27, 11:30?pm, harryos wrote: > I had been using ?jaunty as o.s and was coding in python 2.6. While > using Tix widgets in my code I came across a bug as mentioned in > > https://bugs.launchpad.net/ubuntu/+source/tix/+bug/371720 ... > So ,I ?thought upgrading to karmic would help .But even after the > upgrade I am getting segmentation fault..I reinstalled python ,tk and > tix through synaptic..Still the problem persists. > > The versions of packages installed ?are > > python ? =2.6.4-0ubuntu3 > python-tk =2.6.3-0ubuntu1 > tk8.5 =8.5.7-1 > tk8.4 =8.4.19-3 > tix ?=8.4.0-6ubuntu1 > tix-dev =8.4.0-6ubuntu1 As the first link indicates, Tix 8.4.3 has this fixed, which is the latest stable version: https://sourceforge.net/projects/tix/files/ Try building that from source and using it in place of Tix 8.4.0 that you are currently using. Jeff From tar at sevak.isi.edu Tue Sep 28 13:28:08 2010 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 28 Sep 2010 10:28:08 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: Malcolm McLean writes: > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. Done in 1992. See citation at and my extension to it as part of the Loom system: -- Thomas A. Russ, USC/Information Sciences Institute From sylvain.thenault at logilab.fr Tue Sep 28 13:34:01 2010 From: sylvain.thenault at logilab.fr (Sylvain =?utf-8?B?VGjDqW5hdWx0?=) Date: Tue, 28 Sep 2010 19:34:01 +0200 Subject: [ANN] (probably) last version of Pylint supporting python 2.3 released Message-ID: <20100928173401.GM2916@lupus.logilab.fr> Hi there! As someone stuck with python 2.3 tried to use pylint, we made some fixes to get python 2.3 supports back. This resulted in the release of pylint 0.21.3, logilab-astng 0.20.3 and logilab-common 0.52 today. At the time of porting pylint to py3k, this will much probably be the latest set of versions to use to get pylint working with python 2.3 code. And maybe, unless you people think it would be a shame, also for python 2.4, so we can drop support for the old compiler module. ciao, -- Sylvain Th?nault LOGILAB, Paris (France) Formations Python, Debian, M?th. Agiles: http://www.logilab.fr/formations D?veloppement logiciel sur mesure: http://www.logilab.fr/services CubicWeb, the semantic web framework: http://www.cubicweb.org From xahlee at gmail.com Tue Sep 28 13:39:31 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 28 Sep 2010 10:39:31 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> <874odajxkh.fsf@castleamber.com> Message-ID: On Sep 27, 9:34?pm, John Bokma wrote: > Seebs writes: > > fup set to poster > > > On 2010-09-28, John Bokma wrote: > >> Seebs writes: > >>> On 2010-09-26, J?rgen Exner wrote: > >>>> It was livibetter who without any motivation or reasoning posted Python > >>>> code in CLPM. > > >>> Not exactly; he posted it in a crossposted thread, which happened to include > >>> CLPM and other groups, including comp.lang.python. > > >>> It is quite possible that he didn't know about the crossposting. > > >> Oh, he does. It has been Xah's game for years. > > > But did "livibetter" know about it? ?I wasn't defending Xah, who is indeed > > at the very least clueless and disruptive. > > Heh, he's not clueless, the problem is that he knows exactly what he's > doing. And like most spammers, very hard to get rid off. > > > But I was sort of defending > > the poster who was accused of posting Python code in CLPM, because that > > poster may not have understood the game. > > Ah, clear. Well, the problem is somewhat also in CLPM where people > somehow have to reply to messages like this :-(. And I am sure Xah > laughes his ass off each time it happens. Hi John Bokma, can you stop this? doesn't seems fruitful to keep on this. if you don't like my posts, ignore them? i don't post in comp.lang.python or comp.lang.perl.misc that often... maybe have done so 5 times this year. i visited your home page http://johnbokma.com/mexit/2010/08/15/ and there are really a lot beautiful photos. this isn't bribery or something like that. I've been annoyed by you, of course, but it's not fruitful to keep going on this. Best, Xah ? xahlee.org ? From python at mrabarnett.plus.com Tue Sep 28 13:54:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Sep 2010 18:54:05 +0100 Subject: How to match where the search started? In-Reply-To: References: Message-ID: <4CA22BBD.6020800@mrabarnett.plus.com> On 28/09/2010 17:32, Florian Kaufmann wrote: >> If you want to anchor the regex at the start position 'pos' then use >> the 'match' method instead. > > The wickedly problem is that matching at position 'pos' is not a > requirement, its an option. Look again at my 2nd example, the > r'(\=|.)...' part, which (of course wrongly) assumes that \= means > 'match at the beginning of the search'. Before the match I am really > interested in, there is the start of the search, OR there is any > character. An alternative is to use the 'regex' module, available from PyPI: http://pypi.python.org/pypi/regex It has \G, which is the anchor for the start position. From xahlee at gmail.com Tue Sep 28 13:56:55 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 28 Sep 2010 10:56:55 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> Message-ID: <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> xah wrote: > in anycase, how's ?do? not imperative? On Sep 28, 6:27?am, namekuseijin wrote: > > how's ?do? a ?named let?? can you show example or reference of that > > proposal? (is it worthwhile?) > > I'll post it again in the hope you'll read this time: > > " > (do ((i 0 (+ 1 i)) ?; i initially 1, (+ 1 i) at each "step" > ? ? ?(r 0 (+ i r))) ; r initially 0, (+ i r) at each "step" > ? ((> i 5) r)) ? ? ?; when i>5, return r > => 15 > > it's merely a macro (syntax) that gets transformed into this: > (let loop ((i 0) > ? ? ? ? ? ?(r 0)) > ? (if (> i 5) r > ? ? (loop (+ 1 i) (+ i r)))) > => 15 > > which is merely a macro that essentially gets transformed into this: > ((lambda (loop) > ? ?(loop loop 0 0)) > ?(lambda (loop i r) > ? ?(if (> i 5) r > ? ? ? ?(loop loop (+ 1 i) (+ i r))))) > => 15 > > which, as you can see, is merely function application. ?There's > nothing there except evaluation of arguments, application of arguments > to function and function return. ?It's not because they chose `do', or > `for' or `while' for naming such syntax, that it behaves the same as > their imperative homographs." > > > as i said, regarding do: ?do? in general in any lang is simply > > impreative. We don't even have to know the details. I don't care > > whatnot fuck proposal from whatnot lisp of what's actually going on. > > If it is named ?do?, it is imperative. > > It's not: ?one can name factorial do. ?It's just a name. ?Who doesn't > like do? ?It's short, to the point... ultimately, all lang gets transformed at the compiler level to become machine instructions, which is imperative programing in the ultimate sense. You say that ?do? is merely macro and ultimately function application. But to what level should we go down this chain on how the language actually works when evaluating a function in source code? any functional lang, quickly becomes imperative when compiled to some intermediate code or interpreted. In a sense, it can't be any other way. Functions are abstract mathematical ideas, while ?do? loop or any instruction are actual steps of algorithms. Xah ? xahlee.org ? From john at castleamber.com Tue Sep 28 14:13:27 2010 From: john at castleamber.com (John Bokma) Date: Tue, 28 Sep 2010 13:13:27 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> <874odajxkh.fsf@castleamber.com> Message-ID: <87bp7hybw8.fsf@castleamber.com> Xah Lee writes: > can you stop this? Can you stop crossposting? And if there is really, really a need to crosspost, can you please set the follow-up to? > doesn't seems fruitful to keep on this. > > if you don't like my posts, ignore them? i don't post in > comp.lang.python or comp.lang.perl.misc that often... maybe have done > so 5 times this year. Which is enough to disrupt those groups for days. > i visited your home page > http://johnbokma.com/mexit/2010/08/15/ > and there are really a lot beautiful photos. Thanks Xah. Like I wrote, your site /does/ have good information, it's so sad that you somehow think it's necessary to spam Usenet to get visitors. Or maybe you've another reason, don't know. But it /is/ Usenet abuse. > this isn't bribery or something like that. I've been annoyed by you, > of course, but it's not fruitful to keep going on this. Well, you annoy me, I annoy you. It's in your hands to make it stop. My advice is: 1) remove all the excessive swearing from your site. If you have a point, you don't need it. Your argument(s) without the swearing should speak for themselves 2) Stop abusing Usenet. Instead focus on writing more good stuff on your site. 1) & 2) will keep me from linking to your site, ever. And I am sure I am not alone in this. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From gneuner2 at comcast.net Tue Sep 28 14:21:29 2010 From: gneuner2 at comcast.net (George Neuner) Date: Tue, 28 Sep 2010 14:21:29 -0400 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: On 28 Sep 2010 12:42:40 GMT, Albert van der Horst wrote: >I would say the dimensional checking is underrated. It must be >complemented with a hard and fast rule about only using standard >(SI) units internally. > >Oil output internal : m^3/sec >Oil output printed: kbarrels/day "barrel" is not an SI unit. And when speaking about oil there isn't even a simple conversion. 42 US gallons ? 34.9723 imp gal ? 158.9873 L [In case those marks don't render, they are meant to be the double-tilda sign meaning "approximately equal".] George From python at mrabarnett.plus.com Tue Sep 28 14:40:19 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Sep 2010 19:40:19 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <4CA23693.3060605@mrabarnett.plus.com> On 28/09/2010 19:21, George Neuner wrote: > On 28 Sep 2010 12:42:40 GMT, Albert van der Horst > wrote: > >> I would say the dimensional checking is underrated. It must be >> complemented with a hard and fast rule about only using standard >> (SI) units internally. >> >> Oil output internal : m^3/sec >> Oil output printed: kbarrels/day > > "barrel" is not an SI unit. And when speaking about oil there isn't > even a simple conversion. > > 42 US gallons ? 34.9723 imp gal ? 158.9873 L > > [In case those marks don't render, they are meant to be the > double-tilda sign meaning "approximately equal".] > Do you mean: 42 US gallons ? 34.9723 imp gal ? 158.9873 l The post as I received it was encoded as 7-bit us-ascii, so definitely no double-tilde. This post was encoded as utf-8. From rog at pynguins.com Tue Sep 28 14:44:59 2010 From: rog at pynguins.com (Rog) Date: Tue, 28 Sep 2010 19:44:59 +0100 Subject: list problem... Message-ID: Hi all, Have been grappling with a list problem for hours... a = [2, 3, 4, 5,.....] b = [4, 8, 2, 6,.....] Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and b[2] is present. I have tried sets, zip etc with no success. I am tackling Euler projects with Python 3.1, with minimal knowledge, and having to tackle the language as I progress. Enjoyable frustration :) -- Rog http://www.rog.pynguins.com From emayssat at gmail.com Tue Sep 28 14:55:18 2010 From: emayssat at gmail.com (Toto) Date: Tue, 28 Sep 2010 11:55:18 -0700 (PDT) Subject: Reoedering indexes in list of list Message-ID: Hello, I have a list of list assume myList[x][y] is integer I would like to create an alias to that list which I could call this way: alias[y][x] returns myList[x][y] how can I do that ? (python 2.6) (I have a feeling I should use 'property' ;) Thanks, -- From anand.shashwat at gmail.com Tue Sep 28 14:55:27 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 29 Sep 2010 00:25:27 +0530 Subject: list problem... In-Reply-To: References: Message-ID: On Wed, Sep 29, 2010 at 12:14 AM, Rog wrote: > Hi all, > Have been grappling with a list problem for hours... > a = [2, 3, 4, 5,.....] > b = [4, 8, 2, 6,.....] > Basicly I am trying to place a[0], b[0] in a seperate list > IF a[2] and b[2] is present. > You are not exactly clear with your problem statement. Care to elaborate it more. > I have tried sets, zip etc with no success. > I am tackling Euler projects with Python 3.1, with minimal > knowledge, and having to tackle the language as I progress. > Enjoyable frustration :) > > -- > Rog > http://www.rog.pynguins.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Tue Sep 28 14:59:08 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 28 Sep 2010 11:59:08 -0700 Subject: list problem... In-Reply-To: References: Message-ID: On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > Hi all, > Have been grappling with a list problem for hours... > a = [2, 3, 4, 5,.....] > b = [4, 8, 2, 6,.....] > Basicly I am trying to place a[0], b[0] in a seperate list > IF a[2] and b[2] is present. > I have tried sets, zip etc with no success. > I am tackling Euler projects with Python 3.1, with minimal > knowledge, and having to tackle the language as I progress. > Enjoyable frustration ?:) I'm not clear on what your actual problem is, could you restate it? It sounds like you want to copy the ith element out of a and b into some other list- call it c- when the (i+2)th element meets some condition. What's the condition? Geremy Condra From clp2 at rebertia.com Tue Sep 28 15:10:26 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 28 Sep 2010 12:10:26 -0700 Subject: Reoedering indexes in list of list In-Reply-To: References: Message-ID: On Tue, Sep 28, 2010 at 11:55 AM, Toto wrote: > Hello, > > I have a list of list > assume myList[x][y] is integer > I would like to create an alias to that list which I could call this > way: > alias[y][x] returns myList[x][y] If your "alias" can be read-only: alias = zip(*myList) Cheers, Chris -- http://blog.rebertia.com From no.email at nospam.invalid Tue Sep 28 15:11:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 28 Sep 2010 12:11:39 -0700 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> <874odajxkh.fsf@castleamber.com> <87bp7hybw8.fsf@castleamber.com> Message-ID: <7xmxr1isyc.fsf@ruckus.brouhaha.com> John Bokma writes: > Xah Lee writes: ... > Can you stop crossposting? John, can you ALSO stop crossposting? From rog at pynguins.com Tue Sep 28 15:11:51 2010 From: rog at pynguins.com (Rog) Date: Tue, 28 Sep 2010 20:11:51 +0100 Subject: list problem... References: Message-ID: On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >> Hi all, >> Have been grappling with a list problem for hours... a = [2, 3, 4, >> 5,.....] >> b = [4, 8, 2, 6,.....] >> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and >> b[2] is present. >> I have tried sets, zip etc with no success. I am tackling Euler projects >> with Python 3.1, with minimal knowledge, and having to tackle the >> language as I progress. Enjoyable frustration ?:) > > I'm not clear on what your actual problem is, could you restate it? > > It sounds like you want to copy the ith element out of a and b into some > other list- call it c- when the (i+2)th element meets some condition. > What's the condition? > > Geremy Condra The condition is that the i-th element is inverted, but not equal. eg 4,2 - 2,4 , 34,5 - 5,34 etc. Hope that is clearer. Thanks for the response. -- Rog http://www.rog.pynguins.com From 3-nospam at temporary-address.org.uk Tue Sep 28 15:12:51 2010 From: 3-nospam at temporary-address.org.uk (Nick) Date: Tue, 28 Sep 2010 20:12:51 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: <87sk0tvg0c.fsf@temporary-address.org.uk> tar at sevak.isi.edu (Thomas A. Russ) writes: > Malcolm McLean writes: > >> I'd like to design a language like this. If you add a quantity in >> inches to a quantity in centimetres you get a quantity in (say) >> metres. If you multiply them together you get an area, if you divide >> them you get a dimeionless scalar. If you divide a quantity in metres >> by a quantity in seconds you get a velocity, if you try to subtract >> them you get an error. > > Done in 1992. > > See > > citation at > > and my extension to it as part of the Loom system: > I didn't go as far as that, but: $ cat test.can database input 'canal.sqlite' for i=link 'Braunston Turn' to '.*' print 'It is ';i.distance into 'distance:%M';' miles (which is '+i.distance into 'distance:%K'+' km) to ';i.place2 into 'name:place' end for i $ canal test.can It is 0.10 miles (which is 0.16 km) to London Road Bridge No 90 It is 0.08 miles (which is 0.13 km) to Bridge No 95 It is 0.19 miles (which is 0.30 km) to Braunston A45 Road Bridge No 91 -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk From kst-u at mib.org Tue Sep 28 15:15:07 2010 From: kst-u at mib.org (Keith Thompson) Date: Tue, 28 Sep 2010 12:15:07 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: George Neuner writes: > On 28 Sep 2010 12:42:40 GMT, Albert van der Horst > wrote: >>I would say the dimensional checking is underrated. It must be >>complemented with a hard and fast rule about only using standard >>(SI) units internally. >> >>Oil output internal : m^3/sec >>Oil output printed: kbarrels/day > > "barrel" is not an SI unit. He didn't say it was. Internal calculations are done in SI units (in this case, m^3/sec); on output, the internal units can be converted to whatever is convenient. > And when speaking about oil there isn't > even a simple conversion. > > 42 US gallons ? 34.9723 imp gal ? 158.9873 L > > [In case those marks don't render, they are meant to be the > double-tilda sign meaning "approximately equal".] There are multiple different kinds of "barrels", but "barrels of oil" are (consistently, as far as I know) defined as 42 US liquid gallons. A US liquid gallon is, by definition, 231 cubic inches; an inch is, by definition, 0.0254 meter. So a barrel of oil is *exactly* 0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 kbarrels/day. (Please feel free to check my math.) That's admittedly a lot of digits, but there's no need for approximations (unless they're imposed by the numeric representation you're using). -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From emayssat at gmail.com Tue Sep 28 15:29:23 2010 From: emayssat at gmail.com (Toto) Date: Tue, 28 Sep 2010 12:29:23 -0700 (PDT) Subject: Reoedering indexes in list of list References: Message-ID: <7d4f519e-f1f4-494a-bf74-36669e236839@t5g2000prd.googlegroups.com> > If your "alias" can be read-only: > alias = zip(*myList) a=[['00','01'],['10','11']] l=zip(*a) print(l) returns... [('00', '10'), ('01', '11')] IS NOT AT ALL WHAT I WANT ;-) What I want is print a[1][0] '10' but print l[1][0] '01' notice the indexes of the list l are inverted... From nad at acm.org Tue Sep 28 15:30:29 2010 From: nad at acm.org (Ned Deily) Date: Tue, 28 Sep 2010 12:30:29 -0700 Subject: Python 2.7 installation problem References: Message-ID: In article , Ronald Guida wrote: > Sorry, I have one additional piece of information that might be helpful to > others. I have discovered that the *.so files that were not installed, were > actually installed to the ~/lib/python2.6/ folder instead of the > ~/lib/python2.7/ folder where they belong. > > On Sun, Sep 26, 2010 at 9:25 PM, Ronald Guida wrote: > > > Solved -- "make install" failed to actually install a subset of files. I > > had to manually copy them instead. > > > > Specifics: > > I started from /home/oddron/installers/python/Python-2.7/ and executed the > > usual commands: > > $ ./configure --prefix=$HOME > > $ make > > $ make install > > > > I have found that the installer failed to install the contents of > > "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", > > which contains *.so files. This explains why "import collections" would > > work from > > the built python in /home/oddron/installers/python/Python-2.7/, but would > > fail in the installed > > python in /home/oddron/bin/ . > > > > I manually copied the contents of > > "/home/oddron/installers/python/Python-2.7/build/lib.linux-i686-2.7/", > > to /home/oddron/lib/python2.7/ and now everything seems to work. Works for me on a current Debian "testing" system and elsewhere. Any problem in this area is almost surely due to contamination of the build environment by an environment variable setting or possibly something in $HOME/.pydistutils.cfg or not starting with a clean If you still have the build directory, examine the configured Makefile for suspicious values, particularly DESTSHARED. -- Ned Deily, nad at acm.org From emayssat at gmail.com Tue Sep 28 15:30:54 2010 From: emayssat at gmail.com (Toto) Date: Tue, 28 Sep 2010 12:30:54 -0700 (PDT) Subject: Reoedering indexes in list of list References: <7d4f519e-f1f4-494a-bf74-36669e236839@t5g2000prd.googlegroups.com> Message-ID: <03bb8b3d-6bdd-4f45-8f5f-ec14267bf5e4@g6g2000pro.googlegroups.com> again I want: alias[y][x] returns myList[x][y] > print a[1][0] > '10' > but print l[1][0] > '01' > > notice the indexes ?of the list l are inverted... From emayssat at gmail.com Tue Sep 28 15:34:57 2010 From: emayssat at gmail.com (Toto) Date: Tue, 28 Sep 2010 12:34:57 -0700 (PDT) Subject: Reoedering indexes in list of list References: <7d4f519e-f1f4-494a-bf74-36669e236839@t5g2000prd.googlegroups.com> <03bb8b3d-6bdd-4f45-8f5f-ec14267bf5e4@g6g2000pro.googlegroups.com> Message-ID: <422ddb9f-ea12-4e36-8b19-1312b93dceb0@g6g2000pro.googlegroups.com> heu.... the zip trick actually works... my mistake! From pjdelport at gmail.com Tue Sep 28 15:42:18 2010 From: pjdelport at gmail.com (Piet Delport) Date: Tue, 28 Sep 2010 21:42:18 +0200 Subject: [ctpug] Introducing Kids to Programming: 2 or 3? In-Reply-To: References: Message-ID: On Mon, Sep 27, 2010 at 5:48 PM, Marco Gallotta wrote: > > > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. This is really great news! Sounds like you guys have been doing an amazing job. As for your course notes and exercises, targeting 3.x sounds like the more productive choice: - As you point, many of the changes in 3.x make it directly more sensible and suitable for teaching purposes. The avoidance of 2.x's str/unicode confusion should be one of the biggest points for first-time programmers, but all the other special cases and legacy cruft that's been removed from 3.x will help reduce distractions to learning. - As Niel Muller points out, library compatibility with 3.x is relatively good, and will only grow with time, while 2.x will become increasingly unsupported. The fact that you'll probably have to stick for the next few years with the material you produce now should seal the deal in favor of targeting 3.x. - The students whose learning advances far enough that they want to play around with more involved Python libraries are also the ones for whom learning 2.x/3.x differences shouldn't pose any difficulty anymore: if they *really* hit a sticking point that requires the use of 2.x (for now), they can just use it, without having to saddle all beginning learners with it. I doubt that students will be confused much more by seeing 2.x code all over the web, though; it's not really any different to 2.x users seeing code that uses old-style classes, string exceptions, and so on. There's not much that can be done about this: at some point, interested learners will have to encounter old idioms and legacy code, regardless of the choice of 2.x or 3.x now. -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Tue Sep 28 15:46:58 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 28 Sep 2010 20:46:58 +0100 Subject: Reoedering indexes in list of list References: <7d4f519e-f1f4-494a-bf74-36669e236839@t5g2000prd.googlegroups.com> Message-ID: <87r5gdlkgd.fsf@gmail.com> Toto writes: >> If your "alias" can be read-only: >> alias = zip(*myList) > > > > a=[['00','01'],['10','11']] > l=zip(*a) > print(l) > > returns... [('00', '10'), ('01', '11')] > > IS NOT AT ALL WHAT I WANT ;-) > > What I want is > > print a[1][0] > '10' > but print l[1][0] > '01' > > notice the indexes of the list l are inverted... Ahem... >>> a = [['00', '01'], ['10', '11']] >>> l = zip(*a) >>> a[1][0] '10' >>> l[1][0] '01' Looks *exactly* like what you want to me. It doesn't take that long to check. -- Arnaud From sschwarzer at sschwarzer.net Tue Sep 28 16:07:09 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Tue, 28 Sep 2010 22:07:09 +0200 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: <4CA24AED.7000901@sschwarzer.net> Hello Alex, On 2010-09-28 11:27, AlexWalk wrote: > In python 3.1.2(I'm using windows edition, 32bit), > accessing __class__ of an int literal will raise a > SyntaxException, while other literals will not. For > example. 1.__class__ is an error, while 1.1.__class__ runs > ok. > > I searched the python issue tracker but failed to find > relevant reports. I wonder if this is an unreported > issue. It's nothing serious; the Python parser gets a bit confused and probably reads the dot as decimal point. If you use (1).__class__, you get what you expected. Stefan From hansmu at xs4all.nl Tue Sep 28 16:08:44 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 28 Sep 2010 22:08:44 +0200 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: <4ca24b73$0$41110$e4fe514c@news.xs4all.nl> Tim Golden wrote: > On 28/09/2010 10:27, AlexWalk wrote: >> In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ >> of an int literal will raise a SyntaxException, while other literals >> will not. For example. 1.__class__ is an error, while 1.1.__class__ >> runs ok. >> >> >> I searched the python issue tracker but failed to find relevant >> reports. I wonder if this is an unreported issue. > > It's a little bit subtle. The trouble is that the parser > sees a number followed by a dot and assumes that it's looking > at a decimal number. When the next thing isn't a number, it > raises a SyntaxError exception. > > You can achieve what you're after by putting a space before the dot: > > 1 .__class__ Alternatively, you can use parenthesis: (1).__class__ Some people find one solution uglier than the other. -- HansM From anand.shashwat at gmail.com Tue Sep 28 16:09:42 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 29 Sep 2010 01:39:42 +0530 Subject: list problem... In-Reply-To: <4CA245DB.7080609@pynguins.com> References: <4CA245DB.7080609@pynguins.com> Message-ID: On Wed, Sep 29, 2010 at 1:15 AM, rog wrote: > Shashwat Anand wrote: > > >> >> On Wed, Sep 29, 2010 at 12:14 AM, Rog > rog at pynguins.com>> wrote: >> >> Hi all, >> Have been grappling with a list problem for hours... >> a = [2, 3, 4, 5,.....] >> b = [4, 8, 2, 6,.....] >> Basicly I am trying to place a[0], b[0] in a seperate list >> IF a[2] and b[2] is present. >> >> >> You are not exactly clear with your problem statement. >> Care to elaborate it more. >> >> I have tried sets, zip etc with no success. >> I am tackling Euler projects with Python 3.1, with minimal >> knowledge, and having to tackle the language as I progress. >> Enjoyable frustration :) >> >> -- >> Rog >> http://www.rog.pynguins.com >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> >> -- >> ~l0nwlf >> > > "Let d(/n/) be defined as the sum of proper divisors of /n/ (numbers less > than /n/ which divide evenly into /n/). > If d(/a/) = /b/ and d(/b/) = /a/, where /a/ ? /b/, then /a/ and /b/ are an > amicable pair and each of /a/ and /b/ are called amicable numbers. > > For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, > 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, > 71 and 142; so d(284) = 220. > > Evaluate the sum of all the amicable numbers under 10000." > > from Project Euler. > I have all answers contained in two lists but need to extract the amicable > pairs. > eg > a = [200, 4, 284,.....] > b = [284, 9, 200, ......] > Hope that helps. > Thanks for the link. > I am not sure how and what you managed, but what I understand you need to calculate sum of divisors. A quick unoptimized solution can be, >>> def divsum(n):return sum(i for i in range(1, n) if not n % i)... >>> divsum(220)284>>> divsum(284)220 Now all is left is looping and little maths, since upper bound is not high, brute force is Ok. http://codepad.org/g6PRyoiV # For reference Also I guess you missed 'Reply All', please take care of it next time. > Rog > > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Tue Sep 28 16:12:56 2010 From: john at castleamber.com (John Bokma) Date: Tue, 28 Sep 2010 15:12:56 -0500 Subject: toy list processing problem: collect similar terms References: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com> <87y6ao9wgo.fsf@castleamber.com> <877hi68rpg.fsf@castleamber.com> <874odajxkh.fsf@castleamber.com> <87bp7hybw8.fsf@castleamber.com> <7xmxr1isyc.fsf@ruckus.brouhaha.com> Message-ID: <8739sty6d3.fsf@castleamber.com> Paul Rubin writes: > John Bokma writes: >> Xah Lee writes: ... >> Can you stop crossposting? > > John, can you ALSO stop crossposting? Since the issue is on-topic in all groups: no. I did set a follow-up header, which you ignored and on top of that redirected the thing to comp.lang.python. So: Paul, can you ALSO stop acting like a complete ass? -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From irmen.NOSPAM at xs4all.nl Tue Sep 28 16:30:58 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 28 Sep 2010 22:30:58 +0200 Subject: Pyro 4.2 released Message-ID: <4ca25083$0$41112$e4fe514c@news.xs4all.nl> Pyro 4.2 --------- I'm pleased to announce the release of Pyro 4.2! Detailed info here: http://www.razorvine.net/python/Pyro Download here: http://www.xs4all.nl/~irmen/pyro4/download/ Python package index entry: http://pypi.python.org/pypi/Pyro4 License: MIT software license. Note: Pyro 4 is not finalized, this is still a beta release. Changes ------- The most important changes compared to Pyro 4.1 are: - toplevel package renamed to Pyro4 to allow parallel installation of Pyro 3.x and Pyro4 - python 3.x compatibility What is Pyro? ------------- PYthon Remote Objects provides a very easy way of remote communication between python objects somewhere in a network. It enables you to do remote method calls on objects as if they were normal local objects. Objects can be located by a direct identifier or indirectly by logical, humanly-readable names that are managed in a name server. Pyro is designed to be simple (but powerful) so it's only a manner of adding a few lines of code to ignite your objects. Simple example: http://www.razorvine.net/python/Pyro/Example Enjoy, Irmen de Jong From digitig at gmail.com Tue Sep 28 16:58:58 2010 From: digitig at gmail.com (Tim Rowe) Date: Tue, 28 Sep 2010 21:58:58 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: On 27 September 2010 18:46, namekuseijin wrote: > Fact is: ?almost all user data from the external words comes into > programs as strings. Sorry, sent this to the individual, not the group. I'd be very surprised if that were true. I suspect the majority of programs are in embedded systems, and they will get their "user data" come straight from the hardware. I doubt the engine controller in your car or the computer inside your TV pass much data around as strings. Of course, Python probably isn't the ideal language for real-time embedded systems (I expect an advocate will be along in a moment to tell me I'm wrong) but it's important to remember that the desktop isn't the be-all and end-all of computing. For what it's worth, all the research I've seen has found that compile-time checking and testing tend to catch different bugs, so if correctness is really important to you then you'll want both. The truth of the matter is that correctness is only one factor in the equation, and cost is another. Python tilts the balance in favour of cost -- it's really fast to develop in Python compared to some other languages, but you lose compiler checks. That's the right balance for a lot of applications, but not for all. If it's really critical that the program be correct then you'll want a bondage-and-discipline language that does masses of check, you might even do separate static analysis, and you'll *still* do all the dynamic testing you would have in Python. -- Tim Rowe From bthate at gmail.com Tue Sep 28 17:15:25 2010 From: bthate at gmail.com (Bart Thate) Date: Tue, 28 Sep 2010 14:15:25 -0700 (PDT) Subject: JSONBOT 0.4 RELEASED Message-ID: <14f0bdf5-5471-4927-b632-09bc027207cc@30g2000yqm.googlegroups.com> Yesterday i pushed version 0.4 of JSONBOT to pypi and googlecode. This version has a rewritten core that makes it easier to develop bots for and has lots of bugs fixed. A karma plugin was added as well as a silent mode that forwards bot responses to /msg. You can grab a copy on http://jsonbot.googlecode.com or use the mercurial reposistory: "hg clone http://jsonbot.googlecode.com/hg jsonbot". please file any bugs reports at http://code.google.com/p/jsonbot/issues/list we are at #dunkbots on freenode and IRCnet. Have fun ! about JSONBOT: JSONBOT is a remote event-driven framework for building bots that talk JSON to each other over XMPP. IRC/Console/XMPP (shell) Wave/Web/XMPP (GAE) implementations provided. From max at alcyone.com Tue Sep 28 18:02:10 2010 From: max at alcyone.com (Erik Max Francis) Date: Tue, 28 Sep 2010 15:02:10 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Malcolm McLean wrote: > On Sep 27, 9:29 pm, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. Mission saved! >> > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. There are already numerous libraries that help you with this kind of things in various languages; Python (you're crossposting to comp.lang.python), for instance, has several, such as Unum, and including one I've written but not yet released. It's not clear why one would need this built into the language: >>> print si kg m s A K cd mol >>> length = 3*si.in_ # underscore is needed since `in` is a keyword >>> print length 3.0 in_ >>> lengthInCentimeters = length.convert(si.cm) >>> print lengthInCentimeters 7.62 cm >>> area = lengthInCentimeters*lengthInCentimeters >>> print area 58.0644 cm**2 >>> biggerArea = 10.0*area >>> ratio = area/biggerArea >>> print ratio 0.1 >>> speed = (3.0*si.m)/(1.5*si.s) >>> print speed 2.0 m/s >>> ratio - speed Traceback (most recent call last): File "", line 1, in ? File "unity.py", line 218, in __sub__ converted = other.convert(self.strip()) File "unity.py", line 151, in convert raise IncompatibleUnitsError, "%r and %r do not have compatible units" % (self, other) __main__.IncompatibleUnitsError: and do not have compatible units And everybody's favorite: >>> print ((epsilon_0*mu_0)**-0.5).simplify() 299792458.011 m/s >>> print c # floating point accuracy aside 299792458.0 m/s -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis In Heaven all the interesting people are missing. -- Friedrich Nietzsche From ndonohue at gmail.com Tue Sep 28 18:02:14 2010 From: ndonohue at gmail.com (Nick Donohue) Date: Tue, 28 Sep 2010 15:02:14 -0700 (PDT) Subject: function decorators Message-ID: I came across this code just now: def time_me(function): def wrap(*arg): start = time.time() r = function(*arg) end = time.time() print "%s (%0.3f ms)" %(function.func_name, (end-start)*1000) return wrap @time_me def some_function(somearg) some_function(arg) I've been looking online about what I think is going on, and from what I can tell this code is using function decorators. I guess what I'm asking is if someone could tell me what exactly is going on in this code - how is it different from passing: time_me(some_function(123))? I've tried it this way and it works. why would I use these? wouldn't it be more flexible to not write the decorator before the function definition, so I could choose to wrap it or not? thanks From usenet-nospam at seebs.net Tue Sep 28 18:12:47 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 22:12:47 GMT Subject: function decorators References: Message-ID: On 2010-09-28, Nick Donohue wrote: > why would I use these? wouldn't it be more flexible to not write the > decorator before the function definition, so I could choose to wrap it > or not? The utility is that it lets you modify all calls to a function at once, without changing all the instances in a ton of source code. -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 deets at web.de Tue Sep 28 18:24:45 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 29 Sep 2010 00:24:45 +0200 Subject: function decorators References: Message-ID: Nick Donohue writes: > I came across this code just now: > > def time_me(function): > def wrap(*arg): > start = time.time() > r = function(*arg) > end = time.time() > print "%s (%0.3f ms)" %(function.func_name, (end-start)*1000) > return wrap > > @time_me > def some_function(somearg) > > some_function(arg) > > I've been looking online about what I think is going on, and from what > I can tell this code is using function decorators. > > I guess what I'm asking is if someone could tell me what exactly is > going on in this code - how is it different from passing: > time_me(some_function(123))? I've tried it this way and it works. This is *not* what the decorator is doing. The equivalent of a decorator and then calling the result is this: >>> some_function = time_me(some_function) >>> some_function(123) Notice the difference? The decorator (a badly written one, by the way - it doesn't deal with a possible return value and keyword args) wraps the function into time measuring code. In general, a decorator is a callable that takes one argument. And whatever that callable returns is then bound under the same name as the original function (or class, since python 2.6 I believe) Which is what >>> some_function = time_me(some_function) actually does. So decorator syntax with the @ is really just that - a bit of syntactic sugar. > why would I use these? wouldn't it be more flexible to not write the > decorator before the function definition, so I could choose to wrap it > or not? Of course it's more flexible to do whatever the decorator does only if you need it. If you need that, it's a sign of a misuse of decorators. Their strength is in making boiler-plate code run without you having to type it out all the time. E.g. putting transactional boundaries around some code that deals with a database. Checking for proper authentication and authorization. Uniformely deal with exceptions. And so forth. Amongst the more popular decorators in python are the classmethod and property decorators. Go look them up in the stdlib. Diez From ian.g.kelly at gmail.com Tue Sep 28 18:28:21 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Sep 2010 16:28:21 -0600 Subject: function decorators In-Reply-To: References: Message-ID: On Tue, Sep 28, 2010 at 4:02 PM, Nick Donohue wrote: > I came across this code just now: > > def time_me(function): > def wrap(*arg): > start = time.time() > r = function(*arg) > end = time.time() > print "%s (%0.3f ms)" %(function.func_name, (end-start)*1000) > return wrap > > @time_me > def some_function(somearg) > > some_function(arg) > > I've been looking online about what I think is going on, and from what > I can tell this code is using function decorators. > > I guess what I'm asking is if someone could tell me what exactly is > going on in this code - how is it different from passing: > time_me(some_function(123))? I've tried it this way and it works. > Not quite. It's actually equivalent to calling time_me(some_function)(123). > why would I use these? wouldn't it be more flexible to not write the > decorator before the function definition, so I could choose to wrap it > or not? > In general, yes. In the particular case above, I don't know why it would have been written as a decorator, unless it was merely meant to be toy code. Generally I'll use a decorator in order to add common functionality that is critical to the function's operation. Dynamically adding a default keyword argument is one example that comes to mind, or wrapping the function in a context manager without adding indentation to the entire function body. Also, decorators can also be used for things besides wrapping functions, such as registering them with a framework. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From hidura at gmail.com Tue Sep 28 18:31:28 2010 From: hidura at gmail.com (Hidura) Date: Tue, 28 Sep 2010 19:31:28 -0300 Subject: Upload files with wsgi Message-ID: Hello, i have a project on Python3k, and i have a very big problem i don' t find how take an upload file i am using the wsgiref lib, and or theres any way to connect to the client in order to get the file by myself? Thank you Diego Hidalgo. -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From xahlee at gmail.com Tue Sep 28 18:38:23 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 28 Sep 2010 15:38:23 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> Message-ID: <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> 2010-09-28 On Sep 28, 12:07?pm, namekuseijin wrote: > On 28 set, 14:56, Xah Lee wrote: > > > ultimately, all lang gets transformed at the compiler level to become > > machine instructions, which is imperative programing in the ultimate > > sense. > > > You say that ?do? is merely macro and ultimately function application. > > But to what level should we go down this chain on how the language > > actually works when evaluating a function in source code? > > > any functional lang, quickly becomes imperative when compiled to some > > intermediate code or interpreted. In a sense, it can't be any other > > way. Functions are abstract mathematical ideas, while ?do? loop or any > > instruction are actual steps of algorithms. > > That is true as of Mathematica too. ?Difference being that do in > scheme is pretty-much user-level syntax. ?If you look in most (good) > implementations sources, do and let are defined in scheme itself, not > C or lower-level: ?C code only deals with transforming lambda > application and tail calls into proper gotos. > > So, as far as we're talking about scheme, haskell or Mathematica code, > it's all functional in its abstraction context. > > do syntax does allow for imperative commands to be issued in scheme, > just like let. ?It does not mean it was used in said examples nor that > do is automatically inherently imperative just because of choice of > name. ?imperative do -> (do (steppers ...) (final-condition? result) > malign-imperative-code-here ...) > > so, now that we got it clear why do in scheme is not (inherently) > imperative why were you bashing useful (at times) functional syntax in > the form of list comprehensions again? le's get precise. The argument i want to make, is this: ? ?list comprehension? is a very bad jargon; thus harmful to functional programing or programing in general. Being a bad jargon, it encourage mis-communication, mis-understanding. ? ?list comprehension? is a redundant concept in programing. The concept is of historical interest. e.g. when people talk about the history of computer languages. The LC can simply be filter(map(func, list), predicate). ? The special syntax of ?list comprehension? as it exists in many langs, are not necessary. It can simply be a plain function, e.g LC(function, list, filter). I gave a stand-alone explanation of these points at: http://groups.google.com/group/comp.lang.lisp/msg/329b3b68ff034453 Do you disagree or agree with the above? This is the point _I_ want to argue about, but you don't seem to admit any part of it, but you seems to want to discuss about ?do? in Scheme lisp being functional. So, perhaps we can now focus on this subject: The ?do? in Scheme lisp is not imperative, or, it can be considered as functional. Alright. To be honest, i haven't had enough experience to comment on, but in general, i understand the example you've given, and i disagree. Full report on your argument on this is given at: http://groups.google.com/group/comp.lang.lisp/msg/87a987070e80231f Now, in your message (quoted above), you made further argument on this. I think the main point is this, quote: ?do syntax does allow for imperative commands to be issued in scheme, just like let. It does not mean it was used in said examples nor that do is automatically inherently imperative just because of choice of name. imperative do -> (do (steppers ...) (final-condition? result) malign-imperative-code-here ...)? i don't think your argument is forceful enough. It appears that by this argument you even say that ?let? is not functional. Here, the issue verges on what is functional? What is a function? If a function in lisp is defined as macro, does it ceases to be considered as a function? Likewise, if a lisp's has ?for? loop that is defined as a macro, is that ?for? now considered a function? this is getting quite iffy. What level or aspect are we considering? In each lang, usually they define certain terms specifically to the lang, and to various degree of precision. For eample, the term ?object? means very different things in a technical way in different langs. Same for the word ?function?, ?keyword?, ?command?, ?module?, ?package? ... So, overall, i consider your argument for ?do? in Scheme lisp being functional is weak, or trivial. It seems to be a pet peeve. You got annoyed because i seem to have ignored it entirely. But i got annoyed by you because you don't get the point about what i consider more significant opinion on ?list comprehension?, which you totally ignored and kept at hacking the ?do? in Scheme lisp. Xah ? xahlee.org ? From nagle at animats.com Tue Sep 28 18:41:52 2010 From: nagle at animats.com (John Nagle) Date: Tue, 28 Sep 2010 15:41:52 -0700 Subject: Upload files with wsgi In-Reply-To: References: Message-ID: <4ca26f3c$0$1675$742ec2ed@news.sonic.net> On 9/28/2010 3:31 PM, Hidura wrote: > Hello, i have a project on Python3k, and i have a very big problem i > don' t find how take an upload file i am using the wsgiref lib, and or > theres any way to connect to the client in order to get the file by > myself? > > Thank you > Diego Hidalgo. This is not clear. Are you trying to upload a Python program to a server, where a web server will run it in response to web requests? Or what? Does this involve an Apache server? John Nagle From kst-u at mib.org Tue Sep 28 18:51:14 2010 From: kst-u at mib.org (Keith Thompson) Date: Tue, 28 Sep 2010 15:51:14 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Message-ID: Erik Max Francis writes: [...] > >>> print c # floating point accuracy aside > 299792458.0 m/s Actually, the speed of light is exactly 299792458.0 m/s by definition. (The meter and the second are defined in terms of the same wavelength of light; this was changed relatively recently.) -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From catphive at catphive.net Tue Sep 28 18:54:31 2010 From: catphive at catphive.net (Brendan Miller) Date: Tue, 28 Sep 2010 15:54:31 -0700 Subject: utf-8 and ctypes Message-ID: I'm using python 2.5. Currently I have some python bindings written in ctypes. On the C side, my strings are in utf-8. On the python side I use ctypes.c_char_p to convert my strings to python strings. However, this seems to break for non-ascii characters. It seems that characters not in the ascii subset of UTF-8 are discarded by c_char_p during the conversion, or at least they don't print out when I go to print the string. Does python not support utf-8 strings? Is there some other way I should be doing the conversion? Thanks, Brendan From no.email at please.post Tue Sep 28 18:57:08 2010 From: no.email at please.post (kj) Date: Tue, 28 Sep 2010 22:57:08 +0000 (UTC) Subject: partial sums problem Message-ID: The following attempt to get a list of partial sums fails: >>> s = 0 >>> [((s += t) and s) for t in range(1, 10)] File "", line 1 [((s += t) and s) for t in range(1, 10)] ^ SyntaxError: invalid syntax What's the best way to get a list of partial sums? TIA! kj From gherron at digipen.edu Tue Sep 28 19:29:50 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 28 Sep 2010 16:29:50 -0700 Subject: partial sums problem In-Reply-To: References: Message-ID: <4CA27A6E.3010008@digipen.edu> On 09/28/2010 03:57 PM, kj wrote: > > The following attempt to get a list of partial sums fails: > > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] >>>> > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > > What's the best way to get a list of partial sums? > > TIA! > > kj > Program in C (if that's what you want), or learn Python (if you'd prefer), but don't try to mix the two. Python does have "s+=t" as a statement, and it does have list comprehensions [... for ...] as expressions, but you cannot put a statement inside an expression. -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From hidura at gmail.com Tue Sep 28 19:30:30 2010 From: hidura at gmail.com (Hidura) Date: Tue, 28 Sep 2010 20:30:30 -0300 Subject: Upload files with wsgi In-Reply-To: <4ca26f3c$0$1675$742ec2ed@news.sonic.net> References: <4ca26f3c$0$1675$742ec2ed@news.sonic.net> Message-ID: I am trying to upload any type of file ext to an app written in Py3k, using Apache+mod_wsgi i can't use django or cherryPy because i manage the data in the request creating an xml to store the data from selected areas and send it to the server. I am using the wsgiref library to handle the request and the responses. 2010/9/28, John Nagle : > On 9/28/2010 3:31 PM, Hidura wrote: >> Hello, i have a project on Python3k, and i have a very big problem i >> don' t find how take an upload file i am using the wsgiref lib, and or >> theres any way to connect to the client in order to get the file by >> myself? >> >> Thank you >> Diego Hidalgo. > > This is not clear. > > Are you trying to upload a Python program to a server, where > a web server will run it in response to web requests? Or what? > > Does this involve an Apache server? > > John Nagle > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From python at mrabarnett.plus.com Tue Sep 28 19:33:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 00:33:12 +0100 Subject: utf-8 and ctypes In-Reply-To: References: Message-ID: <4CA27B38.4090502@mrabarnett.plus.com> On 28/09/2010 23:54, Brendan Miller wrote: > I'm using python 2.5. > > Currently I have some python bindings written in ctypes. On the C > side, my strings are in utf-8. On the python side I use > ctypes.c_char_p to convert my strings to python strings. However, this > seems to break for non-ascii characters. > > It seems that characters not in the ascii subset of UTF-8 are > discarded by c_char_p during the conversion, or at least they don't > print out when I go to print the string. > > Does python not support utf-8 strings? Is there some other way I > should be doing the conversion? > Python does support bytestrings (8 bits per character, 'str' in Python 2), so you should be getting all the bytes that comprise the UTF-8 string up to the terminating zero-byte). You then need to decode the string from UTF-8 to Unicode. From emile at fenx.com Tue Sep 28 19:35:16 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 28 Sep 2010 16:35:16 -0700 Subject: partial sums problem In-Reply-To: References: Message-ID: On 9/28/2010 3:57 PM kj said... > > > The following attempt to get a list of partial sums fails: > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > > What's the best way to get a list of partial sums? > I'm pretty sure the consensus isn't this... >>> R=[] >>> [ sum(R) for s in range(1,10) if not R.append(s) ] Emile From usenet-nospam at seebs.net Tue Sep 28 19:36:01 2010 From: usenet-nospam at seebs.net (Seebs) Date: 28 Sep 2010 23:36:01 GMT Subject: partial sums problem References: Message-ID: On 2010-09-28, Gary Herron wrote: > Python does have "s+=t" as a statement, and it does have list > comprehensions [... for ...] as expressions, but you cannot put a > statement inside an expression. I've inferred that, in Python, all assignments are by definition statements, rather than expressions, so they can't be arbitrarily substituted in for expressions. It's interesting to see the two ways in which people seem to go from C's middle ground of expressions and statements; some languages go to making statements into expressions, others go for even further narrowing the set of "expressions". I'm not yet sure which I prefer; both have some appeal in avoiding some of the occasional-complexity that can make C hard for people to learn. (Meaning, complexity which is only sometimes at issue, so you have to know about it, but you can't just use it all the time, so you can't assume it's how things work.) -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 python at mrabarnett.plus.com Tue Sep 28 19:36:03 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 00:36:03 +0100 Subject: partial sums problem In-Reply-To: References: Message-ID: <4CA27BE3.1060105@mrabarnett.plus.com> On 28/09/2010 23:57, kj wrote: > > > The following attempt to get a list of partial sums fails: > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > > What's the best way to get a list of partial sums? > Probably: s = 0 p = [] for t in range(1, 10): s += t p.append(s) From rpw3 at rpw3.org Tue Sep 28 19:52:11 2010 From: rpw3 at rpw3.org (Rob Warnock) Date: Tue, 28 Sep 2010 18:52:11 -0500 Subject: "Strong typing vs. strong testing" References: <4836eb5b-94d8-46b5-8b2f-f5e6a1300464@h7g2000yqn.googlegroups.com> Message-ID: EXECUTIVE SUMMARY: 1 inch + 1 second = ~4.03e38 grams. GORY DETAILS: Tim Bradshaw wrote: +--------------- | Malcolm McLean said: | > he problem is that if you allow expressions rather than terms then | > the experssions can get arbitrarily complex. sqrt(1 inch + 1 Second), | > for instance. | | I can't imagine a context where 1 inch + 1 second would not be an | error, so this is a slightly odd example. Indeed I think that in | dimensional analysis summing (or comparing) things with different | dimensions is always an error. +--------------- Unless you convert them to equivalent units first. For example, in relativistic or cosmological physics, one often uses a units basis wherein (almost) everything is scaled to "1": http://en.wikipedia.org/wiki/Natural_units When you set c = 1, then: Einstein's equation E = mc2 can be rewritten in Planck units as E = m. This equation means "The rest-energy of a particle, measured in Planck units of energy, equals the rest-mass of a particle, measured in Planck units of mass." See also: http://en.wikipedia.org/wiki/Planck_units ... The constants that Planck units, by definition, normalize to 1 are the: * Gravitational constant, G; * Reduced Planck constant, h-bar; [h/(2*pi)] * Speed of light in a vacuum, c; * Coulomb constant, 1/(4*pi*epsilon_0) (sometimes k_e or k); * Boltzmann's constant, k_B (sometimes k). This sometimes leads people to do things that would appear sloppy or even flat-out wrong in MKS or CGS units, such as expressing mass in terms of length: Consider the equation A=1e10 in Planck units. If A represents a length, then the equation means A=1.6e-25 meters. If A represents a mass, then the equation means A=220 kilograms. ... In fact, natural units are especially useful when this ambiguity is *deliberate*: For example, in special relativity space and time are so closely related that it can be useful to not specify whether a variable represents a distance or a time. So it is that we find that the mass of the Sun is 1.48 km or 4.93 us, see: http://en.wikipedia.org/wiki/Solar_mass#Related_units In this limited sense, then, one could convert both 1 inch and 1 second to masses[1], and *then* add them, hence: 1 inch + 1 second = ~4.03e38 grams. ;-} ;-} -Rob [1] 1 inch is "only" ~3.41e28 g, whereas 1 second is ~4.03e38 g, so the latter completely dominates in the sum. ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From ian.g.kelly at gmail.com Tue Sep 28 19:52:36 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Sep 2010 17:52:36 -0600 Subject: partial sums problem In-Reply-To: References: Message-ID: On Tue, Sep 28, 2010 at 4:57 PM, kj wrote: > > > The following attempt to get a list of partial sums fails: > > >>> s = 0 > >>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > Because in Python assignment is a statement, not an expression. What's the best way to get a list of partial sums? > sum = 0 sums = [] for t in range(1, 10): sum += t sums.append(sum) Or, if you prefer to keep it functional in nature: def append_sum(sums, x): return sums + [(sums[-1] if sums else 0) + x] reduce(append_sum, range(1, 10), []) Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Sep 28 20:19:03 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Sep 2010 20:19:03 -0400 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: On 9/28/2010 5:27 AM, AlexWalk wrote: > In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ > of an int literal will raise a SyntaxException, while other literals > will not. For example. 1.__class__ is an error, while 1.1.__class__ runs > ok. Third solution: >>> type(0) is 0 .__class__ True A person using instances of a class should seldom use special names directly. They are, in a sense, implementation details, even if documented. The idiom "if __name__ == '__main__':" is an exception. -- Terry Jan Reedy From clp2 at rebertia.com Tue Sep 28 20:32:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 28 Sep 2010 17:32:04 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On Tue, Sep 28, 2010 at 2:55 AM, Malcolm McLean wrote: > On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. ?Mission saved! >> > I'd like to design a language like this. If you add a quantity in > inches to a quantity in centimetres you get a quantity in (say) > metres. If you multiply them together you get an area, if you divide > them you get a dimeionless scalar. If you divide a quantity in metres > by a quantity in seconds you get a velocity, if you try to subtract > them you get an error. Sounds just like Frink: http://futureboy.us/frinkdocs/ http://en.wikipedia.org/wiki/Frink Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Tue Sep 28 20:57:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Sep 2010 20:57:16 -0400 Subject: function decorators In-Reply-To: References: Message-ID: On 9/28/2010 6:02 PM, Nick Donohue wrote: > I came across this code just now: > > def time_me(function): > def wrap(*arg): > start = time.time() > r = function(*arg) > end = time.time() > print "%s (%0.3f ms)" %(function.func_name, (end-start)*1000) > return wrap > > @time_me > def some_function(somearg) As others noted, this is an bad example of a decorator. Please forget it. Let us move on... #deco def func_name(*args): pass is syntactic sugar for (which is to say, is almost and for practical purposes is exactly equivalent to) def func_name(*args): pass func_name = deco(func_name) Indeed, Python did well without them until they were added. But there are 2 advantages of the decorator syntax: 1. Without it, one write (and read!) func_name 3 times instead of 1. One of the use cases that motivated decorators was a situation where someone was required to wrap numerous functions with stylized names about 30 chars long, like 'get_hopscotch_version_a_code_123x76' 2. Understanding the code may require that one know that it will never see the light of day as is. If the body is several lines, the wrapping call may be hard to see. To put it another way, the wrapping calls often belong near the doc string since they are part of a high-level overview of the function. -- Terry Jan Reedy From tjreedy at udel.edu Tue Sep 28 21:12:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Sep 2010 21:12:48 -0400 Subject: partial sums problem In-Reply-To: References: Message-ID: On 9/28/2010 6:57 PM, kj wrote: > > > The following attempt to get a list of partial sums fails: > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ > SyntaxError: invalid syntax > > What's the best way to get a list of partial sums? Do not try to do a reduction with a comprehension. Just write clear, straightforward code that obviously works. s=[1,2,3,4,5,6] def cusum(s): t = 0 for i in s: t += i yield t print(list(cusum(s))) >>> [1, 3, 6, 10, 15, 21] -- Terry Jan Reedy From zed.shaw at gmail.com Tue Sep 28 21:18:07 2010 From: zed.shaw at gmail.com (Zed Shaw) Date: Tue, 28 Sep 2010 18:18:07 -0700 Subject: Request For Comments: Learn Python The Hard Way Message-ID: Hi Everyone, I rarely post to the list, but I'm getting near the end of the book I wrote to help people learn Python and I would like some feedback on it if you please: * Web: http://learnpythonthehardway.org/ * PDF: http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf The book so far has been successful in teaching Python to people who couldn't learn it previously, but I have to still test it with real learners more extensively. It is also in rough draft form, so any grammar errors, spelling, or just plain wrong code/concepts/terms are possible. I'd appreciate if Python experts and newbies could read through the book or choice sections and submit tickets to me if you find errors: http://learnpythonthehardway.org/tktnew Which will require an anonymous login to cut down on spam in the tickets. I'd also appreciate discussion here on the list about the approach I took with the book and what you think. Thanks for your time. Zed P.S. The book is totally free so long as you don't charge for it and you don't change it or break it up. Thanks. From python at mrabarnett.plus.com Tue Sep 28 21:20:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 02:20:55 +0100 Subject: About __class__ of an int literal In-Reply-To: References: Message-ID: <4CA29477.5070304@mrabarnett.plus.com> On 29/09/2010 01:19, Terry Reedy wrote: > On 9/28/2010 5:27 AM, AlexWalk wrote: >> In python 3.1.2(I'm using windows edition, 32bit), accessing __class__ >> of an int literal will raise a SyntaxException, while other literals >> will not. For example. 1.__class__ is an error, while 1.1.__class__ runs >> ok. > > Third solution: > >>> type(0) is 0 .__class__ > True > > A person using instances of a class should seldom use special names > directly. They are, in a sense, implementation details, even if documented. > The idiom "if __name__ == '__main__':" is an exception. > __file__ is another exception. From msarro at gmail.com Tue Sep 28 21:22:55 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 28 Sep 2010 21:22:55 -0400 Subject: Request For Comments: Learn Python The Hard Way In-Reply-To: References: Message-ID: Cool idea! I'll gladly take a look and get back to you. -Matthew On Tue, Sep 28, 2010 at 9:18 PM, Zed Shaw wrote: > Hi Everyone, > > I rarely post to the list, but I'm getting near the end of the book I > wrote to help people learn Python and I would like some feedback on it > if you please: > > * Web: http://learnpythonthehardway.org/ > * PDF: http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf > > The book so far has been successful in teaching Python to people who > couldn't learn it previously, but I have to still test it with real > learners more extensively. It is also in rough draft form, so any > grammar errors, spelling, or just plain wrong code/concepts/terms are > possible. > > > I'd appreciate if Python experts and newbies could read through the > book or choice sections and submit tickets to me if you find errors: > > http://learnpythonthehardway.org/tktnew > > Which will require an anonymous login to cut down on spam in the tickets. > > I'd also appreciate discussion here on the list about the approach I > took with the book and what you think. > > > Thanks for your time. > > Zed > > P.S. The book is totally free so long as you don't charge for it and > you don't change it or break it up. Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gneuner2 at comcast.net Tue Sep 28 21:35:17 2010 From: gneuner2 at comcast.net (George Neuner) Date: Tue, 28 Sep 2010 21:35:17 -0400 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson wrote: >George Neuner writes: >> On 28 Sep 2010 12:42:40 GMT, Albert van der Horst >> wrote: >>>I would say the dimensional checking is underrated. It must be >>>complemented with a hard and fast rule about only using standard >>>(SI) units internally. >>> >>>Oil output internal : m^3/sec >>>Oil output printed: kbarrels/day >> >> "barrel" is not an SI unit. > >He didn't say it was. Internal calculations are done in SI units (in >this case, m^3/sec); on output, the internal units can be converted to >whatever is convenient. That's true. But it is a situation where the conversion to SI units loses precision and therefore probably shouldn't be done. > >> And when speaking about oil there isn't >> even a simple conversion. >> >> 42 US gallons ? 34.9723 imp gal ? 158.9873 L >> >> [In case those marks don't render, they are meant to be the >> double-tilda sign meaning "approximately equal".] > >There are multiple different kinds of "barrels", but "barrels of oil" >are (consistently, as far as I know) defined as 42 US liquid gallons. >A US liquid gallon is, by definition, 231 cubic inches; an inch >is, by definition, 0.0254 meter. So a barrel of oil is *exactly* >0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 >kbarrels/day. (Please feel free to check my math.) That's >admittedly a lot of digits, but there's no need for approximations >(unless they're imposed by the numeric representation you're using). I don't care to check it ... the fact that the SI unit involves 12 decimal places whereas the imperial unit involves 3 tells me the conversion probably shouldn't be done in a program that wants accuracy. George From hidura at gmail.com Tue Sep 28 23:22:48 2010 From: hidura at gmail.com (Hidura) Date: Wed, 29 Sep 2010 00:22:48 -0300 Subject: Example or recomendation of a webserver Message-ID: I am working on a web project written on Py3k and using mod_wsgi on the Apache that have to recibes the request client via a xml structure and i am facing a lot of troubles with the upload files mainly because i can' t see where they are, so i' ve decide to write my own web server-django and the others doen' t work for my propouse-, what you recomend me for start that? -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From usenet-nospam at seebs.net Wed Sep 29 00:34:04 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 04:34:04 GMT Subject: Example or recomendation of a webserver References: Message-ID: On 2010-09-29, Hidura wrote: > I am working on a web project written on Py3k and using mod_wsgi on > the Apache that have to recibes the request client via a xml structure > and i am facing a lot of troubles with the upload files mainly because > i can' t see where they are, so i' ve decide to write my own web > server-django and the others doen' t work for my propouse-, what you > recomend me for start that? I suggest learning to use one of the existing ones. The chances that, if you can't make the existing ones work, you can write something better, are usually pretty much nil. -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 max at alcyone.com Wed Sep 29 02:03:55 2010 From: max at alcyone.com (Erik Max Francis) Date: Tue, 28 Sep 2010 23:03:55 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Message-ID: Keith Thompson wrote: > Erik Max Francis writes: > [...] >> >>> print c # floating point accuracy aside >> 299792458.0 m/s > > Actually, the speed of light is exactly 299792458.0 m/s by > definition. (The meter and the second are defined in terms of the > same wavelength of light; this was changed relatively recently.) I know. Hence why I wrote the comment "floating point accuracy aside" when printing it. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis If the past sits in judgment on the present, the future will be lost. -- Winston Churchill From rustompmody at gmail.com Wed Sep 29 02:43:13 2010 From: rustompmody at gmail.com (rustom) Date: Tue, 28 Sep 2010 23:43:13 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On Sep 29, 5:32?am, Chris Rebert wrote: > On Tue, Sep 28, 2010 at 2:55 AM, Malcolm McLean > > > > wrote: > > On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) > > wrote: > >> On the other hand, with the dynamic typing mindset, you might even wrap > >> your values (of whatever numerical type) in a symbolic expression > >> mentionning the unit and perhaps other meta data, so that when the other > >> module receives it, it may notice (dynamically) that two values are not > >> of the same unit, but if compatible, it could (dynamically) convert into > >> the expected unit. ?Mission saved! > > > I'd like to design a language like this. If you add a quantity in > > inches to a quantity in centimetres you get a quantity in (say) > > metres. If you multiply them together you get an area, if you divide > > them you get a dimeionless scalar. If you divide a quantity in metres > > by a quantity in seconds you get a velocity, if you try to subtract > > them you get an error. > > Sounds just like Frink:http://futureboy.us/frinkdocs/http://en.wikipedia.org/wiki/Frink A currently developed language with units is curl: see http://developers.curl.com/userdocs/docs/en/dguide/quantities-basic.html From nospam at torek.net Wed Sep 29 02:59:42 2010 From: nospam at torek.net (Chris Torek) Date: 29 Sep 2010 06:59:42 GMT Subject: partial sums problem References: Message-ID: In article kj wrote: >The following attempt to get a list of partial sums fails: > >>>> s = 0 >>>> [((s += t) and s) for t in range(1, 10)] > File "", line 1 > [((s += t) and s) for t in range(1, 10)] > ^ >SyntaxError: invalid syntax > >What's the best way to get a list of partial sums? Well, define "best"; but curiously enough, I wrote this just a few days ago for other purposes, so here you go, a slightly cleaned-up / better documented version of what I wrote: def iaccumulate(vec, op): """Do an accumulative operation on a vector (any iterable, really). The result is a generator whose first call produces vec[0], second call produces vec[0] op vec[1], third produces (vec[0] op vec[1]) op vec[2], and so on. Mostly useful with + and *, probably. """ iterable = iter(vec) acc = iterable.next() yield acc for x in iterable: acc = op(acc, x) yield acc def cumsum(vec): """Return a list of the cumulative sums of a vector.""" import operator return list(iaccumulate(vec, operator.add)) -- 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 clp2 at rebertia.com Wed Sep 29 03:14:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 29 Sep 2010 00:14:35 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On Tue, Sep 28, 2010 at 11:43 PM, rustom wrote: > On Sep 29, 5:32?am, Chris Rebert wrote: >> On Tue, Sep 28, 2010 at 2:55 AM, Malcolm McLean >> wrote: >> > On Sep 27, 9:29?pm, p... at informatimago.com (Pascal J. Bourguignon) >> > wrote: >> >> On the other hand, with the dynamic typing mindset, you might even wrap >> >> your values (of whatever numerical type) in a symbolic expression >> >> mentionning the unit and perhaps other meta data, so that when the other >> >> module receives it, it may notice (dynamically) that two values are not >> >> of the same unit, but if compatible, it could (dynamically) convert into >> >> the expected unit. ?Mission saved! >> >> > I'd like to design a language like this. If you add a quantity in >> > inches to a quantity in centimetres you get a quantity in (say) >> > metres. If you multiply them together you get an area, if you divide >> > them you get a dimeionless scalar. If you divide a quantity in metres >> > by a quantity in seconds you get a velocity, if you try to subtract >> > them you get an error. >> >> Sounds just like Frink: >> http://futureboy.us/frinkdocs/ > > A currently developed language with units is curl: see > http://developers.curl.com/userdocs/docs/en/dguide/quantities-basic.html Frink's most recent version is only 17 days old. (You seemed to imply Frink isn't under active development.) Cheers, Chris From rustompmody at gmail.com Wed Sep 29 03:48:28 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 29 Sep 2010 13:18:28 +0530 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> Message-ID: On Wed, Sep 29, 2010 at 12:44 PM, Chris Rebert wrote: > On Tue, Sep 28, 2010 at 11:43 PM, rustom wrote: > > A currently developed language with units is curl: see > > http://developers.curl.com/userdocs/docs/en/dguide/quantities-basic.html > > Frink's most recent version is only 17 days old. (You seemed to imply > Frink isn't under active development.) > > Cheers, > Chris > Sorry... I was really referring/comparing with some earlier posts that seemed to be about old/obsolete systems (HP48...) -------------- next part -------------- An HTML attachment was scrubbed... URL: From chardster at gmail.com Wed Sep 29 03:55:32 2010 From: chardster at gmail.com (Richard Thomas) Date: Wed, 29 Sep 2010 00:55:32 -0700 (PDT) Subject: Upload files with wsgi References: Message-ID: <470d630b-717b-4dd1-8a86-0fc3928cf49d@l6g2000yqb.googlegroups.com> On Sep 28, 11:31?pm, Hidura wrote: > Hello, i have a project on Python3k, and i have a very big problem i > don' t find how take an upload file i am using the wsgiref lib, and or > theres any way to connect to the client in order to get the file by > myself? > > Thank you > Diego Hidalgo. > > -- > Enviado desde mi dispositivo m?vil > > Diego I. Hidalgo D. 'wsgiref' doesn't do that part of request handling. You want to use the 'cgi' module to parse the POST data: http://docs.python.org/library/cgi.html Remember to set the enctype on your
tags to multipart/form- data. Chard. From karaken12 at gmail.com Wed Sep 29 05:05:49 2010 From: karaken12 at gmail.com (Tom Potts) Date: Wed, 29 Sep 2010 10:05:49 +0100 Subject: File holes in Linux Message-ID: Hi, all. I'm not sure if this is a bug report, a feature request or what, so I'm posting it here first to see what people make of it. I was copying over a large number of files using shutil, and I noticed that the final files were taking up a lot more space than the originals; a bit more investigation showed that files with a positive nominal filesize which originally took up 0 blocks were now taking up the full amount. It seems that Python does not write back file holes as it should; here is a simple program to illustrate: data = '\0' * 1000000 file = open('filehole.test', 'wb') file.write(data) file.close() A quick `ls -sl filehole.test' will show that the created file actually takes up about 980k, rather than the 0 bytes expected. If anyone can let me know if this is indeed a bug or feature request, how to get around it, or where to take it next, I'd really appreciate it. Thanks a lot, Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From vivanov at ivanov-nest.com Wed Sep 29 05:53:02 2010 From: vivanov at ivanov-nest.com (Velko Ivanov) Date: Wed, 29 Sep 2010 12:53:02 +0300 Subject: Certificate validation with HTTPSConnection Message-ID: Hello, I've always wandered why HTTPSConnection does not validate certificates? It is fairly simple to use the SSL socket's validation: > class HTTPSConnection(HTTPConnection): > """This class allows communication via SSL. > It is a copy of the http.client.HTTPSConnection with added certificate validation > """ > > default_port = HTTPS_PORT > > def __init__(self, host, port=None, key_file=None, cert_file=None, ca_file=None, > cert_reqs=ssl.CERT_NONE, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): > HTTPConnection.__init__(self, host, port, strict, timeout) > self.key_file = key_file > self.cert_file = cert_file > self.cert_reqs = cert_reqs > self.ca_file = ca_file > > def connect(self): > "Connect to a host on a given (SSL) port." > > sock = socket.create_connection((self.host, self.port), self.timeout) > > if self._tunnel_host: > self.sock = sock > self._tunnel() > > self.sock = ssl.wrap_socket(sock, keyfile=self.key_file, certfile=self.cert_file, cert_reqs=self.cert_reqs, ca_certs=self.ca_file) > conn = HTTPSConnection(host, cert_file=certfile, cert_reqs=ssl.CERT_REQUIRED, ca_file=cafile) IMO it doesn't matter how well is the validation covered in the ssl lib, or the filenames vs. files issues of ssl.wrap_socket() - HTTPSConnection should only provide the means to use what is available in SSL and include a link in docs to explanations of how SSL does what it does, so that people can make their decisions. The above code works quite well for me in production, where client nodes connect to apache and nginx servers by HTTPS with certificate based authentication. I'm using self signed CA though and I don't need revocation lists, so I know nothing of whether that part of validation is/could be working. Just sharing a simple solution to a simple problem on which I spent more that few hours in reading, hope this helps the next lost soul Best Regards Velko Ivanov -------------- next part -------------- An HTML attachment was scrubbed... URL: From foo at meisterderspiele.de Wed Sep 29 05:53:17 2010 From: foo at meisterderspiele.de (=?ISO-8859-1?Q?Torsten_Z=FChlsdorff?=) Date: Wed, 29 Sep 2010 11:53:17 +0200 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Message-ID: Keith Thompson schrieb: >> >>> print c # floating point accuracy aside >> 299792458.0 m/s > > Actually, the speed of light is exactly 299792458.0 m/s by > definition. Yes, but just in vacuum. Greetings, Torsten -- http://www.dddbl.de - ein Datenbank-Layer, der die Arbeit mit 8 verschiedenen Datenbanksystemen abstrahiert, Queries von Applikationen trennt und automatisch die Query-Ergebnisse auswerten kann. From jacob.abraham at gmail.com Wed Sep 29 06:09:49 2010 From: jacob.abraham at gmail.com (Jacob Abraham) Date: Wed, 29 Sep 2010 15:39:49 +0530 Subject: Paramiko and Threading Message-ID: Hi, Could someone help me understand how to using threading along with paramiko. For some reason only one of two of the threads returns the output correctly. Some of the threads returns an empty string as command output, but no errors are thrown. My attempt is pasted below. regards, Jacob Abraham import time import socket import sys from threading import Thread import os from paramiko import AutoAddPolicy, SSHClient, SSHException, AuthenticationException class SSHCollector(Thread): def __init__(self, hostname, username, password, proto, loggername, zapiport, sshport=22, keepalive=True, tmo=60): Thread.__init__(self) self.hostname = hostname self.username = username self.password = password self.keepalive = keepalive self.tmo = tmo self._conn = None self.success = False self.client = SSHClient() self.client.load_system_host_keys() self.client.set_missing_host_key_policy(AutoAddPolicy()) self.client.set_log_channel(loggername) def _connect(self): if None is not self.client.get_transport() and self.client.get_transport().is_active(): return if None is self.username: self.client.connect(hostname=self.hostname, timeout=self.tmo) elif None is self.password: self.client.connect(hostname=self.hostname, username=self.username, password=self.password, timeout=self.tmo) else: self.client.connect(hostname=self.hostname, username=self.username, password=self.password, look_for_keys=False, timeout=self.tmo) trans = self.client.get_transport() trans.use_compression(True) trans.set_keepalive(1) def close(self): self.client.close() __del__ = close def execute(self, lcmd, auto_close=False, tmo=300, read_max=10*1024*1024): output = r'' err = r'' self._error = "" read_max = int(read_max/2) exit_status = False self._connect() chan = self.client.get_transport().open_session() if not self.keepalive: self.client.get_transport().set_keepalive(0) chan.settimeout(tmo) chan.exec_command(lcmd) stdin = chan.makefile('wb', -1) stdout = chan.makefile('rb', -1) stderr = chan.makefile_stderr('rb', -1) start_time = time.time() while True: if stderr.channel.recv_stderr_ready(): ret = stderr.read() if ret: err += ret if stdout.channel.recv_ready(): try: ret = stdout.read(read_max) if ret: output += ret except socket.timeout: pass exit_status = chan.exit_status_ready() if exit_status or ((int(start_time) + tmo) < int(time.time())): timeout = False if exit_status: exit_status = str(stderr.channel.recv_exit_status()) else: self.signal(chan, 'KILL') exit_status = str(stderr.channel.recv_exit_status()) timeout = True if stdin: stdin.channel.shutdown_write() stdin.close() if stdout.channel.recv_ready(): ret = stdout.read(read_max) if ret: output += ret stdout.close() if stderr.channel.recv_stderr_ready(): ret = stderr.read() if ret: err += ret err += "exit_status("+str(exit_status)+") to("+str(timeout)+")" stderr.close() break self.success = True if auto_close: self.client.close() return (output, err) def setCommand(self, cmd): self.cmd = cmd def runcmd(self, cmd): return self.execute(cmd, auto_close=True) def run(self): self.resultset = self.runcmd(self.cmd) if __name__ == '__main__': cmd = 'date' threads = [] a = time.time() for i in range(3): collector = SSHCollector('11.11.111.111', 'dummyusername', 'dummypassword', \ 'auto', 'dummylogger', None) collector.setCommand(cmd) threads.append(collector) for i in threads: i.start() for i in threads: i.join() for i in threads: print i.resultset b=time.time() print b-a -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Wed Sep 29 06:11:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 29 Sep 2010 23:11:45 +1300 Subject: utf-8 and ctypes References: Message-ID: In message , Brendan Miller wrote: > It seems that characters not in the ascii subset of UTF-8 are > discarded by c_char_p during the conversion ... Not a chance. > ... or at least they don't print out when I go to print the string. So it seems there?s a problem on the printing side. What happens when you construct a UTF-8-encoded string directly in Python and try printing it the same way? From ldo at geek-central.gen.new_zealand Wed Sep 29 06:13:41 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 29 Sep 2010 23:13:41 +1300 Subject: Nautilus Python References: Message-ID: In message , Eduardo Ribeiro wrote: > But it doesn't work. What messages do you get? From pjb at informatimago.com Wed Sep 29 06:40:58 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Wed, 29 Sep 2010 12:40:58 +0200 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <87bp7gq1c5.fsf@kuiper.lan.informatimago.com> George Neuner writes: > On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson > wrote: > >>George Neuner writes: >>> On 28 Sep 2010 12:42:40 GMT, Albert van der Horst >>> wrote: >>>>I would say the dimensional checking is underrated. It must be >>>>complemented with a hard and fast rule about only using standard >>>>(SI) units internally. >>>> >>>>Oil output internal : m^3/sec >>>>Oil output printed: kbarrels/day >>> >>> "barrel" is not an SI unit. >> >>He didn't say it was. Internal calculations are done in SI units (in >>this case, m^3/sec); on output, the internal units can be converted to >>whatever is convenient. > > That's true. But it is a situation where the conversion to SI units > loses precision and therefore probably shouldn't be done. > >> >>> And when speaking about oil there isn't >>> even a simple conversion. >>> >>> 42 US gallons ? 34.9723 imp gal ? 158.9873 L >>> >>> [In case those marks don't render, they are meant to be the >>> double-tilda sign meaning "approximately equal".] >> >>There are multiple different kinds of "barrels", but "barrels of oil" >>are (consistently, as far as I know) defined as 42 US liquid gallons. >>A US liquid gallon is, by definition, 231 cubic inches; an inch >>is, by definition, 0.0254 meter. So a barrel of oil is *exactly* >>0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 >>kbarrels/day. (Please feel free to check my math.) That's >>admittedly a lot of digits, but there's no need for approximations >>(unless they're imposed by the numeric representation you're using). > > I don't care to check it ... the fact that the SI unit involves 12 > decimal places whereas the imperial unit involves 3 tells me the > conversion probably shouldn't be done in a program that wants > accuracy. Because perhaps you're thinking that oil is sent over the oceans, and sold retails in barrils of 42 gallons? Actually, when I buy oil, it's from a pump that's graduated in liters! It comes from trucks with citerns containing 24 m?. And these trucks get it from reservoirs of 23,850 m?. "Tankers move approximately 2,000,000,000 metric tons" says the English Wikipedia page... Now perhaps it all depends on whether you buy your oil from Total or from Texaco, but in my opinion, you're forgetting something: the last drop. You never get exactly 42 gallons of oil, there's always a little drop more or less, so what you get is perhaps 158.987 liter or 41.9999221 US gallons, or even 158.98 liter = 41.9980729 US gallons, where you need more significant digits. -- __Pascal Bourguignon__ http://www.informatimago.com/ From affdfsdfdsfsd at b.com Wed Sep 29 06:42:37 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 29 Sep 2010 10:42:37 GMT Subject: if the else short form Message-ID: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Hi all, I'm studying PyGTK tutorial and i've found this strange form: button = gtk.Button(("False,", "True,")[fill==True]) the label of button is True if fill==True, is False otherwise. i have googled for this form but i haven't found nothing, so can any of you pass me any reference/link to this particular if/then/else form? thanks Nico From deets at web.de Wed Sep 29 06:45:08 2010 From: deets at web.de (Diez B. Roggisch) Date: Wed, 29 Sep 2010 12:45:08 +0200 Subject: Example or recomendation of a webserver References: Message-ID: <87r5gcomkr.fsf@web.de> Hidura writes: > I am working on a web project written on Py3k and using mod_wsgi on > the Apache that have to recibes the request client via a xml structure > and i am facing a lot of troubles with the upload files mainly because > i can' t see where they are, so i' ve decide to write my own web > server-django and the others doen' t work for my propouse-, what you > recomend me for start that? not doing it. Reading the HTTP-RFC and the WSGI-PEP. And trying print environ["wsgi.input"].read() inside your wsgi-script. Then, use webob to wrap the whole WSGI-stuff to have at least a minimum of sensible abstraction. Or simply use Django or TurboGears2, follow the advices in their docs on how to depoly them using mod_wsgi, and be happy. Diez From karaken12 at gmail.com Wed Sep 29 07:19:53 2010 From: karaken12 at gmail.com (Tom Potts) Date: Wed, 29 Sep 2010 12:19:53 +0100 Subject: if the else short form In-Reply-To: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: This is just a sneaky shorthand, which is fine if that's what you want, but it makes it harder to read. The reason it works is that 'fill==True' is a boolean expression, which evaluates to True or False, but if you force a True into being an integer, it will be 1, and a False will become 0. Try writing 'True == 1' on the Python interpreter to see what I mean. So this code snippet is creating a tuple with two elements, and then selecting the first if 'fill==True' is False, or 0, and selecting the second if 'fill==True' is True, or 1. As I say, this kind of coding is absolutely fine, but it makes things harder to read and doesn't really save much space. I wouldn't recommend using this kind of style yourself, at least until you're more familiar with programming in Python. Tom On 29 September 2010 11:42, Tracubik wrote: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can any of > you pass me any reference/link to this particular if/then/else form? > > thanks > Nico > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.j.molenaar at gmail.com Wed Sep 29 07:19:55 2010 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Wed, 29 Sep 2010 13:19:55 +0200 Subject: if the else short form In-Reply-To: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: Hi Nico, it's converting fill==True to an int, thereby choosing the string "False," or "True," by indexing into the tuple. Try this in an interpreter: >>> ['a','b'][False] 'a' >>> ['a','b'][True] 'b' >>> int(False) 0 >>>?int(True) 1 Joost On 29 September 2010 12:42, Tracubik wrote: > > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can any of > you pass me any reference/link to this particular if/then/else form? > > thanks > Nico > -- > http://mail.python.org/mailman/listinfo/python-list From hugol at fastmail.net Wed Sep 29 07:27:04 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Wed, 29 Sep 2010 07:27:04 -0400 Subject: System idle time under Linux Message-ID: <1285759624.9416.1397468677@webmail.messagingengine.com> I have found it for windows and mac, but no luck under linux. Any idea? Thanks -- Hugo L?veill? hugol at fastmail.net From hniksic at xemacs.org Wed Sep 29 07:38:48 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 29 Sep 2010 13:38:48 +0200 Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: <877hi44w53.fsf@xemacs.org> Tracubik writes: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. The tutorial likely predates if/else expression syntax introduced in 2.5, which would be spelled as: button = gtk.Button("True" if fill else "False") BTW adding "==True" to a boolean value is redundant and can even break for logically true values that don't compare equal to True (such as the number 10 or the string "foo"). From oswald.harry at gmail.com Wed Sep 29 07:59:13 2010 From: oswald.harry at gmail.com (harryos) Date: Wed, 29 Sep 2010 04:59:13 -0700 (PDT) Subject: scheduler or infinite loop Message-ID: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> hi I am trying to write a program to read data from a site url. The program must read the data from site every 5 minutes. def get_data_from_site(pageurlstr): h=urllib.urlopen(pageurlstr) data=h.read() process_data(data) At first, I thought of using the sched module ,but then it doesn't look right adding so many scheduler.enter() statements.The program is supposed to execute the above function every 5 minutes until the application is shut down by the user. I created an infinite loop while True: print time.asctime() get_data_from_site('http://somesite.com/') time.sleep(300) Is there a better way to do this?Any suggestions ,pointers most welcome thanks harry From nitinpawar432 at gmail.com Wed Sep 29 08:02:23 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Wed, 29 Sep 2010 17:32:23 +0530 Subject: scheduler or infinite loop In-Reply-To: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> Message-ID: why not schedule cron */5 * * * * and check in your code that previous execution was successful or not On Wed, Sep 29, 2010 at 5:29 PM, harryos wrote: > hi > I am trying to write a program to read data from a site url. > The program must read the data from site every 5 minutes. > > def get_data_from_site(pageurlstr): > h=urllib.urlopen(pageurlstr) > data=h.read() > process_data(data) > > At first, I thought of using the sched module ,but then it doesn't > look right adding so many scheduler.enter() statements.The program is > supposed to execute the above function every > 5 minutes until the application is shut down by the user. > > I created an infinite loop > while True: > print time.asctime() > get_data_from_site('http://somesite.com/') > time.sleep(300) > > Is there a better way to do this?Any suggestions ,pointers most > welcome > thanks > harry > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Wed Sep 29 08:07:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Sep 2010 12:07:56 GMT Subject: About __class__ of an int literal References: Message-ID: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> On Wed, 29 Sep 2010 02:20:55 +0100, MRAB wrote: > On 29/09/2010 01:19, Terry Reedy wrote: >> A person using instances of a class should seldom use special names >> directly. They are, in a sense, implementation details, even if >> documented. The idiom "if __name__ == '__main__':" is an exception. >> > __file__ is another exception. As are __iter__, __next__, __add__, __dict__, and, yes, __class__, to say nothing of all the other special methods. I'm afraid that I have to disagree with Terry here. Double-underscore special variables don't start with double underscores because they're implementation details, or to indicate that they're private. They are reserved names for attributes or methods that have special meaning to Python. An implementation that didn't use __dict__ for the namespace of an ordinary class, or didn't call __add__ for the + operator, would be considered to be buggy. Naturally one has to be careful about the assumptions you make with such special methods. You shouldn't assume, for example, that all classes will have a __dict__ attribute. If the class has __slots__ defined, it may not. But I think that it is safe to assume any object will have a __class__ attribute. At least, I'd report it as a bug if I found one that didn't. (This may change in the future. Given type(), and isinstance(), I'm not sure what value __class__ adds.) -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Sep 29 08:17:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Sep 2010 12:17:13 GMT Subject: list problem... References: Message-ID: <4ca32e49$0$28654$c3e8da3@news.astraweb.com> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >>> Hi all, >>> Have been grappling with a list problem for hours... a = [2, 3, 4, >>> 5,.....] >>> b = [4, 8, 2, 6,.....] >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and >>> b[2] is present. >>> I have tried sets, zip etc with no success. I am tackling Euler >>> projects with Python 3.1, with minimal knowledge, and having to tackle >>> the language as I progress. Enjoyable frustration ?:) >> >> I'm not clear on what your actual problem is, could you restate it? >> >> It sounds like you want to copy the ith element out of a and b into >> some other list- call it c- when the (i+2)th element meets some >> condition. What's the condition? >> >> Geremy Condra > > The condition is that the i-th element is inverted, but not equal. eg > 4,2 - 2,4 , 34,5 - 5,34 etc. > Hope that is clearer. Clear as mud. Perhaps you should given an example. Given input a = [2, 3, 4, 5, 6, 7] b = [4, 8, 2, 6, 10, 42] what output are you expecting, and how would you work it out by hand? -- Steven From brendan.simon at etrix.com.au Wed Sep 29 08:23:31 2010 From: brendan.simon at etrix.com.au (Brendan Simon (eTRIX)) Date: Wed, 29 Sep 2010 22:23:31 +1000 Subject: [Python-list] if the else short form In-Reply-To: References: Message-ID: <4CA32FC3.5090106@etrix.com.au> On 29/09/10 9:20 PM, python-list-request at python.org wrote: > Subject: > if the else short form > From: > Tracubik > Date: > 29 Sep 2010 10:42:37 GMT > > To: > python-list at python.org > > > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can any of > you pass me any reference/link to this particular if/then/else form? > As others have pointed out, a tuple with two items is created and then indexed by the integer conversion of conditional. It is "creative" coding but I wouldn't recommend using it either. For this particular case you may achieve the same thing with: button = gtk.Button(str(fill==True)) or possibly just: button = gtk.Button(fill==True) It's a little better but still not great. A verbose form of something more generic may be: if fill: label = 'True' else: label = 'False' button = gtk.Button(label) or possibly: label = 'True' if fill else 'False' button = gtk.Button(label) or using a dict for label lookup: label = { True : 'True', False : 'False' } button = gtk.Button(label[fill]) Cheers, Brendan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Wed Sep 29 08:34:33 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 29 Sep 2010 14:34:33 +0200 Subject: About __class__ of an int literal References: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> Message-ID: <8739ss4tk6.fsf@xemacs.org> Steven D'Aprano writes: > On Wed, 29 Sep 2010 02:20:55 +0100, MRAB wrote: > >> On 29/09/2010 01:19, Terry Reedy wrote: > >>> A person using instances of a class should seldom use special names >>> directly. They are, in a sense, implementation details, even if >>> documented. The idiom "if __name__ == '__main__':" is an exception. >>> >> __file__ is another exception. > > > As are __iter__, __next__, __add__, __dict__, and, yes, __class__, to > say nothing of all the other special methods. I think by "person using instances of a class" Terry referred to the user of a class as opposed to the implementor. In that sense the user should be calling iter(foo) instead of foo.__iter__(), next(foo) instead of foo.__next__(), and foo+bar instead of foo.__add__(bar). Direct calls to special-name methods, such as __len__, often indicate that the programmer hasn't grasped how those methods are intended to be used in Python. Obviously, none of this applies to __dict__, __class__, and friends, nor does it apply to cases where you know what you're doing, such as invoking ____ of a superclass. > (This may change in the future. Given type(), and isinstance(), I'm not > sure what value __class__ adds.) None whatsoever. __class__ used to be necessary to tell the appart instances of different old-style classes: >>> class X: pass # old-style ... >>> X().__class__ >>> type(X()) Now that classes produce real types, they are equivalent. From bruno.desthuilliers at gmail.com Wed Sep 29 08:52:32 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 29 Sep 2010 05:52:32 -0700 (PDT) Subject: list problem... References: <4ca32e49$0$28654$c3e8da3@news.astraweb.com> Message-ID: <0e563359-c2fd-4fbc-808b-02cb2e483ad5@l20g2000yqm.googlegroups.com> On 29 sep, 14:17, Steven D'Aprano wrote: > On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > > >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > >>> Hi all, > >>> Have been grappling with a list problem for hours... a = [2, 3, 4, > >>> 5,.....] > >>> b = [4, 8, 2, 6,.....] > >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] and > >>> b[2] is present. > >>> I have tried sets, zip etc with no success. I am tackling Euler > >>> projects with Python 3.1, with minimal knowledge, and having to tackle > >>> the language as I progress. Enjoyable frustration ?:) > > >> I'm not clear on what your actual problem is, could you restate it? > > >> It sounds like you want to copy the ith element out of a and b into > >> some other list- call it c- when the (i+2)th element meets some > >> condition. What's the condition? > > >> Geremy Condra > > > The condition is that the i-th element is inverted, but not equal. eg > > 4,2 - 2,4 , 34,5 - 5,34 etc. > > Hope that is clearer. > > Clear as mud. > > Perhaps you should given an example. Given input > > a = [2, 3, 4, 5, 6, 7] > b = [4, 8, 2, 6, 10, 42] > > what output are you expecting, AFAICT, the OP expects [2, 4] in this case, but it's not clear what he'd expect for let's say: a = [2, 3, 21, 4, 5, 6, 7] b = [4, 8, 22, 2, 6, 10, 42] (the 'reversed' pair is at i+3, not i+2) or a = [0, 2, 3, 4, 5, 6, 7] b = [3, 4, 8, 2, 6, 10, 42] (the first pair is at pos 1, not 0) or a = [2, 3, 4, 8, 6, 7] b = [4, 8, 2, 3, 10, 42] (there's a second 'non-reversed/reversed' match at positions resp. 1 & 3) From philip at semanchuk.com Wed Sep 29 08:53:17 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 29 Sep 2010 08:53:17 -0400 Subject: if the else short form In-Reply-To: References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: On Sep 29, 2010, at 7:19 AM, Tom Potts wrote: > This is just a sneaky shorthand, which is fine if that's what you want, but > it makes it harder to read. The reason it works is that 'fill==True' is a > boolean expression, which evaluates to True or False, but if you force a > True into being an integer, it will be 1, and a False will become 0. Try > writing 'True == 1' on the Python interpreter to see what I mean. So this > code snippet is creating a tuple with two elements, and then selecting the > first if 'fill==True' is False, or 0, and selecting the second if > 'fill==True' is True, or 1. > > As I say, this kind of coding is absolutely fine, but it makes things harder > to read and doesn't really save much space. I wouldn't recommend using this > kind of style yourself, at least until you're more familiar with programming > in Python. Does Python make any guarantee that int(True) == 1 and int(False) == 0 will always hold, or are their values an implementation detail? Thanks Philip > On 29 September 2010 11:42, Tracubik wrote: > >> Hi all, >> I'm studying PyGTK tutorial and i've found this strange form: >> >> button = gtk.Button(("False,", "True,")[fill==True]) >> >> the label of button is True if fill==True, is False otherwise. >> >> i have googled for this form but i haven't found nothing, so can any of >> you pass me any reference/link to this particular if/then/else form? >> >> thanks >> Nico >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list From pw at panix.com Wed Sep 29 08:55:57 2010 From: pw at panix.com (Paul Wallich) Date: Wed, 29 Sep 2010 08:55:57 -0400 Subject: "Strong typing vs. strong testing" In-Reply-To: <87bp7gq1c5.fsf@kuiper.lan.informatimago.com> References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <87bp7gq1c5.fsf@kuiper.lan.informatimago.com> Message-ID: On 9/29/10 6:40 AM, Pascal J. Bourguignon wrote: > George Neuner writes: > >> On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson >> wrote: >> >>> George Neuner writes: >>>> On 28 Sep 2010 12:42:40 GMT, Albert van der Horst >>>> wrote: >>>>> I would say the dimensional checking is underrated. It must be >>>>> complemented with a hard and fast rule about only using standard >>>>> (SI) units internally. >>>>> >>>>> Oil output internal : m^3/sec >>>>> Oil output printed: kbarrels/day >>>> >>>> "barrel" is not an SI unit. >>> >>> He didn't say it was. Internal calculations are done in SI units (in >>> this case, m^3/sec); on output, the internal units can be converted to >>> whatever is convenient. >> >> That's true. But it is a situation where the conversion to SI units >> loses precision and therefore probably shouldn't be done. >> >>> >>>> And when speaking about oil there isn't >>>> even a simple conversion. >>>> >>>> 42 US gallons ? 34.9723 imp gal ? 158.9873 L >>>> >>>> [In case those marks don't render, they are meant to be the >>>> double-tilda sign meaning "approximately equal".] >>> >>> There are multiple different kinds of "barrels", but "barrels of oil" >>> are (consistently, as far as I know) defined as 42 US liquid gallons. >>> A US liquid gallon is, by definition, 231 cubic inches; an inch >>> is, by definition, 0.0254 meter. So a barrel of oil is *exactly* >>> 0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 >>> kbarrels/day. (Please feel free to check my math.) That's >>> admittedly a lot of digits, but there's no need for approximations >>> (unless they're imposed by the numeric representation you're using). >> >> I don't care to check it ... the fact that the SI unit involves 12 >> decimal places whereas the imperial unit involves 3 tells me the >> conversion probably shouldn't be done in a program that wants >> accuracy. [...] > > Now perhaps it all depends on whether you buy your oil from Total or > from Texaco, but in my opinion, you're forgetting something: the last > drop. You never get exactly 42 gallons of oil, there's always a little > drop more or less, so what you get is perhaps 158.987 liter or > 41.9999221 US gallons, or even 158.98 liter = 41.9980729 US gallons, > where you need more significant digits. And even that pales in comparison to the expansion and contraction of petroleum products with temperature. Compensation to standard temp is required in some jurisdictions but not in others... From bruno.desthuilliers at gmail.com Wed Sep 29 08:58:16 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 29 Sep 2010 05:58:16 -0700 (PDT) Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <877hi44w53.fsf@xemacs.org> Message-ID: On 29 sep, 13:38, Hrvoje Niksic wrote: > Tracubik writes: > > > button = gtk.Button(("False,", "True,")[fill==True]) (snip) > BTW adding "==True" to a boolean value is redundant and can even break > for logically true values that don't compare equal to True (such as the > number 10 or the string "foo"). Note that if fill is actually an int outside the (0, 1) domain, it will break too. The correct test would be: ("False,", "True,")[bool(fill)]) >>> ['a', 'b'][bool(10)] 'b' >>> ['a', 'b'][bool('')] 'a' >>> ['a', 'b'][bool("yes")] 'b' >>> ['a', 'b'][bool([])] 'a' >>> ['a', 'b'][bool([42, 24])] 'b' >>> ['a', 'b'][bool(None)] 'a' >>> From alex at moreati.org.uk Wed Sep 29 08:59:51 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Wed, 29 Sep 2010 05:59:51 -0700 (PDT) Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <877hi44w53.fsf@xemacs.org> Message-ID: <95b7daae-a086-4575-8a67-23097ea98f07@i5g2000yqe.googlegroups.com> On Sep 29, 12:38?pm, Hrvoje Niksic wrote: > Tracubik writes: > > Hi all, > > I'm studying PyGTK tutorial and i've found this strange form: > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > the label of button is True if fill==True, is False otherwise. > > The tutorial likely predates if/else expression syntax introduced in > 2.5, which would be spelled as: > > button = gtk.Button("True" if fill else "False") > > BTW adding "==True" to a boolean value is redundant and can even break > for logically true values that don't compare equal to True (such as the > number 10 or the string "foo"). Totally agreed with one nit. If one chooses to fake x = true_val if expr else false_val prior to Python 2.5, with x = (false_val, true_val)[expr] then one should ensure that expr evaluates to either 0, 1 or a bool. If expr evaluates to "fred" or 42 a TypeError or IndexError will occur. So better to use (in original line) button = gtk.Button(("False,", "True,")[bool(fill)]) but still best for readability, to use a full if-else block From ldo at geek-central.gen.new_zealand Wed Sep 29 09:01:07 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 30 Sep 2010 02:01:07 +1300 Subject: System idle time under Linux References: Message-ID: /proc/stat or /proc/uptime, depending. See the proc(5) man page. From frank at chagford.com Wed Sep 29 09:04:23 2010 From: frank at chagford.com (Frank Millman) Date: Wed, 29 Sep 2010 15:04:23 +0200 Subject: scheduler or infinite loop References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> Message-ID: harryos wrote: > hi > I am trying to write a program to read data from a site url. > The program must read the data from site every 5 minutes. > > def get_data_from_site(pageurlstr): > h=urllib.urlopen(pageurlstr) > data=h.read() > process_data(data) > > At first, I thought of using the sched module ,but then it doesn't > look right adding so many scheduler.enter() statements.The program is > supposed to execute the above function every > 5 minutes until the application is shut down by the user. > > I created an infinite loop > while True: > print time.asctime() > get_data_from_site('http://somesite.com/') > time.sleep(300) > > Is there a better way to do this?Any suggestions ,pointers most > welcome > thanks > harry Here is a technique that allows the loop to run in the background, in its own thread, leaving the main program to do other processing - import threading class DataGetter(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.event = threading.Event() def run(self): event = self.event # make local while not event.is_set(): print time.asctime() # either call the function from here, # or put the body of the function here get_data_from_site('http://somesite.com/') event.wait(300) def stop(self): self.event.set() In the startup of the main program, insert the following - data_getter = DataGetter() data_getter.start() At the end of the program, terminate the loop like this - data_getter.stop() HTH Frank Millman From ldo at geek-central.gen.new_zealand Wed Sep 29 09:07:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 30 Sep 2010 02:07:44 +1300 Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: In message , Seebs wrote: > Helps, perhaps, that I got exposed to group theory early enough to be used > to redefining + and * to be any two operations which have interesting > properties ... But groups only have one such operation; it?s rings and fields (and number systems) that have two. From oswald.harry at gmail.com Wed Sep 29 09:26:41 2010 From: oswald.harry at gmail.com (harryos) Date: Wed, 29 Sep 2010 06:26:41 -0700 (PDT) Subject: scheduler or infinite loop References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> Message-ID: <344a231a-1ed7-4be6-bd14-aa6adf965b03@n19g2000prf.googlegroups.com> thanks Frank > > Here is a technique that allows the loop to run in the background, in its > own thread, leaving the main program to do other processing - > > import threading > > class DataGetter(threading.Thread): > From emekamicro at gmail.com Wed Sep 29 09:46:55 2010 From: emekamicro at gmail.com (Emeka) Date: Wed, 29 Sep 2010 14:46:55 +0100 Subject: Introducing Kids to Programming: 2 or 3? In-Reply-To: References: Message-ID: Marco, This is a great news coming out of Africa. I would very much like to see this your success story replicate across the continent. I would like to participate and to have your programs for my country, Nigeria. >From what you asked for, I would say that those kids should be part of the future and not the past. So, go for Python 3. Being new to programming, what matters most is learning programming and not the minor syntactical differences. Get them to understand the real thing and they would build up from there. Regards , Emeka On Mon, Sep 27, 2010 at 4:48 PM, Marco Gallotta wrote: > Hi there > > I'm sure you get a lot of "2 or 3" questions, but here's another. > Umonya [1] uses Python to introduce school kids to programming. The > initiative is only 15 months old and up till now we've been using > existing notes and exercises and thus Python 2. But we're at the stage > where we can either stick with 2 for the next few years, or go to 3 > now. > > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. As such, we're taking the time now > to write our very own specialised course notes and exercises, and we > this is why we need to decide *now* which path to take: 2 or 3? As we > will be translating the notes we'll probably stick with out choice for > the next few years. > > Since these are kids, we feel the nice changes in 3 such as removing > integer division will help in teaching. It will also remove confusion > when they go to download Python and grab the latest version. Since > they're just starting, chances are almost none will be hit by the > limited library support for at least a year or two. They will, > however, be hit by the confusion of seeing Python 2 code all over the > web. > > We're tending towards 3, but I am a little cautious myself. > > Marco > > [1] http://umonya.co.za > > -- > Marco Gallotta > MSc Student > Department of Computer Science, University of Cape Town > people.cs.uct.ac.za/~mgallott | > marco-za.blogspot.com > marco AT gallotta DOT co DOT za | 073 170 4444 | 021 552 2731 > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom.conneely at gmail.com Wed Sep 29 09:50:05 2010 From: tom.conneely at gmail.com (Tom Conneely) Date: Wed, 29 Sep 2010 06:50:05 -0700 (PDT) Subject: PyCObject & malloc creating memory leak Message-ID: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> I'm attempting to write a library for reading data via USB from a device and processing the data to display graphs. I have already implemented parts of this code as pure python, as a proof of concept but I have now moved on to implementing the functions in a C extension. My original plan was to have the data processing and data acquisition functions running in separate processes, with a multiprocessing.Queue for passing the raw data packets. The raw data is read in as a char*, with a non constant length, hence I have allocated memory using PyMem_Malloc and I am returning from the acquisition function a PyCObject containing a pointer to this char* buffer, along with a destructor. The following code shows a simple test function I've written (with some module/class boilerplate removed) to demonstrate this. static void p_destruct(void *p) { PyMem_Free((void*)p); } static PyObject *malloc_buffer(MyClass *k1) { PyObject *cobj; char *foo = PyMem_Malloc(1024 * sizeof(char)); if (foo == NULL) { return NULL; } foo = "foo"; cobj = PyCObject_FromVoidPtr(foo, p_destruct); return cobj; } static PyObject *retrieve_buffer(MyClass *k1, PyObject *args) { char *foo2; PyObject cobj2; char *kwlist[] = {"foo1", NULL}; if (!PyArg_ParseTuple(args, "O", &cobj2)) { return NULL; } foo2 = PyCObject_AsVoidPtr(cobj2); //Do something PySys_WriteStdout(foo2); Py_RETURN_NONE; } So if I call these functions in a loop, e.g. The following will generate ~10GB of data x = MyClass() for i in xrange(0, 10 * 2**20): c = x.malloc_buffer() x.retrieve_buffer(c) All my memory disapears, until python crashes with a MemoryError. By placing a print in the destructor function I know it's being called, however it's not actually freeing the memory. So in short, what am I doing wrong? This is the first time I've written a non-trivial python C extension, and I'm still getting my head round the whole Py_INC/DECREF and the correct way to manage memory, so I spent a while playing around with incref/decref but I left these out of my above example to keep what I'm trying to achieve clearer. Also, I'm aware PyCObject is deprecated in >=2.7 but I'm targeting Python 2.6 at the moment, and I will move on to using capsules once I've made the big jump with some other libraries. So if there is anything that could be hugely different using capsules could you point this out. I'm developing using: Python - 2.6.5 Windows XP (although linux is a future target platform) msvc compiler Cheers, any help would be greatly appreciated. From no.email at please.post Wed Sep 29 09:54:18 2010 From: no.email at please.post (kj) Date: Wed, 29 Sep 2010 13:54:18 +0000 (UTC) Subject: Supplementing the std lib (Was: partial sums problem) References: Message-ID: In Terry Reedy writes: >Do not try to do a reduction with a comprehension. Just write clear, >straightforward code that obviously works. >s=[1,2,3,4,5,6] >def cusum(s): > t = 0 > for i in s: > t += i > yield t >print(list(cusum(s))) > >>> >[1, 3, 6, 10, 15, 21] Actually, this is just fine. Thank you! But it brings up a new question, of an entirely different nature. It's a recurrent conundrum, actually, and I have not found a good solution. Your cusum function is one that I would like to see somewhere in the standard library (in itertools maybe?). Maybe some future version of the standard library will have it, or something like it (I'm thinking of a generalized form which, like reduce, takes a function and an initial value as arguments). But in the immediate term, cusum is not part of the standard library. Where would you put it if you wanted to reuse it? Do you create a module just for it? Or do you create a general stdlib2 module with all those workhorse functions that have not made it to the standard library? Or something else entirely? (I'm not expecting to get *the* solution from anyone reply; rather, I'm interested in reading people's take on the question and their way of dealing with those functions they consider worthy of the standard library.) kj From hugol at fastmail.net Wed Sep 29 09:55:33 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Wed, 29 Sep 2010 09:55:33 -0400 Subject: System idle time under Linux In-Reply-To: References: Message-ID: <1285768533.14918.1397491647@webmail.messagingengine.com> Thanks, will take a closer look on that But to get me started, how would you get, via python, the info from that ? Thanks alot On Thu, 30 Sep 2010 02:01 +1300, "Lawrence D'Oliveiro" wrote: > /proc/stat or /proc/uptime, depending. See the proc(5) man page. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hugo L?veill? hugol at fastmail.net From usenot at geekmail.INVALID Wed Sep 29 09:57:10 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 29 Sep 2010 09:57:10 -0400 Subject: Reoedering indexes in list of list References: Message-ID: <20100929095710.550552bf@geekmail.INVALID> On Tue, 28 Sep 2010 11:55:18 -0700 (PDT) Toto wrote: > Hello, > > I have a list of list > assume myList[x][y] is integer > I would like to create an alias to that list which I could call this > way: > alias[y][x] returns myList[x][y] > > how can I do that ? (python 2.6) > > (I have a feeling I should use 'property' ;) > The zip thing certainly seems nice. But I can never get my head around zip quick enough to not be confused by it. So my initial idea would have been a function: def reverse_indices(lst, x, y): return lst[y][x] (or, possibly, a subclass of list with this as an additional method.) Granted, the invocation is different from what you want, but I don't know enough about your problem to judge whether this is an issue. /W -- INVALID? DE! From kst-u at mib.org Wed Sep 29 10:00:56 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 07:00:56 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <1d6e115c-cada-46fc-9444-01e80e0afd75@c10g2000yqh.googlegroups.com> <3cmdnamM_bd--D_RnZ2dnUVZ5vSdnZ2d@giganews.com> Message-ID: Erik Max Francis writes: > Keith Thompson wrote: >> Erik Max Francis writes: >> [...] >>> >>> print c # floating point accuracy aside >>> 299792458.0 m/s >> >> Actually, the speed of light is exactly 299792458.0 m/s by >> definition. (The meter and the second are defined in terms of the >> same wavelength of light; this was changed relatively recently.) > > I know. Hence why I wrote the comment "floating point accuracy aside" > when printing it. Ok. I took the comment to be an indication that the figure was subject to floating point accuracy concerns; in fact you meant just the opposite. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From w_a_x_man at yahoo.com Wed Sep 29 10:04:26 2010 From: w_a_x_man at yahoo.com (w_a_x_man) Date: Wed, 29 Sep 2010 07:04:26 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Message-ID: On Sep 26, 9:24?am, p... at informatimago.com (Pascal J. Bourguignon) wrote: > Xah Lee writes: > > here's a interesting toy list processing problem. > > > I have a list of lists, where each sublist is labelled by > > a number. I need to collect together the contents of all sublists > > sharing > > the same label. So if I have the list > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > r) (5 s t)) > > > where the first element of each sublist is the label, I need to > > produce: > > > output: > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > a Mathematica solution is here: > >http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > > R5RS Scheme lisp solution: > >http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_... > > by Sourav Mukherjee > > > also, a Common Lisp solution can be found here: > >http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1de... > > It's too complex. Just write: > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > ? ? ? ? ? ? ? (2 o p) (4 q r) (5 s t)))) > > ? (mapcar (lambda (class) (reduce (function append) class :key (function rest))) > ? ? ? ? ? ?(com.informatimago.common-lisp.list:equivalence-classes list :key (function first))) > > ? ?) > > --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) > > -- > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/ Ruby: [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], [5, 's', 't']]. group_by{|x| x.first}.values.map{|x| x.map{|y| y[1..-1]}.flatten} ==>[["s", "t"], ["a", "b"], ["c", "d", "i", "j"], ["e", "f", "k", "l", "o", "p"], ["g", "h"], ["m", "n", "q", "r"]] From tinauser at libero.it Wed Sep 29 10:06:43 2010 From: tinauser at libero.it (tinauser at libero.it) Date: Wed, 29 Sep 2010 16:06:43 +0200 (CEST) Subject: embedding python in macOS 10.6 Message-ID: <12106339.2710371285769203628.JavaMail.defaultUser@defaultHost> hi there, i'm trying to embed python in a c++ code.i'm starting with the example in the tutorial.i've problem with setting up the enveiroment. I've installed python with the distributed version (i.e., i did not, as a start, build it myself); i added the library where both python.h and pyconfig are stored and i linked to libpython2.6.a (which is, in the distributed version, an alias). the program builds and links correctely, but if I try to run it, i get the following error: Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] 'import site' failed; use -v for traceback Traceback (most recent call last): File "", line 1, in ImportError: No module named time what is the problem? in my .profile i have set PATH: /Library/Frameworks/Python. framework/Versions/2.6/bin From wizzardx at gmail.com Wed Sep 29 10:24:27 2010 From: wizzardx at gmail.com (David) Date: Wed, 29 Sep 2010 16:24:27 +0200 Subject: Python becoming orphaned over ssh Message-ID: Hi there, I have a strange situation. If I do this: 1. Make a script /tmp/test.py on a remote server, with this contents: #!/usr/bin/python from subprocess import check_call check_call(['ping', 'www.google.com']) 2. Call the script like this over SSH: ssh root at testbox /tmp/test.py 3. Interrupt the script with Ctrl+C. Then what happens: The SSH session terminates, as expected. However: On the testing box, the Python script is still running, and so is the ping session. However, if I make an equivalent shell script, /tmp/test.sh, with this contents: #!/bin/bash ping www.google.com And then run it over ssh like this: ssh root at testbox /tmp/test.sh And then hit Ctrl+C, then the shell script and ping are both interrupted remotely, as expected. Here is how 'pstree -p' looks for the python script on the test box, before Ctrl+C: ??sshd(1158)???sshd(19756)???test.py(19797)???ping(19798) ? ??sshd(20233)???bash(20269)???pstree(19875) And after Ctrl+C: ??sshd(1158)???sshd(20233)???bash(20269)???pstree(20218) ??test.py(19797)???ping(19798) Basically, the server-side sshd sub-process has disconnected, but the Python script (and it's ping subprocess) have become orphaned, and now belong to the init process. Note, this only seems to happen if Python is executing a subprocess, and only while Python is being run through a non-interactive ssh session. How can I make Python behave better? I want it to close down itself and it's subprocess, and not orphan itself when I hit ctrl+C PS: The Python version on the testing box: 2.6.4, and the box itself is running Ubuntu Karmic. Also, it's not just ping, but other utilities, eg wget. PPS: I did also try adding logic to the python script, to keep an eye on all the ppids (parent, grandparent, etc), and then to interrupt itself and kill it's subprocess, but that doesn't seem to work: For whatever reason, Python seems to be unable to kill it's subprocess in this situation. The Python process closes, and ping becomes a child of init. But I can then kill ping manually, from a separate ssh session. From tinauser at libero.it Wed Sep 29 10:26:49 2010 From: tinauser at libero.it (tinauser at libero.it) Date: Wed, 29 Sep 2010 16:26:49 +0200 (CEST) Subject: R: embedding python in macOS 10.6 Message-ID: <29636155.2715721285770409375.JavaMail.defaultUser@defaultHost> sorry, my error; in order to achieve what written before, i had to link to the libpython2.6.a that i find downloading the surce code. instead, if I link to the one of the distributed version, i get the following error: missing required architecture x86_64 in file. i tried to build with the -m32 option,but then to that message, another is added for the object file file was built for i386 which is not the architecture being linked (x86_64) >----Messaggio originale---- >Da: tinauser at libero.it >Data: 29/09/2010 16.06 >A: >Ogg: embedding python in macOS 10.6 > >hi there, > >i'm trying to embed python in a c++ code.i'm starting with the example in the >tutorial.i've problem with setting up the enveiroment. >I've installed python with the distributed version (i.e., i did not, as a >start, build it myself); i added the library where both python.h and pyconfig >are stored and i linked to libpython2.6.a (which is, in the distributed >version, an alias). >the program builds and links correctely, but if I try to run it, i get the >following error: > >Could not find platform independent libraries >Could not find platform dependent libraries >Consider setting $PYTHONHOME to [:] >'import site' failed; use -v for traceback >Traceback (most recent call last): > File "", line 1, in >ImportError: No module named time > >what is the problem? > >in my .profile i have set PATH: /Library/Frameworks/Python. >framework/Versions/2.6/bin From hidura at gmail.com Wed Sep 29 10:29:40 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Wed, 29 Sep 2010 14:29:40 +0000 Subject: Upload files with wsgi In-Reply-To: <90e6ba4fc572b3f22a0491653fe5@google.com> Message-ID: <90e6ba53acdcbc11b4049166caf7@google.com> That is what i get: FieldStorage(None, None, []) On Sep 29, 2010 8:39am, hidura at gmail.com wrote: > Python3k give me an error doing that. > On Sep 29, 2010 3:55am, Richard Thomas chardster at gmail.com> wrote: > > On Sep 28, 11:31 pm, Hidura hid... at gmail.com> wrote: > > > > > Hello, i have a project on Python3k, and i have a very big problem i > > > > > don' t find how take an upload file i am using the wsgiref lib, and or > > > > > theres any way to connect to the client in order to get the file by > > > > > myself? > > > > > > > > > > Thank you > > > > > Diego Hidalgo. > > > > > > > > > > -- > > > > > Enviado desde mi dispositivo m?vil > > > > > > > > > > Diego I. Hidalgo D. > > > > > > > > 'wsgiref' doesn't do that part of request handling. You want to use > > > > the 'cgi' module to parse the POST data: > http://docs.python.org/library/cgi.html > > > > > > > > Remember to set the enctype on your tags to multipart/form- > > > > data. > > > > > > > > Chard. > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Wed Sep 29 10:48:49 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Sep 2010 14:48:49 +0000 (UTC) Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > > Thanks, will take a closer look on that > > But to get me started, how would you get, via python, the info from that? Good grief. They're text files. You open them, you read them, you parse the contents for the stuff you want. -- Grant Edwards grant.b.edwards Yow! Did something bad at happen or am I in a gmail.com drive-in movie?? From thomas at jollybox.de Wed Sep 29 10:56:22 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Wed, 29 Sep 2010 16:56:22 +0200 Subject: System idle time under Linux In-Reply-To: <1285768533.14918.1397491647@webmail.messagingengine.com> References: <1285768533.14918.1397491647@webmail.messagingengine.com> Message-ID: <201009291656.23480.thomas@jollybox.de> On Wednesday 29 September 2010, it occurred to Hugo L?veill? to exclaim: > Thanks, will take a closer look on that > > But to get me started, how would you get, via python, the info from that > ? Parse the files. They may be very special files, but they are just files. > > Thanks alot > > > On Thu, 30 Sep 2010 02:01 +1300, "Lawrence D'Oliveiro" > > wrote: > > /proc/stat or /proc/uptime, depending. See the proc(5) man page. From hugol at fastmail.net Wed Sep 29 10:57:47 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Wed, 29 Sep 2010 10:57:47 -0400 Subject: System idle time under Linux In-Reply-To: References: Message-ID: <1285772267.31332.1397503573@webmail.messagingengine.com> Sorry, I am not a linux guy. Did not know it was a text file On Wed, 29 Sep 2010 14:48 +0000, "Grant Edwards" wrote: > On 2010-09-29, Hugo L?veill? wrote: > > > > Thanks, will take a closer look on that > > > > But to get me started, how would you get, via python, the info from that? > > Good grief. They're text files. You open them, you read them, > you parse the contents for the stuff you want. > > -- > Grant Edwards grant.b.edwards Yow! Did something bad > at happen or am I in a > gmail.com drive-in movie?? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hugo L?veill? hugol at fastmail.net From invalid at invalid.invalid Wed Sep 29 11:36:33 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Sep 2010 15:36:33 +0000 (UTC) Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > Sorry, I am not a linux guy. Did not know it was a text file And the "file" command (the usual way to figure that out) doesn't appear to be helpful: $ file /etc/passwd /etc/passwd: ASCII text [That's helpful] $ file /proc/stat /proc/stat: empty [That's not] However, as usual, Google comes to rescue. The first hit for "/proc/stat" has a detailed description: http://www.linuxhowtos.org/System/procstat.htm -- Grant Edwards grant.b.edwards Yow! My mind is a potato at field ... gmail.com From philip at semanchuk.com Wed Sep 29 11:44:53 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 29 Sep 2010 11:44:53 -0400 Subject: how to test get_special_folder_path()? Message-ID: <8CEC873D-98E1-4D3A-AEDC-52784EA5D927@semanchuk.com> Hi all, The documentation for get_special_folder_path() and friends says that they're "available as additional built-in functions in the installation script". http://docs.python.org/distutils/builtdist.html#the-postinstallation-script Does anyone know of a way to play around with these functions outside of a post-install script? It's time-consuming to install something just to experiment with a single function. Thanks Philip From emile at fenx.com Wed Sep 29 11:46:43 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 29 Sep 2010 08:46:43 -0700 Subject: if the else short form In-Reply-To: References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: On 9/29/2010 5:53 AM Philip Semanchuk said... > > Does Python make any guarantee that int(True) == 1 and int(False) == 0 will always hold, or are their values an implementation detail? > I had exactly this same question occur to me yesterday, and yes, I believe it does. From http://docs.python.org/reference/datamodel.html#objects-values-and-types Booleans These represent the truth values False and True. The two objects representing the values False and True are the only Boolean objects. The Boolean type is a subtype of plain integers, and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively. Emile From usenot at geekmail.INVALID Wed Sep 29 11:47:01 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 29 Sep 2010 11:47:01 -0400 Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: <20100929114701.110c18b5@geekmail.INVALID> On Wed, 29 Sep 2010 08:53:17 -0400 Philip Semanchuk wrote: > Does Python make any guarantee that int(True) == 1 and int(False) == > 0 will always hold, or are their values an implementation detail? > Booleans (bool) These represent the truth values False and True. The two objects representing the values False and True are the only Boolean objects. The Boolean type is a subtype of the integer type, and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively. /W -- INVALID? DE! From sridharr at activestate.com Wed Sep 29 12:16:54 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Wed, 29 Sep 2010 09:16:54 -0700 Subject: bzr 2.2.1 released ! In-Reply-To: References: Message-ID: Hi, It seems that you forgot to update PyPI - which lists 2.1.0rc1 as the latest version. -srid On 2010-09-28, at 7:20 AM, Vincent Ladeuil wrote: > The Bazaar team is happy to announce availability of a new > release of the bzr adaptive version control system. > Bazaar is part of the GNU system . > > This is a bugfix release which also includes bugfixes from 2.0.6 and > 2.1.3. None are critical, but upgrading is recommended for all users on > earlier 2.2 releases. > > Thanks to everyone who contributed patches, suggestions, and > feedback. > > Bazaar is now available for download from > > https://launchpad.net/bzr/2.2/2.2.1/ > > as a source tarball. Packages are already available for Ubuntu, FreeBSD > and others. Installers are available for OSX, windows installers should > be available Really Soon Now (watch the url above where they should pop > up as soon as they become available). > > bzr 2.2.1 > ######### > > :2.2.1: 2010-09-17 > > This is a bugfix release which also includes bugfixes from 2.0.6 and > 2.1.3. None are critical, but upgrading is recommended for all users on > earlier 2.2 releases. > > Bug Fixes > ********* > > * Additional merges after an unrelated branch has been merged with its > history no longer crash when deleted files are involved. > (Vincent Ladeuil, John Arbash Meinel, #375898) > > * ``bzr add SYMLINK/FILE`` now works properly when the symlink points to a > previously-unversioned directory within the tree: the directory is > marked versioned too. > (Martin Pool, #192859) > > * ``bzr commit SYMLINK`` now works, rather than trying to commit the > target of the symlink. > (Martin Pool, John Arbash Meinel, #128562) > > * ``bzr upgrade`` now creates the ``backup.bzr`` directory with the same > permissions as ``.bzr`` directory on a POSIX OS. > (Parth Malwankar, #262450) > > * CommitBuilder now uses the committer instead of _config.username to generate > the revision-id. (Aaron Bentley, #614404) > > * Configuration files in ``${BZR_HOME}`` are now written in an atomic > way which should help avoid problems with concurrent writers. > (Vincent Ladeuil, #525571) > > * Cope with Microsoft FTP server that returns reply '250 Directory > created' when mkdir succeeds. (Martin Pool, #224373) > > * Don't traceback trying to unversion children files of an already > unversioned directory. (Vincent Ladeuil, #494221) > > * Don't traceback when a lockdir's ``held/info`` file is corrupt (e.g. > contains only NUL bytes). Instead warn the user, and allow ``bzr > break-lock`` to remove it. (Andrew Bennetts, #619872) > > * Fix ``AttributeError on parent.children`` when adding a file under a > directory that was a symlink in the previous commit. > (Martin Pool, #192859) > > * Fix ``AttributeError: 'NoneType' object has no attribute 'close'`` in > ``_close_ssh_proc`` when using ``bzr+ssh://``. This was causing > connections to pre-1.6 bzr+ssh servers to fail, and causing warnings on > stderr in some other circumstances. (Andrew Bennetts, #633745) > > * Only call ``setlocale`` in the bzr startup script on posix systems. This > avoids an issue with the newer windows C runtimes used by Python 2.6 and > later which can mangle bytestrings printed to the console. > (Martin [gz], #631350) > > * Prevent ``CHKMap.apply_delta`` from generating non-canonical CHK maps, > which can result in "missing referenced chk root keys" errors when > fetching from repositories with affected revisions. > (Andrew Bennetts, #522637) > > * Raise ValueError instead of a string exception. > (John Arbash Meinel, #586926) > > * Reduce peak memory by one copy of compressed text. > (John Arbash Meinel, #566940) > > * Repositories accessed via a smart server now reject being stacked on a > repository in an incompatible format, as is the case when accessing them > via other methods. This was causing fetches from those repositories via > a smart server (e.g. using ``bzr branch``) to receive invalid data. > (Andrew Bennetts, #562380) > > * Selftest with versions of subunit that support ``stopTestRun`` will no longer > error. This error was caused by 2.0 not being updated when upstream > python merged the end of run patch, which chose ``stopTestRun`` rather than > ``done``. (Robert Collins, #571437) > > * Stop ``AttributeError: 'module' object has no attribute 'ElementTree'`` > being thrown from ``xml_serializer`` on certain cElementTree setups. > (Martin [gz], #254278) > > * Upgrading or fetching from a non-rich-root repository to a rich-root > repository (e.g. from pack-0.92 to 2a) no longer fails with > ``'Inter1and2Helper' object has no attribute 'source_repo'``. This was > a regression from Bazaar 2.1. (Andrew Bennetts, #636930) > > * When passing a file to ``UTF8DirReader`` make sure to close the current > directory file handle after the chdir fails. Otherwise when passing many > filenames into a command line ``bzr status`` we would leak descriptors. > (John Arbash Meinel, #583486) > > Documentation > ************* > > * Fix a lot of references in the docs to the old http://bazaar-vcs.org to > the new http://bazaar.canonical.com or http://wiki.bazaar.canonical.com > (John Arbash Meinel, #617503) > > Internals > ********* > > * Remove used and broken code path in ``BranchInitHookParams.__repr__``. > (Andrew Bennetts) > > Testing > ******* > > * ``build_tree_contents`` can create symlinks. > (Martin Pool, John Arbash Meinel) > > * Tracebacks from a parameterized test are no longer reported against every > parameterization of that test. This was done by adding a hack to > ``bzrlib.tests.clone_test`` so that it no longer causes > testtools.TestCase instances to share a details dict. > (Andrew Bennetts, #625574) > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ From nagle at animats.com Wed Sep 29 12:49:37 2010 From: nagle at animats.com (John Nagle) Date: Wed, 29 Sep 2010 09:49:37 -0700 Subject: Python becoming orphaned over ssh In-Reply-To: References: Message-ID: <4ca36e44$0$1584$742ec2ed@news.sonic.net> On 9/29/2010 7:24 AM, David wrote: > Hi there, I have a strange situation. > > If I do this: > > 1. Make a script /tmp/test.py on a remote server, with this contents: > > #!/usr/bin/python > from subprocess import check_call Python's signal handling for multithread and multiprocess programs leaves something to be desired. John Nagle From jmellander at lbl.gov Wed Sep 29 12:50:21 2010 From: jmellander at lbl.gov (Jim Mellander) Date: Wed, 29 Sep 2010 09:50:21 -0700 Subject: Determine sockets in use by python Message-ID: Hi: I'm a newbie to python, although not to programming. Briefly, I am using a binding to an external library used for communication in a client-server context, with the server in python. Typically, I would set this up with event callbacks, and then enter a select loop, which, most the time idles and processes input events when the socket shows activity, kinda like: while True: socket.select((my_socket),(),()) process_event() Unfortunately, the API does not expose the socket to the script level, and the developer recommends a busy loop: while True: sleep(1) process_event() which I hope to avoid, for many reasons. If the socket can be exposed to the script level, then the problem would be solved. Failing that, it would be nice to be able to pythonically determine the sockets in use and select on those. Does anyone have any suggestions on how to proceed? Thanks in advance From ethan at stoneleaf.us Wed Sep 29 13:11:13 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 29 Sep 2010 10:11:13 -0700 Subject: Supplementing the std lib (Was: partial sums problem) In-Reply-To: References: Message-ID: <4CA37331.2020704@stoneleaf.us> kj wrote: > I'm interested in reading people's take on the question and their > way of dealing with those functions they consider worthy of the > standard library.) Well, I have no functions than I'm lobbying to get into the stdlib, but for all those handy-dandy utility functions, decorators, and classes, I have a cookbook package that I add them to. Mine currently looks like this: cookbook __init__.py decorators.py meters.py simplegeneric.py utils.py collections __init__.py NamedTuple.py RecordType.py From usenet-nospam at seebs.net Wed Sep 29 13:20:39 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 17:20:39 GMT Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: On 2010-09-29, Tracubik wrote: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can any of > you pass me any reference/link to this particular if/then/else form? Oh, what a nasty idiom. Here's the gimmick. ("False,", "True,") is a tuple. That means you can index it. For instance: ("False,", "True,")[0] is the string "False,". So, what is the numeric value of "fill == True"? Apparently, at least at the time this was written, it was 0 if fill was not equal to True, and 1 if fill was equal to True. Let me say, though, that I'm a C programmer, so I'm coming from a language where the result of 0-or-1 for test operators is guaranteed, and I still wouldn't use this in live code. It's insufficiently legible. -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 Sep 29 13:25:03 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 17:25:03 GMT Subject: sequence multiplied by -1 References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 2010-09-29, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> Helps, perhaps, that I got exposed to group theory early enough to be used >> to redefining + and * to be any two operations which have interesting >> properties ... > But groups only have one such operation; it???s rings and fields (and number > systems) that have two. They're covered in the same class, therefore, they're part of the same field (of study, that is). :P -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 Sep 29 13:27:13 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 17:27:13 GMT Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > I have found it for windows and mac, but no luck under linux. Any idea? I don't think it's semantically well-defined. What makes a system "idle"? Is the machine in my basement idle? I don't think anyone's touched the keyboard in a week, but it's spent a big chunk of that time with 100% CPU load across all eight processors, and I was running a bunch of work on it yesterday, including interactive sessions. Windows and Mac systems *typically* have a well-defined "console" on which the primary user is active... But as a counterexample, my news reader is actually running on an OS X box that's about fifty feet from me, which I connect to via ssh. I would be very curious to see whether your test for "system idle time" would realize that the machine I'm currently working on is actively in use, even though I don't think the console is even logged in... Basically, I can't help you, but I can tell you that you are quite possibly asking the wrong question. -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 tar at sevak.isi.edu Wed Sep 29 13:54:53 2010 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 29 Sep 2010 10:54:53 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: George Neuner writes: > On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson > wrote: > >He didn't say it was. Internal calculations are done in SI units (in > >this case, m^3/sec); on output, the internal units can be converted to > >whatever is convenient. > > That's true. But it is a situation where the conversion to SI units > loses precision and therefore probably shouldn't be done. I suppose that one has to choose between two fundamental designs for any computational system of units. One can either store the results internally in a canonical form, which generally means an internal representation in SI units. Then all calculations are performed using the interal units representation and conversion happens only on input or output. Or one can store the values in their original input form, and perform conversions on the fly during calculations. For calculations one will still need to have some canonical representation for cases where the result value doesn't have a preferred unit provided. For internal calculations this will often be the case. Now whether one will necessarily have a loss of precision depends on whether the conversion factors are exact or approximations. As long as the factors are exact, one can have the internal representation be exact as well. One method would be to use something like the Commmon Lisp rational numbers or the Gnu mp library. And a representation where one preserves the "preferred" unit for display purposes based on the original data as entered is also nice. Roman Cunis' Common Lisp library does that, and with the use of rational numbers for storing values and conversion factors allows one to do nice things like make sure that 30mph * 3h = 90mi even when the internal representation is in SI units (m/s, s, m). -- Thomas A. Russ, USC/Information Sciences Institute From namekuseijin at gmail.com Wed Sep 29 14:02:03 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Wed, 29 Sep 2010 11:02:03 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> Message-ID: <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> On 28 set, 19:38, Xah Lee wrote: > ? ?list comprehension? is a very bad jargon; thus harmful to > functional programing or programing in general. Being a bad jargon, it > encourage mis-communication, mis-understanding. I disagree: it is a quite intuitive term to describe what the expression does. > ? ?list comprehension? is a redundant concept in programing. The > concept is of historical interest. e.g. when people talk about the > history of computer languages. The LC can simply be filter(map(func, > list), predicate). I agree it is redundant. Like pretty much all syntax: all one needs is a way to define functions and to apply function to arguments (or assignment and pre-defined loops for imperative folks). Syntax may still be more convenient, though. Which is strange since you were an ardent syntax lover a few iterations ago. > ? The special syntax of ?list comprehension? as it exists in many > langs, are not necessary. It can simply be a plain function, e.g > LC(function, list, filter). I disagree. Syntax may be redundant, but it is there to be convenient. I'll quote it again: "For instance, this is far more convenient: [x+1 for x in [1,2,3,4,5] if x%2==0] than this: map(lambda x:x+1,filter(lambda x:x%2==0,[1,2,3,4,5])) but on the other hand, this is more convenient: map(inc,filter(evenp,[1,2,3,4,5])) (ignoring the lines of code for inc and evenp, of course. But as long as they are used in many parts, it *is* more convenient) In short, list comprehensions are useful syntatic expressions returning lists as long as you don't care for the short functions used in them." > ?do syntax does allow for imperative commands to be issued in scheme, > just like let. It does not mean it was used in said examples nor that > do is automatically inherently imperative just because of choice of > name. imperative do -> (do (steppers ...) (final-condition? result) > malign-imperative-code-here ...)? > > i don't think your argument is forceful enough. > > It appears that by this argument you even say that ?let? is not > functional. In the case of Lisps, it depends on context: let is an expression returning a value, but Lisps are not purely functional languages and you *may* use imperative statements in the body, resulting in useful side-effect computations. That's why I said do is no more imperative than let: 1) because it *is* let and 2) because Lisps *allow* imperative constructs in the body of lambdas. do is not inherently imperative in the same sense Lisp/Scheme is not inherently imperative: they allow you to do purely functional evaluation of expressions but also to tint the computations with side-effects... your choice. > So, overall, i consider your argument for ?do? in Scheme lisp being > functional is weak, or trivial. It seems to be a pet peeve. It is a pet peeve in that you call `do' imperative without arguments while a few other Schemers call `do' imperative on the basis of political bickering. Nobody gives `do' a chance of the base of it being what it is: a macro transform into let. Any imperative programming you do with `do' will get the same effect as if you do the same imperative programming with let. Imperative or functional, it's up to the user, not inherently from any language construct. > You got > annoyed because i seem to have ignored it entirely. But i got annoyed > by you because you don't get the point about what i consider more > significant opinion on ?list comprehension?, which you totally ignored > and kept at hacking the ?do? in Scheme lisp. It's because I don't think I have much to comment on list comprehensions other than being useful syntax at times for an expression returning a list. From gherron at digipen.edu Wed Sep 29 14:05:14 2010 From: gherron at digipen.edu (Gary Herron) Date: Wed, 29 Sep 2010 11:05:14 -0700 Subject: Determine sockets in use by python In-Reply-To: References: Message-ID: <4CA37FDA.3080605@digipen.edu> On 09/29/2010 09:50 AM, Jim Mellander wrote: > Hi: > > I'm a newbie to python, although not to programming. Briefly, I am > using a binding to an external library used for communication in a > client-server context, with the server in python. Typically, I would > set this up with event callbacks, and then enter a select loop, which, > most the time idles and processes input events when the socket shows > activity, kinda like: > > while True: > socket.select((my_socket),(),()) > process_event() > > Unfortunately, the API does not expose the socket to the script level, > and the developer recommends a busy loop: > > while True: > sleep(1) > process_event() > > which I hope to avoid, for many reasons. If the socket can be exposed > to the script level, then the problem would be solved. > > Failing that, it would be nice to be able to pythonically determine > the sockets in use and select on those. Does anyone have any > suggestions on how to proceed? > > Thanks in advance > It's certain that any answer to this will depend on which operating system you are using. So do tell: What OS? -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From gneuner2 at comcast.net Wed Sep 29 14:18:27 2010 From: gneuner2 at comcast.net (George Neuner) Date: Wed, 29 Sep 2010 14:18:27 -0400 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <87bp7gq1c5.fsf@kuiper.lan.informatimago.com> Message-ID: On Wed, 29 Sep 2010 12:40:58 +0200, pjb at informatimago.com (Pascal J. Bourguignon) wrote: >George Neuner writes: > >> On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson >> wrote: >> >>>George Neuner writes: >>>> On 28 Sep 2010 12:42:40 GMT, Albert van der Horst >>>> wrote: >>>>>I would say the dimensional checking is underrated. It must be >>>>>complemented with a hard and fast rule about only using standard >>>>>(SI) units internally. >>>>> >>>>>Oil output internal : m^3/sec >>>>>Oil output printed: kbarrels/day >>>> >>>> "barrel" is not an SI unit. >>> >>>He didn't say it was. Internal calculations are done in SI units (in >>>this case, m^3/sec); on output, the internal units can be converted to >>>whatever is convenient. >> >> That's true. But it is a situation where the conversion to SI units >> loses precision and therefore probably shouldn't be done. >> >>> >>>> And when speaking about oil there isn't >>>> even a simple conversion. >>>> >>>> 42 US gallons ? 34.9723 imp gal ? 158.9873 L >>>> >>>> [In case those marks don't render, they are meant to be the >>>> double-tilda sign meaning "approximately equal".] >>> >>>There are multiple different kinds of "barrels", but "barrels of oil" >>>are (consistently, as far as I know) defined as 42 US liquid gallons. >>>A US liquid gallon is, by definition, 231 cubic inches; an inch >>>is, by definition, 0.0254 meter. So a barrel of oil is *exactly* >>>0.158987294928 m^3, and 1 m^3/sec is exactly 13.7365022817792 >>>kbarrels/day. (Please feel free to check my math.) That's >>>admittedly a lot of digits, but there's no need for approximations >>>(unless they're imposed by the numeric representation you're using). >> >> I don't care to check it ... the fact that the SI unit involves 12 >> decimal places whereas the imperial unit involves 3 tells me the >> conversion probably shouldn't be done in a program that wants >> accuracy. > > >Because perhaps you're thinking that oil is sent over the oceans, and >sold retails in barrils of 42 gallons? > >Actually, when I buy oil, it's from a pump that's graduated in liters! > >It comes from trucks with citerns containing 24 m?. > >And these trucks get it from reservoirs of 23,850 m?. > >"Tankers move approximately 2,000,000,000 metric tons" says the English >Wikipedia page... > > > >Now perhaps it all depends on whether you buy your oil from Total or >from Texaco, but in my opinion, you're forgetting something: the last >drop. You never get exactly 42 gallons of oil, there's always a little >drop more or less, so what you get is perhaps 158.987 liter or >41.9999221 US gallons, or even 158.98 liter = 41.9980729 US gallons, >where you need more significant digits. No. I'm just reacting to the "significant figures" issue. Real world issues like US vs Eurozone and measurement error aside - and without implying anyone here - many people seem to forget that multiplying significant figures doesn't add them, and results to 12 decimal places are not necessarily any more accurate than results to 2 decimal places. It makes sense to break macro barrel into micro units only when necessary. When a refinery purchases 500,000 barrels, it is charged a barrel price, not some multiple of gallon or liter price and regardless of drop over/under. The refinery's process is continuous and it needs a delivery if it has less than 20,000 barrels - so the current reserve figure of 174,092 barrels is as accurate as is needed (they need to order by tomorrow because delivery will take 10 days). OTOH, because the refinery sells product to commercial vendors of gasoline/petrol and heating oil in gallons or liters, it does makes sense to track inventory and sales in (large multiples of) those units. Similarly, converting everything to m? simply because you can does not make sense. When talking about the natural gas reserve of the United States, the figures are given in Km? - a few thousand m? either way is irrelevant. George From python at mrabarnett.plus.com Wed Sep 29 14:18:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 19:18:51 +0100 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <4CA3830B.60807@mrabarnett.plus.com> On 29/09/2010 18:54, Thomas A. Russ wrote: > George Neuner writes: > >> On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson >> wrote: >>> He didn't say it was. Internal calculations are done in SI units (in >>> this case, m^3/sec); on output, the internal units can be converted to >>> whatever is convenient. >> >> That's true. But it is a situation where the conversion to SI units >> loses precision and therefore probably shouldn't be done. > > I suppose that one has to choose between two fundamental designs for any > computational system of units. One can either store the results > internally in a canonical form, which generally means an internal > representation in SI units. Then all calculations are performed using > the interal units representation and conversion happens only on input or > output. > > Or one can store the values in their original input form, and perform > conversions on the fly during calculations. For calculations one will > still need to have some canonical representation for cases where the > result value doesn't have a preferred unit provided. For internal > calculations this will often be the case. > > Now whether one will necessarily have a loss of precision depends on > whether the conversion factors are exact or approximations. As long as > the factors are exact, one can have the internal representation be exact > as well. One method would be to use something like the Commmon Lisp > rational numbers or the Gnu mp library. > > And a representation where one preserves the "preferred" unit for > display purposes based on the original data as entered is also nice. > Roman Cunis' Common Lisp library does that, and with the use of rational > numbers for storing values and conversion factors allows one to do nice > things like make sure that > > 30mph * 3h = 90mi > > even when the internal representation is in SI units (m/s, s, m). > You could compare it to handling strings, where Unicode is used internally and the encoding can be preserved for when you want to output. From catphive at catphive.net Wed Sep 29 14:33:46 2010 From: catphive at catphive.net (Brendan Miller) Date: Wed, 29 Sep 2010 11:33:46 -0700 Subject: utf-8 and ctypes In-Reply-To: References: Message-ID: 2010/9/29 Lawrence D'Oliveiro : > In message , Brendan > Miller wrote: > >> It seems that characters not in the ascii subset of UTF-8 are >> discarded by c_char_p during the conversion ... > > Not a chance. > >> ... or at least they don't print out when I go to print the string. > > So it seems there?s a problem on the printing side. What happens when you > construct a UTF-8-encoded string directly in Python and try printing it the > same way? Doing this seems to confirm something is broken in ctypes w.r.t. UTF-8... if I enter: str = "???????" Then: print str ??????? However, when I create a string buffer, pass it into my c++ code, and write the same UTF-8 string into it, python seems to discard pretty much all the text. The same code works for pure ascii strings. Python code: _std_string_size = _lib_mbxclient.std_string_size _std_string_size.restype = c_long _std_string_size.argtypes = [c_void_p] _std_string_copy = _lib_mbxclient.std_string_copy _std_string_copy.restype = None _std_string_copy.argtypes = [c_void_p, POINTER(c_char)] # This function works for ascii, but breaks on strings with UTF-8! def std_string_to_string(str_ptr): buf = create_string_buffer(_std_string_size(str_ptr)) _std_string_copy(str_ptr, buf) return buf.raw C++ code: extern "C" long std_string_size(string* str) { return str->size(); } extern "C" void std_string_copy(string* str, char* buf) { std::copy(str->begin(), str->end(), buf); } From hugol at fastmail.net Wed Sep 29 14:36:00 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Wed, 29 Sep 2010 14:36:00 -0400 Subject: System idle time under Linux In-Reply-To: References: Message-ID: <1285785360.27605.1397544741@webmail.messagingengine.com> Good point One I am looking for, is time since last user mouse or keyboard action. So I guess I am looking for the exact same thing a screensaver is looking for On Wed, 29 Sep 2010 17:27 +0000, "Seebs" wrote: > On 2010-09-29, Hugo L?veill? wrote: > > I have found it for windows and mac, but no luck under linux. Any idea? > > I don't think it's semantically well-defined. What makes a system > "idle"? > > Is the machine in my basement idle? I don't think anyone's touched the > keyboard in a week, but it's spent a big chunk of that time with 100% CPU > load across all eight processors, and I was running a bunch of work on > it yesterday, including interactive sessions. > > Windows and Mac systems *typically* have a well-defined "console" on > which > the primary user is active... But as a counterexample, my news reader is > actually running on an OS X box that's about fifty feet from me, which I > connect to via ssh. > > I would be very curious to see whether your test for "system idle time" > would realize that the machine I'm currently working on is actively in > use, > even though I don't think the console is even logged in... > > Basically, I can't help you, but I can tell you that you are quite > possibly > asking the wrong question. > > -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 > -- Hugo L?veill? hugol at fastmail.net From tjreedy at udel.edu Wed Sep 29 14:46:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Sep 2010 14:46:18 -0400 Subject: About __class__ of an int literal In-Reply-To: <8739ss4tk6.fsf@xemacs.org> References: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> <8739ss4tk6.fsf@xemacs.org> Message-ID: On 9/29/2010 8:34 AM, Hrvoje Niksic wrote: > Steven D'Aprano writes: > >> On Wed, 29 Sep 2010 02:20:55 +0100, MRAB wrote: >> >>> On 29/09/2010 01:19, Terry Reedy wrote: >> >>>> A person using instances of a class should seldom use special names >>>> directly. They are, in a sense, implementation details, even if >>>> documented. The idiom "if __name__ == '__main__':" is an exception. >>>> >>> __file__ is another exception. >> As are __iter__, __next__, __add__, __dict__, and, yes, __class__, to >> say nothing of all the other special methods. I strongly disagree. > I think by "person using instances of a class" Terry referred to the > user of a class as opposed to the implementor. Yes. > In that sense the user > should be calling iter(foo) instead of foo.__iter__(), next(foo) instead > of foo.__next__(), and foo+bar instead of foo.__add__(bar). Yes. Guido added iter() and next() to the list of built-in functions, even though they seem reduncant.. I believe it is his intention that the use of special names outside of class statements should be fairly rare. If I remember right, in the old, pre-2.2 system that separated built-in types and user-written classes, the builtins did not have accessible special method attributes. They are only for customizing user classes. So one could not have generically written foo.__add__(bar). Special-method attribute were added to builtins so that they could be inherited (or replaced) by user-written subclasses, not so that one could replace normal syntax. > Direct > calls to special-name methods, such as __len__, often indicate that the > programmer hasn't grasped how those methods are intended to be used in > Python. Right. That fact that *Python* interpreters implement syntax with special methods is an implementation detail of the *language*. The importance is that it allow *writers* of new classes to rather easily imitate built-in classes so that their classes seamlessly plug into the syntax. -- Terry Jan Reedy From usenet-nospam at seebs.net Wed Sep 29 15:07:55 2010 From: usenet-nospam at seebs.net (Seebs) Date: 29 Sep 2010 19:07:55 GMT Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > One I am looking for, is time since last user mouse or keyboard action. > So I guess I am looking for the exact same thing a screensaver is > looking for You can probably get it from X somehow, but... Basically, be aware that it is entirely possible for a Linux user to invoke python scripts in an enviromnent where this information cannot be obtained, and may not even meaningfully exist. So be sure you fail back gracefully when that happens. Decide in advance what you will infer from "there is no way to obtain this information". Also provide an override. Imagine how helpful it would be to a user to have your script act as though the user had gone idle based on what some OTHER user was doing! -s From invalid at invalid.invalid Wed Sep 29 15:23:54 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Sep 2010 19:23:54 +0000 (UTC) Subject: System idle time under Linux References: Message-ID: On 2010-09-29, Hugo L?veill? wrote: > One I am looking for, is time since last user mouse or keyboard action. > So I guess I am looking for the exact same thing a screensaver is > looking for Oh. That's not what "idle" generally means in a Unix/Linux context, so you can disregard previous answers involving /proc/stat et al. -- Grant Edwards grant.b.edwards Yow! It's some people at inside the wall! This is gmail.com better than mopping! From squeamz at hotmail.com Wed Sep 29 15:41:00 2010 From: squeamz at hotmail.com (Squeamizh) Date: Wed, 29 Sep 2010 12:41:00 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> Message-ID: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> On Sep 27, 10:46?am, namekuseijin wrote: > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > wrote: > > > RG writes: > > > > In article > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, > > > > ?TheFlyingDutchman wrote: > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > >> > This might have been mentioned here before, but I just came across it: a > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get built in > > > >> > dynamically-typed languages. ?It echoes things we've all said here, but > > > >> > I think it's interesting because it describes a conversion experience: > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > >> > -- Scott > > > > >> If you are writing a function to determine the maximum of two numbers > > > >> passed as arguents in a dynamic typed language, what is the normal > > > >> procedure used by Eckel and others to handle someone passing in > > > >> invalid values - such as a file handle for one varible and an array > > > >> for the other? > > > > > The normal procedure is to hit such a person over the head with a stick > > > > and shout "FOO". > > > > Moreover, the functions returning the maximum may be able to work on > > > non-numbers, as long as they're comparable. ?What's more, there are > > > numbers that are NOT comparable by the operator you're thinking about!. > > > > So to implement your specifications, that function would have to be > > > implemented for example as: > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > (defmethod lessp ((x complex) (y complex)) > > > ? (or (< (real-part x) (real-part y)) > > > ? ? ? (and (= (real-part x) (real-part y)) > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > (defun maximum (a b) > > > ? (if (lessp a b) b a)) > > > > And then the client of that function could very well add methods: > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > and call: > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > and who are you to forbid it!? > > > > -- > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/-Hidequoted text - > > > > - Show quoted text - > > > in C I can have a function maximum(int a, int b) that will always > > work. Never blow up, and never give an invalid answer. If someone > > tries to call it incorrectly it is a compile error. > > In a dynamic typed language maximum(a, b) can be called with incorrect > > datatypes. Even if I make it so it can handle many types as you did > > above, it could still be inadvertantly called with a file handle for a > > parameter or some other type not provided for. So does Eckel and > > others, when they are writing their dynamically typed code advocate > > just letting the function blow up or give a bogus answer, or do they > > check for valid types passed? If they are checking for valid types it > > would seem that any benefits gained by not specifying type are lost by > > checking for type. And if they don't check for type it would seem that > > their code's error handling is poor. > > that is a lie. > > Compilation only makes sure that values provided at compilation-time > are of the right datatype. > > What happens though is that in the real world, pretty much all > computation depends on user provided values at runtime. ?See where are > we heading? > > this works at compilation time without warnings: > int m=numbermax( 2, 6 ); > > this too: > int a, b, m; > scanf( "%d", &a ); > scanf( "%d", &b ); > m=numbermax( a, b ); > > no compiler issues, but will not work just as much as in python if > user provides "foo" and "bar" for a and b... fail. > > What you do if you're feeling insecure and paranoid? ?Just what > dynamically typed languages do: ?add runtime checks. ?Unit tests are > great to assert those. > > Fact is: ?almost all user data from the external words comes into > programs as strings. ?No typesystem or compiler handles this fact all > that graceful... I disagree with your conclusion. Sure, the data was textual when it was initially read by the program, but that should only be relevant to the input processing code. The data is likely converted to some internal representation immediately after it is read and validated, and in a sanely-designed program, it maintains this representation throughout its life time. If the structure of some data needs to change during development, the compiler of a statically-typed language will automatically tell you about any client code that was not updated to account for the change. Dynamically typed languages do not provide this assurance. From jmellander at lbl.gov Wed Sep 29 16:08:30 2010 From: jmellander at lbl.gov (Jim Mellander) Date: Wed, 29 Sep 2010 13:08:30 -0700 Subject: Determine sockets in use by python In-Reply-To: <4CA37FDA.3080605@digipen.edu> References: <4CA37FDA.3080605@digipen.edu> Message-ID: Hi Gary: Certainly not windows.... I'm developing on OS/X but for production probably Linux and FreeBSD (I'm hoping for something a bit more portable than running 'lsof' and parsing the output, but appreciate any/all advice) On Wed, Sep 29, 2010 at 11:05 AM, Gary Herron wrote: > On 09/29/2010 09:50 AM, Jim Mellander wrote: >> >> Hi: >> >> I'm a newbie to python, although not to programming. ?Briefly, I am >> using a binding to an external library used for communication in a >> client-server context, with the server in python. ?Typically, I would >> set this up with event callbacks, and then enter a select loop, which, >> most the time idles and processes input events when the socket shows >> activity, kinda like: >> >> while True: >> ? ? socket.select((my_socket),(),()) >> ? ? process_event() >> >> Unfortunately, the API does not expose the socket to the script level, >> and the developer recommends a busy loop: >> >> while True: >> ? ? sleep(1) >> ? ? process_event() >> >> which I hope to avoid, for many reasons. ?If the socket can be exposed >> to the script level, then the problem would be solved. >> >> Failing that, it would be nice to be able to pythonically determine >> the sockets in use and select on those. ?Does anyone have any >> suggestions on how to proceed? >> >> Thanks in advance >> > > It's certain that any answer to this will depend on which operating system > you are using. ?So do tell: What OS? > > -- > Gary Herron, PhD. > Department of Computer Science > DigiPen Institute of Technology > (425) 895-4418 > > -- > http://mail.python.org/mailman/listinfo/python-list > From nad at acm.org Wed Sep 29 16:12:49 2010 From: nad at acm.org (Ned Deily) Date: Wed, 29 Sep 2010 13:12:49 -0700 Subject: File holes in Linux References: Message-ID: In article , Tom Potts wrote: > Hi, all. I'm not sure if this is a bug report, a feature request or what, > so I'm posting it here first to see what people make of it. I was copying > over a large number of files using shutil, and I noticed that the final > files were taking up a lot more space than the originals; a bit more > investigation showed that files with a positive nominal filesize which > originally took up 0 blocks were now taking up the full amount. It seems > that Python does not write back file holes as it should; here is a simple > program to illustrate: > data = '\0' * 1000000 > file = open('filehole.test', 'wb') > file.write(data) > file.close() > A quick `ls -sl filehole.test' will show that the created file actually > takes up about 980k, rather than the 0 bytes expected. I would expect the file size to be 980k in that case. AFAIK, simply writing null bytes doesn't automatically create a sparse file on Unix-y systems. Generally, on file systems that support it, files become sparse when you don't write to certain parts of it, i.e. by using lseek(2) to position forward past the end of the file when writing, thereby implying that the intermediate blocks should be treated as zero when reading. Only files on certain file systems on certain platforms support operations like that. Python makes no claim to do that optimization in either its lower-level i/o routines or in the shutil module. The latter's copyfile just copies bytes from input to output. If you want to always preserve sparse files, you could use the GNU cp routine with --sparse=always. If you look at its code, you see that it checks for all-zero blocks when copying and then uses lseek to skip over them when writing. Something like that could be added to shutil, with the necessary tests for which platforms support it. If you are interested in adding that feature, you could write a patch and open a feature request on the Python bug tracker (http://bugs.python.org/). It's not likely to progress without a supplied patch and even then maybe not. -- Ned Deily, nad at acm.org From nad at acm.org Wed Sep 29 16:18:48 2010 From: nad at acm.org (Ned Deily) Date: Wed, 29 Sep 2010 13:18:48 -0700 Subject: Certificate validation with HTTPSConnection References: Message-ID: In article , Velko Ivanov wrote: > I've always wandered why HTTPSConnection does not validate > certificates? > > It is fairly simple to use the SSL socket's validation: [...] Perhaps you can write up your example as a documentation patch to the http.client documentation page and submit it to the Python bug tracker (http://bugs.python.org/). -- Ned Deily, nad at acm.org From lists at cheimes.de Wed Sep 29 16:32:05 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 29 Sep 2010 22:32:05 +0200 Subject: File holes in Linux In-Reply-To: References: Message-ID: Am 29.09.2010 11:05, schrieb Tom Potts: > A quick `ls -sl filehole.test' will show that the created file actually > takes up about 980k, rather than the 0 bytes expected. > > If anyone can let me know if this is indeed a bug or feature request, how to > get around it, or where to take it next, I'd really appreciate it. It's not a bug in Python. You simply misunderstand how sparse files are created. When you write null bytes to a file each null byte takes up space on the file system, too. In order to create a hole, you have to set the file handler's position beyond the file's end. >>> with open("sparse", "w") as fh: ... fh.seek(1000**3) ... fh.write("data") ... $ ls -l --si sparse -rw-r--r-- 1 heimes heimes 1,1G 2010-09-29 22:25 sparse $ ls -s sparse 4 sparse $ du sparse 4 sparse Christian From invalid at invalid.invalid Wed Sep 29 16:38:14 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Sep 2010 20:38:14 +0000 (UTC) Subject: File holes in Linux References: Message-ID: On 2010-09-29, Ned Deily wrote: >, > Tom Potts wrote: >> Hi, all. I'm not sure if this is a bug report, a feature request or what, >> so I'm posting it here first to see what people make of it. I was copying >> over a large number of files using shutil, and I noticed that the final >> files were taking up a lot more space than the originals; a bit more >> investigation showed that files with a positive nominal filesize which >> originally took up 0 blocks were now taking up the full amount. It seems >> that Python does not write back file holes as it should; here is a simple >> program to illustrate: >> data = '\0' * 1000000 >> file = open('filehole.test', 'wb') >> file.write(data) >> file.close() >> A quick `ls -sl filehole.test' will show that the created file actually >> takes up about 980k, rather than the 0 bytes expected. > > I would expect the file size to be 980k in that case. AFAIK, simply > writing null bytes doesn't automatically create a sparse file on Unix-y > systems. Correct. As Ned says, you create holes by seeking past the end of the file before writing data, not by writing 0x00 bytes. Here's a demonstration: Writing 0x00 values: $ dd if=/dev/zero of=foo1 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB) copied, 0.0315967 s, 332 MB/s $ ls -l foo1 -rw-r--r-- 1 grante users 10485760 Sep 29 15:32 foo1 $ du -s foo1 10256 foo1 Seeking, then write a single byte: $ dd if=/dev/zero of=foo2 bs=1 count=1 seek=10485759 1+0 records in 1+0 records out 1 byte (1 B) copied, 8.3075e-05 s, 12.0 kB/s $ ls -l foo2 -rw-r--r-- 1 grante users 10485760 Sep 29 15:35 foo2 $ du -s foo2 16 foo2 -- Grant Edwards grant.b.edwards Yow! Please come home with at me ... I have Tylenol!! gmail.com From nagle at animats.com Wed Sep 29 16:41:15 2010 From: nagle at animats.com (John Nagle) Date: Wed, 29 Sep 2010 13:41:15 -0700 Subject: Certificate validation with HTTPSConnection In-Reply-To: References: Message-ID: <4CA3A46B.4080006@animats.com> On 9/29/2010 1:18 PM, Ned Deily wrote: > In article, > Velko Ivanov wrote: > >> I've always wandered why HTTPSConnection does not validate >> certificates? >> >> It is fairly simple to use the SSL socket's validation: > [...] > > Perhaps you can write up your example as a documentation patch to the > http.client documentation page and submit it to the Python bug tracker > (http://bugs.python.org/). We've been through this. Too many times. http://bugs.python.org/issue1114345 (2005: Broken in Python 2.2, eventually fixed) http://www.justinsamuel.com/2008/12/25/the-importance-of-validating-ssl-certificates/ (2008: Why this matters) http://www.mail-archive.com/python-list at python.org/msg281736.html (2010: Broken in new Python 2.6 SSL module.) http://bugs.python.org/issue1589 (2010: Developer "Bill Jansen" in denial, others disagree. Currently being debated. See bug tracker.) The really stupid thing about the current SSL module is that it accepts a file of root certificates as a parameter, but ignores it. So it creates the illusion of security without providing it. As someone pointed out, the current SSL module "lets you talk encrypted to your attacker". John Nagle From xahlee at gmail.com Wed Sep 29 16:46:08 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 29 Sep 2010 13:46:08 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> Message-ID: <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> On Sep 29, 11:02?am, namekuseijin wrote: > On 28 set, 19:38, Xah Lee wrote: > > > ? ?list comprehension? is a very bad jargon; thus harmful to > > functional programing or programing in general. Being a bad jargon, it > > encourage mis-communication, mis-understanding. > > I disagree: ?it is a quite intuitive term to describe what the > expression does. what's your basis in saying that ?list comprehension? is intuitive? any statics, survery, research, references you have to cite? to put this in context, are you saying that lambda, is also intuitive? ?let? is intuitive? ?for? is intuitive? ?when? is intuitive? I mean, give your evaluation of some common computer language termilogies, and tell us which you think are good and which are bad, so we have some context to judge your claim. For example, let us know, in your view, how good are terms: currying, lisp1 lisp2, tail recursion, closure, subroutine, command, object. Or, perhaps expound on the comparative merits and meaning on the terms module vs package vs add-on vs library. I would like to see your view on this with at least few paragraphs of analysis on each. If you, say, write a essay that's at least 1k words on this topic, then we all can make some judgement of your familiarity and understanding in this area. Also, ?being intuitive? is not the only aspect to consider whether a term is good or bad. For example, emacs's uses the term ?frame?. It's quite intuitive, because frame is a common english word, everyone understands. You know, door frame, window frame, picture frame, are all analogous to emacs's ?frame? on a computer. However, by some turn of history, in computer software we call such as ?window? now, and by happance the term ?window? also has a technical meaning in emacs, what we call ?split window? or ?pane? today. So, in emacs, the term ?frame? and ?window? is confusing, because emacs's ?frame? is what we call ?window?, while emacs's ?window? is what me might call a pane of a split window. So here, is a example, that even when a term is intuitive, it can still be bad. as another example, common understanding by the target group the term is to be used is also a important aspect. For example, the term ?lambda?, which is a name of greek char, does not convey well what we use it for. The word's meaning by itself has no connection to the concept of function. The char happens to be used by a logician as a shorthand notation in his study of what's called ?lambda calculus? (the ?calculus? part is basically 1700's terminology for a systematic science, especially related to mechanical reasoning). However, the term ?lambda? used in this way in computer science and programing has been long and wide, around 50 years in recent history (and more back if we trace origins). So, because of established use, here it may decrease the level of what we might think of it as a bad jargon, by the fact that it already become a standard usage or understanding. Even still, note that just because a term has establish use, if the term itself is very bad in many other aspects, it may still warrant a need for change. For one example of a reason, the argon will be a learning curve problem for all new generations. You see, when you judge a terminology, you have to consider many aspects. It is quite involved. When judging a jargon, some question you might ask are: ? does the jargon convey its meaning by the word itself? (i.e. whether the jargon as a word is effective in communication) ? how long has been the jargon in use? ? do people in the community understand the jargon? (e.g. what percentage) each of these sample questions can get quite involved. For example, it calls for expertise in linguistics (many sub-fields are relevant: pragmatics, history of language, etymology), practical experience in the field (programing or computer science), educational expertise (e.g. educators, professors, programing book authors/teachers), scientific survey, social science of communication... also, you may not know, there are bodies of professional scientists who work on terminologies for publication. It is not something like ?O think it's good, becus it is intuitive to me.?. I wrote about 14 essays on various jargons in past decade. You can find them on my site. i removed your arguments on other parts about ?list comprehension?, because i didn't find them valuable. (barely read them) However, i appreciate your inputs on the ?do? in Scheme lisp has a functional usage, and some other misc chat info from the beginning of this thread on comp.lang.lisp. Xah ? xahlee.org ? From ian.g.kelly at gmail.com Wed Sep 29 17:48:06 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 29 Sep 2010 15:48:06 -0600 Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] In-Reply-To: <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> References: <611b2b4c-4b3d-4ec0-80d4-446352c6a0e3@y11g2000yqm.googlegroups.com> <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> Message-ID: On Wed, Sep 29, 2010 at 2:46 PM, Xah Lee wrote: > what's your basis in saying that ?list comprehension? is intuitive? > > any statics, survery, research, references you have to cite? > > to put this in context, are you saying that lambda, is also intuitive? > ?let? is intuitive? ?for? is intuitive? ?when? is intuitive? I mean, > give your evaluation of some common computer language termilogies, and > tell us which you think are good and which are bad, so we have some > context to judge your claim. > > For example, let us know, in your view, how good are terms: currying, > lisp1 lisp2, tail recursion, closure, subroutine, command, object. Or, > perhaps expound on the comparative merits and meaning on the terms > module vs package vs add-on vs library. I would like to see your view > on this with at least few paragraphs of analysis on each. If you, say, > write a essay that's at least 1k words on this topic, then we all can > make some judgement of your familiarity and understanding in this > area. > Have you actually written an essay on this topic of the sort that you are requesting here? I googled your site, but all I could find was your Perl-Python tutorial in which you simply stated that "This construct has acquired a [sic] incomprehensible name 'list comprehension' in computing industry and academia." The obvious pun aside, I don't understand why you find the name to be incomprehensible. All it means is that the list is being defined by comprehension (i.e. intension) in the logical sense, as opposed to the more common extensive definition (e.g. myList = [1, 2, 3]). The suggestion that this nomenclature is any more obscure than "lambda", in either origin or industry, is dubious to me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rog at pynguins.com Wed Sep 29 17:50:56 2010 From: rog at pynguins.com (Rog) Date: Wed, 29 Sep 2010 22:50:56 +0100 Subject: list problem... References: <4ca32e49$0$28654$c3e8da3@news.astraweb.com> <0e563359-c2fd-4fbc-808b-02cb2e483ad5@l20g2000yqm.googlegroups.com> Message-ID: On Wed, 29 Sep 2010 05:52:32 -0700, bruno.desthuilliers at gmail.com wrote: > On 29 sep, 14:17, Steven D'Aprano > wrote: >> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: >> > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: >> >> >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: >> >>> Hi all, >> >>> Have been grappling with a list problem for hours... a = [2, 3, 4, >> >>> 5,.....] >> >>> b = [4, 8, 2, 6,.....] >> >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] >> >>> and b[2] is present. >> >>> I have tried sets, zip etc with no success. I am tackling Euler >> >>> projects with Python 3.1, with minimal knowledge, and having to >> >>> tackle the language as I progress. Enjoyable frustration ?:) >> >> >> I'm not clear on what your actual problem is, could you restate it? >> >> >> It sounds like you want to copy the ith element out of a and b into >> >> some other list- call it c- when the (i+2)th element meets some >> >> condition. What's the condition? >> >> >> Geremy Condra >> >> > The condition is that the i-th element is inverted, but not equal. eg >> > 4,2 - 2,4 , 34,5 - 5,34 etc. >> > Hope that is clearer. >> >> Clear as mud. >> >> Perhaps you should given an example. Given input >> >> a = [2, 3, 4, 5, 6, 7] >> b = [4, 8, 2, 6, 10, 42] >> >> what output are you expecting, > > AFAICT, the OP expects [2, 4] in this case, but it's not clear what he'd > expect for let's say: > > a = [2, 3, 21, 4, 5, 6, 7] > b = [4, 8, 22, 2, 6, 10, 42] > > (the 'reversed' pair is at i+3, not i+2) > > or > > a = [0, 2, 3, 4, 5, 6, 7] > b = [3, 4, 8, 2, 6, 10, 42] > > (the first pair is at pos 1, not 0) > > or > > a = [2, 3, 4, 8, 6, 7] > b = [4, 8, 2, 3, 10, 42] > > (there's a second 'non-reversed/reversed' match at positions resp. 1 & 3) It is true that I would have needed any 'non-reversed/reversed' pairs, these would have been the amicable pairs I was looking for. The method to recognise them eluded me. Eyes are not good enough :) I have now joined Python-List and will follow the correct route. I have used a method suggested that has made the problem redundant, though it will bug me from now on. g = [] def divsum(n): return sum(i for i in range(1, n) if not n % i) for x in range(10000, 2, -1): c = divsum(x) v = divsum(c) if v == x and v != c: g.append(divsum(x)) else: continue print(sum(g)) -- Rog http://www.rog.pynguins.com From rNOSPAMon at flownet.com Wed Sep 29 18:02:43 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 15:02:43 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> Message-ID: In article <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1 at k22g2000prb.googlegroups.com>, Squeamizh wrote: > On Sep 27, 10:46?am, namekuseijin wrote: > > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > > > > > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > > wrote: > > > > RG writes: > > > > > In article > > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, > > > > > ?TheFlyingDutchman wrote: > > > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > > >> > This might have been mentioned here before, but I just came across > > > > >> > it: a > > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get built in > > > > >> > dynamically-typed languages. ?It echoes things we've all said > > > > >> > here, but > > > > >> > I think it's interesting because it describes a conversion > > > > >> > experience: > > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > > > >> > -- Scott > > > > > > >> If you are writing a function to determine the maximum of two > > > > >> numbers > > > > >> passed as arguents in a dynamic typed language, what is the normal > > > > >> procedure used by Eckel and others to handle someone passing in > > > > >> invalid values - such as a file handle for one varible and an array > > > > >> for the other? > > > > > > > The normal procedure is to hit such a person over the head with a > > > > > stick > > > > > and shout "FOO". > > > > > > Moreover, the functions returning the maximum may be able to work on > > > > non-numbers, as long as they're comparable. ?What's more, there are > > > > numbers that are NOT comparable by the operator you're thinking about!. > > > > > > So to implement your specifications, that function would have to be > > > > implemented for example as: > > > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > > (defmethod lessp ((x complex) (y complex)) > > > > ? (or (< (real-part x) (real-part y)) > > > > ? ? ? (and (= (real-part x) (real-part y)) > > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > > > (defun maximum (a b) > > > > ? (if (lessp a b) b a)) > > > > > > And then the client of that function could very well add methods: > > > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > > > and call: > > > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > > > and who are you to forbid it!? > > > > > > -- > > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? > > > > ?http://www.informatimago.com/-Hidequoted text - > > > > > > - Show quoted text - > > > > > in C I can have a function maximum(int a, int b) that will always > > > work. Never blow up, and never give an invalid answer. If someone > > > tries to call it incorrectly it is a compile error. > > > In a dynamic typed language maximum(a, b) can be called with incorrect > > > datatypes. Even if I make it so it can handle many types as you did > > > above, it could still be inadvertantly called with a file handle for a > > > parameter or some other type not provided for. So does Eckel and > > > others, when they are writing their dynamically typed code advocate > > > just letting the function blow up or give a bogus answer, or do they > > > check for valid types passed? If they are checking for valid types it > > > would seem that any benefits gained by not specifying type are lost by > > > checking for type. And if they don't check for type it would seem that > > > their code's error handling is poor. > > > > that is a lie. > > > > Compilation only makes sure that values provided at compilation-time > > are of the right datatype. > > > > What happens though is that in the real world, pretty much all > > computation depends on user provided values at runtime. ?See where are > > we heading? > > > > this works at compilation time without warnings: > > int m=numbermax( 2, 6 ); > > > > this too: > > int a, b, m; > > scanf( "%d", &a ); > > scanf( "%d", &b ); > > m=numbermax( a, b ); > > > > no compiler issues, but will not work just as much as in python if > > user provides "foo" and "bar" for a and b... fail. > > > > What you do if you're feeling insecure and paranoid? ?Just what > > dynamically typed languages do: ?add runtime checks. ?Unit tests are > > great to assert those. > > > > Fact is: ?almost all user data from the external words comes into > > programs as strings. ?No typesystem or compiler handles this fact all > > that graceful... > > I disagree with your conclusion. Sure, the data was textual when it > was initially read by the program, but that should only be relevant to > the input processing code. The data is likely converted to some > internal representation immediately after it is read and validated, > and in a sanely-designed program, it maintains this representation > throughout its life time. If the structure of some data needs to > change during development, the compiler of a statically-typed language > will automatically tell you about any client code that was not updated > to account for the change. Dynamically typed languages do not provide > this assurance. This is a red herring. You don't have to invoke run-time input to demonstrate bugs in a statically typed language that are not caught by the compiler. For example: [ron at mighty:~]$ cat foo.c #include int maximum(int a, int b) { return (a > b ? a : b); } int foo(int x) { return 9223372036854775807+x; } int main () { printf("%d\n", maximum(foo(1), 1)); return 0; } [ron at mighty:~]$ gcc -Wall foo.c [ron at mighty:~]$ ./a.out 1 Even simple arithmetic is Turing-complete, so catching all type-related errors at compile time would entail solving the halting problem. rg From hidura at gmail.com Wed Sep 29 18:09:40 2010 From: hidura at gmail.com (Hidura) Date: Wed, 29 Sep 2010 18:09:40 -0400 Subject: Example or recomendation of a webserver In-Reply-To: References: <87r5gcomkr.fsf@web.de> Message-ID: I use Python3.1, TurboGears, webOb, CherryPy and the others don' t work on Python 3, please somebody recomend me a web framework for Python3.1 I AM DESPERATE On Wed, Sep 29, 2010 at 6:08 PM, Hidura wrote: > I use Python3.1, TurboGears, webOb, CherryPy and the others don' t work on > Python 3, please somebody recomend me a web framework for Python3.1 I AM > DESPERATE > > On Wed, Sep 29, 2010 at 6:45 AM, Diez B. Roggisch wrote: > >> Hidura writes: >> >> > I am working on a web project written on Py3k and using mod_wsgi on >> > the Apache that have to recibes the request client via a xml structure >> > and i am facing a lot of troubles with the upload files mainly because >> > i can' t see where they are, so i' ve decide to write my own web >> > server-django and the others doen' t work for my propouse-, what you >> > recomend me for start that? >> >> not doing it. Reading the HTTP-RFC and the WSGI-PEP. And trying >> >> print environ["wsgi.input"].read() >> >> inside your wsgi-script. Then, use webob to wrap the whole WSGI-stuff to >> have at least a minimum of sensible abstraction. >> >> Or simply use Django or TurboGears2, follow the advices in their docs on >> how to depoly them using mod_wsgi, and be happy. >> >> Diez >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Diego I. Hidalgo D. > -- Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From squeamz at hotmail.com Wed Sep 29 18:11:18 2010 From: squeamz at hotmail.com (Squeamizh) Date: Wed, 29 Sep 2010 15:11:18 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> Message-ID: <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> On Sep 29, 3:02?pm, RG wrote: > In article > <996bd4e6-37ff-4a55-8db5-6e7574fbd... at k22g2000prb.googlegroups.com>, > > > > > > ?Squeamizh wrote: > > On Sep 27, 10:46?am, namekuseijin wrote: > > > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > > > wrote: > > > > > RG writes: > > > > > > In article > > > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com>, > > > > > > ?TheFlyingDutchman wrote: > > > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > > > >> > This might have been mentioned here before, but I just came across > > > > > >> > it: a > > > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get built in > > > > > >> > dynamically-typed languages. ?It echoes things we've all said > > > > > >> > here, but > > > > > >> > I think it's interesting because it describes a conversion > > > > > >> > experience: > > > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > > > >> > -- Scott > > > > > > >> If you are writing a function to determine the maximum of two > > > > > >> numbers > > > > > >> passed as arguents in a dynamic typed language, what is the normal > > > > > >> procedure used by Eckel and others to handle someone passing in > > > > > >> invalid values - such as a file handle for one varible and an array > > > > > >> for the other? > > > > > > > The normal procedure is to hit such a person over the head with a > > > > > > stick > > > > > > and shout "FOO". > > > > > > Moreover, the functions returning the maximum may be able to work on > > > > > non-numbers, as long as they're comparable. ?What's more, there are > > > > > numbers that are NOT comparable by the operator you're thinking about!. > > > > > > So to implement your specifications, that function would have to be > > > > > implemented for example as: > > > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > > > (defmethod lessp ((x complex) (y complex)) > > > > > ? (or (< (real-part x) (real-part y)) > > > > > ? ? ? (and (= (real-part x) (real-part y)) > > > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > > > (defun maximum (a b) > > > > > ? (if (lessp a b) b a)) > > > > > > And then the client of that function could very well add methods: > > > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > > > and call: > > > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > > > and who are you to forbid it!? > > > > > > -- > > > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? > > > > > ?http://www.informatimago.com/-Hidequotedtext - > > > > > > - Show quoted text - > > > > > in C I can have a function maximum(int a, int b) that will always > > > > work. Never blow up, and never give an invalid answer. If someone > > > > tries to call it incorrectly it is a compile error. > > > > In a dynamic typed language maximum(a, b) can be called with incorrect > > > > datatypes. Even if I make it so it can handle many types as you did > > > > above, it could still be inadvertantly called with a file handle for a > > > > parameter or some other type not provided for. So does Eckel and > > > > others, when they are writing their dynamically typed code advocate > > > > just letting the function blow up or give a bogus answer, or do they > > > > check for valid types passed? If they are checking for valid types it > > > > would seem that any benefits gained by not specifying type are lost by > > > > checking for type. And if they don't check for type it would seem that > > > > their code's error handling is poor. > > > > that is a lie. > > > > Compilation only makes sure that values provided at compilation-time > > > are of the right datatype. > > > > What happens though is that in the real world, pretty much all > > > computation depends on user provided values at runtime. ?See where are > > > we heading? > > > > this works at compilation time without warnings: > > > int m=numbermax( 2, 6 ); > > > > this too: > > > int a, b, m; > > > scanf( "%d", &a ); > > > scanf( "%d", &b ); > > > m=numbermax( a, b ); > > > > no compiler issues, but will not work just as much as in python if > > > user provides "foo" and "bar" for a and b... fail. > > > > What you do if you're feeling insecure and paranoid? ?Just what > > > dynamically typed languages do: ?add runtime checks. ?Unit tests are > > > great to assert those. > > > > Fact is: ?almost all user data from the external words comes into > > > programs as strings. ?No typesystem or compiler handles this fact all > > > that graceful... > > > I disagree with your conclusion. ?Sure, the data was textual when it > > was initially read by the program, but that should only be relevant to > > the input processing code. ?The data is likely converted to some > > internal representation immediately after it is read and validated, > > and in a sanely-designed program, it maintains this representation > > throughout its life time. ?If the structure of some data needs to > > change during development, the compiler of a statically-typed language > > will automatically tell you about any client code that was not updated > > to account for the change. ?Dynamically typed languages do not provide > > this assurance. > > This is a red herring. ?You don't have to invoke run-time input to > demonstrate bugs in a statically typed language that are not caught by > the compiler. ?For example: > > [ron at mighty:~]$ cat foo.c > #include > > int maximum(int a, int b) { > ? return (a > b ? a : b); > > } > > int foo(int x) { return 9223372036854775807+x; } > > int main () { > ? printf("%d\n", maximum(foo(1), 1)); > ? return 0;} > > [ron at mighty:~]$ gcc -Wall foo.c > [ron at mighty:~]$ ./a.out > 1 > > Even simple arithmetic is Turing-complete, so catching all type-related > errors at compile time would entail solving the halting problem. > > rg In short, static typing doesn't solve all conceivable problems. We are all aware that there is no perfect software development process or tool set. I'm interested in minimizing the number of problems I run into during development, and the number of bugs that are in the finished product. My opinion is that static typed languages are better at this for large projects, for the reasons I stated in my previous post. From rNOSPAMon at flownet.com Wed Sep 29 18:14:51 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 15:14:51 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, Squeamizh wrote: > On Sep 29, 3:02?pm, RG wrote: > > In article > > <996bd4e6-37ff-4a55-8db5-6e7574fbd... at k22g2000prb.googlegroups.com>, > > > > > > > > > > > > ?Squeamizh wrote: > > > On Sep 27, 10:46?am, namekuseijin wrote: > > > > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > > > > wrote: > > > > > > RG writes: > > > > > > > In article > > > > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com > > > > > > > >, > > > > > > > ?TheFlyingDutchman wrote: > > > > > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > > > > >> > This might have been mentioned here before, but I just came > > > > > > >> > across > > > > > > >> > it: a > > > > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get > > > > > > >> > built in > > > > > > >> > dynamically-typed languages. ?It echoes things we've all said > > > > > > >> > here, but > > > > > > >> > I think it's interesting because it describes a conversion > > > > > > >> > experience: > > > > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > > > > > >> > -- Scott > > > > > > > > >> If you are writing a function to determine the maximum of two > > > > > > >> numbers > > > > > > >> passed as arguents in a dynamic typed language, what is the > > > > > > >> normal > > > > > > >> procedure used by Eckel and others to handle someone passing in > > > > > > >> invalid values - such as a file handle for one varible and an > > > > > > >> array > > > > > > >> for the other? > > > > > > > > > The normal procedure is to hit such a person over the head with a > > > > > > > stick > > > > > > > and shout "FOO". > > > > > > > > Moreover, the functions returning the maximum may be able to work > > > > > > on > > > > > > non-numbers, as long as they're comparable. ?What's more, there are > > > > > > numbers that are NOT comparable by the operator you're thinking > > > > > > about!. > > > > > > > > So to implement your specifications, that function would have to be > > > > > > implemented for example as: > > > > > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > > > > (defmethod lessp ((x complex) (y complex)) > > > > > > ? (or (< (real-part x) (real-part y)) > > > > > > ? ? ? (and (= (real-part x) (real-part y)) > > > > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > > > > > (defun maximum (a b) > > > > > > ? (if (lessp a b) b a)) > > > > > > > > And then the client of that function could very well add methods: > > > > > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > > > > > and call: > > > > > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > > > > > and who are you to forbid it!? > > > > > > > > -- > > > > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? > > > > > > ?http://www.informatimago.com/-Hidequotedtext - > > > > > > > > - Show quoted text - > > > > > > > in C I can have a function maximum(int a, int b) that will always > > > > > work. Never blow up, and never give an invalid answer. If someone > > > > > tries to call it incorrectly it is a compile error. > > > > > In a dynamic typed language maximum(a, b) can be called with > > > > > incorrect > > > > > datatypes. Even if I make it so it can handle many types as you did > > > > > above, it could still be inadvertantly called with a file handle for > > > > > a > > > > > parameter or some other type not provided for. So does Eckel and > > > > > others, when they are writing their dynamically typed code advocate > > > > > just letting the function blow up or give a bogus answer, or do they > > > > > check for valid types passed? If they are checking for valid types it > > > > > would seem that any benefits gained by not specifying type are lost > > > > > by > > > > > checking for type. And if they don't check for type it would seem > > > > > that > > > > > their code's error handling is poor. > > > > > > that is a lie. > > > > > > Compilation only makes sure that values provided at compilation-time > > > > are of the right datatype. > > > > > > What happens though is that in the real world, pretty much all > > > > computation depends on user provided values at runtime. ?See where are > > > > we heading? > > > > > > this works at compilation time without warnings: > > > > int m=numbermax( 2, 6 ); > > > > > > this too: > > > > int a, b, m; > > > > scanf( "%d", &a ); > > > > scanf( "%d", &b ); > > > > m=numbermax( a, b ); > > > > > > no compiler issues, but will not work just as much as in python if > > > > user provides "foo" and "bar" for a and b... fail. > > > > > > What you do if you're feeling insecure and paranoid? ?Just what > > > > dynamically typed languages do: ?add runtime checks. ?Unit tests are > > > > great to assert those. > > > > > > Fact is: ?almost all user data from the external words comes into > > > > programs as strings. ?No typesystem or compiler handles this fact all > > > > that graceful... > > > > > I disagree with your conclusion. ?Sure, the data was textual when it > > > was initially read by the program, but that should only be relevant to > > > the input processing code. ?The data is likely converted to some > > > internal representation immediately after it is read and validated, > > > and in a sanely-designed program, it maintains this representation > > > throughout its life time. ?If the structure of some data needs to > > > change during development, the compiler of a statically-typed language > > > will automatically tell you about any client code that was not updated > > > to account for the change. ?Dynamically typed languages do not provide > > > this assurance. > > > > This is a red herring. ?You don't have to invoke run-time input to > > demonstrate bugs in a statically typed language that are not caught by > > the compiler. ?For example: > > > > [ron at mighty:~]$ cat foo.c > > #include > > > > int maximum(int a, int b) { > > ? return (a > b ? a : b); > > > > } > > > > int foo(int x) { return 9223372036854775807+x; } > > > > int main () { > > ? printf("%d\n", maximum(foo(1), 1)); > > ? return 0;} > > > > [ron at mighty:~]$ gcc -Wall foo.c > > [ron at mighty:~]$ ./a.out > > 1 > > > > Even simple arithmetic is Turing-complete, so catching all type-related > > errors at compile time would entail solving the halting problem. > > > > rg > > In short, static typing doesn't solve all conceivable problems. More specifically, the claim made above: > in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. is false. And it is not necessary to invoke the vagaries of run-time input to demonstrate that it is false. > We are all aware that there is no perfect software development process > or tool set. I'm interested in minimizing the number of problems I > run into during development, and the number of bugs that are in the > finished product. My opinion is that static typed languages are > better at this for large projects, for the reasons I stated in my > previous post. More power to you. What are you doing here on cll then? rg From tar at sevak.isi.edu Wed Sep 29 18:19:08 2010 From: tar at sevak.isi.edu (Thomas A. Russ) Date: 29 Sep 2010 15:19:08 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: > > More power to you. What are you doing here on cll then? This thread is massively cross-posted. -- Thomas A. Russ, USC/Information Sciences Institute From nad at acm.org Wed Sep 29 18:24:01 2010 From: nad at acm.org (Ned Deily) Date: Wed, 29 Sep 2010 15:24:01 -0700 Subject: Certificate validation with HTTPSConnection References: <4CA3A46B.4080006@animats.com> Message-ID: In article <4CA3A46B.4080006 at animats.com>, John Nagle wrote: > We've been through this. Too many times. > > http://bugs.python.org/issue1114345 > (2005: Broken in Python 2.2, eventually fixed) > > http://www.justinsamuel.com/2008/12/25/the-importance-of-validating-ssl-certif > icates/ > (2008: Why this matters) > > http://www.mail-archive.com/python-list at python.org/msg281736.html > (2010: Broken in new Python 2.6 SSL module.) > > http://bugs.python.org/issue1589 > (2010: Developer "Bill Jansen" in denial, others disagree. > Currently being debated. See bug tracker.) > > The really stupid thing about the current SSL module is that it > accepts a file of root certificates as a parameter, but ignores it. > So it creates the illusion of security without providing it. > As someone pointed out, the current SSL module "lets you talk > encrypted to your attacker". I'll just note in passing that Issue1589 is being discussed again. Feel free to contribute. -- Ned Deily, nad at acm.org From python at mrabarnett.plus.com Wed Sep 29 18:34:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Sep 2010 23:34:22 +0100 Subject: utf-8 and ctypes In-Reply-To: References: Message-ID: <4CA3BEEE.2030005@mrabarnett.plus.com> On 29/09/2010 19:33, Brendan Miller wrote: > 2010/9/29 Lawrence D'Oliveiro: >> In message, Brendan >> Miller wrote: >> >>> It seems that characters not in the ascii subset of UTF-8 are >>> discarded by c_char_p during the conversion ... >> >> Not a chance. >> >>> ... or at least they don't print out when I go to print the string. >> >> So it seems there?s a problem on the printing side. What happens when you >> construct a UTF-8-encoded string directly in Python and try printing it the >> same way? > > Doing this seems to confirm something is broken in ctypes w.r.t. UTF-8... > > if I enter: > str = "???????" > > Then: > print str > ??????? > > However, when I create a string buffer, pass it into my c++ code, and > write the same UTF-8 string into it, python seems to discard pretty > much all the text. The same code works for pure ascii strings. > > Python code: > _std_string_size = _lib_mbxclient.std_string_size > _std_string_size.restype = c_long > _std_string_size.argtypes = [c_void_p] > > _std_string_copy = _lib_mbxclient.std_string_copy > _std_string_copy.restype = None > _std_string_copy.argtypes = [c_void_p, POINTER(c_char)] > > # This function works for ascii, but breaks on strings with UTF-8! > def std_string_to_string(str_ptr): > buf = create_string_buffer(_std_string_size(str_ptr)) > _std_string_copy(str_ptr, buf) > return buf.raw > > C++ code: > > extern "C" > long std_string_size(string* str) > { > return str->size(); > } > > extern "C" > void std_string_copy(string* str, char* buf) > { > std::copy(str->begin(), str->end(), buf); > } It might have something to do with the character encoding of your source files. Also, try printing out the character codes of the string and the size of the string's character in the C++ code. From solipsis at pitrou.net Wed Sep 29 18:51:05 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 30 Sep 2010 00:51:05 +0200 Subject: PyCObject & malloc creating memory leak References: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> Message-ID: <20100930005105.767d0f58@pitrou.net> On Wed, 29 Sep 2010 06:50:05 -0700 (PDT) Tom Conneely wrote: > > My original plan was to have the data processing and data acquisition > functions running in separate processes, with a multiprocessing.Queue > for passing the raw data packets. The raw data is read in as a char*, > with a non constant length, hence I have allocated memory using > PyMem_Malloc and I am returning from the acquisition function a > PyCObject containing a pointer to this char* buffer, along with a > destructor. That sounds overkill, and I also wonder how you plan to pass that object in a multiprocessing Queue (which relies on objects being pickleable). Why don't you simply create a PyString object instead? > So if I call these functions in a loop, e.g. The following will > generate ~10GB of data > > x = MyClass() > for i in xrange(0, 10 * 2**20): > c = x.malloc_buffer() > x.retrieve_buffer(c) > > All my memory disapears, until python crashes with a MemoryError. By > placing a print in the destructor function I know it's being called, > however it's not actually freeing the memory. So in short, what am I > doing wrong? Python returns memory to the OS by calling free(). Not all OSes actually relinquish memory when free() is called; some will simply set it aside for the next allocation. Another possible (and related) issue is memory fragmentation. Again, it depends on the memory allocator. Regards Antoine. From solipsis at pitrou.net Wed Sep 29 18:51:55 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 30 Sep 2010 00:51:55 +0200 Subject: Certificate validation with HTTPSConnection References: <4CA3A46B.4080006@animats.com> Message-ID: <20100930005155.0727523d@pitrou.net> On Wed, 29 Sep 2010 13:41:15 -0700 John Nagle wrote: > > The really stupid thing about the current SSL module is that it > accepts a file of root certificates as a parameter, but ignores it. That's not true. You have to pass CERT_OPTIONAL or CERT_REQUIRED as a parameter (CERT_NONE is though). Regards Antoine. From kst-u at mib.org Wed Sep 29 19:07:19 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 16:07:19 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: > In article > <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, > Squeamizh wrote: >> On Sep 29, 3:02?pm, RG wrote: [...] >> > This is a red herring. ?You don't have to invoke run-time input to >> > demonstrate bugs in a statically typed language that are not caught by >> > the compiler. ?For example: >> > >> > [ron at mighty:~]$ cat foo.c >> > #include >> > >> > int maximum(int a, int b) { >> > ? return (a > b ? a : b); >> > >> > } >> > >> > int foo(int x) { return 9223372036854775807+x; } >> > >> > int main () { >> > ? printf("%d\n", maximum(foo(1), 1)); >> > ? return 0;} >> > >> > [ron at mighty:~]$ gcc -Wall foo.c >> > [ron at mighty:~]$ ./a.out >> > 1 >> > >> > Even simple arithmetic is Turing-complete, so catching all type-related >> > errors at compile time would entail solving the halting problem. >> > >> > rg >> >> In short, static typing doesn't solve all conceivable problems. > > More specifically, the claim made above: > >> in C I can have a function maximum(int a, int b) that will always >> work. Never blow up, and never give an invalid answer. > > is false. And it is not necessary to invoke the vagaries of run-time > input to demonstrate that it is false. But the above maximum() function does exactly that. The program's behavior happens to be undefined or implementation-defined for reasons unrelated to the maximum() function. Depending on the range of type int on the given system, either the behavior of the addition in foo() is undefined (because it overflows), or the implicit conversion of the result to int either yields an implementation-defined result or (in C99) raises an implementation-defined signal; the latter can lead to undefined behavior. Since 9223372036854775807 is 2**63-1, what *typically* happens is that the addition yields the value 0, but the C language doesn't require that particular result. You then call maximum with arguments 0 and 1, and it quite correctly returns 1. >> We are all aware that there is no perfect software development process >> or tool set. I'm interested in minimizing the number of problems I >> run into during development, and the number of bugs that are in the >> finished product. My opinion is that static typed languages are >> better at this for large projects, for the reasons I stated in my >> previous post. > > More power to you. What are you doing here on cll then? This thread is cross-posted to several newsgroups, including comp.lang.c. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From pjb at informatimago.com Wed Sep 29 19:17:39 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 01:17:39 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <87k4m4nnqk.fsf@kuiper.lan.informatimago.com> Squeamizh writes: > In short, static typing doesn't solve all conceivable problems. > > We are all aware that there is no perfect software development process > or tool set. I'm interested in minimizing the number of problems I > run into during development, and the number of bugs that are in the > finished product. My opinion is that static typed languages are > better at this for large projects, for the reasons I stated in my > previous post. Our experience is that a garbage collector and native bignums are much more important to minimize the number of problems we run into during development and the number of bugs that are in the finished products. -- __Pascal Bourguignon__ http://www.informatimago.com/ From rNOSPAMon at flownet.com Wed Sep 29 19:47:38 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 16:47:38 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > RG writes: > > In article > > <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, > > Squeamizh wrote: > >> On Sep 29, 3:02?pm, RG wrote: > [...] > >> > This is a red herring. ?You don't have to invoke run-time input to > >> > demonstrate bugs in a statically typed language that are not caught by > >> > the compiler. ?For example: > >> > > >> > [ron at mighty:~]$ cat foo.c > >> > #include > >> > > >> > int maximum(int a, int b) { > >> > ? return (a > b ? a : b); > >> > > >> > } > >> > > >> > int foo(int x) { return 9223372036854775807+x; } > >> > > >> > int main () { > >> > ? printf("%d\n", maximum(foo(1), 1)); > >> > ? return 0;} > >> > > >> > [ron at mighty:~]$ gcc -Wall foo.c > >> > [ron at mighty:~]$ ./a.out > >> > 1 > >> > > >> > Even simple arithmetic is Turing-complete, so catching all type-related > >> > errors at compile time would entail solving the halting problem. > >> > > >> > rg > >> > >> In short, static typing doesn't solve all conceivable problems. > > > > More specifically, the claim made above: > > > >> in C I can have a function maximum(int a, int b) that will always > >> work. Never blow up, and never give an invalid answer. > > > > is false. And it is not necessary to invoke the vagaries of run-time > > input to demonstrate that it is false. > > But the above maximum() function does exactly that. The program's > behavior happens to be undefined or implementation-defined for reasons > unrelated to the maximum() function. > > Depending on the range of type int on the given system, either the > behavior of the addition in foo() is undefined (because it overflows), > or the implicit conversion of the result to int either yields an > implementation-defined result or (in C99) raises an > implementation-defined signal; the latter can lead to undefined > behavior. > > Since 9223372036854775807 is 2**63-1, what *typically* happens is that > the addition yields the value 0, but the C language doesn't require that > particular result. You then call maximum with arguments 0 and 1, and > it quite correctly returns 1. This all hinges on what you consider to be "a function maximum(int a, int b) that ... always work[s] ... [and] never give[s] an invalid answer." But if you don't consider an incorrect answer (according to the rules of arithmetic) to be an invalid answer then the claim becomes vacuous. You could simply ignore the arguments and return 0, and that would meet the criteria. If you try to refine this claim so that it is both correct and non-vacuous you will find that static typing does not do nearly as much for you as most of its adherents think it does. > >> We are all aware that there is no perfect software development process > >> or tool set. I'm interested in minimizing the number of problems I > >> run into during development, and the number of bugs that are in the > >> finished product. My opinion is that static typed languages are > >> better at this for large projects, for the reasons I stated in my > >> previous post. > > > > More power to you. What are you doing here on cll then? > > This thread is cross-posted to several newsgroups, including > comp.lang.c. Ah, so it is. My bad. rg From kst-u at mib.org Wed Sep 29 20:26:38 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 17:26:38 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: > In article , > Keith Thompson wrote: > >> RG writes: >> > In article >> > <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, >> > Squeamizh wrote: >> >> On Sep 29, 3:02?pm, RG wrote: >> [...] >> >> > This is a red herring. ?You don't have to invoke run-time input to >> >> > demonstrate bugs in a statically typed language that are not caught by >> >> > the compiler. ?For example: >> >> > >> >> > [ron at mighty:~]$ cat foo.c >> >> > #include >> >> > >> >> > int maximum(int a, int b) { >> >> > ? return (a > b ? a : b); >> >> > >> >> > } >> >> > >> >> > int foo(int x) { return 9223372036854775807+x; } >> >> > >> >> > int main () { >> >> > ? printf("%d\n", maximum(foo(1), 1)); >> >> > ? return 0;} >> >> > >> >> > [ron at mighty:~]$ gcc -Wall foo.c >> >> > [ron at mighty:~]$ ./a.out >> >> > 1 >> >> > >> >> > Even simple arithmetic is Turing-complete, so catching all type-related >> >> > errors at compile time would entail solving the halting problem. >> >> > >> >> > rg >> >> >> >> In short, static typing doesn't solve all conceivable problems. >> > >> > More specifically, the claim made above: >> > >> >> in C I can have a function maximum(int a, int b) that will always >> >> work. Never blow up, and never give an invalid answer. >> > >> > is false. And it is not necessary to invoke the vagaries of run-time >> > input to demonstrate that it is false. >> >> But the above maximum() function does exactly that. The program's >> behavior happens to be undefined or implementation-defined for reasons >> unrelated to the maximum() function. >> >> Depending on the range of type int on the given system, either the >> behavior of the addition in foo() is undefined (because it overflows), >> or the implicit conversion of the result to int either yields an >> implementation-defined result or (in C99) raises an >> implementation-defined signal; the latter can lead to undefined >> behavior. >> >> Since 9223372036854775807 is 2**63-1, what *typically* happens is that >> the addition yields the value 0, but the C language doesn't require that >> particular result. You then call maximum with arguments 0 and 1, and >> it quite correctly returns 1. > > This all hinges on what you consider to be "a function maximum(int a, > int b) that ... always work[s] ... [and] never give[s] an invalid > answer." int maximum(int a, int b) { return a > b ? a : b; } > But if you don't consider an incorrect answer (according to > the rules of arithmetic) to be an invalid answer then the claim becomes > vacuous. You could simply ignore the arguments and return 0, and that > would meet the criteria. I don't believe it's possible in any language to write a maximum() function that returns a correct result *when given incorrect argument values*. The program (assuming a typical implementation) calls maximum() with arguments 0 and 1. maximum() returns 1. It works. The problem is elsewhere in the program. (And on a hypothetical system with INT_MAX >= 9223372036854775808, the program's entire behavior is well defined and mathematically correct. C requires INT_MAX >= 32767; it can be as large as the implementation chooses. In practice, the largest value I've ever seen for INT_MAX is 9223372036854775807.) > If you try to refine this claim so that it is both correct and > non-vacuous you will find that static typing does not do nearly as much > for you as most of its adherents think it does. Speaking only for myself, I've never claimed that static typing solves all conceivable problems. My point is only about this specific example of a maximum() function. [...] -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From anand.shashwat at gmail.com Wed Sep 29 20:42:56 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 30 Sep 2010 06:12:56 +0530 Subject: list problem... In-Reply-To: References: <4ca32e49$0$28654$c3e8da3@news.astraweb.com> <0e563359-c2fd-4fbc-808b-02cb2e483ad5@l20g2000yqm.googlegroups.com> Message-ID: On Thu, Sep 30, 2010 at 3:20 AM, Rog wrote: > On Wed, 29 Sep 2010 05:52:32 -0700, bruno.desthuilliers at gmail.com wrote: > > > On 29 sep, 14:17, Steven D'Aprano > > > wrote: > >> On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > >> > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > >> > >> >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > >> >>> Hi all, > >> >>> Have been grappling with a list problem for hours... a = [2, 3, 4, > >> >>> 5,.....] > >> >>> b = [4, 8, 2, 6,.....] > >> >>> Basicly I am trying to place a[0], b[0] in a seperate list IF a[2] > >> >>> and b[2] is present. > >> >>> I have tried sets, zip etc with no success. I am tackling Euler > >> >>> projects with Python 3.1, with minimal knowledge, and having to > >> >>> tackle the language as I progress. Enjoyable frustration :) > >> > >> >> I'm not clear on what your actual problem is, could you restate it? > >> > >> >> It sounds like you want to copy the ith element out of a and b into > >> >> some other list- call it c- when the (i+2)th element meets some > >> >> condition. What's the condition? > >> > >> >> Geremy Condra > >> > >> > The condition is that the i-th element is inverted, but not equal. eg > >> > 4,2 - 2,4 , 34,5 - 5,34 etc. > >> > Hope that is clearer. > >> > >> Clear as mud. > >> > >> Perhaps you should given an example. Given input > >> > >> a = [2, 3, 4, 5, 6, 7] > >> b = [4, 8, 2, 6, 10, 42] > >> > >> what output are you expecting, > > > > AFAICT, the OP expects [2, 4] in this case, but it's not clear what he'd > > expect for let's say: > > > > a = [2, 3, 21, 4, 5, 6, 7] > > b = [4, 8, 22, 2, 6, 10, 42] > > > > (the 'reversed' pair is at i+3, not i+2) > > > > or > > > > a = [0, 2, 3, 4, 5, 6, 7] > > b = [3, 4, 8, 2, 6, 10, 42] > > > > (the first pair is at pos 1, not 0) > > > > or > > > > a = [2, 3, 4, 8, 6, 7] > > b = [4, 8, 2, 3, 10, 42] > > > > (there's a second 'non-reversed/reversed' match at positions resp. 1 & 3) > > > It is true that I would have needed any 'non-reversed/reversed' pairs, > these would have been the amicable pairs I was looking for. > The method to recognise them eluded me. Eyes are not good enough :) > I have now joined Python-List and will follow the correct route. > I have used a method suggested that has made the problem redundant, > though it will bug me from now on. > > g = [] > > def divsum(n): > return sum(i for i in range(1, n) if not n % i) > You can optimize divsum. Remember that factors exist in pairs except when numbers are squares. Like say 12 have factors = 1, 12, 2, 6, 3, 4 so you can run the loop till sqrt(n) for n since floor(sqrt(n)) = 3 where n = 12 now factors are , (1, n/1), (2, n/2), (3, n/2). for a square number say n = 9, the factors are (1, 3, 12) If you run the loop till sqrt(n) for n since floor(sqrt(n)) = 3 where n = 9 we get the factors as (1, 9), (3, 3) One of the factor will be redundant, so you need to take care of that. > > for x in range(10000, 2, -1): > c = divsum(x) > v = divsum(c) > Can be done as, c, v = divsum(x), divsum(divsum(x)) > if v == x and v != c: > g.append(divsum(x)) > No need for else part, what is the use ? > else: > continue > > print(sum(g)) > You could pack this up as, >>> sum(i for i in range(10000, 0, -2) if divsum(divsum(i)) == i and divsum(i) != i) 31626 > -- > Rog > http://www.rog.pynguins.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve-REMOVE-THIS at cybersource.com.au Wed Sep 29 20:54:36 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 30 Sep 2010 00:54:36 GMT Subject: About __class__ of an int literal References: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> <8739ss4tk6.fsf@xemacs.org> Message-ID: <4ca3dfcc$0$28672$c3e8da3@news.astraweb.com> On Wed, 29 Sep 2010 14:46:18 -0400, Terry Reedy wrote: >> In that sense the user >> should be calling iter(foo) instead of foo.__iter__(), next(foo) >> instead of foo.__next__(), and foo+bar instead of foo.__add__(bar). > > Yes. Guido added iter() and next() to the list of built-in functions, > even though they seem reduncant.. I believe it is his intention that the > use of special names outside of class statements should be fairly rare. Fairly rare but not non-existent. For example, there's nothing wrong with using a callback function of (say) instance.__sub__ instead of lambda b, a=instance: a - b. Not only is the direct call to the method slightly faster, but more importantly it's easier to read and more clear to intent. Admittedly beginners may find instance.__sub__ to be a tad mysterious, but then beginners are likely to find the lambda form with its two arguments and default value mysterious too. > If I remember right, in the old, pre-2.2 system that separated built-in > types and user-written classes, the builtins did not have accessible > special method attributes. Yes, that's correct. But we're talking about Python *now*, not back in the mists of time before new-style classes. Would you argue that users shouldn't use decorators, iterators or closures because Python 2.1 didn't have them? I don't think so. > They are only for customizing user classes. Say "were" rather than "are" and I will agree with you. Say "primarily for" rather than "only" and I will also agree with you. > So one could not have generically written foo.__add__(bar). > Special-method attribute were added to builtins so that they could be > inherited (or replaced) by user-written subclasses, not so that one > could replace normal syntax. Of course one shouldn't prefer seq.__len__() over len(seq). But that's a readability issue, and not because Python implementations are free to change __len__ to something else. If I gave the opposite impression, that was not my intention and I'm sorry for the failure to be more clear. >> Direct >> calls to special-name methods, such as __len__, often indicate that the >> programmer hasn't grasped how those methods are intended to be used in >> Python. > > Right. That fact that *Python* interpreters implement syntax with > special methods is an implementation detail of the *language*. The > importance is that it allow *writers* of new classes to rather easily > imitate built-in classes so that their classes seamlessly plug into the > syntax. If I've understood this paragraph correctly, you're trying to say that since *other languages* that aren't Python are free to implement syntax features using some other mechanism, *Python* developers shouldn't use special methods because they are implementation details. If we're prohibited from using anything which is an implementation detail of "the *language*" (your emphasis), then we can't use *anything*. Yes, special methods are an implementation detail of Python, but only in the same sense that it is an implementation detail of Python that we write this: def f(a, b): x = a + b return math.sqrt(x) rather than this: function f(a, b: integer):float: var x: integer; begin x := a + b; f := sqrt(x) end; -- Steven From squeamz at hotmail.com Wed Sep 29 20:58:23 2010 From: squeamz at hotmail.com (Squeamizh) Date: Wed, 29 Sep 2010 17:58:23 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <1d035a69-dc5f-4321-9ca4-2828fb64a3c8@z34g2000pro.googlegroups.com> On Sep 29, 3:14?pm, RG wrote: > In article > <07f75df3-778d-4e3d-8aa0-fbd4bd108... at k22g2000prb.googlegroups.com>, > > > > > > ?Squeamizh wrote: > > On Sep 29, 3:02?pm, RG wrote: > > > In article > > > <996bd4e6-37ff-4a55-8db5-6e7574fbd... at k22g2000prb.googlegroups.com>, > > > > ?Squeamizh wrote: > > > > On Sep 27, 10:46?am, namekuseijin wrote: > > > > > On 27 set, 05:46, TheFlyingDutchman wrote: > > > > > > > On Sep 27, 12:58?am, p... at informatimago.com (Pascal J. Bourguignon) > > > > > > wrote: > > > > > > > RG writes: > > > > > > > > In article > > > > > > > > <7df0eb06-9be1-4c9c-8057-e9fdb7f0b... at q16g2000prf.googlegroups.com > > > > > > > > >, > > > > > > > > ?TheFlyingDutchman wrote: > > > > > > > > >> On Sep 22, 10:26?pm, "Scott L. Burson" wrote: > > > > > > > >> > This might have been mentioned here before, but I just came > > > > > > > >> > across > > > > > > > >> > it: a > > > > > > > >> > 2003 essay by Bruce Eckel on how reliable systems can get > > > > > > > >> > built in > > > > > > > >> > dynamically-typed languages. ?It echoes things we've all said > > > > > > > >> > here, but > > > > > > > >> > I think it's interesting because it describes a conversion > > > > > > > >> > experience: > > > > > > > >> > Eckel started out in the strong-typing camp and was won over. > > > > > > > > >> > ? ?https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk > > > > > > > > >> > -- Scott > > > > > > > > >> If you are writing a function to determine the maximum of two > > > > > > > >> numbers > > > > > > > >> passed as arguents in a dynamic typed language, what is the > > > > > > > >> normal > > > > > > > >> procedure used by Eckel and others to handle someone passing in > > > > > > > >> invalid values - such as a file handle for one varible and an > > > > > > > >> array > > > > > > > >> for the other? > > > > > > > > > The normal procedure is to hit such a person over the head with a > > > > > > > > stick > > > > > > > > and shout "FOO". > > > > > > > > Moreover, the functions returning the maximum may be able to work > > > > > > > on > > > > > > > non-numbers, as long as they're comparable. ?What's more, there are > > > > > > > numbers that are NOT comparable by the operator you're thinking > > > > > > > about!. > > > > > > > > So to implement your specifications, that function would have to be > > > > > > > implemented for example as: > > > > > > > > (defmethod lessp ((x real) (y real)) (< x y)) > > > > > > > (defmethod lessp ((x complex) (y complex)) > > > > > > > ? (or (< (real-part x) (real-part y)) > > > > > > > ? ? ? (and (= (real-part x) (real-part y)) > > > > > > > ? ? ? ? ? ?(< (imag-part x) (imag-part y))))) > > > > > > > > (defun maximum (a b) > > > > > > > ? (if (lessp a b) b a)) > > > > > > > > And then the client of that function could very well add methods: > > > > > > > > (defmethod lessp ((x symbol) (y t)) (lessp (string x) y)) > > > > > > > (defmethod lessp ((x t) (y symbol)) (lessp x (string y))) > > > > > > > (defmethod lessp ((x string) (y string)) (string< x y)) > > > > > > > > and call: > > > > > > > > (maximum 'hello "WORLD") --> "WORLD" > > > > > > > > and who are you to forbid it!? > > > > > > > > -- > > > > > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? > > > > > > > ?http://www.informatimago.com/-Hidequotedtext- > > > > > > > > - Show quoted text - > > > > > > > in C I can have a function maximum(int a, int b) that will always > > > > > > work. Never blow up, and never give an invalid answer. If someone > > > > > > tries to call it incorrectly it is a compile error. > > > > > > In a dynamic typed language maximum(a, b) can be called with > > > > > > incorrect > > > > > > datatypes. Even if I make it so it can handle many types as you did > > > > > > above, it could still be inadvertantly called with a file handle for > > > > > > a > > > > > > parameter or some other type not provided for. So does Eckel and > > > > > > others, when they are writing their dynamically typed code advocate > > > > > > just letting the function blow up or give a bogus answer, or do they > > > > > > check for valid types passed? If they are checking for valid types it > > > > > > would seem that any benefits gained by not specifying type are lost > > > > > > by > > > > > > checking for type. And if they don't check for type it would seem > > > > > > that > > > > > > their code's error handling is poor. > > > > > > that is a lie. > > > > > > Compilation only makes sure that values provided at compilation-time > > > > > are of the right datatype. > > > > > > What happens though is that in the real world, pretty much all > > > > > computation depends on user provided values at runtime. ?See where are > > > > > we heading? > > > > > > this works at compilation time without warnings: > > > > > int m=numbermax( 2, 6 ); > > > > > > this too: > > > > > int a, b, m; > > > > > scanf( "%d", &a ); > > > > > scanf( "%d", &b ); > > > > > m=numbermax( a, b ); > > > > > > no compiler issues, but will not work just as much as in python if > > > > > user provides "foo" and "bar" for a and b... fail. > > > > > > What you do if you're feeling insecure and paranoid? ?Just what > > > > > dynamically typed languages do: ?add runtime checks. ?Unit tests are > > > > > great to assert those. > > > > > > Fact is: ?almost all user data from the external words comes into > > > > > programs as strings. ?No typesystem or compiler handles this fact all > > > > > that graceful... > > > > > I disagree with your conclusion. ?Sure, the data was textual when it > > > > was initially read by the program, but that should only be relevant to > > > > the input processing code. ?The data is likely converted to some > > > > internal representation immediately after it is read and validated, > > > > and in a sanely-designed program, it maintains this representation > > > > throughout its life time. ?If the structure of some data needs to > > > > change during development, the compiler of a statically-typed language > > > > will automatically tell you about any client code that was not updated > > > > to account for the change. ?Dynamically typed languages do not provide > > > > this assurance. > > > > This is a red herring. ?You don't have to invoke run-time input to > > > demonstrate bugs in a statically typed language that are not caught by > > > the compiler. ?For example: > > > > [ron at mighty:~]$ cat foo.c > > > #include > > > > int maximum(int a, int b) { > > > ? return (a > b ? a : b); > > > > } > > > > int foo(int x) { return 9223372036854775807+x; } > > > > int main () { > > > ? printf("%d\n", maximum(foo(1), 1)); > > > ? return 0;} > > > > [ron at mighty:~]$ gcc -Wall foo.c > > > [ron at mighty:~]$ ./a.out > > > 1 > > > > Even simple arithmetic is Turing-complete, so catching all type-related > > > errors at compile time would entail solving the halting problem. > > > > rg > > > In short, static typing doesn't solve all conceivable problems. > > More specifically, the claim made above: > > > in C I can have a function maximum(int a, int b) that will always > > work. Never blow up, and never give an invalid answer. > > is false. ?And it is not necessary to invoke the vagaries of run-time > input to demonstrate that it is false. OK. You finished your post with a reference to the halting problem, which does not help to bolster any practical argument. That is why I summarized your post in the manner I did. I agree that static typed languages do not prevent these types of overflow errors. From rNOSPAMon at flownet.com Wed Sep 29 21:01:02 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 18:01:02 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > RG writes: > > In article , > > Keith Thompson wrote: > > > >> RG writes: > >> > In article > >> > <07f75df3-778d-4e3d-8aa0-fbd4bd108a57 at k22g2000prb.googlegroups.com>, > >> > Squeamizh wrote: > >> >> On Sep 29, 3:02?pm, RG wrote: > >> [...] > >> >> > This is a red herring. ?You don't have to invoke run-time input to > >> >> > demonstrate bugs in a statically typed language that are not caught > >> >> > by > >> >> > the compiler. ?For example: > >> >> > > >> >> > [ron at mighty:~]$ cat foo.c > >> >> > #include > >> >> > > >> >> > int maximum(int a, int b) { > >> >> > ? return (a > b ? a : b); > >> >> > > >> >> > } > >> >> > > >> >> > int foo(int x) { return 9223372036854775807+x; } > >> >> > > >> >> > int main () { > >> >> > ? printf("%d\n", maximum(foo(1), 1)); > >> >> > ? return 0;} > >> >> > > >> >> > [ron at mighty:~]$ gcc -Wall foo.c > >> >> > [ron at mighty:~]$ ./a.out > >> >> > 1 > >> >> > > >> >> > Even simple arithmetic is Turing-complete, so catching all > >> >> > type-related > >> >> > errors at compile time would entail solving the halting problem. > >> >> > > >> >> > rg > >> >> > >> >> In short, static typing doesn't solve all conceivable problems. > >> > > >> > More specifically, the claim made above: > >> > > >> >> in C I can have a function maximum(int a, int b) that will always > >> >> work. Never blow up, and never give an invalid answer. > >> > > >> > is false. And it is not necessary to invoke the vagaries of run-time > >> > input to demonstrate that it is false. > >> > >> But the above maximum() function does exactly that. The program's > >> behavior happens to be undefined or implementation-defined for reasons > >> unrelated to the maximum() function. > >> > >> Depending on the range of type int on the given system, either the > >> behavior of the addition in foo() is undefined (because it overflows), > >> or the implicit conversion of the result to int either yields an > >> implementation-defined result or (in C99) raises an > >> implementation-defined signal; the latter can lead to undefined > >> behavior. > >> > >> Since 9223372036854775807 is 2**63-1, what *typically* happens is that > >> the addition yields the value 0, but the C language doesn't require that > >> particular result. You then call maximum with arguments 0 and 1, and > >> it quite correctly returns 1. > > > > This all hinges on what you consider to be "a function maximum(int a, > > int b) that ... always work[s] ... [and] never give[s] an invalid > > answer." > > int maximum(int a, int b) { return a > b ? a : b; } > > > But if you don't consider an incorrect answer (according to > > the rules of arithmetic) to be an invalid answer then the claim becomes > > vacuous. You could simply ignore the arguments and return 0, and that > > would meet the criteria. > > I don't believe it's possible in any language to write a maximum() > function that returns a correct result *when given incorrect argument > values*. > > The program (assuming a typical implementation) calls maximum() with > arguments 0 and 1. maximum() returns 1. It works. The problem > is elsewhere in the program. That the problem is "elsewhere in the program" ought to be small comfort. But very well, try this instead: [ron at mighty:~]$ cat foo.c #include int maximum(int a, int b) { return a > b ? a : b; } int main() { long x = 8589934592; printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); return 0; } [ron at mighty:~]$ gcc -Wall foo.c [ron at mighty:~]$ ./a.out Max of 8589934592 and 1 is 1 From zooko at zooko.com Wed Sep 29 21:04:57 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Wed, 29 Sep 2010 19:04:57 -0600 Subject: ANNOUNCING Tahoe, the Least-Authority File System, v1.8.0 Message-ID: Hello, people of python-list. This storage project uses Python for almost everything, except we use C/C++ for the CPU-intensive computations (cryptography and erasure coding) and we use JavaScript for some user interface bits. We're even looking at the possibility of replacing the C/C++ crypto code with pure-Python code, relying on JIT compilers such as PyPy to make it efficient enough. :-) http://twitter.com/#!/fijall/status/25314330015 Regards, Zooko ANNOUNCING Tahoe, the Least-Authority File System, v1.8.0 The Tahoe-LAFS team is pleased to announce the immediate availability of version 1.8.0 of Tahoe-LAFS, an extremely reliable distributed storage system. Get it here: http://tahoe-lafs.org/source/tahoe/trunk/docs/quickstart.html Tahoe-LAFS is the first distributed storage system to offer "provider-independent security" ? meaning that not even the operators of your storage servers can read or alter your data without your consent. Here is the one-page explanation of its unique security and fault-tolerance properties: http://tahoe-lafs.org/source/tahoe/trunk/docs/about.html The previous stable release of Tahoe-LAFS was v1.7.1, which was released July 18, 2010 [1]. v1.8.0 offers greatly improved performance and fault-tolerance of downloads and improved Windows support. See the NEWS file [2] for details. WHAT IS IT GOOD FOR? With Tahoe-LAFS, you distribute your filesystem across multiple servers, and even if some of the servers fail or are taken over by an attacker, the entire filesystem continues to work correctly, and continues to preserve your privacy and security. You can easily share specific files and directories with other people. In addition to the core storage system itself, volunteers have built other projects on top of Tahoe-LAFS and have integrated Tahoe-LAFS with existing systems, including Windows, JavaScript, iPhone, Android, Hadoop, Flume, Django, Puppet, bzr, mercurial, perforce, duplicity, TiddlyWiki, and more. See the Related Projects page on the wiki [3]. We believe that strong cryptography, Free and Open Source Software, erasure coding, and principled engineering practices make Tahoe-LAFS safer than RAID, removable drive, tape, on-line backup or cloud storage. This software is developed under test-driven development, and there are no known bugs or security flaws which would compromise confidentiality or data integrity under recommended use. (For all important issues that we are currently aware of please see the known_issues.txt file [4].) COMPATIBILITY This release is compatible with the version 1 series of Tahoe-LAFS. Clients from this release can write files and directories in the format used by clients of all versions back to v1.0 (which was released March 25, 2008). Clients from this release can read files and directories produced by clients of all versions since v1.0. Servers from this release can serve clients of all versions back to v1.0 and clients from this release can use servers of all versions back to v1.0. This is the eleventh release in the version 1 series. This series of Tahoe-LAFS will be actively supported and maintained for the forseeable future, and future versions of Tahoe-LAFS will retain the ability to read and write files compatible with this series. LICENCE You may use this package under the GNU General Public License, version 2 or, at your option, any later version. See the file "COPYING.GPL" [5] for the terms of the GNU General Public License, version 2. You may use this package under the Transitive Grace Period Public Licence, version 1 or, at your option, any later version. (The Transitive Grace Period Public Licence has requirements similar to the GPL except that it allows you to delay for up to twelve months after you redistribute a derived work before releasing the source code of your derived work.) See the file "COPYING.TGPPL.html" [6] for the terms of the Transitive Grace Period Public Licence, version 1. (You may choose to use this package under the terms of either licence, at your option.) INSTALLATION Tahoe-LAFS works on Linux, Mac OS X, Windows, Cygwin, Solaris, *BSD, and probably most other systems. Start with "docs/quickstart.html" [7]. HACKING AND COMMUNITY Please join us on the mailing list [8]. Patches are gratefully accepted -- the RoadMap page [9] shows the next improvements that we plan to make and CREDITS [10] lists the names of people who've contributed to the project. The Dev page [11] contains resources for hackers. SPONSORSHIP Tahoe-LAFS was originally developed by Allmydata, Inc., a provider of commercial backup services. After discontinuing funding of Tahoe-LAFS R&D in early 2009, they continued to provide servers, bandwidth, small personal gifts as tokens of appreciation, and bug reports. Google, Inc. sponsored Tahoe-LAFS development as part of the Google Summer of Code 2010. They awarded four sponsorships to students from around the world to hack on Tahoe-LAFS that summer. Thank you to Allmydata and Google for their generous and public-spirited support. HACK TAHOE-LAFS! If you can find a security flaw in Tahoe-LAFS which is serious enough that feel compelled to warn our users and issue a fix, then we will award you with a customized t-shirts with your exploit printed on it and add you to the "Hack Tahoe-LAFS Hall Of Fame" [12]. ACKNOWLEDGEMENTS This is the fifth release of Tahoe-LAFS to be created solely as a labor of love by volunteers. Thank you very much to the team of "hackers in the public interest" who make Tahoe-LAFS possible. David-Sarah Hopwood and Zooko Wilcox-O'Hearn on behalf of the Tahoe-LAFS team September 23, 2010 Rainhill, Merseyside, UK and Boulder, Colorado, USA [1] http://tahoe-lafs.org/trac/tahoe/browser/relnotes.txt?rev=4579 [2] http://tahoe-lafs.org/trac/tahoe/browser/NEWS?rev=4732 [3] http://tahoe-lafs.org/trac/tahoe/wiki/RelatedProjects [4] http://tahoe-lafs.org/trac/tahoe/browser/docs/known_issues.txt [5] http://tahoe-lafs.org/trac/tahoe/browser/COPYING.GPL [6] http://tahoe-lafs.org/source/tahoe/trunk/COPYING.TGPPL.html [7] http://tahoe-lafs.org/source/tahoe/trunk/docs/quickstart.html [8] http://tahoe-lafs.org/cgi-bin/mailman/listinfo/tahoe-dev [9] http://tahoe-lafs.org/trac/tahoe/roadmap [10] http://tahoe-lafs.org/trac/tahoe/browser/CREDITS?rev=4591 [11] http://tahoe-lafs.org/trac/tahoe/wiki/Dev [12] http://tahoe-lafs.org/hacktahoelafs/ From no.email at nospam.invalid Wed Sep 29 21:06:26 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 29 Sep 2010 18:06:26 -0700 Subject: Supplementing the std lib (Was: partial sums problem) References: Message-ID: <7x1v8cm44t.fsf@ruckus.brouhaha.com> kj writes: > But in the immediate term, cusum is not part of the standard library. > > Where would you put it if you wanted to reuse it? Do you create > a module just for it? Or do you create a general stdlib2 module > with all those workhorse functions that have not made it to the > standard library? Or something else entirely? In a typical application you'd have a bunch of such utility functions in a single "utils.py" module or something like that. Java programs use separate files for each class, so you get zillions of files, but Python users tend to put more code in each file. As for the stdlib, the natural places for such a function would be either itertools or functools, and the function should probably be called "scan", inspired by this: http://en.wikibooks.org/wiki/Haskell/List_processing#Scans Python's version would be like "scanl" with an optional arg to make it like "scanl1". From usenet-nospam at seebs.net Wed Sep 29 21:17:53 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 01:17:53 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: On 2010-09-30, RG wrote: > That the problem is "elsewhere in the program" ought to be small > comfort. It is, perhaps, but it's also an important technical point: You CAN write correct code for such a thing. > int maximum(int a, int b) { return a > b ? a : b; } > int main() { > long x = 8589934592; > printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); You invoked implementation-defined behavior here by calling maximum() with a value which was outside the range. The defined behavior is that the arguments are converted to the given type, namely int. The conversion is implementation-defined and could include yielding an implementation-defined signal which aborts execution. Again, the maximum() function is 100% correct -- your call of it is incorrect. You didn't pass it the right sort of data. That's your problem. (And no, the lack of a diagnostic doesn't necessarily prove anything; see the gcc documentation for details of what it does when converting an out of range value into a signed type, it may well have done exactly what it is defined to do.) -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-REMOVE-THIS at cybersource.com.au Wed Sep 29 21:21:38 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 30 Sep 2010 01:21:38 GMT Subject: About __class__ of an int literal References: <4ca32c1b$0$28654$c3e8da3@news.astraweb.com> <8739ss4tk6.fsf@xemacs.org> Message-ID: <4ca3e622$0$28672$c3e8da3@news.astraweb.com> On Wed, 29 Sep 2010 14:34:33 +0200, Hrvoje Niksic wrote: > Steven D'Aprano writes: >> (This may change in the future. Given type(), and isinstance(), I'm not >> sure what value __class__ adds.) > > None whatsoever. __class__ used to be necessary to tell the appart > instances of different old-style classes: > >>>> class X: pass # old-style > ... >>>> X().__class__ > >>>> type(X()) > > > Now that classes produce real types, they are equivalent. I've been thinking about this, and I think that there may be a use-case for changing __class__ manually. I'm not entirely sure if this is a good idea or not, I'd need to spend some time experimenting, but imagine a class that wraps another object and uses delegation instead of inheritance. If you also set __class__ (on the class itself, naturally, not the instance) appropriately, then type(instance) and instance.__class__ will be different. type() will return the "real" type of the delegation class, while instance.__class__ returns the class that it is trying to be. And of course, presumably metaclasses can do anything they like with __class__, for good or ill. I'm not sure if and when this would be useful, but it's a hint that perhaps the distinction is not entirely meaningless. -- Steven From kst-u at mib.org Wed Sep 29 21:28:15 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 18:28:15 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: [...] > That the problem is "elsewhere in the program" ought to be small > comfort. I don't claim that it's comforting, merely that it's true. > But very well, try this instead: > > [ron at mighty:~]$ cat foo.c > #include > > int maximum(int a, int b) { return a > b ? a : b; } > > int main() { > long x = 8589934592; > printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > return 0; > } > [ron at mighty:~]$ gcc -Wall foo.c > [ron at mighty:~]$ ./a.out > Max of 8589934592 and 1 is 1 That exhibits a very similar problem. 8589934592 is 2**33. Given the output you got, I presume your system has 32-bit int and 64-bit long. The call maximum(x, 1) implicitly converts the long value 8589934592 to int. The result is implementation-defined, but typically 0. So maximum() is called with arguments of 0 and 1, as you could see by adding a printf call to maximum(). Even here, maximum() did exactly what was asked of it. I'll grant you that having a conversion from a larger type to a smaller type quietly discard high-order bits is unfriendly. But it matches the behavior of most CPUs. Here's another example: #include int maximum(int a, int b) { return a > b ? a : b; } int main(void) { double x = 1.8; printf("Max of %f and 1 is %d\n", x, maximum(x, 1)); return 0; } Output: Max of 1.800000 and 1 is 1 -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From ian-news at hotmail.com Wed Sep 29 22:00:59 2010 From: ian-news at hotmail.com (Ian Collins) Date: Thu, 30 Sep 2010 15:00:59 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <8gi9arFg2jU5@mid.individual.net> On 09/30/10 02:17 PM, Seebs wrote: > On 2010-09-30, RG wrote: >> That the problem is "elsewhere in the program" ought to be small >> comfort. > > It is, perhaps, but it's also an important technical point: You CAN write > correct code for such a thing. > >> int maximum(int a, int b) { return a> b ? a : b; } > >> int main() { >> long x = 8589934592; >> printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > > You invoked implementation-defined behavior here by calling maximum() with > a value which was outside the range. The defined behavior is that the > arguments are converted to the given type, namely int. The conversion > is implementation-defined and could include yielding an implementation-defined > signal which aborts execution. > > Again, the maximum() function is 100% correct -- your call of it is incorrect. > You didn't pass it the right sort of data. That's your problem. > > (And no, the lack of a diagnostic doesn't necessarily prove anything; see > the gcc documentation for details of what it does when converting an out > of range value into a signed type, it may well have done exactly what it > is defined to do.) Note that the mistake can be diagnosed: lint /tmp/u.c -m64 -errchk=all (7) warning: passing 64-bit integer arg, expecting 32-bit integer: maximum(arg 1) -- Ian Collins From ian.g.kelly at gmail.com Wed Sep 29 22:17:46 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 29 Sep 2010 20:17:46 -0600 Subject: Supplementing the std lib (Was: partial sums problem) In-Reply-To: <7x1v8cm44t.fsf@ruckus.brouhaha.com> References: <7x1v8cm44t.fsf@ruckus.brouhaha.com> Message-ID: On Wed, Sep 29, 2010 at 7:06 PM, Paul Rubin wrote: > As for the stdlib, the natural places for such a function would be > either itertools or functools, and the function should probably be called > "scan", inspired by this: > > http://en.wikibooks.org/wiki/Haskell/List_processing#Scans > > Python's version would be like "scanl" with an optional arg to make it > like "scanl1". > Something like this? NoInitialValue = object() def scan(function, iterable, initial=NoInitialValue): iterator = iter(iterable) if initial is NoInitialValue: try: accumulator = iterator.next() except StopIteration: return else: accumulator = initial yield accumulator for arg in iterator: accumulator = function(accumulator, arg) yield accumulator Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruce at futurewavedesigns.com Wed Sep 29 22:32:13 2010 From: bruce at futurewavedesigns.com (Bruce Whealton) Date: Wed, 29 Sep 2010 22:32:13 -0400 Subject: Clarification of notation Message-ID: <4CA3F6AD.3020603@futurewavedesigns.com> Hello all, I recently started learning python. I am a bit thrown by a certain notation that I see. I was watching a training course on lynda.com and this notation was not presented. For lists, when would you use what appears to be nested lists, like: [[], [], []] a list of lists? Would you, and could you combine a dictionary with a list in this fashion? Next, from the documentation I see and this is just an example (this kind of notation is seen elsewhere in the documentation: str.count(sub[, start[, end]]) This particular example is from the string methods. Is this a nesting of two lists inside a a third list? I know that it would suggest that some of the arguments are optional, so perhaps if there are 2 items the first is the sub, and the second is start? Or did I read that backwards? Thanks, Bruce From pbloom at crystald.com Wed Sep 29 22:38:29 2010 From: pbloom at crystald.com (Philip Bloom) Date: Wed, 29 Sep 2010 19:38:29 -0700 Subject: Strange os.stat behavior Message-ID: I'm on python 2.6.1: Ran into some os.stat behavior that knocked me for a loop. I was using os.stat to retrieve file st_ctime and st_mtime from a remote server through a unc path, and doing this I encountered that os.stat was returning me st_ctime and st_mtime values that were months off, reporting values that not only were months in the past, but also relatively wrong (Reporting a greater difference between Modified and Created than there should be). Below, run through localtime and formatted a little for easier reading.). C++ stat, Win32API, and Windows own directory report all match with the same seen time (and are correct). Has anyone seen something like this before? It's quite scary to me that os.stat is returning a different value that it's getting from somewhere and doesn't match with either the Windows API or the C++ stat library. I read over the release notes for 2.6.x and didn't see any mention of os.stat relevant bugs or fixes. I'm curious what it could possibly be doing differently than the others (I thought it used the windows api under the hood for Windows nt derived systems). Ex: \\mpkarc01\Build_stats\tras\MayaExportKernel_p.config\mabahazy~RWCWRK_70 01470.stats\9-27-2010_log.txt 1279755701.87 1285810489.65 Created: time.struct_time(tm_year=2010, tm_mon=7, tm_mday=21, tm_hour=16, tm_min=41, tm_sec=41, tm_wday=2, tm_yday=202, tm_isdst=1) Modified: time.struct_time(tm_year=2010, tm_mon=7, tm_mday=25, tm_hour=0, tm_min=59, tm_sec=45, tm_wday=6, tm_yday=206, tm_isdst=1), raw: 1280044785 Accessed: time.struct_time(tm_year=2010, tm_mon=9, tm_mday=29, tm_hour=17, tm_min=25, tm_sec=31, tm_wday=2, tm_yday=272, tm_isdst=1) Raw Time.Time(): time.struct_time(tm_year=2010, tm_mon=9, tm_mday=29, tm_hour=18, tm_min=34, tm_sec=49, tm_wday=2, tm_yday=272, tm_isdst=1), raw: 1285810489.65 Win32API Ctime: 09/27/10 20:18:11 Win32API MTime: 09/28/10 01:18:37 Win32API ATime: 09/29/10 00:24:46 Relevant code segment: import win32api import win32con import win32file import time import os ... statinfo = os.stat(os.path.join(root, name)) print os.path.join(root, name) + " " + str(statinfo.st_ctime) + " " + str(time.time()) print "Modified: ", time.localtime(int(statinfo.st_mtime)),int(statinfo.st_mtime) print "Created: ", time.localtime(int(statinfo.st_ctime)) print "Accessed: ", time.localtime(int(statinfo.st_atime)) print time.localtime(),time.time() fh = win32file.CreateFile(os.path.join(root, name), win32file.GENERIC_READ | win32file.GENERIC_WRITE, 0, None, win32file.OPEN_EXISTING,0, 0) sts, creationTime, accessTime, writeTime = win32file.GetFileTime(fh) print creationTime, accessTime, writeTime win32file.CloseHandle(fh) Platform of executing code: Windows XP, 64 bit. ______________________________________________________________________ This email has been scanned by the MessageLabs ______________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From namekuseijin at gmail.com Wed Sep 29 23:28:35 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Wed, 29 Sep 2010 20:28:35 -0700 (PDT) Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> Message-ID: On 29 set, 17:46, Xah Lee wrote: > On Sep 29, 11:02?am, namekuseijin wrote: > > > On 28 set, 19:38, Xah Lee wrote: > > > > ? ?list comprehension? is a very bad jargon; thus harmful to > > > functional programing or programing in general. Being a bad jargon, it > > > encourage mis-communication, mis-understanding. > > > I disagree: ?it is a quite intuitive term to describe what the > > expression does. > > what's your basis in saying that ?list comprehension? is intuitive? it generates a list from syntax comprehended in list-like syntax! > any statics, survery, research, references you have to cite? how about common sense? > to put this in context, are you saying that lambda, is also intuitive? No. > ?let? is intuitive? yes, it's focking everyday term used in the same way: let this be this and that be that and thus... > ?for? is intuitive? yes, it's focking everyday term used in the same way: for this and this and this do that... > ?when? is intuitive? when this, then that? common sense, Xah! > For example, let us know, in your view, how good are terms: currying, > lisp1 lisp2, tail recursion, closure, subroutine, command, object. These terms have a technical meaning coming from historic events in the areas they are used. It's like that in all areas, you may also bash medicine jargon if you want. Though subroutine, command and object are pretty intuitive by common sense alone. > perhaps expound on the comparative merits and meaning on the terms > module vs package vs add-on vs library. I would like to see your view > on this with at least few paragraphs of analysis on each. They are all the same shit. These were developed by managers and buzzwriters... ;) > Also, ?being intuitive? is not the only aspect to consider whether a > term is good or bad. For example, emacs's uses the term ?frame?. It's > quite intuitive, because frame is a common english word, everyone > understands. You know, door frame, window frame, picture frame, are > all analogous to emacs's ?frame? on a computer. However, by some turn > of history, in computer software we call such as ?window? now, and by > happance the term ?window? also has a technical meaning in emacs, what > we call ?split window? or ?pane? today. So, in emacs, the term ?frame? > and ?window? is confusing, because emacs's ?frame? is what we call > ?window?, while emacs's ?window? is what me might call a pane of a > split window. So here, is a example, that even when a term is > intuitive, it can still be bad. emacs is all FUBAR in more than one way. being intuitive is not exactly what it is known for... ;) well, I shouldn't be bashing it, my vim is not that funky among commoners anymore anyway... :p > I wrote about 14 essays on various jargons in past decade. You can > find them on my site. yeah, I've read them once in a while... From nagle at animats.com Wed Sep 29 23:41:00 2010 From: nagle at animats.com (John Nagle) Date: Wed, 29 Sep 2010 20:41:00 -0700 Subject: Certificate validation with HTTPSConnection In-Reply-To: References: <4CA3A46B.4080006@animats.com> Message-ID: <4ca406ef$0$1633$742ec2ed@news.sonic.net> On 9/29/2010 3:51 PM, Antoine Pitrou wrote: > On Wed, 29 Sep 2010 13:41:15 -0700 > John Nagle wrote: >> >> The really stupid thing about the current SSL module is that it >> accepts a file of root certificates as a parameter, but ignores it. > > That's not true. You have to pass CERT_OPTIONAL or CERT_REQUIRED as a > parameter (CERT_NONE is though). If you pass CERT_REQUIRED and a root certificate authority file, there has to be some certificate, but the signature chain is not validated against the CA file, so the cert doesn't certify anything. Phony web sites look valid to Python's SSL library. John Nagle From usenet-nospam at seebs.net Wed Sep 29 23:48:06 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 03:48:06 GMT Subject: (and scheme lisp) x Python and modern langs [was Re: gossip, Guy Steel, Lojban, Racket] References: <0bc242cf-13b0-435f-85ca-74e2853b4e12@u5g2000prn.googlegroups.com> <68062f9f-7a73-4e53-8db0-e6cc1bb1f312@l38g2000pro.googlegroups.com> <5a35cbad-4fed-48ab-9c4e-1c7249292568@a19g2000yql.googlegroups.com> <82b1b06c-6a3a-4ebf-a84e-57788fd958f0@m35g2000prn.googlegroups.com> <55240f01-7caa-46ee-bc51-d82158ac1e5d@i3g2000yql.googlegroups.com> <8a001b43-edef-492f-923f-a0d04a0a69be@p24g2000pra.googlegroups.com> <1760b92a-e6bc-483f-be57-2d2ac549310e@l32g2000prn.googlegroups.com> <5dfabe5f-06d1-4e2a-bfa2-e0eb583b4e2a@f25g2000yqc.googlegroups.com> <3317b3f8-50b1-41b7-a1b1-eca758f05ac6@n19g2000prf.googlegroups.com> Message-ID: On 2010-09-30, namekuseijin wrote: > it generates a list from syntax comprehended in list-like syntax! Okay, help me out here. (Killed the crossposting.) I am not understanding how the word applies. I'm fine with it, but I don't see any relation at all between the thing called a list comprehension and the word "comprehension" as I normally understand it. Who or what is doing the comprehending? Is this a sense of "comprehension" other than "to understand"? It seems like it's perhaps related to "comprehensive". However, I've never seen "comprehension" used to refer to anything other than understanding prior to encountering "list comprehensions". [... hmm. maybe time to go searching...] Looking around, it seems this is from mathematical jargon, to wit, "set comprehensions". Since I hadn't run into that jargon, I had no clue what the etymology was, and "comprehended" is not a verb I would ever have used with this. However, looking around, it appears that this usage also occurs in the same jargon; once you've got one of them the other follows. I guess the key, though, is that this is purely jargon, and jargon from another field -- not all programmers have done all mathematics. I even took a ton of bonus math in college, but happened not to have done anything where this terminology was used. So the usage is, pardon the pun, incomprehensible to me to begin with, and saying it's called a comprehension because it's comprehended doesn't help -- that's two forms of the same unfamiliar jargon. Of course, the jargon is pretty reasonable as such goes, in no small part because of the plain English sense of "comprehensive" in the sense of covering something completely, so it's not awful. But from where I'm coming, it would be every bit as obvious to call it a "list exhaustion", by analagous derivation from "exhaustive". -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 Sep 30 00:27:38 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 04:27:38 GMT Subject: Clarification of notation References: Message-ID: On 2010-09-30, Bruce Whealton wrote: > Next, from the documentation I see and this is just an example (this > kind of notation is seen elsewhere in the documentation: > str.count(sub[, start[, end]]) > This particular example is from the string methods. > Is this a nesting of two lists inside a a third list? No, it's not -- it's a different use of [] to indicate that things are optional, a convention which dates back to long before Python existed. >I know that it > would suggest that some of the arguments are optional, so perhaps if > there are 2 items the first is the sub, and the second is start? Or did > I read that backwards? That is exactly correct. The key is the implication that you can omit end, or both start and end. (But you can't omit start and provide end.) -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 Thu Sep 30 00:29:58 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 29 Sep 2010 21:29:58 -0700 (PDT) Subject: Clarification of notation References: Message-ID: <80347433-9acd-4958-8786-cd5acd8a7b79@u4g2000prn.googlegroups.com> Bruce Whealton wrote: > For lists, when would > you use what appears to be nested lists, like: > [[], [], []] > a list of lists? Well, you'd use it when you'd want a list of lists ;) There's nothing magical about a list of lists, it's just a list with objects inside like any other, in this case they just happen to be lists. Possibly the canonical example is for a simple multidimensional array: >>> array5x5 = [[0]*5 for i in range(5)] >>> array5x5[2][3] = 7 >>> array5x5[4][1] = 2 >>> array5x5 [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 7, 0], [0, 0, 0, 0, 0], [0, 2, 0, 0, 0]] > Would you, and could you combine a dictionary with a list in this fashion? Lists can contain dictionaries that contain dictionaries containing lists :) So yes, they can easily be combined. Here's a list with dictionaries: elements = [ {'tag': 'strong', 'style': 'bold'}, {'tag': 'header', 'style': 'bolder', 'color': 'red}, ] And a dictionary of lists: classes_2010 = { 'economics': ['John Crowley', 'Jack Savage', 'Jane Austen'], 'voodoo economics': ['Ronald Reagan', 'Ferris Beuller'], } (Note that the formatting style is a personal taste and not essential). Generally, you tend to use a list when you want to work on items in sequence, and a dictionary when you want to work on an item on demand. > Next, from the documentation I see and this is just an example (this > kind of notation is seen elsewhere in the documentation: > > str.count(sub[, start[, end]]) > This particular example is from the string methods. > Is this a nesting of two lists inside a a third list? ?I know that it > would suggest that some of the arguments are optional, so perhaps if > there are 2 items the first is the sub, and the second is start? ?Or did In documentation (as opposed to code), [] represents optional arguments, and have nothing at all to do with Python lists. The above example is showing that the method can be called in the following ways: 'foobarbazbam'.count('ba') 'foobarbazbam'.count('ba', 6) 'foobarbazbam'.count('ba', 6, 9) Hope this helps. From clp2 at rebertia.com Thu Sep 30 00:50:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 29 Sep 2010 21:50:42 -0700 Subject: Clarification of notation In-Reply-To: <4CA3F6AD.3020603@futurewavedesigns.com> References: <4CA3F6AD.3020603@futurewavedesigns.com> Message-ID: On Wed, Sep 29, 2010 at 7:32 PM, Bruce Whealton wrote: > Hello all, > ? ? ? ? I recently started learning python. ?I am a bit thrown by a certain > notation that I see. ?I was watching a training course on lynda.com and this > notation was not presented. ?For lists, when would you use what appears to > be nested lists, like: > [[], [], []] > a list of lists? Lists are for working with a group of data. Sometimes each datum happens to itself be a list; thus, one naturally ends up with a list-of-lists. Say I have, for each school in my school district, a list of its students' test scores. I want to compute each school's average score. So I put all the lists of scores into a nested list. I then iterate over the nested list, taking the average of each inner list of scores. (Do the analogous thing at higher and higher levels of aggregation (e.g. county, state, country) and you naturally get progressively more nested lists.) > Would you, and could you combine a dictionary with a list in this fashion? Yes, of course: {'a' : [1,2,3]} [{'a' : 1}, {'b' : 2}] Just note that lists can't be dictionary keys due to their mutability. {[1,2,3] : "one two three"} # ERROR > Next, from the documentation I see and this is just an example (this kind of > notation is seen elsewhere in the documentation: > > str.count(sub[, start[, end]]) > This particular example is from the string methods. > I know that it would > suggest that some of the arguments are optional, so perhaps if there are 2 > items the first is the sub, and the second is start? ?Or did I read that > backwards? No, you read it exactly correctly. The []s here indicate levels of optional-ness and have nothing to do with the list datatype. Basically, if you want to pass an optional argument, you have to have also specified any less-nested arguments (unless you use keyword rather than positional arguments). str.count(a) # sub = a str.count(a, b) # sub = a, start = b str.count(a, b, c) # sub = a, start = b, end = c Usually, it's straightforward left-to-right as you specify more arguments (doing otherwise requires kludges or black magic). However, there are rare exceptions, the most common one being range()/xrange(): range(...) range([start,] stop[, step]) -> list of integers Thus: range(a) # stop = a (*not* start = a, as would be normal) range(a, b) # start = a, stop = b range(a, b, c) # start = a, stop = b, step = c Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Thu Sep 30 00:55:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Sep 2010 00:55:59 -0400 Subject: Clarification of notation In-Reply-To: <4CA3F6AD.3020603@futurewavedesigns.com> References: <4CA3F6AD.3020603@futurewavedesigns.com> Message-ID: On 9/29/2010 10:32 PM, Bruce Whealton wrote: > Would you, and could you combine a dictionary with a list in this fashion? A python list is a mutable sequence of Python objects. Extremely mixed example. >>> mixed = [1, 1.0, '1', [1], (1,), {1:1}, set((1,)), list, list.append] >>> mixed.append(mixed) # make the list recursive >>> mixed # list to string can handle that! [1, 1.0, '1', [1], (1,), {1: 1}, {1}, , , [...]] > Next, from the documentation I see and this is just an example (this > kind of notation is seen elsewhere in the documentation: > > str.count(sub[, start[, end]]) square bracket are standard for indicating optional items in extended Backus-Naur context-free grammar notations. https://secure.wikimedia.org/wikipedia/en/wiki/Backus%E2%80%93Naur_Form In Python3 docs, they have been removed as redundant when an explicit default value is given: compile(source, filename, mode, flags=0, dont_inherit=False) -- Terry Jan Reedy From rNOSPAMon at flownet.com Thu Sep 30 00:57:46 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 21:57:46 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > RG writes: > [...] > > That the problem is "elsewhere in the program" ought to be small > > comfort. > > I don't claim that it's comforting, merely that it's true. > > > But very well, try this instead: > > > > [ron at mighty:~]$ cat foo.c > > #include > > > > int maximum(int a, int b) { return a > b ? a : b; } > > > > int main() { > > long x = 8589934592; > > printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > > return 0; > > } > > [ron at mighty:~]$ gcc -Wall foo.c > > [ron at mighty:~]$ ./a.out > > Max of 8589934592 and 1 is 1 > > That exhibits a very similar problem. > > 8589934592 is 2**33. > > Given the output you got, I presume your system has 32-bit int and > 64-bit long. The call maximum(x, 1) implicitly converts the long > value 8589934592 to int. The result is implementation-defined, > but typically 0. So maximum() is called with arguments of 0 and 1, > as you could see by adding a printf call to maximum(). > > Even here, maximum() did exactly what was asked of it. Of course. Computers always do only exactly what you ask of them. On this view there is, by definition, no such thing as a bug, only specifications that don't correspond to one's intentions. Unfortunately, correspondence to intentions is the thing that actually matters when writing code. > I'll grant you that having a conversion from a larger type to a smaller > type quietly discard high-order bits is unfriendly. "Unfriendly" is not the adjective that I would choose to describe this behavior. There is a whole hierarchy of this sort of "unfriendly" behavior, some of which can be caught at compile time using a corresponding hierarchy of ever more sophisticated tools. But sooner or later if you are using Turing-complete operations you will encounter the halting problem, at which point your compile-time tools will fail. (c.f. the Collatz problem) I'm not saying one should not use compile-time tools, only that one should not rely on them. "Compiling without errors" is not -- and cannot ever be -- be a synonym for "bug-free." rg From frank at chagford.com Thu Sep 30 01:01:14 2010 From: frank at chagford.com (Frank Millman) Date: Thu, 30 Sep 2010 07:01:14 +0200 Subject: scheduler or infinite loop References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> <344a231a-1ed7-4be6-bd14-aa6adf965b03@n19g2000prf.googlegroups.com> Message-ID: harryos wrote >> >> Here is a technique that allows the loop to run in the background, in its >> own thread, leaving the main program to do other processing - >> >> import threading >> >> class DataGetter(threading.Thread): >> > thanks Frank A pleasure. I left out a line that will usually be desirable. At the end of the program, you should have - data_getter.stop() + data_getter.join() This forces the main program to wait until the thread has terminated before continuing. Frank From usenet-nospam at seebs.net Thu Sep 30 01:05:45 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 05:05:45 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: On 2010-09-30, RG wrote: > Of course. Computers always do only exactly what you ask of them. On > this view there is, by definition, no such thing as a bug, only > specifications that don't correspond to one's intentions. f00f. That said... I think you're missing Keith's point. > Unfortunately, correspondence to intentions is the thing that actually > matters when writing code. Yes. Nonetheless, the maximum() function does exactly what it is intended to do *with the inputs it receives*. The failure is outside the function; it did the right thing with the data actually passed to it, the problem was a user misunderstanding as to what data were being passed to it. So there's a bug -- there's code which does not do what it was intended to do. However, that bug is in the caller, not in the maximum() function. This is an important distinction -- it means we can write a function which performs that function reliably. Now we just need to figure out how to call it with valid data... :) -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-news at hotmail.com Thu Sep 30 01:08:13 2010 From: ian-news at hotmail.com (Ian Collins) Date: Thu, 30 Sep 2010 18:08:13 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <8gik9tFq44U4@mid.individual.net> On 09/30/10 05:57 PM, RG wrote: > > I'm not saying one should not use compile-time tools, only that one > should not rely on them. "Compiling without errors" is not -- and > cannot ever be -- be a synonym for "bug-free." We is why wee all have run time tools called unit tests, don't we? -- Ian Collins From nagle at animats.com Thu Sep 30 01:24:53 2010 From: nagle at animats.com (John Nagle) Date: Wed, 29 Sep 2010 22:24:53 -0700 Subject: scheduler or infinite loop In-Reply-To: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> References: <89f4fe0b-1697-4303-a699-21b60c9d4c2a@s24g2000pri.googlegroups.com> Message-ID: <4ca41f48$0$1648$742ec2ed@news.sonic.net> On 9/29/2010 4:59 AM, harryos wrote: > hi > I am trying to write a program to read data from a site url. > The program must read the data from site every 5 minutes. > > def get_data_from_site(pageurlstr): > h=urllib.urlopen(pageurlstr) > data=h.read() > process_data(data) A key point here is that you're not handling network failures. The first time you have a brief network outage, your program will fail. Consider something like this: def get_data_from_site(pageurlstr): try : h=urllib.urlopen(pageurlstr) data=h.read() except EnvironmentError as message : print("Error reading %s from network at %s: %s" % (pageurlstr, time.asctime(), str(message)) return(False) process_data(data) return(True) lastpoll = 0 # time of last successful read POLLINTERVAL = 300.0 RETRYINTERVAL = 30.0 while True: status = get_data_from_site('http://somesite.com/') if not status : # if fail time.sleep(RETRYINTERVAL) # try again soon print("Retrying...") continue now = time.time() # success # Wait for the next poll period. Compensate for how # long the read took. waittime = max(POLLINTERVAL - (now - lastpoll), 1.0) lastpoll = now time.sleep(waittime) From no.email at nospam.invalid Thu Sep 30 01:34:08 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 29 Sep 2010 22:34:08 -0700 Subject: Supplementing the std lib (Was: partial sums problem) References: <7x1v8cm44t.fsf@ruckus.brouhaha.com> Message-ID: <7xbp7fhk1b.fsf@ruckus.brouhaha.com> Dennis Lee Bieber writes: >> Python's version would be like "scanl" with an optional arg to make it >> like "scanl1". > Vs APL's "expand" operator? I'm not familiar with that but maybe it's similar. From lie.1296 at gmail.com Thu Sep 30 01:38:28 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 30 Sep 2010 15:38:28 +1000 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <4ca421a1$1@dnews.tpgi.com.au> On 09/30/10 11:17, Seebs wrote: > On 2010-09-30, RG wrote: >> That the problem is "elsewhere in the program" ought to be small >> comfort. > > It is, perhaps, but it's also an important technical point: You CAN write > correct code for such a thing. > >> int maximum(int a, int b) { return a > b ? a : b; } > >> int main() { >> long x = 8589934592; >> printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > > You invoked implementation-defined behavior here by calling maximum() with > a value which was outside the range. The defined behavior is that the > arguments are converted to the given type, namely int. The conversion > is implementation-defined and could include yielding an implementation-defined > signal which aborts execution. > > Again, the maximum() function is 100% correct -- your call of it is incorrect. > You didn't pass it the right sort of data. That's your problem. That argument can be made for dynamic language as well. If you write in dynamic language (e.g. python): def maximum(a, b): return a if a > b else b The dynamic language's version of maximum() function is 100% correct -- if you passed an uncomparable object, instead of a number, your call of it is incorrect; you just didn't pass the right sort of data. And that's your problem as a caller. In fact, since Python's integer is infinite precision (only bounded by available memory); in practice, Python's version of maximum() has less chance of producing erroneous result. The /most/ correct version of maximum() function is probably one written in Haskell as: maximum :: Integer -> Integer -> Integer maximum a b = if a > b then a else b Integer in Haskell has infinite precision (like python's int, only bounded by memory), but Haskell also have static type checking, so you can't pass just any arbitrary objects. But even then, it's still not 100% correct. If you pass a really large values that exhaust the memory, the maximum() could still produce unwanted result. Second problem is that Haskell has Int, the bounded integer, and if you have a calculation in Int that overflowed in some previous calculation, then you can still get an incorrect result. In practice, the type-agnostic language with *mandatory* infinite precision arithmetic wins in terms of correctness. Any language which only has optional infinite precision arithmetic can always produce erroneous result. Anyone can dream of 100% correct program; but anyone who believes they can write a 100% correct program is just a dreamer. In reality, we don't usually need 100% correct program; we just need a program that runs correctly enough most of the times that the 0.0000001% chance of producing erroneous result becomes irrelevant. In summary, in this particular case with maximum() function, static checking does not help in producing the most correct code; if you need to ensure the highest correctness, you must use a language with *mandatory* infinite precision integers. From zzbbaadd at aol.com Thu Sep 30 01:51:28 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Wed, 29 Sep 2010 22:51:28 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: > > More specifically, the claim made above: > > > in C I can have a function maximum(int a, int b) that will always > > work. Never blow up, and never give an invalid answer. > > is false. ?And it is not necessary to invoke the vagaries of run-time > input to demonstrate that it is false. > I don't think you demonstrated it is false. Any values larger than an int get truncated before they ever get to maximum. The problem does not lie with the maximum function. It correctly returns the maximum of whatever two integers it is provided. Calling it with values that are larger than an int, that get converted to an int _before_ maximum is called, is an issue outside of maximum. From metolone+gmane at gmail.com Thu Sep 30 01:55:06 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Wed, 29 Sep 2010 22:55:06 -0700 Subject: utf-8 and ctypes References: Message-ID: "Brendan Miller" wrote in message news:AANLkTi=2f3L++398St-16MPEs8wzfbLbu+Qa8zTPAbsd at mail.gmail.com... > 2010/9/29 Lawrence D'Oliveiro : >> In message , >> Brendan >> Miller wrote: >> >>> It seems that characters not in the ascii subset of UTF-8 are >>> discarded by c_char_p during the conversion ... >> >> Not a chance. >> >>> ... or at least they don't print out when I go to print the string. >> >> So it seems there?s a problem on the printing side. What happens when >> you >> construct a UTF-8-encoded string directly in Python and try printing it >> the >> same way? > > Doing this seems to confirm something is broken in ctypes w.r.t. UTF-8... > > if I enter: > str = "???????" > > Then: > print str > ??????? > > However, when I create a string buffer, pass it into my c++ code, and > write the same UTF-8 string into it, python seems to discard pretty > much all the text. The same code works for pure ascii strings. > > Python code: > _std_string_size = _lib_mbxclient.std_string_size > _std_string_size.restype = c_long > _std_string_size.argtypes = [c_void_p] > > _std_string_copy = _lib_mbxclient.std_string_copy > _std_string_copy.restype = None > _std_string_copy.argtypes = [c_void_p, POINTER(c_char)] > > # This function works for ascii, but breaks on strings with UTF-8! > def std_string_to_string(str_ptr): > buf = create_string_buffer(_std_string_size(str_ptr)) > _std_string_copy(str_ptr, buf) > return buf.raw > > C++ code: > > extern "C" > long std_string_size(string* str) > { > return str->size(); > } > > extern "C" > void std_string_copy(string* str, char* buf) > { > std::copy(str->begin(), str->end(), buf); > } I didn't see what OS you are using, but I fleshed out your example code and have a working example for Windows. Below is the code for the DLL and script: --------- x.cpp [cl /LD /EHsc /W4 x.cpp] ---------------------------------------------------- #include #include using namespace std; extern "C" __declspec(dllexport) long std_string_size(string* str) { return str->size(); } extern "C" __declspec(dllexport) void std_string_copy(string* str, char* buf) { std::copy(str->begin(), str->end(), buf); } extern "C" __declspec(dllexport) void* make(const char* s) { return new string(s); } extern "C" __declspec(dllexport) void destroy(void* s) { delete (string*)s; } ---- x.py --------------------------------------------------------- # coding: utf8 from ctypes import * _lib_mbxclient = CDLL('x') _std_string_size = _lib_mbxclient.std_string_size _std_string_size.restype = c_long _std_string_size.argtypes = [c_void_p] _std_string_copy = _lib_mbxclient.std_string_copy _std_string_copy.restype = None _std_string_copy.argtypes = [c_void_p, c_char_p] make = _lib_mbxclient.make make.restype = c_void_p make.argtypes = [c_char_p] destroy = _lib_mbxclient.destroy destroy.restype = None destroy.argtypes = [c_void_p] # This function works for ascii, but breaks on strings with UTF-8! def std_string_to_string(str_ptr): buf = create_string_buffer(_std_string_size(str_ptr)) _std_string_copy(str_ptr, buf) return buf.raw s = make(u'??????'.encode('utf8')) print std_string_to_string(s).decode('utf8') ------------------------------------------------------ And output (in Pythonwin...US Windows console doesn't support Chinese): ?????? I used c_char_p instead of POINTER(c_char) and added functions to create and destroy a std::string for Python's use, but it is otherwise the same as your code. Hope this helps you work it out, -Mark From kst-u at mib.org Thu Sep 30 02:00:56 2010 From: kst-u at mib.org (Keith Thompson) Date: Wed, 29 Sep 2010 23:00:56 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: RG writes: > In article , > Keith Thompson wrote: [...] >> Even here, maximum() did exactly what was asked of it. > > Of course. Computers always do only exactly what you ask of them. On > this view there is, by definition, no such thing as a bug, only > specifications that don't correspond to one's intentions. > Unfortunately, correspondence to intentions is the thing that actually > matters when writing code. Of course there's such a thing as a bug. This version of maximum: int maximum(int a, int b) { return a > b ? a : a; } has a bug. This version: int maximum(int a, int b) { return a > b ? a : b; } I would argue, does not. The fact that it might be included in a buggy program does not mean that it is itself buggy. [...] > I'm not saying one should not use compile-time tools, only that one > should not rely on them. "Compiling without errors" is not -- and > cannot ever be -- be a synonym for "bug-free." Agreed. (Though C does make it notoriously easy to sneak buggy code past the compiler.) -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From zzbbaadd at aol.com Thu Sep 30 02:09:05 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Wed, 29 Sep 2010 23:09:05 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> Message-ID: > > That argument can be made for dynamic language as well. If you write in > dynamic language (e.g. python): > > def maximum(a, b): > ? ? return a if a > b else b > > The dynamic language's version of maximum() function is 100% correct -- > if you passed an uncomparable object, instead of a number, your call of > it is incorrect; you just didn't pass the right sort of data. And that's > your problem as a caller. > > In fact, since Python's integer is infinite precision (only bounded by > available memory); in practice, Python's version of maximum() has less > chance of producing erroneous result. "in C I can have a function maximum(int a, int b) that will always work. Never blow up, and never give an invalid answer. " Dynamic typed languages like Python fail in this case on "Never blows up". From rNOSPAMon at flownet.com Thu Sep 30 02:29:55 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 23:29:55 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > > I'm not saying one should not use compile-time tools, only that one > > should not rely on them. "Compiling without errors" is not -- and > > cannot ever be -- be a synonym for "bug-free." > > Agreed. (Though C does make it notoriously easy to sneak buggy code > past the compiler.) Let's just leave it at that then. rg From rNOSPAMon at flownet.com Thu Sep 30 02:38:14 2010 From: rNOSPAMon at flownet.com (RG) Date: Wed, 29 Sep 2010 23:38:14 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In article , Seebs wrote: > On 2010-09-30, RG wrote: > > Of course. Computers always do only exactly what you ask of them. On > > this view there is, by definition, no such thing as a bug, only > > specifications that don't correspond to one's intentions. > > f00f. > > That said... I think you're missing Keith's point. > > > Unfortunately, correspondence to intentions is the thing that actually > > matters when writing code. > > Yes. Nonetheless, the maximum() function does exactly what it is intended > to do *with the inputs it receives*. The failure is outside the function; > it did the right thing with the data actually passed to it, the problem > was a user misunderstanding as to what data were being passed to it. > > So there's a bug -- there's code which does not do what it was intended > to do. However, that bug is in the caller, not in the maximum() > function. > > This is an important distinction -- it means we can write a function > which performs that function reliably. Now we just need to figure out > how to call it with valid data... :) We lost some important context somewhere along the line: > > > in C I can have a function maximum(int a, int b) that will always > > > work. Never blow up, and never give an invalid answer. If someone > > > tries to call it incorrectly it is a compile error. Please take note of the second sentence. One way or another, this claim is plainly false. The point I was trying to make is not so much that the claim is false (someone else was already doing that), but that it can be demonstrated to be false without having to rely on any run-time input. rg From 3-nospam at temporary-address.org.uk Thu Sep 30 02:48:18 2010 From: 3-nospam at temporary-address.org.uk (Nick) Date: Thu, 30 Sep 2010 07:48:18 +0100 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <8gik9tFq44U4@mid.individual.net> Message-ID: <87hbh7afrh.fsf@temporary-address.org.uk> Ian Collins writes: > On 09/30/10 05:57 PM, RG wrote: >> >> I'm not saying one should not use compile-time tools, only that one >> should not rely on them. "Compiling without errors" is not -- and >> cannot ever be -- be a synonym for "bug-free." > > We is why wee all have run time tools called unit tests, don't we? But you have to know a lot about the language to know that there's a problem. You cannot sensibly test your max function on every combination of (even int) input which it's designed for (and, of course, it works for those). -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk From v.ladeuil+lp at free.fr Thu Sep 30 02:51:36 2010 From: v.ladeuil+lp at free.fr (Vincent Ladeuil) Date: Thu, 30 Sep 2010 08:51:36 +0200 Subject: bzr 2.2.1 released ! In-Reply-To: (Sridhar Ratnakumar's message of "Wed, 29 Sep 2010 09:16:54 -0700") References: Message-ID: >>>>> Sridhar Ratnakumar writes: > Hi, > It seems that you forgot to update PyPI - which lists 2.1.0rc1 as the latest version. > -srid This should be fixed now. Let us know if you encounter problems. Vincent From ian-news at hotmail.com Thu Sep 30 03:03:14 2010 From: ian-news at hotmail.com (Ian Collins) Date: Thu, 30 Sep 2010 20:03:14 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: <4ca421a1$1@dnews.tpgi.com.au> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> Message-ID: <8gir4qFc8bU1@mid.individual.net> On 09/30/10 06:38 PM, Lie Ryan wrote: > > The /most/ correct version of maximum() function is probably one written > in Haskell as: > > maximum :: Integer -> Integer -> Integer > maximum a b = if a> b then a else b > > Integer in Haskell has infinite precision (like python's int, only > bounded by memory), but Haskell also have static type checking, so you > can't pass just any arbitrary objects. > > But even then, it's still not 100% correct. If you pass a really large > values that exhaust the memory, the maximum() could still produce > unwanted result. > > Second problem is that Haskell has Int, the bounded integer, and if you > have a calculation in Int that overflowed in some previous calculation, > then you can still get an incorrect result. In practice, the > type-agnostic language with *mandatory* infinite precision arithmetic > wins in terms of correctness. Any language which only has optional > infinite precision arithmetic can always produce erroneous result. > > Anyone can dream of 100% correct program; but anyone who believes they > can write a 100% correct program is just a dreamer. In reality, we don't > usually need 100% correct program; we just need a program that runs > correctly enough most of the times that the 0.0000001% chance of > producing erroneous result becomes irrelevant. > > In summary, in this particular case with maximum() function, static > checking does not help in producing the most correct code; if you need > to ensure the highest correctness, you must use a language with > *mandatory* infinite precision integers. Or using the new suffix return syntax in C++0x. Something like template [] maximum( T0 a, T1 b) { return a > b ? a : b; } Where the return type is deduced at compile time. -- Ian Collins From zzbbaadd at aol.com Thu Sep 30 03:23:55 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 00:23:55 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> > > Yes. ?Nonetheless, the maximum() function does exactly what it is intended > > to do *with the inputs it receives*. ?The failure is outside the function; > > it did the right thing with the data actually passed to it, the problem > > was a user misunderstanding as to what data were being passed to it. > > > So there's a bug -- there's code which does not do what it was intended > > to do. ?However, that bug is in the caller, not in the maximum() > > function. > > > This is an important distinction -- it means we can write a function > > which performs that function reliably. ?Now we just need to figure out > > how to call it with valid data... :) > > We lost some important context somewhere along the line: > > > > > in C I can have a function maximum(int a, int b) that will always > > > > work. Never blow up, and never give an invalid answer. If someone > > > > tries to call it incorrectly it is a compile error. > > Please take note of the second sentence. > > One way or another, this claim is plainly false. ?The point I was trying > to make is not so much that the claim is false (someone else was already > doing that), but that it can be demonstrated to be false without having > to rely on any run-time input. > The second sentence is not disproved by a cast from one datatype to another (which changes the value) that happens before maximum() is called. From ldo at geek-central.gen.new_zealand Thu Sep 30 04:01:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 30 Sep 2010 21:01:53 +1300 Subject: System idle time under Linux References: Message-ID: In message , Hugo L?veill? wrote: > Sorry, I am not a linux guy. Did not know it was a text file That?s why I said to check the proc(5) man page for further details. From no.email at nospam.invalid Thu Sep 30 04:02:49 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 01:02:49 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: <7xlj6j3bh2.fsf@ruckus.brouhaha.com> >> > > > in C I can have a function maximum(int a, int b) that will always >> > > > work. Never blow up, and never give an invalid answer. If someone >> > > > tries to call it incorrectly it is a compile error. > The second sentence is not disproved by a cast from one datatype to > another (which changes the value) that happens before maximum() is called. int maximum(int a, int b); int foo() { int (*barf)() = maximum; return barf(3); } This compiles fine for me. Where is the cast? Where is the error message? Are you saying barf(3) doesn't call maximum? From pjb at informatimago.com Thu Sep 30 04:07:12 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 10:07:12 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <8gir4qFc8bU1@mid.individual.net> Message-ID: <87fwwrodsf.fsf@kuiper.lan.informatimago.com> Ian Collins writes: > On 09/30/10 06:38 PM, Lie Ryan wrote: >> >> The /most/ correct version of maximum() function is probably one written >> in Haskell as: >> >> maximum :: Integer -> Integer -> Integer >> maximum a b = if a> b then a else b >> >> Integer in Haskell has infinite precision (like python's int, only >> bounded by memory), but Haskell also have static type checking, so you >> can't pass just any arbitrary objects. >> >> But even then, it's still not 100% correct. If you pass a really large >> values that exhaust the memory, the maximum() could still produce >> unwanted result. >> >> Second problem is that Haskell has Int, the bounded integer, and if you >> have a calculation in Int that overflowed in some previous calculation, >> then you can still get an incorrect result. In practice, the >> type-agnostic language with *mandatory* infinite precision arithmetic >> wins in terms of correctness. Any language which only has optional >> infinite precision arithmetic can always produce erroneous result. >> >> Anyone can dream of 100% correct program; but anyone who believes they >> can write a 100% correct program is just a dreamer. In reality, we don't >> usually need 100% correct program; we just need a program that runs >> correctly enough most of the times that the 0.0000001% chance of >> producing erroneous result becomes irrelevant. >> >> In summary, in this particular case with maximum() function, static >> checking does not help in producing the most correct code; if you need >> to ensure the highest correctness, you must use a language with >> *mandatory* infinite precision integers. > > Or using the new suffix return syntax in C++0x. Something like > > template > [] maximum( T0 a, T1 b) { return a > b ? a : b; } > > Where the return type is deduced at compile time. Indeed. This is generic programming. And it happens that in Lisp (and I assume in languages such as Python), sinte types are not checked at compilation time, all the functions you write are always generic functions. In particular, the property "arguments are not comparable" is not something that can be determined at compilation time, since the program may add a compare method for the given argument at run-time (if the comparison operator used is a generic function). -- __Pascal Bourguignon__ http://www.informatimago.com/ From ifrit at underground Thu Sep 30 04:19:42 2010 From: ifrit at underground (Ifrit) Date: Thu, 30 Sep 2010 10:19:42 +0200 Subject: System idle time under Linux References: Message-ID: <4ca44815$0$41117$e4fe514c@news.xs4all.nl> Hugo L?veill? heeft het volgende neergekrabbeld: > > Thanks, will take a closer look on that > > But to get me started, how would you get, via python, the info from that >From a unix command prompt use the cat command to view their contents. You'll notice that they plain text files with very informative content: # cat /proc/stat cpu 3799492 103198 3546212 82899838 1183162 137849 118698 0 0 cpu0 1071799 22089 1141874 20155255 262512 2714 1704 0 0 cpu1 926425 27349 694583 21016324 302881 2488 4253 0 0 cpu2 938331 29131 736412 21113333 202243 123636 104475 0 0 cpu3 862937 24629 973343 20614926 415526 9011 8266 0 0 intr 153564472 28 10 0 0 0 0 0 7 1 3018879 0 0 173 0 0 0 62 55962320 0 0 0 0 0 9620148 749 0 0 0 0 0 0 0 0 0 0 3136950 4742352 320982 1 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 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 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 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 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 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 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 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 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 ctxt 478141455 btime 1285609820 processes 45111 procs_running 1 procs_blocked 0 softirq 195073836 0 34148873 30536 22265404 4426357 0 55946604 22390786 370319 55494957 -- Ifrit http://nl.wikipedia.org/wiki/Ifriet From ifrit at underground Thu Sep 30 04:22:31 2010 From: ifrit at underground (Ifrit) Date: Thu, 30 Sep 2010 10:22:31 +0200 Subject: System idle time under Linux References: <4ca44815$0$41117$e4fe514c@news.xs4all.nl> Message-ID: <4ca448be$0$41117$e4fe514c@news.xs4all.nl> Ifrit heeft het volgende neergekrabbeld: > Hugo L?veill? heeft het volgende neergekrabbeld: > >> >> Thanks, will take a closer look on that >> >> But to get me started, how would you get, via python, the info from that > > From a unix command prompt use the cat command to view their contents. > You'll notice that they plain text files with very informative content: > > # cat /proc/stat And the man proc command gives info on the format of the content: /proc/stat kernel/system statistics. Varies with architecture. Common entries include: cpu 3357 0 4313 1362393 The amount of time, measured in units of USER_HZ (1/100ths of a second on most architectures, use sysconf(_SC_CLK_TCK) to obtain the right value), that the system spent in user mode, user mode with low priority (nice), system mode, and the idle task, respectively. The last value should be USER_HZ times the second entry in the uptime pseudo-file. In Linux 2.6 this line includes three additional columns: iowait - time waiting for I/O to complete (since 2.5.41); irq - time servicing interrupts (since 2.6.0-test4); softirq - time servicing softirqs (since 2.6.0-test4). Since Linux 2.6.11, there is an eighth column, steal - stolen time, which is the time spent in other operating systems when running in a virtualized environment Since Linux 2.6.24, there is a ninth column, guest, which is the time spent running a virtual CPU for guest operating systems under the control of the Linux kernel. page 5741 1808 The number of pages the system paged in and the number that were paged out (from disk). swap 1 0 The number of swap pages that have been brought in and out. intr 1462898 This line shows counts of interrupts serviced since boot time, for each of the possible system interrupts. The first column is the total of all interrupts serviced; each subsequent column is the total for a particular interrupt. disk_io: (2,0):(31,30,5764,1,2) (3,0):... (major,disk_idx):(noinfo, read_io_ops, blks_read, write_io_ops, blks_written) (Linux 2.4 only) ctxt 115315 The number of context switches that the system underwent. btime 769041601 boot time, in seconds since the Epoch (January 1, 1970). processes 86031 Number of forks since boot. procs_running 6 Number of processes in runnable state. (Linux 2.5.45 onwards.) procs_blocked 2 Number of processes blocked waiting for I/O to complete. (Linux 2.5.45 onwards.) -- Ifrit http://nl.wikipedia.org/wiki/Ifriet From rNOSPAMon at flownet.com Thu Sep 30 04:40:43 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 01:40:43 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: In article <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21 at y12g2000prb.googlegroups.com>, TheFlyingDutchman wrote: > > > Yes. ?Nonetheless, the maximum() function does exactly what it is intended > > > to do *with the inputs it receives*. ?The failure is outside the function; > > > it did the right thing with the data actually passed to it, the problem > > > was a user misunderstanding as to what data were being passed to it. > > > > > So there's a bug -- there's code which does not do what it was intended > > > to do. ?However, that bug is in the caller, not in the maximum() > > > function. > > > > > This is an important distinction -- it means we can write a function > > > which performs that function reliably. ?Now we just need to figure out > > > how to call it with valid data... :) > > > > We lost some important context somewhere along the line: > > > > > > > in C I can have a function maximum(int a, int b) that will always > > > > > work. Never blow up, and never give an invalid answer. If someone > > > > > tries to call it incorrectly it is a compile error. > > > > Please take note of the second sentence. > > > > One way or another, this claim is plainly false. ?The point I was trying > > to make is not so much that the claim is false (someone else was already > > doing that), but that it can be demonstrated to be false without having > > to rely on any run-time input. > > > > The second sentence is not disproved by a cast from one datatype to > another (which changes the value) that happens before maximum() is > called. You can't have it both ways. Either I am calling it incorrectly, in which case I should get a compiler error, or I am calling it correctly, and I should get the right answer. That I got neither does in fact falsify the claim. The only way out of this is to say that maximum(8589934592, 1) returning 1 is in fact "correct", in which case we'll just have to agree to disagree. rg From as at sci.fi Thu Sep 30 04:41:48 2010 From: as at sci.fi (Anssi Saari) Date: Thu, 30 Sep 2010 11:41:48 +0300 Subject: how to get partition information of a hard disk with python References: Message-ID: Nobody writes: > On Wed, 22 Sep 2010 00:31:04 +0200, Hellmut Weber wrote: > >> I'm looking for a possibility to access the partiton inforamtion of a >> hard disk of my computer from within a python program. > > Have you considered parsing /proc/partitions? One could also just read the partition table directly, it's on the first sector usually. (Assuming a PC without a GUID partition table...) The partition table is just 64 bytes at offset 446 into the sector. In unixlikes you can just open the disk with file.open()... Then again, unixlikes other than Linux have somewhat different ideas about partitioning... From zzbbaadd at aol.com Thu Sep 30 04:43:38 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 01:43:38 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: <785d0d80-c4ec-4e02-94ff-fe18dc4a7ddd@e34g2000prn.googlegroups.com> On Sep 30, 1:02?am, Paul Rubin wrote: > >> > > > in C I can have a function maximum(int a, int b) that will always > >> > > > work. Never blow up, and never give an invalid answer. If someone > >> > > > tries to call it incorrectly it is a compile error. > > The second sentence is not disproved by a cast from one datatype to > > another (which changes the value) that happens before maximum() is called. > > ? ? int maximum(int a, int b); > > ? ? int foo() { > ? ? ? int (*barf)() = maximum; > ? ? ? return barf(3); > ? ? } > > This compiles fine for me. ?Where is the cast? ?Where is the error message? > Are you saying barf(3) doesn't call maximum? With Tiny C on my system, your code does not cause maximum to give an incorrect value, or to blow up: int maximum(int a, int b) { printf("entering maximum %d %d\n",a,b); if ( a > b ) return a; else return b; } int foo() { int (*barf)() = maximum; return barf(3); } int main (int argc, char *argv[]) { printf("maximum is %d\n",foo()); } ------------- output ----------------------------------- entering maximum 3 4198400 maximum is 4198400 From zzbbaadd at aol.com Thu Sep 30 04:55:39 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 01:55:39 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: On Sep 30, 1:40?am, RG wrote: > In article > <5bf24e59-1be0-4d31-9fa7-c03a8bf9b... at y12g2000prb.googlegroups.com>, > > > > > > ?TheFlyingDutchman wrote: > > > > Yes. ?Nonetheless, the maximum() function does exactly what it is intended > > > > to do *with the inputs it receives*. ?The failure is outside the function; > > > > it did the right thing with the data actually passed to it, the problem > > > > was a user misunderstanding as to what data were being passed to it. > > > > > So there's a bug -- there's code which does not do what it was intended > > > > to do. ?However, that bug is in the caller, not in the maximum() > > > > function. > > > > > This is an important distinction -- it means we can write a function > > > > which performs that function reliably. ?Now we just need to figure out > > > > how to call it with valid data... :) > > > > We lost some important context somewhere along the line: > > > > > > > in C I can have a function maximum(int a, int b) that will always > > > > > > work. Never blow up, and never give an invalid answer. If someone > > > > > > tries to call it incorrectly it is a compile error. > > > > Please take note of the second sentence. > > > > One way or another, this claim is plainly false. ?The point I was trying > > > to make is not so much that the claim is false (someone else was already > > > doing that), but that it can be demonstrated to be false without having > > > to rely on any run-time input. > > > The second sentence is not disproved by a cast from one datatype to > > another (which changes the value) that happens before maximum() is > > called. > > You can't have it both ways. ?Either I am calling it incorrectly, in > which case I should get a compiler error, or I am calling it correctly, > and I should get the right answer. ?That I got neither does in fact > falsify the claim. ?The only way out of this is to say that > maximum(8589934592, 1) returning 1 is in fact "correct", in which case > we'll just have to agree to disagree. > 1) long trying_to_break_maximum = 8589934592; 2) /* compiler adds */ int created_to_allow_maximum_call = (int) trying_to_break_maximum; 3) maximum(created_to_allow_maximum_call, 1); I think we have to agree to disagree, because I don't see the lack of a compiler error at step 2 as a problem with the maximum() function. From lie.1296 at gmail.com Thu Sep 30 04:55:57 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 30 Sep 2010 18:55:57 +1000 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> Message-ID: <4ca44fea@dnews.tpgi.com.au> On 09/30/10 16:09, TheFlyingDutchman wrote: > >> >> That argument can be made for dynamic language as well. If you write in >> dynamic language (e.g. python): >> >> def maximum(a, b): >> return a if a > b else b >> >> The dynamic language's version of maximum() function is 100% correct -- >> if you passed an uncomparable object, instead of a number, your call of >> it is incorrect; you just didn't pass the right sort of data. And that's >> your problem as a caller. >> >> In fact, since Python's integer is infinite precision (only bounded by >> available memory); in practice, Python's version of maximum() has less >> chance of producing erroneous result. > > "in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. " > > Dynamic typed languages like Python fail in this case on "Never blows > up". How do you define "Never blows up"? Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow up, and of the worst kind since it passes silently. From deets at web.de Thu Sep 30 04:59:28 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 30 Sep 2010 10:59:28 +0200 Subject: utf-8 and ctypes References: Message-ID: <87iq1nobdb.fsf@web.de> Brendan Miller writes: > 2010/9/29 Lawrence D'Oliveiro : >> In message , Brendan >> Miller wrote: >> >>> It seems that characters not in the ascii subset of UTF-8 are >>> discarded by c_char_p during the conversion ... >> >> Not a chance. >> >>> ... or at least they don't print out when I go to print the string. >> >> So it seems there?s a problem on the printing side. What happens when you >> construct a UTF-8-encoded string directly in Python and try printing it the >> same way? > > Doing this seems to confirm something is broken in ctypes w.r.t. UTF-8... > > if I enter: > str = "???????" What is this? Which encoding is used by your editor to produce this byte-string? If you want to be sure you have the right encoding, you need to do this: - put a coding: utf-8 (or actually whatever your editor uses) in the first or second line - use unicode literals. That are the funny little strings with a "u" in front of them. They will be *decoded* using the declared encoding. - when passing this to C, explicitly *encode* with utf-8 first. Diez From rbrown780 at gmail.com Thu Sep 30 05:02:39 2010 From: rbrown780 at gmail.com (roronron) Date: Thu, 30 Sep 2010 09:02:39 -0000 Subject: install 3.1 Message-ID: My python installed but the gui gives me syntax error on any code I type or paste in. Newbie needs help. From clp2 at rebertia.com Thu Sep 30 05:16:34 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 30 Sep 2010 02:16:34 -0700 Subject: install 3.1 In-Reply-To: References: Message-ID: On Thu, Sep 30, 2010 at 2:02 AM, roronron wrote: > My python installed but the gui gives me syntax error on any code I type > or paste in. Newbie needs help. Post the full, exact text of the error message. See also: http://www.catb.org/esr/faqs/smart-questions.html Cheers, Chris From funthyme at gmail.com Thu Sep 30 05:26:23 2010 From: funthyme at gmail.com (John Pinner) Date: Thu, 30 Sep 2010 02:26:23 -0700 (PDT) Subject: System idle time under Linux References: Message-ID: <51c5b69c-1a8e-47d7-b90d-f377334c69ae@k10g2000yqa.googlegroups.com> On Sep 29, 7:36?pm, Hugo L?veill? wrote: > Good point > > One I am looking for, is time since last user mouse or keyboard action. > So I guess I am looking for the exact same thing a screensaver is > looking for The command who -Hu). will give you idle time for each logged-in user ( H - print headers; u - list users ) and you could run this command via subprocess, then read and parse its output. Alternatively you could parse the same file(s) as who - I think it reads /var/run/utmp - but that would be a lot more work, as it is a binary file (run man utmp to see its format, use the struct module to decode) Best wishes, John -- From pc at p-cos.net Thu Sep 30 05:27:48 2010 From: pc at p-cos.net (Pascal Costanza) Date: Thu, 30 Sep 2010 11:27:48 +0200 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> Message-ID: <8gj3gkFtsmU1@mid.individual.net> On 30/09/2010 08:09, TheFlyingDutchman wrote: > >> >> That argument can be made for dynamic language as well. If you write in >> dynamic language (e.g. python): >> >> def maximum(a, b): >> return a if a> b else b >> >> The dynamic language's version of maximum() function is 100% correct -- >> if you passed an uncomparable object, instead of a number, your call of >> it is incorrect; you just didn't pass the right sort of data. And that's >> your problem as a caller. >> >> In fact, since Python's integer is infinite precision (only bounded by >> available memory); in practice, Python's version of maximum() has less >> chance of producing erroneous result. > > "in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. " > > Dynamic typed languages like Python fail in this case on "Never blows > up". They don't "blow up". They may throw an exception, on which you can act. You make it sound like a core dump, which it isn't. Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ From ian-news at hotmail.com Thu Sep 30 05:52:40 2010 From: ian-news at hotmail.com (Ian Collins) Date: Thu, 30 Sep 2010 22:52:40 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: <7xlj6j3bh2.fsf@ruckus.brouhaha.com> References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: <8gj4v8Fc8aU1@mid.individual.net> On 09/30/10 09:02 PM, Paul Rubin wrote: > > int maximum(int a, int b); > > int foo() { > int (*barf)() = maximum; > return barf(3); > } > > This compiles fine for me. Where is the cast? Where is the error message? > Are you saying barf(3) doesn't call maximum? Try a language with stricter type checking: CC /tmp/u.c "/tmp/u.c", line 7: Error: Cannot use int(*)(int,int) to initialize int(*)(). "/tmp/u.c", line 8: Error: Too many arguments in call to "int(*)()". -- Ian Collins From nobody at nowhere.com Thu Sep 30 06:01:32 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 30 Sep 2010 11:01:32 +0100 Subject: how to get partition information of a hard disk with python References: Message-ID: On Thu, 30 Sep 2010 11:41:48 +0300, Anssi Saari wrote: >>> I'm looking for a possibility to access the partiton inforamtion of a >>> hard disk of my computer from within a python program. >> >> Have you considered parsing /proc/partitions? > > One could also just read the partition table directly, it's on the > first sector usually. (Assuming a PC without a GUID partition > table...) The partition table is just 64 bytes at offset 446 into the > sector. In unixlikes you can just open the disk with file.open()... > Then again, unixlikes other than Linux have somewhat different ideas > about partitioning... Apart from the portability issues, you usually need elevated privileges to read the disk directly, while /proc/partitions is normally readable by anyone. OTOH, many of the tasks for which partition information is necessary would require root privilege anyhow. From zzbbaadd at aol.com Thu Sep 30 06:14:47 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 03:14:47 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> > > > "in C I can have a function maximum(int a, int b) that will always > > work. Never blow up, and never give an invalid answer. " > > > Dynamic typed languages like Python fail in this case on "Never blows > > up". > > How do you define "Never blows up"? Never has execution halt. I think a key reason in the big rise in the popularity of interpreted languages is that when execution halts, they normally give a call stack and usually a good reason for why things couldn't continue. As opposed to compiled languages which present you with a blank screen and force you to - fire up a debugger, or much much worse, look at a core dump - to try and discern all the information the interpreter presents to you immediately. > > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > up, and of the worst kind since it passes silently. If I had to choose between "blow up" or "invalid answer" I would pick "invalid answer". In this example RG is passing a long literal greater than INT_MAX to a function that takes an int and the compiler apparently didn't give a warning about the change in value as it created the cast to an int, even with the option -Wall (all warnings). I think it's legitmate to consider that an option for a warning/error on this condition should be available. As far the compiler generating code that checks for a change in value at runtime when a number is cast to a smaller data type, I think that's also a legitimate request for a C compiler option (in addition to other runtime check options like array subscript out of bounds). From joel.hedlund at gmail.com Thu Sep 30 06:17:18 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 03:17:18 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness Message-ID: I'm having a weird problem with the 'External Tools' plugin for gedit, that seems to get weirder the more I dig into it. When I start gedit by clicking a launcher (from the Ubuntu menu, panel or desktop) everything is dandy and the 'External Tools' plugin works as expected. When gedit is launched from the terminal, the 'External Tools' plugin is greyed out in the plugin list and I get this traceback on stderr: $ gedit Traceback (most recent call last): File "/usr/lib/gedit-2/plugins/externaltools/__init__.py", line 24, in from manager import Manager File "/usr/lib/gedit-2/plugins/externaltools/manager.py", line 27, in import hashlib File "/usr/lib/python2.6/hashlib.py", line 136, in md5 = __get_builtin_constructor('md5') File "/usr/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor import _md5 ImportError: No module named _md5 ** (gedit:8714): WARNING **: Error loading plugin 'External Tools' The same thing happens if I try to activate the plugin from a gedit launched from the terminal (if it's already been deactivated from a gedit launched from the menu). My analysis is that gedit tries to import the externaltools package, which imports hashlib, which tries to import _hashlib but fails and falls back to _md5 which also fails, which apparently /should not happen/, or so google tells me. One of _hashlib and _md5 should always exist. However, importing _hashlib in a python interpreter works just fine, i.e: $ python -c 'import _hashlib' returns nothing. What also puzzles me is that I don't seem to have _hashlib* anywhere on my system (am I supposed to?) and getting the __file__ attribute off the module doesn't work, and help(_hashlib) says FILE is (built-in). >>> import _hashlib >>> _hashlib.__file__ Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute '__file__' Google drops vague hints that there may be a a virtualenv that one might have to rebuild, but in that case I have no idea where to begin. I've tried reinstalling the ubuntu packages gedit, gedit-common and gedit-plugins, but to no avail. And the machine runs a fully updated ubuntu karmic koala (10.4) that has survived numerous dist-upgrades, if that's of any use to anybody. I'd appreciate any input on this, even if it's just new bushes to whack for scaring the problem out into the light. Cheers! /Joel From sion at viridian.paintbox Thu Sep 30 06:21:49 2010 From: sion at viridian.paintbox (Sion Arrowsmith) Date: Thu, 30 Sep 2010 10:21:49 GMT Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <20100929114701.110c18b5@geekmail.INVALID> Message-ID: <1xZoo.1781$Fk6.1722@newsfe13.ams2> Andreas Waldenburger wrote: > > [ ... ] > Boolean values behave like the values 0 and 1, respectively, in > almost all contexts, the exception being that when converted to a > string, the strings "False" or "True" are returned, respectively. Hmm. So the original problem of: button = gtk.Button(("False,", "True,")[fill==True]) could also rewritten as: button = gtk.Button(str(bool(fill))+",") -- \S under construction From affdfsdfdsfsd at b.com Thu Sep 30 06:41:01 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 30 Sep 2010 10:41:01 GMT Subject: will Gnome 3.0 kill pygtk? Message-ID: <4ca4693d$0$40283$4fafbaef@reader2.news.tin.it> Hi! It seem that the new version of gnome 3.0 will dismiss pygtk support. link: [1] http://live.gnome.org/TwoPointNinetyone/ (search killing pygtk) [2] http://live.gnome.org/GnomeGoals/PythonIntrospectionPorting i'm studying pygtk right now, am i wasting my time considering that my preferred platform is linux/gnome? thanks Nico From bruno.desthuilliers at gmail.com Thu Sep 30 06:42:29 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 30 Sep 2010 03:42:29 -0700 (PDT) Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: On 29 sep, 19:20, Seebs wrote: > On 2010-09-29, Tracubik wrote: > > button = gtk.Button(("False,", "True,")[fill==True]) > Oh, what a nasty idiom. > Well, it's not very different from dict-based dispatch , which is the core of OO polymorphic dispatch in quite a few dynamic OOPLs. Anyway, it's a common Python idiom and one that's not specially hard to grasp so I don't see any legibility problem here. From hugol at fastmail.net Thu Sep 30 06:58:47 2010 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Thu, 30 Sep 2010 06:58:47 -0400 Subject: System idle time under Linux In-Reply-To: <51c5b69c-1a8e-47d7-b90d-f377334c69ae@k10g2000yqa.googlegroups.com> References: <51c5b69c-1a8e-47d7-b90d-f377334c69ae@k10g2000yqa.googlegroups.com> Message-ID: <1285844327.4647.1397663319@webmail.messagingengine.com> Ok after some testing, what the who -Hu is giving me is the idle time of each running open shell. The first line always return a "?" as the IDLE time. ex: NAME LINE TIME IDLE PID COMMENT vg0619hl :0 2010-09-30 06:10 ? 13091 vg0619hl pts/1 2010-09-30 06:27 00:11 14084 (:0.0) vg0619hl pts/2 2010-09-30 06:54 . 14084 (:0.0) On Thu, 30 Sep 2010 02:26 -0700, "John Pinner" wrote: > On Sep 29, 7:36?pm, Hugo L?veill? wrote: > > Good point > > > > One I am looking for, is time since last user mouse or keyboard action. > > So I guess I am looking for the exact same thing a screensaver is > > looking for > > The command > > who -Hu). > > > will give you idle time for each logged-in user > > ( H - print headers; u - list users ) > > and you could run this command via subprocess, then read and parse its > output. > > Alternatively you could parse the same file(s) as who - I think it > reads /var/run/utmp - but that would be a lot more work, as it is a > binary file (run man utmp to see its format, use the struct module to > decode) > > Best wishes, > > John > -- > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hugo L?veill? hugol at fastmail.net From santiago.caracol at gmail.com Thu Sep 30 07:05:21 2010 From: santiago.caracol at gmail.com (Santiago Caracol) Date: Thu, 30 Sep 2010 04:05:21 -0700 (PDT) Subject: sys.setrecursionlimit() and regular expressions Message-ID: Hello, in my program I use recursive functions. A recursion limit of 10 would be by far sufficient. Yet, I also use some (not very complicated) regular expressions, which only compile if I set the recursion limit to 100, or so. This means, of course, an unnecessary loss of speed. Can I use one recursion limit for my functions and another one for the re module? Santiago From tom.conneely at gmail.com Thu Sep 30 07:06:03 2010 From: tom.conneely at gmail.com (Tom Conneely) Date: Thu, 30 Sep 2010 04:06:03 -0700 (PDT) Subject: PyCObject & malloc creating memory leak References: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> Message-ID: <4bf06438-5c31-4809-89bb-c335289fffe9@a15g2000yqm.googlegroups.com> Thanks for your reply, you've given me plenty to think about On Sep 29, 11:51?pm, Antoine Pitrou wrote: > > > My original plan was to have the data processing and data acquisition > > functions running in separate processes, with a multiprocessing.Queue > > for passing the raw data packets. The raw data is read in as a char*, > > with a non constant length, hence I have allocated memory using > > PyMem_Malloc and I am returning from the acquisition function a > > PyCObject containing a pointer to this char* buffer, along with a > > destructor. > > That sounds overkill, and I also wonder how you plan to pass that > object in a multiprocessing Queue (which relies on objects being > pickleable). Why don't you simply create a PyString object instead? Could you elaborate on why you feel this is overkill? Also, your right about passing the PyCObjects through a Queue, something which I hadn't really considered, so I've switched to using python strings as you suggested, an overhead I hoped to avoid but you can't win them all I suppose. > > So if I call these functions in a loop, e.g. The following will > > generate ~10GB of data > > > ? ? x = MyClass() > > ? ? for i in xrange(0, 10 * 2**20): > > ? ? ? ? c = x.malloc_buffer() > > ? ? ? ? x.retrieve_buffer(c) > > > All my memory disapears, until python crashes with a MemoryError. By > > placing a print in the destructor function I know it's being called, > > however it's not actually freeing the memory. So in short, what am I > > doing wrong? > > Python returns memory to the OS by calling free(). Not all OSes > actually relinquish memory when free() is called; some will simply set > it aside for the next allocation. > Another possible (and related) issue is memory fragmentation. Again, it > depends on the memory allocator. Yes, I know that's the case but the "freed" memory should be used for the next allocation, or atleast at some point before python runs out of memory. Anyway, this is besides the point as I've switched to using strings. Again thanks for taking the time to help me out, Tom Conneely From joel.hedlund at gmail.com Thu Sep 30 07:34:59 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 04:34:59 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: Message-ID: <2f87f2f8-3f23-42df-a5b0-3c5b84d51870@d25g2000yqc.googlegroups.com> bah, I meant to say I'm running "a fully updated ubuntu lucid lynx (10.4)". From __peter__ at web.de Thu Sep 30 07:35:09 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 13:35:09 +0200 Subject: sys.setrecursionlimit() and regular expressions References: Message-ID: Santiago Caracol wrote: > in my program I use recursive functions. A recursion limit of 10 would > be by far sufficient. Yet, I also use some (not very complicated) > regular expressions, which only compile if I set the recursion limit > to 100, or so. This means, of course, an unnecessary loss of speed. Why do you think so? The recursion limit has no effect on the speed of your script. It's just a number that the interpreter checks against. Peter From santiago.caracol at gmail.com Thu Sep 30 07:53:32 2010 From: santiago.caracol at gmail.com (Santiago Caracol) Date: Thu, 30 Sep 2010 04:53:32 -0700 (PDT) Subject: sys.setrecursionlimit() and regular expressions References: Message-ID: > Why do you think so? The recursion limit has no effect on the speed of your > script. It's just a number that the interpreter checks against. Yes, sorry. I was just about to explain that. The 'of course' in my post was silly. In MY program, the recursion limit is relevant for performance, because I use constructs of the following kind: def analyze(sentence): try: ... except RuntimeError: ... I.e. I try to apply certain recursive rules to a sentence. If this doesn't lead to any results (up to recursion limit N), then I skip the analysis. From __peter__ at web.de Thu Sep 30 07:54:07 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 13:54:07 +0200 Subject: gedit 'External Tools' plugin hashlib weirdness References: Message-ID: Joel Hedlund wrote: > I'm having a weird problem with the 'External Tools' plugin for gedit, > that seems to get weirder the more I dig into it. When I start gedit > by clicking a launcher (from the Ubuntu menu, panel or desktop) > everything is dandy and the 'External Tools' plugin works as expected. > When gedit is launched from the terminal, the 'External Tools' plugin > is greyed out in the plugin list and I get this traceback on stderr: > > $ gedit > Traceback (most recent call last): > File "/usr/lib/gedit-2/plugins/externaltools/__init__.py", line 24, > in > from manager import Manager > File "/usr/lib/gedit-2/plugins/externaltools/manager.py", line 27, > in > import hashlib > File "/usr/lib/python2.6/hashlib.py", line 136, in > md5 = __get_builtin_constructor('md5') > File "/usr/lib/python2.6/hashlib.py", line 63, in > __get_builtin_constructor > import _md5 > ImportError: No module named _md5 > > ** (gedit:8714): WARNING **: Error loading plugin 'External Tools' > > The same thing happens if I try to activate the plugin from a gedit > launched from the terminal (if it's already been deactivated from a > gedit launched from the menu). > > My analysis is that gedit tries to import the externaltools package, > which imports hashlib, which tries to import _hashlib but fails and > falls back to _md5 which also fails, which apparently /should not > happen/, or so google tells me. One of _hashlib and _md5 should always > exist. > > However, importing _hashlib in a python interpreter works just fine, > i.e: > > $ python -c 'import _hashlib' > > returns nothing. What also puzzles me is that I don't seem to have > _hashlib* anywhere on my system (am I supposed to?) and getting the > __file__ attribute off the module doesn't work, and help(_hashlib) > says FILE is (built-in). > >>>> import _hashlib >>>> _hashlib.__file__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute '__file__' > > Google drops vague hints that there may be a a virtualenv that one > might have to rebuild, but in that case I have no idea where to > begin. > > I've tried reinstalling the ubuntu packages gedit, gedit-common and > gedit-plugins, but to no avail. And the machine runs a fully updated > ubuntu karmic koala (10.4) that has survived numerous dist-upgrades, > if that's of any use to anybody. > > I'd appreciate any input on this, even if it's just new bushes to > whack for scaring the problem out into the light. You could add import sys print sys.executable at the top of /usr/lib/gedit-2/plugins/externaltools/__init__.py Maybe there's some confusion about what python interpreter should be used. Peter From __peter__ at web.de Thu Sep 30 08:10:38 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 14:10:38 +0200 Subject: sys.setrecursionlimit() and regular expressions References: Message-ID: Santiago Caracol wrote: > >> Why do you think so? The recursion limit has no effect on the speed of >> your script. It's just a number that the interpreter checks against. > > Yes, sorry. I was just about to explain that. The 'of course' in my > post was silly. > > In MY program, the recursion limit is relevant for performance, > because I use constructs of the following kind: > > def analyze(sentence): > try: > ... > except RuntimeError: > ... > > I.e. I try to apply certain recursive rules to a sentence. If this > doesn't lead to any results (up to recursion limit N), > then I skip the analysis. Here's a depth limitation decorator that you can apply selectively. In the example below you can have as many gamma() calls as the interpreter's recursion limit permits, but only a total of 10 calls of alpha() and beta(). import random class TooDeep(Exception): pass _limit = 10 def limited(f): def g(*args, **kw): global _limit if not _limit: raise TooDeep _limit -= 1 try: return f(*args, **kw) finally: _limit += 1 return g @limited def alpha(n): print "alpha", n beta(n+1) @limited def beta(n): print "beta", n gamma(n+1) def gamma(n): print "gamma", n random.choice([alpha, beta, gamma])(n+1) if __name__ == "__main__": try: alpha(0) except TooDeep as e: print e Peter From Antoon.Pardon at rece.vub.ac.be Thu Sep 30 08:10:43 2010 From: Antoon.Pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 30 Sep 2010 14:10:43 +0200 Subject: sequence multiplied by -1 In-Reply-To: References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> Message-ID: <20100930121043.GD2272@rcpc42.vub.ac.be> On Sun, Sep 26, 2010 at 03:20:18PM +0000, Grant Edwards wrote: > On 2010-09-26, Paul Rubin wrote: > > Steven D'Aprano writes: > >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > > > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > > Because > > 3 * "spam" == "spam" + "spam" + "spam" > > Just like > > 3 * 6 = 6 + 6 + 6 > > So now I suppose "+" for string concatenation is a bad thing. Well I find it an unfortunate choice. The problem is, that it is not that unusual to want some class to have the possibility of both addition and concatenation. But since we only one symbol for both operations, you will have to loose some consistency over this. -- Antoon Pardon From rustompmody at gmail.com Thu Sep 30 08:14:56 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 30 Sep 2010 17:44:56 +0530 Subject: PyRTF object model Message-ID: I am trying to use PyRTF. I gather that an RTF doc consists of a list of sections, a section consists of a list of paras, paras seem to be just text (not sure on that one) Some questions: When does one end one section and start another? How does one handle lists (as in numbered, bulleted etc)? From nick_keighley_nospam at hotmail.com Thu Sep 30 08:19:04 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 30 Sep 2010 05:19:04 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> Message-ID: <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> On 27 Sep, 20:29, p... at informatimago.com (Pascal J. Bourguignon) wrote: > namekuseijin writes: > > Fact is: ?almost all user data from the external words comes into > > programs as strings. ?No typesystem or compiler handles this fact all > > that graceful... > > I would even go further. > > Types are only part of the story. ?You may distinguish between integers > and floating points, fine. ?But what about distinguishing between > floating points representing lengths and floating points representing > volumes? ?Worse, what about distinguishing and converting floating > points representing lengths expressed in feets and floating points > representing lengths expressed in meters. fair points > If you start with the mindset of static type checking, you will consider > that your types are checked and if the types at the interface of two > modules matches you'll think that everything's ok. ?And six months later > you Mars mission will crash. do you have any evidence that this is actually so? That people who program in statically typed languages actually are prone to this "well it compiles so it must be right" attitude? > On the other hand, with the dynamic typing mindset, you might even wrap > your values (of whatever numerical type) in a symbolic expression > mentionning the unit and perhaps other meta data, so that when the other > module receives it, it may notice (dynamically) that two values are not > of the same unit, but if compatible, it could (dynamically) convert into > the expected unit. ?Mission saved! they *may* do this but do they *actually* do it? My (limited) experience of dynamically typed languges is everynow and again you attempt to apply an operator to the wrong type of operand and kerblam! If your testing is inadaquate then it's inadaquate whatever the typiness of your language. From joel.hedlund at gmail.com Thu Sep 30 08:26:45 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 05:26:45 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: Message-ID: How do I catch output to stdout/stderr when launching from a launcher? I added this to /usr/lib/gedit-2/plugins/externaltools/__init__.py: import sys f = open('/tmp/eraseme.txt', 'w') print >> f, "The executable is %r." % sys.executable f.close() In both cases (launcher/termial) the contents of eraseme.txt are: The executable is '/usr/bin/python'. From tom.conneely at gmail.com Thu Sep 30 08:29:17 2010 From: tom.conneely at gmail.com (Tom Conneely) Date: Thu, 30 Sep 2010 05:29:17 -0700 (PDT) Subject: PyCObject & malloc creating memory leak References: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> <4bf06438-5c31-4809-89bb-c335289fffe9@a15g2000yqm.googlegroups.com> Message-ID: <08338e8a-28d3-46b9-b4a5-6502e7a9d0ea@z28g2000yqh.googlegroups.com> I'm posting this last message as I've found the source of my initial memory leak problem, unfortunately it was an embarrassingly basic mistake. In my defence I've got a horrible cold, but I'm just making excuses. I begin by mallocing the memory, which gives me a pointer "foo" to that memory: char *foo = PyMem_Malloc(1024 * sizeof(char)); then assign a value to it: foo = "foo"; of course what this actually does is change the pointer to point to a new memory address containing a constant "foo". Hence, when I free the memory in the PYCObject's destructor, the pointer is for the constant "foo", not the memory I initially allocated. I only posted this to help people searching, sorry for the noise. Tom Conneely From namekuseijin at gmail.com Thu Sep 30 08:35:20 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Thu, 30 Sep 2010 05:35:20 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Message-ID: <6784f34c-2948-408b-b2eb-4a3b171c5afe@k10g2000yqa.googlegroups.com> On 29 set, 11:04, w_a_x_man wrote: > On Sep 26, 9:24?am, p... at informatimago.com (Pascal J. Bourguignon) > wrote: > > > > > Xah Lee writes: > > > here's a interesting toy list processing problem. > > > > I have a list of lists, where each sublist is labelled by > > > a number. I need to collect together the contents of all sublists > > > sharing > > > the same label. So if I have the list > > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > > r) (5 s t)) > > > > where the first element of each sublist is the label, I need to > > > produce: > > > > output: > > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > > a Mathematica solution is here: > > >http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > > > R5RS Scheme lisp solution: > > >http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_... > > > by Sourav Mukherjee > > > > also, a Common Lisp solution can be found here: > > >http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1de... > > > It's too complex. Just write: > > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > > ? ? ? ? ? ? ? (2 o p) (4 q r) (5 s t)))) > > > ? (mapcar (lambda (class) (reduce (function append) class :key (function rest))) > > ? ? ? ? ? ?(com.informatimago.common-lisp.list:equivalence-classes list :key (function first))) > > > ? ?) > > > --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) > > > -- > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/ > > Ruby: > > [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, > 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], > [5, 's', 't']]. > group_by{|x| x.first}.values.map{|x| x.map{|y| y[1..-1]}.flatten} > > ? ? ==>[["s", "t"], ["a", "b"], ["c", "d", "i", "j"], > ?["e", "f", "k", "l", "o", "p"], > ?["g", "h"], ["m", "n", "q", "r"]] cool, it comes with order all fucked up. This is something I was criticized for before, though not all that important to most functional processing. Not the case here, though. here's a scheme version that is hopefully better than the given one: (define (dig in) (if (null? in) '() (let* ((n (first-of-first in)) (all-n (filter in (lambda (x) (eq? n (first x))))) (all-but-n (filter in (lambda (x) (not (eq? n (first x))))))) (pair (fold all-n (lambda (i o) (pair (second i) (pair (third i) o)))) (dig all-but-n))))) ; given these aliases to lisp n00bs (define pair cons) (define first car) (define rest cdr) (define first-of-first caar) (define second cadr) (define third caddr) ; and these well-known functions (non-tail-recursive for benefit of n00bs) (define (fold ls f) ; AKA reduce (if (null? ls) '() (f (first ls) (fold (rest ls) f)))) (define (filter ls f) (fold ls (lambda (i o) (if (f i) (pair i o) o)))) ; testing (let ((in '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t)))) (display (dig in)) (newline)) From nick_keighley_nospam at hotmail.com Thu Sep 30 08:36:17 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 30 Sep 2010 05:36:17 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: On 30 Sep, 11:14, TheFlyingDutchman wrote: > > > "in C I can have a function maximum(int a, int b) that will always > > > work. Never blow up, and never give an invalid answer. " > > > > Dynamic typed languages like Python fail in this case on "Never blows > > > up". > > > How do you define "Never blows up"? > > Never has execution halt. > > I think a key reason in the big rise in the popularity of interpreted > languages is that when execution halts, they normally give a call > stack and usually a good reason for why things couldn't continue. As > opposed to compiled languages which present you with a blank screen > and force you to - fire up a debugger, or much much worse, look at a > core dump - to try and discern all the information the interpreter > presents to you immediately. > > > > > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > > up, and of the worst kind since it passes silently. > > If I had to choose between "blow up" or "invalid answer" I would pick > "invalid answer". there are some application domains where neither option would be viewed as a satisfactory error handling strategy. Fly-by-wire, petro- chemicals, nuclear power generation. Hell you'd expect better than this from your phone! > In this example RG is passing a long literal greater than INT_MAX to a > function that takes an int and the compiler apparently didn't give a > warning about the change in value as it created the cast to an int, > even with the option -Wall (all warnings). I think it's legitmate to > consider that an option for a warning/error on this condition should > be available. As far the compiler generating code that checks for a > change in value at runtime when a number is cast to a smaller data > type, I think that's also a legitimate request for a C compiler option > (in addition to other runtime check options like array subscript out > of bounds). From joel.hedlund at gmail.com Thu Sep 30 08:37:52 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 05:37:52 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: Message-ID: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> FOUND IT! I added the line print >> f, '\n'.join(sorted(sys.path)) and diff:ed the files produced from terminal/launcher. When using the launcher, changes to PYTHONPATH done in ~/.bashrc are not picked up, and I apparently had an old reference to /usr/lib/ python2.4 sitting in there. Removed it, reloaded .bashrc, plugin now works. The question still remains why gnome disregards ~/.bashrc, but that's a whole other topic. Thanks a bunch, you guys are ever so helpful. From nhodgson at bigpond.net.au Thu Sep 30 08:41:14 2010 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Thu, 30 Sep 2010 22:41:14 +1000 Subject: will Gnome 3.0 kill pygtk? In-Reply-To: <4ca4693d$0$40283$4fafbaef@reader2.news.tin.it> References: <4ca4693d$0$40283$4fafbaef@reader2.news.tin.it> Message-ID: Tracubik: > i'm studying pygtk right now, am i wasting my time considering that my > preferred platform is linux/gnome? I expect the dynamic binding will be very similar to the current static binding but easier to keep up-to-date. There's already some use of dynamic binding in the recent PyGTK 2.22.0: http://www.daa.com.au/pipermail/pygtk/2010-September/019013.html Neil From joel.hedlund at gmail.com Thu Sep 30 08:48:59 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 05:48:59 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> Message-ID: <165a3586-8d0c-4d4e-930f-b8de8a62eb54@w19g2000yqb.googlegroups.com> I guess the moral of the story is don't always dist-upgrade. Reformat once in a while to remove old forgotten garbage. Clear the blood clots from your systems, so to say. From deets at web.de Thu Sep 30 08:54:39 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 30 Sep 2010 14:54:39 +0200 Subject: will Gnome 3.0 kill pygtk? References: <4ca4693d$0$40283$4fafbaef@reader2.news.tin.it> Message-ID: <87eicbo0hc.fsf@web.de> Tracubik writes: > Hi! > It seem that the new version of gnome 3.0 will dismiss pygtk support. > > link: > > [1] http://live.gnome.org/TwoPointNinetyone/ (search killing pygtk) > > [2] http://live.gnome.org/GnomeGoals/PythonIntrospectionPorting > > > i'm studying pygtk right now, am i wasting my time considering that my > preferred platform is linux/gnome? The important bit is that it will not ditch Python-support. I can't comment at the actual differences between pygtk and the upcoming reflection-based approach, but I doubt learning pygtk now is a waste. First of all, it will be quite a while until pygtk (and gnome 2.x) are really gone. And even if, the concepts stay the same, so unless pygtk adds an extra layer of abstraction (which AFAIK it doesn't), your knownledge is still usable - if not translatable one-to-one. Diez From wizzardx at gmail.com Thu Sep 30 09:08:08 2010 From: wizzardx at gmail.com (David) Date: Thu, 30 Sep 2010 15:08:08 +0200 Subject: Python becoming orphaned over ssh In-Reply-To: <4ca36e44$0$1584$742ec2ed@news.sonic.net> References: <4ca36e44$0$1584$742ec2ed@news.sonic.net> Message-ID: On Wed, Sep 29, 2010 at 6:49 PM, John Nagle wrote: > ? Python's signal handling for multithread and multiprocess programs > leaves something to be desired. > Thanks for the confirmation (that I'm not missing something obvious). I've reported a bug for this behavior in the Python issue tracker. In the meanwhile, I've made a workaround function called "check_call_and_monitor_ppids", that behaves like subprocess.check_call, except that it regularly checks if the parent pid "chain" (up to init process) changes during execution, and then terminates the subprocess and raises an exception. Actually I tried this before, and it didn't work. But strangely, it seems to work fine so long as I don't try to print any warning messages to stderr or stdout from the Python script (though, the called tool itself may print to stdout or stderr without problems). Quite peculiar... Anyway, I hope that one of the Python developers will fix this sometime. David. From solipsis at pitrou.net Thu Sep 30 09:08:56 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 30 Sep 2010 15:08:56 +0200 Subject: PyCObject & malloc creating memory leak In-Reply-To: <4bf06438-5c31-4809-89bb-c335289fffe9@a15g2000yqm.googlegroups.com> References: <96ac8c12-064c-4989-85bc-6b49850a30fc@t20g2000yqa.googlegroups.com> <4bf06438-5c31-4809-89bb-c335289fffe9@a15g2000yqm.googlegroups.com> Message-ID: <20100930150856.34fc1599@pitrou.net> On Thu, 30 Sep 2010 04:06:03 -0700 (PDT) Tom Conneely wrote: > Thanks for your reply, you've given me plenty to think about > > On Sep 29, 11:51?pm, Antoine Pitrou wrote: > > > > > My original plan was to have the data processing and data acquisition > > > functions running in separate processes, with a multiprocessing.Queue > > > for passing the raw data packets. The raw data is read in as a char*, > > > with a non constant length, hence I have allocated memory using > > > PyMem_Malloc and I am returning from the acquisition function a > > > PyCObject containing a pointer to this char* buffer, along with a > > > destructor. > > > > That sounds overkill, and I also wonder how you plan to pass that > > object in a multiprocessing Queue (which relies on objects being > > pickleable). Why don't you simply create a PyString object instead? > > Could you elaborate on why you feel this is overkill? Also, your right > about > passing the PyCObjects through a Queue, something which I hadn't > really > considered, so I've switched to using python strings as you > suggested, > an overhead I hoped to avoid but you can't win them all I suppose. Well, there should be no overhead. Actually, a string should be cheaper since: - the string contents are allocated inline with the PyObject header - while your PyCObject contents were allocated separately (two allocations rather than one) Regards Antoine. From bruce at futurewavedesigns.com Thu Sep 30 09:13:59 2010 From: bruce at futurewavedesigns.com (Bruce W.) Date: Thu, 30 Sep 2010 09:13:59 -0400 Subject: Clarification of notation In-Reply-To: References: <4CA3F6AD.3020603@futurewavedesigns.com> Message-ID: <4CA48D17.1030609@futurewavedesigns.com> So, this kind of notation would be different: args[0][2] verses args[[0][2]] the latter is multidimensional. Can you think of example of using this type of list? I don't know why this had me a bit confused. I've got to get into programming more... I had done more in the past. Bruce Chriebert wrote: > On Wed, Sep 29, 2010 at 7:32 PM, Bruce Whealton > wrote: > >> Hello all, >> I recently started learning python. I am a bit thrown by a certain >> notation that I see. I was watching a training course on lynda.com and this >> notation was not presented. For lists, when would you use what appears to >> be nested lists, like: >> [[], [], []] >> a list of lists? >> > > Lists are for working with a group of data. Sometimes each datum > happens to itself be a list; thus, one naturally ends up with a > list-of-lists. > > Say I have, for each school in my school district, a list of its > students' test scores. I want to compute each school's average score. > So I put all the lists of scores into a nested list. I then iterate > over the nested list, taking the average of each inner list of scores. > (Do the analogous thing at higher and higher levels of aggregation > (e.g. county, state, country) and you naturally get progressively more > nested lists.) > > >> Would you, and could you combine a dictionary with a list in this fashion? >> > > Yes, of course: > {'a' : [1,2,3]} > [{'a' : 1}, {'b' : 2}] > > Just note that lists can't be dictionary keys due to their mutability. > {[1,2,3] : "one two three"} # ERROR > > >> Next, from the documentation I see and this is just an example (this kind of >> notation is seen elsewhere in the documentation: >> >> str.count(sub[, start[, end]]) >> This particular example is from the string methods. >> > > >> I know that it would >> suggest that some of the arguments are optional, so perhaps if there are 2 >> items the first is the sub, and the second is start? Or did I read that >> backwards? >> > > No, you read it exactly correctly. The []s here indicate levels of > optional-ness and have nothing to do with the list datatype. > > Basically, if you want to pass an optional argument, you have to have > also specified any less-nested arguments (unless you use keyword > rather than positional arguments). > str.count(a) # sub = a > str.count(a, b) # sub = a, start = b > str.count(a, b, c) # sub = a, start = b, end = c > > Usually, it's straightforward left-to-right as you specify more > arguments (doing otherwise requires kludges or black magic). However, > there are rare exceptions, the most common one being range()/xrange(): > > range(...) > range([start,] stop[, step]) -> list of integers > > Thus: > range(a) # stop = a (*not* start = a, as would be normal) > range(a, b) # start = a, stop = b > range(a, b, c) # start = a, stop = b, step = c > > Cheers, > Chris > -- > http://blog.rebertia.com > > From pjb at invitado-174.medicalis.es Thu Sep 30 09:14:36 2010 From: pjb at invitado-174.medicalis.es (Pascal Bourguignon) Date: Thu, 30 Sep 2010 15:14:36 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: TheFlyingDutchman writes: > In this example RG is passing a long literal greater than INT_MAX to a > function that takes an int and the compiler apparently didn't give a > warning about the change in value as it created the cast to an int, > even with the option -Wall (all warnings). I think it's legitmate to > consider that an option for a warning/error on this condition should > be available. As far the compiler generating code that checks for a > change in value at runtime when a number is cast to a smaller data > type, I think that's also a legitimate request for a C compiler option > (in addition to other runtime check options like array subscript out > of bounds). I think that it's a legitimate request, in this age and day, for a C programmer to require that it be NOT an option to a C compiler not to give any error for this and similar cases. (And we should just kill all the programs that don't pass this check, which I'm afraid would be a big number, which I understand, is the reason why C compilers don't change). -- __Pascal Bourguignon__ http://www.informatimago.com From eric.brunel at pragmadev.nospam.com Thu Sep 30 09:30:29 2010 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Thu, 30 Sep 2010 15:30:29 +0200 Subject: PyRTF object model References: Message-ID: In article , Rustom Mody wrote: > I am trying to use PyRTF. > > I gather that an RTF doc consists of a list of sections, a section > consists of a list of paras, > paras seem to be just text (not sure on that one) They also include a style, not only text. > Some questions: > > When does one end one section and start another? You don't 'end a section. You just create a new one and append it to your document's sections: my_document = PyRTF.Document() my_section1 = PyRTF.Section() my_document.Sections.append(my_section1) my_section2 = PyRTF.Section() my_document.Sections.append(my_section2) > How does one handle lists (as in numbered, bulleted etc)? Not sure on this one. I've had to do it, but could handle it via regular paragraph style properties and insert the bullets or numbers explicitely, so I did it just like that. For example, your can create a PyRTF.ParagraphPropertySet with the options left_indent to 1133 twips = 2cm, first_line_indent to -567 twips = -1cm and set a tab at 1cm with the option: tabs=[PyRTF.TabPropertySet(width=567)] Then you create a PyRTF.ParagraphStyle using this PyRTF.ParagraphPropertySet and pass it as the first argument when you create your PyRTF.Paragraph. Then, you just insert tour bullet or number in the paragraph explicitely, followed by a tab. There might be a better way to do it. BTW, as you might have noticed, the documentation for PyRTF is quite minimal to say the least, so the only way to figure out what can be done is by reading the PyRTF source code? HTH -Eric - From namekuseijin at gmail.com Thu Sep 30 09:32:32 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Thu, 30 Sep 2010 06:32:32 -0700 (PDT) Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> <6784f34c-2948-408b-b2eb-4a3b171c5afe@k10g2000yqa.googlegroups.com> Message-ID: On 30 set, 09:35, namekuseijin wrote: > On 29 set, 11:04, w_a_x_man wrote: > > > > > On Sep 26, 9:24?am, p... at informatimago.com (Pascal J. Bourguignon) > > wrote: > > > > Xah Lee writes: > > > > here's a interesting toy list processing problem. > > > > > I have a list of lists, where each sublist is labelled by > > > > a number. I need to collect together the contents of all sublists > > > > sharing > > > > the same label. So if I have the list > > > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > > > > r) (5 s t)) > > > > > where the first element of each sublist is the label, I need to > > > > produce: > > > > > output: > > > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > > > a Mathematica solution is here: > > > >http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > > > > R5RS Scheme lisp solution: > > > >http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_... > > > > by Sourav Mukherjee > > > > > also, a Common Lisp solution can be found here: > > > >http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1de... > > > > It's too complex. Just write: > > > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > > > ? ? ? ? ? ? ? (2 o p) (4 q r) (5 s t)))) > > > > ? (mapcar (lambda (class) (reduce (function append) class :key (function rest))) > > > ? ? ? ? ? ?(com.informatimago.common-lisp.list:equivalence-classes list :key (function first))) > > > > ? ?) > > > > --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) > > > > -- > > > __Pascal Bourguignon__ ? ? ? ? ? ? ? ? ? ?http://www.informatimago.com/ > > > Ruby: > > > [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, > > 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], > > [5, 's', 't']]. > > group_by{|x| x.first}.values.map{|x| x.map{|y| y[1..-1]}.flatten} > > > ? ? ==>[["s", "t"], ["a", "b"], ["c", "d", "i", "j"], > > ?["e", "f", "k", "l", "o", "p"], > > ?["g", "h"], ["m", "n", "q", "r"]] > > cool, it comes with order all fucked up. ?This is something I was > criticized for before, though not all that important to most > functional processing. ?Not the case here, though. > > here's a scheme version that is hopefully better than the given one: (define (dig in) ? (if (null? in) '() ? ? (let* ((n ? ? ? ? (first-of-first in)) ? ? ? ? ? ?(all-n ? ? (filter in (lambda (x) ? ? ?(eq? n (first x))))) ? ? ? ? ? ?(all-but-n (filter in (lambda (x) (not (eq? n (first x))))))) ? ? ? ?(pair ? ? ? ? ? (fold all-n ? ? ? ? ? ? ?(lambda (i o) (pair (second i) (pair (third i) o)))) ? ? ? ? ? (dig all-but-n))))) ; given these aliases to lisp n00bs (define pair cons) (define first car) (define rest cdr) (define first-of-first caar) (define second cadr) (define third caddr) ; and these well-known functions?(non-tail-recursive for benefit of n00bs) (define (fold ls f) ; AKA reduce ? (if (null? ls) '() ? ? ? (f (first ls) (fold (rest ls) f)))) (define (filter ls f) ? (fold ls (lambda (i o) (if (f i) (pair i o) o)))) ; testing (let ((in '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) ? ? ? ? ? ? (2 o p) (4 q r) (5 s t)))) ? (display (dig in)) ? (newline)) ;frakkin text editor... From __peter__ at web.de Thu Sep 30 09:40:33 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 15:40:33 +0200 Subject: gedit 'External Tools' plugin hashlib weirdness References: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> Message-ID: Joel Hedlund wrote: > FOUND IT! Heureka! > I added the line > > print >> f, '\n'.join(sorted(sys.path)) > > and diff:ed the files produced from terminal/launcher. > > When using the launcher, changes to PYTHONPATH done in ~/.bashrc are > not picked up, and I apparently had an old reference to /usr/lib/ > python2.4 sitting in there. Removed it, reloaded .bashrc, plugin now > works. I'm surprised that /usr/lib/python2.4 doesn't appear in the traceback. > The question still remains why gnome disregards ~/.bashrc, but that's > a whole other topic. Thanks a bunch, you guys are ever so helpful. I think the breakage you've experienced could be the answer. Peter From pjb at invitado-174.medicalis.es Thu Sep 30 09:57:58 2010 From: pjb at invitado-174.medicalis.es (Pascal Bourguignon) Date: Thu, 30 Sep 2010 15:57:58 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> Message-ID: Nick Keighley writes: > On 27 Sep, 20:29, p... at informatimago.com (Pascal J. Bourguignon) > wrote: >> If you start with the mindset of static type checking, you will consider >> that your types are checked and if the types at the interface of two >> modules matches you'll think that everything's ok. ?And six months later >> you Mars mission will crash. > > do you have any evidence that this is actually so? That people who > program in statically typed languages actually are prone to this "well > it compiles so it must be right" attitude? Yes, I can witness that it's in the mind set. Well, the problem being always the same, the time pressures coming from the sales people (who can sell products of which the first line of specifications has not been written yet, much less of code), it's always a battle to explain that once the code is written, there is still a lot of time needed to run tests and debug it. I've even technical managers, who should know better, expecting that we write bug-free code in the first place (when we didn't even have a specification to begin with!). >> On the other hand, with the dynamic typing mindset, you might even wrap >> your values (of whatever numerical type) in a symbolic expression >> mentionning the unit and perhaps other meta data, so that when the other >> module receives it, it may notice (dynamically) that two values are not >> of the same unit, but if compatible, it could (dynamically) convert into >> the expected unit. ?Mission saved! > > they *may* do this but do they *actually* do it? My (limited) > experience of dynamically typed languges is everynow and again you > attempt to apply an operator to the wrong type of operand and kerblam! > If your testing is inadaquate then it's inadaquate whatever the > typiness of your language. Unfortunately, a lot of programmers in dynamic programming languages have been formed with static programming languages bring with them their old mindset. Moreover, when the syntax of the newer dynamic programming languages is explicitely designed similar to an older static programming language, in order to attract these programmers toward the better technologies, this does not help changing the mindset either. Unfortunately, you can write FORTRAN code in any programming language. But my point is that at least with dynamic programming languages, there's an alternative mindset and it is easier to implement such a scheme than with static programming languages. In Lisp, which stresses the symbolic computing part (S-expr are Symbolic Expressions), it is almost trivial to implement. -- __Pascal Bourguignon__ http://www.informatimago.com From exarkun at twistedmatrix.com Thu Sep 30 10:01:09 2010 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Thu, 30 Sep 2010 07:01:09 -0700 (PDT) Subject: Python becoming orphaned over ssh References: <4ca36e44$0$1584$742ec2ed@news.sonic.net> Message-ID: <91cdb1f0-5db1-4566-9899-386a7f06104d@y31g2000vbt.googlegroups.com> On Sep 30, 9:08?am, David wrote: > On Wed, Sep 29, 2010 at 6:49 PM, John Nagle wrote: > > ? Python's signal handling for multithread and multiprocess programs > > leaves something to be desired. > > Thanks for the confirmation (that I'm not missing something obvious). > > I've reported a bug for this behavior in the Python issue tracker. > > In the meanwhile, I've made a workaround function called > "check_call_and_monitor_ppids", that behaves like > subprocess.check_call, except that it regularly checks if the parent > pid "chain" (up to init process) changes during execution, and then > terminates the subprocess and raises an exception. > > Actually I tried this before, and it didn't work. But strangely, it > seems to work fine so long as I don't try to print any warning > messages to stderr or stdout from the Python script (though, the > called tool itself may print to stdout or stderr without problems). > Quite peculiar... > > Anyway, I hope that one of the Python developers will fix this sometime. > > David. Python ignores SIGPIPE by default. The default SIGPIPE behavior is to exit. This is sort of what people on POSIX expect. If you're talking to another process over a pipe and that process goes away, and then you write to the pipe, you get a SIGPIPE and you exit (of course, if it takes you 20 minutes before you do another write, then it's 20 minutes before you exit). But with SIGPIPE ignored, a Python process won't do exactly this. Instead, you'll get an exception from the write. If you don't handle the exception, then it'll propagate to the top-level and you'll exit. Just like with a "normal" process. Except you also get the option to doing something other than exiting. Pretty nice. But signal dispositions are inherited by child processes. So you run ping from your short Python program, and it inherits SIGPIPE being ignored. And it's written in C, not Python, so when it writes to the pipe, there's no exception. So ping never gets any indication that it should exit. No Python writes ever happen in this scenario. The SSH supplied stdout is shared with the ping process, which writes to it directly. You can fix this by resetting the signal disposition of SIGPIPE for the ping process: #!/usr/bin/python import signal def reset(): signal.signal(signal.SIGPIPE, signal.SIG_DFL) from subprocess import check_call check_call(['ping', 'www.google.com'], preexec_fn=reset) Very likely the subprocess module should be resetting the disposition of signals that Python itself has fiddled with (and resetting any other unusual state that the child is going to inherit, but nothing else comes immediately to mind). From emile at fenx.com Thu Sep 30 10:02:40 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 Sep 2010 07:02:40 -0700 Subject: sequence multiplied by -1 In-Reply-To: <20100930121043.GD2272@rcpc42.vub.ac.be> References: <299735.67644.qm@web54205.mail.re2.yahoo.com> <4c9ed575$0$1644$742ec2ed@news.sonic.net> <4c9ee7b3$0$28659$c3e8da3@news.astraweb.com> <7xd3s1knmm.fsf@ruckus.brouhaha.com> <4c9efccb$0$28659$c3e8da3@news.astraweb.com> <7x4odcc426.fsf@ruckus.brouhaha.com> <20100930121043.GD2272@rcpc42.vub.ac.be> Message-ID: On 9/30/2010 5:10 AM Antoon Pardon said... > On Sun, Sep 26, 2010 at 03:20:18PM +0000, Grant Edwards wrote: >> On 2010-09-26, Paul Rubin wrote: >>> Steven D'Aprano writes: >>>> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", >> >>> Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? >> >> Because >> >> 3 * "spam" == "spam" + "spam" + "spam" >> >> Just like >> >> 3 * 6 = 6 + 6 + 6 >> >> So now I suppose "+" for string concatenation is a bad thing. > > Well I find it an unfortunate choice. The problem is, that it is not that > unusual to want some class to have the possibility of both addition and > concatenation. But since we only one symbol for both operations, you will > have to loose some consistency over this. > Which is actually a good thing for a class that wants to have both concatenation and addition -- which would it do with only one symbol? Emile From emile at fenx.com Thu Sep 30 10:05:06 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 30 Sep 2010 07:05:06 -0700 Subject: if the else short form In-Reply-To: <1xZoo.1781$Fk6.1722@newsfe13.ams2> References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> <20100929114701.110c18b5@geekmail.INVALID> <1xZoo.1781$Fk6.1722@newsfe13.ams2> Message-ID: On 9/30/2010 3:21 AM Sion Arrowsmith said... > Andreas Waldenburger wrote: >> >> [ ... ] >> Boolean values behave like the values 0 and 1, respectively, in >> almost all contexts, the exception being that when converted to a >> string, the strings "False" or "True" are returned, respectively. > > Hmm. So the original problem of: > > button = gtk.Button(("False,", "True,")[fill==True]) > > could also rewritten as: > > button = gtk.Button(str(bool(fill))+",") > I think I'd prefer button = gtk.Button("%s," % bool(fill)) Emile From exarkun at twistedmatrix.com Thu Sep 30 10:14:42 2010 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Thu, 30 Sep 2010 07:14:42 -0700 (PDT) Subject: Determine sockets in use by python References: <4CA37FDA.3080605@digipen.edu> Message-ID: On Sep 29, 4:08?pm, Jim Mellander wrote: > > On Wed, Sep 29, 2010 at 11:05 AM, Gary Herron wrote: > > On 09/29/2010 09:50 AM, Jim Mellander wrote: > > >> Hi: > > >> I'm a newbie to python, although not to programming. ?Briefly, I am > >> using a binding to an external library used for communication in a > >> client-server context, with the server in python. ?Typically, I would > >> set this up with event callbacks, and then enter a select loop, which, > >> most the time idles and processes input events when the socket shows > >> activity, kinda like: > > >> while True: > >> ? ? socket.select((my_socket),(),()) > >> ? ? process_event() > > >> Unfortunately, the API does not expose the socket to the script level, > >> and the developer recommends a busy loop: > > >> while True: > >> ? ? sleep(1) > >> ? ? process_event() > > >> which I hope to avoid, for many reasons. ?If the socket can be exposed > >> to the script level, then the problem would be solved. > > >> Failing that, it would be nice to be able to pythonically determine > >> the sockets in use and select on those. ?Does anyone have any > >> suggestions on how to proceed? > > >> Thanks in advance > > > It's certain that any answer to this will depend on which operating system > > you are using. ?So do tell: What OS? > > Hi Gary: > > Certainly not windows.... ?I'm developing on OS/X but for production > probably Linux and FreeBSD > > (I'm hoping for something a bit more portable than running 'lsof' and > parsing the output, but appreciate any/all advice) > Linux has /proc/self/fd and OS X has /dev/fd. Those both suppose you have some way of determining which file descriptor corresponds to the socket or sockets that the library is using, of course. Vastly better would be to convince the author to expose that information via a real API. Jean-Paul From brandon.harris at reelfx.com Thu Sep 30 10:21:16 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Thu, 30 Sep 2010 09:21:16 -0500 Subject: eval string Message-ID: <4CA49CDC.7010609@reelfx.com> Needing to pass a string command into a third party program and having issues creating a string to do what I need. here's what I have so far. eval('import sys; sys.stderr.write(\'\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n\');') Traceback (most recent call last): File "", line 1, in File "", line 1 sys.stderr.write(' ^ SyntaxError: EOL while scanning string literal so I've changed it up every way I can think and I get other errors. eval('import sys; sys.stderr.write("\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n");') Traceback (most recent call last): File "", line 1, in File "", line 1 import sys; sys.stderr.write(" ^ SyntaxError: invalid syntax Brandon L. Harris From zzbbaadd at aol.com Thu Sep 30 10:24:39 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Thu, 30 Sep 2010 07:24:39 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: > > > If I had to choose between "blow up" or "invalid answer" I would pick > > "invalid answer". > > there are some application domains where neither option would be > viewed as a satisfactory error handling strategy. Fly-by-wire, petro- > chemicals, nuclear power generation. Hell you'd expect better than > this from your phone! > I wasn't speaking generally, just in the case of which of only two choices RG's code should be referred to - "blowing up" or "giving an invalid answer". I think error handling in personal computer and website software has improved over the years but there is still some room for improvement as you will still get error messages that don't tell you something you can relay to tech support more than that an error occurred or that some operation can't be performed. But I worked with programmers doing in-house software who were incredibly turned off by exception handling in C++. I thought that meant that they preferred to return and check error codes from functions as they had done in C, and for some of them it did seem to mean that. But for others it seemed that they didn't want to anticipate errors at all ("that file is always gonna be there!"). I read a Java book by Deitel and Deitel and they pointed out what might have lead to that attitude - the homework and test solutions in college usually didn't require much if any error handling - the student could assume files were present, data was all there and in the format expected, user input was valid and complete, etc. From davea at ieee.org Thu Sep 30 10:37:33 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 30 Sep 2010 10:37:33 -0400 Subject: Clarification of notation In-Reply-To: <4CA48D17.1030609@futurewavedesigns.com> References: <4CA3F6AD.3020603@futurewavedesigns.com> <4CA48D17.1030609@futurewavedesigns.com> Message-ID: <4CA4A0AD.2060103@ieee.org> On 2:59 PM, Bruce W. wrote: > So, this kind of notation would be different: > args[0][2] > verses args[[0][2]] > the latter is multidimensional. Can you think of example of using > this type of list? > I don't know why this had me a bit confused. I've got to get into > programming more... I had done more in the past. > Bruce > > The data in a multidimensional list (list of lists) would look like: [ [3,5], [4,2,99] ] But a reference to it would be args[1][2] DaveA From __peter__ at web.de Thu Sep 30 10:46:11 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 16:46:11 +0200 Subject: eval string References: Message-ID: Brandon Harris wrote: > Needing to pass a string command into a third party program and having > issues creating a string to do what I need. > > here's what I have so far. > > eval('import sys; > sys.stderr.write(\'\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!! \nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n\');') > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > sys.stderr.write(' > ^ > SyntaxError: EOL while scanning string literal > > > so I've changed it up every way I can think and I get other errors. > > eval('import sys; > sys.stderr.write("\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!! \nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n");') > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > import sys; sys.stderr.write(" > ^ > SyntaxError: invalid syntax > > > Brandon L. Harris Python discriminates between statements and expressions. eval() can only deal with expressions, but 'import whatever' is a statement. Try exec 'import sys\nsys.stderr.write("completed!\n")' instead. From thomas at jollybox.de Thu Sep 30 10:50:02 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 30 Sep 2010 16:50:02 +0200 Subject: eval string In-Reply-To: <4CA49CDC.7010609@reelfx.com> References: <4CA49CDC.7010609@reelfx.com> Message-ID: <201009301650.03412.thomas@jollybox.de> On Thursday 30 September 2010, it occurred to Brandon Harris to exclaim: > Needing to pass a string command into a third party program and having > issues creating a string to do what I need. > > here's what I have so far. > > eval('import sys; > sys.stderr.write(\'\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nComplete > d!!!\nCompleted!!!\nCompleted!!!\n\n\n\');') > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > sys.stderr.write(' Neither ' nor " can delimit a multiline string literal. You need triplets. > ^ > SyntaxError: EOL while scanning string literal > > > so I've changed it up every way I can think and I get other errors. > > eval('import sys; > sys.stderr.write("\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted > !!!\nCompleted!!!\nCompleted!!!\n\n\n");') > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 > import sys; sys.stderr.write(" > ^ > SyntaxError: invalid syntax > > > Brandon L. Harris From nick_keighley_nospam at hotmail.com Thu Sep 30 11:02:29 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 30 Sep 2010 08:02:29 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: <04f34901-8978-4b94-9ff6-40295de6084d@d25g2000yqc.googlegroups.com> On 30 Sep, 15:24, TheFlyingDutchman wrote: > > > If I had to choose between "blow up" or "invalid answer" I would pick > > > "invalid answer". > > > there are some application domains where neither option would be > > viewed as a satisfactory error handling strategy. Fly-by-wire, petro- > > chemicals, nuclear power generation. Hell you'd expect better than > > this from your phone! > > I wasn't speaking generally, just in the case of which of only two > choices RG's code should be referred to - "blowing up" or "giving an > invalid answer". I think I'd prefer termination if those were my only choices. What's the rest of the program going to do with the wrong result? When the program finally gives up the cause is lost in the mists of time, and those are hard to debug! > I think error handling in personal computer and website software has > improved over the years but there is still some room for improvement > as you will still get error messages that don't tell you something you > can relay to tech support more than that an error occurred or that > some operation can't be performed. > > But I worked with programmers doing in-house software who were > incredibly turned off by exception handling in C++. I thought that > meant that they preferred to return and check error codes from > functions as they had done in C, and for some of them it did seem to > mean that. But for others it seemed that they didn't want to > anticipate errors at all ("that file is always gonna be there!"). that was one of the reasons I liked exceptions. If my library threw an exception then the caller *had* to do something about it. Even to ignore it he had to write some code. > I > read a Java book by Deitel and Deitel and they pointed out what might > have lead to that attitude - the homework and test solutions in > college usually didn't require much if any error handling - the > student could assume files were present, data was all there and in the > format expected, user input was valid and complete, etc. plausible. Going from beginner to I probably steadily increased the pessimism of my code. The file might not be there. That other team might send us syntactically invalid commands. Even if it can't go wrong it will go wrong. Fortunately my collage stuff included some OS kernal stuff. There anything that can go wrong will go wrong. From __peter__ at web.de Thu Sep 30 11:09:21 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Sep 2010 17:09:21 +0200 Subject: eval string References: Message-ID: Peter Otten wrote: > exec 'import sys\nsys.stderr.write("completed!\n")' Oops, you need to escape the backslashes for newlines inside quotes inside quotes: >>> exec 'import sys\nsys.stderr.write("completed!\\n")' completed! Peter From tfb at tfeb.org Thu Sep 30 11:13:43 2010 From: tfb at tfeb.org (Tim Bradshaw) Date: Thu, 30 Sep 2010 16:13:43 +0100 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: On 2010-09-30 13:36:17 +0100, Nick Keighley said: > there are some application domains where neither option would be > viewed as a satisfactory error handling strategy. Fly-by-wire, petro- > chemicals, nuclear power generation. Hell you'd expect better than > this from your phone! People always give these kind of scenarios, but actually there are far more mundane ones. In my day job I'm a sysadmin and I spend a bunch of time writing code (typically what would nowadays be called "scripts" rather than programs, but there's no real difference) which does things of the form for every machine in do where is fairly often "modify critical system configuration file". Programs like that have some absolute, non-negotiable requirements: - they must never fail silently; - they must check everything they do however unlikely it seems that it would failm because they will come across systems which have almost arbitrary misconfiguration. - they should be idempotent if possible; - if they come across something odd they either need to handle it, or put things back the way they were and back out; - if they absolutely can not put things back, they need to report this very clearly and carefully preserve any detriitus in such a way that a human can pick up the bits; - whatever they do they need to report in a completely parsable way what happened (success, failure, already done, backed out, not backed out, and so on). These are quite mundane everyday things, but the consequences of getting them wrong can be quite nasty (the worst ones being "the machines will still run, but won't boot"). From drobinow at gmail.com Thu Sep 30 11:16:31 2010 From: drobinow at gmail.com (David Robinow) Date: Thu, 30 Sep 2010 11:16:31 -0400 Subject: PyRTF object model In-Reply-To: References: Message-ID: On Thu, Sep 30, 2010 at 8:14 AM, Rustom Mody wrote: > I am trying to use PyRTF. > > I gather that an RTF doc consists of a list of sections, a section > consists of a list of paras, > paras seem to be just text (not sure on that one) > > Some questions: > > When does one end one section and start another? > How does one handle lists (as in numbered, bulleted etc)? You might find the RTF specification helpful. One source is: http://msdn.microsoft.com/en-us/library/aa140277%28office.10%29.aspx From kst-u at mib.org Thu Sep 30 11:26:38 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 08:26:38 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: RG writes: [...] > You can't have it both ways. Either I am calling it incorrectly, in > which case I should get a compiler error, or I am calling it correctly, > and I should get the right answer. That I got neither does in fact > falsify the claim. The only way out of this is to say that > maximum(8589934592, 1) returning 1 is in fact "correct", in which case > we'll just have to agree to disagree. You are calling maximum() incorrectly, but you are doing so in a way that the compiler is not required to diagnose. If you want to say that the fact that the compiler is not required to diagnose the error is a flaw in the C language, I won't argue with you. It's just not a flaw in the maximum() function. If I write: const double pi = 22.0/7.0; printf("pi = %f\n", pi); then I suppose I'm calling printf() incorrectly, but I wouldn't expect my compiler to warn me about it. If you're arguing that int maximum(int a, int b) { return a > b ? a : b; } is flawed because it's too easy to call it incorrectly, you're effectively arguing that it's not possible to write correct code in C at all. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From hidura at gmail.com Thu Sep 30 11:33:01 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 30 Sep 2010 15:33:01 +0000 Subject: Problems with wsgi Python3 Message-ID: <0016362840cc20212c04917bcb34@google.com> Hello list, i had seriously troubles with the connection between a form and the wsgi, i' ve made an application on Python3 and was running perfectly but when i try to use the to pass the data this can't be see on the server, so what is your recommendation?, i am open to all the ideas less leave to Python2 i can't all the project was write on Python3, i was looking into the PEP 444 proposal too. Here is the code what i used to take the data: print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])).decode())) and here it's what the os.environ.item() prints to me: ('LESSOPEN', '|/usr/bin/lesspipe.sh %s') ('SSH_CLIENT', '190.94.122.180 38415 22') ('CVS_RSH', 'ssh') ('LOGNAME', 'hidura') ('INPUTRC', '/etc/inputrc') ('HOME', '/home/hidura') ('PATH', '/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/dell/srvadmin/bin:/home/hidura/bin') ('LD_LIBRARY_PATH', '/home/hidura/webapps/karinapp/apache2/lib') ('LANG', 'en_US.UTF-8') ('TERM', 'xterm') ('SHELL', '/bin/bash') ('SHLVL', '3') ('G_BROKEN_FILENAMES', '1') ('HISTSIZE', '1000') ('_', '/home/hidura/webapps/karinapp/apache2/bin/httpd.worker') ('SSH_CONNECTION', '190.94.122.180 38415 174.121.79.178 22') ('SSH_TTY', '/dev/pts/5') ('HOSTNAME', 'web152.webfaction.com') ('PWD', '/home/hidura') ('MAIL', '/var/spool/mail/hidura') ('LS_COLORS', 'no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:') -----------------------------110550484811701713451664404475--\r Thanks, i am desperate. -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Thu Sep 30 11:54:48 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 15:54:48 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, Lie Ryan wrote: > On 09/30/10 16:09, TheFlyingDutchman wrote: >> Dynamic typed languages like Python fail in this case on "Never blows >> up". > How do you define "Never blows up"? I would say "blow up" would be "raise an exception". > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > up, and of the worst kind since it passes silently. So run your compiler with a decent set of warning levels, and watch as you are magically warned that you're passing an object of the wrong type. On any given system, one or the other is true: 1. The constant 8589934592 is of type int, and the function will "work" -- will give that result. 2. The constant is not of type int, and the compiler will warn you about this if you ask. -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 deets at web.de Thu Sep 30 11:55:06 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 30 Sep 2010 17:55:06 +0200 Subject: Problems with wsgi Python3 References: Message-ID: <87aamzns4l.fsf@web.de> hidura at gmail.com writes: > Hello list, i had seriously troubles with the connection between a form and the > wsgi, i' ve made an application on Python3 and was running perfectly but when i > try to use the to pass the data this can't be see on the server, so what > is your recommendation?, i am open to all the ideas less leave to Python2 i > can't all the project was write on Python3, i was looking into the PEP 444 > proposal too. > > Here is the code what i used to take the data: > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(environ > ['CONTENT_LENGTH'])).decode())) What is the ouptut of this? What does import pprint pprint.pprint(environ) give you? > > and here it's what the os.environ.item() prints to me: That's irrelevant. The WSGI-environ is what is needed. Diez From usenet-nospam at seebs.net Thu Sep 30 11:55:48 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 15:55:48 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: On 2010-09-30, TheFlyingDutchman wrote: > even with the option -Wall (all warnings). For various historical reasons, "-Wall" has the semantics you might expect from an option named "-Wsome-common-warnings-but-not-others". -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 Sep 30 12:01:22 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:01:22 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: On 2010-09-30, RG wrote: > We lost some important context somewhere along the line: >> > > in C I can have a function maximum(int a, int b) that will always >> > > work. Never blow up, and never give an invalid answer. If someone >> > > tries to call it incorrectly it is a compile error. > Please take note of the second sentence. I did. That is entirely correct. > One way or another, this claim is plainly false. The point I was trying > to make is not so much that the claim is false (someone else was already > doing that), but that it can be demonstrated to be false without having > to rely on any run-time input. It is not at all obvious to me that it is, in fact, false. So far as I can tell, *if* the function is successfully called, then it will take two integers, compare them, and return the larger one. It will never return something which is not an integer. It will never raise an exception. It will never return a value which, if you try to treat it as an integer, raise an exception. Now, if you pass the wrong values to it, you will get wrong answers -- but that's your problem for passing it wrong values. I would understand an "invalid" answer to be one of the wrong category. For instance, if I have a function in Python that I expect to return a string, and it returns None, I have gotten an answer that is "invalid" -- it's not a string. -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 Sep 30 12:03:29 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:03:29 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: On 2010-09-30, Paul Rubin wrote: > int maximum(int a, int b); > > int foo() { > int (*barf)() = maximum; > return barf(3); > } > This compiles fine for me. Where is the cast? On the first line of code inside foo(). > Where is the error message? You chose to use a form that suppresses the error message. > Are you saying barf(3) doesn't call maximum? I would say that it is undefined whether or not it calls maximum, because you called a function through a function pointer of a different sort, which invoked undefined behavior. There exist real compiles on which code much like this will coredump without ever once trying to jump to the address of the maximum function, because the compiler caught your error. -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 Sep 30 12:04:35 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:04:35 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: On 2010-09-30, RG wrote: > You can't have it both ways. Either I am calling it incorrectly, in > which case I should get a compiler error, You get a warning if you ask for it. If you choose to run without all the type checking on, that's your 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 usenet-nospam at seebs.net Thu Sep 30 12:06:52 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:06:52 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> Message-ID: On 2010-09-30, Pascal Bourguignon wrote: > Nick Keighley writes: >> do you have any evidence that this is actually so? That people who >> program in statically typed languages actually are prone to this "well >> it compiles so it must be right" attitude? > Yes, I can witness that it's in the mind set. Huh. So here I am, programming in statically typed languages, and I have never in my life thought that things which compiled were necessarily right. Not even when I was an arrogant teenager. I guess I don't exist. *sob* > Well, the problem being always the same, the time pressures coming from > the sales people (who can sell products of which the first line of > specifications has not been written yet, much less of code), it's always > a battle to explain that once the code is written, there is still a lot > of time needed to run tests and debug it. At $dayjob, they give us months between feature complete and shipping, because they expect us to spend a lot of time testing, debugging, and cleaning up. But during that time we are explicitly not adding features... > But my point is that at least with dynamic programming languages, > there's an alternative mindset and it is easier to implement such > a scheme than with static programming languages. I think this grossly oversimplifies 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 rNOSPAMon at flownet.com Thu Sep 30 12:10:05 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 09:10:05 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: In article , Keith Thompson wrote: > RG writes: > [...] > > You can't have it both ways. Either I am calling it incorrectly, in > > which case I should get a compiler error, or I am calling it correctly, > > and I should get the right answer. That I got neither does in fact > > falsify the claim. The only way out of this is to say that > > maximum(8589934592, 1) returning 1 is in fact "correct", in which case > > we'll just have to agree to disagree. > > You are calling maximum() incorrectly, but you are doing so in a way > that the compiler is not required to diagnose. Yes. I know. That was my whole point. There are ways to call a function incorrectly (more broadly, there are errors in code) that a C compiler is not required to diagnose. > If you want to say that the fact that the compiler is not required > to diagnose the error is a flaw in the C language, I won't > argue with you. I'm not even saying it's a flaw in the language. All I'm saying is that the original claim -- that any error in a C program will be caught by the compiler -- is false, and more specifically, that it can be demonstrated to be false without appeal to unknown run-time input. As an aside, this particular error *could* be caught (and in fact would be caught by other tools like lint), but there are errors that can not be caught by any static analysis, and that therefore one should not be lulled into a false sense of security by the fact that your code is written in a statically typed language and compiled without errors or warnings. That's all. > If I write: > > const double pi = 22.0/7.0; > printf("pi = %f\n", pi); > > then I suppose I'm calling printf() incorrectly, but I wouldn't > expect my compiler to warn me about it. > > If you're arguing that > > int maximum(int a, int b) { return a > b ? a : b; } > > is flawed because it's too easy to call it incorrectly, you're > effectively arguing that it's not possible to write correct > code in C at all. I would say that it is very, very hard to write correct code in C for any non-vacuous definition of "correct". That is the reason that core dumps and buffer overflows are so ubiquitous. I prefer Lisp or Python, where core dumps and buffer overflows are virtually nonexistent. One does get the occasional run-time error that might have been caught at compile time, but I much prefer that to a core dump or a security hole. One might hypothesize that the best of both worlds would be a dynamic language with a static analyzer layered on top. Such a thing does not exist. It makes an instructive exercise to try to figure out why. (For the record, I don't know the answer, but I've learned a lot through the process of pondering this conundrum.) rg From psilord at cs.wisc.edu Thu Sep 30 12:14:01 2010 From: psilord at cs.wisc.edu (Peter Keller) Date: Thu, 30 Sep 2010 16:14:01 +0000 (UTC) Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: In comp.lang.lisp TheFlyingDutchman wrote: > >> >> More specifically, the claim made above: >> >> > in C I can have a function maximum(int a, int b) that will always >> > work. Never blow up, and never give an invalid answer. >> >> is false. ?And it is not necessary to invoke the vagaries of run-time >> input to demonstrate that it is false. >> > I don't think you demonstrated it is false. Any values larger than an > int get truncated before they ever get to maximum. The problem does > not lie with the maximum function. It correctly returns the maximum of > whatever two integers it is provided. Calling it with values that are > larger than an int, that get converted to an int _before_ maximum is > called, is an issue outside of maximum. After thinking for a bit. I believe I can demonstrate a situation where indeed maximum could return the wrong answer and it isn't due to being passed incorrect input. If, in maximum, after the entrance to the function call but right before the comparison, a signal handler gets invoked, walks the stack, swaps the two values for a and b, and returns back into maximum. Then maximum will do the wrong thing. Since control flow was always in a subgraph of the control flow graph through maximum, this would classify as a failure given your strict view. (As an aside, one can do the same thing with a debugger.) Blocking the signals around the comparison and assignment of the result to a temporary variable that you will return won't fix it. This is because (in C) you must have a sequence point after the unblocking of the signals and before the assignment of a temporary variable holding the result to the return register, where, in fact, another signal could arrive and again corrupt the results. Depending upon the optimzation values of the compiler, it may or may not adjust the ordering semantics of the assignment to the return register in relation to the call to unblock the signals. The assignment of a result to a return register is not defined to be something in C, and can happen anywhere. But the C statements you used to write it must adhere to sequence evaluation. Since the signal handler could do anything, including completely replacing the text segments and/r loaded libraries of the code or move the PC to an arbitrary palce, I don't think you can "fix" this problem. Ever. If you think this is a pedantic case which never happens in practice, I'm the maintainer of a well-known user space checkpointing system where these types of problems have to be thought about deeply because they happen. In addition, there are other modes of error injection: in compute clusters with very high density memory that is not ECC, you can actually calculate the probability that a bit will flip at an address in memory due to cosmic rays. That probability is disturbingly high. Just an idle search online produced this article: http://news.cnet.com/8301-30685_3-10370026-264.html which mentions some statistics. Think 1 billion hours is a lot and "it'll never happen"? There are 8760 hours in a year. So, you'd only need 114,156 computers in a cluster running for one year before amassing 1 billion hours of computation. That isn't a big number for large financial companies, google, etc, etc, etc to own. As a fun statistic, the BlueGene/P supercomputer can have 884,736 processors with associated memory modules. According to the math in the article, one BlueGene/P should see a max of ~600,000 memory errors per year. Sure, you might not think any of this is a problem, because your home desktop always produces the right answer when balancing your checkbook, but it is a matter of perception of scale. Lots of large clusters and data movement houses go to great length to ensure data integrity. Injecting wrong data 4 hours into a 6 month long workflow running on thousands of computers really upsets the hell out of people. I've run into physicists who simply run their buggy software over and over and over again on the same data and do statistical analysis on the results. They've come to the realization that they can't find/fix/verify all the bugs in their code, so they assume they are there and write systems which try to be mathematically robust to the nature of the beast. It is cheaper to wait for 1000 runs of a program to be computed on a cluster than to spend human time debugging a difficult bug in the code. So, mathematically, maximum can't fail inside of itself, realistically while executing on a physical machine, you bet it'll fail. :) -pete From rNOSPAMon at flownet.com Thu Sep 30 12:32:08 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 09:32:08 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Seebs wrote: > On 2010-09-30, Lie Ryan wrote: > > On 09/30/10 16:09, TheFlyingDutchman wrote: > >> Dynamic typed languages like Python fail in this case on "Never blows > >> up". > > > How do you define "Never blows up"? > > I would say "blow up" would be "raise an exception". > > > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > > up, and of the worst kind since it passes silently. > > So run your compiler with a decent set of warning levels, and watch as > you are magically warned that you're passing an object of the wrong type. My code compiles with no warnings under gcc -Wall. > On any given system, one or the other is true: > > 1. The constant 8589934592 is of type int, and the function will > "work" -- will give that result. > 2. The constant is not of type int, and the compiler will warn you about > this if you ask. It would be nice if this were true, but my example clearly demonstrates that it is not. And if your response is to say that I should have used lint, then my response to that will be that because of the halting problem, for any static analyzer that you present, I can construct a program that either contains an error that either your analyzer will not catch, or for which it will generate a false positive. It just so happens that constructing such examples for standard C is very easy. rg From rNOSPAMon at flownet.com Thu Sep 30 12:36:22 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 09:36:22 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: In article , Seebs wrote: > On 2010-09-30, RG wrote: > > You can't have it both ways. Either I am calling it incorrectly, in > > which case I should get a compiler error, > > You get a warning if you ask for it. If you choose to run without all > the type checking on, that's your problem. My example compiles with no warnings under gcc -Wall. Yes, I know I could have used lint. But that misses the point. For any static analyzer, because of the halting problem, I can construct a program that either contains an error that the analyzer will not catch, or for which the analyzer will produce a false positive. rg From dsrtegle at gmail.com Thu Sep 30 12:38:05 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Thu, 30 Sep 2010 09:38:05 -0700 (PDT) Subject: Please help: pylint does not work with Emacs23 on Windows Message-ID: <66da9bf4-3c1c-4aad-96ef-0c9fee798e90@a4g2000prm.googlegroups.com> Hi, I am trying to use Pylint with Emacs on Windows XP. My Emacs version is EmacsW32 23.1, pylint is 0.21.3 with Python 2.5. After easy_install pylint, I added the code block below to Emacs init file, copied form Emacs Wiki. (when (load "flymake" t) (defun flymake-pylint-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "epylint" (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pylint-init))) When I invoke the flymake-mode on a .py file, I can see the flymake starting the syntax check, the mode status changed to flymake*, and then goes back to flymake after several seconds. But no error is reported, and no syntax error highlighting. I tried to use pylint in command line, and it works with command "pylint test.py", reporting syntax errors on the same file. I even tried to clear out my .emacs file, but it doesn't help. Could someone help me on this? Thanks a lot. From clp2 at rebertia.com Thu Sep 30 12:39:08 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 30 Sep 2010 09:39:08 -0700 Subject: install 3.1 In-Reply-To: References: Message-ID: > On Thu, Sep 30, 2010 at 4:16 PM, Chris Rebert wrote: >> On Thu, Sep 30, 2010 at 2:02 AM, roronron wrote: >> > My python installed but the gui gives me syntax error on any code I type >> > or paste in. Newbie needs help. >> >> Post the full, exact text of the error message. >> See also: http://www.catb.org/esr/faqs/smart-questions.html On Thu, Sep 30, 2010 at 2:57 AM, ronald brown wrote: >>>> print 'Hello, world!' > SyntaxError: invalid syntax >>>> > Installed 3 times. Used uninstall in program files and control panel. > Followed directions on video for 3.1 Read the fine docs: http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function Python 3 has several backward-incompatible syntax changes. One of them is that the print statement was removed and replaced with a print() function. Regards, Chris From usenet-nospam at seebs.net Thu Sep 30 12:49:16 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 16:49:16 GMT Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, RG wrote: > My code compiles with no warnings under gcc -Wall. That's nice. gcc -Wall uses only a small subset of warnings that fit the usual expectations of C code that's trying to work on common architectures. >> 2. The constant is not of type int, and the compiler will warn you about >> this if you ask. > It would be nice if this were true, but my example clearly demonstrates > that it is not. No, it doesn't, because you didn't ask for the relevant kind of warnings. > And if your response is to say that I should have used > lint, then my response to that will be that because of the halting > problem, for any static analyzer that you present, I can construct a > program that either contains an error that either your analyzer will not > catch, or for which it will generate a false positive. It just so > happens that constructing such examples for standard C is very easy. I'm not sure that that's actually a halting problem case. The thing about static typing is that we don't actually HAVE to solve the halting problem; we only have look at the types of the components, all of which are knowable at compile time, and we can tell you whether there's any unsafe conversions. And that's the magic of static typing: It is not a false positive to warn you that "2L" is not of type int. There are things which would be a false positive in trying to determine whether something will be out of range in a runtime expression, but which are not false positives in a statically typed 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 dsrtegle at gmail.com Thu Sep 30 12:50:37 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Thu, 30 Sep 2010 09:50:37 -0700 (PDT) Subject: Please help: pylint does not work with Emacs23 on Windows References: <66da9bf4-3c1c-4aad-96ef-0c9fee798e90@a4g2000prm.googlegroups.com> Message-ID: <10208d80-559d-4c4d-8583-42b074dc1e15@h40g2000pro.googlegroups.com> On Sep 30, 9:38?am, Dsrt Egle wrote: > Hi, > > I am trying to use Pylint with Emacs on Windows XP. My Emacs version > is EmacsW32 23.1, pylint is 0.21.3 with Python 2.5. After easy_install > pylint, I added the code block below to Emacs init file, copied form > Emacs Wiki. > > ? ? (when (load "flymake" t) > ? ? ? (defun flymake-pylint-init () > ? ? ? ? (let* ((temp-file (flymake-init-create-temp-buffer-copy > ? ? ? ? ? ? ? ? ? ? ? ? ? ?'flymake-create-temp-inplace)) > ? ? ? ? ? ?(local-file (file-relative-name > ? ? ? ? ? ? ? ? ? ? ? ? temp-file > ? ? ? ? ? ? ? ? ? ? ? ? (file-name-directory buffer-file-name)))) > ? ? ? ? ? (list "epylint" (list local-file)))) > > ? ? ? (add-to-list 'flymake-allowed-file-name-masks > ? ? ? ? ? ? ? ?'("\\.py\\'" flymake-pylint-init))) > > When I invoke the flymake-mode on a .py file, I can see the flymake > starting the syntax check, the mode status changed to flymake*, and > then goes back to flymake after several seconds. But no error is > reported, and no syntax error highlighting. > > I tried to use pylint in command line, and it works with command > "pylint test.py", reporting syntax errors on the same file. > > I even tried to clear out my .emacs file, but it doesn't help. > > Could someone help me on this? Thanks a lot. Question Update: I tried the following at command line prompt with "pylint" and "epylint". Does this mean that epylint has a problem? C:\Projects>pylint test_lib.py No config file found, using default configuration ************* Module test_lib E: 13: invalid syntax C:\Projects>epylint test_lib.py 'test_lib.py':1: [F] No module named 'test_lib.py' C:\Projects>epylint Traceback (most recent call last): File "C:\Python25\Scripts\epylint", line 5, in pkg_resources.run_script('pylint==0.21.3', 'epylint') File "C:\Python25\Lib\site-packages\pkg_resources.py", line 489, in run_script self.require(requires)[0].run_script(script_name, ns) File "C:\Python25\Lib\site-packages\pkg_resources.py", line 1207, in run_script execfile(script_filename, namespace, namespace) File "c:\python25\lib\site-packages\pylint-0.21.3-py2.5.egg\EGG- INFO\scripts\epylint", line 3, in epylint.Run() File "c:\python25\lib\site-packages\pylint-0.21.3-py2.5.egg \pylint\epylint.py", line 93, in Run lint(sys.argv[1]) IndexError: list index out of range From no.email at please.post Thu Sep 30 13:07:12 2010 From: no.email at please.post (kj) Date: Thu, 30 Sep 2010 17:07:12 +0000 (UTC) Subject: namespace hacking question Message-ID: This is a recurrent situation: I want to initialize a whole bunch of local variables in a uniform way, but after initialization, I need to do different things with the various variables. What I end up doing is using a dict: d = dict() for v in ('spam', 'ham', 'eggs'): d[v] = init(v) foo(d['spam']) bar(d['ham']) baz(d['eggs']) This is fine, but I'd like to get rid of the tedium of typing all those extra d['...']s. I.e., what I would *like* to do is something closer to this: d = locals() for v in ('spam', 'ham', 'eggs'): d[v] = init(v) foo(spam) bar(ham) baz(eggs) ...but this results in errors like "NameError: global name 'spam' is not defined". But the problem is deeper than the fact that the error above would suggest, because even this fails: spam = ham = eggs = None d = locals() for v in ('spam', 'ham', 'eggs'): d[v] = init(v) foo(spam) # calls foo(None) bar(ham) # calls bar(None) baz(eggs) # calls baz(None) In other words, setting the value of locals()['x'] does not set the value of the local variable x. I also tried a hack using eval: for v in ('spam', 'ham', 'eggs'): eval "%s = init('%s')" % (v, v) but the "=" sign in the eval string resulted in a "SyntaxError: invalid syntax". Is there any way to use a loop to set a whole bunch of local variables (and later refer to these variables by their individual names)? TIA! kj From usenot at geekmail.INVALID Thu Sep 30 13:22:31 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 30 Sep 2010 13:22:31 -0400 Subject: if the else short form References: <4ca3181d$0$31381$4fafbaef@reader1.news.tin.it> Message-ID: <20100930132231.6f51b2a6@geekmail.INVALID> On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) "bruno.desthuilliers at gmail.com" wrote: > On 29 sep, 19:20, Seebs wrote: > > On 2010-09-29, Tracubik wrote: > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > Oh, what a nasty idiom. > > > > Well, it's not very different from dict-based dispatch , which is the > core of OO polymorphic dispatch in quite a few dynamic OOPLs. > > Anyway, it's a common Python idiom and one that's not specially hard > to grasp so I don't see any legibility problem here. But it does violate the "explicit is better than implicit" tenet, don't you think? /W -- INVALID? DE! From usenot at geekmail.INVALID Thu Sep 30 13:30:00 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 30 Sep 2010 13:30:00 -0400 Subject: install 3.1 References: Message-ID: <20100930133000.5bd85f16@geekmail.INVALID> On Thu, 30 Sep 2010 09:39:08 -0700 Chris Rebert wrote: > On Thu, Sep 30, 2010 at 2:57 AM, ronald brown > wrote: > >>>> print 'Hello, world!' > > SyntaxError: invalid syntax > >>>> > > Installed 3 times. Used uninstall in program files and control > > panel. Followed directions on video for 3.1 > > Read the fine docs: > http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function > Python 3 has several backward-incompatible syntax changes. One of them > is that the print statement was removed and replaced with a print() > function. > Sort of serious proposal here: Would it make sense to display a big, fat warning during the install process (and possibly on the first few invocations of the interpreter) to the effect that "If you're starting to learn Python, make sure you're using a Python 3 tutorial!". This seems to throw a lot of people, and I don't see it going away too soon. So maybe this might help? /W -- INVALID? DE! From bruno.desthuilliers at gmail.com Thu Sep 30 13:36:49 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 30 Sep 2010 10:36:49 -0700 (PDT) Subject: namespace hacking question References: Message-ID: <14b5bdd0-f3a6-498a-8b1f-a52b3fd49ca9@j18g2000yqd.googlegroups.com> On 30 sep, 19:07, kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(d['spam']) > bar(d['ham']) > baz(d['eggs']) > > This is fine, but I'd like to get rid of the tedium of typing all > those extra d['...']s. > > I.e., what I would *like* to do is something closer to this: > > d = locals() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(spam) > bar(ham) > baz(eggs) > > ...but this results in errors like "NameError: global name 'spam' is > not defined". > > But the problem is deeper than the fact that the error above would > suggest, because even this fails: > > spam = ham = eggs = None > d = locals() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) The local namespace is not implemented as a dict - locals() only returns a dict representation of it, so updating this dict has no effect on the local namespace. This is documented FWIW. > > I also tried a hack using eval: > > for v in ('spam', 'ham', 'eggs'): > ? ? eval "%s = init('%s')" % (v, v) > > but the "=" sign in the eval string resulted in a "SyntaxError: > invalid syntax". eval only accepts expressions. You'd need exec here - but that's a bit ugly. From python at mrabarnett.plus.com Thu Sep 30 13:40:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Sep 2010 18:40:23 +0100 Subject: namespace hacking question In-Reply-To: References: Message-ID: <4CA4CB87.2050605@mrabarnett.plus.com> On 30/09/2010 18:07, kj wrote: > > > > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', 'ham', 'eggs'): > d[v] = init(v) > > foo(d['spam']) > bar(d['ham']) > baz(d['eggs']) > > > > This is fine, but I'd like to get rid of the tedium of typing all > those extra d['...']s. > > I.e., what I would *like* to do is something closer to this: > > d = locals() > for v in ('spam', 'ham', 'eggs'): > d[v] = init(v) > > foo(spam) > bar(ham) > baz(eggs) > > ...but this results in errors like "NameError: global name 'spam' is > not defined". > > But the problem is deeper than the fact that the error above would > suggest, because even this fails: > > spam = ham = eggs = None > d = locals() > for v in ('spam', 'ham', 'eggs'): > d[v] = init(v) > > foo(spam) # calls foo(None) > bar(ham) # calls bar(None) > baz(eggs) # calls baz(None) > > > In other words, setting the value of locals()['x'] does not set > the value of the local variable x. > > I also tried a hack using eval: > > for v in ('spam', 'ham', 'eggs'): > eval "%s = init('%s')" % (v, v) > > but the "=" sign in the eval string resulted in a "SyntaxError: > invalid syntax". > > Is there any way to use a loop to set a whole bunch of local > variables (and later refer to these variables by their individual > names)? > The handling of local variables in CPython is optimised, so changing locals() won't have any effect, as you discovered. An alternative is to create a namespace in an instance of a class and then add attributes to it: class Namespace(object): pass n = Namespace() for v in ('spam', 'ham', 'eggs'): setattr(n, v, init(v)) foo(n.spam) bar(n.ham) baz(n.eggs) From cousinstanley at gmail.com Thu Sep 30 13:43:49 2010 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 30 Sep 2010 17:43:49 +0000 (UTC) Subject: problem in Gasp ! References: Message-ID: n.a.s wrote: > I want to ask about graphics using Gasp .Attached is exercise 10 > (houses at night) > > if i call the draw_house function once it will work properly ,but more than > one call,windows and doors disappear from some houses . > > Any one can advice? A working version that runs using Python2.6 under Debian 6 Squeeze can be found at .... http://csphx.net/python/house.tar.bz A screenshot of the result is included in that archive .... http://csphx.net/image/houses_10.png -- Stanley C. Kitching Human Being Phoenix, Arizona From Scott at ergy.com Thu Sep 30 13:56:48 2010 From: Scott at ergy.com (Scott L. Burson) Date: Thu, 30 Sep 2010 10:56:48 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <8gik9tFq44U4@mid.individual.net> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <8gik9tFq44U4@mid.individual.net> Message-ID: Ian Collins wrote: > On 09/30/10 05:57 PM, RG wrote: >> >> I'm not saying one should not use compile-time tools, only that one >> should not rely on them. "Compiling without errors" is not -- and >> cannot ever be -- be a synonym for "bug-free." > > We is why we all have run time tools called unit tests, don't we? > My post that kicked off this thread was not cross-posted, so many of the participants may not have seen it. Here it is again, for your convenience: --------------------- This might have been mentioned here before, but I just came across it: a 2003 essay by Bruce Eckel on how reliable systems can get built in dynamically-typed languages. It echoes things we've all said here, but I think it's interesting because it describes a conversion experience: Eckel started out in the strong-typing camp and was won over. https://docs.google.com/View?id=dcsvntt2_25wpjvbbhk -- Scott From rNOSPAMon at flownet.com Thu Sep 30 14:01:29 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 11:01:29 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Seebs wrote: > And that's the magic of static typing: It is not a false positive to > warn you that "2L" is not of type int. We'll have to agree to disagree about that. The numerical value 2 can safely be represented as an int, so I would consider this a false positive. rg From Scott at ergy.com Thu Sep 30 14:06:18 2010 From: Scott at ergy.com (Scott L. Burson) Date: Thu, 30 Sep 2010 11:06:18 -0700 Subject: "Strong typing vs. strong testing" In-Reply-To: <87k4m4nnqk.fsf@kuiper.lan.informatimago.com> References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <87k4m4nnqk.fsf@kuiper.lan.informatimago.com> Message-ID: Pascal J. Bourguignon wrote: > Squeamizh writes: > >> In short, static typing doesn't solve all conceivable problems. >> >> We are all aware that there is no perfect software development process >> or tool set. I'm interested in minimizing the number of problems I >> run into during development, and the number of bugs that are in the >> finished product. My opinion is that static typed languages are >> better at this for large projects, for the reasons I stated in my >> previous post. Here's a post I wrote earlier, before the conversation got cross-posted. To me, this is the essence of the matter. ----------------------- Norbert_Paul wrote: > > OK, but sometimes it is handy to have the possibility to make compile-time > assertions which prevent you from committing easily avoidable simple > mistakes. Agreed. I actually don't see this issue in black and white terms; I've written lots of Lisp, and I've written lots of code in statically typed languages, and they all have advantages and disadvantages. In the end it all comes back to my time: how much time does it take me to ship a debugged system? Working in Lisp, sometimes I don't get immediate feedback from the compiler that I've done something stupid, but this is generally counterbalanced by the ease of interactive testing, that frequently allows me to run a new piece of code several times in the time it would have taken me to do a compile-and-link in, say, C++. So while I agree with you that compiler warnings are sometimes handy, and there are occasions, working in Lisp, that I would like to have more of them(*), it really doesn't happen to me very often that the lack of one is more than a minor problem. (*) Lisp compilers generally do warn about some things, like passing the wrong number of arguments to a function, or inconsistent spelling of the name of a local variable. In my experience, these warnings cover a substantial fraction of the stupid mistakes I actually make. -- Scott From kst-u at mib.org Thu Sep 30 14:09:44 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 11:09:44 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: Seebs writes: > On 2010-09-30, Paul Rubin wrote: >> int maximum(int a, int b); >> >> int foo() { >> int (*barf)() = maximum; >> return barf(3); >> } > >> This compiles fine for me. Where is the cast? > > On the first line of code inside foo(). Look again; there's no cast in foo(). That first line declare barf as an object of type "pointer to function returning int", or more precisely, "pointer to function with an unspecified but fixed number and type of parameters returning int" (i.e., an old-style non-prototype declaration, still legal but deprecated in both C90 and C99). It then initializes it to point to the "maximum" function. I *think* the types are sufficiently "compatible" (not necessarily using that word the same way the standard does) for the initialization to be valid and well defined. I might check the standard later. It would have been better to use a prototype (for those of you in groups other than comp.lang.c, that's a function declaration that specifies the types of any parameters): int (*barf)(int, int) = maximum; IMHO it's better to use prototypes consistently than to figure out the rules for interactions between prototyped vs. non-prototyped function declarations. [...] -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From no.email at nospam.invalid Thu Sep 30 14:11:45 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 11:11:45 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: <7xr5gbxfry.fsf@ruckus.brouhaha.com> RG writes: > Yes, I know I could have used lint. But that misses the point. For any > static analyzer, because of the halting problem, I can construct a > program that either contains an error that the analyzer will not catch, > or for which the analyzer will produce a false positive. Can you describe any plausible real-world programs where the effort of complicated static is justified, and for which the halting problem gets in the way of analysis? By "real world", I meanI wouldn't consider searching for counterexamples to the Collatz conjecture to qualify as sufficiently real-world and sufficiently complex for fancy static analysis. And even if it did, the static analyzer could deliver a partial result, like "this function either returns a counterexample to the Collatz conjecture or else it doesn't return". D. Turner wrote a famous paper arguing something like the above, saying basically that Turing completeness of programming languages is overrated: http://www.jucs.org/jucs_10_7/total_functional_programming The main example of a sensible program that can't be written in a non-complete language is an interpreter for a Turing-complete language. But presumably a high-assurance application should never contain such a thing, since the interpreted programs themselves then wouldn't have static assurance. From pjb at informatimago.com Thu Sep 30 14:21:30 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 20:21:30 +0200 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: <8762xnnlcl.fsf@kuiper.lan.informatimago.com> RG writes: > One might hypothesize that the best of both worlds would be a dynamic > language with a static analyzer layered on top. Such a thing does not > exist. It makes an instructive exercise to try to figure out why. (For > the record, I don't know the answer, but I've learned a lot through the > process of pondering this conundrum.) There are static analysis tools for Common Lisp: http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/tools/lint/0.html or lisp in general. For example PHENARETE is in the category of static analysis tools. One could regret that they're not more developed, but I guess this only proves the success of using dynamic programming languages: if there were a real need for these tools, along with a good ROI, they would be more developed. In the meantime, several test frameworks are developed. -- __Pascal Bourguignon__ http://www.informatimago.com/ From pjb at informatimago.com Thu Sep 30 14:23:50 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 20:23:50 +0200 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: <871v8bnl8p.fsf@kuiper.lan.informatimago.com> RG writes: > In article , > Seebs wrote: > >> On 2010-09-30, RG wrote: >> > You can't have it both ways. Either I am calling it incorrectly, in >> > which case I should get a compiler error, >> >> You get a warning if you ask for it. If you choose to run without all >> the type checking on, that's your problem. > > My example compiles with no warnings under gcc -Wall. IIRC, -Wall is not reall ALL. Try with: gcc -Wall -Wextra -Werror I would still argue that should be the default, and if really there was a need, there could be options to disable some warning, or to have some errors be warnings... -- __Pascal Bourguignon__ http://www.informatimago.com/ From kst-u at mib.org Thu Sep 30 14:25:03 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 11:25:03 -0700 Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> Message-ID: RG writes: > In article , > Keith Thompson wrote: >> RG writes: >> [...] >> > You can't have it both ways. Either I am calling it incorrectly, in >> > which case I should get a compiler error, or I am calling it correctly, >> > and I should get the right answer. That I got neither does in fact >> > falsify the claim. The only way out of this is to say that >> > maximum(8589934592, 1) returning 1 is in fact "correct", in which case >> > we'll just have to agree to disagree. >> >> You are calling maximum() incorrectly, but you are doing so in a way >> that the compiler is not required to diagnose. > > Yes. I know. That was my whole point. There are ways to call a > function incorrectly (more broadly, there are errors in code) that a C > compiler is not required to diagnose. Of course. >> If you want to say that the fact that the compiler is not required >> to diagnose the error is a flaw in the C language, I won't >> argue with you. > > I'm not even saying it's a flaw in the language. All I'm saying is that > the original claim -- that any error in a C program will be caught by > the compiler -- is false, and more specifically, that it can be > demonstrated to be false without appeal to unknown run-time input. Did someone *really* claim that "any error in a C program will be caught by the compiler"? If so, I must have missed that. It's certainly not true; code that compiles cleanly can be riddled with errors. That's true in any language, but more so in C than in some others. > As an aside, this particular error *could* be caught (and in fact would > be caught by other tools like lint), but there are errors that can not > be caught by any static analysis, and that therefore one should not be > lulled into a false sense of security by the fact that your code is > written in a statically typed language and compiled without errors or > warnings. That's all. I don't believe anyone has said otherwise. >> If I write: >> >> const double pi = 22.0/7.0; >> printf("pi = %f\n", pi); >> >> then I suppose I'm calling printf() incorrectly, but I wouldn't >> expect my compiler to warn me about it. >> >> If you're arguing that >> >> int maximum(int a, int b) { return a > b ? a : b; } >> >> is flawed because it's too easy to call it incorrectly, you're >> effectively arguing that it's not possible to write correct >> code in C at all. > > I would say that it is very, very hard to write correct code in C for > any non-vacuous definition of "correct". That is the reason that core > dumps and buffer overflows are so ubiquitous. I prefer Lisp or Python, > where core dumps and buffer overflows are virtually nonexistent. One > does get the occasional run-time error that might have been caught at > compile time, but I much prefer that to a core dump or a security hole. I would say that it can certainly be difficult to write correct code in C, but I don't believe it's nearly as hard as you think it is. It requires more discipline than some other languages, and it can require some detailed knowledge of the language itself, particularly what it defines and what it doesn't. And it's not always worth the effort if another language can do the job as well or better. > One might hypothesize that the best of both worlds would be a dynamic > language with a static analyzer layered on top. Such a thing does not > exist. It makes an instructive exercise to try to figure out why. (For > the record, I don't know the answer, but I've learned a lot through the > process of pondering this conundrum.) -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From pjb at informatimago.com Thu Sep 30 14:37:22 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 20:37:22 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> <676fe660-2761-487a-9472-e6232f659d1e@q40g2000prg.googlegroups.com> Message-ID: <87wrq3m61p.fsf@kuiper.lan.informatimago.com> TheFlyingDutchman writes: >> >> > "in C I can have a function maximum(int a, int b) that will always >> > work. Never blow up, and never give an invalid answer. " >> >> > Dynamic typed languages like Python fail in this case on "Never blows >> > up". >> >> How do you define "Never blows up"? > > Never has execution halt. > > I think a key reason in the big rise in the popularity of interpreted > languages This is a false conception. Whether the execution of a program is done by a processor of the programming language, or a processor of another programming language (and therefore requiring a translation phase), is a notion is NOT a characteristic of programming language, but only of execution environments. 1- There are C interpreters CINT - http://root.cern.ch/root/Cint.html EiC - http://eic.sourceforge.net/ Ch - http://www.softintegration.com 2- All the current Common Lisp implementations have compilers, 3- Most current Common Lisp implementations actually compile to native code (ie they chose to translate to programming languages that are implemented by Intel, AMD or Motorola. (Notice that these programming languages are NOT implemented in hardware, but in software, called micro-code, stored on the real hardware inside the micro-processors); some choose to translate to C and call an external C compiler to eventually translate to "native" code). 4- Actually, there is NO current Common Lisp implementation having only an interpreter. On the contrary, most of the don't have any interpreter (but all of them have a REPL, this is an orthogonal concept). 5- Even the first LISP implementation made in 1959 had a compiler. 6- I know less the situation for the other dynamic programming language, but for example, if CPython weren't a compiler, you should know that CLPython is a compiler (it's an implementation of Python written in Common Lisp, which translates Python into Common Lisp and compiles it). > is that when execution halts, they normally give a call > stack and usually a good reason for why things couldn't continue. As > opposed to compiled languages which present you with a blank screen > and force you to - fire up a debugger, or much much worse, look at a > core dump - to try and discern all the information the interpreter > presents to you immediately. Theorically, a compiler for a static programming language has even more information about the program, so it should be able to produce even better backtrace in case of problem... -- __Pascal Bourguignon__ http://www.informatimago.com/ From hidura at gmail.com Thu Sep 30 14:38:05 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 30 Sep 2010 18:38:05 +0000 Subject: Problems with wsgi Python3 In-Reply-To: <67044A5A-FEE5-4AFE-8CA7-78DBD0B19687@web.de> Message-ID: <90e6ba4765e1fbc29904917e6033@google.com> Sorry, for the last mail, here it's what you asked: {'CONTENT_LENGTH': '61', [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; boundary=---------------------------8905735096173894531259794847', [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite', [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': [Thu Sep 30 13:35:07 2010] [error] 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': [Thu Sep 30 13:35:07 2010] [error] 'close', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': [Thu Sep 30 13:35:07 2010] [error] 'http://hidura.webfactional.com/?md=btdump', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10', [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': [Thu Sep 30 13:35:07 2010] [error] '58742', [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': [Thu Sep 30 13:35:07 2010] [error] 'POST', [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': [Thu Sep 30 13:35:07 2010] [error] '[no address given]', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': [Thu Sep 30 13:35:07 2010] [error] '80', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 Python/3.1', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': [Thu Sep 30 13:35:07 2010] [error] 'application', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': [Thu Sep 30 13:35:07 2010] [error] '0', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': [Thu Sep 30 13:35:07 2010] [error] '51543', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': [Thu Sep 30 13:35:07 2010] [error] '', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': [Thu Sep 30 13:35:07 2010] [error] '1', [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': [Thu Sep 30 13:35:07 2010] [error] (3, 3), [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': [Thu Sep 30 13:35:07 2010] [error] <_io.TextIOWrapper encoding='utf-8'>, [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': [Thu Sep 30 13:35:07 2010] [error] , [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': [Thu Sep 30 13:35:07 2010] [error] , [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': [Thu Sep 30 13:35:07 2010] [error] False, [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': [Thu Sep 30 13:35:07 2010] [error] True, [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': [Thu Sep 30 13:35:07 2010] [error] False, [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': [Thu Sep 30 13:35:07 2010] [error] 'http', [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': [Thu Sep 30 13:35:07 2010] [error] (1, 1)} On Sep 30, 2010 1:56pm, "Diez B. Roggisch" wrote: > *sigh* > AGAIN, please do *not* reply to me personally. Reply to the ML or NG you > are posting in. I'm beginning to believe that it's a waste of time to > answer you since you seem not able to follow even the most simple of > advice and rules. > And read the answers you get thoroughly, you did not give all the > information I asked you for. > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > The output is: > > > > -----------------------------110550484811701713451664404475--\r > > > > No more i don 't know what that means or what do with this. > > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: > > > hidura at gmail.com writes: > > > > > > > > > > > > > Hello list, i had seriously troubles with the connection between a > form and the > > > > > > > wsgi, i' ve made an application on Python3 and was running > perfectly but when i > > > > > > > try to use the to pass the data this can't be see on the server, so > what > > > > > > > is your recommendation?, i am open to all the ideas less leave to > Python2 i > > > > > > > can't all the project was write on Python3, i was looking into the > PEP 444 > > > > > > > proposal too. > > > > > > > > > > > > > > Here is the code what i used to take the data: > > > > > > > > > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(environ > > > > > > > ['CONTENT_LENGTH'])).decode())) > > > > > > > > > > > > What is the ouptut of this? What does > > > > > > > > > > > > import pprint > > > > > > pprint.pprint(environ) > > > > > > > > > > > > give you? > > > > > > > > > > > > > > > > > > > > > > > > > > and here it's what the os.environ.item() prints to me: > > > > > > > > > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > > > > > > > > > Diez > > > > > > -- > > > > > > http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Thu Sep 30 14:41:59 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 30 Sep 2010 19:41:59 +0100 Subject: namespace hacking question References: Message-ID: <87mxqzkr9k.fsf@gmail.com> MRAB writes: > On 30/09/2010 18:07, kj wrote: >> >> >> >> This is a recurrent situation: I want to initialize a whole bunch >> of local variables in a uniform way, but after initialization, I >> need to do different things with the various variables. >> >> What I end up doing is using a dict: >> >> d = dict() >> for v in ('spam', 'ham', 'eggs'): >> d[v] = init(v) >> >> foo(d['spam']) >> bar(d['ham']) >> baz(d['eggs']) >> >> >> >> This is fine, but I'd like to get rid of the tedium of typing all >> those extra d['...']s. >> >> I.e., what I would *like* to do is something closer to this: >> >> d = locals() >> for v in ('spam', 'ham', 'eggs'): >> d[v] = init(v) >> >> foo(spam) >> bar(ham) >> baz(eggs) >> >> ...but this results in errors like "NameError: global name 'spam' is >> not defined". >> >> But the problem is deeper than the fact that the error above would >> suggest, because even this fails: >> >> spam = ham = eggs = None >> d = locals() >> for v in ('spam', 'ham', 'eggs'): >> d[v] = init(v) >> >> foo(spam) # calls foo(None) >> bar(ham) # calls bar(None) >> baz(eggs) # calls baz(None) >> >> >> In other words, setting the value of locals()['x'] does not set >> the value of the local variable x. >> >> I also tried a hack using eval: >> >> for v in ('spam', 'ham', 'eggs'): >> eval "%s = init('%s')" % (v, v) >> >> but the "=" sign in the eval string resulted in a "SyntaxError: >> invalid syntax". >> >> Is there any way to use a loop to set a whole bunch of local >> variables (and later refer to these variables by their individual >> names)? >> > The handling of local variables in CPython is optimised, so changing > locals() won't have any effect, as you discovered. > > An alternative is to create a namespace in an instance of a class and > then add attributes to it: > > class Namespace(object): > pass > > n = Namespace() > for v in ('spam', 'ham', 'eggs'): > setattr(n, v, init(v)) > > foo(n.spam) > bar(n.ham) > baz(n.eggs) Note that "exec" can be used: >>> def init(name): ... return "init " + name ... >>> def foo(): ... for name in "bar", "baz": ... exec "%s = init(name)" % name ... print bar ... print baz ... >>> foo() init bar init baz Not that I can think of a reason to do this :) -- Arnaud From Peter.Bienstman at UGent.be Thu Sep 30 14:47:00 2010 From: Peter.Bienstman at UGent.be (pbienst) Date: Thu, 30 Sep 2010 11:47:00 -0700 (PDT) Subject: C API: Getting PyObject by name Message-ID: <3ed9a977-b77f-4f2a-b62c-bae97e2f3339@x42g2000yqx.googlegroups.com> Hi, I'm embedding Python in a C app. Say I do the following: PyRun_SimpleString("a = 1") Is there then a way to get access to the PyObject corresponding to a, only making use in C of the fact that it's called "a"? I've searched through the API docs, but I couldn't really find what I was looking for. Any help most appreciated! Peter From usenet-nospam at seebs.net Thu Sep 30 15:17:39 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 19:17:39 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, RG wrote: > In article , > Seebs wrote: >> And that's the magic of static typing: It is not a false positive to >> warn you that "2L" is not of type int. > We'll have to agree to disagree about that. No, we won't. It's the *definition* of static typing. Static typing is there to give you some guarantees at the expense of not being able to express some things without special extra effort. That's why it's static. > The numerical value 2 can > safely be represented as an int, so I would consider this a false > positive. That's nice for you, I guess. The point of static typing is that it makes it possible to ensure that the values that reach a function are in fact of the correct type -- at the cost of not being able to rely on free runtime conversions. If you want to write safe conversions, you can do that. If you don't bother to do that, you end up with errors -- by definition. -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 Sep 30 15:21:58 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 19:21:58 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: On 2010-09-30, Keith Thompson wrote: > Seebs writes: >> On 2010-09-30, Paul Rubin wrote: >>> int maximum(int a, int b); >>> int foo() { >>> int (*barf)() = maximum; >>> return barf(3); >>> } > That first line declare barf as an object of type "pointer to > function returning int", or more precisely, "pointer to function with > an unspecified but fixed number and type of parameters returning int" > (i.e., an old-style non-prototype declaration, still legal but > deprecated in both C90 and C99). It then initializes it to point > to the "maximum" function. I *think* the types are sufficiently > "compatible" (not necessarily using that word the same way the > standard does) for the initialization to be valid and well defined. > I might check the standard later. Hmm. You have a point. It's clearly a conversion from one type to another. > IMHO it's better to use prototypes consistently than to figure out the > rules for interactions between prototyped vs. non-prototyped function > declarations. Yes. It's clearly undefined behavior to call a function through a pointer to a different type, or to call a function with the wrong number of arguments. I am pretty sure at least one compiler catches 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 thomas at jollybox.de Thu Sep 30 15:24:32 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 30 Sep 2010 21:24:32 +0200 Subject: C API: Getting PyObject by name In-Reply-To: <3ed9a977-b77f-4f2a-b62c-bae97e2f3339@x42g2000yqx.googlegroups.com> References: <3ed9a977-b77f-4f2a-b62c-bae97e2f3339@x42g2000yqx.googlegroups.com> Message-ID: <201009302124.32894.thomas@jollybox.de> On Thursday 30 September 2010, it occurred to pbienst to exclaim: > Hi, > > I'm embedding Python in a C app. > > Say I do the following: > > PyRun_SimpleString("a = 1") > > Is there then a way to get access to the PyObject corresponding to a, > only making use in C of the fact that it's called "a"? > > I've searched through the API docs, but I couldn't really find what I > was looking for. No. Not as such. But you could use PyRun_String, or PyRun_StringFlags. You could then access the globals object, but I ask you, why would you want to bind the object to a name in the first place? Use the fact that PyRun_String returns a reference to the result of an expression! From ian-news at hotmail.com Thu Sep 30 15:29:06 2010 From: ian-news at hotmail.com (Ian Collins) Date: Fri, 01 Oct 2010 08:29:06 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> Message-ID: <8gk6o2Fc8aU2@mid.individual.net> On 10/ 1/10 02:57 AM, Pascal Bourguignon wrote: > Nick Keighley writes: > >> On 27 Sep, 20:29, p... at informatimago.com (Pascal J. Bourguignon) >> wrote: >>> If you start with the mindset of static type checking, you will consider >>> that your types are checked and if the types at the interface of two >>> modules matches you'll think that everything's ok. And six months later >>> you Mars mission will crash. >> >> do you have any evidence that this is actually so? That people who >> program in statically typed languages actually are prone to this "well >> it compiles so it must be right" attitude? > > Yes, I can witness that it's in the mind set. > > Well, the problem being always the same, the time pressures coming from > the sales people (who can sell products of which the first line of > specifications has not been written yet, much less of code), it's always > a battle to explain that once the code is written, there is still a lot > of time needed to run tests and debug it. I've even technical managers, > who should know better, expecting that we write bug-free code in the > first place (when we didn't even have a specification to begin with!). Which is why agile practices such as TDD have an edge. If it compiles *and* passes all its tests, it must be right. -- Ian Collins From jmellander at lbl.gov Thu Sep 30 15:32:45 2010 From: jmellander at lbl.gov (Jim Mellander) Date: Thu, 30 Sep 2010 12:32:45 -0700 Subject: Determine sockets in use by python In-Reply-To: References: <4CA37FDA.3080605@digipen.edu> Message-ID: Thanks, I realized that even if I found out relevant info on the socket, I would probably need to use ctypes to provide a low level interface to select, as the socket wouldn't be a python socket object, unless there is some way to promote a c socket to a python socket object. Appreciate the info, folks. On Thu, Sep 30, 2010 at 7:14 AM, Jean-Paul Calderone wrote: > On Sep 29, 4:08?pm, Jim Mellander wrote: >> >> On Wed, Sep 29, 2010 at 11:05 AM, Gary Herron wrote: >> > On 09/29/2010 09:50 AM, Jim Mellander wrote: >> >> >> Hi: >> >> >> I'm a newbie to python, although not to programming. ?Briefly, I am >> >> using a binding to an external library used for communication in a >> >> client-server context, with the server in python. ?Typically, I would >> >> set this up with event callbacks, and then enter a select loop, which, >> >> most the time idles and processes input events when the socket shows >> >> activity, kinda like: >> >> >> while True: >> >> ? ? socket.select((my_socket),(),()) >> >> ? ? process_event() >> >> >> Unfortunately, the API does not expose the socket to the script level, >> >> and the developer recommends a busy loop: >> >> >> while True: >> >> ? ? sleep(1) >> >> ? ? process_event() >> >> >> which I hope to avoid, for many reasons. ?If the socket can be exposed >> >> to the script level, then the problem would be solved. >> >> >> Failing that, it would be nice to be able to pythonically determine >> >> the sockets in use and select on those. ?Does anyone have any >> >> suggestions on how to proceed? >> >> >> Thanks in advance >> >> > It's certain that any answer to this will depend on which operating system >> > you are using. ?So do tell: What OS? >> >> Hi Gary: >> >> Certainly not windows.... ?I'm developing on OS/X but for production >> probably Linux and FreeBSD >> >> (I'm hoping for something a bit more portable than running 'lsof' and >> parsing the output, but appreciate any/all advice) >> > > Linux has /proc/self/fd and OS X has /dev/fd. ?Those both suppose you > have some way of determining which file descriptor corresponds to the > socket or sockets that the library is using, of course. ?Vastly better > would be to convince the author to expose that information via a real > API. > > Jean-Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From ian-news at hotmail.com Thu Sep 30 15:35:56 2010 From: ian-news at hotmail.com (Ian Collins) Date: Fri, 01 Oct 2010 08:35:56 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: <8gk74sFc8aU3@mid.individual.net> On 10/ 1/10 08:21 AM, Seebs wrote: > On 2010-09-30, Keith Thompson wrote: > >> IMHO it's better to use prototypes consistently than to figure out the >> rules for interactions between prototyped vs. non-prototyped function >> declarations. > > Yes. It's clearly undefined behavior to call a function through a > pointer to a different type, or to call a function with the wrong number > of arguments. I am pretty sure at least one compiler catches this. Any C++ compiler will refuse to accept it. C isn't really a strongly typed language and having to support archaic non-prototyped function declarations makes thorough type checking extremely difficult if not impossible. -- Ian Collins From hidura at gmail.com Thu Sep 30 15:41:58 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 30 Sep 2010 19:41:58 +0000 Subject: Problems with wsgi Python3 In-Reply-To: <90e6ba4765e1fbc29904917e6033@google.com> Message-ID: <90e6ba4fc20672903204917f4555@google.com> What mean this -----------------------------743346150198628700241600224--\r? On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > Sorry, for the last mail, here it's what you asked: > {'CONTENT_LENGTH': '61', > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > boundary=---------------------------8905735096173894531259794847', > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite', > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > [Thu Sep 30 13:35:07 2010] > [error] 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > [Thu Sep 30 13:35:07 2010] [error] 'close', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > [Thu Sep 30 13:35:07 2010] > [error] 'http://hidura.webfactional.com/?md=btdump', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux x86_64; > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10', > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > [Thu Sep 30 13:35:07 2010] [error] '58742', > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > [Thu Sep 30 13:35:07 2010] [error] 'POST', > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > [Thu Sep 30 13:35:07 2010] > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > [Thu Sep 30 13:35:07 2010] [error] '80', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 > Python/3.1', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > [Thu Sep 30 13:35:07 2010] [error] 'application', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > [Thu Sep 30 13:35:07 2010] [error] '0', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > [Thu Sep 30 13:35:07 2010] [error] '51543', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > [Thu Sep 30 13:35:07 2010] [error] '', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > [Thu Sep 30 13:35:07 2010] [error] '1', > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > [Thu Sep 30 13:35:07 2010] [error] , > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > [Thu Sep 30 13:35:07 2010] [error] , > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > [Thu Sep 30 13:35:07 2010] [error] , > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > [Thu Sep 30 13:35:07 2010] [error] False, > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > [Thu Sep 30 13:35:07 2010] [error] True, > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > [Thu Sep 30 13:35:07 2010] [error] False, > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > [Thu Sep 30 13:35:07 2010] [error] 'http', > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > > > > > > *sigh* > > > > > > > > AGAIN, please do *not* reply to me personally. Reply to the ML or NG > you are posting in. I'm beginning to believe that it's a waste of time to > answer you since you seem not able to follow even the most simple of > advice and rules. > > > > > > > > And read the answers you get thoroughly, you did not give all the > information I asked you for. > > > > > > > > > > > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > > > > > > > > The output is: > > > > > > > > > > -----------------------------110550484811701713451664404475--\r > > > > > > > > > > No more i don 't know what that means or what do with this. > > > > > > > > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: > > > > > > hidura at gmail.com writes: > > > > > > > > > > > > > > > > > > > > > > > > > Hello list, i had seriously troubles with the connection between > a form and the > > > > > > > > > > > > > wsgi, i' ve made an application on Python3 and was running > perfectly but when i > > > > > > > > > > > > > try to use the to pass the data this can't be see on the server, > so what > > > > > > > > > > > > > is your recommendation?, i am open to all the ideas less leave to > Python2 i > > > > > > > > > > > > > can't all the project was write on Python3, i was looking into > the PEP 444 > > > > > > > > > > > > > proposal too. > > > > > > > > > > > > > > > > > > > > > > > > > > Here is the code what i used to take the data: > > > > > > > > > > > > > > > > > > > > > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(environ > > > > > > > > > > > > > ['CONTENT_LENGTH'])).decode())) > > > > > > > > > > > > > > > > > > > > > > > > What is the ouptut of this? What does > > > > > > > > > > > > > > > > > > > > > > > > import pprint > > > > > > > > > > > > pprint.pprint(environ) > > > > > > > > > > > > > > > > > > > > > > > > give you? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > and here it's what the os.environ.item() prints to me: > > > > > > > > > > > > > > > > > > > > > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > > > > > > > > > > > > > > > > > > > > > Diez > > > > > > > > > > > > -- > > > > > > > > > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From exarkun at twistedmatrix.com Thu Sep 30 15:44:13 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Thu, 30 Sep 2010 19:44:13 -0000 Subject: Determine sockets in use by python In-Reply-To: References: <4CA37FDA.3080605@digipen.edu> Message-ID: <20100930194413.2022.131818072.divmod.xquotient.60@localhost.localdomain> On 07:32 pm, jmellander at lbl.gov wrote: >Thanks, I realized that even if I found out relevant info on the >socket, I would probably need to use ctypes to provide a low level >interface to select, as the socket wouldn't be a python socket object, >unless there is some way to promote a c socket to a python socket >object. > >Appreciate the info, folks. There are a few options to help with that part of it: * select() works with integer file descriptors * socket.socket.fromfd gives you a socket object from an integer file descriptor * os.read and os.write let you read and write directly on file descriptors (although it sounds like you might not need this) Jean-Paul >On Thu, Sep 30, 2010 at 7:14 AM, Jean-Paul Calderone > wrote: >>On Sep 29, 4:08?pm, Jim Mellander wrote: >>> >>>On Wed, Sep 29, 2010 at 11:05 AM, Gary Herron >>>wrote: >>> > On 09/29/2010 09:50 AM, Jim Mellander wrote: >>> >>> >> Hi: >>> >>> >> I'm a newbie to python, although not to programming. ?Briefly, I >>>am >>> >> using a binding to an external library used for communication in a >>> >> client-server context, with the server in python. ?Typically, I >>>would >>> >> set this up with event callbacks, and then enter a select loop, >>>which, >>> >> most the time idles and processes input events when the socket >>>shows >>> >> activity, kinda like: >>> >>> >> while True: >>> >> ? ? socket.select((my_socket),(),()) >>> >> ? ? process_event() >>> >>> >> Unfortunately, the API does not expose the socket to the script >>>level, >>> >> and the developer recommends a busy loop: >>> >>> >> while True: >>> >> ? ? sleep(1) >>> >> ? ? process_event() >>> >>> >> which I hope to avoid, for many reasons. ?If the socket can be >>>exposed >>> >> to the script level, then the problem would be solved. >>> >>> >> Failing that, it would be nice to be able to pythonically >>>determine >>> >> the sockets in use and select on those. ?Does anyone have any >>> >> suggestions on how to proceed? >>> >>> >> Thanks in advance >>> >>> > It's certain that any answer to this will depend on which operating >>>system >>> > you are using. ?So do tell: What OS? >>> >>>Hi Gary: >>> >>>Certainly not windows.... ?I'm developing on OS/X but for production >>>probably Linux and FreeBSD >>> >>>(I'm hoping for something a bit more portable than running 'lsof' and >>>parsing the output, but appreciate any/all advice) >> >>Linux has /proc/self/fd and OS X has /dev/fd. ?Those both suppose you >>have some way of determining which file descriptor corresponds to the >>socket or sockets that the library is using, of course. ?Vastly better >>would be to convince the author to expose that information via a real >>API. >> >>Jean-Paul >>-- >>http://mail.python.org/mailman/listinfo/python-list > From rNOSPAMon at flownet.com Thu Sep 30 15:45:46 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 12:45:46 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: In article <7xr5gbxfry.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > RG writes: > > Yes, I know I could have used lint. But that misses the point. For any > > static analyzer, because of the halting problem, I can construct a > > program that either contains an error that the analyzer will not catch, > > or for which the analyzer will produce a false positive. > > Can you describe any plausible real-world programs where the effort of > complicated static is justified, and for which the halting problem gets > in the way of analysis? By "real world", I meanI wouldn't consider > searching for counterexamples to the Collatz conjecture to qualify as > sufficiently real-world and sufficiently complex for fancy static > analysis. And even if it did, the static analyzer could deliver a > partial result, like "this function either returns a counterexample to > the Collatz conjecture or else it doesn't return". > > D. Turner wrote a famous paper arguing something like the above, saying > basically that Turing completeness of programming languages is > overrated: > > http://www.jucs.org/jucs_10_7/total_functional_programming > > The main example of a sensible program that can't be written in a > non-complete language is an interpreter for a Turing-complete language. > But presumably a high-assurance application should never contain such a > thing, since the interpreted programs themselves then wouldn't have > static assurance. There are only two possibilities: either you have a finite-state machine, or you have a Turning machine. (Well, OK, you could have a pushdown automaton, but there are no programming languages that model a PDA. Well, OK, there's Forth, but AFAIK there are no static type checkers for Forth. Besides, who uses Forth? ;-) If you have a finite state machine everything is trivial. If you have a Turing machine everything is generally impossible. This is an oversimplification but not far from the fundamental underlying truth. My favorite practical example is the square root function. The standard C library defines a square root function on floats (actually on doubles), which is to say, over a finite-state model with 2^64 states. The model is not well defined over half of that range (negative numbers), which the static type checker cannot catch because there is no such thing as an unsigned double. But the fun doesn't stop there. Doubles >= 0.0 are not the only thing one might reasonably want to take a square root of, and indeed C++ overloads sqrt to work on complex and valarray types in addition to floats of various lengths (though you still have to manually keep track of whether or not the argument to sqrt might be a negative real). But what if I want an exact integer square root? Or a square root of a data type that represents irrational numbers not as floating point approximations but as exact symbolic representations? I haven't worked out the details, but I'd be surprised if none of these variations turned out to be Turing complete. The Turner paper is right on point: there's a fundamental distinction between the (known) finite and the (potentially) infinite. In my experience most of the cool interesting stuff has been found in the latter domain, and trying to shoehorn the latter into the former is more trouble then it's worth. rg From jadill33 at gmail.com Thu Sep 30 15:48:51 2010 From: jadill33 at gmail.com (ImpalerCore) Date: Thu, 30 Sep 2010 12:48:51 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> On Sep 29, 9:01?pm, RG wrote: > [ron at mighty:~]$ cat foo.c > #include > > int maximum(int a, int b) { return a > b ? a : b; } > > int main() { > ? long x = 8589934592; > ? printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > ? return 0;} > > [ron at mighty:~]$ gcc -Wall foo.c > [ron at mighty:~]$ ./a.out > Max of 8589934592 and 1 is 1 In the context of procedural programming, there is always an implicit contract between the function and its client. If you're going to fool around sending cleverly crafted garbage into the input of 'maximum' due to C conversion rules, why do you expect the 'maximum' function to be responsible for producing the correct response to an ill-formed question? What alternative behavior of 'maximum' would you prefer to see, that the C language auto-promote the function arguments and return type to type long based on the type of arguments provided to the 'maximum' function? You either learn to play in the sandbox that C provides, splinters and all, or you find another sandbox. Best regards, John D. From kst-u at mib.org Thu Sep 30 15:52:08 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 12:52:08 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: RG writes: > In article , > Seebs wrote: > >> On 2010-09-30, Lie Ryan wrote: >> > On 09/30/10 16:09, TheFlyingDutchman wrote: >> >> Dynamic typed languages like Python fail in this case on "Never blows >> >> up". >> >> > How do you define "Never blows up"? >> >> I would say "blow up" would be "raise an exception". >> >> > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow >> > up, and of the worst kind since it passes silently. >> >> So run your compiler with a decent set of warning levels, and watch as >> you are magically warned that you're passing an object of the wrong type. > > My code compiles with no warnings under gcc -Wall. Conclusion: "-Wall" is not "a decent set of warning levels" in this context, in spite of the name. (If you want to complain that the name "-Wall" is misleading, I won't disagree, but it's a gcc issue, not a C issue.) With "-Wconversion", I get: c.c: In function 'main': c.c:7: warning: passing argument 1 of 'maximum' with different width due to prototype [...] >> On any given system, one or the other is true: >> >> 1. The constant 8589934592 is of type int, and the function will >> "work" -- will give that result. >> 2. The constant is not of type int, and the compiler will warn you about >> this if you ask. > > It would be nice if this were true, but my example clearly demonstrates > that it is not. And if your response is to say that I should have used > lint, then my response to that will be that because of the halting > problem, for any static analyzer that you present, I can construct a > program that either contains an error that either your analyzer will not > catch, or for which it will generate a false positive. It just so > happens that constructing such examples for standard C is very easy. And yet you have not managed to do it. It seems to me that the line between errors that a sufficiently clever compiler could or should warn you about, and errors that compilers cannot reasonably be expected to detect, is a very fuzzy one. A fairly clear example of the latter is: const double pi = 2.71828182845904523526; To a human reader, it's obviously either a mistake or deliberate obfuscation, but I'm not sure I'd *want* my compiler to warn me about it just because I named the object "pi" rather than "e". (And if I called it "x", even an intelligent human wouldn't know that it's wrong.) -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From rNOSPAMon at flownet.com Thu Sep 30 15:52:58 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 12:52:58 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> Message-ID: In article <0390e2b4-fa28-49b3-a867-39be6d66828f at w19g2000yqb.googlegroups.com>, ImpalerCore wrote: > On Sep 29, 9:01?pm, RG wrote: > > > > > [ron at mighty:~]$ cat foo.c > > #include > > > > int maximum(int a, int b) { return a > b ? a : b; } > > > > int main() { > > ? long x = 8589934592; > > ? printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > > ? return 0;} > > > > [ron at mighty:~]$ gcc -Wall foo.c > > [ron at mighty:~]$ ./a.out > > Max of 8589934592 and 1 is 1 > > In the context of procedural programming, there is always an implicit > contract between the function and its client. If you're going to fool > around sending cleverly crafted garbage into the input of 'maximum' > due to C conversion rules, why do you expect the 'maximum' function to > be responsible for producing the correct response to an ill-formed > question? What alternative behavior of 'maximum' would you prefer to > see, that the C language auto-promote the function arguments and > return type to type long based on the type of arguments provided to > the 'maximum' function? > > You either learn to play in the sandbox that C provides, splinters and > all, or you find another sandbox. > > Best regards, > John D. You're missing a lot of context. I'm not trying to criticize C, just to refute a false claim that was made about it. rg From rNOSPAMon at flownet.com Thu Sep 30 15:56:58 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 12:56:58 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Seebs wrote: > On 2010-09-30, RG wrote: > > In article , > > Seebs wrote: > >> And that's the magic of static typing: It is not a false positive to > >> warn you that "2L" is not of type int. > > > We'll have to agree to disagree about that. > > No, we won't. It's the *definition* of static typing. Static typing > is there to give you some guarantees at the expense of not being able > to express some things without special extra effort. That's why it's > static. I don't want to quibble over terminology. Whatever label you choose to put on it ("false positive", "not being able to express some things without special extra effort") I consider it a deficiency. The costs are greater than the benefits. Reasonable people can (and obviously do) disagree. rg From thomas at jollybox.de Thu Sep 30 16:02:47 2010 From: thomas at jollybox.de (Thomas Jollans) Date: Thu, 30 Sep 2010 22:02:47 +0200 Subject: Problems with wsgi Python3 In-Reply-To: <90e6ba4fc20672903204917f4555@google.com> References: <90e6ba4fc20672903204917f4555@google.com> Message-ID: <201009302202.47714.thomas@jollybox.de> On Thursday 30 September 2010, it occurred to hidura at gmail.com to exclaim: > What mean this > -----------------------------743346150198628700241600224--\r? it looks like a MIME boundary. In this context most likely from a multipart/form-data transmission. > > On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > > Sorry, for the last mail, here it's what you asked: > > > > {'CONTENT_LENGTH': '61', > > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > > boundary=---------------------------8905735096173894531259794847', > > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > > [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite', > > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > > [Thu Sep 30 13:35:07 2010] > > [error] > > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', [Thu > > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > > [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > > [Thu Sep 30 13:35:07 2010] [error] 'close', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > > [Thu Sep 30 13:35:07 2010] > > [error] 'http://hidura.webfactional.com/?md=btdump', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux x86_64; > > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10', > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > > [Thu Sep 30 13:35:07 2010] [error] '58742', > > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > > [Thu Sep 30 13:35:07 2010] [error] 'POST', > > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > > [Thu Sep 30 13:35:07 2010] > > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > > [Thu Sep 30 13:35:07 2010] [error] '80', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 > > Python/3.1', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > > [Thu Sep 30 13:35:07 2010] [error] 'application', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > > [Thu Sep 30 13:35:07 2010] [error] '0', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > > [Thu Sep 30 13:35:07 2010] [error] '51543', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > > [Thu Sep 30 13:35:07 2010] [error] '', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > > [Thu Sep 30 13:35:07 2010] [error] '1', > > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > > [Thu Sep 30 13:35:07 2010] [error] , > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > > [Thu Sep 30 13:35:07 2010] [error] , > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > > [Thu Sep 30 13:35:07 2010] [error] , > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > > [Thu Sep 30 13:35:07 2010] [error] False, > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > > [Thu Sep 30 13:35:07 2010] [error] True, > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > > [Thu Sep 30 13:35:07 2010] [error] False, > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > > [Thu Sep 30 13:35:07 2010] [error] 'http', > > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > > > > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > > > *sigh* > > > > > > > > > > > > AGAIN, please do *not* reply to me personally. Reply to the ML or NG > > > > you are posting in. I'm beginning to believe that it's a waste of time to > > answer you since you seem not able to follow even the most simple of > > advice and rules. > > > > > And read the answers you get thoroughly, you did not give all the > > > > information I asked you for. > > > > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > > > The output is: > > > > > > > > > > > > > > > > -----------------------------110550484811701713451664404475--\r > > > > > > > > > > > > > > > > No more i don 't know what that means or what do with this. > > > > > > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: > > > > > hidura at gmail.com writes: > > > > > > Hello list, i had seriously troubles with the connection between > > > > a form and the > > > > > > > > wsgi, i' ve made an application on Python3 and was running > > > > perfectly but when i > > > > > > > > try to use the to pass the data this can't be see on the server, > > > > so what > > > > > > > > is your recommendation?, i am open to all the ideas less leave to > > > > Python2 i > > > > > > > > can't all the project was write on Python3, i was looking into > > > > the PEP 444 > > > > > > > > proposal too. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Here is the code what i used to take the data: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro > > > > > > n > > > > > > > > > > > > > > > > > > > > > > > > ['CONTENT_LENGTH'])).decode())) > > > > > > > > > > What is the ouptut of this? What does > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > import pprint > > > > > > > > > > > > > > > > > > > > pprint.pprint(environ) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > give you? > > > > > > > > > > > and here it's what the os.environ.item() prints to me: > > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Diez > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > > > > > > > > > http://mail.python.org/mailman/listinfo/python-list From gene.ressler at gmail.com Thu Sep 30 16:06:53 2010 From: gene.ressler at gmail.com (Gene) Date: Thu, 30 Sep 2010 13:06:53 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: On Sep 30, 3:45?pm, RG wrote: > In article <7xr5gbxfry.... at ruckus.brouhaha.com>, > ?Paul Rubin wrote: > > > > > > > RG writes: > > > Yes, I know I could have used lint. ?But that misses the point. ?For any > > > static analyzer, because of the halting problem, I can construct a > > > program that either contains an error that the analyzer will not catch, > > > or for which the analyzer will produce a false positive. > > > Can you describe any plausible real-world programs where the effort of > > complicated static is justified, and for which the halting problem gets > > in the way of analysis? ?By "real world", I meanI wouldn't consider > > searching for counterexamples to the Collatz conjecture to qualify as > > sufficiently real-world and sufficiently complex for fancy static > > analysis. ?And even if it did, the static analyzer could deliver a > > partial result, like "this function either returns a counterexample to > > the Collatz conjecture or else it doesn't return". ? > > > D. Turner wrote a famous paper arguing something like the above, saying > > basically that Turing completeness of programming languages is > > overrated: > > > ?http://www.jucs.org/jucs_10_7/total_functional_programming > > > The main example of a sensible program that can't be written in a > > non-complete language is an interpreter for a Turing-complete language. > > But presumably a high-assurance application should never contain such a > > thing, since the interpreted programs themselves then wouldn't have > > static assurance. > > There are only two possibilities: either you have a finite-state > machine, or you have a Turning machine. ?(Well, OK, you could have a > pushdown automaton, but there are no programming languages that model a > PDA. ?Well, OK, there's Forth, but AFAIK there are no static type > checkers for Forth. ?Besides, who uses Forth? ;-) > > If you have a finite state machine everything is trivial. ?If you have a > Turing machine everything is generally impossible. ?This is an > oversimplification but not far from the fundamental underlying truth. > > My favorite practical example is the square root function. ?The standard > C library defines a square root function on floats (actually on > doubles), which is to say, over a finite-state model with 2^64 states. ? > The model is not well defined over half of that range (negative > numbers), which the static type checker cannot catch because there is no > such thing as an unsigned double. > > But the fun doesn't stop there. ?Doubles >= 0.0 are not the only thing > one might reasonably want to take a square root of, and indeed C++ > overloads sqrt to work on complex and valarray types in addition to > floats of various lengths (though you still have to manually keep track > of whether or not the argument to sqrt might be a negative real). ?But > what if I want an exact integer square root? ?Or a square root of a data > type that represents irrational numbers not as floating point > approximations but as exact symbolic representations? ?I haven't worked > out the details, but I'd be surprised if none of these variations turned > out to be Turing complete. > > The Turner paper is right on point: there's a fundamental distinction > between the (known) finite and the (potentially) infinite. ?In my > experience most of the cool interesting stuff has been found in the > latter domain, and trying to shoehorn the latter into the former is more > trouble then it's worth. > The FA or TM dichotomy is more painful to contemplate than you say. Making appropriate simplifications for input, any modern computer is a FA with 2^(a few trillion) states. Consequently, the gestalt of computer science seems to be to take it on faith that at some very large number of states, the FA behavior makes a transition to TM behavior for all possible practical purposes (and I mean all). So what is it--really--that's trivial to analyze? And what is impossible? I'm sorry this is drifting OT and will stop here. From rNOSPAMon at flownet.com Thu Sep 30 16:14:18 2010 From: rNOSPAMon at flownet.com (RG) Date: Thu, 30 Sep 2010 13:14:18 -0700 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: In article , Keith Thompson wrote: > RG writes: > > In article , > > Seebs wrote: > > > >> On 2010-09-30, Lie Ryan wrote: > >> > On 09/30/10 16:09, TheFlyingDutchman wrote: > >> >> Dynamic typed languages like Python fail in this case on "Never blows > >> >> up". > >> > >> > How do you define "Never blows up"? > >> > >> I would say "blow up" would be "raise an exception". > >> > >> > Personally, I'd consider maximum(8589934592, 1) returning 1 as a blow > >> > up, and of the worst kind since it passes silently. > >> > >> So run your compiler with a decent set of warning levels, and watch as > >> you are magically warned that you're passing an object of the wrong type. > > > > My code compiles with no warnings under gcc -Wall. > > Conclusion: "-Wall" is not "a decent set of warning levels" in this > context, in spite of the name. (If you want to complain that the > name "-Wall" is misleading, I won't disagree, but it's a gcc issue, > not a C issue.) > > With "-Wconversion", I get: > > c.c: In function 'main': > c.c:7: warning: passing argument 1 of 'maximum' with different width due to > prototype > > [...] That gives (what I would consider to be) false positives, e.g.: [ron at mighty:~]$ cat foo.c void foo(long x) {} int main() { foo(1); } [ron at mighty:~]$ gcc -Wconversion foo.c foo.c: In function ?main?: foo.c:4: warning: passing argument 1 of ?foo? with different width due to prototype > >> On any given system, one or the other is true: > >> > >> 1. The constant 8589934592 is of type int, and the function will > >> "work" -- will give that result. > >> 2. The constant is not of type int, and the compiler will warn you about > >> this if you ask. > > > > It would be nice if this were true, but my example clearly demonstrates > > that it is not. And if your response is to say that I should have used > > lint, then my response to that will be that because of the halting > > problem, for any static analyzer that you present, I can construct a > > program that either contains an error that either your analyzer will not > > catch, or for which it will generate a false positive. It just so > > happens that constructing such examples for standard C is very easy. > > And yet you have not managed to do it. Actually I have. Twice now. Remember, the claim is not that the compiler will fail to warn. It's trivial to never fail to warn simply by always warning. The claim is that the compiler with *either* fail to warn *or* generate false positives. So you have to choose your compiler (and flags) first, and then I get to construct my example. If my example has *either* an error that the compiler doesn't catch *or* a non-error that it does catch then I win. Want to try another round? rg From pjb at informatimago.com Thu Sep 30 16:17:45 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 22:17:45 +0200 Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: <87mxqzm1ee.fsf@kuiper.lan.informatimago.com> RG writes: >> The main example of a sensible program that can't be written in a >> non-complete language is an interpreter for a Turing-complete language. >> But presumably a high-assurance application should never contain such a >> thing, since the interpreted programs themselves then wouldn't have >> static assurance. > > There are only two possibilities: either you have a finite-state > machine, or you have a Turning machine. (Well, OK, you could have a > pushdown automaton, but there are no programming languages that model a > PDA. Well, OK, there's Forth, but AFAIK there are no static type > checkers for Forth. Besides, who uses Forth? ;-) > > If you have a finite state machine everything is trivial. If you have a > Turing machine everything is generally impossible. This is an > oversimplification but not far from the fundamental underlying truth. All our computers are FSA: they don't have infinite memory. Even if we developed a robot able to crunch stellar matter and use it as memory, it would still NOT be a Turing Machine, since the universe is finite, has finite matter and energy. Therefore it's trivial. (Indeed, the answer is 42). Now the problem is rather our minds. We use the notion of mathematical infinite, and of Turing Machines vs. DFA, because beyond a certain size, a DFA is not manageable any more by our little minds, and also, computationnaly. While it's finite, computing its most of its properties will require more time than the universe (which is also limited in time). So we need another conceptualization to reduce the complexity of big DFAs. Turing Machines are much simplier, they just slip the complexity under the infinite tape (which conceptually is rather simple, as long as you don't try to reach the end of the tape, or you don't try to use it to weave an infinite rug... -- __Pascal Bourguignon__ http://www.informatimago.com/ From pjb at informatimago.com Thu Sep 30 16:20:20 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 22:20:20 +0200 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> Message-ID: <87iq1nm1a3.fsf@kuiper.lan.informatimago.com> Ian Collins writes: > On 10/ 1/10 02:57 AM, Pascal Bourguignon wrote: >> Nick Keighley writes: >> >>> On 27 Sep, 20:29, p... at informatimago.com (Pascal J. Bourguignon) >>> wrote: >>>> If you start with the mindset of static type checking, you will consider >>>> that your types are checked and if the types at the interface of two >>>> modules matches you'll think that everything's ok. And six months later >>>> you Mars mission will crash. >>> >>> do you have any evidence that this is actually so? That people who >>> program in statically typed languages actually are prone to this "well >>> it compiles so it must be right" attitude? >> >> Yes, I can witness that it's in the mind set. >> >> Well, the problem being always the same, the time pressures coming from >> the sales people (who can sell products of which the first line of >> specifications has not been written yet, much less of code), it's always >> a battle to explain that once the code is written, there is still a lot >> of time needed to run tests and debug it. I've even technical managers, >> who should know better, expecting that we write bug-free code in the >> first place (when we didn't even have a specification to begin with!). > > Which is why agile practices such as TDD have an edge. If it compiles > *and* passes all its tests, it must be right. Well, at least it passes the test. I would like to see a peer reviewed proof that the program is correct ;-) But indeed tests are required in any case. -- __Pascal Bourguignon__ http://www.informatimago.com/ From no.email at nospam.invalid Thu Sep 30 16:21:45 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 13:21:45 -0700 Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xr5gbxfry.fsf@ruckus.brouhaha.com> Message-ID: <7xtyl7oucm.fsf@ruckus.brouhaha.com> RG writes: > There are only two possibilities: either you have a finite-state > machine, or you have a Turning machine. (Well, OK, you could have a > pushdown automaton, but there are no programming languages that model a > PDA. The point is that the halting problem for general Turing machines is undecidable, but there is a subset of the Turing machines, in which the halting problem is decidable. And it turns out that the decidable subset is substantial enough to write almost every program anyone usually wants to write in practice. > Well, OK, there's Forth, but AFAIK there are no static type > checkers for Forth. http://home.vrweb.de/stephan.becher/forth/ but anyway, Forth is Turing-complete. > If you have a finite state machine everything is trivial. If you have a > Turing machine everything is generally impossible. This is an > oversimplification but not far from the fundamental underlying truth. I'm sorry, but I don't think you understand the actual situation enough to be making pronouncements like that. The stuff about finite-state machines isn't even slightly relevant. > The Turner paper is right on point: there's a fundamental distinction > between the (known) finite and the (potentially) infinite. In my > experience most of the cool interesting stuff has been found in the > latter domain, and trying to shoehorn the latter into the former is more > trouble then it's worth. The point of the Turner paper is that you can design a language with separate types for finite data (like arrays) and "infinite" data (like an endless stream of requests going into a server). Such a language can restrict you to writing provably halting programs on the finite data, and provably non-halting programs on the infinite data. That is, the language doesn't let you write infinite loops on finite data or break out of infinite loops on infinite data (you can only shut down your server by "unplugging the computer", e.g. by killing the process externally). The claim is that these two classes of programs are enough for most purposes. The third possible class, the programs like the Collatz searcher where you can't tell by static analysis whether the program halts, just isn't that important. The paper argues that by giving up the ability to express those undecidable programs, a language can gain other advantages that make up for the loss of Turing-completeness most of the time. I don't think anyone has suggested languages like that are a great idea for everyday programming, but obviously there can be metholodogies that use such approaches for special purposes. From pjb at informatimago.com Thu Sep 30 16:25:56 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 30 Sep 2010 22:25:56 +0200 Subject: "Strong typing vs. strong testing" References: <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: <87eicbm10r.fsf@kuiper.lan.informatimago.com> Keith Thompson writes: > const double pi = 2.71828182845904523526; > > To a human reader, it's obviously either a mistake or deliberate > obfuscation, but I'm not sure I'd *want* my compiler to warn me > about it just because I named the object "pi" rather than "e". > (And if I called it "x", even an intelligent human wouldn't know > that it's wrong.) Well, you see, I think it would be perfectly nice from a compiler to provide a warning if you gave that value to a variable named pi. On the other hand, I'd expect an error where gcc only gives warning (I usually compile with -Werror, but that should be the default). -- __Pascal Bourguignon__ http://www.informatimago.com/ From kst-u at mib.org Thu Sep 30 16:34:44 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 13:34:44 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> Message-ID: Seebs writes: > On 2010-09-30, Keith Thompson wrote: >> Seebs writes: >>> On 2010-09-30, Paul Rubin wrote: >>>> int maximum(int a, int b); > >>>> int foo() { >>>> int (*barf)() = maximum; >>>> return barf(3); >>>> } > >> That first line declare barf as an object of type "pointer to >> function returning int", or more precisely, "pointer to function with >> an unspecified but fixed number and type of parameters returning int" >> (i.e., an old-style non-prototype declaration, still legal but >> deprecated in both C90 and C99). It then initializes it to point >> to the "maximum" function. I *think* the types are sufficiently >> "compatible" (not necessarily using that word the same way the >> standard does) for the initialization to be valid and well defined. >> I might check the standard later. > > Hmm. You have a point. It's clearly a conversion from one type > to another. If I'm reading 6.7.5.3p15 correctly, the types int (*)() and int (*)(int, int) are compatible, so the declaration and initialization of barf is perfectly legal, and a call bar(3, 4) would also be legal and would return 4. I actually didn't notice on my initial reading that the call is passing the wrong number of arguments. Since the type of barf doesn't specify the number or types of the arguments, no diagnostic is required, but the behavior is undefined. >> IMHO it's better to use prototypes consistently than to figure out the >> rules for interactions between prototyped vs. non-prototyped function >> declarations. > > Yes. It's clearly undefined behavior to call a function through a > pointer to a different type, or to call a function with the wrong number > of arguments. I am pretty sure at least one compiler catches this. The former is not a problem here; the type of barf is compatible with the type of a pointer to maximum. The latter is the problem, and a sufficiently clever compiler can warn about it. Note that you could do something silly like this: int one_param(int a); int two_params(int a, int b); int (*barf)(); if (some_condition) { barf = one_param; } else { barf = two_params; } if (some_other_condition) { barf(1); } else { barf(2, 3); } No constraint violations, and no undefined behavior as long as some_condition and some_other_condition have the same value. The best a compiler can do (unless it knows about the conditions) is warn you that something *might* go wrong. For programmers, the solution is simple: *Don't do that!*. -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From no.email at nospam.invalid Thu Sep 30 16:36:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 13:36:40 -0700 Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: <7xpqvvotnr.fsf@ruckus.brouhaha.com> RG writes: > I don't want to quibble over terminology. Whatever label you choose to > put on it ("false positive", "not being able to express some things > without special extra effort") I consider it a deficiency. The costs > are greater than the benefits. Reasonable people can (and obviously do) > disagree. Chris Smith's essay "What To Know Before Debating Type Systems" discusses the question basically that way, without taking either side. It's well worth reading: http://web.archive.org/web/20080822101209/http://www.pphsg.org/cdsmith/types.html From deets at web.de Thu Sep 30 16:55:13 2010 From: deets at web.de (Diez B. Roggisch) Date: Thu, 30 Sep 2010 22:55:13 +0200 Subject: Problems with wsgi Python3 References: <90e6ba4fc20672903204917f4555@google.com> Message-ID: Thomas Jollans writes: > On Thursday 30 September 2010, it occurred to hidura at gmail.com to exclaim: >> What mean this >> -----------------------------743346150198628700241600224--\r? > > it looks like a MIME boundary. In this context most likely from a > multipart/form-data transmission. yep, as one can see in the headers below. Additonally, it looks to me as if the form you are submitting is empty. The content-length of just 61 matches barely the boundary. Use something like pdict = cgi.parse_header(environ["CONTENT_TYPE"])[1] cgi.parse_multipart(environ["wsgi.input"], pdict) to properly parse the request. But then of course actually upload something. Diez > >> >> On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: >> > Sorry, for the last mail, here it's what you asked: >> > >> > {'CONTENT_LENGTH': '61', >> > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': >> > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; >> > boundary=---------------------------8905735096173894531259794847', >> > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': >> > [Thu Sep 30 13:35:07 2010] [error] '/home/hidura/webapps/karinapp/Suite', >> > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': >> > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': >> > [Thu Sep 30 13:35:07 2010] >> > [error] >> > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', [Thu >> > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': >> > [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': >> > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': >> > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': >> > [Thu Sep 30 13:35:07 2010] [error] 'close', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': >> > [Thu Sep 30 13:35:07 2010] >> > [error] 'http://hidura.webfactional.com/?md=btdump', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': >> > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux x86_64; >> > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10', >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': >> > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', >> > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': >> > [Thu Sep 30 13:35:07 2010] [error] '58742', >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': >> > [Thu Sep 30 13:35:07 2010] [error] 'POST', >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': >> > [Thu Sep 30 13:35:07 2010] >> > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': >> > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': >> > [Thu Sep 30 13:35:07 2010] [error] '80', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': >> > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 >> > Python/3.1', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': >> > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': >> > [Thu Sep 30 13:35:07 2010] [error] 'application', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': >> > [Thu Sep 30 13:35:07 2010] [error] '0', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': >> > [Thu Sep 30 13:35:07 2010] [error] '51543', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': >> > [Thu Sep 30 13:35:07 2010] [error] '', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': >> > [Thu Sep 30 13:35:07 2010] [error] '1', >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': >> > [Thu Sep 30 13:35:07 2010] [error] (3, 3), >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': >> > [Thu Sep 30 13:35:07 2010] [error] , >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': >> > [Thu Sep 30 13:35:07 2010] [error] , >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': >> > [Thu Sep 30 13:35:07 2010] [error] , >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': >> > [Thu Sep 30 13:35:07 2010] [error] False, >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': >> > [Thu Sep 30 13:35:07 2010] [error] True, >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': >> > [Thu Sep 30 13:35:07 2010] [error] False, >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': >> > [Thu Sep 30 13:35:07 2010] [error] 'http', >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': >> > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} >> > >> > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: >> > > *sigh* >> > > >> > > >> > > >> > > AGAIN, please do *not* reply to me personally. Reply to the ML or NG >> > >> > you are posting in. I'm beginning to believe that it's a waste of time to >> > answer you since you seem not able to follow even the most simple of >> > advice and rules. >> > >> > > And read the answers you get thoroughly, you did not give all the >> > >> > information I asked you for. >> > >> > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: >> > > > The output is: >> > > > >> > > > >> > > > >> > > > -----------------------------110550484811701713451664404475--\r >> > > > >> > > > >> > > > >> > > > No more i don 't know what that means or what do with this. >> > > > >> > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: >> > > > > hidura at gmail.com writes: >> > > > > > Hello list, i had seriously troubles with the connection between >> > >> > a form and the >> > >> > > > > > wsgi, i' ve made an application on Python3 and was running >> > >> > perfectly but when i >> > >> > > > > > try to use the to pass the data this can't be see on the server, >> > >> > so what >> > >> > > > > > is your recommendation?, i am open to all the ideas less leave to >> > >> > Python2 i >> > >> > > > > > can't all the project was write on Python3, i was looking into >> > >> > the PEP 444 >> > >> > > > > > proposal too. >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > Here is the code what i used to take the data: >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro >> > > > > > n >> > > > > > >> > > > > > >> > > > > > >> > > > > > ['CONTENT_LENGTH'])).decode())) >> > > > > >> > > > > What is the ouptut of this? What does >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > import pprint >> > > > > >> > > > > >> > > > > >> > > > > pprint.pprint(environ) >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > give you? >> > > > > >> > > > > > and here it's what the os.environ.item() prints to me: >> > > > > That's irrelevant. The WSGI-environ is what is needed. >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > Diez >> > > > > >> > > > > >> > > > > >> > > > > -- >> > > > > >> > > > > >> > > > > >> > > > > http://mail.python.org/mailman/listinfo/python-list From kst-u at mib.org Thu Sep 30 17:02:06 2010 From: kst-u at mib.org (Keith Thompson) Date: Thu, 30 Sep 2010 14:02:06 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> Message-ID: RG writes: [...] > You're missing a lot of context. I'm not trying to criticize C, just to > refute a false claim that was made about it. Can you cite the article that made this false claim, and exactly what the false claim was? -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From dsrtegle at gmail.com Thu Sep 30 17:06:14 2010 From: dsrtegle at gmail.com (Dsrt Egle) Date: Thu, 30 Sep 2010 14:06:14 -0700 (PDT) Subject: Pyflakes and IPython does not work for Emacs on Windows? References: Message-ID: On Sep 24, 4:53?pm, David Robinow wrote: > On Fri, Sep 24, 2010 at 4:59 PM,DsrtEgle wrote: > > ... > > I can't invoke IPython by Emacs on Windows, either. Looks ipyhon.el > > only works for Linux? > > There don't appear to be a lot of ipython.el users on Windows. > You may have better look on an emacs list since there appear to be > some configuration issues. > Doeshttps://bugs.launchpad.net/ipython/+bug/290228? ? help at all? Hi David, This fix seems not working for me. I am using IPython 0.10, Python 2.5, and EmacsW32 23.1. When I invoke python-shell in Emacs, IPython crashes with the following long debugging information: ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (14, 0)) --------------------------------------------------------------------------- TypeError Python 2.5.2: C: \Python25\python.exe Thu Sep 30 14:00:08 2010 A problem occured executing Python code. Here is the sequence of function calls leading up to the error, with the most recent (innermost) call last. c:\Python25\Scripts\ipython-script.py in () 1 2 3 4 5 6 7 ----> 8 global load_entry_point = 9 #!C:\Python25\python.exe 10 # EASY-INSTALL-ENTRY-SCRIPT: 'ipython==0.10','console_scripts','ipython' 11 __requires__ = 'ipython==0.10' 12 import sys 13 from pkg_resources import load_entry_point 14 15 sys.exit( 16 load_entry_point('ipython==0.10', 'console_scripts', 'ipython')() 17 ) 18 19 20 21 22 23 24 25 26 27 28 29 30 31 C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\ipapi.pyc in launch_new_instance(user_ns=None, shellclass=None) 541 542 def check_hotname(self,name): 543 if name in self.hotnames: 544 self.debug_stack( "HotName '%s' caught" % name) 545 546 547 def launch_new_instance(user_ns = None,shellclass = None): 548 """ Make and start a new ipython instance. 549 550 This can be called even without having an already initialized 551 ipython session running. 552 553 This is also used as the egg entry point for the 'ipython' script. 554 555 """ --> 556 ses = make_session(user_ns,shellclass) 557 ses.mainloop() 558 559 560 def make_user_ns(user_ns = None): 561 """Return a valid user interactive namespace. 562 563 This builds a dict with the minimal information needed to operate as a 564 valid IPython user namespace, which you can pass to the various embedding 565 classes in ipython. 566 567 This API is currently deprecated. Use ipapi.make_user_namespaces() instead 568 to make both the local and global namespace objects simultaneously. 569 570 :Parameters: 571 user_ns : dict-like, optional C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\ipapi.pyc in make_session(user_ns=None, shellclass=None) 669 670 def make_session(user_ns = None, shellclass = None): 671 """Makes, but does not launch an IPython session. 672 673 Later on you can call obj.mainloop() on the returned object. 674 675 Inputs: 676 677 - user_ns(None): a dict to be used as the user's namespace with initial 678 data. 679 680 WARNING: This should *not* be run when a session exists already.""" 681 682 import IPython.Shell 683 if shellclass is None: --> 684 return IPython.Shell.start(user_ns) 685 return shellclass(user_ns = user_ns) 686 687 688 689 690 691 692 693 694 695 696 697 698 699 C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\Shell.pyc in start(user_ns=None) 1226 th_mode = special_opts.pop() 1227 except KeyError: 1228 th_mode = 'tkthread' 1229 return th_shell[th_mode] 1230 1231 1232 # This is the one which should be called by external code. 1233 def start(user_ns = None): 1234 """Return a running shell instance, dealing with threading options. 1235 1236 This is a factory function which will instantiate the proper IPython shell 1237 based on the user's threading choice. Such a selector is needed because 1238 different GUI toolkits require different thread handling details.""" 1239 1240 shell = _select_shell(sys.argv) -> 1241 return shell(user_ns = user_ns) 1242 1243 # Some aliases for backwards compatibility 1244 IPythonShell = IPShell 1245 IPythonShellEmbed = IPShellEmbed 1246 #************************ End of file *************************** 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\Shell.pyc in __init__(self=, argv=None, user_ns=None, user_global_ns=None, debug=1, shell_class=) 58 # Default timeout for waiting for multithreaded shells (in seconds) 59 GUI_TIMEOUT = 10 60 61 #----------------------------------------------------------------------------- 62 # This class is trivial now, but I want to have it in to publish a clean 63 # interface. Later when the internals are reorganized, code that uses this 64 # shouldn't have to change. 65 66 class IPShell: 67 """Create an IPython instance.""" 68 69 def __init__(self,argv=None,user_ns=None,user_global_ns=None, 70 debug=1,shell_class=InteractiveShell): 71 self.IP = make_IPython(argv,user_ns=user_ns, 72 user_global_ns=user_global_ns, ---> 73 debug=debug,shell_class=shell_class) global that = undefined global gets = undefined global prepended = undefined global to = undefined global all = undefined global calls = undefined global so = undefined global header = undefined global used = undefined 74 75 def mainloop(self,sys_exit=0,banner=None): 76 self.IP.mainloop(banner) 77 if sys_exit: 78 sys.exit() 79 80 #----------------------------------------------------------------------------- 81 def kill_embedded(self,parameter_s=''): 82 """%kill_embedded : deactivate for good the current embedded IPython. 83 84 This function (after asking for confirmation) sets an internal flag so that 85 an embedded IPython will never activate again. This is useful to 86 permanently disable a shell that is being called inside a loop: once you've 87 figured out what you needed from it, you may then kill it and the program 88 will then continue to run without the interactive shell interfering again. C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython \ipmaker.pyc in make_IPython(argv=[r'c:\Python25\Scripts\ipython- script.py', '-i'], user_ns=None, user_global_ns=None, debug=1, rc_override=None, shell_class=, embedded=False, **kw={}) 755 IP_rc.banner = 0 756 if IP_rc.banner: 757 BANN_P = IP.BANNER_PARTS 758 else: 759 BANN_P = [] 760 761 if IP_rc.profile: BANN_P.append('IPython profile: %s\n' % IP_rc.profile) 762 763 # add message log (possibly empty) 764 if msg.summary: BANN_P.append(msg.summary) 765 # Final banner is a string 766 IP.BANNER = '\n'.join(BANN_P) 767 768 # Finalize the IPython instance. This assumes the rc structure is fully 769 # in place. --> 770 IP.post_config_initialization() 771 772 return IP 773 #************************ end of file ************************** 774 775 776 777 778 779 780 781 782 783 784 785 C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\iplib.pyc in post_config_initialization(self=) 847 This is called after the configuration files have been processed to 848 'finalize' the initialization.""" 849 850 rc = self.rc 851 852 # Object inspector 853 self.inspector = OInspect.Inspector(OInspect.InspectColors, 854 PyColorize.ANSICodeColors, 855 'NoColor', 856 rc.object_info_string_level) 857 858 self.rl_next_input = None 859 self.rl_do_indent = False 860 # Load readline proper 861 if rc.readline: --> 862 self.init_readline() 863 864 # local shortcut, this is used a LOT 865 self.log = self.logger.log 866 867 # Initialize cache, set in/out prompts and printing system 868 self.outputcache = CachedOutput(self, 869 rc.cache_size, 870 rc.pprint, 871 input_sep = rc.separate_in, 872 output_sep = rc.separate_out, 873 output_sep2 = rc.separate_out2, 874 ps1 = rc.prompt_in1, 875 ps2 = rc.prompt_in2, 876 ps_out = rc.prompt_out, 877 pad_left = rc.prompts_pad_left) C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\iplib.pyc in init_readline(self=) 1476 if not readline.uses_libedit: 1477 for rlcommand in self.rc.readline_parse_and_bind: 1478 #print "loading rl:",rlcommand # dbg 1479 readline.parse_and_bind(rlcommand) 1480 1481 # Remove some chars from the delimiters list. If we encounter 1482 # unicode chars, discard them. 1483 delims = readline.get_completer_delims().encode("ascii", "ignore") 1484 delims = delims.translate(string._idmap, 1485 self.rc.readline_remove_delims) 1486 readline.set_completer_delims(delims) 1487 # otherwise we end up with a monster history after a while: 1488 readline.set_history_length(1000) 1489 try: 1490 #print '*** Reading readline history' # dbg -> 1491 readline.read_history_file(self.histfile) 1492 except IOError: 1493 pass # It doesn't exist yet. 1494 1495 atexit.register(self.atexit_operations) 1496 del atexit 1497 1498 # Configure auto-indent for all platforms 1499 self.set_autoindent(self.rc.autoindent) 1500 1501 def ask_yes_no(self,prompt,default=True): 1502 if self.rc.quiet: 1503 return True 1504 return ask_yes_no(prompt,default) 1505 1506 def new_main_mod(self,ns=None): C:\Python25\lib\site-packages\pyreadline\rlmain.pyc in read_history_file(self=, filename=u'C:\\Home\\_ipython\\history') 168 169 def set_history_length(self, length): 170 '''Set the number of lines to save in the history file. 171 172 write_history_file() uses this value to truncate the history file 173 when saving. Negative values imply unlimited history file size. 174 ''' 175 self._history.set_history_length(length) 176 177 def clear_history(self): 178 '''Clear readline history''' 179 self._history.clear_history() 180 181 def read_history_file(self, filename=None): 182 '''Load a readline history file. The default filename is ~/.history.''' --> 183 self._history.read_history_file(filename) 184 185 def write_history_file(self, filename=None): 186 '''Save a readline history file. The default filename is ~/.history.''' 187 self._history.write_history_file(filename) 188 189 #Completer functions 190 191 def set_completer(self, function=None): 192 '''Set or remove the completer function. 193 194 If function is specified, it will be used as the new completer 195 function; if omitted or None, any completer function already 196 installed is removed. The completer function is called as 197 function(text, state), for state in 0, 1, 2, ..., until it returns a 198 non-string value. It should return the next possible completion C:\Python25\lib\site-packages\pyreadline\lineeditor\history.pyc in read_history_file(self=, filename=u'C:\\Home\\_ipython\\history') 55 56 history_length=property(get_history_length,set_history_length) 57 history_cursor=property(get_history_cursor,set_history_cursor) 58 59 def clear_history(self): 60 '''Clear readline history.''' 61 self.history[:] = [] 62 self.history_cursor = 0 63 64 def read_history_file(self, filename=None): 65 '''Load a readline history file.''' 66 if filename is None: 67 filename=self.history_filename 68 try: 69 for line in open(filename, 'r'): ---> 70 self.add_history(lineobj.ReadLineTextBuffer(ensure_unicode(line.rstrip()))) global n = undefined global Xd = undefined global S = undefined global NR = undefined global i = undefined global R2 = undefined global R = undefined global t = undefined global history_search_forwardt = undefined global history_search_backwardt = undefined global joinR2 = undefined global maxR = undefined global mint = undefined global IndexError = undefined global RX = undefined global partialt = undefined global hcstartt = undefined global hct = undefined global ht = undefined global result = undefined global s = undefined global C = undefined global Python25 = undefined global lib = undefined global site = undefined global packages = undefined global pyreadline = global lineeditor = undefined global history.pyt = undefined global _search = undefined global I = undefined global c = undefined global d = undefined global Search = undefined global forward = undefined global through = undefined global the = undefined global history = undefined global string = global of = undefined global characters = undefined global between = undefined global start = undefined global current = undefined line = 'import sys\n' global point.This = undefined global a = undefined global non = undefined global incremental = undefined global search.By = undefined global default = undefined global this = undefined global command = undefined global unbound.i = undefined global Rj = undefined global Re = undefined global q = undefined global history.pyR_ = undefined global backward = undefined global Rk = undefined global history.pyR = undefined global N = undefined global propertyR = undefined global R4 = undefined global R5 = undefined global R7 = undefined global R8 = undefined global RC = undefined global RD = undefined global R_ = undefined global s.t = undefined Press enter to exit: global __main__t = undefined global aaaat = undefined global aabat = undefined global aacat = undefined global akcat = undefined global bbbt = undefined global ako = undefined global ret = undefined global operatorRS = undefined global sysR = undefined global pyreadline.unicode_helperR = undefined global modulesR = undefined global exceptionst = undefined global ExceptionR = undefined global pyreadline.loggerR = undefined global FalseR9 = undefined global objectR = undefined global RLR = undefined global history.pys = undefined global module = undefined 71 except IOError: 72 self.history = [] 73 self.history_cursor = 0 74 75 def write_history_file(self, filename=None): 76 '''Save a readline history file.''' 77 if filename is None: 78 filename=self.history_filename 79 fp = open(filename, 'wb') 80 for line in self.history[-self.history_length:]: 81 fp.write(ensure_str(line.get_line_text())) 82 fp.write('\n') 83 fp.close() 84 85 C:\Python25\lib\site-packages\pyreadline\unicode_helper.pyc in ensure_unicode(text='import sys') 5 # Distributed under the terms of the BSD License. The full license is in 6 # the file COPYING, distributed as part of this software. 7 #***************************************************************************** 8 import sys 9 10 try: 11 pyreadline_codepage=sys.stdout.encoding 12 except AttributeError: #This error occurs when pdb imports readline and doctest has replaced 13 #stdout with stdout collector 14 pyreadline_codepage="ascii" #assume ascii codepage 15 16 17 def ensure_unicode(text): 18 """helper to ensure that text passed to WriteConsoleW is unicode""" 19 if isinstance(text, str): ---> 20 return text.decode(pyreadline_codepage, "replace") 21 return text 22 23 def ensure_str(text): 24 """Convert unicode to str using pyreadline_codepage""" 25 if isinstance(text, unicode): 26 return text.encode(pyreadline_codepage, "replace") 27 return text 28 29 30 31 32 33 34 35 TypeError: decode() argument 1 must be string, not None ********************************************************************** Oops, IPython crashed. We do our best to make it stable, but... A crash report was automatically generated with the following information: - A verbatim copy of the crash traceback. - A copy of your input history during this session. - Data on your current IPython configuration. It was left in the file named: 'C:\Home\_ipython\IPython_crash_report.txt' If you can email this file to the developers, the information in it will help them in understanding and correcting the problem. You can mail it to: Fernando Perez at fperez.net at gmail.com with the subject 'IPython Crash Report'. If you want to do it now, the following command will work (under Unix): mail -s 'IPython Crash Report' fperez.net at gmail.com < C:\Home\_ipython \IPython_crash_report.txt To ensure accurate tracking of this issue, please file a report about it at: https://bugs.launchpad.net/ipython/+filebug From usenet-nospam at seebs.net Thu Sep 30 17:24:31 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 21:24:31 GMT Subject: "Strong typing vs. strong testing" References: <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, RG wrote: > I don't want to quibble over terminology. May I suggest that, if you don't want to use words and terminology precisely, perhaps computer programming is not for you? > Whatever label you choose to > put on it ("false positive", "not being able to express some things > without special extra effort") I consider it a deficiency. Oh, it definitely is a deficiency. However, the deficiency is that you have to do extra work to get data safely in, and you have to figure out for yourself how you want to handle things if, say, you have a value which is not of the right type, and you want to make it be of the right type, but it may not be possible to do so. It is, however, entirely possible to write a function which returns the maximum of its two inputs, 100% reliably, in C. > The costs are greater than the benefits. Reasonable people can > (and obviously do) disagree. I tend to think it depends on what I'm trying to do, and why I'm trying to do it. There are plenty of tasks for which I prefer C's semantics to those of most scripting languages -- and others for which I prefer scripting language semantics. In practice, I have dozens to hundreds of times more problems with scripting languages where something ends up being of the wrong type (or more precisely, not of any of the types which can be used in that context) than I have, say, overflow problems in C. On the other hand, it's usually much easier to catch them and deal with 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 no.email at nospam.invalid Thu Sep 30 17:25:36 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 14:25:36 -0700 Subject: "Strong typing vs. strong testing" References: <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <5bf24e59-1be0-4d31-9fa7-c03a8bf9bd21@y12g2000prb.googlegroups.com> <7xlj6j3bh2.fsf@ruckus.brouhaha.com> <785d0d80-c4ec-4e02-94ff-fe18dc4a7ddd@e34g2000prn.googlegroups.com> Message-ID: <7xhbh6q5yn.fsf@ruckus.brouhaha.com> TheFlyingDutchman writes: > With Tiny C on my system, your code does not cause maximum to give an > incorrect value, or to blow up: > > int maximum(int a, int b) > { > printf("entering maximum %d %d\n",a,b); > if ( a > b ) > return a; > else > return b; > } What did printf show as "b" when you ran it? If that code worked at all, it was by accident. Try changing the name "maximum" to "minimum" and change the ">" to "<", compile the same program, and see if you still get a correct value. From usenet-nospam at seebs.net Thu Sep 30 17:27:03 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 21:27:03 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> Message-ID: On 2010-09-30, Ian Collins wrote: > Which is why agile practices such as TDD have an edge. If it compiles > *and* passes all its tests, it must be right. So far as I know, that actually just means that the test suite is insufficient. :) Based on my experience thus far, anyway, I am pretty sure it's essentially not what happens that the tests and code are both correct, and it is usually the case either that the tests fail or that there are not enough tests. -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 joel.hedlund at gmail.com Thu Sep 30 17:30:43 2010 From: joel.hedlund at gmail.com (Joel Hedlund) Date: Thu, 30 Sep 2010 14:30:43 -0700 (PDT) Subject: gedit 'External Tools' plugin hashlib weirdness References: <9b96e07d-ee84-4cb2-ab1b-06bc01868aab@p26g2000yqb.googlegroups.com> Message-ID: <2b3740e5-b798-4275-b505-b68da470e18b@i5g2000yqe.googlegroups.com> On Sep 30, 3:40?pm, Peter Otten <__pete... at web.de> wrote: > I'm surprised that /usr/lib/python2.4 doesn't appear in the traceback. That certainly would have been useful, wouldn't it? From usenet-nospam at seebs.net Thu Sep 30 17:31:23 2010 From: usenet-nospam at seebs.net (Seebs) Date: 30 Sep 2010 21:31:23 GMT Subject: "Strong typing vs. strong testing" References: <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <4ca421a1$1@dnews.tpgi.com.au> <4ca44fea@dnews.tpgi.com.au> Message-ID: On 2010-09-30, RG wrote: > That gives (what I would consider to be) false positives, e.g.: > [ron at mighty:~]$ cat foo.c > void foo(long x) {} > int main() { foo(1); } > [ron at mighty:~]$ gcc -Wconversion foo.c > foo.c: In function ???main???: > foo.c:4: warning: passing argument 1 of ???foo??? with different width due > to prototype But it's *not* a false positive. The compiler is not claiming that the conversion couldn't be done -- it's just telling you that there is a change of type going on. If you don't want that message, it is certainly possible to write code which won't get it, and which will reliably work everywhere. > So you have to choose your compiler > (and flags) first, and then I get to construct my example. If my > example has *either* an error that the compiler doesn't catch *or* a > non-error that it does catch then I win. Those goal posts are sorta red shifted at this point. You're redefining "error" and "non-error" so as to demand that a statically typed language offer you the same semantics of errors and non-errors that dynamically typed languages have. That's cheating, though. The claim is about C, not about what people who are expecting a dynamically typed language would like C to be like. -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-news at hotmail.com Thu Sep 30 17:44:10 2010 From: ian-news at hotmail.com (Ian Collins) Date: Fri, 01 Oct 2010 10:44:10 +1300 Subject: "Strong typing vs. strong testing" In-Reply-To: References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <87fwwvrnmf.fsf@kuiper.lan.informatimago.com> <989aab6e-0f95-4ed2-a445-5d3cb0dca3a7@x42g2000yqx.googlegroups.com> <8gk6o2Fc8aU2@mid.individual.net> Message-ID: <8gkelaFc8aU4@mid.individual.net> On 10/ 1/10 10:27 AM, Seebs wrote: > On 2010-09-30, Ian Collins wrote: >> Which is why agile practices such as TDD have an edge. If it compiles >> *and* passes all its tests, it must be right. > > So far as I know, that actually just means that the test suite is > insufficient. :) > > Based on my experience thus far, anyway, I am pretty sure it's essentially > not what happens that the tests and code are both correct, and it is usually > the case either that the tests fail or that there are not enough tests. Which is why we write the tests first. The only code written is written to pass a test. Reviewing tests is a lot easier than reviewing the code while working out what is is supposed to do. -- Ian Collins From vend82 at virgilio.it Thu Sep 30 18:02:30 2010 From: vend82 at virgilio.it (Vend) Date: Thu, 30 Sep 2010 15:02:30 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: On 30 Set, 01:47, RG wrote: > In article , > ?Keith Thompson wrote: > > > > > RG writes: > > > In article > > > <07f75df3-778d-4e3d-8aa0-fbd4bd108... at k22g2000prb.googlegroups.com>, > > > ?Squeamizh wrote: > > >> On Sep 29, 3:02?pm, RG wrote: > > [...] > > >> > This is a red herring. ?You don't have to invoke run-time input to > > >> > demonstrate bugs in a statically typed language that are not caught by > > >> > the compiler. ?For example: > > > >> > [ron at mighty:~]$ cat foo.c > > >> > #include > > > >> > int maximum(int a, int b) { > > >> > ? return (a > b ? a : b); > > > >> > } > > > >> > int foo(int x) { return 9223372036854775807+x; } > > > >> > int main () { > > >> > ? printf("%d\n", maximum(foo(1), 1)); > > >> > ? return 0;} > > > >> > [ron at mighty:~]$ gcc -Wall foo.c > > >> > [ron at mighty:~]$ ./a.out > > >> > 1 > > > >> > Even simple arithmetic is Turing-complete, so catching all type-related > > >> > errors at compile time would entail solving the halting problem. > > > >> > rg > > > >> In short, static typing doesn't solve all conceivable problems. > > > > More specifically, the claim made above: > > > >> in C I can have a function maximum(int a, int b) that will always > > >> work. Never blow up, and never give an invalid answer. > > > > is false. ?And it is not necessary to invoke the vagaries of run-time > > > input to demonstrate that it is false. > > > But the above maximum() function does exactly that. ?The program's > > behavior happens to be undefined or implementation-defined for reasons > > unrelated to the maximum() function. > > > Depending on the range of type int on the given system, either the > > behavior of the addition in foo() is undefined (because it overflows), > > or the implicit conversion of the result to int either yields an > > implementation-defined result or (in C99) raises an > > implementation-defined signal; the latter can lead to undefined > > behavior. > > > Since 9223372036854775807 is 2**63-1, what *typically* happens is that > > the addition yields the value 0, but the C language doesn't require that > > particular result. ?You then call maximum with arguments 0 and 1, and > > it quite correctly returns 1. > > This all hinges on what you consider to be "a function maximum(int a, > int b) that ... always work[s] ... [and] never give[s] an invalid > answer." ?But if you don't consider an incorrect answer (according to > the rules of arithmetic) to be an invalid answer then the claim becomes > vacuous. ?You could simply ignore the arguments and return 0, and that > would meet the criteria. But in your own example the function maximum() does give the correct answer, therefore your point doesn't stand. From vend82 at virgilio.it Thu Sep 30 18:07:20 2010 From: vend82 at virgilio.it (Vend) Date: Thu, 30 Sep 2010 15:07:20 -0700 (PDT) Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> Message-ID: <40e338f5-eff8-42ca-bbfa-3117c109b918@f25g2000yqc.googlegroups.com> On 30 Set, 03:01, RG wrote: > In article , > ?Keith Thompson wrote: > > > > > RG writes: > > > In article , > > > ?Keith Thompson wrote: > > > >> RG writes: > > >> > In article > > >> > <07f75df3-778d-4e3d-8aa0-fbd4bd108... at k22g2000prb.googlegroups.com>, > > >> > ?Squeamizh wrote: > > >> >> On Sep 29, 3:02?pm, RG wrote: > > >> [...] > > >> >> > This is a red herring. ?You don't have to invoke run-time input to > > >> >> > demonstrate bugs in a statically typed language that are not caught > > >> >> > by > > >> >> > the compiler. ?For example: > > > >> >> > [ron at mighty:~]$ cat foo.c > > >> >> > #include > > > >> >> > int maximum(int a, int b) { > > >> >> > ? return (a > b ? a : b); > > > >> >> > } > > > >> >> > int foo(int x) { return 9223372036854775807+x; } > > > >> >> > int main () { > > >> >> > ? printf("%d\n", maximum(foo(1), 1)); > > >> >> > ? return 0;} > > > >> >> > [ron at mighty:~]$ gcc -Wall foo.c > > >> >> > [ron at mighty:~]$ ./a.out > > >> >> > 1 > > > >> >> > Even simple arithmetic is Turing-complete, so catching all > > >> >> > type-related > > >> >> > errors at compile time would entail solving the halting problem. > > > >> >> > rg > > > >> >> In short, static typing doesn't solve all conceivable problems. > > > >> > More specifically, the claim made above: > > > >> >> in C I can have a function maximum(int a, int b) that will always > > >> >> work. Never blow up, and never give an invalid answer. > > > >> > is false. ?And it is not necessary to invoke the vagaries of run-time > > >> > input to demonstrate that it is false. > > > >> But the above maximum() function does exactly that. ?The program's > > >> behavior happens to be undefined or implementation-defined for reasons > > >> unrelated to the maximum() function. > > > >> Depending on the range of type int on the given system, either the > > >> behavior of the addition in foo() is undefined (because it overflows), > > >> or the implicit conversion of the result to int either yields an > > >> implementation-defined result or (in C99) raises an > > >> implementation-defined signal; the latter can lead to undefined > > >> behavior. > > > >> Since 9223372036854775807 is 2**63-1, what *typically* happens is that > > >> the addition yields the value 0, but the C language doesn't require that > > >> particular result. ?You then call maximum with arguments 0 and 1, and > > >> it quite correctly returns 1. > > > > This all hinges on what you consider to be "a function maximum(int a, > > > int b) that ... always work[s] ... [and] never give[s] an invalid > > > answer." > > > int maximum(int a, int b) { return a > b ? a : b; } > > > > ? ? ? ? ? But if you don't consider an incorrect answer (according to > > > the rules of arithmetic) to be an invalid answer then the claim becomes > > > vacuous. ?You could simply ignore the arguments and return 0, and that > > > would meet the criteria. > > > I don't believe it's possible in any language to write a maximum() > > function that returns a correct result *when given incorrect argument > > values*. > > > The program (assuming a typical implementation) calls maximum() with > > arguments 0 and 1. ?maximum() returns 1. ?It works. ?The problem > > is elsewhere in the program. > > That the problem is "elsewhere in the program" ought to be small > comfort. ?But very well, try this instead: > > [ron at mighty:~]$ cat foo.c > #include > > int maximum(int a, int b) { return a > b ? a : b; } > > int main() { > ? long x = 8589934592; > ? printf("Max of %ld and 1 is %d\n", x, maximum(x,1)); > ? return 0;} > > [ron at mighty:~]$ gcc -Wall foo.c > [ron at mighty:~]$ ./a.out > Max of 8589934592 and 1 is 1 So the incorrect behavior happens in a case where C doesn't enforce strict typing rules. From hidura at gmail.com Thu Sep 30 18:16:29 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 30 Sep 2010 22:16:29 +0000 Subject: Problems with wsgi Python3 In-Reply-To: Message-ID: <90e6ba4fc5720cce4a0491816e70@google.com> I still receive nothing, here it's the code of the form maybe there it's the problem: On Sep 30, 2010 4:55pm, "Diez B. Roggisch" wrote: > Thomas Jollans thomas at jollybox.de> writes: > > On Thursday 30 September 2010, it occurred to hidura at gmail.com to > exclaim: > >> What mean this > >> -----------------------------743346150198628700241600224--\r? > > > > it looks like a MIME boundary. In this context most likely from a > > multipart/form-data transmission. > yep, as one can see in the headers below. > Additonally, it looks to me as if the form you are submitting is > empty. The content-length of just 61 matches barely the boundary. > Use something like > pdict = cgi.parse_header(environ["CONTENT_TYPE"])[1] > cgi.parse_multipart(environ["wsgi.input"], pdict) > to properly parse the request. But then of course actually upload > something. > Diez > > > >> > >> On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > >> > Sorry, for the last mail, here it's what you asked: > >> > > >> > {'CONTENT_LENGTH': '61', > >> > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > >> > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > >> > boundary=---------------------------8905735096173894531259794847', > >> > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > >> > [Thu Sep 30 13:35:07 2010] > [error] '/home/hidura/webapps/karinapp/Suite', > >> > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > >> > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > >> > [Thu Sep 30 13:35:07 2010] > >> > [error] > >> > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', > [Thu > >> > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > >> > [Thu Sep 30 13:35:07 2010] [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > >> > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > >> > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > >> > [Thu Sep 30 13:35:07 2010] [error] 'close', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > >> > [Thu Sep 30 13:35:07 2010] > >> > [error] 'http://hidura.webfactional.com/?md=btdump', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > >> > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux > x86_64; > >> > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) > Firefox/3.6.10', > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > >> > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > >> > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > >> > [Thu Sep 30 13:35:07 2010] [error] '58742', > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > >> > [Thu Sep 30 13:35:07 2010] [error] 'POST', > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > >> > [Thu Sep 30 13:35:07 2010] > >> > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > >> > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > >> > [Thu Sep 30 13:35:07 2010] [error] '80', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > >> > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) mod_wsgi/3.3 > >> > Python/3.1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > >> > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com|/gate.py', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > >> > [Thu Sep 30 13:35:07 2010] [error] 'application', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > >> > [Thu Sep 30 13:35:07 2010] [error] '0', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > >> > [Thu Sep 30 13:35:07 2010] [error] '51543', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > >> > [Thu Sep 30 13:35:07 2010] [error] '', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > >> > [Thu Sep 30 13:35:07 2010] [error] '1', > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > >> > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > >> > [Thu Sep 30 13:35:07 2010] [error] , > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > >> > [Thu Sep 30 13:35:07 2010] [error] , > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > >> > [Thu Sep 30 13:35:07 2010] [error] , > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > >> > [Thu Sep 30 13:35:07 2010] [error] False, > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > >> > [Thu Sep 30 13:35:07 2010] [error] True, > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > >> > [Thu Sep 30 13:35:07 2010] [error] False, > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > >> > [Thu Sep 30 13:35:07 2010] [error] 'http', > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > >> > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > >> > > >> > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > >> > > *sigh* > >> > > > >> > > > >> > > > >> > > AGAIN, please do *not* reply to me personally. Reply to the ML or > NG > >> > > >> > you are posting in. I'm beginning to believe that it's a waste of > time to > >> > answer you since you seem not able to follow even the most simple of > >> > advice and rules. > >> > > >> > > And read the answers you get thoroughly, you did not give all the > >> > > >> > information I asked you for. > >> > > >> > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > >> > > > The output is: > >> > > > > >> > > > > >> > > > > >> > > > -----------------------------110550484811701713451664404475--\r > >> > > > > >> > > > > >> > > > > >> > > > No more i don 't know what that means or what do with this. > >> > > > > >> > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> wrote: > >> > > > > hidura at gmail.com writes: > >> > > > > > Hello list, i had seriously troubles with the connection > between > >> > > >> > a form and the > >> > > >> > > > > > wsgi, i' ve made an application on Python3 and was running > >> > > >> > perfectly but when i > >> > > >> > > > > > try to use the to pass the data this can't be see on the > server, > >> > > >> > so what > >> > > >> > > > > > is your recommendation?, i am open to all the ideas less > leave to > >> > > >> > Python2 i > >> > > >> > > > > > can't all the project was write on Python3, i was looking > into > >> > > >> > the PEP 444 > >> > > >> > > > > > proposal too. > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > Here is the code what i used to take the data: > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro > >> > > > > > n > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > ['CONTENT_LENGTH'])).decode())) > >> > > > > > >> > > > > What is the ouptut of this? What does > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > import pprint > >> > > > > > >> > > > > > >> > > > > > >> > > > > pprint.pprint(environ) > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > give you? > >> > > > > > >> > > > > > and here it's what the os.environ.item() prints to me: > >> > > > > That's irrelevant. The WSGI-environ is what is needed. > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > Diez > >> > > > > > >> > > > > > >> > > > > > >> > > > > -- > >> > > > > > >> > > > > > >> > > > > > >> > > > > http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Thu Sep 30 20:49:37 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 30 Sep 2010 17:49:37 -0700 (PDT) Subject: namespace hacking question References: Message-ID: <195b129b-4fbb-4091-8ed5-d4b1bef00d2b@e34g2000prn.googlegroups.com> kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', 'ham', 'eggs'): > ? ? d[v] = init(v) > > foo(d['spam']) > bar(d['ham']) > baz(d['eggs']) > > This is fine, but I'd like to get rid of the tedium of typing all > those extra d['...']s. Here's an approach that uses a decorator. It requires strings to be passed, so it's not an exact fit for your requirement, but it's very straightforward: d = dict( spam = 1, ham = 2, eggs = 3 ) def argdispatch(func): def _wrapper(*args): args = [d[k] for k in args if k in d] return func(*args) return _wrapper @argdispatch def foo(x): print x @argdispatch def bar(x): print x*2 >>> foo('spam') 1 >>> bar('spam') 2 >>> With a good editor, it should even take care of one of the quotes for you ;) From tekion at gmail.com Thu Sep 30 21:54:00 2010 From: tekion at gmail.com (tekion) Date: Thu, 30 Sep 2010 18:54:00 -0700 (PDT) Subject: Having problem with subclass Message-ID: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> All, I have file name A.py with a class name Aclass. I have a file name B.py with sub class of Aclass, like import A class Bclass(Aclass) ...rest of code When I test it, calling B.py, I am getting: class Bclas(Aclass): NameError: name 'Aclass' is not defined When I move Bclass to A.py, it works. Is there some restriction in python that sub classing a class has be in the same file as the class you're are sub classing? Thanks. From don at geddis.org Thu Sep 30 21:57:27 2010 From: don at geddis.org (Don Geddis) Date: Thu, 30 Sep 2010 18:57:27 -0700 Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> Message-ID: <87tyl63cag.fsf@mail.geddis.org> Keith Thompson wrote on Thu, 30 Sep 2010: > RG writes: >> You're missing a lot of context. I'm not trying to criticize C, just to >> refute a false claim that was made about it. > Can you cite the article that made this false claim, and exactly what > the false claim was? http://groups.google.com/group/comp.lang.lisp/msg/431925448da59481 Message-ID: <0497e39d-6bd1-429d-a86f-f4c89babe1a4 at u31g2000pru.googlegroups.com> From: TheFlyingDutchman Newsgroups: comp.lang.lisp [...] in C I can have a function maximum(int a, int b) that will always work. Never blow up, and never give an invalid answer. If someone tries to call it incorrectly it is a compile error. [...] _______________________________________________________________________________ Don Geddis http://don.geddis.org/ don at geddis.org From clp2 at rebertia.com Thu Sep 30 22:08:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 30 Sep 2010 19:08:33 -0700 Subject: Having problem with subclass In-Reply-To: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> References: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> Message-ID: On Thu, Sep 30, 2010 at 6:54 PM, tekion wrote: > All, > I have file name A.py with a class name Aclass. I have a file name > B.py with sub class of Aclass, like > import A > class Bclass(Aclass) > ...rest of code > When I test it, calling B.py, I am getting: > > class Bclas(Aclass): > NameError: name 'Aclass' is not defined > > When I move ?Bclass to A.py, it works. ?Is there some restriction in > python that sub classing a class has be in the same file as the class > you're are sub classing? Thanks. "import A" *only* imports the name "A" into B's namespace; names within A.py are not directly imported and can only be referenced using the dot operator on A (i.e. "A.Aclass"). "from A import *" takes all the names defined in A.py and imports them into B's namespace (which is apparently what you expected "import A" to do), but this is frowned upon as it can pollute B's namespace. You should probably either do "from A import Aclass" (i.e. explicitly specifying which names from A you want), or instead refer to Aclass in B.py using "A.Aclass" (i.e. "class Bclass(A.Aclass)"). Cheers, Chris -- http://blog.rebertia.com From brucep at wn.com.au Thu Sep 30 22:09:14 2010 From: brucep at wn.com.au (Bruce Pearson) Date: Fri, 01 Oct 2010 10:09:14 +0800 Subject: Having problem with subclass In-Reply-To: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> References: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> Message-ID: <4CA542CA.8060604@wn.com.au> Try: import A class Bclass(A.Aclass) ...rest of code On 1/10/2010 9:54 AM, tekion wrote: > All, > I have file name A.py with a class name Aclass. I have a file name > B.py with sub class of Aclass, like > import A > class Bclass(Aclass) > ...rest of code > When I test it, calling B.py, I am getting: > > class Bclas(Aclass): > NameError: name 'Aclass' is not defined > > When I move Bclass to A.py, it works. Is there some restriction in > python that sub classing a class has be in the same file as the class > you're are sub classing? Thanks. From gcontsubodh at gmail.com Thu Sep 30 22:12:06 2010 From: gcontsubodh at gmail.com (Geo_subodh) Date: Thu, 30 Sep 2010 19:12:06 -0700 (PDT) Subject: discussion Message-ID: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> please send me the simple python code that uses input number greater than3 digits(>3 digits) and checks whether the number is palindrome or not. From python.list at tim.thechases.com Thu Sep 30 22:14:16 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 30 Sep 2010 21:14:16 -0500 Subject: Having problem with subclass In-Reply-To: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> References: <5fce1fb4-3fc1-47cc-a588-b335b7516846@c10g2000yqh.googlegroups.com> Message-ID: <4CA543F8.1060600@tim.thechases.com> On 09/30/10 20:54, tekion wrote: > All, > I have file name A.py with a class name Aclass. I have a file name > B.py with sub class of Aclass, like > import A > class Bclass(Aclass) > ...rest of code > When I test it, calling B.py, I am getting: > > class Bclas(Aclass): > NameError: name 'Aclass' is not defined > > When I move Bclass to A.py, it works. Is there some restriction in > python that sub classing a class has be in the same file as the class > you're are sub classing? This is pretty straight-forward name-spacing. You can use class Bclass(A.Aclass): ... or from A import Aclass class Bclass(Aclass): ... But in your code as it currently stands, the module "A" is the only thing in scope, not "Aclass", so you have to either bring Aclass into scope, or qualify it. -tkc From roy at panix.com Thu Sep 30 22:15:54 2010 From: roy at panix.com (Roy Smith) Date: Thu, 30 Sep 2010 22:15:54 -0400 Subject: discussion References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: In article <31a08825-bb72-4e9f-8710-a39fe2bc9216 at u31g2000pru.googlegroups.com>, Geo_subodh wrote: > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and checks whether the number is palindrome > or not. What class is this for? From usenet-nospam at seebs.net Thu Sep 30 22:28:41 2010 From: usenet-nospam at seebs.net (Seebs) Date: 01 Oct 2010 02:28:41 GMT Subject: "Strong typing vs. strong testing" References: <7df0eb06-9be1-4c9c-8057-e9fdb7f0bedd@q16g2000prf.googlegroups.com> <87hbhbty7q.fsf@kuiper.lan.informatimago.com> <0497e39d-6bd1-429d-a86f-f4c89babe1a4@u31g2000pru.googlegroups.com> <9b6e062d-2fd5-413d-9b01-ab9f6213f6ad@w19g2000yqb.googlegroups.com> <996bd4e6-37ff-4a55-8db5-6e7574fbd8e1@k22g2000prb.googlegroups.com> <07f75df3-778d-4e3d-8aa0-fbd4bd108a57@k22g2000prb.googlegroups.com> <0390e2b4-fa28-49b3-a867-39be6d66828f@w19g2000yqb.googlegroups.com> <87tyl63cag.fsf@mail.geddis.org> Message-ID: On 2010-10-01, Don Geddis wrote: > in C I can have a function maximum(int a, int b) that will always > work. Never blow up, and never give an invalid answer. If someone > tries to call it incorrectly it is a compile error. I would agree that the third sentence is arguably wrong, simply because there's no such thing (outside #error) of a mandate to stop compiling. However, my understanding was that the dispute was over the second sentence, and that's certainly correct. The obvious simple maximum() in C will not raise an exception nor return something which isn't an int in any program which is not on its face invalid in the call. This is by definite contrast with several of the interpreted languages, where a function or subroutine like that cannot specify that its argument must be some kind of integer. -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 Sep 30 22:30:35 2010 From: nagle at animats.com (John Nagle) Date: Thu, 30 Sep 2010 19:30:35 -0700 Subject: discussion In-Reply-To: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: <4ca547ed$0$1647$742ec2ed@news.sonic.net> On 9/30/2010 7:12 PM, Geo_subodh wrote: > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and checks whether the number is palindrome > or not. def ispalin(s) : s = str(s) n = len(s) / 2 return(s[:n] == s[::-1][:n]) Please use a message subject that describes the content of the message. John Nagle From clp2 at rebertia.com Thu Sep 30 22:30:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 30 Sep 2010 19:30:41 -0700 Subject: discussion In-Reply-To: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> Message-ID: On Thu, Sep 30, 2010 at 7:12 PM, Geo_subodh wrote: > please send me the simple python code that uses input number greater > than3 digits(>3 digits) and ?checks whether the number is palindrome > or not. Do your own homework; it's not like you're even paying us (not that we would have the moral turpitude to be accessories to academic misconduct anyway). If you're having trouble, ask a *specific question* rather than childishly saying "PLZ SEND ME THE CODE!". Cheers, Chris -- Relevant, Entertaining, and Groan-inducing!: http://plzsendmethecode.blogspot.com/ From no.email at nospam.invalid Thu Sep 30 22:49:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 30 Sep 2010 19:49:15 -0700 Subject: discussion References: <31a08825-bb72-4e9f-8710-a39fe2bc9216@u31g2000pru.googlegroups.com> <4ca547ed$0$1647$742ec2ed@news.sonic.net> Message-ID: <7xd3rupqz8.fsf@ruckus.brouhaha.com> John Nagle writes: > def ispalin(s) : > s = str(s) > n = len(s) / 2 > return(s[:n] == s[::-1][:n]) def ispalin(s): return (s == "You betcha!") ;-) From hidura at gmail.com Thu Sep 30 23:56:46 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Fri, 01 Oct 2010 03:56:46 +0000 Subject: Problems with wsgi Python3 In-Reply-To: <90e6ba4fc5720cce4a0491816e70@google.com> Message-ID: <90e6ba53b492f430e40491862e7a@google.com> Ppl, thankyou Diez and Thomas for your answers i did it, but it present me a problem with the solution what you give me Thomas this is the code: ValueError: Invalid boundary in multipart form: '' On Sep 30, 2010 6:16pm, hidura at gmail.com wrote: > I still receive nothing, here it's the code of the form maybe there it's > the problem: > On Sep 30, 2010 4:55pm, "Diez B. Roggisch" deets at web.de> wrote: > > Thomas Jollans thomas at jollybox.de> writes: > > > > > > > > > On Thursday 30 September 2010, it occurred to hidura at gmail.com to > exclaim: > > > > >> What mean this > > > > >> -----------------------------743346150198628700241600224--\r? > > > > > > > > > > it looks like a MIME boundary. In this context most likely from a > > > > > multipart/form-data transmission. > > > > > > > > yep, as one can see in the headers below. > > > > > > > > Additonally, it looks to me as if the form you are submitting is > > > > empty. The content-length of just 61 matches barely the boundary. > > > > > > > > Use something like > > > > > > > > pdict = cgi.parse_header(environ["CONTENT_TYPE"])[1] > > > > cgi.parse_multipart(environ["wsgi.input"], pdict) > > > > > > > > to properly parse the request. But then of course actually upload > > > > something. > > > > > > > > Diez > > > > > > > > > > > > > > > > > >> > > > > >> On Sep 30, 2010 2:38pm, hidura at gmail.com wrote: > > > > >> > Sorry, for the last mail, here it's what you asked: > > > > >> > > > > > >> > {'CONTENT_LENGTH': '61', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'CONTENT_TYPE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'multipart/form-data; > > > > >> > boundary=---------------------------8905735096173894531259794847', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'DOCUMENT_ROOT': > > > > >> > [Thu Sep 30 13:35:07 2010] > [error] '/home/hidura/webapps/karinapp/Suite', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'GATEWAY_INTERFACE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'CGI/1.1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT': > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > >> > [error] > > > > >> > 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', > [Thu > > > > >> > Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_CHARSET': > > > > >> > [Thu Sep 30 13:35:07 2010] > [error] 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_ENCODING': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'gzip,deflate', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_ACCEPT_LANGUAGE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'es-do,en-us;q=0.7,en;q=0.3', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_CONNECTION': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'close', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_HOST': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_REFERER': > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > >> > [error] 'http://hidura.webfactional.com/?md=btdump', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_USER_AGENT': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'Mozilla/5.0 (X11; U; Linux > x86_64; > > > > >> > en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) > Firefox/3.6.10', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP_X_FORWARDED_FOR': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '190.94.122.180', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'PATH_INFO': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'QUERY_STRING': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_ADDR': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REMOTE_PORT': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '58742', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_METHOD': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'POST', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'REQUEST_URI': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_FILENAME': > > > > >> > [Thu Sep 30 13:35:07 2010] > > > > >> > [error] '/home/hidura/webapps/karinapp/Suite/Gate.py', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SCRIPT_NAME': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '/Gate.py', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADDR': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '127.0.0.1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_ADMIN': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '[no address given]', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_NAME': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'hidura.webfactional.com', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PORT': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '80', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_PROTOCOL': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'HTTP/1.0', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SIGNATURE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'SERVER_SOFTWARE': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'Apache/2.2.15 (Unix) > mod_wsgi/3.3 > > > > >> > Python/3.1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.application_group': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'web152.webfaction.com| > /gate.py', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.callable_object': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'application', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.handler_script': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.input_chunked': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '0', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_host': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.listener_port': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '51543', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.process_group': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.request_handler': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi-script', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.script_reloading': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] '1', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'mod_wsgi.version': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] (3, 3), > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.errors': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.file_wrapper': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.input': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] , > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multiprocess': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] False, > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.multithread': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] True, > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.run_once': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] False, > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.url_scheme': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'http', > > > > >> > [Thu Sep 30 13:35:07 2010] [error] 'wsgi.version': > > > > >> > [Thu Sep 30 13:35:07 2010] [error] (1, 1)} > > > > >> > > > > > >> > On Sep 30, 2010 1:56pm, "Diez B. Roggisch" deets at web.de> wrote: > > > > >> > > *sigh* > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > AGAIN, please do *not* reply to me personally. Reply to the ML > or NG > > > > >> > > > > > >> > you are posting in. I'm beginning to believe that it's a waste of > time to > > > > >> > answer you since you seem not able to follow even the most simple > of > > > > >> > advice and rules. > > > > >> > > > > > >> > > And read the answers you get thoroughly, you did not give all the > > > > >> > > > > > >> > information I asked you for. > > > > >> > > > > > >> > > On Sep 30, 2010, at 7:08 PM, hidura at gmail.com wrote: > > > > >> > > > The output is: > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > -----------------------------110550484811701713451664404475--\r > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > No more i don 't know what that means or what do with this. > > > > >> > > > > > > > >> > > > On Sep 30, 2010 11:55am, "Diez B. Roggisch" deets at web.de> > wrote: > > > > >> > > > > hidura at gmail.com writes: > > > > >> > > > > > Hello list, i had seriously troubles with the connection > between > > > > >> > > > > > >> > a form and the > > > > >> > > > > > >> > > > > > wsgi, i' ve made an application on Python3 and was running > > > > >> > > > > > >> > perfectly but when i > > > > >> > > > > > >> > > > > > try to use the to pass the data this can't be see on the > server, > > > > >> > > > > > >> > so what > > > > >> > > > > > >> > > > > > is your recommendation?, i am open to all the ideas less > leave to > > > > >> > > > > > >> > Python2 i > > > > >> > > > > > >> > > > > > can't all the project was write on Python3, i was looking > into > > > > >> > > > > > >> > the PEP 444 > > > > >> > > > > > >> > > > > > proposal too. > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > Here is the code what i used to take the data: > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > print(urllib.parse.parse_qs(environ['wsgi.input'].read(int(enviro > > > > >> > > > > > n > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > ['CONTENT_LENGTH'])).decode())) > > > > >> > > > > > > > > >> > > > > What is the ouptut of this? What does > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > import pprint > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > pprint.pprint(environ) > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > give you? > > > > >> > > > > > > > > >> > > > > > and here it's what the os.environ.item() prints to me: > > > > >> > > > > That's irrelevant. The WSGI-environ is what is needed. > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > Diez > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > -- > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > http://mail.python.org/mailman/listinfo/python-list > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: